#= require jquery-ui/widgets/draggable #= require jquery-ui/widgets/resizable $ -> $('#blocks_controls').draggable() $(document).on "click", '.block', -> createInput(this) createInput = (block) -> window.currentBlock = block window.blocksControlsDisplay = $('#blocks_controls').css('display') $('#blocks_controls').hide() key = $(block).attr('class').match(/block_key_\w+/)[0].replace(/block_key_/, '') $.get "/#{$('html').attr('lang')}/admin/blocks/#{key}/edit", (data) -> $('#block_editor').remove() $("
").appendTo('body').draggable().resizable().css(blockRect()) .animate top: $(window).height() * 0.2 left: $(window).width() * 0.2 height: $(window).height() * 0.6 width: $(window).width() * 0.6 , 250 , -> $(data).appendTo('#block_editor') resizeTextArea() $('#block_editor textarea').each -> $textArea = $(this) $textArea.val($(block).html()) unless $textArea.val() $textArea.val($textArea.val().replace(/\s+/gi, " ").replace(/\s*/gi, "")) $(document).on "resize", "#block_editor", (e) -> resizeTextArea() resizeTextArea = -> $('#block_editor textarea').height($('#block_editor').height() - 100) blockRect = -> top: $(window.currentBlock).offset().top - window.scrollY left: $(window.currentBlock).offset().left - window.scrollX height: $(window.currentBlock).height() width: $(window.currentBlock).width() $(document).on "mousemove", "#block_editor a", (e) -> e.stopImmediatePropagation() $(document).on "wheel", "#block_editor", (e) -> e.stopImmediatePropagation() e.target.type == 'textarea' # e.target.scroll(e) false # e.preventDefault() $(document).on "click", "#cancel_block_editing", (e) -> $('#block_editor').animate opacity: 0 top: $('#block_editor').position().top + 0.25 * $('#block_editor').height() left: $('#block_editor').position().left + 0.25 * $('#block_editor').width() height: 0.5 * $('#block_editor').height() width: 0.5 * $('#block_editor').width() , 250 , -> $('#block_editor').remove() $('#blocks_controls').css(display: window.blocksControlsDisplay) e.preventDefault() false $(document).on "click", "#apply_block_editing", (e) -> $('#block_editor').animate blockRect(), 250, -> $('#block_editor form').submit() $('#block_editor').remove() e.preventDefault() false