patternjavascriptMinor
A package for the DOM
Viewed 0 times
domtheforpackage
Problem
Concerned with the length of this and the organization. Looking to organize it better if possible. If anyone knows the jQuery equivalent of these methods I would like to put them in the comments.
I'm not interested in changing the style, i.e. - identifier names, whitespace, etc.
```
/*****
**DOM
- additional coverage for the dom
- consistent coding style ...
- fewer function branches
*****/
(function (win, doc) {
"use strict";
// p(R)ivate propeties go here
var Priv = {},
// (P)ublic properties go here
Pub = function (selector) {
return new Priv.Constructor(selector);
},
// (D)ependencies go here
$A;
$A = (function manageGlobal() {
// manually match to utility global
Priv.g = '$A';
if (win[Priv.g] && win[Priv.g].pack && win[Priv.g].pack.utility) {
// utility was found, add dom
win[Priv.g].pack.dom = true;
} else {
throw new Error("dom requires utility module");
}
return win[Priv.g];
}());
Pub.Debug = (function () {
var publik = {},
hold = {};
// addTags and removeTags can add and remove groups of html tags for
// visual feedback on how a site works
publik.addTags = function (tag) {
if (hold[tag]) {
$A.someIndex(hold[tag], function (val) {
if (tag === 'script' || tag === 'style') {
document.head.appendChild(val);
} else {
document.body.appendChild(val);
}
I'm not interested in changing the style, i.e. - identifier names, whitespace, etc.
```
/*****
**DOM
- additional coverage for the dom
- consistent coding style ...
- fewer function branches
*****/
(function (win, doc) {
"use strict";
// p(R)ivate propeties go here
var Priv = {},
// (P)ublic properties go here
Pub = function (selector) {
return new Priv.Constructor(selector);
},
// (D)ependencies go here
$A;
$A = (function manageGlobal() {
// manually match to utility global
Priv.g = '$A';
if (win[Priv.g] && win[Priv.g].pack && win[Priv.g].pack.utility) {
// utility was found, add dom
win[Priv.g].pack.dom = true;
} else {
throw new Error("dom requires utility module");
}
return win[Priv.g];
}());
Pub.Debug = (function () {
var publik = {},
hold = {};
// addTags and removeTags can add and remove groups of html tags for
// visual feedback on how a site works
publik.addTags = function (tag) {
if (hold[tag]) {
$A.someIndex(hold[tag], function (val) {
if (tag === 'script' || tag === 'style') {
document.head.appendChild(val);
} else {
document.body.appendChild(val);
}
Solution
From a once over
From here I still only reviewed half of the code.
Your helper functions like
- ASCII header, using "use strict" in a surrounding function, good stuff
addTags, would have been nice if the caller could set the parent to which the tags should be added ( a la jQuery )
addTags, it is unclear from naming whatholdis, what is supposed to do, there are no explaining comments either
addTags, it is clear after readingremoveTags, maybe you should put that function there
addTags,removeTags, the code does not put the tags back from where they were removed, that is a very limited feature
removeTags->stylesseems an unfortunate name, the parameter could have been calledtagName
removeStorage-> Seems to be the wrong library, you have different a library for storage already
zIndex-> why not just return the elements in the array ? It would take less memory, while returning more info
Pub.elneeds a comment with sampleselector_nativevalues
Pub.removeElementetc., silent failures, could be frustrating
isElement->!!on a Boolean expression seems pointless, update : it is not pointless, it will convert a falsey value to the boolean false.
eachChild-> some cryptic names, not following lowerCamelCase, the name is lying since it is not guaranteed to iterate overeachchild
HTMLToElementis smart, but could use a comment as to how it works
someKey-> sigh.. , really you should use js 1.6, or use the shims
Priv.Constructor-> too much white space by far
win-> you are making it too hard, just usewindow
doc-> seriously..
(/^(@|#|\.)([\x20-\x7E]+)$/is used twice, you should give it a good name in a constant
- You are having code in
Priv.Constructorthat is very similar to what is inPub.el, consider merging some of this code
From here I still only reviewed half of the code.
Your helper functions like
expandFont really need each a few lines of comment so that the reader can easily determine what it does ( yes, it increase the font but what does max_time, big_size and direction do ?? )Context
StackExchange Code Review Q#39913, answer score: 4
Revisions (0)
No revisions yet.