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.

936 lines
29 KiB

10 years ago
8 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
8 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
8 years ago
10 years ago
10 years ago
10 years ago
8 years ago
10 years ago
8 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
8 years ago
10 years ago
10 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
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
9 years ago
10 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
9 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
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
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
9 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
9 years ago
9 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
9 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
10 years ago
10 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
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
9 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
9 years ago
10 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
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
10 years ago
9 years ago
10 years ago
10 years ago
8 years ago
10 years ago
  1. /*!
  2. * # Semantic UI 2.2.2 - Sticky
  3. * http://github.com/semantic-org/semantic-ui/
  4. *
  5. *
  6. * Released under the MIT license
  7. * http://opensource.org/licenses/MIT
  8. *
  9. */
  10. ;(function ($, window, document, undefined) {
  11. "use strict";
  12. window = (typeof window != 'undefined' && window.Math == Math)
  13. ? window
  14. : (typeof self != 'undefined' && self.Math == Math)
  15. ? self
  16. : Function('return this')()
  17. ;
  18. $.fn.sticky = function(parameters) {
  19. var
  20. $allModules = $(this),
  21. moduleSelector = $allModules.selector || '',
  22. time = new Date().getTime(),
  23. performance = [],
  24. query = arguments[0],
  25. methodInvoked = (typeof query == 'string'),
  26. queryArguments = [].slice.call(arguments, 1),
  27. returnedValue
  28. ;
  29. $allModules
  30. .each(function() {
  31. var
  32. settings = ( $.isPlainObject(parameters) )
  33. ? $.extend(true, {}, $.fn.sticky.settings, parameters)
  34. : $.extend({}, $.fn.sticky.settings),
  35. className = settings.className,
  36. namespace = settings.namespace,
  37. error = settings.error,
  38. eventNamespace = '.' + namespace,
  39. moduleNamespace = 'module-' + namespace,
  40. $module = $(this),
  41. $window = $(window),
  42. $scroll = $(settings.scrollContext),
  43. $container,
  44. $context,
  45. selector = $module.selector || '',
  46. instance = $module.data(moduleNamespace),
  47. requestAnimationFrame = window.requestAnimationFrame
  48. || window.mozRequestAnimationFrame
  49. || window.webkitRequestAnimationFrame
  50. || window.msRequestAnimationFrame
  51. || function(callback) { setTimeout(callback, 0); },
  52. element = this,
  53. documentObserver,
  54. observer,
  55. module
  56. ;
  57. module = {
  58. initialize: function() {
  59. module.determineContainer();
  60. module.determineContext();
  61. module.verbose('Initializing sticky', settings, $container);
  62. module.save.positions();
  63. module.checkErrors();
  64. module.bind.events();
  65. if(settings.observeChanges) {
  66. module.observeChanges();
  67. }
  68. module.instantiate();
  69. },
  70. instantiate: function() {
  71. module.verbose('Storing instance of module', module);
  72. instance = module;
  73. $module
  74. .data(moduleNamespace, module)
  75. ;
  76. },
  77. destroy: function() {
  78. module.verbose('Destroying previous instance');
  79. module.reset();
  80. if(documentObserver) {
  81. documentObserver.disconnect();
  82. }
  83. if(observer) {
  84. observer.disconnect();
  85. }
  86. $window
  87. .off('load' + eventNamespace, module.event.load)
  88. .off('resize' + eventNamespace, module.event.resize)
  89. ;
  90. $scroll
  91. .off('scrollchange' + eventNamespace, module.event.scrollchange)
  92. ;
  93. $module.removeData(moduleNamespace);
  94. },
  95. observeChanges: function() {
  96. if('MutationObserver' in window) {
  97. documentObserver = new MutationObserver(module.event.documentChanged);
  98. observer = new MutationObserver(module.event.changed);
  99. documentObserver.observe(document, {
  100. childList : true,
  101. subtree : true
  102. });
  103. observer.observe(element, {
  104. childList : true,
  105. subtree : true
  106. });
  107. observer.observe($context[0], {
  108. childList : true,
  109. subtree : true
  110. });
  111. module.debug('Setting up mutation observer', observer);
  112. }
  113. },
  114. determineContainer: function() {
  115. $container = $module.offsetParent();
  116. },
  117. determineContext: function() {
  118. if(settings.context) {
  119. $context = $(settings.context);
  120. }
  121. else {
  122. $context = $container;
  123. }
  124. if($context.length === 0) {
  125. module.error(error.invalidContext, settings.context, $module);
  126. return;
  127. }
  128. },
  129. checkErrors: function() {
  130. if( module.is.hidden() ) {
  131. module.error(error.visible, $module);
  132. }
  133. if(module.cache.element.height > module.cache.context.height) {
  134. module.reset();
  135. module.error(error.elementSize, $module);
  136. return;
  137. }
  138. },
  139. bind: {
  140. events: function() {
  141. $window
  142. .on('load' + eventNamespace, module.event.load)
  143. .on('resize' + eventNamespace, module.event.resize)
  144. ;
  145. // pub/sub pattern
  146. $scroll
  147. .off('scroll' + eventNamespace)
  148. .on('scroll' + eventNamespace, module.event.scroll)
  149. .on('scrollchange' + eventNamespace, module.event.scrollchange)
  150. ;
  151. }
  152. },
  153. event: {
  154. changed: function(mutations) {
  155. clearTimeout(module.timer);
  156. module.timer = setTimeout(function() {
  157. module.verbose('DOM tree modified, updating sticky menu', mutations);
  158. module.refresh();
  159. }, 100);
  160. },
  161. documentChanged: function(mutations) {
  162. [].forEach.call(mutations, function(mutation) {
  163. if(mutation.removedNodes) {
  164. [].forEach.call(mutation.removedNodes, function(node) {
  165. if(node == element || $(node).find(element).length > 0) {
  166. module.debug('Element removed from DOM, tearing down events');
  167. module.destroy();
  168. }
  169. });
  170. }
  171. });
  172. },
  173. load: function() {
  174. module.verbose('Page contents finished loading');
  175. requestAnimationFrame(module.refresh);
  176. },
  177. resize: function() {
  178. module.verbose('Window resized');
  179. requestAnimationFrame(module.refresh);
  180. },
  181. scroll: function() {
  182. requestAnimationFrame(function() {
  183. $scroll.triggerHandler('scrollchange' + eventNamespace, $scroll.scrollTop() );
  184. });
  185. },
  186. scrollchange: function(event, scrollPosition) {
  187. module.stick(scrollPosition);
  188. settings.onScroll.call(element);
  189. }
  190. },
  191. refresh: function(hardRefresh) {
  192. module.reset();
  193. if(!settings.context) {
  194. module.determineContext();
  195. }
  196. if(hardRefresh) {
  197. module.determineContainer();
  198. }
  199. module.save.positions();
  200. module.stick();
  201. settings.onReposition.call(element);
  202. },
  203. supports: {
  204. sticky: function() {
  205. var
  206. $element = $('<div/>'),
  207. element = $element[0]
  208. ;
  209. $element.addClass(className.supported);
  210. return($element.css('position').match('sticky'));
  211. }
  212. },
  213. save: {
  214. lastScroll: function(scroll) {
  215. module.lastScroll = scroll;
  216. },
  217. elementScroll: function(scroll) {
  218. module.elementScroll = scroll;
  219. },
  220. positions: function() {
  221. var
  222. scrollContext = {
  223. height : $scroll.height()
  224. },
  225. element = {
  226. margin: {
  227. top : parseInt($module.css('margin-top'), 10),
  228. bottom : parseInt($module.css('margin-bottom'), 10),
  229. },
  230. offset : $module.offset(),
  231. width : $module.outerWidth(),
  232. height : $module.outerHeight()
  233. },
  234. context = {
  235. offset : $context.offset(),
  236. height : $context.outerHeight()
  237. },
  238. container = {
  239. height: $container.outerHeight()
  240. }
  241. ;
  242. if( !module.is.standardScroll() ) {
  243. module.debug('Non-standard scroll. Removing scroll offset from element offset');
  244. scrollContext.top = $scroll.scrollTop();
  245. scrollContext.left = $scroll.scrollLeft();
  246. element.offset.top += scrollContext.top;
  247. context.offset.top += scrollContext.top;
  248. element.offset.left += scrollContext.left;
  249. context.offset.left += scrollContext.left;
  250. }
  251. module.cache = {
  252. fits : ( element.height < scrollContext.height ),
  253. scrollContext : {
  254. height : scrollContext.height
  255. },
  256. element: {
  257. margin : element.margin,
  258. top : element.offset.top - element.margin.top,
  259. left : element.offset.left,
  260. width : element.width,
  261. height : element.height,
  262. bottom : element.offset.top + element.height
  263. },
  264. context: {
  265. top : context.offset.top,
  266. height : context.height,
  267. bottom : context.offset.top + context.height
  268. }
  269. };
  270. module.set.containerSize();
  271. module.set.size();
  272. module.stick();
  273. module.debug('Caching element positions', module.cache);
  274. }
  275. },
  276. get: {
  277. direction: function(scroll) {
  278. var
  279. direction = 'down'
  280. ;
  281. scroll = scroll || $scroll.scrollTop();
  282. if(module.lastScroll !== undefined) {
  283. if(module.lastScroll < scroll) {
  284. direction = 'down';
  285. }
  286. else if(module.lastScroll > scroll) {
  287. direction = 'up';
  288. }
  289. }
  290. return direction;
  291. },
  292. scrollChange: function(scroll) {
  293. scroll = scroll || $scroll.scrollTop();
  294. return (module.lastScroll)
  295. ? (scroll - module.lastScroll)
  296. : 0
  297. ;
  298. },
  299. currentElementScroll: function() {
  300. if(module.elementScroll) {
  301. return module.elementScroll;
  302. }
  303. return ( module.is.top() )
  304. ? Math.abs(parseInt($module.css('top'), 10)) || 0
  305. : Math.abs(parseInt($module.css('bottom'), 10)) || 0
  306. ;
  307. },
  308. elementScroll: function(scroll) {
  309. scroll = scroll || $scroll.scrollTop();
  310. var
  311. element = module.cache.element,
  312. scrollContext = module.cache.scrollContext,
  313. delta = module.get.scrollChange(scroll),
  314. maxScroll = (element.height - scrollContext.height + settings.offset),
  315. elementScroll = module.get.currentElementScroll(),
  316. possibleScroll = (elementScroll + delta)
  317. ;
  318. if(module.cache.fits || possibleScroll < 0) {
  319. elementScroll = 0;
  320. }
  321. else if(possibleScroll > maxScroll ) {
  322. elementScroll = maxScroll;
  323. }
  324. else {
  325. elementScroll = possibleScroll;
  326. }
  327. return elementScroll;
  328. }
  329. },
  330. remove: {
  331. lastScroll: function() {
  332. delete module.lastScroll;
  333. },
  334. elementScroll: function(scroll) {
  335. delete module.elementScroll;
  336. },
  337. offset: function() {
  338. $module.css('margin-top', '');
  339. }
  340. },
  341. set: {
  342. offset: function() {
  343. module.verbose('Setting offset on element', settings.offset);
  344. $module
  345. .css('margin-top', settings.offset)
  346. ;
  347. },
  348. containerSize: function() {
  349. var
  350. tagName = $container.get(0).tagName
  351. ;
  352. if(tagName === 'HTML' || tagName == 'body') {
  353. // this can trigger for too many reasons
  354. //module.error(error.container, tagName, $module);
  355. module.determineContainer();
  356. }
  357. else {
  358. if( Math.abs($container.outerHeight() - module.cache.context.height) > settings.jitter) {
  359. module.debug('Context has padding, specifying exact height for container', module.cache.context.height);
  360. $container.css({
  361. height: module.cache.context.height
  362. });
  363. }
  364. }
  365. },
  366. minimumSize: function() {
  367. var
  368. element = module.cache.element
  369. ;
  370. $container
  371. .css('min-height', element.height)
  372. ;
  373. },
  374. scroll: function(scroll) {
  375. module.debug('Setting scroll on element', scroll);
  376. if(module.elementScroll == scroll) {
  377. return;
  378. }
  379. if( module.is.top() ) {
  380. $module
  381. .css('bottom', '')
  382. .css('top', -scroll)
  383. ;
  384. }
  385. if( module.is.bottom() ) {
  386. $module
  387. .css('top', '')
  388. .css('bottom', scroll)
  389. ;
  390. }
  391. },
  392. size: function() {
  393. if(module.cache.element.height !== 0 && module.cache.element.width !== 0) {
  394. element.style.setProperty('width', module.cache.element.width + 'px', 'important');
  395. element.style.setProperty('height', module.cache.element.height + 'px', 'important');
  396. }
  397. }
  398. },
  399. is: {
  400. standardScroll: function() {
  401. return ($scroll[0] == window);
  402. },
  403. top: function() {
  404. return $module.hasClass(className.top);
  405. },
  406. bottom: function() {
  407. return $module.hasClass(className.bottom);
  408. },
  409. initialPosition: function() {
  410. return (!module.is.fixed() && !module.is.bound());
  411. },
  412. hidden: function() {
  413. return (!$module.is(':visible'));
  414. },
  415. bound: function() {
  416. return $module.hasClass(className.bound);
  417. },
  418. fixed: function() {
  419. return $module.hasClass(className.fixed);
  420. }
  421. },
  422. stick: function(scroll) {
  423. var
  424. cachedPosition = scroll || $scroll.scrollTop(),
  425. cache = module.cache,
  426. fits = cache.fits,
  427. element = cache.element,
  428. scrollContext = cache.scrollContext,
  429. context = cache.context,
  430. offset = (module.is.bottom() && settings.pushing)
  431. ? settings.bottomOffset
  432. : settings.offset,
  433. scroll = {
  434. top : cachedPosition + offset,
  435. bottom : cachedPosition + offset + scrollContext.height
  436. },
  437. direction = module.get.direction(scroll.top),
  438. elementScroll = (fits)
  439. ? 0
  440. : module.get.elementScroll(scroll.top),
  441. // shorthand
  442. doesntFit = !fits,
  443. elementVisible = (element.height !== 0)
  444. ;
  445. if(elementVisible) {
  446. if( module.is.initialPosition() ) {
  447. if(scroll.top >= context.bottom) {
  448. module.debug('Initial element position is bottom of container');
  449. module.bindBottom();
  450. }
  451. else if(scroll.top > element.top) {
  452. if( (element.height + scroll.top - elementScroll) >= context.bottom ) {
  453. module.debug('Initial element position is bottom of container');
  454. module.bindBottom();
  455. }
  456. else {
  457. module.debug('Initial element position is fixed');
  458. module.fixTop();
  459. }
  460. }
  461. }
  462. else if( module.is.fixed() ) {
  463. // currently fixed top
  464. if( module.is.top() ) {
  465. if( scroll.top <= element.top ) {
  466. module.debug('Fixed element reached top of container');
  467. module.setInitialPosition();
  468. }
  469. else if( (element.height + scroll.top - elementScroll) >= context.bottom ) {
  470. module.debug('Fixed element reached bottom of container');
  471. module.bindBottom();
  472. }
  473. // scroll element if larger than screen
  474. else if(doesntFit) {
  475. module.set.scroll(elementScroll);
  476. module.save.lastScroll(scroll.top);
  477. module.save.elementScroll(elementScroll);
  478. }
  479. }
  480. // currently fixed bottom
  481. else if(module.is.bottom() ) {
  482. // top edge
  483. if( (scroll.bottom - element.height) <= element.top) {
  484. module.debug('Bottom fixed rail has reached top of container');
  485. module.setInitialPosition();
  486. }
  487. // bottom edge
  488. else if(scroll.bottom >= context.bottom) {
  489. module.debug('Bottom fixed rail has reached bottom of container');
  490. module.bindBottom();
  491. }
  492. // scroll element if larger than screen
  493. else if(doesntFit) {
  494. module.set.scroll(elementScroll);
  495. module.save.lastScroll(scroll.top);
  496. module.save.elementScroll(elementScroll);
  497. }
  498. }
  499. }
  500. else if( module.is.bottom() ) {
  501. if( scroll.top <= element.top ) {
  502. module.debug('Jumped from bottom fixed to top fixed, most likely used home/end button');
  503. module.setInitialPosition();
  504. }
  505. else {
  506. if(settings.pushing) {
  507. if(module.is.bound() && scroll.bottom <= context.bottom ) {
  508. module.debug('Fixing bottom attached element to bottom of browser.');
  509. module.fixBottom();
  510. }
  511. }
  512. else {
  513. if(module.is.bound() && (scroll.top <= context.bottom - element.height) ) {
  514. module.debug('Fixing bottom attached element to top of browser.');
  515. module.fixTop();
  516. }
  517. }
  518. }
  519. }
  520. }
  521. },
  522. bindTop: function() {
  523. module.debug('Binding element to top of parent container');
  524. module.remove.offset();
  525. $module
  526. .css({
  527. left : '',
  528. top : '',
  529. marginBottom : ''
  530. })
  531. .removeClass(className.fixed)
  532. .removeClass(className.bottom)
  533. .addClass(className.bound)
  534. .addClass(className.top)
  535. ;
  536. settings.onTop.call(element);
  537. settings.onUnstick.call(element);
  538. },
  539. bindBottom: function() {
  540. module.debug('Binding element to bottom of parent container');
  541. module.remove.offset();
  542. $module
  543. .css({
  544. left : '',
  545. top : ''
  546. })
  547. .removeClass(className.fixed)
  548. .removeClass(className.top)
  549. .addClass(className.bound)
  550. .addClass(className.bottom)
  551. ;
  552. settings.onBottom.call(element);
  553. settings.onUnstick.call(element);
  554. },
  555. setInitialPosition: function() {
  556. module.debug('Returning to initial position');
  557. module.unfix();
  558. module.unbind();
  559. },
  560. fixTop: function() {
  561. module.debug('Fixing element to top of page');
  562. module.set.minimumSize();
  563. module.set.offset();
  564. $module
  565. .css({
  566. left : module.cache.element.left,
  567. bottom : '',
  568. marginBottom : ''
  569. })
  570. .removeClass(className.bound)
  571. .removeClass(className.bottom)
  572. .addClass(className.fixed)
  573. .addClass(className.top)
  574. ;
  575. settings.onStick.call(element);
  576. },
  577. fixBottom: function() {
  578. module.debug('Sticking element to bottom of page');
  579. module.set.minimumSize();
  580. module.set.offset();
  581. $module
  582. .css({
  583. left : module.cache.element.left,
  584. bottom : '',
  585. marginBottom : ''
  586. })
  587. .removeClass(className.bound)
  588. .removeClass(className.top)
  589. .addClass(className.fixed)
  590. .addClass(className.bottom)
  591. ;
  592. settings.onStick.call(element);
  593. },
  594. unbind: function() {
  595. if( module.is.bound() ) {
  596. module.debug('Removing container bound position on element');
  597. module.remove.offset();
  598. $module
  599. .removeClass(className.bound)
  600. .removeClass(className.top)
  601. .removeClass(className.bottom)
  602. ;
  603. }
  604. },
  605. unfix: function() {
  606. if( module.is.fixed() ) {
  607. module.debug('Removing fixed position on element');
  608. module.remove.offset();
  609. $module
  610. .removeClass(className.fixed)
  611. .removeClass(className.top)
  612. .removeClass(className.bottom)
  613. ;
  614. settings.onUnstick.call(element);
  615. }
  616. },
  617. reset: function() {
  618. module.debug('Resetting elements position');
  619. module.unbind();
  620. module.unfix();
  621. module.resetCSS();
  622. module.remove.offset();
  623. module.remove.lastScroll();
  624. },
  625. resetCSS: function() {
  626. $module
  627. .css({
  628. width : '',
  629. height : ''
  630. })
  631. ;
  632. $container
  633. .css({
  634. height: ''
  635. })
  636. ;
  637. },
  638. setting: function(name, value) {
  639. if( $.isPlainObject(name) ) {
  640. $.extend(true, settings, name);
  641. }
  642. else if(value !== undefined) {
  643. settings[name] = value;
  644. }
  645. else {
  646. return settings[name];
  647. }
  648. },
  649. internal: function(name, value) {
  650. if( $.isPlainObject(name) ) {
  651. $.extend(true, module, name);
  652. }
  653. else if(value !== undefined) {
  654. module[name] = value;
  655. }
  656. else {
  657. return module[name];
  658. }
  659. },
  660. debug: function() {
  661. if(!settings.silent && settings.debug) {
  662. if(settings.performance) {
  663. module.performance.log(arguments);
  664. }
  665. else {
  666. module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
  667. module.debug.apply(console, arguments);
  668. }
  669. }
  670. },
  671. verbose: function() {
  672. if(!settings.silent && settings.verbose && settings.debug) {
  673. if(settings.performance) {
  674. module.performance.log(arguments);
  675. }
  676. else {
  677. module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
  678. module.verbose.apply(console, arguments);
  679. }
  680. }
  681. },
  682. error: function() {
  683. if(!settings.silent) {
  684. module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
  685. module.error.apply(console, arguments);
  686. }
  687. },
  688. performance: {
  689. log: function(message) {
  690. var
  691. currentTime,
  692. executionTime,
  693. previousTime
  694. ;
  695. if(settings.performance) {
  696. currentTime = new Date().getTime();
  697. previousTime = time || currentTime;
  698. executionTime = currentTime - previousTime;
  699. time = currentTime;
  700. performance.push({
  701. 'Name' : message[0],
  702. 'Arguments' : [].slice.call(message, 1) || '',
  703. 'Element' : element,
  704. 'Execution Time' : executionTime
  705. });
  706. }
  707. clearTimeout(module.performance.timer);
  708. module.performance.timer = setTimeout(module.performance.display, 0);
  709. },
  710. display: function() {
  711. var
  712. title = settings.name + ':',
  713. totalTime = 0
  714. ;
  715. time = false;
  716. clearTimeout(module.performance.timer);
  717. $.each(performance, function(index, data) {
  718. totalTime += data['Execution Time'];
  719. });
  720. title += ' ' + totalTime + 'ms';
  721. if(moduleSelector) {
  722. title += ' \'' + moduleSelector + '\'';
  723. }
  724. if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
  725. console.groupCollapsed(title);
  726. if(console.table) {
  727. console.table(performance);
  728. }
  729. else {
  730. $.each(performance, function(index, data) {
  731. console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
  732. });
  733. }
  734. console.groupEnd();
  735. }
  736. performance = [];
  737. }
  738. },
  739. invoke: function(query, passedArguments, context) {
  740. var
  741. object = instance,
  742. maxDepth,
  743. found,
  744. response
  745. ;
  746. passedArguments = passedArguments || queryArguments;
  747. context = element || context;
  748. if(typeof query == 'string' && object !== undefined) {
  749. query = query.split(/[\. ]/);
  750. maxDepth = query.length - 1;
  751. $.each(query, function(depth, value) {
  752. var camelCaseValue = (depth != maxDepth)
  753. ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
  754. : query
  755. ;
  756. if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
  757. object = object[camelCaseValue];
  758. }
  759. else if( object[camelCaseValue] !== undefined ) {
  760. found = object[camelCaseValue];
  761. return false;
  762. }
  763. else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
  764. object = object[value];
  765. }
  766. else if( object[value] !== undefined ) {
  767. found = object[value];
  768. return false;
  769. }
  770. else {
  771. return false;
  772. }
  773. });
  774. }
  775. if ( $.isFunction( found ) ) {
  776. response = found.apply(context, passedArguments);
  777. }
  778. else if(found !== undefined) {
  779. response = found;
  780. }
  781. if($.isArray(returnedValue)) {
  782. returnedValue.push(response);
  783. }
  784. else if(returnedValue !== undefined) {
  785. returnedValue = [returnedValue, response];
  786. }
  787. else if(response !== undefined) {
  788. returnedValue = response;
  789. }
  790. return found;
  791. }
  792. };
  793. if(methodInvoked) {
  794. if(instance === undefined) {
  795. module.initialize();
  796. }
  797. module.invoke(query);
  798. }
  799. else {
  800. if(instance !== undefined) {
  801. instance.invoke('destroy');
  802. }
  803. module.initialize();
  804. }
  805. })
  806. ;
  807. return (returnedValue !== undefined)
  808. ? returnedValue
  809. : this
  810. ;
  811. };
  812. $.fn.sticky.settings = {
  813. name : 'Sticky',
  814. namespace : 'sticky',
  815. silent : false,
  816. debug : false,
  817. verbose : true,
  818. performance : true,
  819. // whether to stick in the opposite direction on scroll up
  820. pushing : false,
  821. context : false,
  822. // Context to watch scroll events
  823. scrollContext : window,
  824. // Offset to adjust scroll
  825. offset : 0,
  826. // Offset to adjust scroll when attached to bottom of screen
  827. bottomOffset : 0,
  828. jitter : 5, // will only set container height if difference between context and container is larger than this number
  829. // Whether to automatically observe changes with Mutation Observers
  830. observeChanges : false,
  831. // Called when position is recalculated
  832. onReposition : function(){},
  833. // Called on each scroll
  834. onScroll : function(){},
  835. // Called when element is stuck to viewport
  836. onStick : function(){},
  837. // Called when element is unstuck from viewport
  838. onUnstick : function(){},
  839. // Called when element reaches top of context
  840. onTop : function(){},
  841. // Called when element reaches bottom of context
  842. onBottom : function(){},
  843. error : {
  844. container : 'Sticky element must be inside a relative container',
  845. visible : 'Element is hidden, you must call refresh after element becomes visible. Use silent setting to surpress this warning in production.',
  846. method : 'The method you called is not defined.',
  847. invalidContext : 'Context specified does not exist',
  848. elementSize : 'Sticky element is larger than its container, cannot create sticky.'
  849. },
  850. className : {
  851. bound : 'bound',
  852. fixed : 'fixed',
  853. supported : 'native',
  854. top : 'top',
  855. bottom : 'bottom'
  856. }
  857. };
  858. })( jQuery, window, document );