plugin.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Base64Image Plugin for CKEditor (http://github.com/nmmf/base64image)
  3. * Created by ALL-INKL.COM - Neue Medien M�nnich - 04. Feb 2014
  4. * Licensed under the terms of GPL, LGPL and MPL licenses.
  5. */
  6. CKEDITOR.plugins.add("base64image", {
  7. lang : ["af","ar","bg","bn","bs","ca","cs","cy","da","de","el","en","en-au","en-ca","en-gb","eo","es","et","eu","fa","fi","fo","fr","fr-ca","gl","gu","he","hi","hr","hu","id","is","it","ja","ka","km","ko","ku","lt","lv","mk","mn","ms","nb","nl","no","pl","pt","pt-br","ro","ru","si","sk","sl","sq","sr","sr-latn","sv","th","tr","ug","uk","vi","zh","zh-cn"],
  8. requires: "dialog",
  9. icons : "base64image",
  10. hidpi : true,
  11. init : function(editor){
  12. var pluginName = 'base64imageDialog';
  13. editor.ui.addButton("base64image", {
  14. label: editor.lang.common.image,
  15. command: pluginName,
  16. toolbar: "insert"
  17. });
  18. CKEDITOR.dialog.add(pluginName, this.path+"dialogs/base64image.js");
  19. var allowed = 'img[alt,!src]{border-style,border-width,float,height,margin,margin-bottom,margin-left,margin-right,margin-top,width}',
  20. required = 'img[alt,src]';
  21. editor.addCommand( pluginName, new CKEDITOR.dialogCommand( pluginName, {
  22. allowedContent: allowed,
  23. requiredContent: required,
  24. contentTransformations: [
  25. [ 'img{width}: sizeToStyle', 'img[width]: sizeToAttribute' ],
  26. [ 'img{float}: alignmentToStyle', 'img[align]: alignmentToAttribute' ]
  27. ]
  28. } ) );
  29. editor.on("doubleclick", function(evt){
  30. if(evt.data.element && !evt.data.element.isReadOnly() && evt.data.element.getName() === "img") {
  31. evt.data.dialog = pluginName;
  32. editor.getSelection().selectElement(evt.data.element);
  33. }
  34. });
  35. if(editor.addMenuItem) {
  36. editor.addMenuGroup("base64imageGroup");
  37. editor.addMenuItem("base64imageItem", {
  38. label: editor.lang.common.image,
  39. icon: this.path+"icons/base64image.png",
  40. command: pluginName,
  41. group: "base64imageGroup"
  42. });
  43. }
  44. if(editor.contextMenu) {
  45. editor.contextMenu.addListener(function(element, selection) {
  46. if(element && element.getName() === "img") {
  47. editor.getSelection().selectElement(element);
  48. return { base64imageItem: CKEDITOR.TRISTATE_ON };
  49. }
  50. return null;
  51. });
  52. }
  53. }
  54. });