diff --git a/lib/atrackt.console.js b/lib/atrackt.console.js
index 1a7af7c..be8e840 100644
--- a/lib/atrackt.console.js
+++ b/lib/atrackt.console.js
@@ -45,63 +45,28 @@ https://github.com/brewster1134/atrackt
};
AtracktConsole.prototype._registerElement = function(context, element, event) {
+ var contextName;
AtracktConsole.__super__._registerElement.call(this, context, element, event);
- return this._renderConsoleElements();
+ contextName = context.name ? context.name : 'ALL';
+ return this._renderConsoleElement(contextName, element, event);
};
- AtracktConsole.prototype._renderConsoleElements = function() {
- var element, elements, eventType, plugin, pluginName, _i, _len, _ref, _ref1, _results;
- $('tbody', this.$console).empty();
- _ref = this._elements;
- for (eventType in _ref) {
- elements = _ref[eventType];
- for (_i = 0, _len = elements.length; _i < _len; _i++) {
- element = elements[_i];
- this._renderConsoleElement('ALL', element, eventType);
- }
- }
- _ref1 = this.plugins;
- _results = [];
- for (pluginName in _ref1) {
- plugin = _ref1[pluginName];
- _results.push((function() {
- var _ref2, _results1;
- _ref2 = plugin._elements;
- _results1 = [];
- for (eventType in _ref2) {
- elements = _ref2[eventType];
- _results1.push((function() {
- var _j, _len1, _results2;
- _results2 = [];
- for (_j = 0, _len1 = elements.length; _j < _len1; _j++) {
- element = elements[_j];
- _results2.push(this._renderConsoleElement(pluginName, element, eventType));
- }
- return _results2;
- }).call(this));
- }
- return _results1;
- }).call(this));
- }
- return _results;
- };
-
- AtracktConsole.prototype._renderConsoleElement = function(plugin, element, eventType) {
+ AtracktConsole.prototype._renderConsoleElement = function(contextName, element, eventType) {
var $rowEl, $trackEl, elementValueId, trackObject;
trackObject = this._getTrackObject(element, eventType);
- $rowEl = $("
" + plugin + " | " + eventType + " | " + trackObject._categories + " | " + trackObject._value + " |
");
- $trackEl = $(element);
- $('tbody', this.$console).append($rowEl);
elementValueId = trackObject._categories.slice(0);
- elementValueId.push(trackObject._value);
- elementValueId.push(eventType);
- elementValueId = elementValueId.join('-').replace(/[^A-Za-z0-9]+/g, '');
- if ($("#" + elementValueId, this.$console).length) {
- $("#" + elementValueId, this.$console).addClass('error');
+ elementValueId.unshift(trackObject._value);
+ elementValueId.unshift(eventType);
+ elementValueId = elementValueId.join('-').toLowerCase().replace(/[^a-z]/g, '');
+ $rowEl = $("" + contextName + " | " + eventType + " | " + trackObject._categories + " | " + trackObject._value + " |
");
+ $trackEl = $(element);
+ if ($("tr#" + elementValueId, this.$console).length) {
+ $("tr#" + elementValueId, this.$console).addClass('error');
$rowEl.addClass('error');
}
- $trackEl.attr('data-atrackt-id', elementValueId);
+ $('tbody', this.$console).append($rowEl);
$rowEl.attr('id', elementValueId);
+ $trackEl.attr('data-atrackt-id', elementValueId);
return $rowEl.add($trackEl).hover(function() {
$rowEl.addClass('atrackt-console-active');
return $trackEl.addClass('atrackt-console-active');
diff --git a/lib/atrackt.js b/lib/atrackt.js
index 96d63a2..73c752c 100644
--- a/lib/atrackt.js
+++ b/lib/atrackt.js
@@ -197,10 +197,10 @@ https://github.com/brewster1134/atrackt
return _results;
};
- Atrackt.prototype._registerElement = function(context, element, event) {
+ Atrackt.prototype._registerElement = function(context, element, eventType) {
var globalEvent, pluginEvent;
- context._elements[event].push(element);
- globalEvent = [event, 'atrackt'];
+ context._elements[eventType].push(element);
+ globalEvent = [eventType, 'atrackt'];
if (context.name) {
pluginEvent = globalEvent.slice(0);
if (context.name) {
diff --git a/src/atrackt.coffee b/src/atrackt.coffee
index 32d03b8..c9540f1 100644
--- a/src/atrackt.coffee
+++ b/src/atrackt.coffee
@@ -155,11 +155,11 @@ https://github.com/brewster1134/atrackt
# * add the element to an elements array (global or plugin)
# * bind the appropriate event (global or plugin)
#
- _registerElement: (context, element, event) ->
- context._elements[event].push element
+ _registerElement: (context, element, eventType) ->
+ context._elements[eventType].push element
# create event namespaces
- globalEvent = [event, 'atrackt']
+ globalEvent = [eventType, 'atrackt']
if context.name
pluginEvent = globalEvent.slice(0)
pluginEvent.push context.name if context.name
diff --git a/src/atrackt.console.coffee b/src/atrackt.console.coffee
index 40eff7a..f4f19c6 100644
--- a/src/atrackt.console.coffee
+++ b/src/atrackt.console.coffee
@@ -59,50 +59,41 @@ https://github.com/brewster1134/atrackt
#
_registerElement: (context, element, event) ->
super context, element, event
- @_renderConsoleElements()
- # Re-render console elements
- #
- _renderConsoleElements: ->
- $('tbody', @$console).empty()
-
- # Render global elements
- for eventType, elements of @_elements
- for element in elements
- @_renderConsoleElement 'ALL', element, eventType
+ contextName = if context.name
+ context.name
+ else
+ 'ALL'
- # Render all plugin elements
- for pluginName, plugin of @plugins
- for eventType, elements of plugin._elements
- for element in elements
- @_renderConsoleElement pluginName, element, eventType
+ @_renderConsoleElement contextName, element, event
# Add a single element to the console
#
- _renderConsoleElement: (plugin, element, eventType) ->
+ _renderConsoleElement: (contextName, element, eventType) ->
# Get element meta data
trackObject = @_getTrackObject element, eventType
- # Build console element html & add it to the dom
- $rowEl = $("#{plugin} | #{eventType} | #{trackObject._categories} | #{trackObject._value} |
")
- $trackEl = $(element)
-
- $('tbody', @$console).append $rowEl
-
# Create unique id
elementValueId = trackObject._categories.slice(0)
- elementValueId.push(trackObject._value)
- elementValueId.push(eventType)
- elementValueId = elementValueId.join('-').replace(/[^A-Za-z0-9]+/g, '')
+ elementValueId.unshift(trackObject._value)
+ elementValueId.unshift(eventType)
+ elementValueId = elementValueId.join('-').toLowerCase().replace(/[^a-z]/g, '')
+
+ # Build console element html
+ $rowEl = $("#{contextName} | #{eventType} | #{trackObject._categories} | #{trackObject._value} |
")
+ $trackEl = $(element)
# Add error class if elements track duplicate data
- if $("##{elementValueId}", @$console).length
- $("##{elementValueId}", @$console).addClass 'error'
+ if $("tr##{elementValueId}", @$console).length
+ $("tr##{elementValueId}", @$console).addClass 'error'
$rowEl.addClass 'error'
+ # add row to console
+ $('tbody', @$console).append $rowEl
+
# Give id to both elements
- $trackEl.attr 'data-atrackt-id', elementValueId
$rowEl.attr 'id', elementValueId
+ $trackEl.attr 'data-atrackt-id', elementValueId
# Add hover event to console element to highlight both the console and the tracked element
$rowEl.add($trackEl).hover ->