Created
September 29, 2011 15:36
-
-
Save iamdustan/1251013 to your computer and use it in GitHub Desktop.
Bookmarklet: Autoslug Badge and Level Keys based on the Name in Demand Media's Pluck v1.0 CMW
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
/* | |
* Autoslug's because we'd all rather be lazy. | |
* The CMW uses Prototype. I like jQuery. | |
*/ | |
/* @Source */ | |
(function(d,t){ | |
var g=d.createElement(t),s=d.getElementsByTagName(t)[0]; | |
g.src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'; | |
s.parentNode.insertBefore(g,s); | |
(function init() { | |
if( !jQuery ) { return setTimeout(function () { init(); }, 10); } | |
jQuery.noConflict(); | |
jQuery( document ).delegate( 'input[name*="Name"]', 'keyup', function( e ) { | |
var self = jQuery(this) | |
, val = self.val() | |
, autoTuned = autoTune( val ) | |
, base = (self.attr('name').indexOf('plckBadgeLevelName_')!==-1 ) ? 'plckBadgeLevelName_' : 'plckBadge' | |
, key = self.attr('name').split( base )[1] | |
, relatedElem; | |
if( isNaN( key ) ) { | |
relatedElem = jQuery( 'input[name=' + (base+'FamilyId') + ']' ) | |
} else { | |
relatedElem = jQuery( 'input[name=' + ('plckBadgeLevelKey_'+key) + ']' ) | |
} | |
function autoTune( txt ) { | |
txt = txt.replace( / /g, '-' ).replace( /.,[\][&!?*:;\/\\'"]/g, '' ); | |
return txt.toLowerCase(); | |
}; | |
relatedElem.val( autoTune( val ) ); | |
}); | |
})(); | |
})(document,'script'); | |
/* @Bookmarklet */ | |
javascript:(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js';s.parentNode.insertBefore(g,s);(function init(){if(!jQuery){return setTimeout(function(){init();},10);}jQuery.noConflict();jQuery(document).delegate('input[name*="Name"]','keyup',function(e){var self=jQuery(this),val=self.val(),autoTuned=autoTune(val),base=(self.attr('name').indexOf('plckBadgeLevelName_')!==-1)?'plckBadgeLevelName_':'plckBadge',key=self.attr('name').split(base)[1],relatedElem;if(isNaN(key)){relatedElem=jQuery('input[name='+(base+'FamilyId')+']')}else{relatedElem=jQuery('input[name='+('plckBadgeLevelKey_'+key)+']')}function autoTune(txt){txt=txt.replace(/ /g,'-').replace(/[\][&!?*:;\/\\'"]/g,'');return txt.toLowerCase();};relatedElem.val(autoTune(val));});})();})(document,'script'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment