| @@ 9853-10349 (lines=497) @@ | ||
| 9850 | * |
|
| 9851 | */ |
|
| 9852 | ||
| 9853 | ;(function ($, window, document, undefined) { |
|
| 9854 | ||
| 9855 | "use strict"; |
|
| 9856 | ||
| 9857 | window = (typeof window != 'undefined' && window.Math == Math) |
|
| 9858 | ? window |
|
| 9859 | : (typeof self != 'undefined' && self.Math == Math) |
|
| 9860 | ? self |
|
| 9861 | : Function('return this')() |
|
| 9862 | ; |
|
| 9863 | ||
| 9864 | $.fn.nag = function(parameters) { |
|
| 9865 | var |
|
| 9866 | $allModules = $(this), |
|
| 9867 | moduleSelector = $allModules.selector || '', |
|
| 9868 | ||
| 9869 | time = new Date().getTime(), |
|
| 9870 | performance = [], |
|
| 9871 | ||
| 9872 | query = arguments[0], |
|
| 9873 | methodInvoked = (typeof query == 'string'), |
|
| 9874 | queryArguments = [].slice.call(arguments, 1), |
|
| 9875 | returnedValue |
|
| 9876 | ; |
|
| 9877 | $allModules |
|
| 9878 | .each(function() { |
|
| 9879 | var |
|
| 9880 | settings = ( $.isPlainObject(parameters) ) |
|
| 9881 | ? $.extend(true, {}, $.fn.nag.settings, parameters) |
|
| 9882 | : $.extend({}, $.fn.nag.settings), |
|
| 9883 | ||
| 9884 | className = settings.className, |
|
| 9885 | selector = settings.selector, |
|
| 9886 | error = settings.error, |
|
| 9887 | namespace = settings.namespace, |
|
| 9888 | ||
| 9889 | eventNamespace = '.' + namespace, |
|
| 9890 | moduleNamespace = namespace + '-module', |
|
| 9891 | ||
| 9892 | $module = $(this), |
|
| 9893 | ||
| 9894 | $close = $module.find(selector.close), |
|
| 9895 | $context = (settings.context) |
|
| 9896 | ? $(settings.context) |
|
| 9897 | : $('body'), |
|
| 9898 | ||
| 9899 | element = this, |
|
| 9900 | instance = $module.data(moduleNamespace), |
|
| 9901 | ||
| 9902 | moduleOffset, |
|
| 9903 | moduleHeight, |
|
| 9904 | ||
| 9905 | contextWidth, |
|
| 9906 | contextHeight, |
|
| 9907 | contextOffset, |
|
| 9908 | ||
| 9909 | yOffset, |
|
| 9910 | yPosition, |
|
| 9911 | ||
| 9912 | timer, |
|
| 9913 | module, |
|
| 9914 | ||
| 9915 | requestAnimationFrame = window.requestAnimationFrame |
|
| 9916 | || window.mozRequestAnimationFrame |
|
| 9917 | || window.webkitRequestAnimationFrame |
|
| 9918 | || window.msRequestAnimationFrame |
|
| 9919 | || function(callback) { setTimeout(callback, 0); } |
|
| 9920 | ; |
|
| 9921 | module = { |
|
| 9922 | ||
| 9923 | initialize: function() { |
|
| 9924 | module.verbose('Initializing element'); |
|
| 9925 | ||
| 9926 | $module |
|
| 9927 | .on('click' + eventNamespace, selector.close, module.dismiss) |
|
| 9928 | .data(moduleNamespace, module) |
|
| 9929 | ; |
|
| 9930 | ||
| 9931 | if(settings.detachable && $module.parent()[0] !== $context[0]) { |
|
| 9932 | $module |
|
| 9933 | .detach() |
|
| 9934 | .prependTo($context) |
|
| 9935 | ; |
|
| 9936 | } |
|
| 9937 | ||
| 9938 | if(settings.displayTime > 0) { |
|
| 9939 | setTimeout(module.hide, settings.displayTime); |
|
| 9940 | } |
|
| 9941 | module.show(); |
|
| 9942 | }, |
|
| 9943 | ||
| 9944 | destroy: function() { |
|
| 9945 | module.verbose('Destroying instance'); |
|
| 9946 | $module |
|
| 9947 | .removeData(moduleNamespace) |
|
| 9948 | .off(eventNamespace) |
|
| 9949 | ; |
|
| 9950 | }, |
|
| 9951 | ||
| 9952 | show: function() { |
|
| 9953 | if( module.should.show() && !$module.is(':visible') ) { |
|
| 9954 | module.debug('Showing nag', settings.animation.show); |
|
| 9955 | if(settings.animation.show == 'fade') { |
|
| 9956 | $module |
|
| 9957 | .fadeIn(settings.duration, settings.easing) |
|
| 9958 | ; |
|
| 9959 | } |
|
| 9960 | else { |
|
| 9961 | $module |
|
| 9962 | .slideDown(settings.duration, settings.easing) |
|
| 9963 | ; |
|
| 9964 | } |
|
| 9965 | } |
|
| 9966 | }, |
|
| 9967 | ||
| 9968 | hide: function() { |
|
| 9969 | module.debug('Showing nag', settings.animation.hide); |
|
| 9970 | if(settings.animation.show == 'fade') { |
|
| 9971 | $module |
|
| 9972 | .fadeIn(settings.duration, settings.easing) |
|
| 9973 | ; |
|
| 9974 | } |
|
| 9975 | else { |
|
| 9976 | $module |
|
| 9977 | .slideUp(settings.duration, settings.easing) |
|
| 9978 | ; |
|
| 9979 | } |
|
| 9980 | }, |
|
| 9981 | ||
| 9982 | onHide: function() { |
|
| 9983 | module.debug('Removing nag', settings.animation.hide); |
|
| 9984 | $module.remove(); |
|
| 9985 | if (settings.onHide) { |
|
| 9986 | settings.onHide(); |
|
| 9987 | } |
|
| 9988 | }, |
|
| 9989 | ||
| 9990 | dismiss: function(event) { |
|
| 9991 | if(settings.storageMethod) { |
|
| 9992 | module.storage.set(settings.key, settings.value); |
|
| 9993 | } |
|
| 9994 | module.hide(); |
|
| 9995 | event.stopImmediatePropagation(); |
|
| 9996 | event.preventDefault(); |
|
| 9997 | }, |
|
| 9998 | ||
| 9999 | should: { |
|
| 10000 | show: function() { |
|
| 10001 | if(settings.persist) { |
|
| 10002 | module.debug('Persistent nag is set, can show nag'); |
|
| 10003 | return true; |
|
| 10004 | } |
|
| 10005 | if( module.storage.get(settings.key) != settings.value.toString() ) { |
|
| 10006 | module.debug('Stored value is not set, can show nag', module.storage.get(settings.key)); |
|
| 10007 | return true; |
|
| 10008 | } |
|
| 10009 | module.debug('Stored value is set, cannot show nag', module.storage.get(settings.key)); |
|
| 10010 | return false; |
|
| 10011 | } |
|
| 10012 | }, |
|
| 10013 | ||
| 10014 | get: { |
|
| 10015 | storageOptions: function() { |
|
| 10016 | var |
|
| 10017 | options = {} |
|
| 10018 | ; |
|
| 10019 | if(settings.expires) { |
|
| 10020 | options.expires = settings.expires; |
|
| 10021 | } |
|
| 10022 | if(settings.domain) { |
|
| 10023 | options.domain = settings.domain; |
|
| 10024 | } |
|
| 10025 | if(settings.path) { |
|
| 10026 | options.path = settings.path; |
|
| 10027 | } |
|
| 10028 | return options; |
|
| 10029 | } |
|
| 10030 | }, |
|
| 10031 | ||
| 10032 | clear: function() { |
|
| 10033 | module.storage.remove(settings.key); |
|
| 10034 | }, |
|
| 10035 | ||
| 10036 | storage: { |
|
| 10037 | set: function(key, value) { |
|
| 10038 | var |
|
| 10039 | options = module.get.storageOptions() |
|
| 10040 | ; |
|
| 10041 | if(settings.storageMethod == 'localstorage' && window.localStorage !== undefined) { |
|
| 10042 | window.localStorage.setItem(key, value); |
|
| 10043 | module.debug('Value stored using local storage', key, value); |
|
| 10044 | } |
|
| 10045 | else if(settings.storageMethod == 'sessionstorage' && window.sessionStorage !== undefined) { |
|
| 10046 | window.sessionStorage.setItem(key, value); |
|
| 10047 | module.debug('Value stored using session storage', key, value); |
|
| 10048 | } |
|
| 10049 | else if($.cookie !== undefined) { |
|
| 10050 | $.cookie(key, value, options); |
|
| 10051 | module.debug('Value stored using cookie', key, value, options); |
|
| 10052 | } |
|
| 10053 | else { |
|
| 10054 | module.error(error.noCookieStorage); |
|
| 10055 | return; |
|
| 10056 | } |
|
| 10057 | }, |
|
| 10058 | get: function(key, value) { |
|
| 10059 | var |
|
| 10060 | storedValue |
|
| 10061 | ; |
|
| 10062 | if(settings.storageMethod == 'localstorage' && window.localStorage !== undefined) { |
|
| 10063 | storedValue = window.localStorage.getItem(key); |
|
| 10064 | } |
|
| 10065 | else if(settings.storageMethod == 'sessionstorage' && window.sessionStorage !== undefined) { |
|
| 10066 | storedValue = window.sessionStorage.getItem(key); |
|
| 10067 | } |
|
| 10068 | // get by cookie |
|
| 10069 | else if($.cookie !== undefined) { |
|
| 10070 | storedValue = $.cookie(key); |
|
| 10071 | } |
|
| 10072 | else { |
|
| 10073 | module.error(error.noCookieStorage); |
|
| 10074 | } |
|
| 10075 | if(storedValue == 'undefined' || storedValue == 'null' || storedValue === undefined || storedValue === null) { |
|
| 10076 | storedValue = undefined; |
|
| 10077 | } |
|
| 10078 | return storedValue; |
|
| 10079 | }, |
|
| 10080 | remove: function(key) { |
|
| 10081 | var |
|
| 10082 | options = module.get.storageOptions() |
|
| 10083 | ; |
|
| 10084 | if(settings.storageMethod == 'localstorage' && window.localStorage !== undefined) { |
|
| 10085 | window.localStorage.removeItem(key); |
|
| 10086 | } |
|
| 10087 | else if(settings.storageMethod == 'sessionstorage' && window.sessionStorage !== undefined) { |
|
| 10088 | window.sessionStorage.removeItem(key); |
|
| 10089 | } |
|
| 10090 | // store by cookie |
|
| 10091 | else if($.cookie !== undefined) { |
|
| 10092 | $.removeCookie(key, options); |
|
| 10093 | } |
|
| 10094 | else { |
|
| 10095 | module.error(error.noStorage); |
|
| 10096 | } |
|
| 10097 | } |
|
| 10098 | }, |
|
| 10099 | ||
| 10100 | setting: function(name, value) { |
|
| 10101 | module.debug('Changing setting', name, value); |
|
| 10102 | if( $.isPlainObject(name) ) { |
|
| 10103 | $.extend(true, settings, name); |
|
| 10104 | } |
|
| 10105 | else if(value !== undefined) { |
|
| 10106 | if($.isPlainObject(settings[name])) { |
|
| 10107 | $.extend(true, settings[name], value); |
|
| 10108 | } |
|
| 10109 | else { |
|
| 10110 | settings[name] = value; |
|
| 10111 | } |
|
| 10112 | } |
|
| 10113 | else { |
|
| 10114 | return settings[name]; |
|
| 10115 | } |
|
| 10116 | }, |
|
| 10117 | internal: function(name, value) { |
|
| 10118 | if( $.isPlainObject(name) ) { |
|
| 10119 | $.extend(true, module, name); |
|
| 10120 | } |
|
| 10121 | else if(value !== undefined) { |
|
| 10122 | module[name] = value; |
|
| 10123 | } |
|
| 10124 | else { |
|
| 10125 | return module[name]; |
|
| 10126 | } |
|
| 10127 | }, |
|
| 10128 | debug: function() { |
|
| 10129 | if(!settings.silent && settings.debug) { |
|
| 10130 | if(settings.performance) { |
|
| 10131 | module.performance.log(arguments); |
|
| 10132 | } |
|
| 10133 | else { |
|
| 10134 | module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':'); |
|
| 10135 | module.debug.apply(console, arguments); |
|
| 10136 | } |
|
| 10137 | } |
|
| 10138 | }, |
|
| 10139 | verbose: function() { |
|
| 10140 | if(!settings.silent && settings.verbose && settings.debug) { |
|
| 10141 | if(settings.performance) { |
|
| 10142 | module.performance.log(arguments); |
|
| 10143 | } |
|
| 10144 | else { |
|
| 10145 | module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':'); |
|
| 10146 | module.verbose.apply(console, arguments); |
|
| 10147 | } |
|
| 10148 | } |
|
| 10149 | }, |
|
| 10150 | error: function() { |
|
| 10151 | if(!settings.silent) { |
|
| 10152 | module.error = Function.prototype.bind.call(console.error, console, settings.name + ':'); |
|
| 10153 | module.error.apply(console, arguments); |
|
| 10154 | } |
|
| 10155 | }, |
|
| 10156 | performance: { |
|
| 10157 | log: function(message) { |
|
| 10158 | var |
|
| 10159 | currentTime, |
|
| 10160 | executionTime, |
|
| 10161 | previousTime |
|
| 10162 | ; |
|
| 10163 | if(settings.performance) { |
|
| 10164 | currentTime = new Date().getTime(); |
|
| 10165 | previousTime = time || currentTime; |
|
| 10166 | executionTime = currentTime - previousTime; |
|
| 10167 | time = currentTime; |
|
| 10168 | performance.push({ |
|
| 10169 | 'Name' : message[0], |
|
| 10170 | 'Arguments' : [].slice.call(message, 1) || '', |
|
| 10171 | 'Element' : element, |
|
| 10172 | 'Execution Time' : executionTime |
|
| 10173 | }); |
|
| 10174 | } |
|
| 10175 | clearTimeout(module.performance.timer); |
|
| 10176 | module.performance.timer = setTimeout(module.performance.display, 500); |
|
| 10177 | }, |
|
| 10178 | display: function() { |
|
| 10179 | var |
|
| 10180 | title = settings.name + ':', |
|
| 10181 | totalTime = 0 |
|
| 10182 | ; |
|
| 10183 | time = false; |
|
| 10184 | clearTimeout(module.performance.timer); |
|
| 10185 | $.each(performance, function(index, data) { |
|
| 10186 | totalTime += data['Execution Time']; |
|
| 10187 | }); |
|
| 10188 | title += ' ' + totalTime + 'ms'; |
|
| 10189 | if(moduleSelector) { |
|
| 10190 | title += ' \'' + moduleSelector + '\''; |
|
| 10191 | } |
|
| 10192 | if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) { |
|
| 10193 | console.groupCollapsed(title); |
|
| 10194 | if(console.table) { |
|
| 10195 | console.table(performance); |
|
| 10196 | } |
|
| 10197 | else { |
|
| 10198 | $.each(performance, function(index, data) { |
|
| 10199 | console.log(data['Name'] + ': ' + data['Execution Time']+'ms'); |
|
| 10200 | }); |
|
| 10201 | } |
|
| 10202 | console.groupEnd(); |
|
| 10203 | } |
|
| 10204 | performance = []; |
|
| 10205 | } |
|
| 10206 | }, |
|
| 10207 | invoke: function(query, passedArguments, context) { |
|
| 10208 | var |
|
| 10209 | object = instance, |
|
| 10210 | maxDepth, |
|
| 10211 | found, |
|
| 10212 | response |
|
| 10213 | ; |
|
| 10214 | passedArguments = passedArguments || queryArguments; |
|
| 10215 | context = element || context; |
|
| 10216 | if(typeof query == 'string' && object !== undefined) { |
|
| 10217 | query = query.split(/[\. ]/); |
|
| 10218 | maxDepth = query.length - 1; |
|
| 10219 | $.each(query, function(depth, value) { |
|
| 10220 | var camelCaseValue = (depth != maxDepth) |
|
| 10221 | ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1) |
|
| 10222 | : query |
|
| 10223 | ; |
|
| 10224 | if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) { |
|
| 10225 | object = object[camelCaseValue]; |
|
| 10226 | } |
|
| 10227 | else if( object[camelCaseValue] !== undefined ) { |
|
| 10228 | found = object[camelCaseValue]; |
|
| 10229 | return false; |
|
| 10230 | } |
|
| 10231 | else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) { |
|
| 10232 | object = object[value]; |
|
| 10233 | } |
|
| 10234 | else if( object[value] !== undefined ) { |
|
| 10235 | found = object[value]; |
|
| 10236 | return false; |
|
| 10237 | } |
|
| 10238 | else { |
|
| 10239 | module.error(error.method, query); |
|
| 10240 | return false; |
|
| 10241 | } |
|
| 10242 | }); |
|
| 10243 | } |
|
| 10244 | if ( $.isFunction( found ) ) { |
|
| 10245 | response = found.apply(context, passedArguments); |
|
| 10246 | } |
|
| 10247 | else if(found !== undefined) { |
|
| 10248 | response = found; |
|
| 10249 | } |
|
| 10250 | if($.isArray(returnedValue)) { |
|
| 10251 | returnedValue.push(response); |
|
| 10252 | } |
|
| 10253 | else if(returnedValue !== undefined) { |
|
| 10254 | returnedValue = [returnedValue, response]; |
|
| 10255 | } |
|
| 10256 | else if(response !== undefined) { |
|
| 10257 | returnedValue = response; |
|
| 10258 | } |
|
| 10259 | return found; |
|
| 10260 | } |
|
| 10261 | }; |
|
| 10262 | ||
| 10263 | if(methodInvoked) { |
|
| 10264 | if(instance === undefined) { |
|
| 10265 | module.initialize(); |
|
| 10266 | } |
|
| 10267 | module.invoke(query); |
|
| 10268 | } |
|
| 10269 | else { |
|
| 10270 | if(instance !== undefined) { |
|
| 10271 | instance.invoke('destroy'); |
|
| 10272 | } |
|
| 10273 | module.initialize(); |
|
| 10274 | } |
|
| 10275 | }) |
|
| 10276 | ; |
|
| 10277 | ||
| 10278 | return (returnedValue !== undefined) |
|
| 10279 | ? returnedValue |
|
| 10280 | : this |
|
| 10281 | ; |
|
| 10282 | }; |
|
| 10283 | ||
| 10284 | $.fn.nag.settings = { |
|
| 10285 | ||
| 10286 | name : 'Nag', |
|
| 10287 | ||
| 10288 | silent : false, |
|
| 10289 | debug : false, |
|
| 10290 | verbose : false, |
|
| 10291 | performance : true, |
|
| 10292 | ||
| 10293 | namespace : 'Nag', |
|
| 10294 | ||
| 10295 | // allows cookie to be overridden |
|
| 10296 | persist : false, |
|
| 10297 | ||
| 10298 | // set to zero to require manually dismissal, otherwise hides on its own |
|
| 10299 | displayTime : 0, |
|
| 10300 | ||
| 10301 | animation : { |
|
| 10302 | show : 'slide', |
|
| 10303 | hide : 'slide' |
|
| 10304 | }, |
|
| 10305 | ||
| 10306 | context : false, |
|
| 10307 | detachable : false, |
|
| 10308 | ||
| 10309 | expires : 30, |
|
| 10310 | domain : false, |
|
| 10311 | path : '/', |
|
| 10312 | ||
| 10313 | // type of storage to use |
|
| 10314 | storageMethod : 'cookie', |
|
| 10315 | ||
| 10316 | // value to store in dismissed localstorage/cookie |
|
| 10317 | key : 'nag', |
|
| 10318 | value : 'dismiss', |
|
| 10319 | ||
| 10320 | error: { |
|
| 10321 | noCookieStorage : '$.cookie is not included. A storage solution is required.', |
|
| 10322 | noStorage : 'Neither $.cookie or store is defined. A storage solution is required for storing state', |
|
| 10323 | method : 'The method you called is not defined.' |
|
| 10324 | }, |
|
| 10325 | ||
| 10326 | className : { |
|
| 10327 | bottom : 'bottom', |
|
| 10328 | fixed : 'fixed' |
|
| 10329 | }, |
|
| 10330 | ||
| 10331 | selector : { |
|
| 10332 | close : '.close.icon' |
|
| 10333 | }, |
|
| 10334 | ||
| 10335 | speed : 500, |
|
| 10336 | easing : 'easeOutQuad', |
|
| 10337 | ||
| 10338 | onHide: function() {} |
|
| 10339 | ||
| 10340 | }; |
|
| 10341 | ||
| 10342 | // Adds easing |
|
| 10343 | $.extend( $.easing, { |
|
| 10344 | easeOutQuad: function (x, t, b, c, d) { |
|
| 10345 | return -c *(t/=d)*(t-2) + b; |
|
| 10346 | } |
|
| 10347 | }); |
|
| 10348 | ||
| 10349 | })( jQuery, window, document ); |
|
| 10350 | ||
| 10351 | /*! |
|
| 10352 | * # Semantic UI 2.2.11 - Popup |
|
| @@ 11-507 (lines=497) @@ | ||
| 8 | * |
|
| 9 | */ |
|
| 10 | ||
| 11 | ;(function ($, window, document, undefined) { |
|
| 12 | ||
| 13 | "use strict"; |
|
| 14 | ||
| 15 | window = (typeof window != 'undefined' && window.Math == Math) |
|
| 16 | ? window |
|
| 17 | : (typeof self != 'undefined' && self.Math == Math) |
|
| 18 | ? self |
|
| 19 | : Function('return this')() |
|
| 20 | ; |
|
| 21 | ||
| 22 | $.fn.nag = function(parameters) { |
|
| 23 | var |
|
| 24 | $allModules = $(this), |
|
| 25 | moduleSelector = $allModules.selector || '', |
|
| 26 | ||
| 27 | time = new Date().getTime(), |
|
| 28 | performance = [], |
|
| 29 | ||
| 30 | query = arguments[0], |
|
| 31 | methodInvoked = (typeof query == 'string'), |
|
| 32 | queryArguments = [].slice.call(arguments, 1), |
|
| 33 | returnedValue |
|
| 34 | ; |
|
| 35 | $allModules |
|
| 36 | .each(function() { |
|
| 37 | var |
|
| 38 | settings = ( $.isPlainObject(parameters) ) |
|
| 39 | ? $.extend(true, {}, $.fn.nag.settings, parameters) |
|
| 40 | : $.extend({}, $.fn.nag.settings), |
|
| 41 | ||
| 42 | className = settings.className, |
|
| 43 | selector = settings.selector, |
|
| 44 | error = settings.error, |
|
| 45 | namespace = settings.namespace, |
|
| 46 | ||
| 47 | eventNamespace = '.' + namespace, |
|
| 48 | moduleNamespace = namespace + '-module', |
|
| 49 | ||
| 50 | $module = $(this), |
|
| 51 | ||
| 52 | $close = $module.find(selector.close), |
|
| 53 | $context = (settings.context) |
|
| 54 | ? $(settings.context) |
|
| 55 | : $('body'), |
|
| 56 | ||
| 57 | element = this, |
|
| 58 | instance = $module.data(moduleNamespace), |
|
| 59 | ||
| 60 | moduleOffset, |
|
| 61 | moduleHeight, |
|
| 62 | ||
| 63 | contextWidth, |
|
| 64 | contextHeight, |
|
| 65 | contextOffset, |
|
| 66 | ||
| 67 | yOffset, |
|
| 68 | yPosition, |
|
| 69 | ||
| 70 | timer, |
|
| 71 | module, |
|
| 72 | ||
| 73 | requestAnimationFrame = window.requestAnimationFrame |
|
| 74 | || window.mozRequestAnimationFrame |
|
| 75 | || window.webkitRequestAnimationFrame |
|
| 76 | || window.msRequestAnimationFrame |
|
| 77 | || function(callback) { setTimeout(callback, 0); } |
|
| 78 | ; |
|
| 79 | module = { |
|
| 80 | ||
| 81 | initialize: function() { |
|
| 82 | module.verbose('Initializing element'); |
|
| 83 | ||
| 84 | $module |
|
| 85 | .on('click' + eventNamespace, selector.close, module.dismiss) |
|
| 86 | .data(moduleNamespace, module) |
|
| 87 | ; |
|
| 88 | ||
| 89 | if(settings.detachable && $module.parent()[0] !== $context[0]) { |
|
| 90 | $module |
|
| 91 | .detach() |
|
| 92 | .prependTo($context) |
|
| 93 | ; |
|
| 94 | } |
|
| 95 | ||
| 96 | if(settings.displayTime > 0) { |
|
| 97 | setTimeout(module.hide, settings.displayTime); |
|
| 98 | } |
|
| 99 | module.show(); |
|
| 100 | }, |
|
| 101 | ||
| 102 | destroy: function() { |
|
| 103 | module.verbose('Destroying instance'); |
|
| 104 | $module |
|
| 105 | .removeData(moduleNamespace) |
|
| 106 | .off(eventNamespace) |
|
| 107 | ; |
|
| 108 | }, |
|
| 109 | ||
| 110 | show: function() { |
|
| 111 | if( module.should.show() && !$module.is(':visible') ) { |
|
| 112 | module.debug('Showing nag', settings.animation.show); |
|
| 113 | if(settings.animation.show == 'fade') { |
|
| 114 | $module |
|
| 115 | .fadeIn(settings.duration, settings.easing) |
|
| 116 | ; |
|
| 117 | } |
|
| 118 | else { |
|
| 119 | $module |
|
| 120 | .slideDown(settings.duration, settings.easing) |
|
| 121 | ; |
|
| 122 | } |
|
| 123 | } |
|
| 124 | }, |
|
| 125 | ||
| 126 | hide: function() { |
|
| 127 | module.debug('Showing nag', settings.animation.hide); |
|
| 128 | if(settings.animation.show == 'fade') { |
|
| 129 | $module |
|
| 130 | .fadeIn(settings.duration, settings.easing) |
|
| 131 | ; |
|
| 132 | } |
|
| 133 | else { |
|
| 134 | $module |
|
| 135 | .slideUp(settings.duration, settings.easing) |
|
| 136 | ; |
|
| 137 | } |
|
| 138 | }, |
|
| 139 | ||
| 140 | onHide: function() { |
|
| 141 | module.debug('Removing nag', settings.animation.hide); |
|
| 142 | $module.remove(); |
|
| 143 | if (settings.onHide) { |
|
| 144 | settings.onHide(); |
|
| 145 | } |
|
| 146 | }, |
|
| 147 | ||
| 148 | dismiss: function(event) { |
|
| 149 | if(settings.storageMethod) { |
|
| 150 | module.storage.set(settings.key, settings.value); |
|
| 151 | } |
|
| 152 | module.hide(); |
|
| 153 | event.stopImmediatePropagation(); |
|
| 154 | event.preventDefault(); |
|
| 155 | }, |
|
| 156 | ||
| 157 | should: { |
|
| 158 | show: function() { |
|
| 159 | if(settings.persist) { |
|
| 160 | module.debug('Persistent nag is set, can show nag'); |
|
| 161 | return true; |
|
| 162 | } |
|
| 163 | if( module.storage.get(settings.key) != settings.value.toString() ) { |
|
| 164 | module.debug('Stored value is not set, can show nag', module.storage.get(settings.key)); |
|
| 165 | return true; |
|
| 166 | } |
|
| 167 | module.debug('Stored value is set, cannot show nag', module.storage.get(settings.key)); |
|
| 168 | return false; |
|
| 169 | } |
|
| 170 | }, |
|
| 171 | ||
| 172 | get: { |
|
| 173 | storageOptions: function() { |
|
| 174 | var |
|
| 175 | options = {} |
|
| 176 | ; |
|
| 177 | if(settings.expires) { |
|
| 178 | options.expires = settings.expires; |
|
| 179 | } |
|
| 180 | if(settings.domain) { |
|
| 181 | options.domain = settings.domain; |
|
| 182 | } |
|
| 183 | if(settings.path) { |
|
| 184 | options.path = settings.path; |
|
| 185 | } |
|
| 186 | return options; |
|
| 187 | } |
|
| 188 | }, |
|
| 189 | ||
| 190 | clear: function() { |
|
| 191 | module.storage.remove(settings.key); |
|
| 192 | }, |
|
| 193 | ||
| 194 | storage: { |
|
| 195 | set: function(key, value) { |
|
| 196 | var |
|
| 197 | options = module.get.storageOptions() |
|
| 198 | ; |
|
| 199 | if(settings.storageMethod == 'localstorage' && window.localStorage !== undefined) { |
|
| 200 | window.localStorage.setItem(key, value); |
|
| 201 | module.debug('Value stored using local storage', key, value); |
|
| 202 | } |
|
| 203 | else if(settings.storageMethod == 'sessionstorage' && window.sessionStorage !== undefined) { |
|
| 204 | window.sessionStorage.setItem(key, value); |
|
| 205 | module.debug('Value stored using session storage', key, value); |
|
| 206 | } |
|
| 207 | else if($.cookie !== undefined) { |
|
| 208 | $.cookie(key, value, options); |
|
| 209 | module.debug('Value stored using cookie', key, value, options); |
|
| 210 | } |
|
| 211 | else { |
|
| 212 | module.error(error.noCookieStorage); |
|
| 213 | return; |
|
| 214 | } |
|
| 215 | }, |
|
| 216 | get: function(key, value) { |
|
| 217 | var |
|
| 218 | storedValue |
|
| 219 | ; |
|
| 220 | if(settings.storageMethod == 'localstorage' && window.localStorage !== undefined) { |
|
| 221 | storedValue = window.localStorage.getItem(key); |
|
| 222 | } |
|
| 223 | else if(settings.storageMethod == 'sessionstorage' && window.sessionStorage !== undefined) { |
|
| 224 | storedValue = window.sessionStorage.getItem(key); |
|
| 225 | } |
|
| 226 | // get by cookie |
|
| 227 | else if($.cookie !== undefined) { |
|
| 228 | storedValue = $.cookie(key); |
|
| 229 | } |
|
| 230 | else { |
|
| 231 | module.error(error.noCookieStorage); |
|
| 232 | } |
|
| 233 | if(storedValue == 'undefined' || storedValue == 'null' || storedValue === undefined || storedValue === null) { |
|
| 234 | storedValue = undefined; |
|
| 235 | } |
|
| 236 | return storedValue; |
|
| 237 | }, |
|
| 238 | remove: function(key) { |
|
| 239 | var |
|
| 240 | options = module.get.storageOptions() |
|
| 241 | ; |
|
| 242 | if(settings.storageMethod == 'localstorage' && window.localStorage !== undefined) { |
|
| 243 | window.localStorage.removeItem(key); |
|
| 244 | } |
|
| 245 | else if(settings.storageMethod == 'sessionstorage' && window.sessionStorage !== undefined) { |
|
| 246 | window.sessionStorage.removeItem(key); |
|
| 247 | } |
|
| 248 | // store by cookie |
|
| 249 | else if($.cookie !== undefined) { |
|
| 250 | $.removeCookie(key, options); |
|
| 251 | } |
|
| 252 | else { |
|
| 253 | module.error(error.noStorage); |
|
| 254 | } |
|
| 255 | } |
|
| 256 | }, |
|
| 257 | ||
| 258 | setting: function(name, value) { |
|
| 259 | module.debug('Changing setting', name, value); |
|
| 260 | if( $.isPlainObject(name) ) { |
|
| 261 | $.extend(true, settings, name); |
|
| 262 | } |
|
| 263 | else if(value !== undefined) { |
|
| 264 | if($.isPlainObject(settings[name])) { |
|
| 265 | $.extend(true, settings[name], value); |
|
| 266 | } |
|
| 267 | else { |
|
| 268 | settings[name] = value; |
|
| 269 | } |
|
| 270 | } |
|
| 271 | else { |
|
| 272 | return settings[name]; |
|
| 273 | } |
|
| 274 | }, |
|
| 275 | internal: function(name, value) { |
|
| 276 | if( $.isPlainObject(name) ) { |
|
| 277 | $.extend(true, module, name); |
|
| 278 | } |
|
| 279 | else if(value !== undefined) { |
|
| 280 | module[name] = value; |
|
| 281 | } |
|
| 282 | else { |
|
| 283 | return module[name]; |
|
| 284 | } |
|
| 285 | }, |
|
| 286 | debug: function() { |
|
| 287 | if(!settings.silent && settings.debug) { |
|
| 288 | if(settings.performance) { |
|
| 289 | module.performance.log(arguments); |
|
| 290 | } |
|
| 291 | else { |
|
| 292 | module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':'); |
|
| 293 | module.debug.apply(console, arguments); |
|
| 294 | } |
|
| 295 | } |
|
| 296 | }, |
|
| 297 | verbose: function() { |
|
| 298 | if(!settings.silent && settings.verbose && settings.debug) { |
|
| 299 | if(settings.performance) { |
|
| 300 | module.performance.log(arguments); |
|
| 301 | } |
|
| 302 | else { |
|
| 303 | module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':'); |
|
| 304 | module.verbose.apply(console, arguments); |
|
| 305 | } |
|
| 306 | } |
|
| 307 | }, |
|
| 308 | error: function() { |
|
| 309 | if(!settings.silent) { |
|
| 310 | module.error = Function.prototype.bind.call(console.error, console, settings.name + ':'); |
|
| 311 | module.error.apply(console, arguments); |
|
| 312 | } |
|
| 313 | }, |
|
| 314 | performance: { |
|
| 315 | log: function(message) { |
|
| 316 | var |
|
| 317 | currentTime, |
|
| 318 | executionTime, |
|
| 319 | previousTime |
|
| 320 | ; |
|
| 321 | if(settings.performance) { |
|
| 322 | currentTime = new Date().getTime(); |
|
| 323 | previousTime = time || currentTime; |
|
| 324 | executionTime = currentTime - previousTime; |
|
| 325 | time = currentTime; |
|
| 326 | performance.push({ |
|
| 327 | 'Name' : message[0], |
|
| 328 | 'Arguments' : [].slice.call(message, 1) || '', |
|
| 329 | 'Element' : element, |
|
| 330 | 'Execution Time' : executionTime |
|
| 331 | }); |
|
| 332 | } |
|
| 333 | clearTimeout(module.performance.timer); |
|
| 334 | module.performance.timer = setTimeout(module.performance.display, 500); |
|
| 335 | }, |
|
| 336 | display: function() { |
|
| 337 | var |
|
| 338 | title = settings.name + ':', |
|
| 339 | totalTime = 0 |
|
| 340 | ; |
|
| 341 | time = false; |
|
| 342 | clearTimeout(module.performance.timer); |
|
| 343 | $.each(performance, function(index, data) { |
|
| 344 | totalTime += data['Execution Time']; |
|
| 345 | }); |
|
| 346 | title += ' ' + totalTime + 'ms'; |
|
| 347 | if(moduleSelector) { |
|
| 348 | title += ' \'' + moduleSelector + '\''; |
|
| 349 | } |
|
| 350 | if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) { |
|
| 351 | console.groupCollapsed(title); |
|
| 352 | if(console.table) { |
|
| 353 | console.table(performance); |
|
| 354 | } |
|
| 355 | else { |
|
| 356 | $.each(performance, function(index, data) { |
|
| 357 | console.log(data['Name'] + ': ' + data['Execution Time']+'ms'); |
|
| 358 | }); |
|
| 359 | } |
|
| 360 | console.groupEnd(); |
|
| 361 | } |
|
| 362 | performance = []; |
|
| 363 | } |
|
| 364 | }, |
|
| 365 | invoke: function(query, passedArguments, context) { |
|
| 366 | var |
|
| 367 | object = instance, |
|
| 368 | maxDepth, |
|
| 369 | found, |
|
| 370 | response |
|
| 371 | ; |
|
| 372 | passedArguments = passedArguments || queryArguments; |
|
| 373 | context = element || context; |
|
| 374 | if(typeof query == 'string' && object !== undefined) { |
|
| 375 | query = query.split(/[\. ]/); |
|
| 376 | maxDepth = query.length - 1; |
|
| 377 | $.each(query, function(depth, value) { |
|
| 378 | var camelCaseValue = (depth != maxDepth) |
|
| 379 | ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1) |
|
| 380 | : query |
|
| 381 | ; |
|
| 382 | if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) { |
|
| 383 | object = object[camelCaseValue]; |
|
| 384 | } |
|
| 385 | else if( object[camelCaseValue] !== undefined ) { |
|
| 386 | found = object[camelCaseValue]; |
|
| 387 | return false; |
|
| 388 | } |
|
| 389 | else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) { |
|
| 390 | object = object[value]; |
|
| 391 | } |
|
| 392 | else if( object[value] !== undefined ) { |
|
| 393 | found = object[value]; |
|
| 394 | return false; |
|
| 395 | } |
|
| 396 | else { |
|
| 397 | module.error(error.method, query); |
|
| 398 | return false; |
|
| 399 | } |
|
| 400 | }); |
|
| 401 | } |
|
| 402 | if ( $.isFunction( found ) ) { |
|
| 403 | response = found.apply(context, passedArguments); |
|
| 404 | } |
|
| 405 | else if(found !== undefined) { |
|
| 406 | response = found; |
|
| 407 | } |
|
| 408 | if($.isArray(returnedValue)) { |
|
| 409 | returnedValue.push(response); |
|
| 410 | } |
|
| 411 | else if(returnedValue !== undefined) { |
|
| 412 | returnedValue = [returnedValue, response]; |
|
| 413 | } |
|
| 414 | else if(response !== undefined) { |
|
| 415 | returnedValue = response; |
|
| 416 | } |
|
| 417 | return found; |
|
| 418 | } |
|
| 419 | }; |
|
| 420 | ||
| 421 | if(methodInvoked) { |
|
| 422 | if(instance === undefined) { |
|
| 423 | module.initialize(); |
|
| 424 | } |
|
| 425 | module.invoke(query); |
|
| 426 | } |
|
| 427 | else { |
|
| 428 | if(instance !== undefined) { |
|
| 429 | instance.invoke('destroy'); |
|
| 430 | } |
|
| 431 | module.initialize(); |
|
| 432 | } |
|
| 433 | }) |
|
| 434 | ; |
|
| 435 | ||
| 436 | return (returnedValue !== undefined) |
|
| 437 | ? returnedValue |
|
| 438 | : this |
|
| 439 | ; |
|
| 440 | }; |
|
| 441 | ||
| 442 | $.fn.nag.settings = { |
|
| 443 | ||
| 444 | name : 'Nag', |
|
| 445 | ||
| 446 | silent : false, |
|
| 447 | debug : false, |
|
| 448 | verbose : false, |
|
| 449 | performance : true, |
|
| 450 | ||
| 451 | namespace : 'Nag', |
|
| 452 | ||
| 453 | // allows cookie to be overridden |
|
| 454 | persist : false, |
|
| 455 | ||
| 456 | // set to zero to require manually dismissal, otherwise hides on its own |
|
| 457 | displayTime : 0, |
|
| 458 | ||
| 459 | animation : { |
|
| 460 | show : 'slide', |
|
| 461 | hide : 'slide' |
|
| 462 | }, |
|
| 463 | ||
| 464 | context : false, |
|
| 465 | detachable : false, |
|
| 466 | ||
| 467 | expires : 30, |
|
| 468 | domain : false, |
|
| 469 | path : '/', |
|
| 470 | ||
| 471 | // type of storage to use |
|
| 472 | storageMethod : 'cookie', |
|
| 473 | ||
| 474 | // value to store in dismissed localstorage/cookie |
|
| 475 | key : 'nag', |
|
| 476 | value : 'dismiss', |
|
| 477 | ||
| 478 | error: { |
|
| 479 | noCookieStorage : '$.cookie is not included. A storage solution is required.', |
|
| 480 | noStorage : 'Neither $.cookie or store is defined. A storage solution is required for storing state', |
|
| 481 | method : 'The method you called is not defined.' |
|
| 482 | }, |
|
| 483 | ||
| 484 | className : { |
|
| 485 | bottom : 'bottom', |
|
| 486 | fixed : 'fixed' |
|
| 487 | }, |
|
| 488 | ||
| 489 | selector : { |
|
| 490 | close : '.close.icon' |
|
| 491 | }, |
|
| 492 | ||
| 493 | speed : 500, |
|
| 494 | easing : 'easeOutQuad', |
|
| 495 | ||
| 496 | onHide: function() {} |
|
| 497 | ||
| 498 | }; |
|
| 499 | ||
| 500 | // Adds easing |
|
| 501 | $.extend( $.easing, { |
|
| 502 | easeOutQuad: function (x, t, b, c, d) { |
|
| 503 | return -c *(t/=d)*(t-2) + b; |
|
| 504 | } |
|
| 505 | }); |
|
| 506 | ||
| 507 | })( jQuery, window, document ); |
|
| 508 | ||