Skip to content

Instantly share code, notes, and snippets.

@iamdustan
Created September 29, 2011 15:36
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 iamdustan/1251013 to your computer and use it in GitHub Desktop.
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
/*
* 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