2013-01-20 21:52:56 +00:00
|
|
|
###
|
|
|
|
|
Sets up "+1 Exp", "Level Up", etc notifications
|
|
|
|
|
###
|
|
|
|
|
module.exports.setupGrowlNotifications = (model) ->
|
|
|
|
|
return unless jQuery? # Only run this in the browser
|
|
|
|
|
user = model.at '_user'
|
|
|
|
|
|
|
|
|
|
statsNotification = (html, type) ->
|
|
|
|
|
#don't show notifications if user dead
|
|
|
|
|
return if user.get('stats.lvl') == 0
|
|
|
|
|
$.bootstrapGrowl html,
|
|
|
|
|
type: type # (null, 'info', 'error', 'success')
|
|
|
|
|
top_offset: 20
|
|
|
|
|
align: 'right' # ('left', 'right', or 'center')
|
|
|
|
|
width: 250 # (integer, or 'auto')
|
|
|
|
|
delay: 3000
|
|
|
|
|
allow_dismiss: true
|
|
|
|
|
stackup_spacing: 10 # spacing between consecutive stacecked growls.
|
|
|
|
|
|
|
|
|
|
# Setup listeners which trigger notifications
|
|
|
|
|
user.on 'set', 'stats.hp', (captures, args) ->
|
|
|
|
|
num = captures - args
|
|
|
|
|
rounded = Math.abs(num.toFixed(1))
|
|
|
|
|
if num < 0
|
|
|
|
|
statsNotification "<i class='icon-heart'></i>HP -#{rounded}", 'error' # lost hp from purchase
|
|
|
|
|
|
|
|
|
|
user.on 'set', 'stats.money', (captures, args) ->
|
|
|
|
|
num = captures - args
|
|
|
|
|
rounded = Math.abs(num.toFixed(1))
|
|
|
|
|
# made purchase
|
|
|
|
|
if num < 0
|
|
|
|
|
# FIXME use 'warning' when unchecking an accidently completed daily/todo, and notify of exp too
|
|
|
|
|
statsNotification "<i class='icon-star'></i>GP -#{rounded}", 'success'
|
|
|
|
|
# gained money (and thereby exp)
|
|
|
|
|
else if num > 0
|
|
|
|
|
num = Math.abs(num)
|
|
|
|
|
statsNotification "<i class='icon-star'></i>Exp,GP +#{rounded}", 'success'
|
|
|
|
|
|
|
|
|
|
user.on 'set', 'stats.lvl', (captures, args) ->
|
|
|
|
|
if captures > args
|
|
|
|
|
statsNotification('<i class="icon-chevron-up"></i> Level Up!', 'info')
|
|
|
|
|
|
2012-12-05 16:09:27 +00:00
|
|
|
###
|
|
|
|
|
Loads JavaScript files from (1) public/js/* and (2) external sources
|
|
|
|
|
We use this file (instead of <Scripts:> or <Tail:> inside .html) so we can utilize require() to concatinate for
|
|
|
|
|
faster page load, and $.getScript for asyncronous external script loading
|
|
|
|
|
###
|
2013-01-20 21:52:56 +00:00
|
|
|
module.exports.loadJavaScripts = (model) ->
|
2012-12-05 16:09:27 +00:00
|
|
|
|
|
|
|
|
# Load public/js/* files
|
|
|
|
|
# TODO use Bower
|
|
|
|
|
require '../../public/js/jquery.min'
|
2013-01-18 22:36:14 +00:00
|
|
|
require '../../public/js/jquery-ui.min' unless model.get('_view.mobileDevice')
|
2012-12-05 16:09:27 +00:00
|
|
|
require '../../public/js/bootstrap.min' #http://twitter.github.com/bootstrap/assets/js/bootstrap.min.js
|
|
|
|
|
require '../../public/js/jquery.cookie' #https://raw.github.com/carhartl/jquery-cookie/master/jquery.cookie.js
|
|
|
|
|
require '../../public/js/bootstrap-tour' #https://raw.github.com/pushly/bootstrap-tour/master/bootstrap-tour.js
|
|
|
|
|
require '../../public/js/jquery.bootstrap-growl.min'
|
|
|
|
|
|
|
|
|
|
# JS files not needed right away (google charts) or entirely optional (analytics)
|
|
|
|
|
# Each file getsload asyncronously via $.getScript, so it doesn't bog page-load
|
2013-01-18 22:36:14 +00:00
|
|
|
unless model.get('_view.mobileDevice')
|
2012-12-05 16:09:27 +00:00
|
|
|
|
|
|
|
|
# Addthis
|
|
|
|
|
$.getScript "https://s7.addthis.com/js/250/addthis_widget.js#pubid=lefnire"
|
|
|
|
|
|
|
|
|
|
# Google Charts
|
|
|
|
|
$.getScript "https://www.google.com/jsapi", ->
|
|
|
|
|
# Specifying callback in options param is vital! Otherwise you get blank screen, see http://stackoverflow.com/a/12200566/362790
|
|
|
|
|
google.load "visualization", "1", {packages:["corechart"], callback: ->}
|
|
|
|
|
|
2012-12-12 05:30:36 +00:00
|
|
|
# Note, Google Analyatics giving beef if in this file. Moved back to index.html. It's ok, it's async - really the
|
|
|
|
|
# syncronous requires up top are what benefit the most from this file.
|