<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:www.refactormycode.com,2007:users940</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/940" rel="self"/>
  <title>paul.wilkins.myopenid.com</title>
  <updated>Sat Feb 04 14:09:35 -0800 2012</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor615918</id>
    <published>2012-02-04T14:09:35-08:00</published>
    <title>[JavaScript] On Convert simple Javascript to jQuery plugin</title>
    <content type="html">&lt;p&gt;Here's some details on how to achieve that.
&lt;br /&gt;&lt;a href="http://docs.jquery.com/Plugins/Authoring" target="_blank"&gt;http://docs.jquery.com/Plugins/Authoring&lt;/a&gt;&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1995-convert-simple-javascript-to-jquery-plugin/refactors/615918" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor615917</id>
    <published>2012-02-04T14:09:22-08:00</published>
    <title>[JavaScript] On Convert simple Javascript to jQuery plugin</title>
    <content type="html">&lt;p&gt;Here's some details on how to achieve that.
&lt;br /&gt;&lt;a href="http://docs.jquery.com/Plugins/Authoring" target="_blank"&gt;http://docs.jquery.com/Plugins/Authoring&lt;/a&gt;&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1995-convert-simple-javascript-to-jquery-plugin/refactors/615917" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor600787</id>
    <published>2011-12-18T02:02:05-08:00</published>
    <title>[JavaScript] On Rounding in JS</title>
    <content type="html">&lt;p&gt;After writing some unit tests that provided full coverage over the original code, the following code results in the same end result.
&lt;/p&gt;

&lt;pre&gt;util.roundNumber = function(num, factor, type) {
    var roundTypes = {
        normal: 'round',
        up: 'ceil',
        down: 'floor'
    };
    return Math[roundTypes[type]](num / factor) * factor;
}&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1906-rounding-in-js/refactors/600787" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor600786</id>
    <published>2011-12-18T02:01:18-08:00</published>
    <title>[JavaScript] On Rounding in JS</title>
    <content type="html">&lt;p&gt;After writing some unit tests that provided full coverage over the original code, the following code results in the same end result.
&lt;/p&gt;

&lt;pre&gt;util.roundNumber = function(num, factor, type) {
    var roundTypes = {
        normal: 'round',
        up: 'ceil',
        down: 'floor'
    };
    return Math[roundTypes[type]](num / factor) * factor;
}&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1906-rounding-in-js/refactors/600786" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor546465</id>
    <published>2010-12-06T11:02:09-08:00</published>
    <title>[JavaScript] On Toggle a few divs</title>
    <content type="html">&lt;p&gt;You can use the attribute-starts-with selector
&lt;br /&gt;&lt;a href="http://api.jquery.com/attribute-starts-with-selector/" target="_blank"&gt;http://api.jquery.com/attribute-starts-with-selector/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The triggered function will run in the context of the matching element, which could be the &amp;quot;li-div3&amp;quot; element. That allows us to get the element using the this keyword.&lt;/p&gt;

&lt;p&gt;Once we have the element, we can get its id, and then take the part of that id which starts from the third character which gives us the appropriate div, &amp;quot;div3&amp;quot;&lt;/p&gt;

&lt;p&gt;Here I presume that the &amp;quot;div31&amp;quot; in the original post was a typing mistake, and should instead be &amp;quot;div3&amp;quot;&lt;/p&gt;

&lt;pre&gt;jQuery(function ($) {
  $('a[id^=&amp;quot;li-div&amp;quot;]').click(function () {
    $('#' + this.id.substring(3)).slideToggle();
  });
});&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1511-toggle-a-few-divs/refactors/546465" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor526577</id>
    <published>2010-08-21T00:16:51-07:00</published>
    <title>[JavaScript] On console.log for ie</title>
    <content type="html">&lt;p&gt;The major change here is removing the reliance on jQuery.&lt;/p&gt;

&lt;p&gt;Functions were declared as both function statements and as function decarations. They are now consistently done as function declarations.&lt;/p&gt;

&lt;p&gt;The enumObj function now uses an anonymous function to help reduce the scope of the content variables.&lt;/p&gt;

&lt;p&gt;Many other minor tweaks have also been made, for example with the makePanel function, which should have a separate responsibiity as that of the showPanel function.&lt;/p&gt;

&lt;pre&gt;(function () {
    function addHeading(obj) {
        var objType, h2, text;
        objType = (obj instanceof Array) ? &amp;quot;Array&amp;quot; : &amp;quot;Object&amp;quot;;
        h2 = document.createElement('h2');
        text = document.createTextNode(objType + ' details:');
        h2.appendChild(text);
        return h2;
    }
    function escapeHTML(str) {
        var div, text;
        div = document.createElement('div');
        text = document.createTextNode(str);
        div.appendChild(text);
        return div.innerHTML;
    }
    function enumObj(obj, skipHeading) {
        var content;
        content = document.createDocumentFragment();
        if (typeof (obj) === &amp;quot;object&amp;quot;) {
            if (skipHeading !== false) {
                content.appendChild(addHeading(obj));
            }
            content.appendChild(function () {
                var ul, li, span, text, key;
                ul = document.createElement('ul');
                ul.className = 'consoleObjList';
                for (key in obj) {
                    if (obj.hasOwnProperty(key)) {
                        li = document.createElement('li');
                        span = document.createElement('span');
                        text = document.createTextNode(key);
                        span.appendChild(text);
                        li.appendChild(span);
                        
                        li.appendChild(document.createTextNode(': '));
                        li.appendChild(enumObj(obj[key], false));
                        ul.appendChild(li);
                    }
                }
                return ul;
            }());
        } else {
            //treat it as a string
            content.appendChild(document.createTextNode(escapeHTML(obj)));
        }
        return content;
    }
    function makePanel() {
        var ul = document.createElement('ul');
        ul.id = 'consolePanel';
        ul.className = 'rc6';
        return ul;
    }
    function showPanel(li) {
        var panel = document.getElementById(&amp;quot;consolePanel&amp;quot;);
        if (!panel) {
            panel = makePanel();
            document.body.appendChild(panel);
        }
        panel.appendChild(li);
    }

    if (!window.console) {
        window.console = {};

        window.console.log = function (obj) {
            var li = document.createElement('li');
            li.className = 'fc tal m_12';
            li.appendChild(enumObj(obj));
            showPanel(li);
        };
    }
}());&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1409-console-log-for-ie/refactors/526577" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor523210</id>
    <published>2010-08-03T03:18:01-07:00</published>
    <title>[JavaScript] On Javascript Loop Refactor</title>
    <content type="html">&lt;p&gt;You can use clearInterval from within the update function to step the process when the time is right.&lt;/p&gt;

&lt;p&gt;You may also want to use the correct spelling for ceiling.&lt;/p&gt;

&lt;p&gt;This code counts from 0 to totalUsers-1 as does your original code.
&lt;br /&gt;If you want it to instead count from 1 to totalUsers, move the if condition block to the start of the function.&lt;/p&gt;

&lt;pre&gt;function _initCountUpUsers()
{
    var totalUsers, ceiling, floot, update;

    totalUsers = $('#totalUsers');
    ceiling = parseInt(totalUsers.html());
    floor = ceiling - 10;
	
    function updateTotalUsers()
    {
        totalUsers.html(floor);
        floor++;
        if (floor === ceiling) {
            clearInterval(update);
        }
    }
    update = window.setInterval(updateTotalUsers, 1000, floor);
}&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1378-javascript-loop-refactor/refactors/523210" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor513388</id>
    <published>2010-06-10T02:59:59-07:00</published>
    <title>[JavaScript] On Format Numbers With Commas</title>
    <content type="html">&lt;p&gt;The addCommas should be AddCommas&lt;/p&gt;

&lt;p&gt;Originally I was using addCommas as the function name, and when renaming after posting so that it was the same as your original function, I missed one.&lt;/p&gt;

&lt;p&gt;As for the situation with match[1] and match[2], fixing the first issue should have fixed the second.&lt;/p&gt;

&lt;p&gt;Now to explain arguments[1]&lt;/p&gt;

&lt;p&gt;All functions can have their arguments accessed via the arguments collection. The argument called value that is passed to the AddCommas function can be accessed directly, or via arguments[0]&lt;/p&gt;

&lt;p&gt;The AddCommas function uses a second argument to store the part after the comma. I don't want to define the AddCommas function with a second argument, because that implies that the second argument should be used when first calling it. The solution is to pass the extra argument from within, and then to retrieve it using the arguments collection.&lt;/p&gt;

&lt;p&gt;Here's how it works for 100, 1000, and 123456789&lt;/p&gt;

&lt;p&gt;With 100, no match is found when it looks for a digit followed by 3 other digits. That [\.]?.* part just caters for optional decimal point values.
&lt;br /&gt;As no match is found for 100, it is returned without being changed.&lt;/p&gt;

&lt;p&gt;With 1000,
&lt;br /&gt;1. a match is found for 1 and 000
&lt;br /&gt;2. the function is called with 1 and 000
&lt;br /&gt;3. &#194;&#160;&#194;&#160;no match is found within just the 1
&lt;br /&gt;4. &#194;&#160;&#194;&#160;1,000 is returned back to the function
&lt;br /&gt;5. 1,000 returned out&lt;/p&gt;

&lt;p&gt;With 123456789
&lt;br /&gt;1. &#194;&#160;a match is found for 123456 and 789
&lt;br /&gt;2. &#194;&#160;the function is called with 123456 and 789
&lt;br /&gt;3. &#194;&#160;&#194;&#160;&#194;&#160;a match is found for 123 and 456
&lt;br /&gt;4. &#194;&#160;&#194;&#160;&#194;&#160;the function is called with 123 and 456
&lt;br /&gt;7. &#194;&#160;&#194;&#160;&#194;&#160;&#194;&#160;&#194;&#160;no match is found within just the 123
&lt;br /&gt;8. &#194;&#160;&#194;&#160;&#194;&#160;&#194;&#160;&#194;&#160;it joins '123' + ',' + '456' and returns 123,456 back to the function
&lt;br /&gt;9. &#194;&#160;&#194;&#160;&#194;&#160;it joins '123,456' + ',' + '789' returns 123,456,789 back to the function
&lt;br /&gt;10. 123,456,879 is returned out
&lt;/p&gt;

&lt;pre&gt;function AddCommas(value) {
    var match = /^(\d+)(\d{3}[\.]?.*)$/.exec(value.replace(/,/g, ''));
    if (match) {
        value = AddCommas(match[1], match[2]);
    }
    return value + (arguments[1] &amp;gt; '' ? ',' + arguments[1] : '');
}&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1316-format-numbers-with-commas/refactors/513388" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor512936</id>
    <published>2010-06-08T01:44:54-07:00</published>
    <title>[JavaScript] On Format Numbers With Commas</title>
    <content type="html">&lt;p&gt;Let's get functional on this.&lt;/p&gt;

&lt;pre&gt;function AddCommas(value) {
    var match = /^(\d+)(\d{3}[\.]?.*)$/.exec(value.replace(/,/g, ''));
    if (match) {
        value = AddCommas(match[1], match[2]);
    }
    return value + (arguments[1] &amp;gt; '' ? ',' + arguments[1] : '');
}
&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1316-format-numbers-with-commas/refactors/512936" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor469491</id>
    <published>2010-03-05T22:06:34-08:00</published>
    <title>[JavaScript] On Rotate co-ordinates</title>
    <content type="html">

