source for sakino.kelbie.scot
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.

431 lines
12 KiB

7 months ago
  1. /*!
  2. * Noty Helpers Javascript From JQuery Javascript Library
  3. *
  4. * Ported by Maksim Pecherskiy. Original Licensing:
  5. *
  6. * http://jquery.com/
  7. *
  8. * Copyright 2011, John Resig
  9. * Dual licensed under the MIT or GPL Version 2 licenses.
  10. * http://jquery.org/license
  11. *
  12. * Includes Sizzle.js
  13. * http://sizzlejs.com/
  14. * Copyright 2011, The Dojo Foundation
  15. * Released under the MIT, BSD, and GPL Licenses.
  16. *
  17. * Date: Mon Nov 21 21:11:03 2011 -0500
  18. */
  19. (function(){
  20. // String to Object flags format cache
  21. var flagsCache = {};
  22. // Convert String-formatted flags into Object-formatted ones and store in cache
  23. function createFlags( flags ) {
  24. var object = flagsCache[ flags ] = {},
  25. i, length;
  26. flags = flags.split( /\s+/ );
  27. for ( i = 0, length = flags.length; i < length; i++ ) {
  28. object[ flags[i] ] = true;
  29. }
  30. return object;
  31. }
  32. jQuery.extend({
  33. _mark: function( elem, type ) {
  34. if ( elem ) {
  35. type = (type || "fx") + "mark";
  36. jQuery.data( elem, type, (jQuery.data(elem,type,undefined,true) || 0) + 1, true );
  37. }
  38. },
  39. _unmark: function( force, elem, type ) {
  40. if ( force !== true ) {
  41. type = elem;
  42. elem = force;
  43. force = false;
  44. }
  45. if ( elem ) {
  46. type = type || "fx";
  47. var key = type + "mark",
  48. count = force ? 0 : ( (jQuery.data( elem, key, undefined, true) || 1 ) - 1 );
  49. if ( count ) {
  50. jQuery.data( elem, key, count, true );
  51. } else {
  52. jQuery.removeData( elem, key, true );
  53. handleQueueMarkDefer( elem, type, "mark" );
  54. }
  55. }
  56. },
  57. queue: function( elem, type, data ) {
  58. if ( elem ) {
  59. type = (type || "fx") + "queue";
  60. var q = jQuery.data( elem, type, undefined, true );
  61. // Speed up dequeue by getting out quickly if this is just a lookup
  62. if ( data ) {
  63. if ( !q || jQuery.isArray(data) ) {
  64. q = jQuery.data( elem, type, jQuery.makeArray(data), true );
  65. } else {
  66. q.push( data );
  67. }
  68. }
  69. return q || [];
  70. }
  71. },
  72. dequeue: function( elem, type ) {
  73. type = type || "fx";
  74. var queue = jQuery.queue( elem, type ),
  75. fn = queue.shift(),
  76. defer;
  77. // If the fx queue is dequeued, always remove the progress sentinel
  78. if ( fn === "inprogress" ) {
  79. fn = queue.shift();
  80. }
  81. if ( fn ) {
  82. // Add a progress sentinel to prevent the fx queue from being
  83. // automatically dequeued
  84. if ( type === "fx" ) {
  85. queue.unshift("inprogress");
  86. }
  87. fn.call(elem, function() {
  88. jQuery.dequeue(elem, type);
  89. });
  90. }
  91. if ( !queue.length ) {
  92. jQuery.removeData( elem, type + "queue", true );
  93. handleQueueMarkDefer( elem, type, "queue" );
  94. }
  95. }
  96. });
  97. jQuery.fn.extend({
  98. queue: function( type, data ) {
  99. if ( typeof type !== "string" ) {
  100. data = type;
  101. type = "fx";
  102. }
  103. if ( data === undefined ) {
  104. return jQuery.queue( this[0], type );
  105. }
  106. return this.each(function() {
  107. var queue = jQuery.queue( this, type, data );
  108. if ( type === "fx" && queue[0] !== "inprogress" ) {
  109. jQuery.dequeue( this, type );
  110. }
  111. });
  112. },
  113. dequeue: function( type ) {
  114. return this.each(function() {
  115. jQuery.dequeue( this, type );
  116. });
  117. },
  118. // Based off of the plugin by Clint Helfers, with permission.
  119. // http://blindsignals.com/index.php/2009/07/jquery-delay/
  120. delay: function( time, type ) {
  121. time = jQuery.fx ? jQuery.fx.speeds[time] || time : time;
  122. type = type || "fx";
  123. return this.queue( type, function() {
  124. var elem = this;
  125. setTimeout(function() {
  126. jQuery.dequeue( elem, type );
  127. }, time );
  128. });
  129. },
  130. clearQueue: function( type ) {
  131. return this.queue( type || "fx", [] );
  132. },
  133. // Get a promise resolved when queues of a certain type
  134. // are emptied (fx is the type by default)
  135. promise: function( type, object ) {
  136. if ( typeof type !== "string" ) {
  137. object = type;
  138. type = undefined;
  139. }
  140. type = type || "fx";
  141. var defer = jQuery.Deferred(),
  142. elements = this,
  143. i = elements.length,
  144. count = 1,
  145. deferDataKey = type + "defer",
  146. queueDataKey = type + "queue",
  147. markDataKey = type + "mark",
  148. tmp;
  149. function resolve() {
  150. if ( !( --count ) ) {
  151. defer.resolveWith( elements, [ elements ] );
  152. }
  153. }
  154. while( i-- ) {
  155. if (( tmp = jQuery.data( elements[ i ], deferDataKey, undefined, true ) ||
  156. ( jQuery.data( elements[ i ], queueDataKey, undefined, true ) ||
  157. jQuery.data( elements[ i ], markDataKey, undefined, true ) ) &&
  158. jQuery.data( elements[ i ], deferDataKey, jQuery._Deferred(), true ) )) {
  159. count++;
  160. tmp.done( resolve );
  161. }
  162. }
  163. resolve();
  164. return defer.promise();
  165. }
  166. });
  167. function handleQueueMarkDefer( elem, type, src ) {
  168. var deferDataKey = type + "defer",
  169. queueDataKey = type + "queue",
  170. markDataKey = type + "mark",
  171. defer = jQuery._data( elem, deferDataKey );
  172. if ( defer &&
  173. ( src === "queue" || !jQuery._data(elem, queueDataKey) ) &&
  174. ( src === "mark" || !jQuery._data(elem, markDataKey) ) ) {
  175. // Give room for hard-coded callbacks to fire first
  176. // and eventually mark/queue something else on the element
  177. setTimeout( function() {
  178. if ( !jQuery._data( elem, queueDataKey ) &&
  179. !jQuery._data( elem, markDataKey ) ) {
  180. jQuery.removeData( elem, deferDataKey, true );
  181. defer.fire();
  182. }
  183. }, 0 );
  184. }
  185. }
  186. jQuery.Callbacks = function( flags ) {
  187. // Convert flags from String-formatted to Object-formatted
  188. // (we check in cache first)
  189. flags = flags ? ( /*flagsCache[ flags ] || */createFlags( flags ) ) : {};
  190. var // Actual callback list
  191. list = [],
  192. // Stack of fire calls for repeatable lists
  193. stack = [],
  194. // Last fire value (for non-forgettable lists)
  195. memory,
  196. // Flag to know if list is currently firing
  197. firing,
  198. // First callback to fire (used internally by add and fireWith)
  199. firingStart,
  200. // End of the loop when firing
  201. firingLength,
  202. // Index of currently firing callback (modified by remove if needed)
  203. firingIndex,
  204. // Add one or several callbacks to the list
  205. add = function( args ) {
  206. var i,
  207. length,
  208. elem,
  209. type,
  210. actual;
  211. for ( i = 0, length = args.length; i < length; i++ ) {
  212. elem = args[ i ];
  213. type = jQuery.type( elem );
  214. if ( type === "array" ) {
  215. // Inspect recursively
  216. add( elem );
  217. } else if ( type === "function" ) {
  218. // Add if not in unique mode and callback is not in
  219. if ( !flags.unique || !self.has( elem ) ) {
  220. list.push( elem );
  221. }
  222. }
  223. }
  224. },
  225. // Fire callbacks
  226. fire = function( context, args ) {
  227. args = args || [];
  228. memory = !flags.memory || [ context, args ];
  229. firing = true;
  230. firingIndex = firingStart || 0;
  231. firingStart = 0;
  232. firingLength = list.length;
  233. for ( ; list && firingIndex < firingLength; firingIndex++ ) {
  234. if ( list[ firingIndex ].apply( context, args ) === false && flags.stopOnFalse ) {
  235. memory = true; // Mark as halted
  236. break;
  237. }
  238. }
  239. firing = false;
  240. if ( list ) {
  241. if ( !flags.once ) {
  242. if ( stack && stack.length ) {
  243. memory = stack.shift();
  244. self.fireWith( memory[ 0 ], memory[ 1 ] );
  245. }
  246. } else if ( memory === true ) {
  247. self.disable();
  248. } else {
  249. list = [];
  250. }
  251. }
  252. },
  253. // Actual Callbacks object
  254. self = {
  255. // Add a callback or a collection of callbacks to the list
  256. add: function() {
  257. if ( list ) {
  258. var length = list.length;
  259. add( arguments );
  260. // Do we need to add the callbacks to the
  261. // current firing batch?
  262. if ( firing ) {
  263. firingLength = list.length;
  264. // With memory, if we're not firing then
  265. // we should call right away, unless previous
  266. // firing was halted (stopOnFalse)
  267. } else if ( memory && memory !== true ) {
  268. firingStart = length;
  269. fire( memory[ 0 ], memory[ 1 ] );
  270. }
  271. }
  272. return this;
  273. },
  274. // Remove a callback from the list
  275. remove: function() {
  276. if ( list ) {
  277. var args = arguments,
  278. argIndex = 0,
  279. argLength = args.length;
  280. for ( ; argIndex < argLength ; argIndex++ ) {
  281. for ( var i = 0; i < list.length; i++ ) {
  282. if ( args[ argIndex ] === list[ i ] ) {
  283. // Handle firingIndex and firingLength
  284. if ( firing ) {
  285. if ( i <= firingLength ) {
  286. firingLength--;
  287. if ( i <= firingIndex ) {
  288. firingIndex--;
  289. }
  290. }
  291. }
  292. // Remove the element
  293. list.splice( i--, 1 );
  294. // If we have some unicity property then
  295. // we only need to do this once
  296. if ( flags.unique ) {
  297. break;
  298. }
  299. }
  300. }
  301. }
  302. }
  303. return this;
  304. },
  305. // Control if a given callback is in the list
  306. has: function( fn ) {
  307. if ( list ) {
  308. var i = 0,
  309. length = list.length;
  310. for ( ; i < length; i++ ) {
  311. if ( fn === list[ i ] ) {
  312. return true;
  313. }
  314. }
  315. }
  316. return false;
  317. },
  318. // Remove all callbacks from the list
  319. empty: function() {
  320. list = [];
  321. return this;
  322. },
  323. // Have the list do nothing anymore
  324. disable: function() {
  325. list = stack = memory = undefined;
  326. return this;
  327. },
  328. // Is it disabled?
  329. disabled: function() {
  330. return !list;
  331. },
  332. // Lock the list in its current state
  333. lock: function() {
  334. stack = undefined;
  335. if ( !memory || memory === true ) {
  336. self.disable();
  337. }
  338. return this;
  339. },
  340. // Is it locked?
  341. locked: function() {
  342. return !stack;
  343. },
  344. // Call all callbacks with the given context and arguments
  345. fireWith: function( context, args ) {
  346. if ( stack ) {
  347. if ( firing ) {
  348. if ( !flags.once ) {
  349. stack.push( [ context, args ] );
  350. }
  351. } else if ( !( flags.once && memory ) ) {
  352. fire( context, args );
  353. }
  354. }
  355. return this;
  356. },
  357. // Call all the callbacks with the given arguments
  358. fire: function() {
  359. self.fireWith( this, arguments );
  360. return this;
  361. },
  362. // To know if the callbacks have already been called at least once
  363. fired: function() {
  364. return !!memory;
  365. }
  366. };
  367. return self;
  368. };
  369. jQuery.fn.extend({
  370. // Get a promise resolved when queues of a certain type
  371. // are emptied (fx is the type by default)
  372. promise: function( type, object ) {
  373. if ( typeof type !== "string" ) {
  374. object = type;
  375. type = undefined;
  376. }
  377. type = type || "fx";
  378. var defer = jQuery.Deferred(),
  379. elements = this,
  380. i = elements.length,
  381. count = 1,
  382. deferDataKey = type + "defer",
  383. queueDataKey = type + "queue",
  384. markDataKey = type + "mark",
  385. tmp;
  386. function resolve() {
  387. if ( !( --count ) ) {
  388. defer.resolveWith( elements, [ elements ] );
  389. }
  390. }
  391. while( i-- ) {
  392. if (( tmp = jQuery.data( elements[ i ], deferDataKey, undefined, true ) ||
  393. ( jQuery.data( elements[ i ], queueDataKey, undefined, true ) ||
  394. jQuery.data( elements[ i ], markDataKey, undefined, true ) ) &&
  395. jQuery.data( elements[ i ], deferDataKey, jQuery.Callbacks( "once memory" ), true ) )) {
  396. count++;
  397. tmp.add( resolve );
  398. }
  399. }
  400. resolve();
  401. return defer.promise();
  402. }
  403. });
  404. })();