forked from brunoti/table-link
-
Notifications
You must be signed in to change notification settings - Fork 0
/
table-link.min.js
1 lines (1 loc) · 4.36 KB
/
table-link.min.js
1
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.TableLink=f()}})(function(){var define,module,exports;return function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r}()({1:[function(require,module,exports){try{var query=require("query")}catch(err){var query=require("component-query")}var proto=Element.prototype;var vendor=proto.matches||proto.webkitMatchesSelector||proto.mozMatchesSelector||proto.msMatchesSelector||proto.oMatchesSelector;module.exports=match;function match(el,selector){if(!el||el.nodeType!==1)return false;if(vendor)return vendor.call(el,selector);var nodes=query.all(selector,el.parentNode);for(var i=0;i<nodes.length;++i){if(nodes[i]==el)return true}return false}},{"component-query":2,query:2}],2:[function(require,module,exports){function one(selector,el){return el.querySelector(selector)}exports=module.exports=function(selector,el){el=el||document;return one(selector,el)};exports.all=function(selector,el){el=el||document;return el.querySelectorAll(selector)};exports.engine=function(obj){if(!obj.one)throw new Error(".one callback required");if(!obj.all)throw new Error(".all callback required");one=obj.one;exports.all=obj.all;return exports}},{}],3:[function(require,module,exports){var DOCUMENT_NODE_TYPE=9;if(typeof Element!=="undefined"&&!Element.prototype.matches){var proto=Element.prototype;proto.matches=proto.matchesSelector||proto.mozMatchesSelector||proto.msMatchesSelector||proto.oMatchesSelector||proto.webkitMatchesSelector}function closest(element,selector){while(element&&element.nodeType!==DOCUMENT_NODE_TYPE){if(typeof element.matches==="function"&&element.matches(selector)){return element}element=element.parentNode}}module.exports=closest},{}],4:[function(require,module,exports){var closest=require("./closest");function _delegate(element,selector,type,callback,useCapture){var listenerFn=listener.apply(this,arguments);element.addEventListener(type,listenerFn,useCapture);return{destroy:function(){element.removeEventListener(type,listenerFn,useCapture)}}}function delegate(elements,selector,type,callback,useCapture){if(typeof elements.addEventListener==="function"){return _delegate.apply(null,arguments)}if(typeof type==="function"){return _delegate.bind(null,document).apply(null,arguments)}if(typeof elements==="string"){elements=document.querySelectorAll(elements)}return Array.prototype.map.call(elements,function(element){return _delegate(element,selector,type,callback,useCapture)})}function listener(element,selector,type,callback){return function(e){e.delegateTarget=closest(e.target,selector);if(e.delegateTarget){callback.call(element,e)}}}module.exports=delegate},{"./closest":3}],5:[function(require,module,exports){var delegate=require("delegate");var matches=require("component-matches-selector");var beforeFn,afterFn;var TableLink={init:function(matchString){matchString=matchString?matchString+",tr,th,td":"tr,th,td";beforeFn=function(){return true};afterFn=function(){};return addTableLinks.call(this,matchString)},before:function(callback){beforeFn=callback.bind(this);return this},after:function(callback){afterFn=callback.bind(this);return this}};function addTableLinks(matchString){var body=document.body;var selector="[data-href]";return delegate(body,selector,"mouseup",function(event){var element=event.delegateTarget;var eventTarget=event.target;var href=element.getAttribute("data-href");var target=element.getAttribute("data-target");if(!matches(eventTarget,matchString)){return null}event.preventDefault();var before=beforeFn(event);if(before===false){return null}if(event.ctrlKey||event.button===1||target==="blank"){var newWindow=window.open(href);afterFn(event);newWindow.focus();return}location.assign(href);afterFn(event)},true)}module.exports=TableLink},{"component-matches-selector":1,delegate:4}]},{},[5])(5)});