{I" class:ETI"BundledAsset;FI"logical_path;TI"*tinymce/plugins/uploadimage/plugin.js;TI" pathname;TI"†D:/Ruby215/lib/ruby/gems/2.1.0/gems/tinymce-rails-imageupload-4.0.16.beta/app/assets/javascripts/tinymce/plugins/uploadimage/plugin.js;TI"content_type;TI"application/javascript;TI" mtime;Tl+GUçTI" length;Ti{I" digest;TI"%41e5934c78db78ab79c85e232695179a;FI" source;TI"{(function() { tinymce.PluginManager.requireLangPack('uploadimage'); tinymce.create('tinymce.plugins.UploadImage', { UploadImage: function(ed, url) { var form, iframe, win, throbber, editor = ed; function showDialog() { win = editor.windowManager.open({ title: ed.translate('Insert an image from your computer'), width: 500 + parseInt(editor.getLang('uploadimage.delta_width', 0), 10), height: 180 + parseInt(editor.getLang('uploadimage.delta_height', 0), 10), body: [ {type: 'iframe', url: 'javascript:void(0)'}, {type: 'textbox', name: 'file', label: ed.translate('Choose an image'), subtype: 'file'}, {type: 'textbox', name: 'alt', label: ed.translate('Image description')}, {type: 'container', classes: 'error', html: "

 

"}, ], buttons: [ { text: ed.translate('Insert'), onclick: insertImage, subtype: 'primary' }, { text: ed.translate('Cancel'), onclick: ed.windowManager.close } ], }, { plugin_url: url }); // TinyMCE likes pointless submit handlers win.off('submit'); win.on('submit', insertImage); /* WHY DO YOU HATE
, TINYMCE!? */ iframe = win.find("iframe")[0]; form = createElement('form', { action: ed.getParam("uploadimage_form_url", "/tinymce_assets"), target: iframe._id, method: "POST", enctype: 'multipart/form-data', accept_charset: "UTF-8", }); // Might have several instances on the same page, // so we TinyMCE create unique IDs and use those. iframe.getEl().name = iframe._id; // Create some needed hidden inputs form.appendChild(createElement('input', {type: "hidden", name: "utf8", value: "✓"})); form.appendChild(createElement('input', {type: 'hidden', name: 'authenticity_token', value: getMetaContents('csrf-token')})); form.appendChild(createElement('input', {type: 'hidden', name: 'hint', value: ed.getParam("uploadimage_hint", "")})); var el = win.getEl(); var body = document.getElementById(el.id + "-body"); // Copy everything TinyMCE made into our form var containers = body.getElementsByClassName('mce-container'); for(var i = 0; i < containers.length; i++) { form.appendChild(containers[i]); } // Fix inputs, since TinyMCE hates HTML and forms var inputs = form.getElementsByTagName('input'); for(var i = 0; i < inputs.length; i++) { var ctrl = inputs[i]; if(ctrl.tagName.toLowerCase() == 'input' && ctrl.type != "hidden") { ctrl.name = ctrl.type == "file" ? "file" : "alt"; } } body.appendChild(form); } function insertImage() { if(getInputValue("file") == "") { return handleError('You must choose a file'); } throbber = new top.tinymce.ui.Throbber(win.getEl()); throbber.show(); clearErrors(); /* Add event listeners. * We remove the existing to avoid them being called twice in case * of errors and re-submitting afterwards. */ var target = iframe.getEl(); if(target.attachEvent) { target.detachEvent('onload', uploadDone); target.attachEvent('onload', uploadDone); } else { target.removeEventListener('load', uploadDone); target.addEventListener('load', uploadDone, false); } form.submit(); } function uploadDone() { if(throbber) { throbber.hide(); } var target = iframe.getEl(); if(target.document || target.contentDocument) { var doc = target.contentDocument || target.contentWindow.document; handleResponse(doc.getElementsByTagName("body")[0].innerHTML); } else { handleError("Didn't get a response from the server"); } } function handleResponse(ret) { console.group("Handling response"); console.log("Raw", ret) try { var json = tinymce.util.JSON.parse(ret); console.log("Parsed", json); if(json["error"]) { console.log("It has an error!", json["error"]["message"]); handleError(json["error"]["message"]); } else { console.log("Inserting", buildHTML(json)); ed.execCommand('mceInsertContent', false, buildHTML(json)); ed.windowManager.close(); } } catch(e) { console.log("Bad response :(", e); handleError('Got a bad response from the server'); } console.groupEnd(); } function clearErrors() { var message = win.find(".error")[0].getEl(); if(message) message.getElementsByTagName("p")[0].innerHTML = " "; } function handleError(error) { console.log("Handling error", error); var message = win.find(".error")[0].getEl(); if(message) message.getElementsByTagName("p")[0].innerHTML = ed.translate(error); } function createElement(element, attributes) { var el = document.createElement(element); for(var property in attributes) { if (!(attributes[property] instanceof Function)) { el[property] = attributes[property]; } } return el; } function buildHTML(json) { var default_class = ed.getParam("uploadimage_default_img_class", ""); var alt_text = getInputValue("alt"); var imgstr = ""; return imgstr; } function getInputValue(name) { var inputs = form.getElementsByTagName("input"); for(var i in inputs) if(inputs[i].name == name) return inputs[i].value; return ""; } function getMetaContents(mn) { var m = document.getElementsByTagName('meta'); for(var i in m) if(m[i].name == mn) return m[i].content; return null; } // Add a button that opens a window editor.addButton('uploadimage', { tooltip: ed.translate('Insert an image from your computer'), icon : 'image', onclick: showDialog }); // Adds a menu item to the tools menu editor.addMenuItem('uploadimage', { text: ed.translate('Insert an image from your computer'), icon : 'image', context: 'insert', onclick: showDialog }); } }); tinymce.PluginManager.add('uploadimage', tinymce.plugins.UploadImage); })(); ;TI"required_assets_digest;TI"%9fe4f637765f2e9073eda021154401c8;FI" _version;TI"%64e62ddc273c2f5847f30d698ca14b67;F