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.

10 lines
6.9 KiB

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