diff --git a/.eslintrc.yml b/.eslintrc.yml index dec7a9c..9c90984 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -4,6 +4,8 @@ env: browser: true jquery: true extends: 'eslint:recommended' +plugins: + - ignore-erb rules: indent: - error diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 3cfbc1b..9faf3dd 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -14,13 +14,7 @@ //= require jquery_ujs //= require turbolinks //= require modernizr-lite/modernizr -//= require jquery-linedtextarea-moser -//= require button-group -//= require form-animation -//= require summary-edit -//= require textarea-limit -//= require live-coder - - -//= require admin +//= require forms/button-group +//= require forms/animations +//= require forms/textarea-limit diff --git a/app/assets/javascripts/form-animation.js b/app/assets/javascripts/forms/animations.js similarity index 99% rename from app/assets/javascripts/form-animation.js rename to app/assets/javascripts/forms/animations.js index ad71014..a920c94 100644 --- a/app/assets/javascripts/form-animation.js +++ b/app/assets/javascripts/forms/animations.js @@ -7,6 +7,7 @@ $textInput.each(function() { $(this).prev('label').addClass('animate'); } }); + $textInput.on('focus', function() { $(this).prev('label').addClass('animate'); }).on('focusout', function() { diff --git a/app/assets/javascripts/button-group.js b/app/assets/javascripts/forms/button-group.js similarity index 100% rename from app/assets/javascripts/button-group.js rename to app/assets/javascripts/forms/button-group.js diff --git a/app/assets/javascripts/textarea-limit.js b/app/assets/javascripts/forms/textarea-limit.js similarity index 100% rename from app/assets/javascripts/textarea-limit.js rename to app/assets/javascripts/forms/textarea-limit.js diff --git a/app/assets/javascripts/live-coder.js b/app/assets/javascripts/live-coder.js new file mode 100644 index 0000000..d641253 --- /dev/null +++ b/app/assets/javascripts/live-coder.js @@ -0,0 +1,2 @@ +//= require live-coder/linedtextarea +//= require live-coder/editor diff --git a/app/assets/javascripts/live-coder.js.erb b/app/assets/javascripts/live-coder/editor.js.erb similarity index 94% rename from app/assets/javascripts/live-coder.js.erb rename to app/assets/javascripts/live-coder/editor.js.erb index c645a5b..3f9652d 100644 --- a/app/assets/javascripts/live-coder.js.erb +++ b/app/assets/javascripts/live-coder/editor.js.erb @@ -18,9 +18,7 @@ function updateResults(elem) { var jqueryNode = document.createElement("script"); jqueryNode.setAttribute("type", "text/javascript"); - // TODO: fix eslint runner to handle erb snippets - // jqueryNode.setAttribute("src", "<%= "//#{ENV['full_app_url']}#{javascript_path "jquery"}" %>"); - jqueryNode.setAttribute("src", "https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"); + jqueryNode.setAttribute("src", "<%= "//#{ENV['full_app_url']}#{javascript_path "jquery"}" %>"); iHead.appendChild(jqueryNode); var codeStyle = document.createElement("style"); diff --git a/app/assets/javascripts/jquery-linedtextarea-moser.js b/app/assets/javascripts/live-coder/linedtextarea.js similarity index 100% rename from app/assets/javascripts/jquery-linedtextarea-moser.js rename to app/assets/javascripts/live-coder/linedtextarea.js diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a638fed..cf00ea8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -28,4 +28,14 @@ module ApplicationHelper %w(Coder live_code) ], selected: (val.blank? ? '' : val)) end + + # include javascript only once + # Allows the safe loading of js dependencies in partials multiple times. + def content_for_javascript_once code_label, &block + @js_blocks ||= [] + return if @js_blocks.include? code_label + + @js_blocks << code_label + content_for :custom_javascipt, &block + end end diff --git a/app/views/admin/question/_live_code.html.erb b/app/views/admin/question/_live_code.html.erb index 99793f0..4efc955 100644 --- a/app/views/admin/question/_live_code.html.erb +++ b/app/views/admin/question/_live_code.html.erb @@ -1,3 +1,9 @@ +<% + content_for_javascript_once 'live-coder' do + javascript_include_tag "live-coder" + end +%> +
diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index ed03bd7..79672e3 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -45,6 +45,8 @@ <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + <%= javascript_include_tag 'admin', 'data-turbolinks-track': 'reload' %> + <%= yield :custom_javascipt %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 1dd9704..dde0cf3 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -52,6 +52,7 @@ <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + <%= yield :custom_javascipt %> diff --git a/app/views/quiz/_live_code.html.erb b/app/views/quiz/_live_code.html.erb index 69b3ccb..98f8477 100644 --- a/app/views/quiz/_live_code.html.erb +++ b/app/views/quiz/_live_code.html.erb @@ -1,4 +1,8 @@ <% + content_for_javascript_once 'live-coder' do + javascript_include_tag "live-coder" + end + option_id = "#{question.question_id}_finish-later" checkbox_html = {class: 'checkbox', id: "answer_#{option_id}", diff --git a/app/views/quiz/summary.html.erb b/app/views/quiz/summary.html.erb index dedf86c..cf0bab9 100644 --- a/app/views/quiz/summary.html.erb +++ b/app/views/quiz/summary.html.erb @@ -2,6 +2,9 @@ content_for :title, "Skills Assessment" content_for :footer_title, "Skills Assessment" content_for :progress, @status.progress.to_s + content_for_javascript_once 'summary-edit' do + javascript_include_tag "summary-edit" + end %>
diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 2cf352a..865c130 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -11,5 +11,5 @@ Rails.application.config.assets.version = '1.0' # Rails.application.config.assets.precompile += %w( search.js ) Rails.application.config.assets.precompile += ['vendor/assets/**/*'] -Rails.application.config.assets.precompile += %w(ie9.js) +Rails.application.config.assets.precompile += %w(ie9.js admin.js summary-edit.js live-coder.js) Rails.application.config.assets.precompile += %w(mailers/foundation_vendor_manifest.scss) diff --git a/package.json b/package.json index 7ce7fab..8ed4a2a 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "rails-dev assets", "dependencies": { "bower": "^1.7.9", - "eslint": "^3.2.2" + "eslint": "^3.2.2", + "eslint-plugin-ignore-erb": "^0.1.0" }, "devDependencies": {}, "repository": {