&lt;pre&gt;this.rotate = function (antiClockwise) {
  var dir = (antiClockwise) ? -1 : 1;
  temp_x = this.x;
  this.x = dir * this.y;
  this.y = -dir * temp_x;
}&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1205-rotate-co-ordinates/refactors/469491" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor469490</id>
    <published>2010-03-05T22:04:35-08:00</published>
    <title>[JavaScript] On Rotate co-ordinates</title>
    <content type="html">&lt;p&gt;duplicate post&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1205-rotate-co-ordinates/refactors/469490" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor436622</id>
    <published>2010-02-04T02:25:13-08:00</published>
    <title>[JavaScript] On filter selectbox with 3000+ options </title>
    <content type="html">&lt;p&gt;Not to step on your toes, but there'a already a multiselect that has been developed for jQuery UI
&lt;br /&gt;&lt;a href="http://quasipartikel.at/multiselect/" target="_blank"&gt;http://quasipartikel.at/multiselect/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You may find quite a difference of performance.&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1168-filter-selectbox-with-3000-options/refactors/436622" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor412769</id>
    <published>2010-01-15T01:39:46-08:00</published>
    <title>[JavaScript] On Cpanel like password generator</title>
    <content type="html">&lt;p&gt;Here's a further refinement&lt;/p&gt;

&lt;pre&gt;function autogeneratepassword(params) {
    var passwd = '',
        length = params.pwlength,
        pwchars = '';
    pwchars += (params.chartype_upper) ? 'ABCDEFGHJKLMNPQRSTUVWYXZ' : '';
    pwchars += (params.chartype_lower) ? 'abcdefhjmnpqrstuvwxyz' : '';
    pwchars += (params.chartype_number) ? '23456789' : '';
    pwchars += (params.chartype_symbol) ? '!@#$%^&amp;amp;*()' : '';

    while (length-- &amp;gt; 0) {
        passwd += pwchars.charAt[Math.floor(Math.random() * pwchars.length)];
    }
    return passwd;
}&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1141-cpanel-like-password-generator/refactors/412769" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor402860</id>
    <published>2010-01-01T23:37:03-08:00</published>
    <title>[JavaScript] On timer.class</title>
    <content type="html">&lt;p&gt;An example usage within the comments would be useful.&lt;/p&gt;

&lt;p&gt;What else do you think is not so good about this code, and in your mind requires further looking at?&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1132-timer-class/refactors/402860" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor352287</id>
    <published>2009-11-01T19:54:36-08:00</published>
    <title>[JavaScript] On Need help with creating a loop</title>
    <content type="html">&lt;p&gt;Edit: using a normal for loop, as with for...in on an array there's no guarantee that other properties aren't prototyped in addition&lt;/p&gt;

&lt;pre&gt;var fields = ['invoice_discount', 'invoice_vat', 'invoice_salestax', 'invoice_freight'],
    i,
    field;
for (i = 0; i &amp;lt; fields.length; i++) {
    field = fields[i];
    this[field] = this.form.down('#' + field);
    this[field].observe('change', this._checkFormat.bindAsEventListener(this));
}&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1085-need-help-with-creating-a-loop/refactors/352287" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor300412</id>
    <published>2009-09-08T15:04:08-07:00</published>
    <title>[JavaScript] On Error on closure</title>
    <content type="html">&lt;p&gt;When the timeout runs the handler, the handler function is run from the scope of the window object.&lt;/p&gt;

&lt;p&gt;You need the handler function to know about the listener object. You can do that by passing listener to a function, and then have that function return a function. That way the returned function will still know about the listener variable.&lt;/p&gt;

&lt;p&gt;The same goes for the event variable as well.&lt;/p&gt;

&lt;pre&gt;fireEvent: function(event) {
    var type = event.type;
    if (!this.events) return;
    var listeners = this.events.get(type);
    var listener;
    if (listeners != null) {
        for (var i = 0,listener; listener = listeners[i++];) {
            // Using timeout, so the handlers may be execute &amp;quot;simultaneously&amp;quot;
            window.setTimeout(function (listener, event) {
                return function handler() {
                    listener.func.apply(listener.scope, [event]);
                };
            }(listener, event), 0);
        }
    }
},&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1026-error-on-closure/refactors/300412" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor300411</id>
    <published>2009-09-08T15:02:06-07:00</published>
    <title>[JavaScript] On Error on closure</title>
    <content type="html">&lt;p&gt;[deleted]&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1026-error-on-closure/refactors/300411" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor286469</id>
    <published>2009-09-01T14:49:07-07:00</published>
    <title>[JavaScript] On Better way in Prototype.js?</title>
    <content type="html">&lt;p&gt;This question has been languishing unresponded to for some time now, so I've crafted together some jQuery code to achieve what you require.&lt;/p&gt;

