Created
August 1, 2016 20:39
-
-
Save WilCF/75d391505313d5539b617b78385793b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(['jquery-noconflict'], function(jQuery) { | |
//Ensure MooTools is where it must be | |
Window.implement('$', function(el, nc){ | |
return document.id(el, nc, this.document); | |
}); | |
var $ = window.jQuery; | |
// a function to randomize cml elements on page | |
// one caveat: if there are other (non-cml) elements on the page, they will | |
// always float to the top. keeping non-cml elements between cml elements | |
// requires more complex code | |
$('.cml.jsawesome').each(function(){ | |
var unit = $(this); | |
var all_cmls = unit.find('.cml_field'); | |
//randomize cmls | |
all_cmls.sort(function() { return (Math.round(Math.random())-0.5); }); | |
// append question numbers to cml labels | |
all_cmls.each(function(index, elem) { | |
var label = $(elem).find('.legend').html(); | |
var q_num = index+1; | |
label = q_num + '. ' + label; | |
$(elem).find('.legend').html(label); | |
}); | |
// remove everything | |
unit.remove('.cml_field'); | |
// add randomized cml elements | |
for(var i=0; i < all_cmls.length; i++) { | |
unit.append(all_cmls[i]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment