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.

1091 lines
34 KiB

10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
9 years ago
9 years ago
10 years ago
9 years ago
10 years ago
10 years ago
9 years ago
9 years ago
9 years ago
10 years ago
9 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
9 years ago
9 years ago
9 years ago
10 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
9 years ago
  1. /*!
  2. * # Semantic UI 2.2.0 - Transition
  3. * http://github.com/semantic-org/semantic-ui/
  4. *
  5. *
  6. * Copyright 2015 Contributors
  7. * Released under the MIT license
  8. * http://opensource.org/licenses/MIT
  9. *
  10. */
  11. ;(function ($, window, document, undefined) {
  12. "use strict";
  13. window = (typeof window != 'undefined' && window.Math == Math)
  14. ? window
  15. : (typeof self != 'undefined' && self.Math == Math)
  16. ? self
  17. : Function('return this')()
  18. ;
  19. $.fn.transition = function() {
  20. var
  21. $allModules = $(this),
  22. moduleSelector = $allModules.selector || '',
  23. time = new Date().getTime(),
  24. performance = [],
  25. moduleArguments = arguments,
  26. query = moduleArguments[0],
  27. queryArguments = [].slice.call(arguments, 1),
  28. methodInvoked = (typeof query === 'string'),
  29. requestAnimationFrame = window.requestAnimationFrame
  30. || window.mozRequestAnimationFrame
  31. || window.webkitRequestAnimationFrame
  32. || window.msRequestAnimationFrame
  33. || function(callback) { setTimeout(callback, 0); },
  34. returnedValue
  35. ;
  36. $allModules
  37. .each(function(index) {
  38. var
  39. $module = $(this),
  40. element = this,
  41. // set at run time
  42. settings,
  43. instance,
  44. error,
  45. className,
  46. metadata,
  47. animationEnd,
  48. animationName,
  49. namespace,
  50. moduleNamespace,
  51. eventNamespace,
  52. module
  53. ;
  54. module = {
  55. initialize: function() {
  56. // get full settings
  57. settings = module.get.settings.apply(element, moduleArguments);
  58. // shorthand
  59. className = settings.className;
  60. error = settings.error;
  61. metadata = settings.metadata;
  62. // define namespace
  63. eventNamespace = '.' + settings.namespace;
  64. moduleNamespace = 'module-' + settings.namespace;
  65. instance = $module.data(moduleNamespace) || module;
  66. // get vendor specific events
  67. animationEnd = module.get.animationEndEvent();
  68. if(methodInvoked) {
  69. methodInvoked = module.invoke(query);
  70. }
  71. // method not invoked, lets run an animation
  72. if(methodInvoked === false) {
  73. module.verbose('Converted arguments into settings object', settings);
  74. if(settings.interval) {
  75. module.delay(settings.animate);
  76. }
  77. else {
  78. module.animate();
  79. }
  80. module.instantiate();
  81. }
  82. },
  83. instantiate: function() {
  84. module.verbose('Storing instance of module', module);
  85. instance = module;
  86. $module
  87. .data(moduleNamespace, instance)
  88. ;
  89. },
  90. destroy: function() {
  91. module.verbose('Destroying previous module for', element);
  92. $module
  93. .removeData(moduleNamespace)
  94. ;
  95. },
  96. refresh: function() {
  97. module.verbose('Refreshing display type on next animation');
  98. delete module.displayType;
  99. },
  100. forceRepaint: function() {
  101. module.verbose('Forcing element repaint');
  102. var
  103. $parentElement = $module.parent(),
  104. $nextElement = $module.next()
  105. ;
  106. if($nextElement.length === 0) {
  107. $module.detach().appendTo($parentElement);
  108. }
  109. else {
  110. $module.detach().insertBefore($nextElement);
  111. }
  112. },
  113. repaint: function() {
  114. module.verbose('Repainting element');
  115. var
  116. fakeAssignment = element.offsetWidth
  117. ;
  118. },
  119. delay: function(interval) {
  120. var
  121. direction = module.get.animationDirection(),
  122. shouldReverse,
  123. delay
  124. ;
  125. if(!direction) {
  126. direction = module.can.transition()
  127. ? module.get.direction()
  128. : 'static'
  129. ;
  130. }
  131. interval = (interval !== undefined)
  132. ? interval
  133. : settings.interval
  134. ;
  135. shouldReverse = (settings.reverse == 'auto' && direction == className.outward);
  136. delay = (shouldReverse || settings.reverse == true)
  137. ? ($allModules.length - index) * settings.interval
  138. : index * settings.interval
  139. ;
  140. module.debug('Delaying animation by', delay);
  141. setTimeout(module.animate, delay);
  142. },
  143. animate: function(overrideSettings) {
  144. settings = overrideSettings || settings;
  145. if(!module.is.supported()) {
  146. module.error(error.support);
  147. return false;
  148. }
  149. module.debug('Preparing animation', settings.animation);
  150. if(module.is.animating()) {
  151. if(settings.queue) {
  152. if(!settings.allowRepeats && module.has.direction() && module.is.occurring() && module.queuing !== true) {
  153. module.debug('Animation is currently occurring, preventing queueing same animation', settings.animation);
  154. }
  155. else {
  156. module.queue(settings.animation);
  157. }
  158. return false;
  159. }
  160. else if(!settings.allowRepeats && module.is.occurring()) {
  161. module.debug('Animation is already occurring, will not execute repeated animation', settings.animation);
  162. return false;
  163. }
  164. else {
  165. module.debug('New animation started, completing previous early', settings.animation);
  166. instance.complete();
  167. }
  168. }
  169. if( module.can.animate() ) {
  170. module.set.animating(settings.animation);
  171. }
  172. else {
  173. module.error(error.noAnimation, settings.animation, element);
  174. }
  175. },
  176. reset: function() {
  177. module.debug('Resetting animation to beginning conditions');
  178. module.remove.animationCallbacks();
  179. module.restore.conditions();
  180. module.remove.animating();
  181. },
  182. queue: function(animation) {
  183. module.debug('Queueing animation of', animation);
  184. module.queuing = true;
  185. $module
  186. .one(animationEnd + '.queue' + eventNamespace, function() {
  187. module.queuing = false;
  188. module.repaint();
  189. module.animate.apply(this, settings);
  190. })
  191. ;
  192. },
  193. complete: function (event) {
  194. module.debug('Animation complete', settings.animation);
  195. module.remove.completeCallback();
  196. module.remove.failSafe();
  197. if(!module.is.looping()) {
  198. if( module.is.outward() ) {
  199. module.verbose('Animation is outward, hiding element');
  200. module.restore.conditions();
  201. module.hide();
  202. }
  203. else if( module.is.inward() ) {
  204. module.verbose('Animation is outward, showing element');
  205. module.restore.conditions();
  206. module.show();
  207. }
  208. else {
  209. module.verbose('Static animation completed');
  210. module.restore.conditions();
  211. settings.onComplete.call(element);
  212. }
  213. }
  214. },
  215. force: {
  216. visible: function() {
  217. var
  218. style = $module.attr('style'),
  219. userStyle = module.get.userStyle(),
  220. displayType = module.get.displayType(),
  221. overrideStyle = userStyle + 'display: ' + displayType + ' !important;',
  222. currentDisplay = $module.css('display'),
  223. emptyStyle = (style === undefined || style === '')
  224. ;
  225. if(currentDisplay !== displayType) {
  226. module.verbose('Overriding default display to show element', displayType);
  227. $module
  228. .attr('style', overrideStyle)
  229. ;
  230. }
  231. else if(emptyStyle) {
  232. $module.removeAttr('style');
  233. }
  234. },
  235. hidden: function() {
  236. var
  237. style = $module.attr('style'),
  238. currentDisplay = $module.css('display'),
  239. emptyStyle = (style === undefined || style === '')
  240. ;
  241. if(currentDisplay !== 'none' && !module.is.hidden()) {
  242. module.verbose('Overriding default display to hide element');
  243. $module
  244. .css('display', 'none')
  245. ;
  246. }
  247. else if(emptyStyle) {
  248. $module
  249. .removeAttr('style')
  250. ;
  251. }
  252. }
  253. },
  254. has: {
  255. direction: function(animation) {
  256. var
  257. hasDirection = false
  258. ;
  259. animation = animation || settings.animation;
  260. if(typeof animation === 'string') {
  261. animation = animation.split(' ');
  262. $.each(animation, function(index, word){
  263. if(word === className.inward || word === className.outward) {
  264. hasDirection = true;
  265. }
  266. });
  267. }
  268. return hasDirection;
  269. },
  270. inlineDisplay: function() {
  271. var
  272. style = $module.attr('style') || ''
  273. ;
  274. return $.isArray(style.match(/display.*?;/, ''));
  275. }
  276. },
  277. set: {
  278. animating: function(animation) {
  279. var
  280. animationClass,
  281. direction
  282. ;
  283. // remove previous callbacks
  284. module.remove.completeCallback();
  285. // determine exact animation
  286. animation = animation || settings.animation;
  287. animationClass = module.get.animationClass(animation);
  288. // save animation class in cache to restore class names
  289. module.save.animation(animationClass);
  290. // override display if necessary so animation appears visibly
  291. module.force.visible();
  292. module.remove.hidden();
  293. module.remove.direction();
  294. module.start.animation(animationClass);
  295. },
  296. duration: function(animationName, duration) {
  297. duration = duration || settings.duration;
  298. duration = (typeof duration == 'number')
  299. ? duration + 'ms'
  300. : duration
  301. ;
  302. if(duration || duration === 0) {
  303. module.verbose('Setting animation duration', duration);
  304. $module
  305. .css({
  306. 'animation-duration': duration
  307. })
  308. ;
  309. }
  310. },
  311. direction: function(direction) {
  312. direction = direction || module.get.direction();
  313. if(direction == className.inward) {
  314. module.set.inward();
  315. }
  316. else {
  317. module.set.outward();
  318. }
  319. },
  320. looping: function() {
  321. module.debug('Transition set to loop');
  322. $module
  323. .addClass(className.looping)
  324. ;
  325. },
  326. hidden: function() {
  327. $module
  328. .addClass(className.transition)
  329. .addClass(className.hidden)
  330. ;
  331. },
  332. inward: function() {
  333. module.debug('Setting direction to inward');
  334. $module
  335. .removeClass(className.outward)
  336. .addClass(className.inward)
  337. ;
  338. },
  339. outward: function() {
  340. module.debug('Setting direction to outward');
  341. $module
  342. .removeClass(className.inward)
  343. .addClass(className.outward)
  344. ;
  345. },
  346. visible: function() {
  347. $module
  348. .addClass(className.transition)
  349. .addClass(className.visible)
  350. ;
  351. }
  352. },
  353. start: {
  354. animation: function(animationClass) {
  355. animationClass = animationClass || module.get.animationClass();
  356. module.debug('Starting tween', animationClass);
  357. $module
  358. .addClass(animationClass)
  359. .one(animationEnd + '.complete' + eventNamespace, module.complete)
  360. ;
  361. if(settings.useFailSafe) {
  362. module.add.failSafe();
  363. }
  364. module.set.duration(settings.duration);
  365. settings.onStart.call(element);
  366. }
  367. },
  368. save: {
  369. animation: function(animation) {
  370. if(!module.cache) {
  371. module.cache = {};
  372. }
  373. module.cache.animation = animation;
  374. },
  375. displayType: function(displayType) {
  376. if(displayType !== 'none') {
  377. $module.data(metadata.displayType, displayType);
  378. }
  379. },
  380. transitionExists: function(animation, exists) {
  381. $.fn.transition.exists[animation] = exists;
  382. module.verbose('Saving existence of transition', animation, exists);
  383. }
  384. },
  385. restore: {
  386. conditions: function() {
  387. var
  388. animation = module.get.currentAnimation()
  389. ;
  390. if(animation) {
  391. $module
  392. .removeClass(animation)
  393. ;
  394. module.verbose('Removing animation class', module.cache);
  395. }
  396. module.remove.duration();
  397. }
  398. },
  399. add: {
  400. failSafe: function() {
  401. var
  402. duration = module.get.duration()
  403. ;
  404. module.timer = setTimeout(function() {
  405. $module.triggerHandler(animationEnd);
  406. }, duration + settings.failSafeDelay);
  407. module.verbose('Adding fail safe timer', module.timer);
  408. }
  409. },
  410. remove: {
  411. animating: function() {
  412. $module.removeClass(className.animating);
  413. },
  414. animationCallbacks: function() {
  415. module.remove.queueCallback();
  416. module.remove.completeCallback();
  417. },
  418. queueCallback: function() {
  419. $module.off('.queue' + eventNamespace);
  420. },
  421. completeCallback: function() {
  422. $module.off('.complete' + eventNamespace);
  423. },
  424. display: function() {
  425. $module.css('display', '');
  426. },
  427. direction: function() {
  428. $module
  429. .removeClass(className.inward)
  430. .removeClass(className.outward)
  431. ;
  432. },
  433. duration: function() {
  434. $module
  435. .css('animation-duration', '')
  436. ;
  437. },
  438. failSafe: function() {
  439. module.verbose('Removing fail safe timer', module.timer);
  440. if(module.timer) {
  441. clearTimeout(module.timer);
  442. }
  443. },
  444. hidden: function() {
  445. $module.removeClass(className.hidden);
  446. },
  447. visible: function() {
  448. $module.removeClass(className.visible);
  449. },
  450. looping: function() {
  451. module.debug('Transitions are no longer looping');
  452. if( module.is.looping() ) {
  453. module.reset();
  454. $module
  455. .removeClass(className.looping)
  456. ;
  457. }
  458. },
  459. transition: function() {
  460. $module
  461. .removeClass(className.visible)
  462. .removeClass(className.hidden)
  463. ;
  464. }
  465. },
  466. get: {
  467. settings: function(animation, duration, onComplete) {
  468. // single settings object
  469. if(typeof animation == 'object') {
  470. return $.extend(true, {}, $.fn.transition.settings, animation);
  471. }
  472. // all arguments provided
  473. else if(typeof onComplete == 'function') {
  474. return $.extend({}, $.fn.transition.settings, {
  475. animation : animation,
  476. onComplete : onComplete,
  477. duration : duration
  478. });
  479. }
  480. // only duration provided
  481. else if(typeof duration == 'string' || typeof duration == 'number') {
  482. return $.extend({}, $.fn.transition.settings, {
  483. animation : animation,
  484. duration : duration
  485. });
  486. }
  487. // duration is actually settings object
  488. else if(typeof duration == 'object') {
  489. return $.extend({}, $.fn.transition.settings, duration, {
  490. animation : animation
  491. });
  492. }
  493. // duration is actually callback
  494. else if(typeof duration == 'function') {
  495. return $.extend({}, $.fn.transition.settings, {
  496. animation : animation,
  497. onComplete : duration
  498. });
  499. }
  500. // only animation provided
  501. else {
  502. return $.extend({}, $.fn.transition.settings, {
  503. animation : animation
  504. });
  505. }
  506. return $.fn.transition.settings;
  507. },
  508. animationClass: function(animation) {
  509. var
  510. animationClass = animation || settings.animation,
  511. directionClass = (module.can.transition() && !module.has.direction())
  512. ? module.get.direction() + ' '
  513. : ''
  514. ;
  515. return className.animating + ' '
  516. + className.transition + ' '
  517. + directionClass
  518. + animationClass
  519. ;
  520. },
  521. currentAnimation: function() {
  522. return (module.cache && module.cache.animation !== undefined)
  523. ? module.cache.animation
  524. : false
  525. ;
  526. },
  527. currentDirection: function() {
  528. return module.is.inward()
  529. ? className.inward
  530. : className.outward
  531. ;
  532. },
  533. direction: function() {
  534. return module.is.hidden() || !module.is.visible()
  535. ? className.inward
  536. : className.outward
  537. ;
  538. },
  539. animationDirection: function(animation) {
  540. var
  541. direction
  542. ;
  543. animation = animation || settings.animation;
  544. if(typeof animation === 'string') {
  545. animation = animation.split(' ');
  546. // search animation name for out/in class
  547. $.each(animation, function(index, word){
  548. if(word === className.inward) {
  549. direction = className.inward;
  550. }
  551. else if(word === className.outward) {
  552. direction = className.outward;
  553. }
  554. });
  555. }
  556. // return found direction
  557. if(direction) {
  558. return direction;
  559. }
  560. return false;
  561. },
  562. duration: function(duration) {
  563. duration = duration || settings.duration;
  564. if(duration === false) {
  565. duration = $module.css('animation-duration') || 0;
  566. }
  567. return (typeof duration === 'string')
  568. ? (duration.indexOf('ms') > -1)
  569. ? parseFloat(duration)
  570. : parseFloat(duration) * 1000
  571. : duration
  572. ;
  573. },
  574. displayType: function() {
  575. if(settings.displayType) {
  576. return settings.displayType;
  577. }
  578. if($module.data(metadata.displayType) === undefined) {
  579. // create fake element to determine display state
  580. module.can.transition(true);
  581. }
  582. return $module.data(metadata.displayType);
  583. },
  584. userStyle: function(style) {
  585. style = style || $module.attr('style') || '';
  586. return style.replace(/display.*?;/, '');
  587. },
  588. transitionExists: function(animation) {
  589. return $.fn.transition.exists[animation];
  590. },
  591. animationStartEvent: function() {
  592. var
  593. element = document.createElement('div'),
  594. animations = {
  595. 'animation' :'animationstart',
  596. 'OAnimation' :'oAnimationStart',
  597. 'MozAnimation' :'mozAnimationStart',
  598. 'WebkitAnimation' :'webkitAnimationStart'
  599. },
  600. animation
  601. ;
  602. for(animation in animations){
  603. if( element.style[animation] !== undefined ){
  604. return animations[animation];
  605. }
  606. }
  607. return false;
  608. },
  609. animationEndEvent: function() {
  610. var
  611. element = document.createElement('div'),
  612. animations = {
  613. 'animation' :'animationend',
  614. 'OAnimation' :'oAnimationEnd',
  615. 'MozAnimation' :'mozAnimationEnd',
  616. 'WebkitAnimation' :'webkitAnimationEnd'
  617. },
  618. animation
  619. ;
  620. for(animation in animations){
  621. if( element.style[animation] !== undefined ){
  622. return animations[animation];
  623. }
  624. }
  625. return false;
  626. }
  627. },
  628. can: {
  629. transition: function(forced) {
  630. var
  631. animation = settings.animation,
  632. transitionExists = module.get.transitionExists(animation),
  633. elementClass,
  634. tagName,
  635. $clone,
  636. currentAnimation,
  637. inAnimation,
  638. directionExists,
  639. displayType
  640. ;
  641. if( transitionExists === undefined || forced) {
  642. module.verbose('Determining whether animation exists');
  643. elementClass = $module.attr('class');
  644. tagName = $module.prop('tagName');
  645. $clone = $('<' + tagName + ' />').addClass( elementClass ).insertAfter($module);
  646. currentAnimation = $clone
  647. .addClass(animation)
  648. .removeClass(className.inward)
  649. .removeClass(className.outward)
  650. .addClass(className.animating)
  651. .addClass(className.transition)
  652. .css('animationName')
  653. ;
  654. inAnimation = $clone
  655. .addClass(className.inward)
  656. .css('animationName')
  657. ;
  658. displayType = $clone
  659. .attr('class', elementClass)
  660. .removeAttr('style')
  661. .removeClass(className.hidden)
  662. .removeClass(className.visible)
  663. .show()
  664. .css('display')
  665. ;
  666. module.verbose('Determining final display state', displayType);
  667. module.save.displayType(displayType);
  668. $clone.remove();
  669. if(currentAnimation != inAnimation) {
  670. module.debug('Direction exists for animation', animation);
  671. directionExists = true;
  672. }
  673. else if(currentAnimation == 'none' || !currentAnimation) {
  674. module.debug('No animation defined in css', animation);
  675. return;
  676. }
  677. else {
  678. module.debug('Static animation found', animation, displayType);
  679. directionExists = false;
  680. }
  681. module.save.transitionExists(animation, directionExists);
  682. }
  683. return (transitionExists !== undefined)
  684. ? transitionExists
  685. : directionExists
  686. ;
  687. },
  688. animate: function() {
  689. // can transition does not return a value if animation does not exist
  690. return (module.can.transition() !== undefined);
  691. }
  692. },
  693. is: {
  694. animating: function() {
  695. return $module.hasClass(className.animating);
  696. },
  697. inward: function() {
  698. return $module.hasClass(className.inward);
  699. },
  700. outward: function() {
  701. return $module.hasClass(className.outward);
  702. },
  703. looping: function() {
  704. return $module.hasClass(className.looping);
  705. },
  706. occurring: function(animation) {
  707. animation = animation || settings.animation;
  708. animation = '.' + animation.replace(' ', '.');
  709. return ( $module.filter(animation).length > 0 );
  710. },
  711. visible: function() {
  712. return $module.is(':visible');
  713. },
  714. hidden: function() {
  715. return $module.css('visibility') === 'hidden';
  716. },
  717. supported: function() {
  718. return(animationEnd !== false);
  719. }
  720. },
  721. hide: function() {
  722. module.verbose('Hiding element');
  723. if( module.is.animating() ) {
  724. module.reset();
  725. }
  726. element.blur(); // IE will trigger focus change if element is not blurred before hiding
  727. module.remove.display();
  728. module.remove.visible();
  729. module.set.hidden();
  730. module.force.hidden();
  731. settings.onHide.call(element);
  732. settings.onComplete.call(element);
  733. // module.repaint();
  734. },
  735. show: function(display) {
  736. module.verbose('Showing element', display);
  737. module.remove.hidden();
  738. module.set.visible();
  739. module.force.visible();
  740. settings.onShow.call(element);
  741. settings.onComplete.call(element);
  742. // module.repaint();
  743. },
  744. toggle: function() {
  745. if( module.is.visible() ) {
  746. module.hide();
  747. }
  748. else {
  749. module.show();
  750. }
  751. },
  752. stop: function() {
  753. module.debug('Stopping current animation');
  754. $module.triggerHandler(animationEnd);
  755. },
  756. stopAll: function() {
  757. module.debug('Stopping all animation');
  758. module.remove.queueCallback();
  759. $module.triggerHandler(animationEnd);
  760. },
  761. clear: {
  762. queue: function() {
  763. module.debug('Clearing animation queue');
  764. module.remove.queueCallback();
  765. }
  766. },
  767. enable: function() {
  768. module.verbose('Starting animation');
  769. $module.removeClass(className.disabled);
  770. },
  771. disable: function() {
  772. module.debug('Stopping animation');
  773. $module.addClass(className.disabled);
  774. },
  775. setting: function(name, value) {
  776. module.debug('Changing setting', name, value);
  777. if( $.isPlainObject(name) ) {
  778. $.extend(true, settings, name);
  779. }
  780. else if(value !== undefined) {
  781. if($.isPlainObject(settings[name])) {
  782. $.extend(true, settings[name], value);
  783. }
  784. else {
  785. settings[name] = value;
  786. }
  787. }
  788. else {
  789. return settings[name];
  790. }
  791. },
  792. internal: function(name, value) {
  793. if( $.isPlainObject(name) ) {
  794. $.extend(true, module, name);
  795. }
  796. else if(value !== undefined) {
  797. module[name] = value;
  798. }
  799. else {
  800. return module[name];
  801. }
  802. },
  803. debug: function() {
  804. if(!settings.silent && settings.debug) {
  805. if(settings.performance) {
  806. module.performance.log(arguments);
  807. }
  808. else {
  809. module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
  810. module.debug.apply(console, arguments);
  811. }
  812. }
  813. },
  814. verbose: function() {
  815. if(!settings.silent && settings.verbose && settings.debug) {
  816. if(settings.performance) {
  817. module.performance.log(arguments);
  818. }
  819. else {
  820. module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
  821. module.verbose.apply(console, arguments);
  822. }
  823. }
  824. },
  825. error: function() {
  826. if(!settings.silent) {
  827. module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
  828. module.error.apply(console, arguments);
  829. }
  830. },
  831. performance: {
  832. log: function(message) {
  833. var
  834. currentTime,
  835. executionTime,
  836. previousTime
  837. ;
  838. if(settings.performance) {
  839. currentTime = new Date().getTime();
  840. previousTime = time || currentTime;
  841. executionTime = currentTime - previousTime;
  842. time = currentTime;
  843. performance.push({
  844. 'Name' : message[0],
  845. 'Arguments' : [].slice.call(message, 1) || '',
  846. 'Element' : element,
  847. 'Execution Time' : executionTime
  848. });
  849. }
  850. clearTimeout(module.performance.timer);
  851. module.performance.timer = setTimeout(module.performance.display, 500);
  852. },
  853. display: function() {
  854. var
  855. title = settings.name + ':',
  856. totalTime = 0
  857. ;
  858. time = false;
  859. clearTimeout(module.performance.timer);
  860. $.each(performance, function(index, data) {
  861. totalTime += data['Execution Time'];
  862. });
  863. title += ' ' + totalTime + 'ms';
  864. if(moduleSelector) {
  865. title += ' \'' + moduleSelector + '\'';
  866. }
  867. if($allModules.length > 1) {
  868. title += ' ' + '(' + $allModules.length + ')';
  869. }
  870. if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
  871. console.groupCollapsed(title);
  872. if(console.table) {
  873. console.table(performance);
  874. }
  875. else {
  876. $.each(performance, function(index, data) {
  877. console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
  878. });
  879. }
  880. console.groupEnd();
  881. }
  882. performance = [];
  883. }
  884. },
  885. // modified for transition to return invoke success
  886. invoke: function(query, passedArguments, context) {
  887. var
  888. object = instance,
  889. maxDepth,
  890. found,
  891. response
  892. ;
  893. passedArguments = passedArguments || queryArguments;
  894. context = element || context;
  895. if(typeof query == 'string' && object !== undefined) {
  896. query = query.split(/[\. ]/);
  897. maxDepth = query.length - 1;
  898. $.each(query, function(depth, value) {
  899. var camelCaseValue = (depth != maxDepth)
  900. ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
  901. : query
  902. ;
  903. if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
  904. object = object[camelCaseValue];
  905. }
  906. else if( object[camelCaseValue] !== undefined ) {
  907. found = object[camelCaseValue];
  908. return false;
  909. }
  910. else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
  911. object = object[value];
  912. }
  913. else if( object[value] !== undefined ) {
  914. found = object[value];
  915. return false;
  916. }
  917. else {
  918. return false;
  919. }
  920. });
  921. }
  922. if ( $.isFunction( found ) ) {
  923. response = found.apply(context, passedArguments);
  924. }
  925. else if(found !== undefined) {
  926. response = found;
  927. }
  928. if($.isArray(returnedValue)) {
  929. returnedValue.push(response);
  930. }
  931. else if(returnedValue !== undefined) {
  932. returnedValue = [returnedValue, response];
  933. }
  934. else if(response !== undefined) {
  935. returnedValue = response;
  936. }
  937. return (found !== undefined)
  938. ? found
  939. : false
  940. ;
  941. }
  942. };
  943. module.initialize();
  944. })
  945. ;
  946. return (returnedValue !== undefined)
  947. ? returnedValue
  948. : this
  949. ;
  950. };
  951. // Records if CSS transition is available
  952. $.fn.transition.exists = {};
  953. $.fn.transition.settings = {
  954. // module info
  955. name : 'Transition',
  956. // hide all output from this component regardless of other settings
  957. silent : false,
  958. // debug content outputted to console
  959. debug : false,
  960. // verbose debug output
  961. verbose : false,
  962. // performance data output
  963. performance : true,
  964. // event namespace
  965. namespace : 'transition',
  966. // delay between animations in group
  967. interval : 0,
  968. // whether group animations should be reversed
  969. reverse : 'auto',
  970. // animation callback event
  971. onStart : function() {},
  972. onComplete : function() {},
  973. onShow : function() {},
  974. onHide : function() {},
  975. // whether timeout should be used to ensure callback fires in cases animationend does not
  976. useFailSafe : true,
  977. // delay in ms for fail safe
  978. failSafeDelay : 100,
  979. // whether EXACT animation can occur twice in a row
  980. allowRepeats : false,
  981. // Override final display type on visible
  982. displayType : false,
  983. // animation duration
  984. animation : 'fade',
  985. duration : false,
  986. // new animations will occur after previous ones
  987. queue : true,
  988. metadata : {
  989. displayType: 'display'
  990. },
  991. className : {
  992. animating : 'animating',
  993. disabled : 'disabled',
  994. hidden : 'hidden',
  995. inward : 'in',
  996. loading : 'loading',
  997. looping : 'looping',
  998. outward : 'out',
  999. transition : 'transition',
  1000. visible : 'visible'
  1001. },
  1002. // possible errors
  1003. error: {
  1004. noAnimation : 'Element is no longer attached to DOM. Unable to animate.',
  1005. repeated : 'That animation is already occurring, cancelling repeated animation',
  1006. method : 'The method you called is not defined',
  1007. support : 'This browser does not support CSS animations'
  1008. }
  1009. };
  1010. })( jQuery, window, document );