User:Ehkano/sandbox

/* * jQuery Impromptu * By: Trent Richardson * Version 2.8 * Last Modified: 2/3/2010 * * Copyright 2010 Trent Richardson * Dual licensed under the MIT and GPL licenses. * http://trentrichardson.com/Impromptu/GPL-LICENSE.txt * http://trentrichardson.com/Impromptu/MIT-LICENSE.txt * */ (function($){$.prompt=function(message,options){options=$.extend({},$.prompt.defaults,options);$.prompt.currentPrefix=options.prefix;var ie6=($.browser.msie&&$.browser.version<7);var $body=$(document.body);var $window=$(window);var msgbox='';if(options.useiframe&&(($('object, applet').length>0)||ie6)){msgbox+=' ';}else{if(ie6){$('select').css('visibility','hidden');}msgbox+=' ';}msgbox+='X  ';msgbox+='   ';var $jqib=$(msgbox).appendTo($body);var $jqi=$jqib.children('#'+options.prefix);var $jqif=$jqib.children('#'+options.prefix+'fade');if(message.constructor==String){message={state0:{html:message,buttons:options.buttons,focus:options.focus,submit:options.submit}};}var states="";$.each(message,function(statename,stateobj){stateobj=$.extend({},$.prompt.defaults.state,stateobj);message[statename]=stateobj;states+=''+stateobj.html+' ';$.each(stateobj.buttons,function(k,v){states+=''+k+' ';});states+='  ';});$jqi.find('#'+options.prefix+'states').html(states).children('.'+options.prefix+'_state:first').css('display','block');$jqi.find('.'+options.prefix+'buttons:empty').css('display','none');$.each(message,function(statename,stateobj){var $state=$jqi.find('#'+options.prefix+'_state_'+statename);$state.children('.'+options.prefix+'buttons').children('button').click(function{var msg=$state.children('.'+options.prefix+'message');var clicked=stateobj.buttons[$(this).text];var forminputs={};$.each($jqi.find('#'+options.prefix+'states :input').serializeArray,function(i,obj){if(forminputs[obj.name]===undefined){forminputs[obj.name]=obj.value;}else if(typeof forminputs[obj.name]==Array||typeof forminputs[obj.name]=='object'){forminputs[obj.name].push(obj.value);}else{forminputs[obj.name]=[forminputs[obj.name],obj.value];}});var close=stateobj.submit(clicked,msg,forminputs);if(close===undefined||close){removePrompt(true,clicked,msg,forminputs);}});$state.find('.'+options.prefix+'buttons button:eq('+stateobj.focus+')').addClass(options.prefix+'defaultbutton');});var ie6scroll=function{$jqib.css({top:$window.scrollTop});};var fadeClicked=function{if(options.persistent){var i=0;$jqib.addClass(options.prefix+'warning');var intervalid=setInterval(function{$jqib.toggleClass(options.prefix+'warning');if(i++>1){clearInterval(intervalid);$jqib.removeClass(options.prefix+'warning');}},100);}else{removePrompt;}};var keyPressEventHandler=function(e){var key=(window.event)?event.keyCode:e.keyCode;if(key==27){fadeClicked;}if(key==9){var $inputels=$(':input:enabled:visible',$jqib);var fwd=!e.shiftKey&&e.target==$inputels[$inputels.length-1];var back=e.shiftKey&&e.target==$inputels[0];if(fwd||back){setTimeout(function{if(!$inputels)return;var el=$inputels[back===true?$inputels.length-1:0];if(el)el.focus;},10);return false;}}};var positionPrompt=function{$jqib.css({position:(ie6)?"absolute":"fixed",height:$window.height,width:"100%",top:(ie6)?$window.scrollTop:0,left:0,right:0,bottom:0});$jqif.css({position:"absolute",height:$window.height,width:"100%",top:0,left:0,right:0,bottom:0});$jqi.css({position:"absolute",top:options.top,left:"50%",marginLeft:(($jqi.outerWidth/2)*-1)});};var stylePrompt=function{$jqif.css({zIndex:options.zIndex,display:"none",opacity:options.opacity});$jqi.css({zIndex:options.zIndex+1,display:"none"});$jqib.css({zIndex:options.zIndex});};var removePrompt=function(callCallback,clicked,msg,formvals){$jqi.remove;if(ie6){$body.unbind('scroll',ie6scroll);}$window.unbind('resize',positionPrompt);$jqif.fadeOut(options.overlayspeed,function{$jqif.unbind('click',fadeClicked);$jqif.remove;if(callCallback){options.callback(clicked,msg,formvals);}$jqib.unbind('keypress',keyPressEventHandler);$jqib.remove;if(ie6&&!options.useiframe){$('select').css('visibility','visible');}});};positionPrompt;stylePrompt;if(ie6){$window.scroll(ie6scroll);}$jqif.click(fadeClicked);$window.resize(positionPrompt);$jqib.bind("keydown keypress",keyPressEventHandler);$jqi.find('.'+options.prefix+'close').click(removePrompt);$jqif.fadeIn(options.overlayspeed);$jqi[options.show](options.promptspeed,options.loaded);$jqi.find('#'+options.prefix+'states .'+options.prefix+'_state:first .'+options.prefix+'defaultbutton').focus;if(options.timeout>0)setTimeout($.prompt.close,options.timeout);return $jqib;};$.prompt.defaults={prefix:'jqi',buttons:{Ok:true},loaded:function{},submit:function{return true;},callback:function{},opacity:0.6,zIndex:999,overlayspeed:'slow',promptspeed:'fast',show:'fadeIn',focus:0,useiframe:false,top:"15%",persistent:true,timeout:0,state:{html:,buttons:{Ok:true},focus:0,submit:function{return true;}}};$.prompt.currentPrefix=$.prompt.defaults.prefix;$.prompt.setDefaults=function(o){$.prompt.defaults=$.extend({},$.prompt.defaults,o);};$.prompt.setStateDefaults=function(o){$.prompt.defaults.state=$.extend({},$.prompt.defaults.state,o);};$.prompt.getStateContent=function(state){return $('#'+$.prompt.currentPrefix+'_state_'+state);};$.prompt.getCurrentState=function{return $('.'+$.prompt.currentPrefix+'_state:visible');};$.prompt.getCurrentStateName=function{var stateid=$.prompt.getCurrentState.attr('id');return stateid.replace($.prompt.currentPrefix+'_state_',);};$.prompt.goToState=function(state){$('.'+$.prompt.currentPrefix+'_state').slideUp('slow');$('#'+$.prompt.currentPrefix+'_state_'+state).slideDown('slow',function{$(this).find('.'+$.prompt.currentPrefix+'defaultbutton').focus;});};$.prompt.nextState=function{var $next=$('.'+$.prompt.currentPrefix+'_state:visible').next;$('.'+$.prompt.currentPrefix+'_state').slideUp('slow');$next.slideDown('slow',function{$next.find('.'+$.prompt.currentPrefix+'defaultbutton').focus;});};$.prompt.prevState=function{var $next=$('.'+$.prompt.currentPrefix+'_state:visible').prev;$('.'+$.prompt.currentPrefix+'_state').slideUp('slow');$next.slideDown('slow',function{$next.find('.'+$.prompt.currentPrefix+'defaultbutton').focus;});};$.prompt.close=function{$('#'+$.prompt.currentPrefix+'box').fadeOut('fast',function{$(this).remove;});};})(jQuery);

