0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-01-06 22:40:26 -05:00
verdaccio/node_modules/onclick/examples/build.js
2014-09-14 18:28:17 +04:00

208 lines
No EOL
5.7 KiB
JavaScript

!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.onClick=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
var click = _dereq_("../src/onClick.js");
click({
'#element': function(e) {
alert("You clicked!");
}
});
click('.elementSet', function(e) {
alert("You clicked the set");
});
},{"../src/onClick.js":3}],2:[function(_dereq_,module,exports){
(function (global){
(function(root) {
var unopinionate = {
selector: root.jQuery || root.Zepto || root.ender || root.$,
template: root.Handlebars || root.Mustache
};
/*** Export ***/
//AMD
if(typeof define === 'function' && define.amd) {
define([], function() {
return unopinionate;
});
}
//CommonJS
else if(typeof module.exports !== 'undefined') {
module.exports = unopinionate;
}
//Global
else {
root.unopinionate = unopinionate;
}
})(typeof window != 'undefined' ? window : global);
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],3:[function(_dereq_,module,exports){
var $ = _dereq_('unopinionate').selector;
var $document = $(document),
bindings = {};
var click = function(events) {
click.bind.apply(click, arguments);
return click;
};
/*** Configuration Options ***/
click.distanceLimit = 10;
click.timeLimit = 140;
/*** Useful Properties ***/
click.isTouch = ('ontouchstart' in window) ||
window.DocumentTouch &&
document instanceof DocumentTouch;
/*** Cached Functions ***/
var onTouchstart = function(e) {
e.stopPropagation(); //Prevents multiple click events from happening
click._doAnywheres(e);
var $this = $(this),
startTime = new Date().getTime(),
startPos = click._getPos(e);
$this.one('touchend', function(e) {
e.preventDefault(); //Prevents click event from firing
var time = new Date().getTime() - startTime,
endPos = click._getPos(e),
distance = Math.sqrt(
Math.pow(endPos.x - startPos.x, 2) +
Math.pow(endPos.y - startPos.y, 2)
);
if(time < click.timeLimit && distance < click.distanceLimit) {
//Find the correct callback
$.each(bindings, function(selector, callback) {
if($this.is(selector)) {
callback.apply(e.target, [e]);
return false;
}
});
}
});
};
/*** API ***/
click.bind = function(events) {
//Argument Surgery
if(!$.isPlainObject(events)) {
newEvents = {};
newEvents[arguments[0]] = arguments[1];
events = newEvents;
}
$.each(events, function(selector, callback) {
/*** Register Binding ***/
if(typeof bindings[selector] != 'undefined') {
click.unbind(selector); //Ensure no duplicates
}
bindings[selector] = callback;
/*** Touch Support ***/
if(click.isTouch) {
$document.delegate(selector, 'touchstart', onTouchstart);
}
/*** Mouse Support ***/
$document.delegate(selector, 'click', function(e) {
e.stopPropagation(); //Prevents multiple click events from happening
//click._doAnywheres(e); //Do anywheres first to be consistent with touch order
callback.apply(this, [e]);
});
});
return this;
};
click.unbind = function(selector) {
$document
.undelegate(selector, 'touchstart')
.undelegate(selector, 'click');
delete bindings[selector];
return this;
};
click.unbindAll = function() {
$.each(bindings, function(selector, callback) {
$document
.undelegate(selector, 'touchstart')
.undelegate(selector, 'click');
});
bindings = {};
return this;
};
click.trigger = function(selector, e) {
e = e || $.Event('click');
if(typeof bindings[selector] != 'undefined') {
bindings[selector](e);
}
else {
console.error("No click events bound for selector '"+selector+"'.");
}
return this;
};
click.anywhere = function(callback) {
click._anywheres.push(callback);
return this;
};
/*** Internal (but useful) Methods ***/
click._getPos = function(e) {
e = e.originalEvent;
if(e.pageX || e.pageY) {
return {
x: e.pageX,
y: e.pageY
};
}
else if(e.changedTouches) {
return {
x: e.changedTouches[0].clientX,
y: e.changedTouches[0].clientY
};
}
else {
return {
x: e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft,
y: e.clientY + document.body.scrollTop + document.documentElement.scrollTop
};
}
};
click._anywheres = [];
click._doAnywheres = function(e) {
var i = click._anywheres.length;
while(i--) {
click._anywheres[i](e);
}
};
$(document).bind('mousedown', click._doAnywheres);
module.exports = click;
},{"unopinionate":2}]},{},[1])
(1)
});