www.webdeveloper.com
Results 1 to 3 of 3

Thread: Converting a script to use with jQuery instead of MooTools

Hybrid View

  1. #1
    Join Date
    Jul 2012
    Posts
    7

    Converting a script to use with jQuery instead of MooTools

    Would anyone be able to tell me how to go about this..? The script I'm looking to convert is this:

    Code:
    <script type="text/javascript">
    // sort all divs with classname 'sortitem' by html content
    function sort_div_content() {
    	//thanks to Thomas Sturm for this lovely little piece of javascript
    	// copy all divs into array and destroy them in the page
    	divsbucket = new Array();
    	divslist = $$('div.sortitem');
    	for (a=0;a<divslist.length;a++) {
    		divsbucket[a] = divslist[a].dispose();
    	}
    
    	// sort array by HTML content of divs
    	divsbucket.sort(function(a, b) {
    		if (a.innerHTML.toLowerCase() === b.innerHTML.toLowerCase()) {
    			return 0;
    		}
    		if (a.innerHTML.toLowerCase() > b.innerHTML.toLowerCase()) {
    			return 1;
    		} else {
    			return -1;
    		}
    	});
    
    	// re-inject sorted divs into page
    	for (a=0;a<divslist.length;a++) {
    		divsbucket[a].inject($('Shelf'));
    	}
    }
    
    // sort by attributes - usage for our example: sort_div_attribute('sortweight');
    function sort_div_attribute(attname) {
    	// copy all divs into array and destroy them in the page
    	divsbucket = new Array();
    	divslist = $$('div.sortitem');
    	for (a=0;a<divslist.length;a++) {
    		divsbucket[a] = new Array();
    		// we'vev passed in the name of the attribute to sort by
    		divsbucket[a][0] = divslist[a].get(attname);
    		divsbucket[a][1] = divslist[a].dispose();
    	}
    
    	// sort array by sort attribute content
    	divsbucket.sort(function(a, b) {
    		if (a[0].toLowerCase() === b[0].toLowerCase()) {
    			return 0;
    		}
    		if (a[0].toLowerCase() > b[0].toLowerCase()) {
    			return 1;
    		} else {
    			return -1;
    		}
    	});
    
    	// re-inject sorted divs into page
    	for (a=0;a<divslist.length;a++) {
    		divsbucket[a][1].inject($('Shelf'));
    	}
    }
    </script>
    The provider of the script seemed to imply it should be fairly easy to amend but in all honesty I have no idea how to...

    Any replies would be much appreciated!!

    Max

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,344
    Please ask in the Javascript frameworks forum...
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  3. #3
    Join Date
    Jul 2012
    Posts
    7
    sorry!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles