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.

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