You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1 lines
5.1 KiB

!function(a,b,c,d){a.fn.nag=function(c){var e,f=a(this),g=a.extend(!0,{},a.fn.nag.settings,c),h="."+g.namespace,i=g.namespace+"-module",j=f.selector||"",k=(new Date).getTime(),l=[],m=arguments[0],n="string"==typeof m,o=[].slice.call(arguments,1);return a(this).each(function(){var c,f,p,q,r,s,t,u,v,w=a(this),x=w.find(g.selector.close),y=a(g.context),z=this,A=w.data(i),B=g.className,C=g.errors,D=b.requestAnimationFrame||b.mozRequestAnimationFrame||b.webkitRequestAnimationFrame||b.msRequestAnimationFrame||function(a){setTimeout(a,0)};v={initialize:function(){v.verbose("Initializing element"),c=w.offset(),f=w.outerHeight(),p=y.outerWidth(),q=y.outerHeight(),r=y.offset(),w.data(i,v),x.on("click"+h,v.dismiss),g.context==b&&"fixed"==g.position&&w.addClass(B.fixed),g.sticky&&(v.verbose("Adding scroll events"),"absolute"==g.position?y.on("scroll"+h,v.event.scroll).on("resize"+h,v.event.scroll):a(b).on("scroll"+h,v.event.scroll).on("resize"+h,v.event.scroll),a.proxy(v.event.scroll,this)()),g.displayTime>0&&setTimeout(v.hide,g.displayTime),v.should.show()?w.is(":visible")||v.show():v.hide()},destroy:function(){v.verbose("Destroying instance"),w.removeData(i).off(h),g.sticky&&y.off(h)},refresh:function(){v.debug("Refreshing cached calculations"),c=w.offset(),f=w.outerHeight(),p=y.outerWidth(),q=y.outerHeight(),r=y.offset()},show:function(){v.debug("Showing nag",g.animation.show),"fade"==g.animation.show?w.fadeIn(g.duration,g.easing):w.slideDown(g.duration,g.easing)},hide:function(){v.debug("Showing nag",g.animation.hide),"fade"==g.animation.show?w.fadeIn(g.duration,g.easing):w.slideUp(g.duration,g.easing)},onHide:function(){v.debug("Removing nag",g.animation.hide),w.remove(),g.onHide&&g.onHide()},stick:function(){if(v.refresh(),"fixed"==g.position){var c=a(b).prop("pageYOffset")||a(b).scrollTop(),d=w.hasClass(B.bottom)?r.top+(q-f)-c:r.top-c;w.css({position:"fixed",top:d,left:r.left,width:p-g.scrollBarWidth})}else w.css({top:t})},unStick:function(){w.css({top:""})},dismiss:function(a){g.storageMethod&&v.storage.set(g.storedKey,g.storedValue),v.hide(),a.stopImmediatePropagation(),a.preventDefault()},should:{show:function(){return g.persist?(v.debug("Persistent nag is set, can show nag"),!0):v.storage.get(g.storedKey)!=g.storedValue?(v.debug("Stored value is not set, can show nag",v.storage.get(g.storedKey)),!0):(v.debug("Stored value is set, cannot show nag",v.storage.get(g.storedKey)),!1)},stick:function(){return s=y.prop("pageYOffset")||y.scrollTop(),t=w.hasClass(B.bottom)?q-w.outerHeight()+s:s,t>c.top?!0:"fixed"==g.position?!0:!1}},storage:{set:function(c,e){v.debug("Setting stored value",c,e,g.storageMethod),"local"==g.storageMethod&&b.store!==d?b.store.set(c,e):a.cookie!==d?a.cookie(c,e):v.error(C.noStorage)},get:function(c){return v.debug("Getting stored value",c,g.storageMethod),"local"==g.storageMethod&&b.store!==d?b.store.get(c):a.cookie!==d?a.cookie(c):(v.error(C.noStorage),void 0)}},event:{scroll:function(){u!==d&&clearTimeout(u),u=setTimeout(function(){v.should.stick()?D(v.stick):v.unStick()},g.lag)}},setting:function(b,c){return v.debug("Changing setting",b,c),c===d?g[b]:(a.isPlainObject(b)?a.extend(!0,g,b):g[b]=c,void 0)},internal:function(b,c){return v.debug("Changing internal",b,c),c===d?v[b]:(a.isPlainObject(b)?a.extend(!0,v,b):v[b]=c,void 0)},debug:function(){g.debug&&(g.performance?v.performance.log(arguments):v.debug=Function.prototype.bind.call(console.info,console,g.moduleName+":"))},verbose:function(){g.verbose&&g.debug&&(g.performance?v.performance.log(arguments):v.verbose=Function.prototype.bind.call(console.info,console,g.moduleName+":"))},error:function(){v.error=Function.prototype.bind.call(console.log,console,g.moduleName+":")},performance:{log:function(a){var b,c,d;g.performance&&(b=(new Date).getTime(),d=k||b,c=b-d,k=b,l.push({Element:z,Name:a[0],Arguments:[].slice.call(a,1)||"","Execution Time":c})),clearTimeout(v.performance.timer),v.performance.timer=setTimeout(v.performance.display,100)},display:function(){var b=g.moduleName+":",c=0;k=!1,a.each(l,function(a,b){c+=b["Execution Time"]}),b+=" "+c+"ms",j&&(b+=" '"+j+"'"),(console.group!==d||console.table!==d)&&l.length>0&&(console.groupCollapsed(b),console.table?console.table(l):a.each(l,function(a,b){console.log(b.Name+": "+b["Execution Time"]+"ms")}),console.groupEnd()),l=[]}},invoke:function(b,c,e){var f,g;return c=c||o,e=z||e,"string"==typeof b&&A!==d&&(b=b.split(/[\. ]/),f=b.length-1,a.each(b,function(b,c){return a.isPlainObject(A[c])&&b!=f?(A=A[c],!0):A[c]!==d?(g=A[c],!0):(v.error(C.method),!1)})),a.isFunction(g)?g.apply(e,c):g||!1}},n?(A===d&&v.initialize(),e=v.invoke(m)):(A!==d&&v.destroy(),v.initialize())}),e?e:this},a.fn.nag.settings={moduleName:"Nag",verbose:!0,debug:!0,performance:!0,namespace:"Nag",persist:!1,displayTime:0,animation:{show:"slide",hide:"slide"},position:"fixed",scrollBarWidth:18,storageMethod:"cookie",storedKey:"nag",storedValue:"dismiss",sticky:!1,lag:0,context:b,errors:{noStorage:"Neither $.cookie or store is defined. A storage solution is required for storing state"},className:{bottom:"bottom",fixed:"fixed"},selector:{close:".icon.close"},speed:500,easing:"easeOutQuad",onHide:function(){}}}(jQuery,window,document);