Skip to content

Commit ff78d62

Browse files
author
Tobias Deekens
committed
Adds initial version of DOM-logging.
1 parent c28f0b0 commit ff78d62

20 files changed

+1140
-808
lines changed

.jshintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"globals": {
1616
"define": true,
1717
"jQuery": true,
18-
"$": true
18+
"$": true,
19+
"alert": true
1920
},
2021
"node": true
2122
}

Gruntfile.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module.exports = function( grunt ) {
2020
},
2121
src: [
2222
"js/index.js",
23+
"js/dom.js",
2324
"js/logger.js",
2425
"js/util.js",
2526
"js/string.js",
@@ -29,7 +30,6 @@ module.exports = function( grunt ) {
2930
"js/core.js",
3031
"js/confluence.js",
3132
"js/responsive.js",
32-
"js/dom.js",
3333
"js/outro.js"
3434
],
3535
dest: "dist/scandio-<%= pkg.version %>.js"
@@ -90,12 +90,17 @@ module.exports = function( grunt ) {
9090
}
9191
},
9292
copy: {
93-
main: {
93+
scandiojs: {
9494
files: [
9595
{src: "dist/scandio-<%= pkg.version %>.js", dest: "dist/scandio.js"},
9696
{src: "dist/scandio-<%= pkg.version %>.min.js", dest: "dist/scandio.min.js"},
9797
{src: "dist/scandio-<%= pkg.version %>.min.map", dest: "dist/scandio.min.map"}
9898
]
99+
},
100+
scandiocss: {
101+
files: [
102+
{src: "dist/scandio-<%= pkg.version %>.css", dest: "dist/scandio.css"},
103+
{src: "dist/scandio-<%= pkg.version %>.min.css", dest: "dist/scandio.min.css"} ]
99104
}
100105
},
101106
docco: {

assets/css/alert.css

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
.scandio-js .debug {
2+
position: absolute;
3+
bottom: 0;
4+
}
15
.scandio-js .alert {
26
padding: 15px;
37
margin-bottom: 20px;

assets/css/common.css

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.scandio-js {
2+
position: relative;
3+
padding: 25px 50px;
4+
margin: 10px;
5+
z-index: 9999;
6+
background-color: #f2f2f2;
7+
border-width: 1px;
8+
border: 2px dotted #ddd;
9+
border-radius: 4px 4px 0 0;
10+
box-shadow: none;
11+
}

dist/scandio-0.1.0.css

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
.scandio-js {
2+
position: relative;
3+
padding: 25px 50px;
4+
margin: 10px;
5+
z-index: 9999;
6+
background-color: #f2f2f2;
7+
border-width: 1px;
8+
border: 2px dotted #ddd;
9+
border-radius: 4px 4px 0 0;
10+
box-shadow: none;
11+
}.scandio-js .debug {
12+
position: absolute;
13+
bottom: 0;
14+
}
115
.scandio-js .alert {
216
padding: 15px;
317
margin-bottom: 20px;

dist/scandio-0.1.0.js

+117-67
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
var
2323
ß = null,
2424
loadedJs = {},
25+
scandioHtmlClass = 'scandio-js',
26+
$scandioEl = null,
2527
// Previous version for `ß.noConflict`
2628
previousScandio = root.ß,
2729
// Breaker for loop iteration
@@ -92,11 +94,22 @@
9294
}
9395
},
9496

97+
_injectDom = function() {
98+
$(function() {
99+
if ( $(scandioHtmlClass).length === 0 ) {
100+
$scandioEl = $('<div/>', {
101+
class: scandioHtmlClass
102+
}).appendTo('body');
103+
}
104+
});
105+
},
106+
95107
// Any call to subordinate initialization function goes here
96108
// *Note:* We're in pre-creation state
97109
_initialize = function() {
98110
// As the adove catching of console calls
99111
_catchConsole();
112+
_injectDom();
100113
};
101114

102115
// Intialize
@@ -107,36 +120,137 @@
107120

108121
// Version of our library
109122
ß.VERSION = '0.0.1';
123+
// DOM functionality
124+
// ---------------
125+
126+
// Register dom namespace on scandiojs object
127+
128+
ß.dom = {};
129+
130+
// Closes and secures a cache module with within its own scope
131+
// *Note:* This function being an IIFE leaves of parameters on outer function
132+
ß.dom.cache = (function($, ß){
133+
// Sets up local cache store
134+
var
135+
cache = {},
136+
137+
// Handler of DOMNodeRemoved handling external node removals
138+
// Sorry, I didn't hack this
139+
nodeRemoved = function(event) {
140+
var label, coll, l, t = event.target;
141+
for (label in cache) {
142+
l = (coll = cache[label]).length;
143+
while (l--) {
144+
if (coll[l] === t || $.contains(t,coll[l])) {
145+
delete coll[l]; --coll.length;
146+
}
147+
}
148+
}
149+
},
150+
151+
// Updates complete cache or scoped to a label
152+
update = function(label) {
153+
// Passed in label is string, scoping to that label
154+
if (ß.isString(label)) {
155+
//Reset cache value at label
156+
if(cache[label] !== undefined) {
157+
cache[label] = $(cache[label].selector || '');
158+
}
159+
} else {
160+
// For each value in cache refresh it
161+
ß.util.each(cache, function($cached, label) {
162+
cache[label] = $($cached.selector);
163+
});
164+
}
165+
},
166+
167+
// Gets a value from cache or loads it from DOM
168+
get = function(label, selector) {
169+
// Both label and selector passed, cache/dom reading...
170+
if (ß.isString(selector) && ß.isString(label)) {
171+
// ...either from cache or DOM
172+
cache[label] = cache[label] || $(selector);
173+
}
174+
175+
// What the callee gets: a jQuery object
176+
return cache[label];
177+
};
178+
179+
// Bind to node removal in DOM
180+
$(document).on('DOMNodeRemoved', nodeRemoved);
181+
182+
// Return public functions in object literal
183+
return {
184+
get: get,
185+
update: update
186+
};
187+
}(jQuery, ß));
110188
// Debug/logging module
111189
// ---------------
112190

113191
// Sets up logger object with level and log-history
114192
ß.logger = {
115193
level: 5,
116-
logs: {}
194+
logs: {},
195+
logDom: true
117196
};
118197

198+
ß.debug = {};
199+
119200
// `ß.debug` will get a set of methods (*see return-statement*)
120201
ß.debug = (function(){
121202
var
122203
console = window.console,
123204
length = logMethods.length,
124205
methods = {},
206+
alertEls = {
207+
debug: 'info',
208+
error: 'danger',
209+
info: 'info',
210+
log: 'success',
211+
warn: 'warning'
212+
},
125213
// Closes the scope for `method and level`
126214
// *Note:* Due to js and its state-maintainance for closures
127215
// the last passed argument would otherwise win
128216
createLogger = function (method, level) {
217+
var
218+
logElWrapperPath = 'scandio-log--' + method,
219+
logElInnerPath = 'alert alert-' + alertEls[method] || method;
220+
129221
// Sets up history for the log-method
130222
ß.logger.logs[method] = [];
131223

224+
if (ß.logger.logDom === true) {
225+
$(function() {
226+
$('<div/>', {
227+
class: logElWrapperPath
228+
}).appendTo($scandioEl).html(
229+
$('<div />', {
230+
class: logElInnerPath
231+
})
232+
);
233+
});
234+
235+
ß.dom[method] = function(msg) {
236+
var
237+
className = ".alert-" + alertEls[method] || method,
238+
$logEl = ß.dom.cache.get(logElInnerPath, className).length > 0 ?
239+
ß.dom.cache.get(logElInnerPath, className) : ß.dom.cache.update(logElInnerPath);
240+
241+
if (ß.logger.logDom && $logEl && $logEl.length > 0) { $logEl.append(msg + '<hr />'); }
242+
};
243+
}
244+
132245
// The return value's log-type gets a function
133246
methods[method] = function() {
134247
// Lets get some arguments
135248
var args = slice.call(arguments);
136249

137250
// Only log to console if required by level
138-
if(ß.logger.level > level) {
251+
if (ß.logger.level > level) {
139252
console[method].apply(console, args);
253+
ß.dom[method].apply(ß, args);
140254
}
141255

142256
// but always push it to history
@@ -149,8 +263,7 @@
149263

150264
// Now the `ß.debug`-object gets its functions
151265
return methods;
152-
})();
153-
// Utility functions
266+
})();// Utility functions
154267
// ---------------
155268

156269
// Register util namespace on scandiojs object
@@ -810,69 +923,6 @@
810923
ß.responsive.breakpoint = function(name) {
811924
return $( ß.responsive.breakpointEl ).html() === name;
812925
};
813-
// DOM functionality
814-
// ---------------
815-
816-
// Register dom namespace on scandiojs object
817-
818-
ß.dom = {};
819-
820-
// Closes and secures a cache module with within its own scope
821-
// *Note:* This function being an IIFE leaves of parameters on outer function
822-
ß.dom.cache = (function($, ß){
823-
// Sets up local cache store
824-
var
825-
cache = {},
826-
827-
// Handler of DOMNodeRemoved handling external node removals
828-
// Sorry, I didn't hack this
829-
nodeRemoved = function(event) {
830-
var label, coll, l, t = event.target;
831-
for (label in cache) {
832-
l = (coll = cache[label]).length;
833-
while (l--) {
834-
if (coll[l] === t || $.contains(t,coll[l])) {
835-
delete coll[l]; --coll.length;
836-
}
837-
}
838-
}
839-
},
840-
841-
// Updates complete cache or scoped to a label
842-
update = function(label) {
843-
// Passed in label is string, scoping to that label
844-
if (ß.isString(label)) {
845-
//Reset cache value at label
846-
cache[label] = $(cache[label].selector || '');
847-
} else {
848-
// For each value in cache refresh it
849-
ß.util.each(cache, function($cached, label) {
850-
cache[label] = $($cached.selector);
851-
});
852-
}
853-
},
854-
855-
// Gets a value from cache or loads it from DOM
856-
get = function(label, selector) {
857-
// Both label and selector passed, cache/dom reading...
858-
if (ß.isString(selector) && ß.isString(label)) {
859-
// ...either from cache or DOM
860-
cache[label] = cache[label] || $(selector);
861-
}
862-
863-
// What the callee gets: a jQuery object
864-
return cache[label];
865-
};
866-
867-
// Bind to node removal in DOM
868-
$(document).on('DOMNodeRemoved', nodeRemoved);
869-
870-
// Return public functions in object literal
871-
return {
872-
get: get,
873-
update: update
874-
};
875-
}(jQuery, ß));
876926
// Outro, AMD and conflict resolution
877927
// ---------------
878928

dist/scandio-0.1.0.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)