Last active
December 11, 2015 23:48
-
-
Save mcmoyer/4679081 to your computer and use it in GitHub Desktop.
my general coffeescript/javascript style
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#embed this in your body tag | |
# %body{body_data} | |
def body_data | |
{ | |
:"data-controller" => params[:controller], | |
:"data-action" => params[:action], | |
:"data-id" => params[:id], | |
:"data-parent-controller" => parent_controller, | |
:"data-parent-id" => params["#{parent_controller.to_s.singularize}_id".to_sym] | |
} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#app/assets/javascripts/initialize.js.coffee | |
window.APP = | |
common: -> | |
console.log "common base function" | |
jQuery -> | |
controller = $("body").data("controller") | |
action = $("body").data("action") | |
app = window.APP | |
fn = app['common'] | |
if typeof(fn) == 'function' | |
fn.call() | |
if app[controller] | |
fnc = app[controller]['common'] | |
if typeof(fnc) == 'function' | |
fnc.call() | |
fna = app[controller][action] | |
if typeof(fna) == 'function' | |
fna.call() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#app/assets/javascripts/page_objects/products.js.coffee | |
$.extend window.APP, | |
products: | |
common: -> | |
#console.log "common functions" | |
index: -> | |
#console.log "index action functions" | |
show: -> | |
new GalleryColorBox() | |
class GalleryColorBox | |
constructor: -> | |
$("a.gallery").colorbox(rel: 'variants') | |
$("div.product-variants").delegate("a.change-picture", "click", (e) -> | |
e.preventDefault() | |
base = $(e.target).parents("div.variant-panel") | |
key = base.data("key") | |
product = $("body").data("id") | |
console.log product, key |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment