7181a9e3d9cd1e9203d23728531fae00799670ae
[ckeditor.git] / skins / ckeditor / plugins / plinn_image / plugin.js
1 /* © Benoît Pin, MINES ParisTech */
2
3
4 (function(){
5
6 var reSize = /getResizedImage\?size=(\d+)_(\d+)$/;
7
8 function updateImageSizeUrlParameters(img) {
9 if (reSize.test(img.src)){
10 var matches = reSize.exec(img.src);
11 var srcWidth = parseInt(matches[1]);
12 var srcHeight = parseInt(matches[2]);
13
14 var imgWidth = parseInt((img.style.width) ? img.style.width : img.width);
15 var imgHeight = parseInt((img.style.height) ? img.style.height : img.height);
16
17 if ((imgWidth && imgHeight) && srcWidth != imgWidth && srcHeight != imgHeight) {
18 var newUrl = img.getAttribute('src', 2).replace(reSize, 'getResizedImage?size=' + imgWidth + '_' + imgHeight);
19 img.width = imgWidth;
20 img.height = imgHeight;
21 img.src = newUrl;
22 }
23 }
24 }
25
26
27 CKEDITOR.plugins.add( 'plinn_image',
28 {
29 init : function( editor )
30 {
31 editor.on('instanceReady', function(){
32 editor.on('getData',
33 function(evt) {
34 var body = evt.editor.document.$.body;
35 var images = body.getElementsByTagName('IMG');
36 for (var i = 0 ; i < images.length ; i++)
37 updateImageSizeUrlParameters(images[i]);
38 evt.data.dataValue = evt.editor.document.$.body.innerHTML;
39 }
40 );
41 });
42 }
43 });
44
45 })();