Skip to content

Commit

Permalink
v0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Kormanowsky authored Dec 13, 2017
1 parent 2beee70 commit 63262e4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 39 deletions.
67 changes: 29 additions & 38 deletions jextract.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
jExtract: a small function for extracting data from DOM.
Version: 0.0.3
Version: 0.0.4
Author: Mikhail Kormanowsky (@kormanowsky)
Date: 10.12.2017
Date: 13.12.2017
*/
function jExtract(struct, parent) {
//Throw an error about jQuery
Expand All @@ -15,6 +15,7 @@ function jExtract(struct, parent) {
parent = parent || $("html");
//Some functions and objects
var find = function (selector) {
if(selector == '.') return parent;
return parent.find(selector);
},
methodAndArgs = function (input) {
Expand Down Expand Up @@ -50,12 +51,12 @@ function jExtract(struct, parent) {
isFunction = function(v){
return typeof v === "function";
},
isNull = function(v){
return v === null;
},
jExtractText = function (string) {
this._text = string;
},
jExtractElement = function (element) {
this._jquery = element;
},
result = {};
jExtractText.prototype.get = function (trim) {
trim = trim || true;
Expand All @@ -80,20 +81,6 @@ function jExtract(struct, parent) {
if(!isNaN(parseFloat(str)) || leaveNaN) return parseFloat(str);
return 0;
};
jExtractElement.prototype.text = function () {
return new jExtractText(this._jquery.text());
};
jExtractElement.prototype.attr = function (attrName) {
return new jExtractText(this._jquery.attr(attrName));
};
jExtractElement.prototype.recget = function (key) {
var val = this;
key = key.split('.');
key.forEach(function (k) {
if (k in val) val = val[k];
});
return val;
};

//Start our loop
$.each(struct, function (i, e) {
Expand Down Expand Up @@ -135,39 +122,43 @@ function jExtract(struct, parent) {
//Find elements that match selector and extract data from them
element.each(function (a, b) {
if (isUndefined(s)) {
var jElement = new jExtractElement($(b)),
var jElement = $(b),
method,
args,
context;
if(isFunction(data[0])){
method = data[0];
args = [jElement._jquery, element].concat(data[1]);
args = [element, a].concat(data[1]);
context = null;
}else if(isString(data[0])){
method = jElement.recget(data[0]);
method = jElement[data[0]];
args = data[1];
context = jElement;
}else{
method = function(){};
context = null;
args = [];
}
var jElementProp = method.apply(context, args);
if(!(jElementProp instanceof jExtractText)) jElementProp = new jExtractText(jElementProp + '');
if(isFunction(filter[0])){
method = filter[0];
args = [jElementProp].concat(filter[1]);
content = null;
}else if(isString(filter[0])){
method = jElementProp[filter[0]];
args = filter[1];
context = jElementProp;
}else{
method = function(){};
context = null;
args = [];
}
_result.push(method.apply(context, args));
var jElementProp = method.apply(context, args), toPush;
if(isNull(jElementProp) || isUndefined(jElementProp)) return;
else if(isObject(jElementProp) || isArray(jElementProp) || isString(jElementProp)){
if(!(jElementProp instanceof jExtractText)) jElementProp = new jExtractText(jElementProp + '');
if(isFunction(filter[0])){
method = filter[0];
args = [jElementProp, a].concat(filter[1]);
content = null;
}else if(isString(filter[0])){
method = jElementProp[filter[0]];
args = filter[1];
context = jElementProp;
}else{
method = function(){};
context = null;
args = [];
}
toPush = method.apply(context, args);
}else toPush = jElementProp;
_result.push(toPush);
} else {
//Or just make a recursion if needed
_result.push(jExtract(s, $(b)));
Expand Down
2 changes: 1 addition & 1 deletion jextract.min.js

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

0 comments on commit 63262e4

Please sign in to comment.