// HideMe v0.3.1 // Elements in the class "hideme" will be affected by this code. // Correctly done formatting and other HTML will not break the code, but do NOT use any uninitialized or  tags, or the result will be very, very strange. // As with other content on this wiki, this is licensed under the CC-BY-SA.

// Note to code-copiers here: You're welcome to copy this and play around with it, but you'll need the above library (the long gibberish) in order for this to operate.

// Changelog: // v0.1 -> v0.2: Feb 3, 2010: OOP conversion to clean up variable mess // v0.2 -> v0.3: Feb 11, 2010: jQuery Impromptu installed and implemented to produce smoother interface // v0.3 -> v0.3.1: Feb 12, 2010: Allow disabling HideMe via hideme.enabled = false in personal JS.

var hideme = { enabled: true, idtxt: {}, msgs: { hiddenLinkText: "Click Me", messageQuestion: "The following may be the best thing you ever saw. Are you ready?", messageShown: "Here you go." },   init: function { $(".hideme").each(function(i){           hideme.idtxt[i] = $(this).html;            $(this).attr("id","hideme" + i);            $(this).html('[' + hideme.msgs.hiddenLinkText + ']');        }); $.prompt.setStateDefaults({           persistent: false        }); $(".hideme_link").live("click",function(e){           e.preventDefault;            var index = parseInt($(this).parent.attr("id").substr(6),10);            $.prompt({ state0: { html: hideme.msgs.messageQuestion, buttons: {Yes: true, No: false}, focus: 1, submit: function(v,m,f) { if (!v) {return true;} else {$.prompt.goToState('state1');} return false; }               },                state1: { html: hideme.msgs.messageShown + ' ' + hideme.idtxt[index] + ' ', buttons: {OK: true}, }           });        });    } };

$(function{   if (hideme.enabled) {        hideme.init;    } });