diff --git a/Gemfile b/Gemfile index 4ef14eb..451be9a 100644 --- a/Gemfile +++ b/Gemfile @@ -54,6 +54,9 @@ group :development do gem 'capistrano', '~> 3.1' gem 'capistrano-rails', '~> 1.1' gem 'capistrano-faster-assets', '~> 1.0' + + gem 'eventmachine', :github => 'krzcho/eventmachine', :branch => 'master' + gem 'thin', :github => 'krzcho/thin', :branch => 'master' end group :test do diff --git a/app/assets/images/edit.svg b/app/assets/images/edit.svg new file mode 100644 index 0000000..68f41ae --- /dev/null +++ b/app/assets/images/edit.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/app/assets/images/img.svg b/app/assets/images/img.svg new file mode 100644 index 0000000..9a3e09d --- /dev/null +++ b/app/assets/images/img.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/app/assets/images/link.svg b/app/assets/images/link.svg new file mode 100644 index 0000000..f279380 --- /dev/null +++ b/app/assets/images/link.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/app/assets/images/ol.svg b/app/assets/images/ol.svg new file mode 100644 index 0000000..405f9a0 --- /dev/null +++ b/app/assets/images/ol.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/app/assets/images/quote.svg b/app/assets/images/quote.svg new file mode 100644 index 0000000..53c1304 --- /dev/null +++ b/app/assets/images/quote.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/app/assets/images/ul.svg b/app/assets/images/ul.svg new file mode 100644 index 0000000..145e61f --- /dev/null +++ b/app/assets/images/ul.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/app/assets/javascripts/editor.js b/app/assets/javascripts/editor.js new file mode 100644 index 0000000..ed4c0be --- /dev/null +++ b/app/assets/javascripts/editor.js @@ -0,0 +1,79 @@ +(function() { + var pens = {}; + + Array.prototype.forEach.call(document.querySelectorAll('.textarea'), function(editor) { + startEditing(editor); + }); + + function startEditing(editor) { + var name = editor.dataset.name; + pens[name] = new Pen({ + editor: editor, + class: 'pen', + textarea: '', + list: ['p', 'h3', 'h4', 'blockquote', 'insertorderedlist', 'insertunorderedlist', 'bold', 'italic', 'underline', 'strikethrough', 'createlink', 'insertimage'], + title: { + 'p': 'Paragraph', + 'h3': 'Major Heading', + 'h4': 'Minor Heading', + 'blockquote': 'Quotation', + 'insertorderedlist': 'Ordered List', + 'insertunorderedlist': 'Unordered List', + 'bold': 'Bold', + 'italic': 'Italic', + 'underline': 'Underline', + 'strikethrough': 'Strikethrough', + 'createlink': 'Link', + 'insertimage': 'Image' + } + }); + } + + Array.prototype.forEach.call(document.querySelectorAll('form'), function(form) { + var shouldAllowAlert = false; + form.addEventListener('submit', function() { + if (shouldAllowAlert) { + return; + } + Array.prototype.forEach.call(document.querySelectorAll('.textarea'), function(editor) { + var name = editor.dataset.name; + var textarea = document.querySelector('textarea[name="' + name + '"]'); + if (!textarea) { + textarea = document.createElement('textarea'); + textarea.name = name; + textarea.style.display = 'none'; + form.appendChild(textarea); + } + textarea.value = editor.innerHTML; + pens[name].destroy(); + }); + }, false); + Array.prototype.forEach.call(form.querySelectorAll('button'), function(button) { + form.addEventListener('click', function(event) { + shouldAllowAlert = (event.target.value === 'cancel'); + }); + }); + }); + + Array.prototype.forEach.call(document.querySelectorAll('.check-box-field .other input'), function(input) { + var checkbox = document.getElementById(input.parentElement.parentElement.attributes.for.value); + input.addEventListener('keyup', function(event) { + if (event.target.value) { + checkbox.checked = true; + } + }); + input.addEventListener('click', function(event) { + checkbox.checked = true; + }); + var setRequired = function() { + if (checkbox.checked) { + input.setAttribute('required', 'required'); + } else { + input.removeAttribute('required'); + } + }; + Array.prototype.forEach.call(document.querySelectorAll('.check-box-field input'), function(_input) { + _input.addEventListener('change', function(event) { setRequired(); }); + }); + }); +})(); diff --git a/app/assets/javascripts/editor.js.coffee b/app/assets/javascripts/editor.js.coffee deleted file mode 100644 index 56ba4ef..0000000 --- a/app/assets/javascripts/editor.js.coffee +++ /dev/null @@ -1,37 +0,0 @@ -#= require froala_editor.min.js -$ -> - $('[data-editable]').editable({inlineMode: true, blockTags: ["n", "p", "h2", "blockquote", "pre"], buttons: ["formatBlock", "bold", "italic", "underline", "insertOrderedList", "insertUnorderedList", "sep", "createLink", "insertImage", "insertVideo", "html", "undo", "redo"]}) - $('[data-editor]').editable({inlineMode: false, blockTags: ["n", "p", "h2", "blockquote", "pre"], buttons: ["formatBlock", "bold", "italic", "underline", "insertOrderedList", "insertUnorderedList", "sep", "createLink", "html", "undo", "redo"]}) - $('.field.country-select-field select').change () -> - $country = $(this) - country = $country.val() - $territory = $('.field.subregion-select-field select') - if $territory.data().country == country - $territory.removeClass('can cant').addClass('can') - return - - $.post '/location/territories', {country: country}, - (json) -> - $territory.html('') - if json && Object.keys(json).length - $.each json, (code, name) -> - $territory.append($('