Skip to content

Commit

Permalink
Merge pull request #8 from theodi/ie
Browse files Browse the repository at this point in the history
IE polyfill support
  • Loading branch information
Floppy committed Jun 23, 2014
2 parents 039d8f9 + 60a51c5 commit 400977d
Show file tree
Hide file tree
Showing 6 changed files with 504 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dashing.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |s|
s.name = 'dashing'
s.version = '1.3.2'
s.version = '1.3.x'
s.date = '2013-11-21'
s.executables << 'dashing'

Expand Down
15 changes: 12 additions & 3 deletions javascripts/dashing.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Dashing.params = Batman.URI.paramsFromQuery(window.location.search.slice(1));
class Dashing.Widget extends Batman.View
constructor: ->
# Set the view path
@constructor::source = Batman.Filters.underscore(@constructor.name)
@constructor::source = Batman.Filters.underscore(@getName())
super

@mixin($(@node).data())
Expand All @@ -54,7 +54,15 @@ class Dashing.Widget extends Batman.View

@::on 'ready', ->
Dashing.Widget.fire 'ready'


getName: () =>
if (@constructor.name?)
return @constructor.name
# get constructor name from Function.toString
funcNameRegex = /function ([^\(]{1,})\(/;
results = (funcNameRegex).exec(@constructor.toString())
if (results && results.length > 1) then results[1].trim() else ""

receiveData: (data) =>
@mixin(data)
@onData(data)
Expand Down Expand Up @@ -94,7 +102,8 @@ Dashing.debugMode = false

source = new EventSource('/events')
source.addEventListener 'open', (e) ->
console.log("Connection opened", e)
if Dashing.debugMode
console.log("Connection opened", e)

source.addEventListener 'error', (e)->
console.log("Connection error", e)
Expand Down
11 changes: 11 additions & 0 deletions lib/dashing/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,19 @@ def protected!
get '/events', provides: 'text/event-stream' do
protected!
response.headers['X-Accel-Buffering'] = 'no' # Disable buffering for nginx
response.headers['Access-Control-Allow-Origin'] = '*' # For Yaffle eventsource polyfill
response.headers['Cache-Control'] = 'no-cache' # For Yaffle eventsource polyfill

stream :keep_open do |out|
settings.connections << out

# For Yaffle eventsource polyfill
#Add 2k padding for IE
str = ":".ljust(2049) << "\n"
#add retry key
str << "retry: 2000\n"
out << str

out << latest_events
out.callback { settings.connections.delete(out) }
end
Expand Down
6 changes: 5 additions & 1 deletion templates/project/assets/javascripts/application.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# make sure Yaffle's eventsource goes in first
#= require eventsource.js


# dashing.js is located in the dashing framework
# It includes jquery & batman for you.
#= require dashing.js

#= require_directory .
#= require_tree ../../widgets

console.log("Yeah! The dashboard has started!")
# console.log("Yeah! The dashboard has started!")

Dashing.on 'ready', ->
Dashing.widget_margins ||= [5, 5]
Expand Down
Loading

0 comments on commit 400977d

Please sign in to comment.