dcsimg
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,589
    Please ask in the Javascript frameworks forum...
    If your post falls off the page, bump it. ...
    Please remember to wrap any code you have in forum tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  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