Skip to content

Instantly share code, notes, and snippets.

@WilCF
Created August 1, 2016 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WilCF/75d391505313d5539b617b78385793b0 to your computer and use it in GitHub Desktop.
Save WilCF/75d391505313d5539b617b78385793b0 to your computer and use it in GitHub Desktop.
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