I'm working on my framework constructor. First I tried to look into jQuery and understand it, but it's so out of my league. Instead I googled and put this code together. Though there aren't many posts about creating a framework. Anyway, since I'm not a guru I might be doing it the wrong way or missing things. Can I take your opinions, suggestions to make it a little more stable?
var optionalSelector = "$";
(function () {
(this[arguments[0]] = function constructor(input) {
if (!(this instanceof constructor)) {
return new constructor(input);
}
var regExp_id = /^#/;
var regExp_class = /^\./;
var regExp_tag = /[^#]|[^.]/;
var typeOfInput;
function isElement(obj) {
if (obj !== null && typeof obj === "object") {
return obj;
}
}
if (isElement(input)) {
return input;
} // this
else {
if (input.search(regExp_id) != -1) {
typeOfInput = "id";
} else if (input.search(regExp_class) != -1) {
typeOfInput = "class";
} else if (input.search(regExp_tag) != -1) {
typeOfInput = "tag";
}
switch (typeOfInput) {
case "id":
if (document.getElementById(input.replace(/#/, ""))) {
return document.getElementById(input.replace(/#/, ""));
} else {
console.log("Invalid id: " + input);
return false;
}
break;
case "class":
if (document.getElementsByClassName(input.replace(/./, "")).length > 0) {
return document.getElementsByClassName(input.replace(/./, ""));
} else {
console.log("Invalid class: " + input);
return false;
}
break;
case "tag":
if (document.getElementsByTagName(input).length > 0) {
return document.getElementsByTagName(input);
} else {
console.log("Invalid tag: " + input);
return false;
}
break;
}
}
})
})(optionalSelector);