• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

My Monkey Do

A Log of Coding Solutions

  • Home
  • Web Hosts
  • Tools
  • About

javascript

WordPress Widget Image Field

September 19, 2012 by Webhead

I found a great utility plugin to help with adding a Image picker field to a widget.  Basically you install and activate this plugin and you make your own widget and utilize the image field easily.
The only problem I had was that it didn’t work in Firefox.  I found a simple error on line 72 in the scripts.js file.  Instead of calling events.target.href it should be e.target.href because e is the parameter passed in.

 

how to use: http://mondaybynoon.com/20120206/wordpress-widget-image-field/

Filed Under: Coding Tagged With: debug, javascript, wordpress

Passing parameters to setTimeout in a loop

July 12, 2012 by Webhead

Problem

I know to pass a parameter to a setTimeout function you would use javascript’s “closure” to get it to work:

setTimeout(function(){alert(someParameter)}, 1000);

However if you are setting someParameter in a loop, setTimeout will always alert the last value set to someParameter.

 

Solution

The solution is to set a scope around setTimeout like so:

var strings = [ "hello", "world" ]; var delay = 1000; for(var i=0;i<strings.length;i++) {     (function(s){         setTimeout( function(){alert(s);}, delay);     })(strings[i]);     delay += 1000; }

source: http://stackoverflow.com/questions/6425062/passing-functions-to-settimeout-in-a-loop-always-the-last-value

 

Filed Under: Coding Tagged With: javascript

jQuery add table row

April 21, 2012 by Webhead

Problem

How do you add a table row using jQuery?  A table has so many different elements in it that things might get screwy.

 

Solution

There is no one statement-to-use-on-all, but the below line is a pretty general answer and should solve your needs even when there are no table rows:

$('#myTable > tbody:last').append('<tr>...</tr><tr>...</tr>');

keywords: jquery add table row
source: http://stackoverflow.com/questions/171027/add-table-row-in-jquery

Filed Under: Coding Tagged With: javascript, jquery

Javascript Files with PHP

October 5, 2011 by Webhead

Below is a great article on getting your PHP to print out a javascript file and including it like any other javascript file.   You basically just have to name the file something like “something.js.php” so that PHP knows to interpret the file.  Then include it like a normal javascript file.  In the something.js.php you can add a Header() function to make it render like a javascript file (include carriage returns).

www.givegoodweb.com/post/71/javascript-php

 

 

Filed Under: Coding Tagged With: javascript, php

Caching Issue

September 1, 2011 by Webhead

Problem:

Changed a javascript file, but the browser still detects it.  Take out the javascript file, and the page still runs fine as if it is there.  This is occurring in IE.

Solution:

  1. Hit f5 a million times.  Clear the browser cache.
  2. Close browser
  3. Open browser

Filed Under: Coding Tagged With: IE crap, javascript

Chain from Cloth Experiment

August 25, 2011 by Webhead

I needed to make a chain that was free flowing and looked like a real dangling chain.  I remembered Andrew Hoyer’s super cool Cloth Experiment and wanted to adapt it.  It turned out pretty good.  I first limited the points to just one vertical line.  Then had the last point draw an image.  A few more minor tweeks here and there, including using jQuery mouse events instead of Andrew’s mouse events to resolve an isssue with the scrollbar registering clicks, and here it is, in the upper left corner:

http://orasidesign.com/see-what-we-do/

 

Filed Under: Coding Tagged With: html 5, javascript

  • « Go to Previous Page
  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Go to page 4
  • Go to page 5
  • Go to Next Page »

Primary Sidebar

Topics

apache apple bootstrap buddypress chrome cloudways cms css debug drupal eCommerce firebug firefox git gmail goDaddy google hosting htaccess html html 5 IE crap image iPad iPhone javascript jquery kinsta linux localization mac os x ms sql mysql open source optimize php php 7.2 svg tinymce woocommerce wordpress wpengine xss yii youtube

Categories

  • Coding
  • Off the Shelf
  • Plugins
  • Random Thoughts
  • Server Stuff
  • Tools
  • Uncategorized