Sha256: f14939530e8869c80e6e462d68aeb0d829eab772749f8f533d05c23273c711c2

Contents?: true

Size: 1.93 KB

Versions: 11

Compression:

Stored size: 1.93 KB

Contents

<% self.class.include RailsAdminImageManager::Engine.routes.url_helpers %>
window.addQueryString = function ( url, params ) {
  var queryString = [];
  if (!params) return url;
  else {
    for (var i in params) queryString.push(i + "=" + encodeURIComponent( params[i]));
  }
  return url + ( ( url.indexOf( "?" ) != -1 ) ? "&" : "?" ) + queryString.join( "&" );
}

if (!CKEDITOR.plugins.get( 'imageManager')) {
  CKEDITOR.plugins.add( 'imageManager', {
    init: function( editor ) {
      var openManager = function(ele){
        var params = {};
        if (ele != null && ele.$.getAttribute('data-image-id')) {
          params.selectImage = ele.$.getAttribute('data-image-id');
        }
        params.CKEditor = editor.name;
        params.CKEditorFuncNum = editor._.insertImagefn;

        var url = addQueryString('<%= image_manager_index_path %>', params);
        editor.popup(url, 1105, 500);
      }

      editor._.insertImagefn = CKEDITOR.tools.addFunction(function(src, id, title){
          this.insertHtml('<img src="' + src + '" data-image-id="' + id + '" alt="'+title+'" />');
        }, editor);


      editor.ui.addButton( 'imageManager', {
        label: 'Ajouter une image',
        command: 'insertManagerImage',
        icon: "<%= asset_path 'rails_admin_image_manager/image.png' %>"
      });

      editor.on( 'doubleclick', function(evt) {
        var element = evt.data.element;
        if (element.is('img') && !element.data('cke-realelement') && !element.isReadOnly()) {
          editor.execCommand('insertManagerImage');
        }
        evt.preventDefault();
      });

      editor.addCommand( 'insertManagerImage', {
        exec: function(editor) {
          var sel = editor.getSelection();
          openManager(sel.getSelectedElement())
        }
      });

    }
  });

  // CKEDITOR.plugins.contextMenu.removeAll()
  CKEDITOR.config.removePlugins = 'liststyle,tabletools,contextmenu';
  CKEDITOR.config.extraPlugins = 'imageManager';
}

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rails_admin_image_manager-0.1.34 app/assets/javascripts/rails_admin_image_manager/ckeditor_plugin.js.erb
rails_admin_image_manager-0.1.33 app/assets/javascripts/rails_admin_image_manager/ckeditor_plugin.js.erb
rails_admin_image_manager-0.1.31 app/assets/javascripts/rails_admin_image_manager/ckeditor_plugin.js.erb
rails_admin_image_manager-0.1.30 app/assets/javascripts/rails_admin_image_manager/ckeditor_plugin.js.erb
rails_admin_image_manager-0.1.3 app/assets/javascripts/rails_admin_image_manager/ckeditor_plugin.js.erb
rails_admin_image_manager-0.1.29 app/assets/javascripts/rails_admin_image_manager/ckeditor_plugin.js.erb
rails_admin_image_manager-0.1.28 app/assets/javascripts/rails_admin_image_manager/ckeditor_plugin.js.erb
rails_admin_image_manager-0.1.27 app/assets/javascripts/rails_admin_image_manager/ckeditor_plugin.js.erb
rails_admin_image_manager-0.1.26 app/assets/javascripts/rails_admin_image_manager/ckeditor_plugin.js.erb
rails_admin_image_manager-0.1.25 app/assets/javascripts/rails_admin_image_manager/ckeditor_plugin.js.erb
rails_admin_image_manager-0.1.24 app/assets/javascripts/rails_admin_image_manager/ckeditor_plugin.js.erb