organized js assets

completes #11
This commit is contained in:
Mark Moser 2016-09-07 17:45:22 -05:00
parent a977c0ceb3
commit 1ded44610b
16 changed files with 38 additions and 14 deletions

View File

@ -4,6 +4,8 @@ env:
browser: true browser: true
jquery: true jquery: true
extends: 'eslint:recommended' extends: 'eslint:recommended'
plugins:
- ignore-erb
rules: rules:
indent: indent:
- error - error

View File

@ -14,13 +14,7 @@
//= require jquery_ujs //= require jquery_ujs
//= require turbolinks //= require turbolinks
//= require modernizr-lite/modernizr //= require modernizr-lite/modernizr
//= require jquery-linedtextarea-moser
//= require button-group //= require forms/button-group
//= require form-animation //= require forms/animations
//= require summary-edit //= require forms/textarea-limit
//= require textarea-limit
//= require live-coder
//= require admin

View File

@ -7,6 +7,7 @@ $textInput.each(function() {
$(this).prev('label').addClass('animate'); $(this).prev('label').addClass('animate');
} }
}); });
$textInput.on('focus', function() { $textInput.on('focus', function() {
$(this).prev('label').addClass('animate'); $(this).prev('label').addClass('animate');
}).on('focusout', function() { }).on('focusout', function() {

View File

@ -0,0 +1,2 @@
//= require live-coder/linedtextarea
//= require live-coder/editor

View File

@ -18,9 +18,7 @@ function updateResults(elem) {
var jqueryNode = document.createElement("script"); var jqueryNode = document.createElement("script");
jqueryNode.setAttribute("type", "text/javascript"); 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", "<%= "//#{ENV['full_app_url']}#{javascript_path "jquery"}" %>");
jqueryNode.setAttribute("src", "https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js");
iHead.appendChild(jqueryNode); iHead.appendChild(jqueryNode);
var codeStyle = document.createElement("style"); var codeStyle = document.createElement("style");

View File

@ -28,4 +28,14 @@ module ApplicationHelper
%w(Coder live_code) %w(Coder live_code)
], selected: (val.blank? ? '' : val)) ], selected: (val.blank? ? '' : val))
end 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 end

View File

@ -1,3 +1,9 @@
<%
content_for_javascript_once 'live-coder' do
javascript_include_tag "live-coder"
end
%>
<div data-id="live-coder-answer"> <div data-id="live-coder-answer">
<div class="code-input"> <div class="code-input">
<label for="question_input_options_html">HTML</label> <label for="question_input_options_html">HTML</label>

View File

@ -45,6 +45,8 @@
<!--[if ! lte IE 8]><!--> <!--[if ! lte IE 8]><!-->
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'admin', 'data-turbolinks-track': 'reload' %>
<%= yield :custom_javascipt %>
<!--<![endif]--> <!--<![endif]-->
</body> </body>
</html> </html>

View File

@ -52,6 +52,7 @@
<!--[if ! lte IE 8]><!--> <!--[if ! lte IE 8]><!-->
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= yield :custom_javascipt %>
<!--<![endif]--> <!--<![endif]-->
</body> </body>

View File

@ -1,4 +1,8 @@
<% <%
content_for_javascript_once 'live-coder' do
javascript_include_tag "live-coder"
end
option_id = "#{question.question_id}_finish-later" option_id = "#{question.question_id}_finish-later"
checkbox_html = {class: 'checkbox', checkbox_html = {class: 'checkbox',
id: "answer_#{option_id}", id: "answer_#{option_id}",

View File

@ -2,6 +2,9 @@
content_for :title, "Skills Assessment" content_for :title, "Skills Assessment"
content_for :footer_title, "Skills Assessment" content_for :footer_title, "Skills Assessment"
content_for :progress, @status.progress.to_s content_for :progress, @status.progress.to_s
content_for_javascript_once 'summary-edit' do
javascript_include_tag "summary-edit"
end
%> %>
<main class="summary_tpl"> <main class="summary_tpl">

View File

@ -11,5 +11,5 @@ Rails.application.config.assets.version = '1.0'
# Rails.application.config.assets.precompile += %w( search.js ) # Rails.application.config.assets.precompile += %w( search.js )
Rails.application.config.assets.precompile += ['vendor/assets/**/*'] 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) Rails.application.config.assets.precompile += %w(mailers/foundation_vendor_manifest.scss)

View File

@ -4,7 +4,8 @@
"description": "rails-dev assets", "description": "rails-dev assets",
"dependencies": { "dependencies": {
"bower": "^1.7.9", "bower": "^1.7.9",
"eslint": "^3.2.2" "eslint": "^3.2.2",
"eslint-plugin-ignore-erb": "^0.1.0"
}, },
"devDependencies": {}, "devDependencies": {},
"repository": { "repository": {