1/** 2 * Custom made solution for featherlight. 3 */ 4function sv_featherlight(element, configuration) { 5 return (function(el, conf) { 6 var ROOT_CLASS = [ 'featherlight' ], CLOSE_BTN_CLASS = [ 7 'featherlight-close-icon', 'featherlight-close' ], CONTENT_CLASS = [ 'featherlight-content' ], INNER_CONTENT_CLASS = [ 'featherlight-inner' ], _body = document 8 .querySelector('body'), _innerContent = _configureInnerContent(), _content = conf 9 && conf.hideX ? _configureContent(_innerContent) 10 : _configureContent(_configureCloseButton(), _innerContent), _root = _configureRoot(_content); 11 12 init(); 13 return { 14 open : _open, 15 close : _close, 16 }; 17 18 function init() { 19 _open(); 20 } 21 22 /** 23 * Apply classes list to element. 24 * 25 * @param {Node} 26 * el 27 * @param {Array} 28 * classes 29 */ 30 function _applyClasses(el, classes) { 31 classes.forEach(function(item) { 32 el.classList.add(item); 33 }); 34 } 35 36 /** 37 * Configure root element. 38 * 39 * @param {Node} 40 * content 41 * @returns {Node} element 42 */ 43 function _configureRoot(content) { 44 var rootEl = document.createElement('div'); 45 _applyClasses(rootEl, ROOT_CLASS); 46 rootEl.style.display = 'block'; 47 rootEl.appendChild(content); 48 return rootEl; 49 } 50 51 /** 52 * Configure close button. 53 * 54 * @returns {Node} element 55 */ 56 function _configureCloseButton() { 57 var button = document.createElement('button'); 58 _applyClasses(button, CLOSE_BTN_CLASS); 59 button.setAttribute('aria-label', 'Close'); 60 button.addEventListener('click', _close); 61 button.innerHTML = 'â'; 62 return button; 63 } 64 65 /** 66 * Configure inner content. 67 * 68 * @returns {Node} element 69 */ 70 function _configureInnerContent() { 71 var innerContent = el.cloneNode(true); 72 _applyClasses(innerContent, INNER_CONTENT_CLASS); 73 return innerContent; 74 } 75 76 /** 77 * Configure content container. 78 * 79 * @returns {Node} element 80 */ 81 function _configureContent() { 82 var content = document.createElement('div'); 83 _applyClasses(content, CONTENT_CLASS); 84 _forEach(arguments, function(item) { 85 content.appendChild(item); 86 }); 87 return content; 88 } 89 90 function _forEach(array, func) { 91 for (var i = 0; i < array.length; i++) { 92 func(array[i], i); 93 } 94 } 95 96 /** 97 * Open the pop-up. 98 */ 99 function _open() { 100 (conf.beforeOpen || noop).apply(null, arguments); 101 _body.appendChild(_root); 102 (conf.afterContent || noop).apply(null, arguments); 103 } 104 105 /** 106 * Close the pop-up. 107 */ 108 function _close() { 109 if (_body.contains(_root)) { 110 (conf.beforeClose || noop).apply(null, arguments); 111 _body.removeChild(_root); 112 (conf.afterClose || noop).apply(null, arguments); 113 } 114 } 115 })(element, configuration); 116}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.