allowing image insertions from the urls

Oleg committed Dec 13, 2011
commit c34a8d498f6848412f6c5d7935d324f2aa15d6e9
Showing 2 changed files with 26 additions and 11 deletions
app/assets/javascripts/comfortable_mexican_sofa/elrte/elrte.sofa_image.js +19 -11
@@ @@ -3,16 +3,29 @@
elRTE.prototype.ui.prototype.buttons.sofa_image = function(rte, name) {
this.constructor.prototype.constructor.call(this, rte, name);
- var self = this;
- self.rte = rte;
- self.img = null;
- self.dialog = null;
+ var self = this;
+ self.rte = rte;
+ self.img_src = null;
+ self.dialog = null;
+
+ // attaching event handler to the image insertion form
+ $(document).on('submit', '#cms_dialog form.image_url', function(){
+ self.img_src = $(this).find('input[name=image_url]').val();
+ self.set();
+ return false;
+ });
+
+ // attaching event handlers to images
+ $(document).on('click', '#cms_dialog .uploaded_files img', function(){
+ self.img_src = $(this).data('url');
+ self.set();
+ return false;
+ });
this.set = function(){
- var src = self.img.data('url');
self.rte.history.add();
var img = $(self.rte.doc.createElement('img'));
- img.attr('src', src);
+ img.attr('src', self.img_src);
self.rte.selection.insertNode(img[0]);
self.rte.ui.update();
self.dialog.dialog('close');
@@ @@ -35,11 +48,6 @@
self.dialog.html(data);
self.dialog.dialog('open');
$.CMS.enable_uploader();
-
- $('#cms_dialog .uploaded_files img').click(function(){
- self.img = $(this);
- self.set(this);
- });
}
})
}
app/views/cms_admin/dialogs/image.html.erb +7 -0
@@ @@ -1 +1,8 @@
+ <form class='image_url'>
+ <label> URL:
+ <input type='text' name='image_url'/>
+ </label>
+ <input type='submit' value='Insert Image'/>
+ </form>
+
<%= render :partial => 'cms_admin/files/index' %>
\ No newline at end of file