&lt;p&gt;For each element with a class of &amp;quot;toggle&amp;quot;, the code adds a Show/Hide link just below it.&lt;/p&gt;

&lt;p&gt;The link toggles the element by its id attribute, and switches between Show and Hide when you click it.
&lt;/p&gt;

&lt;pre&gt;$(function () {
    $('.toggle')
        .each(function () {
            $('&amp;lt;a href=&amp;quot;#' + $(this).attr('id') + '&amp;quot;&amp;gt;Show&amp;lt;/a&amp;gt;')
                .click(function () {
                    $($(this).attr('href'))
                        .toggle();
                    $(this).text(
                        $(this).text() !== 'Show' ? 'Show' : 'Hide'
                    );
                })
                .wrap('&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;')
                .insertAfter(this);
        })
        .hide();
});
.
.
.
&amp;lt;p id=&amp;quot;content&amp;quot; class=&amp;quot;toggle&amp;quot;&amp;gt;Paragraph to be toggled&amp;lt;/p&amp;gt;
&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/943-better-way-in-prototype-js/refactors/286469" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor286422</id>
    <published>2009-09-01T13:21:48-07:00</published>
    <title>[JavaScript] On Port Prototype Code to jQuery?</title>
    <content type="html">&lt;p&gt;The following seems to provide an improved flow to the code.&lt;/p&gt;

&lt;p&gt;The comment now seems to be superfluous, as the comment says exactly what the code does. Better comments tend to explain why things occur instead.&lt;/p&gt;

&lt;pre&gt;var total = 0;
// For each fieldpair that has a child with a checked input
// we get the sibling with a text input and add that value
// to the total.

$('.fieldpair input:checked')
    .siblings('input:text').each(function () {
        total += parseInt(this.value);
    });
&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1017-port-prototype-code-to-jquery/refactors/286422" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor286414</id>
    <published>2009-09-01T13:10:24-07:00</published>
    <title>[JavaScript] On Port Prototype Code to jQuery?</title>
    <content type="html">&lt;p&gt;The following is a working translation to jQuery, where the this keyword is the fieldpair reference.&lt;/p&gt;

&lt;p&gt;There should be a better way to do this though.&lt;/p&gt;

&lt;pre&gt;var total = 0;
// For each fieldpair that has a child with a checked input
// we get the sibling with a text input and add that value
// to the total.

$('.fieldpair').each(function () {
    if ($('input:checked', this).length) {
        var input = $('input:text', this);
        total += parseInt(input.val());
    }
});
&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1017-port-prototype-code-to-jquery/refactors/286414" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor263178</id>
    <published>2009-08-19T12:55:30-07:00</published>
    <title>[JavaScript] On jQuery traversing</title>
    <content type="html">&lt;p&gt;* Start from the content that you're going to be adding
&lt;br /&gt;* Wrap it with the list item
&lt;br /&gt;* Then append it to the roles list&lt;/p&gt;

&lt;pre&gt;$('&amp;lt;select&amp;gt;...&amp;lt;/select&amp;gt;')
    .click(function () {...})
    .wrap('&amp;lt;li&amp;gt;&amp;lt;/li&amp;gt;')
    .appendTo('ul.roles');
&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1005-jquery-traversing/refactors/263178" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor163283</id>
    <published>2009-06-14T00:08:42-07:00</published>
    <title>[JavaScript] On An incrementor function that could be better.</title>
    <content type="html">&lt;p&gt;Some good ways to refactor this is to remove the math calculations.
