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.

951 lines
30 KiB

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
  1. /*
  2. * # Semantic - Visibility
  3. * http://github.com/semantic-org/semantic-ui/
  4. *
  5. *
  6. * Copyright 2014 Contributor
  7. * Released under the MIT license
  8. * http://opensource.org/licenses/MIT
  9. *
  10. */
  11. ;(function ( $, window, document, undefined ) {
  12. $.fn.visibility = function(parameters) {
  13. var
  14. $allModules = $(this),
  15. moduleSelector = $allModules.selector || '',
  16. time = new Date().getTime(),
  17. performance = [],
  18. query = arguments[0],
  19. methodInvoked = (typeof query == 'string'),
  20. queryArguments = [].slice.call(arguments, 1),
  21. returnedValue
  22. ;
  23. $allModules
  24. .each(function() {
  25. var
  26. settings = $.extend(true, {}, $.fn.visibility.settings, parameters),
  27. className = settings.className,
  28. namespace = settings.namespace,
  29. error = settings.error,
  30. eventNamespace = '.' + namespace,
  31. moduleNamespace = 'module-' + namespace,
  32. $window = $(window),
  33. $module = $(this),
  34. $context = $(settings.context),
  35. $container = $module.offsetParent(),
  36. selector = $module.selector || '',
  37. instance = $module.data(moduleNamespace),
  38. requestAnimationFrame = window.requestAnimationFrame
  39. || window.mozRequestAnimationFrame
  40. || window.webkitRequestAnimationFrame
  41. || window.msRequestAnimationFrame
  42. || function(callback) { setTimeout(callback, 0); },
  43. element = this,
  44. module
  45. ;
  46. module = {
  47. initialize: function() {
  48. module.verbose('Initializing visibility', settings);
  49. module.setup.cache();
  50. module.save.position();
  51. module.bindEvents();
  52. module.instantiate();
  53. if(settings.type == 'image') {
  54. module.setup.image();
  55. }
  56. if(settings.type == 'fixed') {
  57. module.setup.fixed();
  58. }
  59. requestAnimationFrame(module.checkVisibility);
  60. },
  61. instantiate: function() {
  62. module.verbose('Storing instance of module', module);
  63. instance = module;
  64. $module
  65. .data(moduleNamespace, module)
  66. ;
  67. },
  68. destroy: function() {
  69. module.verbose('Destroying previous module');
  70. $module
  71. .off(eventNamespace)
  72. .removeData(moduleNamespace)
  73. ;
  74. },
  75. bindEvents: function() {
  76. module.verbose('Binding visibility events to scroll and resize');
  77. $window
  78. .on('resize' + eventNamespace, module.event.refresh)
  79. ;
  80. $context
  81. .on('scroll' + eventNamespace, module.event.scroll)
  82. ;
  83. },
  84. event: {
  85. refresh: function() {
  86. requestAnimationFrame(module.refresh);
  87. },
  88. scroll: function() {
  89. module.verbose('Scroll position changed');
  90. if(settings.throttle) {
  91. clearTimeout(module.timer);
  92. module.timer = setTimeout(module.checkVisibility, settings.throttle);
  93. }
  94. else {
  95. requestAnimationFrame(module.checkVisibility);
  96. }
  97. }
  98. },
  99. precache: function(images, callback) {
  100. if (!(images instanceof Array)) {
  101. images = [images];
  102. }
  103. var
  104. imagesLength = images.length,
  105. loadedCounter = 0,
  106. cache = [],
  107. cacheImage = document.createElement('img'),
  108. handleLoad = function() {
  109. loadedCounter++;
  110. if (loadedCounter >= images.length) {
  111. if ($.isFunction(callback)) {
  112. callback();
  113. }
  114. }
  115. }
  116. ;
  117. while (imagesLength--) {
  118. cacheImage = document.createElement('img');
  119. cacheImage.onload = handleLoad;
  120. cacheImage.onerror = handleLoad;
  121. cacheImage.src = images[imagesLength];
  122. cache.push(cacheImage);
  123. }
  124. },
  125. setup: {
  126. cache: function() {
  127. module.cache = {
  128. occurred : {},
  129. screen : {},
  130. element : {},
  131. };
  132. },
  133. image: function() {
  134. var
  135. src = $module.data('src')
  136. ;
  137. if(src) {
  138. module.verbose('Lazy loading image', src);
  139. // show when top visible
  140. module.topVisible(function() {
  141. module.precache(src, function() {
  142. module.set.image(src);
  143. settings.onTopVisible = false;
  144. });
  145. });
  146. }
  147. },
  148. fixed: function() {
  149. module.verbose('Setting up fixed on element pass');
  150. $module
  151. .visibility({
  152. once: false,
  153. continuous: false,
  154. onTopPassed: function() {
  155. $module
  156. .addClass(className.fixed)
  157. .css({
  158. position: 'fixed',
  159. top: settings.offset + 'px'
  160. })
  161. ;
  162. if(settings.animation && $.fn.transition !== undefined) {
  163. $module.transition(settings.transition, settings.duration);
  164. }
  165. },
  166. onTopPassedReverse: function() {
  167. $module
  168. .removeClass(className.fixed)
  169. .css({
  170. position: '',
  171. top: ''
  172. })
  173. ;
  174. }
  175. })
  176. ;
  177. }
  178. },
  179. set: {
  180. image: function(src) {
  181. var
  182. offScreen = (module.cache.screen.bottom < module.cache.element.top)
  183. ;
  184. $module
  185. .attr('src', src)
  186. ;
  187. if(offScreen) {
  188. module.verbose('Image outside browser, avoiding animation')
  189. $module.show();
  190. }
  191. else {
  192. if(settings.transition && $.fn.transition !== undefined) {
  193. $module.transition(settings.transition, settings.duration);
  194. }
  195. else {
  196. $module.fadeIn(settings.duration);
  197. }
  198. }
  199. }
  200. },
  201. refresh: function() {
  202. module.debug('Refreshing constants (element width/height)');
  203. module.reset();
  204. module.save.position();
  205. module.checkVisibility();
  206. $.proxy(settings.onRefresh, element)();
  207. },
  208. reset: function() {
  209. module.verbose('Reseting all cached values');
  210. if( $.isPlainObject(module.cache) ) {
  211. module.cache.screen = {};
  212. module.cache.element = {};
  213. }
  214. },
  215. checkVisibility: function() {
  216. module.verbose('Checking visibility of element', module.cache.element);
  217. module.save.scroll();
  218. module.save.direction();
  219. module.save.screenCalculations();
  220. module.save.elementCalculations();
  221. // percentage
  222. module.passed();
  223. // reverse (must be first)
  224. module.passingReverse();
  225. module.topVisibleReverse();
  226. module.bottomVisibleReverse();
  227. module.topPassedReverse();
  228. module.bottomPassedReverse();
  229. // one time
  230. module.passing();
  231. module.topVisible();
  232. module.bottomVisible();
  233. module.topPassed();
  234. module.bottomPassed();
  235. },
  236. passed: function(amount, newCallback) {
  237. var
  238. calculations = module.get.elementCalculations(),
  239. amountInPixels
  240. ;
  241. // assign callback
  242. if(amount !== undefined && newCallback !== undefined) {
  243. settings.onPassed[amount] = newCallback;
  244. }
  245. else if(amount !== undefined) {
  246. return (module.get.pixelsPassed(amount) > calculations.pixelsPassed);
  247. }
  248. else if(calculations.passing) {
  249. $.each(settings.onPassed, function(amount, callback) {
  250. if(calculations.bottomVisible || calculations.pixelsPassed > module.get.pixelsPassed(amount)) {
  251. module.execute(callback, amount);
  252. }
  253. else if(!settings.once) {
  254. module.remove.occurred(callback);
  255. }
  256. });
  257. }
  258. },
  259. passing: function(newCallback) {
  260. var
  261. calculations = module.get.elementCalculations(),
  262. callback = newCallback || settings.onPassing,
  263. callbackName = 'passing'
  264. ;
  265. if(newCallback) {
  266. module.debug('Adding callback for passing', newCallback);
  267. settings.onPassing = newCallback;
  268. }
  269. if(calculations.passing) {
  270. module.execute(callback, callbackName);
  271. }
  272. else if(!settings.once) {
  273. module.remove.occurred(callbackName);
  274. }
  275. if(newCallback !== undefined) {
  276. return calculations.passing;
  277. }
  278. },
  279. topVisible: function(newCallback) {
  280. var
  281. calculations = module.get.elementCalculations(),
  282. callback = newCallback || settings.onTopVisible,
  283. callbackName = 'topVisible'
  284. ;
  285. if(newCallback) {
  286. module.debug('Adding callback for top visible', newCallback);
  287. settings.onTopVisible = newCallback;
  288. }
  289. if(calculations.topVisible) {
  290. module.execute(callback, callbackName);
  291. }
  292. else if(!settings.once) {
  293. module.remove.occurred(callbackName);
  294. }
  295. if(newCallback === undefined) {
  296. return calculations.topVisible;
  297. }
  298. },
  299. bottomVisible: function(newCallback) {
  300. var
  301. calculations = module.get.elementCalculations(),
  302. callback = newCallback || settings.onBottomVisible,
  303. callbackName = 'bottomVisible'
  304. ;
  305. if(newCallback) {
  306. module.debug('Adding callback for bottom visible', newCallback);
  307. settings.onBottomVisible = newCallback;
  308. }
  309. if(calculations.bottomVisible) {
  310. module.execute(callback, callbackName);
  311. }
  312. else if(!settings.once) {
  313. module.remove.occurred(callbackName);
  314. }
  315. if(newCallback === undefined) {
  316. return calculations.bottomVisible;
  317. }
  318. },
  319. topPassed: function(newCallback) {
  320. var
  321. calculations = module.get.elementCalculations(),
  322. callback = newCallback || settings.onTopPassed,
  323. callbackName = 'topPassed'
  324. ;
  325. if(newCallback) {
  326. module.debug('Adding callback for top passed', newCallback);
  327. settings.onTopPassed = newCallback;
  328. }
  329. if(calculations.topPassed) {
  330. module.execute(callback, callbackName);
  331. }
  332. else if(!settings.once) {
  333. module.remove.occurred(callbackName);
  334. }
  335. if(newCallback === undefined) {
  336. return calculations.onTopPassed;
  337. }
  338. },
  339. bottomPassed: function(newCallback) {
  340. var
  341. calculations = module.get.elementCalculations(),
  342. callback = newCallback || settings.onBottomPassed,
  343. callbackName = 'bottomPassed'
  344. ;
  345. if(newCallback) {
  346. module.debug('Adding callback for bottom passed', newCallback);
  347. settings.onBottomPassed = newCallback;
  348. }
  349. if(calculations.bottomPassed) {
  350. module.execute(callback, callbackName);
  351. }
  352. else if(!settings.once) {
  353. module.remove.occurred(callbackName);
  354. }
  355. if(newCallback === undefined) {
  356. return calculations.bottomPassed;
  357. }
  358. },
  359. passingReverse: function(newCallback) {
  360. var
  361. calculations = module.get.elementCalculations(),
  362. callback = newCallback || settings.onPassingReverse,
  363. callbackName = 'passingReverse'
  364. ;
  365. if(newCallback) {
  366. module.debug('Adding callback for passing reverse', newCallback);
  367. settings.onPassingReverse = newCallback;
  368. }
  369. if(!calculations.passing) {
  370. if(module.get.occurred('passing')) {
  371. module.execute(callback, callbackName);
  372. }
  373. }
  374. else if(!settings.once) {
  375. module.remove.occurred(callbackName);
  376. }
  377. if(newCallback !== undefined) {
  378. return !calculations.passing;
  379. }
  380. },
  381. topVisibleReverse: function(newCallback) {
  382. var
  383. calculations = module.get.elementCalculations(),
  384. callback = newCallback || settings.onTopVisibleReverse,
  385. callbackName = 'topVisibleReverse'
  386. ;
  387. if(newCallback) {
  388. module.debug('Adding callback for top visible reverse', newCallback);
  389. settings.onTopVisibleReverse = newCallback;
  390. }
  391. if(!calculations.topVisible) {
  392. if(module.get.occurred('topVisible')) {
  393. module.execute(callback, callbackName);
  394. }
  395. }
  396. else if(!settings.once) {
  397. module.remove.occurred(callbackName);
  398. }
  399. if(newCallback === undefined) {
  400. return !calculations.topVisible;
  401. }
  402. },
  403. bottomVisibleReverse: function(newCallback) {
  404. var
  405. calculations = module.get.elementCalculations(),
  406. callback = newCallback || settings.onBottomVisibleReverse,
  407. callbackName = 'bottomVisibleReverse'
  408. ;
  409. if(newCallback) {
  410. module.debug('Adding callback for bottom visible reverse', newCallback);
  411. settings.onBottomVisibleReverse = newCallback;
  412. }
  413. if(!calculations.bottomVisible) {
  414. if(module.get.occurred('bottomVisible')) {
  415. module.execute(callback, callbackName);
  416. }
  417. }
  418. else if(!settings.once) {
  419. module.remove.occurred(callbackName);
  420. }
  421. if(newCallback === undefined) {
  422. return !calculations.bottomVisible;
  423. }
  424. },
  425. topPassedReverse: function(newCallback) {
  426. var
  427. calculations = module.get.elementCalculations(),
  428. callback = newCallback || settings.onTopPassedReverse,
  429. callbackName = 'topPassedReverse'
  430. ;
  431. if(newCallback) {
  432. module.debug('Adding callback for top passed reverse', newCallback);
  433. settings.onTopPassedReverse = newCallback;
  434. }
  435. if(!calculations.topPassed) {
  436. if(module.get.occurred('topPassed')) {
  437. module.execute(callback, callbackName);
  438. }
  439. }
  440. else if(!settings.once) {
  441. module.remove.occurred(callbackName);
  442. }
  443. if(newCallback === undefined) {
  444. return !calculations.onTopPassed;
  445. }
  446. },
  447. bottomPassedReverse: function(newCallback) {
  448. var
  449. calculations = module.get.elementCalculations(),
  450. callback = newCallback || settings.onBottomPassedReverse,
  451. callbackName = 'bottomPassedReverse'
  452. ;
  453. if(newCallback) {
  454. module.debug('Adding callback for bottom passed reverse', newCallback);
  455. settings.onBottomPassedReverse = newCallback;
  456. }
  457. if(!calculations.bottomPassed) {
  458. if(module.get.occurred('bottomPassed')) {
  459. module.execute(callback, callbackName);
  460. }
  461. }
  462. else if(!settings.once) {
  463. module.remove.occurred(callbackName);
  464. }
  465. if(newCallback === undefined) {
  466. return !calculations.bottomPassed;
  467. }
  468. },
  469. execute: function(callback, callbackName) {
  470. var
  471. calculations = module.get.elementCalculations(),
  472. screen = module.get.screenCalculations()
  473. ;
  474. callback = callback || false;
  475. if(callback) {
  476. if(settings.continuous) {
  477. module.debug('Callback being called continuously', callbackName, calculations);
  478. $.proxy(callback, element)(calculations, screen);
  479. }
  480. else if(!module.get.occurred(callbackName)) {
  481. module.debug('Conditions met', callbackName, calculations);
  482. $.proxy(callback, element)(calculations, screen);
  483. }
  484. }
  485. module.save.occurred(callbackName);
  486. },
  487. remove: {
  488. occurred: function(callback) {
  489. if(callback) {
  490. if(module.cache.occurred[callback] !== undefined && module.cache.occurred[callback] === true) {
  491. module.debug('Callback can now be called again', callback);
  492. module.cache.occurred[callback] = false;
  493. }
  494. }
  495. else {
  496. module.cache.occurred = {};
  497. }
  498. }
  499. },
  500. save: {
  501. occurred: function(callback) {
  502. if(callback) {
  503. if(module.cache.occurred[callback] === undefined || (module.cache.occurred[callback] !== true)) {
  504. module.verbose('Saving callback occurred', callback);
  505. module.cache.occurred[callback] = true;
  506. }
  507. }
  508. },
  509. scroll: function() {
  510. module.cache.scroll = $context.scrollTop() + settings.offset;
  511. },
  512. direction: function() {
  513. var
  514. scroll = module.get.scroll(),
  515. lastScroll = module.get.lastScroll(),
  516. direction
  517. ;
  518. if(scroll > lastScroll && lastScroll) {
  519. direction = 'down';
  520. }
  521. else if(scroll < lastScroll && lastScroll) {
  522. direction = 'up';
  523. }
  524. else {
  525. direction = 'static';
  526. }
  527. module.cache.direction = direction;
  528. return module.cache.direction;
  529. },
  530. elementPosition: function() {
  531. var
  532. screen = module.get.screenSize()
  533. ;
  534. module.verbose('Saving element position');
  535. $.extend(module.cache.element, {
  536. margin : {
  537. top : parseInt($module.css('margin-top'), 10),
  538. bottom : parseInt($module.css('margin-bottom'), 10)
  539. },
  540. fits : (element.height < screen.height),
  541. offset : $module.offset(),
  542. width : $module.outerWidth(),
  543. height : $module.outerHeight()
  544. });
  545. return module.cache.element;
  546. },
  547. elementCalculations: function() {
  548. var
  549. screen = module.get.screenCalculations(),
  550. element = module.get.elementPosition()
  551. ;
  552. // offset
  553. if(settings.includeMargin) {
  554. $.extend(module.cache.element, {
  555. top : element.offset.top - element.margin.top,
  556. bottom : element.offset.top + element.height + element.margin.bottom
  557. });
  558. }
  559. else {
  560. $.extend(module.cache.element, {
  561. top : element.offset.top,
  562. bottom : element.offset.top + element.height
  563. });
  564. }
  565. // visibility
  566. $.extend(module.cache.element, {
  567. topVisible : (screen.bottom >= element.top),
  568. topPassed : (screen.top >= element.top),
  569. bottomVisible : (screen.bottom >= element.bottom),
  570. bottomPassed : (screen.top >= element.bottom),
  571. pixelsPassed : 0,
  572. percentagePassed : 0
  573. });
  574. // meta calculations
  575. $.extend(module.cache.element, {
  576. visible : (module.cache.element.topVisible || module.cache.element.bottomVisible),
  577. passing : (module.cache.element.topPassed && !module.cache.element.bottomPassed),
  578. hidden : (!module.cache.element.topVisible && !module.cache.element.bottomVisible)
  579. });
  580. if(module.cache.element.passing) {
  581. module.cache.element.pixelsPassed = (screen.top - element.top);
  582. module.cache.element.percentagePassed = (screen.top - element.top) / element.height;
  583. }
  584. module.verbose('Updated element calculations', module.cache.element);
  585. },
  586. screenCalculations: function() {
  587. var
  588. scroll = $context.scrollTop() + settings.offset
  589. ;
  590. if(module.cache.scroll === undefined) {
  591. module.cache.scroll = $context.scrollTop() + settings.offset;
  592. }
  593. module.save.direction();
  594. $.extend(module.cache.screen, {
  595. top : scroll,
  596. bottom : scroll + module.cache.screen.height
  597. });
  598. return module.cache.screen;
  599. },
  600. screenSize: function() {
  601. module.verbose('Saving window position');
  602. module.cache.screen = {
  603. height: $context.height()
  604. };
  605. },
  606. position: function() {
  607. module.save.screenSize();
  608. module.save.elementPosition();
  609. }
  610. },
  611. get: {
  612. pixelsPassed: function(amount) {
  613. var
  614. element = module.get.elementCalculations()
  615. ;
  616. if(amount.search('%') > -1) {
  617. return ( element.height * (parseInt(amount, 10) / 100) );
  618. }
  619. return parseInt(amount, 10);
  620. },
  621. occurred: function(callback) {
  622. return (module.cache.occurred !== undefined)
  623. ? module.cache.occurred[callback] || false
  624. : false
  625. ;
  626. },
  627. direction: function() {
  628. if(module.cache.direction === undefined) {
  629. module.save.direction();
  630. }
  631. return module.cache.direction;
  632. },
  633. elementPosition: function() {
  634. if(module.cache.element === undefined) {
  635. module.save.elementPosition();
  636. }
  637. return module.cache.element;
  638. },
  639. elementCalculations: function() {
  640. if(module.cache.element === undefined) {
  641. module.save.elementCalculations();
  642. }
  643. return module.cache.element;
  644. },
  645. screenCalculations: function() {
  646. if(module.cache.screen === undefined) {
  647. module.save.screenCalculations();
  648. }
  649. return module.cache.screen;
  650. },
  651. screenSize: function() {
  652. if(module.cache.screen === undefined) {
  653. module.save.screenSize();
  654. }
  655. return module.cache.screen;
  656. },
  657. scroll: function() {
  658. if(module.cache.scroll === undefined) {
  659. module.save.scroll();
  660. }
  661. return module.cache.scroll;
  662. },
  663. lastScroll: function() {
  664. if(module.cache.screen === undefined) {
  665. module.debug('First scroll event, no last scroll could be found');
  666. return false;
  667. }
  668. return module.cache.screen.top;
  669. }
  670. },
  671. setting: function(name, value) {
  672. if( $.isPlainObject(name) ) {
  673. $.extend(true, settings, name);
  674. }
  675. else if(value !== undefined) {
  676. settings[name] = value;
  677. }
  678. else {
  679. return settings[name];
  680. }
  681. },
  682. internal: function(name, value) {
  683. if( $.isPlainObject(name) ) {
  684. $.extend(true, module, name);
  685. }
  686. else if(value !== undefined) {
  687. module[name] = value;
  688. }
  689. else {
  690. return module[name];
  691. }
  692. },
  693. debug: function() {
  694. if(settings.debug) {
  695. if(settings.performance) {
  696. module.performance.log(arguments);
  697. }
  698. else {
  699. module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
  700. module.debug.apply(console, arguments);
  701. }
  702. }
  703. },
  704. verbose: function() {
  705. if(settings.verbose && settings.debug) {
  706. if(settings.performance) {
  707. module.performance.log(arguments);
  708. }
  709. else {
  710. module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
  711. module.verbose.apply(console, arguments);
  712. }
  713. }
  714. },
  715. error: function() {
  716. module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
  717. module.error.apply(console, arguments);
  718. },
  719. performance: {
  720. log: function(message) {
  721. var
  722. currentTime,
  723. executionTime,
  724. previousTime
  725. ;
  726. if(settings.performance) {
  727. currentTime = new Date().getTime();
  728. previousTime = time || currentTime;
  729. executionTime = currentTime - previousTime;
  730. time = currentTime;
  731. performance.push({
  732. 'Name' : message[0],
  733. 'Arguments' : [].slice.call(message, 1) || '',
  734. 'Element' : element,
  735. 'Execution Time' : executionTime
  736. });
  737. }
  738. clearTimeout(module.performance.timer);
  739. module.performance.timer = setTimeout(module.performance.display, 100);
  740. },
  741. display: function() {
  742. var
  743. title = settings.name + ':',
  744. totalTime = 0
  745. ;
  746. time = false;
  747. clearTimeout(module.performance.timer);
  748. $.each(performance, function(index, data) {
  749. totalTime += data['Execution Time'];
  750. });
  751. title += ' ' + totalTime + 'ms';
  752. if(moduleSelector) {
  753. title += ' \'' + moduleSelector + '\'';
  754. }
  755. if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
  756. console.groupCollapsed(title);
  757. if(console.table) {
  758. console.table(performance);
  759. }
  760. else {
  761. $.each(performance, function(index, data) {
  762. console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
  763. });
  764. }
  765. console.groupEnd();
  766. }
  767. performance = [];
  768. }
  769. },
  770. invoke: function(query, passedArguments, context) {
  771. var
  772. object = instance,
  773. maxDepth,
  774. found,
  775. response
  776. ;
  777. passedArguments = passedArguments || queryArguments;
  778. context = element || context;
  779. if(typeof query == 'string' && object !== undefined) {
  780. query = query.split(/[\. ]/);
  781. maxDepth = query.length - 1;
  782. $.each(query, function(depth, value) {
  783. var camelCaseValue = (depth != maxDepth)
  784. ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
  785. : query
  786. ;
  787. if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
  788. object = object[camelCaseValue];
  789. }
  790. else if( object[camelCaseValue] !== undefined ) {
  791. found = object[camelCaseValue];
  792. return false;
  793. }
  794. else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
  795. object = object[value];
  796. }
  797. else if( object[value] !== undefined ) {
  798. found = object[value];
  799. return false;
  800. }
  801. else {
  802. return false;
  803. }
  804. });
  805. }
  806. if ( $.isFunction( found ) ) {
  807. response = found.apply(context, passedArguments);
  808. }
  809. else if(found !== undefined) {
  810. response = found;
  811. }
  812. if($.isArray(returnedValue)) {
  813. returnedValue.push(response);
  814. }
  815. else if(returnedValue !== undefined) {
  816. returnedValue = [returnedValue, response];
  817. }
  818. else if(response !== undefined) {
  819. returnedValue = response;
  820. }
  821. return found;
  822. }
  823. };
  824. if(methodInvoked) {
  825. if(instance === undefined) {
  826. module.initialize();
  827. }
  828. module.invoke(query);
  829. }
  830. else {
  831. if(instance !== undefined) {
  832. module.destroy();
  833. }
  834. module.initialize();
  835. }
  836. })
  837. ;
  838. return (returnedValue !== undefined)
  839. ? returnedValue
  840. : this
  841. ;
  842. };
  843. $.fn.visibility.settings = {
  844. name : 'Visibility',
  845. namespace : 'visibility',
  846. className: {
  847. fixed: 'fixed'
  848. },
  849. debug : false,
  850. verbose : false,
  851. performance : true,
  852. offset : 0,
  853. includeMargin : false,
  854. context : window,
  855. // visibility check delay in ms (defaults to animationFrame)
  856. throttle : false,
  857. // special visibility type (image, fixed)
  858. type : false,
  859. // image only settings
  860. transition : false,
  861. duration : 500,
  862. // array of callbacks for percentage
  863. onPassed : {},
  864. // standard callbacks
  865. onPassing : false,
  866. onTopVisible : false,
  867. onBottomVisible : false,
  868. onTopPassed : false,
  869. onBottomPassed : false,
  870. // reverse callbacks
  871. onPassingReverse : false,
  872. onTopVisibleReverse : false,
  873. onBottomVisibleReverse : false,
  874. onTopPassedReverse : false,
  875. onBottomPassedReverse : false,
  876. once : true,
  877. continuous : false,
  878. // utility callbacks
  879. onRefresh : function(){},
  880. onScroll : function(){},
  881. error : {
  882. method : 'The method you called is not defined.'
  883. }
  884. };
  885. })( jQuery, window , document );