//= require jquery //= require jquery_ujs //= require jquery-ui/widgets/datepicker //= require autocomplete-rails //= require jquery-fileupload/basic //= require jquery-fileupload/vendor/tmpl //= require lines/admin/pictures //= require lines/admin/autosize.min //= require lines/admin/navbar // Function to insert uploaded pictures into the content at cursor position jQuery.fn.extend({ insertAtCaret: function(myValue){ return this.each(function(i) { if (document.selection) { //For browsers like Internet Explorer this.focus(); sel = document.selection.createRange(); sel.text = myValue; this.focus(); } else if (this.selectionStart || this.selectionStart == '0') { //For browsers like Firefox and Webkit based var startPos = this.selectionStart; var endPos = this.selectionEnd; var scrollTop = this.scrollTop; this.value = this.value.substring(0, startPos)+myValue+this.value.substring(endPos,this.value.length); this.focus(); this.selectionStart = startPos + myValue.length; this.selectionEnd = startPos + myValue.length; this.scrollTop = scrollTop; } else { this.value += myValue; this.focus(); } }); } }); // Handle Attachment Upload attachment = { init: function() { if ($('#article_document').length > 0) { this.bind_events(); } }, bind_events: function() { $(document).on('click', '.btn-delete-attachment', function(e) { e.preventDefault(); $(this).remove(); $('#article_remove_document').prop('checked', true); $('.attachment-label').html('Attach Document'); }); document.getElementById('article_document').addEventListener('change', this.preview, false); }, preview: function(e) { var files = e.target.files; if (files.length > 0) { var f = files[0]; label = f.name + ' (' + Math.round((f.size / 1000000) * 100) / 100 + 'MB)'; $('.attachment-label').html(label); $('.btn-delete-attachment').remove(); $('#article_remove_document').prop('checked', false); $('.attachment-label').after(''); } } }; // Handle Hero Image Uploads / Selection / Preview hero_image = { init: function() { if ($('#article_hero_image').length > 0) { this.bind_events(); this.check_availability(); } }, bind_events: function() { $(document).on('click', '.btn-change-hero', function(e) { e.preventDefault(); $('.upload-overlay').fadeIn('fast'); $('body').addClass('no-scroll'); }); $(document).on('click', '.hero-background-overlay, .upload-overlay-close', function(e) { e.preventDefault(); $('.upload-overlay').fadeOut('fast'); $('body').removeClass('no-scroll'); }); $(document).on('click', '.hero-images img', function(e) { e.preventDefault(); hero_image.preview_default($(this)); }); $(document).on('click', '.btn-remove-hero', function(e) { e.preventDefault(); hero_image.remove_hero(); }); document.getElementById('article_hero_image').addEventListener('change', this.preview, false); }, check_availability: function() { if (!window.File && !window.FileReader && !window.FileList && !window.Blob) { console.log('The File APIs are not fully supported in this browser.'); } }, remove_hero: function() { $('#article_short_hero_image, #article_hero_image_file').val(''); upload_field = $('#article_hero_image') upload_field.wrap('