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.

0 lines
6.7 KiB

  1. !function(a,b,c,d){a.visit=a.fn.visit=function(c){var e,f=a(a.isFunction(this)?b:this),g=f.selector||"",h=(new Date).getTime(),i=[],j=arguments[0],k="string"==typeof j,l=[].slice.call(arguments,1);return f.each(function(){var m,n=a.extend(!0,{},a.fn.visit.settings,c),o=n.error,p=n.namespace,q=p+"-module",r=a(this),s=a(),t=this,u=r.data(q);m={initialize:function(){n.count?m.store(n.key.count,n.count):n.id?m.add.id(n.id):n.increment&&"increment"!==k&&m.increment(),m.add.display(r),m.instantiate()},instantiate:function(){m.verbose("Storing instance of visit module",m),u=m,r.data(q,m)},destroy:function(){m.verbose("Destroying instance"),r.removeData(q)},increment:function(a){var b=m.get.count(),c=+b+1;a?m.add.id(a):(c>n.limit&&!n.surpass&&(c=n.limit),m.debug("Incrementing visits",c),m.store(n.key.count,c))},decrement:function(a){var b=m.get.count(),c=+b-1;a?m.remove.id(a):(m.debug("Removing visit"),m.store(n.key.count,c))},get:{count:function(){return+m.retrieve(n.key.count)||0},idCount:function(a){return a=a||m.get.ids(),a.length},ids:function(a){var b=[];return a=a||m.retrieve(n.key.ids),"string"==typeof a&&(b=a.split(n.delimiter)),m.verbose("Found visited ID list",b),b},storageOptions:function(){var a={};return n.expires&&(a.expires=n.expires),n.domain&&(a.domain=n.domain),n.path&&(a.path=n.path),a}},has:{visited:function(b,c){var e=!1;return c=c||m.get.ids(),b!==d&&c&&a.each(c,function(a,c){c==b&&(e=!0)}),e}},set:{count:function(a){m.store(n.key.count,a)},ids:function(a){m.store(n.key.ids,a)}},reset:function(){m.store(n.key.count,0),m.store(n.key.ids,null)},add:{id:function(a){var b=m.retrieve(n.key.ids),c=b===d||""===b?a:b+n.delimiter+a;m.has.visited(a)?m.debug("Unique content already visited, not adding visit",a,b):a===d?m.debug("ID is not defined"):(m.debug("Adding visit to unique content",a),m.store(n.key.ids,c)),m.set.count(m.get.idCount())},display:function(b){var c=a(b);c.size()>0&&!a.isWindow(c[0])&&(m.debug("Updating visit count for element",c),s=s.size()>0?s.add(c):c)}},remove:{id:function(b){var c=m.get.ids(),e=[];b!==d&&c!==d&&(m.debug("Removing visit to unique content",b,c),a.each(c,function(a,c){c!==b&&e.push(c)}),e=e.join(n.delimiter),m.store(n.key.ids,e)),m.set.count(m.get.idCount())}},check:{limit:function(b){b=b||m.get.count(),n.limit&&(b>=n.limit&&(m.debug("Pages viewed exceeded limit, firing callback",b,n.limit),a.proxy(n.onLimit,this)(b)),m.debug("Limit not reached",b,n.limit),a.proxy(n.onChange,this)(b)),m.update.display(b)}},update:{display:function(a){a=a||m.get.count(),s.size()>0&&(m.debug("Updating displayed view count",s),s.html(a))}},store:function(c,e){var f=m.get.storageOptions(e);if("localstorage"==n.storageMethod&&b.localStorage!==d)b.localStorage.setItem(c,e),m.debug("Value stored using local storage",c,e);else{if(a.cookie===d)return void m.error(o.noCookieStorage);a.cookie(c,e,f),m.debug("Value stored using cookie",c,e,f)}c==n.key.count&&m.check.limit(e)},retrieve:function(c){var e;return"localstorage"==n.storageMethod&&b.localStorage!==d?e=b.localStorage.getItem(c):a.cookie!==d?e=a.cookie(c):m.error(o.noCookieStorage),("undefined"==e||"null"==e||e===d||null===e)&&(e=d),e},setting:function(b,c){if(a.isPlainObject(b))a.extend(!0,n,b);else{if(c===d)return n[b];n[b]=c}},internal:function(b,c){return m.debug("Changing internal",b,c),c===d?m[b]:void(a.isPlainObject(b)?a.extend(!0,m,b):m[b]=c)},debug:function(){n.debug&&(n.performance?m.performance.log(arguments):(m.debug=Function.prototype.bind.call(console.info,console,n.name+":"),m.debug.apply(console,arguments)))},verbose:function(){n.verbose&&n.debug&&(n.performance?m.performance.log(arguments):(m.verbose=Function.prototype.bind.call(console.info,console,n.name+":"),m.verbose.apply(console,arguments)))},error:function(){m.error=Function.prototype.bind.call(console.error,console,n.name+":"),m.error.apply(console,arguments)},performance:{log:function(a){var b,c,d;n.performance&&(b=(new Date).getTime(),d=h||b,c=b-d,h=b,i.push({Name:a[0],Arguments:[].slice.call(a,1)||"",Element:t,"Execution Time":c})),clearTimeout(m.performance.timer),m.perf