{I" class:ETI"ProcessedAsset;FI"logical_path;TI"storytime/editor.js;FI" pathname;TI"\/Users/ben/flyover/projects/storytime/app/assets/javascripts/storytime/editor.js.coffee;FI"content_type;TI"application/javascript;TI" mtime;Tl+#FTI" length;TiI" digest;TI"%043288640af529b69a932a642fac2b97;FI" source;TI"(function() { Storytime.Dashboard.Editor = (function() { var addUnloadHandler; function Editor() {} Editor.prototype.init = function() { var excerpt_character_limit, form, self, title_character_limit; self = this; this.initMedia(); this.initWysiwyg(); title_character_limit = $("#title_character_limit").data("limit"); $("#title_character_limit").html(title_character_limit - $("#post_title").val().length); $("#post_title").keypress(function(e) { if ((e.which === 32 || e.which > 0x20) && ($("#post_title").val().length > title_character_limit - 1)) { e.preventDefault(); } }).keyup(function() { $("#title_character_limit").html(title_character_limit - $("#post_title").val().length); }); excerpt_character_limit = $("#excerpt_character_limit").data("limit"); $("#excerpt_character_limit").html(excerpt_character_limit - $("#post_excerpt").val().length); $("#post_excerpt").keypress(function(e) { if ((e.which === 32 || e.which > 0x20) && ($("#post_excerpt").val().length > excerpt_character_limit - 1)) { e.preventDefault(); } }).keyup(function() { $("#excerpt_character_limit").html(excerpt_character_limit - $("#post_excerpt").val().length); }); if ($(".edit_post").length) { form = $(".edit_post").last(); $("#preview_post").click(function() { self.autosavePostForm(); }); if ($("#main").data("preview")) { $("#preview_post").trigger("click"); window.open($("#preview_post").attr("href")); } } else { form = $(".new_post").last(); $("#preview_new_post").click(function() { $("").insertAfter($(".new_post").children().first()); $(".new_post").submit(); }); } $(".datepicker").datepicker({ dateFormat: "MM d, yy" }); $(".timepicker").timepicker({ showPeriod: true }); addUnloadHandler(form); }; Editor.prototype.initMedia = function() { var mediaInstance; mediaInstance = new Storytime.Dashboard.Media(); mediaInstance.initPagination(); mediaInstance.initInsert(); mediaInstance.initFeaturedImageSelector(); return $(document).on('shown.bs.modal', function() { mediaInstance.initUpload(); }); }; Editor.prototype.initWysiwyg = function() { $(".summernote").summernote({ codemirror: { htmlMode: true, lineNumbers: true, lineWrapping: true, mode: 'text/html', theme: 'monokai' }, height: 300, minHeight: null, maxHeight: null, toolbar: [['style', ['style']], ['font', ['bold', 'italic', 'underline', 'superscript', 'subscript', 'strikethrough', 'clear']], ['color', ['color']], ['para', ['ul', 'ol', 'paragraph']], ['table', ['table']], ['insert', ['link', 'picture', 'video', 'hr']], ['view', ['fullscreen', 'codeview']], ['editing', ['undo', 'redo']], ['help', ['help']]], onblur: function() { $(".summernote").data("range", document.getSelection().getRangeAt(0)); }, onfocus: function() { if ($(".edit_post").length) { self.updateLater(1000); } }, onkeyup: function() { form.data("unsaved-changes", true); }, onImageUpload: function(files, editor, $editable) { $("#media_file").fileupload('send', { files: files }).success(function(result, textStatus, jqXHR) { editor.insertImage($editable, result.file_url); }); } }); $(".note-image-dialog").on('shown.bs.modal', function() { $(".note-image-dialog").find(".row-fluid").append(""); }); return $(".note-image-dialog").on('hide.bs.modal', function() { $("#gallery_copy").remove(); }); }; Editor.prototype.autosavePostForm = function() { var data, post_id, self; self = this; post_id = $("#main").data("post-id"); data = []; data.push({ name: "post[draft_content]", value: $(".summernote").code() }); return $.ajax({ type: "POST", url: "/dashboard/posts/" + post_id + "/autosaves", data: data }); }; Editor.prototype.updateLater = function(timer) { var self, timeoutId; self = this; if (timer == null) { timer = 120000; } timeoutId = window.setTimeout((function() { return self.autosavePostForm().done(function() { var time_now; self.updateLater(10000); time_now = new Date().toLocaleTimeString(); return $("#draft_last_saved_at").html("Draft saved at " + time_now); }).fail(function() { return console.log("Something went wrong while trying to autosave..."); }); }), timer); }; addUnloadHandler = function(form) { form.find("input, textarea").on("keyup", function() { return form.data("unsaved-changes", true); }); $(".save").click(function() { return form.data("unsaved-changes", false); }); return $(window).on("beforeunload", function() { if (form.data("unsaved-changes")) { return "You haven't saved your changes."; } }); }; return Editor; })(); }).call(this); ;TI"dependency_digest;TI"%e706d5aa6b029e9951bacbe29aeee7b8;FI"required_paths;T[I"\/Users/ben/flyover/projects/storytime/app/assets/javascripts/storytime/editor.js.coffee;FI"dependency_paths;T[{I" path;TI"\/Users/ben/flyover/projects/storytime/app/assets/javascripts/storytime/editor.js.coffee;FI" mtime;TI"2014-10-21T04:10:39-05:00;TI" digest;TI"%f336d29876c244eb9bb507a5234b4c77;FI" _version;TI"%5ef14a844324cba3e114bd0123f88a5e;F