UNPKG

12.5 kBJavaScriptView Raw
1/*!
2 * Copyright (c) 2017 NAVER Corp.
3 * @egjs/visible project is licensed under the MIT license
4 *
5 * @egjs/visible JavaScript library
6 * https://naver.github.io/egjs-visible/
7 *
8 * @version 2.2.0
9 *
10 * All-in-one packaged file for ease use of '@egjs/visible' with below dependencies.
11 * NOTE: This is not an official distribution file and is only for user convenience.
12 *
13 */
14!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Visible=t():(e.eg=e.eg||{},e.eg.Visible=t())}(this,function(){return function(e){function __webpack_require__(r){if(t[r])return t[r].exports;var n=t[r]={i:r,l:!1,exports:{}};return e[r].call(n.exports,n,n.exports,__webpack_require__),n.l=!0,n.exports}var t={};return __webpack_require__.m=e,__webpack_require__.c=t,__webpack_require__.d=function(e,t,r){__webpack_require__.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},__webpack_require__.n=function(e){var t=e&&e.__esModule?function(){return e["default"]}:function(){return e};return __webpack_require__.d(t,"a",t),t},__webpack_require__.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},__webpack_require__.p="",__webpack_require__(__webpack_require__.s=0)}([function(e,t,r){"use strict";var n=r(1),o=function(e){return e&&e.__esModule?e:{"default":e}}(n);e.exports=o["default"]},function(e,t,r){"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}t.__esModule=!0;var n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i=r(2),s=function(e){return e&&e.__esModule?e:{"default":e}}(i),u=r(3);"function"!=typeof Object.create&&(Object.create=function(e,t){function F(){}if("object"!==(void 0===e?"undefined":o(e))&&"function"!=typeof e)throw new TypeError("Object prototype may only be an Object: "+e);if(null===e)throw new Error("This browser's implementation of Object.create is a shim and doesn't support 'null' as the first argument.");return F.prototype=e,new F});var c=!!window.IntersectionObserver,a=function(){var e=document.createElement("div");if(!e.getElementsByClassName)return!1;var t=e.getElementsByClassName("dummy");return e.innerHTML="<span class='dummy'></span>",1===t.length}(),l=function(e){function Visible(t,r){_classCallCheck(this,Visible);var o=_possibleConstructorReturn(this,e.call(this));return o.options={targetClass:"check_visible",expandSize:0},n(o.options,r),o._wrapper=(0,u.$)(t)||document,o._wrapper.nodeType&&1===o._wrapper.nodeType?o._getAreaRect=o._getWrapperRect:o._getAreaRect=u.getWindowRect,o._targets=[],o._timer=null,o.refresh(),o}return _inherits(Visible,e),Visible.prototype.refresh=function(){return a?(this._targets=this._wrapper.getElementsByClassName(this.options.targetClass),this.refresh=function(){return this._refreshObserver(),this}):this.refresh=function(){var e=this._wrapper.querySelectorAll("."+this.options.targetClass);this._targets=[];for(var t=0;t<e.length;t++)this._targets.push(e[t]);return this._refreshObserver(),this},this.refresh()},Visible.prototype.check=function(){var e=this,t=arguments.length<=0?undefined:arguments[0],r=arguments.length<=1?undefined:arguments[1];return"number"!=typeof t&&(r=t,t=-1),void 0===t&&(t=-1),void 0===r&&(r=!1),clearTimeout(this._timer),t<0?(this._check(r),this._checkAfter()):this._timer=setTimeout(function(){e._check(r),e._checkAfter(),e._timer=null},t),this},Visible.prototype.getVisibleElements=function(){for(var e=this._targets,t=[],r=0;r<e.length;r++){var n=e[r];n&&!0===n.__VISIBLE__&&t.push(n)}return t},Visible.prototype._getWrapperRect=function(){return this._wrapper.getBoundingClientRect()},Visible.prototype._reviseElements=function(){var e=this;return this._reviseElements=a?function(){return!0}:function(t,r){return!!(0,u.hasClass)(t,e.options.targetClass)||(t.__VISIBLE__=null,e._targets.splice(r,1),!1)},this._reviseElements.apply(this,arguments)},Visible.prototype._check=function(e){var t=parseInt(this.options.expandSize,10),r=void 0,n=void 0,o=void 0,i=void 0,s=this._getAreaRect(),u={top:s.top-t,left:s.left-t,bottom:s.bottom+t,right:s.right+t};for(r=this._targets.length-1;n=this._targets[r];r--)o=n.getBoundingClientRect(),0===o.width&&0===o.height||this._reviseElements(n,r)&&(i=e?!(o.top<u.top||o.bottom>u.bottom||o.right>u.right||o.left<u.left):!(o.bottom<u.top||u.bottom<o.top||o.right<u.left||u.right<o.left),n.__AFTER__=i)},Visible.prototype.checkObserve=function(){var e=this,t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:-1;return this._timer&&(clearTimeout(this._timer),this._timer=0),t<0?this._checkAfter():this._timer=setTimeout(function(){e._checkAfter(),e._timer=null},t),this},Visible.prototype._checkAfter=function(){for(var e=this._targets,t=e.length,r=[],n=[],o=0;o<t;++o){var i=e[o],s=i.__VISIBLE__,u=i.__AFTER__;s!==u&&(u?r.push(i):n.push(i),i.__VISIBLE__=u)}0===r.length&&0===n.length||this.trigger("change",{visible:r,invisible:n,isTrusted:!0})},Visible.prototype.observe=function(){var e=this,t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};if(!c)return this._addObserveEvent(t),this;var r="undefined"==typeof t.delay?-1:t.delay,n=!!t.containment;this._observeCallback=function(t){t.forEach(function(e){e.target.__AFTER__=n?e.intersectionRatio>=1:e.isIntersecting}),e._checkAfter(r)},this._observer&&this.unobserve(),this._observer=new IntersectionObserver(this._observeCallback,{root:1===this._wrapper.nodeType?this._wrapper:null,rootMargin:this.options.expandSize+"px",threshold:n?[0,1]:[0]});for(var o=this._observer,i=this._targets,s=i.length,u=0;u<s;++u)o.observe(i[u]);return this},Visible.prototype.unobserve=function(){return this._observeCallback?(c?this._observer&&this._observer.disconnect():((0,u.removeEvent)(this._wrapper,"scroll",this._observeCallback),(0,u.removeEvent)(this._wrapper,"resize",this._observeCallback)),this._observer=null,this._observeCallback=null,this):this},Visible.prototype._refreshObserver=function(){if(this._observer){this._observer.disconnect();for(var e=this._targets,t=e.length,r=0;r<t;++r)this._observer.observe(e[r])}},Visible.prototype._addObserveEvent=function(){var e=this,t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};if(!this._observeCallback){var r="undefined"==typeof t.delay?-1:t.delay,n=!!t.containment;this._observeCallback=function(t){e._check(n),e.checkObserve(r)},(0,u.addEvent)(this._wrapper,"scroll",this._observeCallback),(0,u.addEvent)(this._wrapper,"resize",this._observeCallback),this._observeCallback()}},Visible.prototype.destroy=function(){this.off(),this.unobserve(),this._targets=[],this._wrapper=null,this._timer=null},Visible}(s["default"]);l.VERSION="2.2.0",t["default"]=l,e.exports=t["default"]},function(e,t,r){!function(t,r){e.exports=r()}(0,function(){return function(e){function __webpack_require__(r){if(t[r])return t[r].exports;var n=t[r]={i:r,l:!1,exports:{}};return e[r].call(n.exports,n,n.exports,__webpack_require__),n.l=!0,n.exports}var t={};return __webpack_require__.m=e,__webpack_require__.c=t,__webpack_require__.d=function(e,t,r){__webpack_require__.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},__webpack_require__.n=function(e){var t=e&&e.__esModule?function(){return e["default"]}:function(){return e};return __webpack_require__.d(t,"a",t),t},__webpack_require__.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},__webpack_require__.p="",__webpack_require__(__webpack_require__.s=0)}([function(e,t,r){"use strict";var n=r(1),o=function(e){return e&&e.__esModule?e:{"default":e}}(n);o["default"].VERSION="2.1.0",e.exports=o["default"]},function(e,t,r){"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}t.__esModule=!0;var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=function(){function Component(){_classCallCheck(this,Component),this._eventHandler={},this.options={}}return Component.prototype.trigger=function(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{},r=this._eventHandler[e]||[];if(!(r.length>0))return!0;r=r.concat(),t.eventType=e;var n=!1,o=[t],i=0;t.stop=function(){n=!0},t.currentTarget=this;for(var s=arguments.length,u=Array(s>2?s-2:0),c=2;c<s;c++)u[c-2]=arguments[c];for(u.length>=1&&(o=o.concat(u)),i=0;r[i];i++)r[i].apply(this,o);return!n},Component.prototype.once=function(e,t){if("object"===(void 0===e?"undefined":n(e))&&void 0===t){var r=e,o=void 0;for(o in r)this.once(o,r[o]);return this}if("string"==typeof e&&"function"==typeof t){var i=this;this.on(e,function listener(){for(var r=arguments.length,n=Array(r),o=0;o<r;o++)n[o]=arguments[o];t.apply(i,n),i.off(e,listener)})}return this},Component.prototype.hasOn=function(e){return!!this._eventHandler[e]},Component.prototype.on=function(e,t){if("object"===(void 0===e?"undefined":n(e))&&void 0===t){var r=e,o=void 0;for(o in r)this.on(o,r[o]);return this}if("string"==typeof e&&"function"==typeof t){var i=this._eventHandler[e];void 0===i&&(this._eventHandler[e]=[],i=this._eventHandler[e]),i.push(t)}return this},Component.prototype.off=function(e,t){if(void 0===e)return this._eventHandler={},this;if(void 0===t){if("string"==typeof e)return this._eventHandler[e]=undefined,this;var r=e,n=void 0;for(n in r)this.off(n,r[n]);return this}var o=this._eventHandler[e];if(o){var i=void 0,s=void 0;for(i=0;(s=o[i])!==undefined;i++)if(s===t){o=o.splice(i,1);break}}return this},Component}();t["default"]=o,e.exports=t["default"]}])})},function(e,t,r){"use strict";function toArray(e){var t=[];if(e)for(var r=0,n=e.length;r<n;r++)t.push(e[r]);return t}function $(e){var t=arguments.length>1&&arguments[1]!==undefined&&arguments[1],r=void 0;if(e===undefined)return undefined;if("string"==typeof e){if(e.match(/^<([a-z]+)\s*([^>]*)>/)){var n=document.createElement("div");n.innerHTML=e,r=toArray(n.childNodes)}else r=toArray(document.querySelectorAll(e));t||(r=r.length>=1?r[0]:undefined)}else e===window?r=e:!e.nodeName||1!==e.nodeType&&9!==e.nodeType?"jQuery"in window&&e instanceof jQuery||e.constructor.prototype.jquery?r=t?e.toArray():e.get(0):Array.isArray(e)&&(r=e.map(function(e){return $(e)}),t||(r=r.length>=1?r[0]:undefined)):r=e;return r}function getWindowRect(){return{top:0,left:0,bottom:window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight,right:window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth}}function hasClass(e,t){return e.classList?e.classList.contains(t):new RegExp("(^| )"+t+"( |$)","gi").test(e.className)}function addEvent(e,t,r,s){if(o){var u=s||!1;"object"===(void 0===s?"undefined":n(s))&&(u=!!i&&s),e.addEventListener(t,r,u)}else e.attachEvent?e.attachEvent("on"+t,r):e["on"+t]=r}function removeEvent(e,t,r){e.removeEventListener?e.removeEventListener(t,r,!1):e.detachEvent?e.detachEvent("on"+t,r):e["on"+t]=null}t.__esModule=!0;var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};t.toArray=toArray,t.$=$,t.getWindowRect=getWindowRect,t.hasClass=hasClass,t.addEvent=addEvent,t.removeEvent=removeEvent;var o=!!("addEventListener"in document),i=function(){var e=!1;try{o&&Object.defineProperty&&document.addEventListener("test",null,Object.defineProperty({},"passive",{get:function(){e=!0}}))}catch(t){}return e}()}])});
\No newline at end of file