jiti-meet/libs/jquery-impromptu.min.js

2 lines
13 KiB
JavaScript

(function(root,factory){if(typeof define==="function"&&define.amd){define(["jquery"],factory)}else{factory(root.jQuery)}})(this,function($){"use strict";var Imp=function(message,options){var t=this;t.id=Imp.count++;Imp.lifo.push(t);if(message){t.open(message,options)}return t};Imp.defaults={prefix:"jqi",classes:{box:"",fade:"",prompt:"",form:"",close:"",title:"",message:"",buttons:"",button:"",defaultButton:""},title:"",closeText:"&times;",buttons:{Ok:true},loaded:function(e){},submit:function(e,v,m,f){},close:function(e,v,m,f){},statechanging:function(e,from,to){},statechanged:function(e,to){},opacity:.6,zIndex:999,overlayspeed:"slow",promptspeed:"fast",show:"fadeIn",hide:"fadeOut",focus:0,defaultButton:0,useiframe:false,top:"15%",position:{container:null,x:null,y:null,arrow:null,width:null},persistent:true,timeout:0,states:{},state:{name:null,title:"",html:"",buttons:{Ok:true},focus:0,defaultButton:0,position:{container:null,x:null,y:null,arrow:null,width:null},submit:function(e,v,m,f){return true}}};Imp.setDefaults=function(o){Imp.defaults=$.extend({},Imp.defaults,o)};Imp.setStateDefaults=function(o){Imp.defaults.state=$.extend({},Imp.defaults.state,o)};Imp.count=0;Imp.lifo=[];Imp.getLast=function(){var l=Imp.lifo.length;return l>0?Imp.lifo[l-1]:false};Imp.removeFromStack=function(id){for(var i=Imp.lifo.length-1;i>=0;i--){if(Imp.lifo[i].id===id){return Imp.lifo.splice(i,1)[0]}}};Imp.prototype={id:null,open:function(message,options){var t=this;t.options=$.extend({},Imp.defaults,options);if(t.timeout){clearTimeout(t.timeout)}t.timeout=false;var opts=t.options,$body=$(document.body),$window=$(window);var msgbox='<div class="'+opts.prefix+"box "+opts.classes.box+'">';if(opts.useiframe&&$("object, applet").length>0){msgbox+='<iframe src="javascript:false;" style="display:block;position:absolute;z-index:-1;" class="'+opts.prefix+"fade "+opts.classes.fade+'"></iframe>'}else{msgbox+='<div class="'+opts.prefix+"fade "+opts.classes.fade+'"></div>'}msgbox+='<div class="'+opts.prefix+" "+opts.classes.prompt+'">'+'<form action="javascript:false;" onsubmit="return false;" class="'+opts.prefix+"form "+opts.classes.form+'">'+'<div class="'+opts.prefix+"close "+opts.classes.close+'">'+opts.closeText+"</div>"+'<div class="'+opts.prefix+'states"></div>'+"</form>"+"</div>"+"</div>";t.jqib=$(msgbox).appendTo($body);t.jqi=t.jqib.children("."+opts.prefix);t.jqif=t.jqib.children("."+opts.prefix+"fade");if(message.constructor===String){message={state0:{title:opts.title,html:message,buttons:opts.buttons,position:opts.position,focus:opts.focus,defaultButton:opts.defaultButton,submit:opts.submit}}}t.options.states={};var k,v;for(k in message){v=$.extend({},Imp.defaults.state,{name:k},message[k]);t.addState(v.name,v);if(t.currentStateName===""){t.currentStateName=v.name}}t.jqi.on("click","."+opts.prefix+"buttons button",function(e){var $t=$(this),$state=$t.parents("."+opts.prefix+"state"),stateobj=t.options.states[$state.data("jqi-name")],msg=$state.children("."+opts.prefix+"message"),clicked=stateobj.buttons[$t.text()]||stateobj.buttons[$t.html()],forminputs={};if(clicked===undefined){for(var i in stateobj.buttons){if(stateobj.buttons[i].title===$t.text()||stateobj.buttons[i].title===$t.html()){clicked=stateobj.buttons[i].value}}}$.each(t.jqi.children("form").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 promptsubmite=new $.Event("impromptu:submit");promptsubmite.stateName=stateobj.name;promptsubmite.state=$state;$state.trigger(promptsubmite,[clicked,msg,forminputs]);if(!promptsubmite.isDefaultPrevented()){t.close(true,clicked,msg,forminputs)}});var fadeClicked=function(){if(opts.persistent){var offset=opts.top.toString().indexOf("%")>=0?$window.height()*(parseInt(opts.top,10)/100):parseInt(opts.top,10),top=parseInt(t.jqi.css("top").replace("px",""),10)-offset;$("html,body").animate({scrollTop:top},"fast",function(){var i=0;t.jqib.addClass(opts.prefix+"warning");var intervalid=setInterval(function(){t.jqib.toggleClass(opts.prefix+"warning");if(i++>1){clearInterval(intervalid);t.jqib.removeClass(opts.prefix+"warning")}},100)})}else{t.close(true)}};var keyDownEventHandler=function(e){var key=window.event?event.keyCode:e.keyCode;if(key===27){fadeClicked()}if(key===13){var $defBtn=t.getCurrentState().find("."+opts.prefix+"defaultbutton");var $tgt=$(e.target);if($tgt.is("textarea,."+opts.prefix+"button")===false&&$defBtn.length>0){e.preventDefault();$defBtn.click()}}if(key===9){var $inputels=$("input,select,textarea,button",t.getCurrentState());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}}};t.position();t.style();t._windowResize=function(e){t.position(e)};$window.resize({animate:false},t._windowResize);t.jqif.click(fadeClicked);t.jqi.find("."+opts.prefix+"close").click(function(){t.close()});t.jqib.on("keydown",keyDownEventHandler).on("impromptu:loaded",opts.loaded).on("impromptu:close",opts.close).on("impromptu:statechanging",opts.statechanging).on("impromptu:statechanged",opts.statechanged);t.jqif[opts.show](opts.overlayspeed);t.jqi[opts.show](opts.promptspeed,function(){var $firstState=t.jqi.find("."+opts.prefix+"states ."+opts.prefix+"state").eq(0);t.goToState($firstState.data("jqi-name"));t.jqib.trigger("impromptu:loaded")});if(opts.timeout>0){t.timeout=setTimeout(function(){t.close(true)},opts.timeout)}return t},close:function(callCallback,clicked,msg,formvals){var t=this;Imp.removeFromStack(t.id);if(t.timeout){clearTimeout(t.timeout);t.timeout=false}if(t.jqib){t.jqib[t.options.hide]("fast",function(){t.jqib.trigger("impromptu:close",[clicked,msg,formvals]);t.jqib.remove();$(window).off("resize",t._windowResize);if(typeof callCallback==="function"){callCallback()}})}t.currentStateName="";return t},addState:function(statename,stateobj,afterState){var t=this,state="",$state=null,arrow="",title="",opts=t.options,$jqistates=$("."+opts.prefix+"states"),buttons=[],showHtml,defbtn,k,v,l,i=0;stateobj=$.extend({},Imp.defaults.state,{name:statename},stateobj);if(stateobj.position.arrow!==null){arrow='<div class="'+opts.prefix+"arrow "+opts.prefix+"arrow"+stateobj.position.arrow+'"></div>'}if(stateobj.title&&stateobj.title!==""){title='<div class="lead '+opts.prefix+"title "+opts.classes.title+'">'+stateobj.title+"</div>"}showHtml=stateobj.html;if(typeof stateobj.html==="function"){showHtml="Error: html function must return text"}state+='<div class="'+opts.prefix+'state" data-jqi-name="'+statename+'" style="display:none;">'+arrow+title+'<div class="'+opts.prefix+"message "+opts.classes.message+'">'+showHtml+"</div>"+'<div class="'+opts.prefix+"buttons "+opts.classes.buttons+'"'+($.isEmptyObject(stateobj.buttons)?'style="display:none;"':"")+">";if($.isArray(stateobj.buttons)){buttons=stateobj.buttons}else if($.isPlainObject(stateobj.buttons)){for(k in stateobj.buttons){if(stateobj.buttons.hasOwnProperty(k)){buttons.push({title:k,value:stateobj.buttons[k]})}}}for(i=0,l=buttons.length;i<l;i++){v=buttons[i],defbtn=stateobj.focus===i||isNaN(stateobj.focus)&&stateobj.defaultButton===i?opts.prefix+"defaultbutton "+opts.classes.defaultButton:"";state+='<button class="'+opts.classes.button+" "+opts.prefix+"button "+defbtn;if(typeof v.classes!=="undefined"){state+=" "+($.isArray(v.classes)?v.classes.join(" "):v.classes)+" "}state+='" name="'+opts.prefix+"_"+statename+"_button"+v.title.replace(/[^a-z0-9]+/gi,"")+'" value="'+v.value+'">'+v.title+"</button>"}state+="</div></div>";$state=$(state);$state.on("impromptu:submit",stateobj.submit);if(afterState!==undefined){$jqistates.find('[data-jqi-name="'+afterState+'"]').after($state)}else{$jqistates.append($state)}t.options.states[statename]=stateobj;return $state},removeState:function(state,newState){var t=this,$state=t.getState(state),rm=function(){$state.remove()};if($state.length===0){return false}if($state.css("display")!=="none"){if(newState!==undefined&&t.getState(newState).length>0){t.goToState(newState,false,rm)}else if($state.next().length>0){t.nextState(rm)}else if($state.prev().length>0){t.prevState(rm)}else{t.close()}}else{$state.slideUp("slow",rm)}return true},getApi:function(){return this},getBox:function(){return this.jqib},getPrompt:function(){return this.jqi},getState:function(statename){return this.jqi.find('[data-jqi-name="'+statename+'"]')},getCurrentState:function(){return this.getState(this.getCurrentStateName())},getCurrentStateName:function(){return this.currentStateName},position:function(e){var t=this,restoreFx=$.fx.off,$state=t.getCurrentState(),stateObj=t.options.states[$state.data("jqi-name")],pos=stateObj?stateObj.position:undefined,$window=$(window),bodyHeight=document.body.scrollHeight,windowHeight=$(window).height(),documentHeight=$(document).height(),height=bodyHeight>windowHeight?bodyHeight:windowHeight,top=parseInt($window.scrollTop(),10)+(t.options.top.toString().indexOf("%")>=0?windowHeight*(parseInt(t.options.top,10)/100):parseInt(t.options.top,10));if(e!==undefined&&e.data.animate===false){$.fx.off=true}t.jqib.css({position:"absolute",height:height,width:"100%",top:0,left:0,right:0,bottom:0});t.jqif.css({position:"fixed",height:height,width:"100%",top:0,left:0,right:0,bottom:0});if(pos&&pos.container){var offset=$(pos.container).offset();if($.isPlainObject(offset)&&offset.top!==undefined){t.jqi.css({position:"absolute"});t.jqi.animate({top:offset.top+pos.y,left:offset.left+pos.x,marginLeft:0,width:pos.width!==undefined?pos.width:null});top=offset.top+pos.y-(t.options.top.toString().indexOf("%")>=0?windowHeight*(parseInt(t.options.top,10)/100):parseInt(t.options.top,10));$("html,body").animate({scrollTop:top},"slow","swing",function(){})}}else if(pos&&pos.width){t.jqi.css({position:"absolute",left:"50%"});t.jqi.animate({top:pos.y||top,left:pos.x||"50%",marginLeft:pos.width/2*-1,width:pos.width})}else{t.jqi.css({position:"absolute",top:top,left:"50%",marginLeft:t.jqi.outerWidth(false)/2*-1})}if(e!==undefined&&e.data.animate===false){$.fx.off=restoreFx}},style:function(){var t=this;t.jqif.css({zIndex:t.options.zIndex,display:"none",opacity:t.options.opacity});t.jqi.css({zIndex:t.options.zIndex+1,display:"none"});t.jqib.css({zIndex:t.options.zIndex})},goToState:function(state,subState,callback){var t=this,$jqi=t.jqi,jqiopts=t.options,$state=t.getState(state),stateobj=jqiopts.states[$state.data("jqi-name")],promptstatechanginge=new $.Event("impromptu:statechanging"),opts=t.options;if(stateobj!==undefined){if(typeof stateobj.html==="function"){var contentLaterFunc=stateobj.html;$state.find("."+opts.prefix+"message ").html(contentLaterFunc())}if(typeof subState==="function"){callback=subState;subState=false}t.jqib.trigger(promptstatechanginge,[t.getCurrentStateName(),state]);if(!promptstatechanginge.isDefaultPrevented()&&$state.length>0){t.jqi.find("."+opts.prefix+"parentstate").removeClass(opts.prefix+"parentstate");if(subState){t.jqi.find("."+opts.prefix+"substate").not($state).slideUp(jqiopts.promptspeed).removeClass("."+opts.prefix+"substate").find("."+opts.prefix+"arrow").hide();t.jqi.find("."+opts.prefix+"state:visible").addClass(opts.prefix+"parentstate");$state.addClass(opts.prefix+"substate")}else{t.jqi.find("."+opts.prefix+"state").not($state).slideUp(jqiopts.promptspeed).find("."+opts.prefix+"arrow").hide()}t.currentStateName=stateobj.name;$state.slideDown(jqiopts.promptspeed,function(){var $t=$(this);if(typeof stateobj.focus==="string"){$t.find(stateobj.focus).eq(0).focus()}else{$t.find("."+opts.prefix+"defaultbutton").focus()}$t.find("."+opts.prefix+"arrow").show(jqiopts.promptspeed);if(typeof callback==="function"){t.jqib.on("impromptu:statechanged",callback)}t.jqib.trigger("impromptu:statechanged",[state]);if(typeof callback==="function"){t.jqib.off("impromptu:statechanged",callback)}});if(!subState){t.position()}}}return $state},nextState:function(callback){var t=this,$next=t.getCurrentState().next();if($next.length>0){t.goToState($next.data("jqi-name"),callback)}return $next},prevState:function(callback){var t=this,$prev=t.getCurrentState().prev();if($prev.length>0){t.goToState($prev.data("jqi-name"),callback)}return $prev}};$.prompt=function(message,options){var api=new Imp(message,options);return api.jqi};$.each(Imp,function(k,v){$.prompt[k]=v});$.each(Imp.prototype,function(k,v){$.prompt[k]=function(){var api=Imp.getLast();if(api&&typeof api[k]==="function"){return api[k].apply(api,arguments)}}});$.fn.prompt=function(options){if(options===undefined){options={}}if(options.withDataAndEvents===undefined){options.withDataAndEvents=false}$.prompt($(this).clone(options.withDataAndEvents).html(),options)};window.Impromptu=Imp});
//# sourceMappingURL=jquery-impromptu.min.map