&lt;br /&gt;Instead of checking if value/10 &amp;lt;= 100, check that value &amp;lt;= 1000&lt;/p&gt;

&lt;p&gt;Then you can use an array that matches up the value limit with the step value.&lt;/p&gt;

&lt;p&gt;Or, you can avoid all of that and make the step value 2% of the next multiple of 10.&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/903-an-incrementor-function-that-could-be-better/refactors/163283" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor158601</id>
    <published>2009-05-21T07:32:32-07:00</published>
    <title>[JavaScript] On There must be a better way to DRY this up...</title>
    <content type="html">&lt;p&gt;Here is a way to improve things. I'm not sure though as to why you have tabContainers assigned, as it's not used in the code.&lt;/p&gt;

&lt;p&gt;Oe of course, if you want an accordion behaviour, there is one built in to jQuery. &lt;a href="http://docs.jquery.com/UI/Accordion" target="_blank"&gt;http://docs.jquery.com/UI/Accordion&lt;/a&gt;&lt;/p&gt;

&lt;pre&gt;$(document).ready(function(){
    var tabContainers = $('div.tabs &amp;gt; div');
    function hideSections() {
        $('#mym-errors').hide();
        $('#mym-errorlinks').hide();
        $('#mym-step1').hide();
        $('#mym-step2').hide();
        $('#mym-step3').hide();
    }
    if ($('#mym-errors').children().length &amp;gt; 0) {
        $('#mym-errors').fadeIn(1000);
        $('#mym-errorlinks').fadeIn(1000);
    } else {
        $('#mym-goto-step1').click(function(){
            hideSections();
            $('#mym-step1').fadeIn(1000);
        });
        $('#mym-goto-step1-errors').click(function(){
            hideSections();
            $('#mym-step1').fadeIn(1000);
        });
        $('#mym-goto-step2').click(function(){
            hideSections();
            $('#mym-step2').fadeIn(1000);
        });
        $('#mym-goto-step3').click(function(){
            hideSections();
            $('#mym-step3').fadeIn(1500);
        });
        $('#mym-gobackto-step2').click(function(){
            hideSections();
            $('#mym-step2').fadeIn(1000);
        });
        $('#mym-startbut').click(function(){
            hideSections();
            $('#mym-step1').fadeIn(1000);
        });
        $('.togglehud').click(function(){
            $('#hud').slideToggle(250);
        });
    }
});&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/876-there-must-be-a-better-way-to-dry-this-up/refactors/158601" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor158163</id>
    <published>2009-05-18T06:58:14-07:00</published>
    <title>[JavaScript] On There must be a better way to DRY this up...</title>
    <content type="html">&lt;p&gt;You could use a function that hides all of the relevant elements.
&lt;br /&gt;Then after calling that function, you just need to show the one that you're needing.&lt;/p&gt;

&lt;pre&gt;&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/876-there-must-be-a-better-way-to-dry-this-up/refactors/158163" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Refactor155069</id>
    <published>2009-04-15T07:13:36-07:00</published>
    <title>[JavaScript] On META tag info</title>
    <content type="html">&lt;p&gt;Double quotes are the more correct ones to use for HTML and XHTML code.&lt;/p&gt;

&lt;p&gt;A space needs to exist before the closing slash, to ensure that Internet Explorer, which cannot interpret XHTML, is capable of understanding the code as HTML.
&lt;br /&gt;See: &lt;a href="http://www.w3.org/TR/xhtml1/#guidelines" target="_blank"&gt;http://www.w3.org/TR/xhtml1/#guidelines&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's also best for the attributes with greater entropy to be listed first.
&lt;/p&gt;

&lt;pre&gt;&amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; content=&amp;quot;text/html; charset=utf-8&amp;quot; /&amp;gt;
&amp;lt;meta name=&amp;quot;keywords&amp;quot; content=&amp;quot;&amp;quot; /&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>paul.wilkins.myopenid.com</name>
      <email>paul.m.wilkins@gmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/823-test-script/refactors/155069" rel="alternate"/>
  </entry>
</feed>

