zepto-browserify
Advanced tools
Comparing version 1.1.3-0 to 1.1.6-0
{ | ||
"name": "zepto-browserify", | ||
"version": "1.1.3-0", | ||
"version": "1.1.6-0", | ||
"description": "Shim repository for the Zepto.js JavaScript library for Browserify", | ||
@@ -5,0 +5,0 @@ "main": "zepto.js", |
`zepto-browserify` | ||
zepto-browserify | ||
------ | ||
This is a fork based on [components/zepto](https://github.com/components/zepto). | ||
> Since Zepto does not provide npm package officially, here's my personal copy of Zepto. | ||
Goto Zepto's home page for docs: http://zeptojs.com/ | ||
Read more about it in official repo: https://github.com/madrobby/zepto | ||
Version of Zepto in this repo is `1.1.3`, while I use `1.1.3-x` in module. | ||
This package is based on [components/zepto](https://github.com/components/zepto). | ||
Goto Zepto's home page for docs: http://zeptojs.com/ | ||
Current version of Zepto: `1.1.6`. | ||
Read more about it in official repo: https://github.com/madrobby/zepto | ||
Version of this repo: `1.1.6-0`. | ||
See official releases: https://github.com/madrobby/zepto/releases | ||
### Usage | ||
``` | ||
```text | ||
npm install --save zepto-browserify | ||
@@ -20,3 +24,3 @@ ``` | ||
```js | ||
$ = require('zepto-browserify').$ | ||
Zepto = require('zepto-browserify') | ||
Zepto = require('zepto-browserify').Zepto | ||
@@ -26,5 +30,5 @@ $ === Zepto // => true | ||
### Differece from Zepto | ||
### Changes from Zepto | ||
How I modified this based on code of `1.1.3`: | ||
Changes I made at line `886`: | ||
@@ -34,6 +38,10 @@ ```js | ||
window.$ === undefined && (window.$ = Zepto) | ||
// Added by github/jiyinyiyong to create an npm package | ||
exports.Zepto = window.Zepto | ||
exports.$ = window.$ | ||
``` | ||
```js | ||
exports.$ = exports.Zepto = Zepto; | ||
``` | ||
### License | ||
MIT https://github.com/madrobby/zepto/blob/225f93e3dcbd6bfb433267e157a744c02176516c/MIT-LICENSE |
183
zepto.js
@@ -1,4 +0,3 @@ | ||
/* Zepto v1.1.3 - zepto event ajax form ie - zeptojs.com/license */ | ||
/* Zepto v1.1.6 - zepto event ajax form ie - zeptojs.com/license */ | ||
var Zepto = (function() { | ||
@@ -270,5 +269,11 @@ var undefined, key, $, classList, emptyArray = [], slice = emptyArray.slice, filter = emptyArray.filter, | ||
$.contains = function(parent, node) { | ||
return parent !== node && parent.contains(node) | ||
} | ||
$.contains = document.documentElement.contains ? | ||
function(parent, node) { | ||
return parent !== node && parent.contains(node) | ||
} : | ||
function(parent, node) { | ||
while (node && (node = node.parentNode)) | ||
if (node === parent) return true | ||
return false | ||
} | ||
@@ -285,3 +290,3 @@ function funcArg(context, arg, idx, payload) { | ||
function className(node, value){ | ||
var klass = node.className, | ||
var klass = node.className || '', | ||
svg = klass && klass.baseVal !== undefined | ||
@@ -302,3 +307,2 @@ | ||
function deserializeValue(value) { | ||
var num | ||
try { | ||
@@ -309,3 +313,3 @@ return value ? | ||
value == "null" ? null : | ||
!/^0/.test(value) && !isNaN(num = Number(value)) ? num : | ||
+value + "" == value ? +value : | ||
/^[\[\{]/.test(value) ? $.parseJSON(value) : | ||
@@ -478,3 +482,4 @@ value ) | ||
var result, $this = this | ||
if (typeof selector == 'object') | ||
if (!selector) result = $() | ||
else if (typeof selector == 'object') | ||
result = $(selector).filter(function(){ | ||
@@ -591,19 +596,21 @@ var node = this | ||
html: function(html){ | ||
return arguments.length === 0 ? | ||
(this.length > 0 ? this[0].innerHTML : null) : | ||
return 0 in arguments ? | ||
this.each(function(idx){ | ||
var originHtml = this.innerHTML | ||
$(this).empty().append( funcArg(this, html, idx, originHtml) ) | ||
}) | ||
}) : | ||
(0 in this ? this[0].innerHTML : null) | ||
}, | ||
text: function(text){ | ||
return arguments.length === 0 ? | ||
(this.length > 0 ? this[0].textContent : null) : | ||
this.each(function(){ this.textContent = (text === undefined) ? '' : ''+text }) | ||
return 0 in arguments ? | ||
this.each(function(idx){ | ||
var newText = funcArg(this, text, idx, this.textContent) | ||
this.textContent = newText == null ? '' : ''+newText | ||
}) : | ||
(0 in this ? this[0].textContent : null) | ||
}, | ||
attr: function(name, value){ | ||
var result | ||
return (typeof name == 'string' && value === undefined) ? | ||
(this.length == 0 || this[0].nodeType !== 1 ? undefined : | ||
(name == 'value' && this[0].nodeName == 'INPUT') ? this.val() : | ||
return (typeof name == 'string' && !(1 in arguments)) ? | ||
(!this.length || this[0].nodeType !== 1 ? undefined : | ||
(!(result = this[0].getAttribute(name)) && name in this[0]) ? this[0][name] : result | ||
@@ -618,25 +625,32 @@ ) : | ||
removeAttr: function(name){ | ||
return this.each(function(){ this.nodeType === 1 && setAttribute(this, name) }) | ||
return this.each(function(){ this.nodeType === 1 && name.split(' ').forEach(function(attribute){ | ||
setAttribute(this, attribute) | ||
}, this)}) | ||
}, | ||
prop: function(name, value){ | ||
name = propMap[name] || name | ||
return (value === undefined) ? | ||
(this[0] && this[0][name]) : | ||
return (1 in arguments) ? | ||
this.each(function(idx){ | ||
this[name] = funcArg(this, value, idx, this[name]) | ||
}) | ||
}) : | ||
(this[0] && this[0][name]) | ||
}, | ||
data: function(name, value){ | ||
var data = this.attr('data-' + name.replace(capitalRE, '-$1').toLowerCase(), value) | ||
var attrName = 'data-' + name.replace(capitalRE, '-$1').toLowerCase() | ||
var data = (1 in arguments) ? | ||
this.attr(attrName, value) : | ||
this.attr(attrName) | ||
return data !== null ? deserializeValue(data) : undefined | ||
}, | ||
val: function(value){ | ||
return arguments.length === 0 ? | ||
return 0 in arguments ? | ||
this.each(function(idx){ | ||
this.value = funcArg(this, value, idx, this.value) | ||
}) : | ||
(this[0] && (this[0].multiple ? | ||
$(this[0]).find('option').filter(function(){ return this.selected }).pluck('value') : | ||
this[0].value) | ||
) : | ||
this.each(function(idx){ | ||
this.value = funcArg(this, value, idx, this.value) | ||
}) | ||
) | ||
}, | ||
@@ -656,3 +670,3 @@ offset: function(coordinates){ | ||
}) | ||
if (this.length==0) return null | ||
if (!this.length) return null | ||
var obj = this[0].getBoundingClientRect() | ||
@@ -668,4 +682,5 @@ return { | ||
if (arguments.length < 2) { | ||
var element = this[0], computedStyle = getComputedStyle(element, '') | ||
var computedStyle, element = this[0] | ||
if(!element) return | ||
computedStyle = getComputedStyle(element, '') | ||
if (typeof property == 'string') | ||
@@ -675,3 +690,3 @@ return element.style[camelize(property)] || computedStyle.getPropertyValue(property) | ||
var props = {} | ||
$.each(isArray(property) ? property: [property], function(_, prop){ | ||
$.each(property, function(_, prop){ | ||
props[prop] = (element.style[camelize(prop)] || computedStyle.getPropertyValue(prop)) | ||
@@ -711,2 +726,3 @@ }) | ||
return this.each(function(idx){ | ||
if (!('className' in this)) return | ||
classList = [] | ||
@@ -722,2 +738,3 @@ var cls = className(this), newName = funcArg(this, name, idx, cls) | ||
return this.each(function(idx){ | ||
if (!('className' in this)) return | ||
if (name === undefined) return className(this, '') | ||
@@ -815,3 +832,4 @@ classList = className(this) | ||
fun(node) | ||
for (var key in node.childNodes) traverseNode(node.childNodes[key], fun) | ||
for (var i = 0, len = node.childNodes.length; i < len; i++) | ||
traverseNode(node.childNodes[i], fun) | ||
} | ||
@@ -843,2 +861,4 @@ | ||
var parentInDocument = $.contains(document.documentElement, parent) | ||
nodes.forEach(function(node){ | ||
@@ -848,3 +868,4 @@ if (copyByClone) node = node.cloneNode(true) | ||
traverseNode(parent.insertBefore(node, target), function(el){ | ||
parent.insertBefore(node, target) | ||
if (parentInDocument) traverseNode(node, function(el){ | ||
if (el.nodeName != null && el.nodeName.toUpperCase() === 'SCRIPT' && | ||
@@ -878,4 +899,9 @@ (!el.type || el.type === 'text/javascript') && !el.src) | ||
exports.$ = exports.Zepto = Zepto; | ||
window.Zepto = Zepto | ||
window.$ === undefined && (window.$ = Zepto) | ||
// Added by github/jiyinyiyong to create an npm package | ||
exports.Zepto = window.Zepto | ||
exports.$ = window.$ | ||
;(function($){ | ||
@@ -969,8 +995,14 @@ var _zid = 1, undefined, | ||
$.proxy = function(fn, context) { | ||
var args = (2 in arguments) && slice.call(arguments, 2) | ||
if (isFunction(fn)) { | ||
var proxyFn = function(){ return fn.apply(context, arguments) } | ||
var proxyFn = function(){ return fn.apply(context, args ? args.concat(slice.call(arguments)) : arguments) } | ||
proxyFn._zid = zid(fn) | ||
return proxyFn | ||
} else if (isString(context)) { | ||
return $.proxy(fn[context], fn) | ||
if (args) { | ||
args.unshift(fn[context], fn) | ||
return $.proxy.apply(null, args) | ||
} else { | ||
return $.proxy(fn[context], fn) | ||
} | ||
} else { | ||
@@ -1101,4 +1133,6 @@ throw new TypeError("expected function") | ||
return this.each(function(){ | ||
// handle focus(), blur() by calling them directly | ||
if (event.type in focus && typeof this[event.type] == "function") this[event.type]() | ||
// items in the collection might not be DOM elements | ||
if('dispatchEvent' in this) this.dispatchEvent(event) | ||
else if ('dispatchEvent' in this) this.dispatchEvent(event) | ||
else $(this).triggerHandler(event, args) | ||
@@ -1125,7 +1159,7 @@ }) | ||
// shortcut methods for `.bind(event, fn)` for each event type | ||
;('focusin focusout load resize scroll unload click dblclick '+ | ||
;('focusin focusout focus blur load resize scroll unload click dblclick '+ | ||
'mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave '+ | ||
'change select keydown keypress keyup error').split(' ').forEach(function(event) { | ||
$.fn[event] = function(callback) { | ||
return callback ? | ||
return (0 in arguments) ? | ||
this.bind(event, callback) : | ||
@@ -1136,13 +1170,2 @@ this.trigger(event) | ||
;['focus', 'blur'].forEach(function(name) { | ||
$.fn[name] = function(callback) { | ||
if (callback) this.bind(name, callback) | ||
else this.each(function(){ | ||
try { this[name]() } | ||
catch(e) {} | ||
}) | ||
return this | ||
} | ||
}) | ||
$.Event = function(type, props) { | ||
@@ -1168,4 +1191,7 @@ if (!isString(type)) props = type, type = props.type | ||
htmlType = 'text/html', | ||
blankRE = /^\s*$/ | ||
blankRE = /^\s*$/, | ||
originAnchor = document.createElement('a') | ||
originAnchor.href = window.location.href | ||
// trigger a custom event and return false if it was cancelled | ||
@@ -1341,3 +1367,4 @@ function triggerAndReturn(context, eventName, data) { | ||
var settings = $.extend({}, options || {}), | ||
deferred = $.Deferred && $.Deferred() | ||
deferred = $.Deferred && $.Deferred(), | ||
urlAnchor | ||
for (key in $.ajaxSettings) if (settings[key] === undefined) settings[key] = $.ajaxSettings[key] | ||
@@ -1347,11 +1374,22 @@ | ||
if (!settings.crossDomain) settings.crossDomain = /^([\w-]+:)?\/\/([^\/]+)/.test(settings.url) && | ||
RegExp.$2 != window.location.host | ||
if (!settings.crossDomain) { | ||
urlAnchor = document.createElement('a') | ||
urlAnchor.href = settings.url | ||
urlAnchor.href = urlAnchor.href | ||
settings.crossDomain = (originAnchor.protocol + '//' + originAnchor.host) !== (urlAnchor.protocol + '//' + urlAnchor.host) | ||
} | ||
if (!settings.url) settings.url = window.location.toString() | ||
serializeData(settings) | ||
if (settings.cache === false) settings.url = appendQuery(settings.url, '_=' + Date.now()) | ||
var dataType = settings.dataType, hasPlaceholder = /\?.+=\?/.test(settings.url) | ||
if (dataType == 'jsonp' || hasPlaceholder) { | ||
if (hasPlaceholder) dataType = 'jsonp' | ||
if (settings.cache === false || ( | ||
(!options || options.cache !== true) && | ||
('script' == dataType || 'jsonp' == dataType) | ||
)) | ||
settings.url = appendQuery(settings.url, '_=' + Date.now()) | ||
if ('jsonp' == dataType) { | ||
if (!hasPlaceholder) | ||
@@ -1496,3 +1534,7 @@ settings.url = appendQuery(settings.url, | ||
var params = [] | ||
params.add = function(k, v){ this.push(escape(k) + '=' + escape(v)) } | ||
params.add = function(key, value) { | ||
if ($.isFunction(value)) value = value() | ||
if (value == null) value = "" | ||
this.push(escape(key) + '=' + escape(value)) | ||
} | ||
serialize(params, obj, traditional) | ||
@@ -1505,13 +1547,13 @@ return params.join('&').replace(/%20/g, '+') | ||
$.fn.serializeArray = function() { | ||
var result = [], el | ||
$([].slice.call(this.get(0).elements)).each(function(){ | ||
el = $(this) | ||
var type = el.attr('type') | ||
if (this.nodeName.toLowerCase() != 'fieldset' && | ||
!this.disabled && type != 'submit' && type != 'reset' && type != 'button' && | ||
((type != 'radio' && type != 'checkbox') || this.checked)) | ||
result.push({ | ||
name: el.attr('name'), | ||
value: el.val() | ||
}) | ||
var name, type, result = [], | ||
add = function(value) { | ||
if (value.forEach) return value.forEach(add) | ||
result.push({ name: name, value: value }) | ||
} | ||
if (this[0]) $.each(this[0].elements, function(_, field){ | ||
type = field.type, name = field.name | ||
if (name && field.nodeName.toLowerCase() != 'fieldset' && | ||
!field.disabled && type != 'submit' && type != 'reset' && type != 'button' && type != 'file' && | ||
((type != 'radio' && type != 'checkbox') || field.checked)) | ||
add($(field).val()) | ||
}) | ||
@@ -1530,3 +1572,3 @@ return result | ||
$.fn.submit = function(callback) { | ||
if (callback) this.bind('submit', callback) | ||
if (0 in arguments) this.bind('submit', callback) | ||
else if (this.length) { | ||
@@ -1575,2 +1617,3 @@ var event = $.Event('submit') | ||
} | ||
})(Zepto) | ||
})(Zepto) | ||
; |
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
57625
1429
45
1