Skip to content

Commit

Permalink
Compatible with jQuery 3
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic100 committed Jun 23, 2016
1 parent cd62f26 commit ae3816a
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 114 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
bower_components
node_modules
/bower_components
/node_modules
/.coverage-results
/.idea
/*.iml
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- "0.10"
- "5"
before_install:
- npm install -g grunt-cli
- npm install -g bower
Expand Down
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module.exports = function(grunt) {
force: true
},
all: {
src: '.coverage-results/all.lcov',
src: '.coverage-results/all.lcov'
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery-extendext",
"version": "0.1.1",
"version": "0.1.2",
"description": "jQuery.extend with configurable behaviour for arrays",
"authors": [{
"name": "Damien \"Mistic\" Sorel",
Expand Down
208 changes: 107 additions & 101 deletions jQuery.extendext.js
Original file line number Diff line number Diff line change
@@ -1,126 +1,132 @@
/*!
* jQuery.extendext 0.1.1
* jQuery.extendext 0.1.2
*
* Copyright 2014 Damien "Mistic" Sorel (http://www.strangeplanet.fr)
* Copyright 2014-2016 Damien "Mistic" Sorel (http://www.strangeplanet.fr)
* Licensed under MIT (http://opensource.org/licenses/MIT)
*
* Based on jQuery.extend by jQuery Foundation, Inc. and other contributors
*/

/*jshint -W083 */

(function(root, factory) {
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery'], factory);
}
else if (typeof module === 'object' && module.exports) {
module.exports = factory(require('jquery'));
}
else {
factory(root.jQuery);
}
}(this, function($) {
"use strict";

$.extendext = function() {
var options, name, src, copy, copyIsArray, clone,
target = arguments[0] || {},
i = 1,
length = arguments.length,
deep = false,
arrayMode = 'default';

// Handle a deep copy situation
if ( typeof target === "boolean" ) {
deep = target;

// Skip the boolean and the target
target = arguments[ i++ ] || {};
}

// Handle array mode parameter
if ( typeof target === "string" ) {
arrayMode = $([target.toLowerCase(), 'default']).filter(['default','concat','replace','extend'])[0];

// Skip the string param
target = arguments[ i++ ] || {};
}

// Handle case when target is a string or something (possible in deep copy)
if ( typeof target !== "object" && !$.isFunction(target) ) {
target = {};
}

// Extend jQuery itself if only one argument is passed
if ( i === length ) {
target = this;
i--;
}
}(this, function ($) {
"use strict";

$.extendext = function () {
var options, name, src, copy, copyIsArray, clone,
target = arguments[0] || {},
i = 1,
length = arguments.length,
deep = false,
arrayMode = 'default';

// Handle a deep copy situation
if (typeof target === "boolean") {
deep = target;

// Skip the boolean and the target
target = arguments[i++] || {};
}

for ( ; i < length; i++ ) {
// Only deal with non-null/undefined values
if ( (options = arguments[ i ]) !== null ) {
// Special operations for arrays
if ($.isArray(options) && arrayMode !== 'default') {
clone = target && $.isArray(target) ? target : [];

switch (arrayMode) {
case 'concat':
target = clone.concat( $.extend( deep, [], options ) );
break;

case 'replace':
target = $.extend( deep, [], options );
break;

case 'extend':
options.forEach(function(e, i) {
if (typeof e === 'object') {
var type = $.isArray(e) ? [] : {};
clone[i] = $.extendext( deep, arrayMode, clone[i] || type, e );

} else if (clone.indexOf(e) === -1) {
clone.push(e);
}
});

target = clone;
break;
}

} else {
// Extend the base object
for ( name in options ) {
src = target[ name ];
copy = options[ name ];

// Prevent never-ending loop
if ( target === copy ) {
continue;
// Handle array mode parameter
if (typeof target === "string") {
arrayMode = target.toLowerCase();
if (arrayMode !== 'concat' && arrayMode !== 'replace' && arrayMode !== 'extend') {
arrayMode = 'default';
}

// Recurse if we're merging plain objects or arrays
if ( deep && copy && ( $.isPlainObject(copy) ||
(copyIsArray = $.isArray(copy)) ) ) {

if ( copyIsArray ) {
copyIsArray = false;
clone = src && $.isArray(src) ? src : [];
// Skip the string param
target = arguments[i++] || {};
}

} else {
clone = src && $.isPlainObject(src) ? src : {};
}
// Handle case when target is a string or something (possible in deep copy)
if (typeof target !== "object" && !$.isFunction(target)) {
target = {};
}

// Never move original objects, clone them
target[ name ] = $.extendext( deep, arrayMode, clone, copy );
// Extend jQuery itself if only one argument is passed
if (i === length) {
target = this;
i--;
}

// Don't bring in undefined values
} else if ( copy !== undefined ) {
target[ name ] = copy;
for (; i < length; i++) {
// Only deal with non-null/undefined values
if ((options = arguments[i]) !== null) {
// Special operations for arrays
if ($.isArray(options) && arrayMode !== 'default') {
clone = target && $.isArray(target) ? target : [];

switch (arrayMode) {
case 'concat':
target = clone.concat($.extend(deep, [], options));
break;

case 'replace':
target = $.extend(deep, [], options);
break;

case 'extend':
options.forEach(function (e, i) {
if (typeof e === 'object') {
var type = $.isArray(e) ? [] : {};
clone[i] = $.extendext(deep, arrayMode, clone[i] || type, e);

} else if (clone.indexOf(e) === -1) {
clone.push(e);
}
});

target = clone;
break;
}

} else {
// Extend the base object
for (name in options) {
src = target[name];
copy = options[name];

// Prevent never-ending loop
if (target === copy) {
continue;
}

// Recurse if we're merging plain objects or arrays
if (deep && copy && ( $.isPlainObject(copy) ||
(copyIsArray = $.isArray(copy)) )) {

if (copyIsArray) {
copyIsArray = false;
clone = src && $.isArray(src) ? src : [];

} else {
clone = src && $.isPlainObject(src) ? src : {};
}

// Never move original objects, clone them
target[name] = $.extendext(deep, arrayMode, clone, copy);

// Don't bring in undefined values
} else if (copy !== undefined) {
target[name] = copy;
}
}
}
}
}
}
}
}

// Return the modified object
return target;
};
// Return the modified object
return target;
};
}));
6 changes: 3 additions & 3 deletions jQuery.extendext.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery-extendext",
"version": "0.1.1",
"version": "0.1.2",
"description": "jQuery.extend with configurable behaviour for arrays",
"authors": [{
"name": "Damien \"Mistic\" Sorel",
Expand All @@ -9,10 +9,10 @@
}],
"main": "jQuery.extendext.js",
"devDependencies": {
"grunt": "~0.4.5",
"grunt-contrib-qunit": "~0.5.2",
"grunt-contrib-uglify": "~0.5.0",
"grunt-contrib-jshint": "~0.11.0",
"grunt": "~1.0.0",
"grunt-contrib-qunit": "~0.7.0",
"grunt-contrib-uglify": "~1.0.0",
"grunt-contrib-jshint": "~1.0.0",
"grunt-qunit-blanket-lcov": "~0.3.1",
"grunt-coveralls": "~1.0.0"
},
Expand Down

0 comments on commit ae3816a

Please sign in to comment.