OSDN Git Service

CKEditorのプラグイン「Googleマップ」プラグインの地図サイズに%を使用可能にする。
authornaoki hirata <naoki@magic3.org>
Wed, 27 Aug 2014 06:05:26 +0000 (15:05 +0900)
committernaoki hirata <naoki@magic3.org>
Wed, 27 Aug 2014 06:05:26 +0000 (15:05 +0900)
scripts/ckeditor4.4.2/plugins/googlemaps/dialogs/googlemaps.js
scripts/ckeditor4.4.2/plugins/googlemaps/dialogs/main.js
scripts/ckeditor4.4.2/plugins/googlemaps/lang/en.js
scripts/ckeditor4.4.2/plugins/googlemaps/lang/ja.js
scripts/ckeditor4.4.2/plugins/googlemaps/plugin.js

index 82b6769..c6bdd6a 100644 (file)
@@ -45,7 +45,9 @@ var GoogleMap = function()
 
        this.width = CKEDITOR.config.googlemaps_width || 400;
        this.height = CKEDITOR.config.googlemaps_height || 240;
-
+       this.widthType = 'px';
+       this.heightType = 'px';
+       
        this.centerLat = CKEDITOR.config.googlemaps_centerLat || 35.594757;
        this.centerLon =  CKEDITOR.config.googlemaps_centerLon || 139.620739;
        this.zoom = CKEDITOR.config.googlemaps_zoom || 11;
@@ -64,6 +66,9 @@ GoogleMap.prototype.generateStaticMap = function()
 {
        var w = Math.min(this.width, 640);
        var h = Math.min(this.height, 640);
+       if (this.widthType == '%') w = 640;
+       if (this.heightType == '%') h = 640;
+       
        var staticMapTypes = ['roadmap', 'satellite', 'hybrid', 'terrain'];
 
        var mapUrl = 'http://maps.google.com/maps/api/staticmap?center=' + this.centerLat + ',' + this.centerLon 
@@ -89,6 +94,7 @@ GoogleMap.prototype.updateDimensions = function( oFakeNode )
 {
        var iWidth, iHeight;
        var regexSize = /^\s*(\d+)px\s*$/i;
+       var regexSizePer = /^\s*(\d+)%\s*$/i;
 
        if (oFakeNode.style.width)
        {
@@ -98,6 +104,16 @@ GoogleMap.prototype.updateDimensions = function( oFakeNode )
                        iWidth = aMatchW[1];
                        oFakeNode.style.width = '';
                        oFakeNode.width = iWidth;
+                       this.widthType = 'px';
+               } else {
+                       aMatchW  = oFakeNode.style.width.match(regexSizePer);
+                       if (aMatchW)
+                       {
+                               iWidth = aMatchW[1];
+                               oFakeNode.style.width = '';
+                               oFakeNode.width = iWidth;
+                               this.widthType = '%';
+                       }
                }
        }
 
@@ -109,16 +125,28 @@ GoogleMap.prototype.updateDimensions = function( oFakeNode )
                        iHeight = aMatchH[1];
                        oFakeNode.style.height = '';
                        oFakeNode.height = iHeight;
+                       this.heightType = 'px';
+               } else {
+                       aMatchH  = oFakeNode.style.height.match(regexSizePer);
+                       if (aMatchH)
+                       {
+                               iHeight = aMatchH[1];
+                               oFakeNode.style.height = '';
+                               oFakeNode.height = iHeight;
+                               this.heightType = '%';
+                       }
                }
        }
 
        this.width      = iWidth ? iWidth : oFakeNode.width;
        this.height     = iHeight ? iHeight : oFakeNode.height;
 }
