Skip to content

Commit

Permalink
First version of iris debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Angel Sanchez committed Feb 11, 2014
1 parent 801e3b0 commit 859a6de
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 13 deletions.
1 change: 1 addition & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ _Creation date: 2012-01-12_
* upd|fix|new|dep|rmv - description

[0.5.7-SNAPSHOT] 2014-XX-XX
* [new] Iris debug mode, Closed #169


[0.5.6] 2014-01-23
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iris",
"version": "0.5.6",
"version": "0.5.7-SNAPSHOT",
"main": [
"./dist/*"
],
Expand Down
77 changes: 71 additions & 6 deletions dist/iris.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! iris - v0.5.6 - 2014-01-23 (http://thegameofcode.github.io/iris) licensed New-BSD */
/*! iris - v0.5.7-SNAPSHOT - 2014-02-11 (http://thegameofcode.github.io/iris) licensed New-BSD */

var iris = {};

Expand Down Expand Up @@ -132,7 +132,7 @@ window.iris = iris;
iris.off(p_eventName, callbacks[i]);
}

this.events[p_eventName] = {};
this.events[p_eventName] = [];
}
}
};
Expand Down Expand Up @@ -676,7 +676,8 @@ window.iris = iris;
// container: $element, // return the parent container associated with hash (#parent/hash/:id)
// parentNavMap: {} // Parent node in the navigation tree
// }
_screenMetadata
_screenMetadata,
_debugMode
;


Expand Down Expand Up @@ -706,6 +707,9 @@ window.iris = iris;

_paths = [];

// By default debug is disabled
_debugMode = false;

iris.on("iris-reset", function () {
$(window).off("hashchange");
document.location.hash = "#";
Expand Down Expand Up @@ -1165,9 +1169,10 @@ window.iris = iris;
}


var Component = function(id, $container, fileJs) {
var Component = function(id, $container, fileJs, type) {
iris.Settable.call(this);

this.type = type;
this.id = id;
this.uis = []; // child UIs
this.uisMap = {}; // UIs sorted by id
Expand Down Expand Up @@ -1558,7 +1563,7 @@ window.iris = iris;
// UI
//
var UI = function($container, id, fileJs, settings, tmplMode, parentUI) {
Component.call(this, id, $container, fileJs);
Component.call(this, id, $container, fileJs, 'ui');

var jqToHash = _jqToHash($container);

Expand Down Expand Up @@ -1592,7 +1597,7 @@ window.iris = iris;
//
var Screen = function(path) {
var screenMeta = _screenMetadata[path];
Component.call(this, path, screenMeta.container, screenMeta.js);
Component.call(this, path, screenMeta.container, screenMeta.js, 'screen');

this.params = {};
this.screenConId = null;
Expand Down Expand Up @@ -1697,6 +1702,65 @@ window.iris = iris;
}

}

//
// Debug mode
//
function _debug (enabled) {
var $doc = $(window.document);
if ( enabled ) {
$doc.on('keydown', _debugModeOnKeyDown);

var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML =
'.iris-debug-ui { outline: 2px dotted blue; }' +
'.iris-debug-ui-info { font-size: 12px; color: white; background-color: blue; }' +

'.iris-debug-screen { outline: 2px dotted red; }' +
'.iris-debug-screen-info { font-size: 12px; color: white; background-color: red; }';

document.getElementsByTagName('head')[0].appendChild(style);

} else {
$doc.off('keydown', _debugModeOnKeyDown);
}
}

function _debugModeOnKeyDown (e) {
// Control + Shift + Alt + D
if ( e.shiftKey && e.ctrlKey && e.altKey &&
e.keyCode !== 16 && e.keyCode === 68 ) {

_debugMode = !_debugMode;

var screen;
for ( var key in _screen ) {
screen = _screen[key];

_applyDebugMode(screen);

for ( var f = 0, F = screen.uis.length; f < F; f++ ) {
_applyDebugMode( screen.uis[f] );
}
}
}
}

function _applyDebugMode (component) {
component.template.toggleClass('iris-debug-' + component.type, _debugMode);

if ( _debugMode ) {
// Add debug info label
component.debugElement = $(
'<span class="iris-debug-' + component.type + '-info">' +
component.id + ' [' + component.fileJs + ',' + component.fileTmpl + ']' +
'</span>').prependTo(component.template);
} else {
// Remove debug info label
component.debugElement.remove();
}
}

iris.screen = _registerScreen;
iris.destroyScreen = _destroyScreenByPath;
Expand All @@ -1706,6 +1770,7 @@ window.iris = iris;
iris.tmpl = _registerTmpl;
iris.resource = _registerRes;
iris.include = _load;
iris.debug = _debug;

//
// Classes
Expand Down
Loading

0 comments on commit 859a6de

Please sign in to comment.