Fixing bug with application require for now. Shoutout for Firebase.

This commit is contained in:
Nick Winter 2014-01-06 23:45:33 -08:00
parent 250b7322a9
commit 70cd16cee4
14 changed files with 46 additions and 58 deletions

View file

@ -5,20 +5,31 @@ locale = require 'locale/locale'
Tracker = require 'lib/Tracker'
CocoView = require 'views/kinds/CocoView'
preventBackspace = (event) ->
if event.keyCode is 8 and not elementAcceptsKeystrokes(event.srcElement or event.target)
event.preventDefault()
elementAcceptsKeystrokes = (el) ->
# http://stackoverflow.com/questions/1495219/how-can-i-prevent-the-backspace-key-from-navigating-back
el ?= document.activeElement
tag = el.tagName.toLowerCase()
type = el.type?.toLowerCase()
textInputTypes = ['text', 'password', 'file', 'number', 'search', 'url', 'tel', 'email', 'date', 'month', 'week', 'time', 'datetimelocal']
# not radio, checkbox, range, or color
return (tag is 'textarea' or (tag is 'input' and type in textInputTypes) or el.contentEditable in ["", "true"]) and not (el.readOnly or el.disabled)
COMMON_FILES = ['/images/modal_background.png', '/images/level/code_palette_background.png']
preload = (arrayOfImages) ->
$(arrayOfImages).each ->
$('<img/>')[0].src = @
Application = initialize: ->
Router = require('lib/Router')
@tracker = new Tracker()
new FacebookHandler()
new GPlusHandler()
$(document).bind 'keydown', preventBackspace
console.log 'done applied it'
preload(COMMON_FILES)
$.i18n.init {
lng: me?.lang() ? 'en'
@ -36,19 +47,3 @@ Application = initialize: ->
module.exports = Application
window.application = Application
preventBackspace = (event) ->
console.log 'PREVENT', event
if event.keyCode is 8 and not elementAcceptsKeystrokes(event.srcElement or event.target)
event.preventDefault()
# event.preventDefault()
elementAcceptsKeystrokes = (el) ->
# http://stackoverflow.com/questions/1495219/how-can-i-prevent-the-backspace-key-from-navigating-back
el ?= document.activeElement
tag = el.tagName.toLowerCase()
type = el.type?.toLowerCase()
textInputTypes = ['text', 'password', 'file', 'number', 'search', 'url', 'tel', 'email', 'date', 'month', 'week', 'time', 'datetimelocal']
# not radio, checkbox, range, or color
return (tag is 'textarea' or (tag is 'input' and type in textInputTypes) or el.contentEditable in ["", "true"]) and not (el.readOnly or el.disabled)

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

View file

@ -14,13 +14,13 @@ app = require 'application'
# * Connecting to Firebase
module.exports = class LevelLoader extends CocoClass
spriteSheetsBuilt: 0
spriteSheetsToBuild: 0
subscriptions:
'god:new-world-created': 'loadSoundsForWorld'
constructor: (@levelID, @supermodel, @sessionID) ->
super()
@loadSession()
@ -28,20 +28,20 @@ module.exports = class LevelLoader extends CocoClass
@loadAudio()
@playJingle()
setTimeout (=> @update()), 1 # lets everything else resolve first
playJingle: ->
jingles = ["ident_1", "ident_2"]
AudioPlayer.playInterfaceSound jingles[Math.floor Math.random() * jingles.length]
# Session Loading
loadSession: ->
url = if @sessionID then "/db/level_session/#{@sessionID}" else "/db/level/#{@levelID}/session"
@session = new LevelSession()
@session.url = -> url
@session.fetch()
@session.once 'sync', @onSessionLoaded
onSessionLoaded: =>
# TODO: maybe have all non versioned models do this? Or make it work to PUT/PATCH to relative urls
@session.url = -> '/db/level.session/' + @id
@ -54,20 +54,20 @@ module.exports = class LevelLoader extends CocoClass
@supermodel.on 'loaded-one', @onSupermodelLoadedOne
@supermodel.once 'error', @onSupermodelError
@level = @supermodel.getModel(Level, @levelID) or new Level _id: @levelID
@supermodel.shouldPopulate = (model) =>
# if left unchecked, the supermodel would load this level
# and every level next on the chain. This limits the population
handles = [model.id, model.get 'slug']
return model.constructor.className isnt "Level" or @levelID in handles
@supermodel.populateModel @level
onSupermodelError: =>
msg = $.i18n.t('play_level.level_load_error',
defaultValue: "Level could not be loaded.")
@$el.html('<div class="alert">' + msg + '</div>')
onSupermodelLoadedOne: (e) =>
@notifyProgress()
if e.model.type() is 'ThangType'
@ -83,8 +83,8 @@ module.exports = class LevelLoader extends CocoClass
@trigger 'loaded-supermodel'
@stopListening(@supermodel)
@update()
# Things to do when either the Session or Supermodel load
# Things to do when either the Session or Supermodel load
update: ->
@notifyProgress()
@ -95,7 +95,7 @@ module.exports = class LevelLoader extends CocoClass
@loadLevelSounds()
app.tracker.updatePlayState(@level, @session)
@updateCompleted = true
denormalizeSession: ->
return if @session.get 'levelName'
patch =
@ -108,12 +108,12 @@ module.exports = class LevelLoader extends CocoClass
tempSession = new LevelSession _id: @session.id
tempSession.save(patch, {patch: true})
@sessionDenormalized = true
# Initial Sound Loading
loadAudio: ->
AudioPlayer.preloadInterfaceSounds ["victory"]
loadLevelSounds: ->
scripts = @level.get 'scripts'
return unless scripts
@ -129,7 +129,7 @@ module.exports = class LevelLoader extends CocoClass
AudioPlayer.preloadSoundReference sound for sound in sounds
# Dynamic sound loading
loadSoundsForWorld: (e) ->
world = e.world
thangTypes = @supermodel.getModels(ThangType)
@ -137,12 +137,12 @@ module.exports = class LevelLoader extends CocoClass
continue unless thangType = _.find thangTypes, (m) -> m.get('name') is spriteName
continue unless sound = AudioPlayer.soundForDialogue message, thangType.get('soundTriggers')
filename = AudioPlayer.preloadSoundReference sound
# everything else sound wise is loaded as needed as worlds are generated
allDone: ->
@supermodel.finished() and @session.loaded and @spriteSheetsBuilt is @spriteSheetsToBuild
progress: ->
return 0 unless @level.loaded
overallProgress = 0
@ -161,4 +161,3 @@ module.exports = class LevelLoader extends CocoClass
destroy: ->
@supermodel.off 'loaded-one', @onSupermodelLoadedOne
super()

View file

@ -1,4 +1,3 @@
application = require 'application'
{me} = require 'lib/auth'
gplusClientID = "800329290710-j9sivplv2gpcdgkrsis9rff3o417mlfa.apps.googleusercontent.com"
@ -62,7 +61,7 @@ module.exports = class CocoRouter extends Backbone.Router
@renderLoginButtons()
renderLoginButtons: ->
$('.share-buttons').addClass('fade-in').delay(10000).removeClass('fade-in', 5000)
$('.share-buttons, .partner-badges').addClass('fade-in').delay(10000).removeClass('fade-in', 5000)
setTimeout(FB.XFBML.parse, 10) if FB? # Handles FB login and Like
twttr?.widgets?.load()

View file

@ -88,10 +88,9 @@ h1 h2 h3 h4
padding-top: 25px
text-align: center
.mixpanel-badge
display: block
.mixpanel-badge, .firebase-badge
width: 100px
margin: 10px auto 0px
margin: 10px 10px 0px
.footer-link-text a
font-family: 'Bangers', cursive
@ -103,7 +102,7 @@ h1 h2 h3 h4
a[data-toggle="modal"]
cursor: pointer
.share-buttons
.share-buttons, .partner-badges
margin-top: 10px
text-align: center
@include opacity(75)

View file

@ -58,5 +58,8 @@ body
.fb-like(data-href="https://www.facebook.com/codecombat", data-send="false", data-layout="button_count", data-width="350", data-show-faces="true", data-ref="coco_footer_#{fbRef}")
a.twitter-follow-button(href="https://twitter.com/CodeCombat", data-show-count="true", data-show-screen-name="false", data-dnt="true", data-align="right", data-i18n="nav.twitter_follow") Follow
//iframe(src="https://www.lendyour.net/embed/lendbutton?account_id=6&campaign_id=7", frameBorder="0")
.partner-badges
a.mixpanel-badge(href="https://mixpanel.com/f/partner")
img(src="//cdn.mxpnl.com/site_media/images/partner/badge_light.png", alt="Mobile Analytics")
a.firebase-bade(href="https://www.firebase.com/")
img(src="/images/pages/base/firebase.png", alt="Powered by Firebase")

View file

@ -1,3 +1,4 @@
SignupModalView = require 'views/modal/signup_modal'
View = require 'views/kinds/RootView'
{me} = require('lib/auth')

View file

@ -1,7 +1,6 @@
View = require 'views/kinds/RootView'
template = require 'templates/editor/article/edit'
Article = require 'models/Article'
app = require 'application'
module.exports = class ArticleEditView extends View
id: "editor-article-edit-view"
@ -10,7 +9,7 @@ module.exports = class ArticleEditView extends View
events:
'click #preview-button': 'openPreview'
subscriptions:
'save-new-version': 'saveNewArticle'
@ -40,7 +39,7 @@ module.exports = class ArticleEditView extends View
change: @pushChangesToPreview
options.readOnly = true unless me.isAdmin()
@treema = @$el.find('#article-treema').treema(options)
@treema.build()
pushChangesToPreview: =>
@ -65,7 +64,7 @@ module.exports = class ArticleEditView extends View
@treema.endExistingEdits()
for key, value of @treema.data
@article.set(key, value)
newArticle = if e.major then @article.cloneNewMajorVersion() else @article.cloneNewMinorVersion()
newArticle.set('commitMessage', e.commitMessage)
res = newArticle.save()

View file

@ -3,7 +3,6 @@ template = require 'templates/editor/level/edit'
Level = require 'models/Level'
LevelSystem = require 'models/LevelSystem'
World = require 'lib/world/world'
app = require 'application'
DocumentFiles = require 'collections/DocumentFiles'
ThangsTabView = require './thangs_tab_view'

View file

@ -2,7 +2,6 @@ View = require 'views/kinds/ModalView'
template = require 'templates/editor/level/fork'
forms = require 'lib/forms'
Level = require 'models/Level'
application = require('application')
module.exports = class LevelForkView extends View
id: "editor-level-fork-modal"
@ -44,4 +43,4 @@ module.exports = class LevelForkView extends View
forms.applyErrorsToForm(@$el.find('form'), JSON.parse(res.responseText))
res.success =>
@hide()
application.router.navigate('editor/level/' + newLevel.get('slug'), {trigger: true})
application.router.navigate('editor/level/' + newLevel.get('slug'), {trigger: true})

View file

@ -3,7 +3,6 @@ template = require 'templates/editor/level/save'
forms = require 'lib/forms'
LevelComponent = require 'models/LevelComponent'
LevelSystem = require 'models/LevelSystem'
application = require('application')
module.exports = class LevelSaveView extends SaveVersionModal
template: template

View file

@ -4,7 +4,6 @@ ThangType = require 'models/ThangType'
SpriteParser = require 'lib/sprites/SpriteParser'
SpriteBuilder = require 'lib/sprites/SpriteBuilder'
CocoSprite = require 'lib/surface/CocoSprite'
app = require 'application'
Camera = require 'lib/surface/Camera'
ThangComponentEditView = require 'views/editor/components/main'
DocumentFiles = require 'collections/DocumentFiles'
@ -104,7 +103,7 @@ module.exports = class ThangTypeEditView extends View
createjs.Ticker.setFPS(30)
createjs.Ticker.addEventListener("tick", @stage)
toggleDots: ->
@showDots = not @showDots
@updateDots()

View file

@ -1,4 +1,3 @@
application = require 'application'
SuperModel = require 'models/SuperModel'
utils = require 'lib/utils'
CocoClass = require 'lib/CocoClass'

View file

@ -1,7 +1,6 @@
View = require 'views/kinds/RootView'
template = require 'templates/play/level'
{me} = require('lib/auth')
application = require('application')
ThangType = require 'models/ThangType'
# temp hard coded data
@ -202,7 +201,6 @@ module.exports = class PlayLevelView extends View
window.tracker?.identify {skipBreakThePrison: skip}
url = '/play/level/taunt' if skip
# application.router.navigate url, trigger: true
Backbone.Mediator.publish 'router:navigate', {
route: url,
viewClass: PlayLevelView,