-GoogleMap.prototype.setDimensions = function(width, height)
+GoogleMap.prototype.setDimensions = function(width, height, widthType, heightType)
 {
        this.width      = width;
        this.height     = height;
+       this.widthType = widthType;
+       this.heightType = heightType;
 }
 GoogleMap.prototype.decodeText = function(string)
 {
index 6de2794..9d1f39a 100644 (file)
@@ -50,6 +50,8 @@
                        // 入力値初期化
                        dialog.setValueOf('tab_map', 'txtWidth', mapInfo.width);
                        dialog.setValueOf('tab_map', 'txtHeight', mapInfo.height);
+                       dialog.setValueOf('tab_map', 'cmbWidthType', mapInfo.widthType);
+                       dialog.setValueOf('tab_map', 'cmbHeightType', mapInfo.heightType);
                        dialog.setValueOf('tab_map', 'cmbZoom', mapInfo.zoom);
                        dialog.setValueOf('tab_map', 'txtCenterLat', mapInfo.centerLat);
                        dialog.setValueOf('tab_map', 'txtCenterLon', mapInfo.centerLon);
                {
                        if (!mapDiv) return;
                        
-                       mapDiv.style.width = dialog.getValueOf('tab_map', 'txtWidth') + 'px';
-                       mapDiv.style.height = dialog.getValueOf('tab_map', 'txtHeight') + 'px';
-
+//                     mapDiv.style.width = dialog.getValueOf('tab_map', 'txtWidth') + 'px';
+//                     mapDiv.style.height = dialog.getValueOf('tab_map', 'txtHeight') + 'px';
+                       mapDiv.style.width = dialog.getValueOf('tab_map', 'txtWidth') + dialog.getValueOf('tab_map', 'cmbWidthType');
+                       mapDiv.style.height = dialog.getValueOf('tab_map', 'txtHeight') + dialog.getValueOf('tab_map', 'cmbHeightType');
+                       
                        //ResizeParent();
                };
                var updatePreview = function()
                                // マップ情報更新
                                mapInfo.width = data.info['txtWidth'];
                                mapInfo.height = data.info['txtHeight'];
+                               mapInfo.widthType = data.info['cmbWidthType'];
+                               mapInfo.heightType = data.info['cmbHeightType'];
                                mapInfo.zoom = data.info['cmbZoom'];
                                mapInfo.centerLat = data.info['txtCenterLat'];
                                mapInfo.centerLon = data.info['txtCenterLon'];
 //                             var newMapElement = CKEDITOR.dom.element.createFromHtml('<div></div>', editor.document);
 //                             newMapElement.append(scriptElement);
                                var newMapElement = CKEDITOR.dom.element.createFromHtml('<div>' + script + '</div>', editor.document);          // IE8 not work.
-                               var style = 'width:' + mapInfo.width + 'px;height:' + mapInfo.height + 'px;display:none;';
+                               var style = 'width:' + mapInfo.width + mapInfo.widthType + ';height:' + mapInfo.height + mapInfo.heightType + ';display:none;';
                                newMapElement.setAttributes({
                                        'id': 'gmap' + mapInfo.number,
                                        'style': style,
                                                        'background-position': 'center center',
                                                        'background-repeat': 'no-repeat',
                                                        'border': '0px',
-                                                       'width': mapInfo.width + 'px',
-                                                       'height': mapInfo.height + 'px'
+                                                       'width': mapInfo.width + mapInfo.widthType,
+                                                       'height': mapInfo.height + mapInfo.heightType
                                                        };
                                var newFakeImage = editor.createFakeElement(newMapElement, 'cke_googlemaps' + mapInfo.number, 'div', false);
                                newFakeImage.setStyles( extraStyles );
                                {
                                        // 項目を横に配置
                                        type: 'hbox',
-                                       widths: [ '10%', '20%' ],               // 項目間幅を調整
+                                       widths: [ '10%', '10%', '10%' ],                // 項目間幅を調整
        /*                              padding: '5px',*/
                                        children: [
                                        {
                                                },
                                                commit: commitValue
                                        }, {
+                                               type: 'select',
+                                               id: 'cmbWidthType',
+                                               label: editor.lang.googlemaps.widthType,
+                                               style: 'width:50px',
+                                               'default': 'px',
+                                               items: [
+                                                       [ 'px', 'px' ],
+                                                       [ '%', '%' ]
+                                               ],
+                                               commit: commitValue
+                                       }, {
                                                type : 'text',
                                                id : 'txtHeight',
                                                label: editor.lang.googlemaps.height,
                                                commit: commitValue
                                        }, {
                                                type: 'select',
-                                               id: 'cmbZoom',
-                                               label: editor.lang.googlemaps.zoomLevel,
+                                               id: 'cmbHeightType',
+                                               label: editor.lang.googlemaps.heightType,
                                                style: 'width:50px',
-                                               'default': '',
+                                               'default': 'px',
                                                items: [
-                                                       [ '0', '0' ],
-                                                       [ '1', '1' ],
-                                                       [ '2', '2' ],
-                                                       [ '3', '3' ],
-                                                       [ '4', '4' ],
-                                                       [ '5', '5' ],
-                                                       [ '6', '6' ],
-                                                       [ '7', '7' ],
-                                                       [ '8', '8' ],
-                                                       [ '9', '9' ],
-                                                       [ '10', '10' ],
-                                                       [ '11', '11' ],
-                                                       [ '12', '12' ],
-                                                       [ '13', '13' ],
-                                                       [ '14', '14' ],
-                                                       [ '15', '15' ],
-                                                       [ '16', '16' ],
-                                                       [ '17', '17' ]
+                                                       [ 'px', 'px' ],
+                                                       [ '%', '%' ]
                                                ],
-                                               onLoad: function(){
-                                                       fieldZoom = document.getElementById(this.getInputElement().$.id);                       // 参照を取得
-                                               },
-                                               onChange: function() {
-                                                       if (mapObj) mapObj.setZoom(parseInt(this.getValue()), 10);
-                                               },
                                                commit: commitValue
                                        } ]
                                }, {
                                        type: 'hbox',
-                                       widths: [ '50%', '50%' ],
+                                       widths: [ '10%', '10%', '10%' ],
                                        children: [
                                        {
                                                type: 'text',
                                                        if (mapObj) mapObj.setCenter(new google.maps.LatLng(fieldCenterLatitude.value, this.getValue()));
                                                },
                                                commit: commitValue
+                                       }, {
+                                               type: 'select',
+                                               id: 'cmbZoom',
+                                               label: editor.lang.googlemaps.zoomLevel,
+                                               style: 'width:50px',
+                                               'default': '',
+                                               items: [
+                                                       [ '0', '0' ],
+                                                       [ '1', '1' ],
+                                                       [ '2', '2' ],
+                                                       [ '3', '3' ],
+                                                       [ '4', '4' ],
+                                                       [ '5', '5' ],
+                                                       [ '6', '6' ],
+                                                       [ '7', '7' ],
+                                                       [ '8', '8' ],
+                                                       [ '9', '9' ],
+                                                       [ '10', '10' ],
+                                                       [ '11', '11' ],
+                                                       [ '12', '12' ],
+                                                       [ '13', '13' ],
+                                                       [ '14', '14' ],
+                                                       [ '15', '15' ],
+                                                       [ '16', '16' ],
+                                                       [ '17', '17' ]
+                                               ],
+                                               onLoad: function(){
+                                                       fieldZoom = document.getElementById(this.getInputElement().$.id);                       // 参照を取得
+                                               },
+                                               onChange: function() {
+                                                       if (mapObj) mapObj.setZoom(parseInt(this.getValue()), 10);
+                                               },
+                                               commit: commitValue
                                        } ]
                                }, {
                                        type: 'html',
index 8734d42..c4262b0 100644 (file)
@@ -7,7 +7,7 @@
  *
  * @package    Magic3 Framework
  * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
- * @copyright  Copyright 2006-2013 Magic3 Project.
+ * @copyright  Copyright 2006-2014 Magic3 Project.
  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
  * @version    SVN: $Id: en.js 5979 2013-05-10 09:20:24Z fishbone $
  * @link       http://www.magic3.org
@@ -21,6 +21,8 @@ CKEDITOR.plugins.setLang( 'googlemaps', 'en', {
        lineTitle: 'Line',
        width: 'Width',
        height: 'Height',
+       widthType: '&nbsp;',
+       heightType: '&nbsp;',
        zoomLevel: 'Zoom Level',
        msgDefaultMarkerText:   'Input text.'
 });
index 73bd137..47a563b 100644 (file)
@@ -7,7 +7,7 @@
  *
  * @package    Magic3 Framework
  * @author     平田直毅(Naoki Hirata) <naoki@aplo.co.jp>
- * @copyright  Copyright 2006-2013 Magic3 Project.
+ * @copyright  Copyright 2006-2014 Magic3 Project.
  * @license    http://www.gnu.org/copyleft/gpl.html  GPL License
  * @version    SVN: $Id: ja.js 6030 2013-05-22 00:48:33Z fishbone $
  * @link       http://www.magic3.org
@@ -21,6 +21,8 @@ CKEDITOR.plugins.setLang( 'googlemaps', 'ja', {
        lineTitle: 'ライン',
        width: '幅',
        height: '高さ',
+       widthType: '&nbsp;',
+       heightType: '&nbsp;',
        zoomLevel: 'ズームレベル',
        latitude: '緯度',
        longitude:      '経度',
index c046f90..0ebe56f 100644 (file)
                                                                var mapInfo = GoogleMapsHandler.getMap(mapNumber);
                                                                if (mapInfo){
                                                                        // 幅、高さを設定
-                                                                       var width, height;
+                                                                       var width, height, widthType, heightType;
                                                                        var style = element.attributes.style;
-                                                                       if ((/width:\s*(\d+)px/i).test(style)) width = RegExp.$1;
-                                                                       if ((/height:\s*(\d+)px/i).test(style)) height = RegExp.$1;
+                                                                       if ((/width:\s*(\d+)px/i).test(style)){
+                                                                               width = RegExp.$1;
+                                                                               widthType = 'px';
+                                                                       } else if ((/width:\s*(\d+)%/i).test(style)){
+                                                                               width = RegExp.$1;
+                                                                               widthType = '%';
+                                                                       }
+                                                                       if ((/height:\s*(\d+)px/i).test(style)){
+                                                                               height = RegExp.$1;
+                                                                               heightType = 'px';
+                                                                       } else if ((/height:\s*(\d+)%/i).test(style)){
+                                                                               height = RegExp.$1;
+                                                                               heightType = '%';
+                                                                       }
                                                                        if (!width || !height){
                                                                                width = CKEDITOR.config.googlemaps_width;
                                                                                height = CKEDITOR.config.googlemaps_height;
+                                                                               widthType = 'px';
+                                                                               heightType = 'px';
                                                                        }
-                                                                       mapInfo.setDimensions(width, height);
+                                                                       mapInfo.setDimensions(width, height, widthType, heightType);
                                                                        
                                                                        // 画像を背景に配置しリサイズ不可にする
                                                                        CKEDITOR.addCss(
                                                                                        'background-position: center center;' +
                                                                                        'background-repeat: no-repeat;' +
                                                                                        'border: 0px;' +
-                                                                                       'width: ' + width + 'px;' +
-                                                                                       'height: ' + height + 'px;' +
+                                                                                       'width: ' + width + widthType + ';' +
+                                                                                       'height: ' + height + heightType + ';' +
                                                                                '}'
                                                                        );
                                                                        var fakeImage = editor.createFakeParserElement(element, 'cke_googlemaps' + mapNumber, 'div', false/*リサイズ不可*/);