{I" class:ETI"ProcessedAsset;FI"logical_path;TI"polyblock/polyblock.js;FI" pathname;TI"i/Applications/XAMPP/xamppfiles/htdocs/polyblock/app/assets/javascripts/polyblock/polyblock.js.coffee;FI"content_type;TI"application/javascript;TI" mtime;Tl+múRI" length;Ti01I" digest;TI"%7c6e3ea19947cf942f8b19a3857339b3;FI" source;TI"01(function() { CKEDITOR.disableAutoInline = true; $(function() { $.unsavedChanges = false; window.onbeforeunload = function() { if ($.unsavedChanges) { return "Are you sure you want to leave this page? Your unsaved changes will not be stored!"; } }; return $(document).ready(function() { var blocks, fetch_blocks, has_switch, initialize, pb_switch; fetch_blocks = (function(_this) { return function() { return $(".polyblock[contenteditable='true']").not('.polyblock-condensed'); }; })(this); blocks = fetch_blocks(); if (!blocks.length) { return; } pb_switch = $('.polyblock-switch'); has_switch = pb_switch.is('*'); initialize = function() { var blockclones, changeChecker, changeText, convertFromTextarea, convertToTextarea, currentMode, editorModeOff, editorModeOn, indicator, initialBodyPadding, instanciateCKEditor, previousMode, revertChanges, saveChanges, showSavedChanges, showSavingChanges, showUnsavedChanges, startListening, stopListening, verbose; blockclones = {}; instanciateCKEditor = function(id) { var editor; return editor = CKEDITOR.inline(id, { on: { contentDom: (function(_this) { return function() { return editor.document.on('keydown', function(e) { if ((e.data.$.ctrlKey || e.data.$.metaKey) && e.data.$.keyCode === 83) { try { e.data.$.preventDefault(); } catch (_error) {} editor.focusManager.blur(true); $('*:focus').blur(); console.log("Before: " + $.unsavedChanges); saveChanges(function() { return console.log("After: " + $.unsavedChanges); }); return false; } }); }; })(this), focus: function(e) { editorModeOn(); return startListening(id); }, blur: function(e) { return stopListening(); } } }); }; blocks.each(function() { var id; id = $(this).attr('id'); blockclones[id] = $(this).clone(); if (!_.contains(_.keys(CKEDITOR.instances), id)) { return instanciateCKEditor(id); } }); verbose = false; changeChecker = null; indicator = $('.pb-change-indicator'); changeText = $('.pb-change-text'); startListening = function(which) { var buffer; stopListening(); if (verbose) { console.log("I'm listening..."); } buffer = CKEDITOR.instances[which].getData(); return changeChecker = setInterval(function() { var reading; if (verbose) { console.log("Checking for changes..."); } reading = CKEDITOR.instances[which].getData(); if (reading !== buffer && !$.unsavedChanges) { return showUnsavedChanges(); } else if (reading === buffer && $.unsavedChanges) { return showSavedChanges(); } }, 1000); }; stopListening = function() { if (changeChecker == null) { return; } if (verbose) { console.log("I'm no longer listening."); } clearInterval(changeChecker); return changeChecker = null; }; showUnsavedChanges = (function(_this) { return function() { indicator.transition({ rotate: "-30deg", color: "red" }); changeText.html("You have unsaved changes.").transition({ color: "red" }); return $.unsavedChanges = true; }; })(this); showSavedChanges = function() { indicator.transition({ rotate: "0deg", color: "green" }); changeText.html("All changes saved.").transition({ color: "green" }); return $.unsavedChanges = false; }; showSavingChanges = (function(_this) { return function() { indicator.transition({ rotate: "30deg", color: "yellow" }); return changeText.html("Saving changes...").transition({ color: "yellow" }); }; })(this); initialBodyPadding = $('body').css("padding-bottom"); editorModeOn = function(pb) { return $('#pb_bar').show("slide", { direction: "down" }, 250, function() { $('body').css("padding-bottom", $("#pb_bar").height() + 20); return typeof pb === "function" ? pb() : void 0; }); }; editorModeOff = function(pb) { return $('#pb_bar').hide("slide", { direction: "down" }, 250, function() { $('body').css("padding-bottom", initialBodyPadding); return typeof pb === "function" ? pb() : void 0; }); }; saveChanges = function(cb) { var pbs; stopListening(); showSavingChanges(); pbs = _.map(blocks, function(b) { return { id: $(b).attr("data-pbid"), name: $(b).attr("data-pbname"), content: $(b).html() }; }); return $.post("/polyblock/update", { pbs: pbs }, function(data) { showSavedChanges(); return editorModeOff(function() { if (typeof alertify !== "undefined" && alertify !== null) { alertify.success("Your changes have been saved."); } return typeof cb === "function" ? cb() : void 0; }); }); }; revertChanges = function(pb) { if (!confirm("Are you sure you want to discard your changes?")) { return; } return editorModeOff(function() { blocks.each(function() { return $(this).replaceWith(blockclones[$(this).attr("id")]); }); if (typeof alertify !== "undefined" && alertify !== null) { return alertify.success("Your changes have been discarded."); } }); }; currentMode = previousMode = "WYSIWYG"; convertToTextarea = function(block, content, tab) { var previous_textarea, replaceIt, tabchars, textarea; if (content == null) { content = null; } if (tab == null) { tab = "\t"; } tabchars = tab.replace(/\\/, "").length; previous_textarea = $("textarea[data-pbid=" + (block.attr("data-pbid")) + "]"); if (content == null) { content = previous_textarea.is("*") ? previous_textarea.val() : block.html(); } textarea = $('