Skip to content

Commit

Permalink
1.0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey.Kupriyanenko committed May 5, 2014
1 parent 43520f2 commit 5556338
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 19 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jbone",
"version": "1.0.12",
"version": "1.0.15",
"ignore": [
"**/.*",
"node_modules",
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "jbone",
"repo": "kupriyanenko/jbone",
"description": "JavaScript Library for DOM manipulation. Replacement jQuery for Backbone in browsers (2.5kb gzipped)",
"version": "1.0.12",
"version": "1.0.15",
"keywords": [
"jquery",
"jbone",
Expand Down
66 changes: 52 additions & 14 deletions dist/jbone.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* jBone v1.0.12 - 2014-05-04 - Library for DOM manipulation
* jBone v1.0.15 - 2014-05-05 - Library for DOM manipulation
*
* https://github.com/kupriyanenko/jbone
*
Expand Down Expand Up @@ -36,7 +36,11 @@ isObject = function(el) {
return el instanceof Object;
},
isFunction = function(el) {
return typeof el === "function";
var getType = {};
return el && getType.toString.call(el) === "[object Function]";
},
isArray = function(el) {
return Array.isArray(el);
},
jBone = function(element, data) {
return new fn.init(element, data);
Expand Down Expand Up @@ -110,13 +114,9 @@ fn = jBone.fn = jBone.prototype = {
if (element instanceof jBone) {
return element;
}
// Return element wrapped by jBone
if (element) {
element = Array.isArray(element) ? element : [element];
return jBone.merge(this, element);
}

return this;
// Return element wrapped by jBone
return jBone.makeArray(element, this);
},

pop: [].pop,
Expand Down Expand Up @@ -178,6 +178,22 @@ jBone._cache = {
jid: 0
};

function isArraylike(obj) {
var length = obj.length,
type = typeof obj;

if (isFunction(type) || obj === win) {
return false;
}

if (obj.nodeType === 1 && length) {
return true;
}

return isArray(type) || length === 0 ||
typeof length === "number" && length > 0 && (length - 1) in obj;
}

jBone.merge = function(first, second) {
var l = second.length,
i = first.length,
Expand Down Expand Up @@ -225,6 +241,20 @@ jBone.extend = function(target) {
return target;
};

jBone.makeArray = function(arr, results) {
var ret = results || [];

if (arr !== null) {
if (isArraylike(arr)) {
jBone.merge(ret, isString(arr) ? [arr] : arr);
} else {
ret.push(arr);
}
}

return ret;
};

function BoneEvent(e, data) {
var key, setter;

Expand Down Expand Up @@ -686,13 +716,25 @@ fn.append = function(appended) {
length = this.length,
setter;

// create jBone object and then append
if (isString(appended) && rquickExpr.exec(appended)) {
appended = jBone(appended);
} else if (!isObject(appended)) {
}
// create text node for inserting
else if (!isObject(appended)) {
appended = document.createTextNode(appended);
}

if (appended instanceof jBone) {
// just append NodeElement
if (appended instanceof Node) {
setter = function(el) {
el.appendChild(appended);
};
}
// wrap object by jBone, and then append
else {
appended = appended instanceof jBone ? appended : jBone(appended);

setter = function(el, i) {
appended.forEach(function(node) {
if (i) {
Expand All @@ -702,10 +744,6 @@ fn.append = function(appended) {
}
});
};
} else if (appended instanceof Node) {
setter = function(el) {
el.appendChild(appended);
};
}

for (; i < length; i++) {
Expand Down
4 changes: 2 additions & 2 deletions dist/jbone.min.js

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jbone",
"title": "jBone",
"version": "1.0.12",
"version": "1.0.15",
"description": "Library for DOM manipulation",
"main": "dist/jbone.js",
"homepage": "https://github.com/kupriyanenko/jbone",
Expand Down

0 comments on commit 5556338

Please sign in to comment.