Réinplémentation du plugin Plinn Image. Il modifie les src des images juste avanc...
authorBenoît Pin <pin@cri.ensmp.fr>
Wed, 17 Aug 2011 15:19:08 +0000 (17:19 +0200)
committerBenoît Pin <pin@cri.ensmp.fr>
Wed, 17 Aug 2011 15:19:08 +0000 (17:19 +0200)
skins/ckeditor/config.js
skins/ckeditor/plugins/plinn_image/plugin.js [new file with mode: 0644]

index 3cd350d..19c2459 100644 (file)
@@ -27,4 +27,6 @@ CKEDITOR.editorConfig = function( config )
        config.filebrowserBrowseUrl = CKEDITOR.basePath + 'filemanager/browser/mac_finder/browser.html?Connector=connectors/plinn/connector';\r
        config.filebrowserWindowHeight = 600;\r
        config.filebrowserWindowWidth = 801;\r
+       \r
+       config.extraPlugins = 'selection,plinn_image';\r
 };
\ No newline at end of file
diff --git a/skins/ckeditor/plugins/plinn_image/plugin.js b/skins/ckeditor/plugins/plinn_image/plugin.js
new file mode 100644 (file)
index 0000000..7181a9e
--- /dev/null
@@ -0,0 +1,45 @@
+/* © Benoît Pin, MINES ParisTech */
+
+
+(function(){
+
+var reSize = /getResizedImage\?size=(\d+)_(\d+)$/;
+
+function updateImageSizeUrlParameters(img) {
+       if (reSize.test(img.src)){
+               var matches = reSize.exec(img.src);
+               var srcWidth = parseInt(matches[1]);
+               var srcHeight = parseInt(matches[2]);
+       
+               var imgWidth = parseInt((img.style.width) ? img.style.width : img.width);
+               var imgHeight = parseInt((img.style.height) ? img.style.height : img.height);
+       
+               if ((imgWidth && imgHeight) && srcWidth != imgWidth && srcHeight != imgHeight) {
+                       var newUrl = img.getAttribute('src', 2).replace(reSize, 'getResizedImage?size=' + imgWidth + '_' + imgHeight);
+                       img.width = imgWidth;
+                       img.height = imgHeight;
+                       img.src = newUrl;
+               }
+       }
+}
+
+
+CKEDITOR.plugins.add( 'plinn_image',
+{
+       init : function( editor )
+       {
+               editor.on('instanceReady', function(){
+                       editor.on('getData',
+                               function(evt) {
+                                       var body = evt.editor.document.$.body;
+                                       var images = body.getElementsByTagName('IMG');
+                                       for (var i = 0 ; i < images.length ; i++)
+                                               updateImageSizeUrlParameters(images[i]);
+                                       evt.data.dataValue = evt.editor.document.$.body.innerHTML;
+                               }
+                       );
+               });
+       }
+});
+
+})();