UNPKG

ielevator

Version:

ielevator is quite useful for simulating elevator.

1 lines 5.08 kB
(function(a,b){if(typeof define==="function"&&define.amd){define(["jquery"],b)}else{if(typeof exports==="object"){module.exports=b(require("jquery"))}else{a.Requester=b(a.$)}}}(this,function(c){function b(g,i,m){var l,f,k,n;var j=0;if(!m){m={}}var h=function(){j=m.leading===false?0:Number(new Date());l=null;n=g.apply(f,k);if(!l){f=k=null}};var e=function(){var o=Number(new Date());if(!j&&m.leading===false){j=o}var p=i-(o-j);f=this;k=arguments;if(p<=0||p>i){if(l){clearTimeout(l);l=null}j=o;n=g.apply(f,k);if(!l){f=k=null}}else{if(!l&&m.trailing!==false){l=setTimeout(h,p)}}return n};e.cancel=function(){clearTimeout(l);j=0;l=f=k=null};return e}if(typeof Array.prototype.indexOf!=="function"){Array.prototype.indexOf=function(f){for(var e=this.length-1;e>=0;e--){if(this[e]===f){return e}}}}function d(f){var e=document.createElement("b");e.innerHTML="<!--[if IE "+f+"]><i></i><![endif]-->";return e.getElementsByTagName("i").length===1}function a(e,f){this.element=c(f);this.namespace="iElevator";var h={floors:null,btns:null,backtop:null,selected:"",sticky:-1,visible:{isHide:"no",numShow:0},speed:400,show:function(i){i.element.show()},hide:function(i){i.element.hide()}},g=this.element.data("ielevator-options")||{};this.settings=c.extend({},h,e,g);this.init(e)}a.prototype=(function(){var j=[],m,i;var n=function(A){var z=r.call(this,"visible"),y=z.isHide.toLowerCase(),x=c(window).scrollTop(),B=z.numShow||0;if(y==="yes"){if(x<B){p.call(this)}else{g.call(this)}}n=function(C){if(C>=B){g.call(this)}else{p.call(this)}}},t=(function(){if(d(6)){c("html").css({backgroundImage:"url(about:blank)",backgroundAttachment:"fixed"});return function(y,x){if(this.element[0].currentStyle.position==="fixed"){this.element.css("position","absolute")}this.element.css("top",parseInt(y,10)+x+"px");t=function(A,z){this.element.css("top",parseInt(A,10)+z+"px")}}}})();function l(x){var y={floors:("floors" in x),btns:("btns" in x),backtop:("backtop" in x)};if(y.floors){this.floors=r.call(this,"floors");this.floors.each(function(){j.push(c(this).offset().top|0)});this.btns=y.btns?r.call(this,"btns"):null}if(y.backtop){this.backtop=r.call(this,"backtop")}if(this.btns){if(this.backtop){i=this.btns.add(this.backtop)}else{i=this.btns}}else{i=this.backtop}m=j.slice();m.push(0);if(!(y.floors&&y.btns&&y.backtop)&&!(y.floors&&y.btns)&&!(y.backtop)){c.error('you provide at least one of "cBacktop" , "cFloors + cBtns" or "cFloors + cBtns + cBacktop"')}}function h(A){var x=document.createElement("style"),y=document.getElementsByTagName("head")[0];x.type="text/css";try{x.appendChild(document.createTextNode(A))}catch(z){x.styleSheet.cssText=A}y.appendChild(x);return x}var e=function(B){var x=+r.call(this,"sticky"),A=this.element.offset().top,z=c(window).scrollTop(),y=".fixed{position: fixed; top: "+x+"px;}";if(x<0){return}h(y);if(z-x>A){this.element.addClass("fixed")}else{this.element.removeClass("fixed")}e=function(C){if(C+x>A){this.element.addClass("fixed")}else{this.element.removeClass("fixed")}}};function r(y){if(y in this.settings){var x=this.settings[y],z={cFloors:true,cBtns:true,cBacktop:true};if(!x&&z[y]){c.error('the "'+y+'" is required, not '+x)}else{return x}}else{c.error('the settings contains no such "'+y+'"option!')}}function g(){r.call(this,"show")(this)}function p(){r.call(this,"hide")(this)}function u(x){var y=parseInt(x,10),z=j.indexOf(y);if(z>-1){return z}j.push(y);j.sort(function(C,D){return C-D});z=j.indexOf(y);j.splice(z,1);return(z-1)}function f(y,x){if(y===-1){return}c("html, body").animate({scrollTop:m[y]},x)}function v(x){var y=r.call(this,"selected");i&&i.removeClass(y).eq(x).addClass(y)}function q(z){var x=r.call(this,"selected"),B,y;if(!x){return}typeof x==="string"?B=x:y=x;B&&i&&i.removeClass(B).eq(z).addClass(B);if(y){var C=i.eq(z).position().top,A=i.eq(z).height();if(z<0){return}y.css({top:C+"px",height:A+"px"})}}function w(){var x=this,z=r.call(this,"speed"),y=m.length;i.on("click."+this.namespace,function(A){var B=i.index(c(this));f.call(x,B,z)});c(window).on("scroll."+this.namespace,b(function(){var B=c(this).scrollTop();var A=u.call(x,B);t&&t.call(x,B,x.numShow);n.call(x,B);q.call(x,A);e.call(x,B)},200))}function o(){this.element.off("."+this.namespace);c(window).off("."+this.namespace)}function s(){o.call(this);c.removeData(this)}function k(x){l.call(this,x);n.call(this);w.call(this)}return{constructor:a,init:function(x){this._(k)(x)},destory:function(){this._(s)()},getSettings:function(x){return this._(r)(x)},_:function(y){var x=this;return function(){return y.apply(x,arguments)}}}})();c.fn.ielevator=function(f){var h="ielevatorPlugin",e,g;if(typeof f==="string"){e=Array.prototype.slice.call(arguments,1);this.each(function(){var i=c.data(this,h);if(!i){c.error("The plugin has not been initialised yet when you tried to call this method: "+f);return}if(!c.isFunction(i[f])){c.error("The plugin contains no such method: "+f);return}else{g=i[f].apply(i,e)}});if(g!==undefined){return g}else{return this}}else{return this.each(function(){var i=c.data(this,h);if(i){i.init(f)}else{c.data(this,h,new a(f,this))}})}}}));