Skip to content

Commit

Permalink
1.0.3
Browse files Browse the repository at this point in the history
* more performant console
  • Loading branch information
Ryan Brewster committed Oct 28, 2014
1 parent 00ae97c commit 5f5194a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 82 deletions.
61 changes: 13 additions & 48 deletions lib/atrackt.console.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions lib/atrackt.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/atrackt.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 19 additions & 28 deletions src/atrackt.console.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $("<tr><td>#{plugin}</td><td>#{eventType}</td><td>#{trackObject._categories}</td><td>#{trackObject._value}</td></tr>")
$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 = $("<tr><td>#{contextName}</td><td>#{eventType}</td><td>#{trackObject._categories}</td><td>#{trackObject._value}</td></tr>")
$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 ->
Expand Down

0 comments on commit 5f5194a

Please sign in to comment.