ここの情報は古いです。ご理解頂いた上でお取り扱いください。

Changeset 12821


Ignore:
Timestamp:
Sep 4, 2009, 11:46:25 AM (13 years ago)
Author:
ShogoKawahara
Message:

#4273:added opWidgetFormRichTextareaOpenPNE to edit decoration text

Location:
OpenPNE3/trunk
Files:
20 added
3 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE3/trunk/lib/widget/opWidgetFormRichTextarea.class.php

    r12732 r12821  
    2020  static protected $firstRender = true;
    2121
    22   static protected $defaultTinyMCEConfigs = array(
     22  protected $defaultTinyMCEConfigs = array(
    2323    'mode'  => 'textareas',
    2424    'theme' => 'advanced',
     
    3131  );
    3232
     33  public function __construct($options = array(), $attributes = array())
     34  {
     35    parent::__construct($options, $attributes);
     36
     37    $this->setOption('config', array_merge($this->defaultTinyMCEConfigs, $this->getOption('config')));
     38  }
     39
    3340  protected function configure($options = array(), $attributes = array())
    3441  {
     
    3643    $this->addOption('is_toggle', true);
    3744    $this->addOption('is_textmode', true);
     45    $this->addOption('textarea_template', '%s');
    3846
    3947    parent::configure($options, $attributes);
    4048  }
    4149
     50  protected function getId($name, $attributes)
     51  {
     52    if (isset($attributes['id']))
     53    {
     54      return $attributes['id'];
     55    }
     56    $tmpAttributes = $this->fixFormId(array_merge(array('name' => $name, $attributes)));
     57    return $tmpAttributes['id'];
     58  }
     59
    4260  public function render($name, $value = null, $attributes = array(), $errors = array())
    4361  {
    44     $this->setOption('config', array_merge(self::$defaultTinyMCEConfigs, $this->getOption('config')));
    45 
    4662    $toggle = '';
    4763    $js = '';
    4864
    49     if (isset($attributes['id']))
    50     {
    51       $id = $attributes['id'];
    52     }
    53     else
    54     {
    55       $tmpAttributes = $this->fixFormId(array_merge(array('name' => $name, $attributes)));
    56       $id = $tmpAttributes['id'];
    57     }
     65    $id = $this->getId($name, $attributes);
    5866
    5967    $changerName = $id.'_changer';
     
    6270    if (self::$firstRender)
    6371    {
     72      sfContext::getInstance()->getResponse()->addJavascript('/sfProtoculousPlugin/js/prototype');
    6473      sfContext::getInstance()->getResponse()->addJavascript('tiny_mce/tiny_mce');
    6574      $js .= <<<EOF
    6675  function op_toggle_mce_editor(id)
    6776  {
    68     var textmode_checked = document.getElementById(id + "_changer_1").checked;
    69     var previewmode_checked = document.getElementById(id + "_changer_2").checked;
     77    var textmode_checked    = $(id + "_changer_1").checked;
     78    var previewmode_checked = $(id + "_changer_2").checked;
     79    var relational_objects  = $$("." + id);
    7080    var editor = tinyMCE.get(id);
    7181    if (!editor) {
    72       if (previewmode_checked)
    73         tinyMCE.execCommand('mceAddControl', 0, id);
     82      if (previewmode_checked) {
     83        tinyMCE.execCommand('mceAddControl', false, id);
     84        relational_objects.each(function(object){ object.style.display = "none"; });
     85      }
    7486      return true;
    7587    }
    76     if (editor.isHidden() && previewmode_checked)
     88    if (editor.isHidden() && previewmode_checked) {
    7789      editor.show();
    78     else if (!editor.isHidden() && textmode_checked)
     90      relational_objects.each(function(object){ object.style.display = "none"; });
     91    } else if (!editor.isHidden() && textmode_checked) {
    7992      editor.hide();
     93      relational_objects.each(function(object){ object.style.display = "block"; });
     94    }
    8095  }
    8196
    8297EOF;
     98      $js .= sprintf("  tinyMCE.init(%s);\n", json_encode($this->getOption('config')));
    8399      self::$firstRender = false;
    84100    }
    85101
    86     $js .= sprintf("  tinyMCE.init(%s);\n", json_encode($this->getOption('config')));
    87102    if (!$this->getOption('is_textmode'))
    88103    {
    89104      $js .= sprintf("  tinyMCE.execCommand('mceAddControl', false, '%s');\n", $id);
    90105    }
    91     $js = '<script type="text/javascript">'."\n".$js.'</script>';
     106
     107    $js .= sprintf("  op_toggle_mce_editor('%s')\n", $id);
     108
     109    if ($js)
     110    {
     111      sfProjectConfiguration::getActive()->loadHelpers('Javascript');
     112      $js = javascript_tag($js);
     113    }
     114
    92115    if ($this->getOption('is_toggle'))
    93116    {
     
    111134      );
    112135    }
    113     return $toggle.parent::render($name, $value, $attributes, $errors).$js;
     136    return $toggle.sprintf($this->getOption('textarea_template'), parent::render($name, $value, $attributes, $errors)).$js;
    114137  }
    115138}
  • OpenPNE3/trunk/web/js/tiny_mce/plugins/openpne/editor_plugin.js

    r9194 r12821  
    33+'" onmousedown="return false;" onclick="return false;" title="'+tinymce.DOM.encode(s.title)+'">';if(s.image){h+='<img class="mceIcon" src="'+s.image+'" /></a>';}else{h+='<span class="mceIcon '+s['class']+'"></span></a>';}
    44return h;},postRender:function(){tinymce.dom.Event.add(this.id,'click',this.showMenu,this);},setColor:function(c){this.value=c;this.hideMenu();this.settings.onselect(c);}});tinymce.create('tinymce.ui.OpenPNEEmojiButton:tinymce.ui.ColorSplitButton',{OpenPNEEmojiButton:function(id,s){var t=this;t.parent(id,s);t.settings=s;},renderMenu:function(){var t=this,m,i=0,s=t.settings,n,tb,tr,w;var DOM=tinymce.DOM,Event=tinymce.dom.Event,is=tinymce.is,each=tinymce.each;w=DOM.add(s.menu_container,'div',{id:t.id+'_menu',dir:'ltr','class':s['menu_class']+' '+s['class'],style:'position:absolute;left:0;top:-1000px;width:402px;'});m=DOM.add(w,'div',{'class':s['class']+' mceSplitButtonMenu'});DOM.add(m,'span',{'class':'mceMenuLine'});n=DOM.add(m,'table',{'class':'mceEmojiSplitMenu'});tb=DOM.add(n,'tbody');for(var num in s.emoji){var emoji=s.emoji[num];for(var i=emoji.start;i<=emoji.end;i++){if(i==emoji.start||i%25==0){tr=DOM.add(tb,'tr');}
    5 n=DOM.add(tr,'td');n=DOM.add(n,'img',{src:"./skin/default/img/emoji/"+s.carrier+"/"+s.carrier+i+".gif",alt:"["+s.carrier+":"+i+"]"});Event.add(n,'mousedown',function(e){if(Prototype.Browser.IE){tinyMCE.execCommand("mceInsertContent",false,e.srcElement.getAttribute("alt"));}else{tinyMCE.execCommand("mceInsertContent",false,e.element().getAttribute("alt"));}});}}
     5n=DOM.add(tr,'td');n=DOM.add(n,'img',{src:op_get_relative_uri_root()+"/images/emoji/"+s.carrier+"/"+s.carrier+i+".gif",alt:"["+s.carrier+":"+i+"]"});Event.add(n,'mousedown',function(e){if(Prototype.Browser.IE){tinyMCE.execCommand("mceInsertContent",false,e.srcElement.getAttribute("alt"));}else{tinyMCE.execCommand("mceInsertContent",false,e.element().getAttribute("alt"));}});}}
    66DOM.addClass(m,'mceColorSplitMenu');return w;},renderHTML:function(){var s=this.settings,h='<a id="'+this.id+'" href="javascript:;" class="mceButton mceButtonEnabled '+s['class']
    77+'" onmousedown="return false;" onclick="return false;" title="'+tinymce.DOM.encode(s.title)+'">';if(s.image){h+='<img class="mceIcon" src="'+s.image+'" /></a>';}else{h+='<span class="mceIcon '+s['class']+'"></span></a>';}
    88return h;},showMenu:function(){var t=this,r,p,e;var DOM=tinymce.DOM,Event=tinymce.dom.Event,is=tinymce.is,each=tinymce.each;if(t.isDisabled())
    99return;if(!t.isMenuRendered){t.renderMenu();t.isMenuRendered=true;}
    10 e=DOM.get(t.id);DOM.show(t.id+'_menu');DOM.addClass(e,'mceSplitButtonSelected');p2=DOM.getPos(e);DOM.setStyles(t.id+'_menu',{left:720-DOM.get(t.id+'_menu').clientWidth,top:p2.y+e.clientHeight,zIndex:150});e=0;Event.add(document,'mousedown',t.hideMenu,t);},postRender:function(){tinymce.dom.Event.add(this.id,'click',this.showMenu,this);}});tinymce.create('tinymce.ui.OpenPNECmdButton:tinymce.ui.Button',{renderHTML:function(){var s=this.settings;var h='<a id="'+this.id+'" href="javascript:;" class="mceButton mceButtonEnabled '+s['class']+'" style="width:40px; margin-left: 25px;" onmousedown="return false;" onclick="return false;" title="'+tinymce.DOM.encode(s.title)+'"><img class="mceIcon" style="width:40px;" src="'+s.image+'" /></a>';return h;}});tinymce.PluginManager.requireLangPack('openpne');var config=pne_mce_editor_get_config();tinymce.create('tinymce.plugins.OpenPNEPlugin',{init:function(ed,url){var t=this;ed.settings.content_css=url+"/css/editor.css";ed.addCommand('mceOpenPNE_op_b',function(){tinyMCE.execCommand("Bold");});ed.addCommand('mceOpenPNE_op_u',function(){tinyMCE.execCommand("Underline");});ed.addCommand('mceOpenPNE_op_s',function(){tinyMCE.execCommand("Strikethrough");});ed.addCommand('mceOpenPNE_op_i',function(){tinyMCE.execCommand("Italic");});ed.addCommand('mceOpenPNE_op_large',function(){tinyMCE.execCommand("Fontsize",false,5);});ed.addCommand('mceOpenPNE_op_small',function(){tinyMCE.execCommand("Fontsize",false,1);});ed.addCommand('mceOpenPNE_op_image',function(){window.open(config.op_image.contentURL.unescapeHTML(),'','width=600,height=550,toolbar=no,scrollbars=yes,left=10,top=10');});ed.addCommand('mceOpenPNE_op_cmd',function(){window.open(config.op_cmd.contentURL.unescapeHTML());});for(var key in config){var value=config[key];if(value.isEnabled&&key!="op_color"){ed.addButton(key,{title:'{#openpne.'+key+'}',image:value.imageURL,cmd:'mceOpenPNE_'+key});}}
    11 ed.onBeforeSetContent.add(function(ed,o){o.content=t._textToPreview(o.content);});ed.onPostProcess.add(function(ed,o){if(o.save){if(ed.isHidden()){o.content=ed.getElement().value.replace(/\n\n/g,"\n \n");}else{o.content=t._previewToText(o.content,ed);}}});ed.onNodeChange.add(function(ed,cm,n){cm.setActive('mce_editor_textarea_op_b',false);cm.setActive('mce_editor_textarea_op_u',false);cm.setActive('mce_editor_textarea_op_s',false);cm.setActive('mce_editor_textarea_op_i',false);cm.setActive('mce_editor_textarea_op_large',false);cm.setActive('mce_editor_textarea_op_small',false);var elm=n;while(elm.parentNode){var tagname=t._getTagName(elm);if((tagname=="large"||tagname=="small")&&(cm.get('mce_editor_textarea_op_large').isActive()||cm.get('mce_editor_textarea_op_small').isActive())){elm=elm.parentNode;continue;}
    12 cm.setActive('mce_editor_textarea_op_'+tagname,true);elm=elm.parentNode;}});},createControl:function(n,cm){var c=null;if(n=="op_color"&&config["op_color"].isEnabled){c=this._createOpenPNEColorButton("op_color",{title:"{#openpne.op_color}",image:config["op_color"].imageURL,cmd:"ForeColor"},cm);}
    13 if(n=="op_emoji_docomo"||n=="op_emoji_au"&&config["op_emoji_au"].isEnabled||n=="op_emoji_softbank"&&config["op_emoji_softbank"].isEnabled){var emoji_config={op_emoji_docomo:{carrier:"i",emoji:[{start:1,end:252}],title:"{#openpne."+n+"}",image:config[n].imageURL},op_emoji_au:{carrier:"e",emoji:[{start:1,end:518},{start:700,end:822}],title:"{#openpne."+n+"}",image:config[n].imageURL},op_emoji_softbank:{carrier:"s",emoji:[{start:1,end:485}],title:"{#openpne."+n+"}",image:config[n].imageURL}}
     10e=DOM.get(t.id);DOM.show(t.id+'_menu');DOM.addClass(e,'mceSplitButtonSelected');p2=DOM.getPos(e);DOM.setStyles(t.id+'_menu',{left:720-DOM.get(t.id+'_menu').clientWidth,top:p2.y+e.clientHeight,zIndex:150});e=0;Event.add(document,'mousedown',t.hideMenu,t);},postRender:function(){tinymce.dom.Event.add(this.id,'click',this.showMenu,this);}});tinymce.create('tinymce.ui.OpenPNECmdButton:tinymce.ui.Button',{renderHTML:function(){var s=this.settings;var h='<a id="'+this.id+'" href="javascript:;" class="mceButton mceButtonEnabled '+s['class']+'" style="width:40px; margin-left: 25px;" onmousedown="return false;" onclick="return false;" title="'+tinymce.DOM.encode(s.title)+'"><img class="mceIcon" style="width:40px;" src="'+s.image+'" /></a>';return h;}});tinymce.PluginManager.requireLangPack('openpne');var config=op_mce_editor_get_config();tinymce.create('tinymce.plugins.OpenPNEPlugin',{init:function(ed,url){var t=this;ed.settings.content_css=url+"/css/editor.css";ed.addCommand('mceOpenPNE_op_b',function(){tinyMCE.execCommand("Bold");});ed.addCommand('mceOpenPNE_op_u',function(){tinyMCE.execCommand("Underline");});ed.addCommand('mceOpenPNE_op_s',function(){tinyMCE.execCommand("Strikethrough");});ed.addCommand('mceOpenPNE_op_i',function(){tinyMCE.execCommand("Italic");});ed.addCommand('mceOpenPNE_op_large',function(){tinyMCE.execCommand("Fontsize",false,5);});ed.addCommand('mceOpenPNE_op_small',function(){tinyMCE.execCommand("Fontsize",false,1);});ed.addCommand('mceOpenPNE_op_image',function(){window.open(config.op_image.contentURL.unescapeHTML(),'','width=600,height=550,toolbar=no,scrollbars=yes,left=10,top=10');});ed.addCommand('mceOpenPNE_op_cmd',function(){window.open(config.op_cmd.contentURL.unescapeHTML());});for(var key in config){var value=config[key];if(value.isEnabled&&key!="op_color"){ed.addButton(key,{title:'{#openpne.'+key+'}',image:value.imageURL,cmd:'mceOpenPNE_'+key});}}
     11ed.onBeforeSetContent.add(function(ed,o){o.content=t._textToPreview(o.content);});ed.onPostProcess.add(function(ed,o){if(o.save){if(ed.isHidden()){o.content=ed.getElement().value.replace(/\n\n/g,"\n \n");}else{o.content=t._previewToText(o.content,ed);}}});ed.onNodeChange.add(function(ed,cm,n){cm.setActive(this.id+'_op_b',false);cm.setActive(this.id+'_op_u',false);cm.setActive(this.id+'_op_s',false);cm.setActive(this.id+'_op_i',false);cm.setActive(this.id+'_op_large',false);cm.setActive(this.id+'_op_small',false);var elm=n;while(elm.parentNode){var tagname=t._getTagName(elm);if((tagname=="large"||tagname=="small")&&(cm.get(this.id+'_op_large').isActive()||cm.get(this.id+'_op_small').isActive())){elm=elm.parentNode;continue;}
     12cm.setActive(this.id+'_op_'+tagname,true);elm=elm.parentNode;}});},createControl:function(n,cm){var c=null;if(n=="op_color"&&config["op_color"].isEnabled){c=this._createOpenPNEColorButton("op_color",{title:"{#openpne.op_color}",image:config["op_color"].imageURL,cmd:"ForeColor"},cm);}
     13if(n=="op_emoji_docomo"||n=="op_emoji_au"&&config["op_emoji_au"]&&config["op_emoji_au"].isEnabled||n=="op_emoji_softbank"&&config["op_emoji_softbank"]&&config["op_emoji_softbank"].isEnabled){var emoji_config={op_emoji_docomo:{carrier:"i",emoji:[{start:1,end:252}],title:"{#openpne."+n+"}",image:config[n].imageURL},op_emoji_au:{carrier:"e",emoji:[{start:1,end:518},{start:700,end:822}],title:"{#openpne."+n+"}",image:config[n].imageURL},op_emoji_softbank:{carrier:"s",emoji:[{start:1,end:485}],title:"{#openpne."+n+"}",image:config[n].imageURL}}
    1414c=this._createOpenPNEEmojiButton(n,emoji_config[n],cm);}
    15 if(n=="op_cmd"&&config["op_cmd"].isEnabled){c=this._createOpenPNECmdButton(n,{title:"{#openpne.op_cmd}",image:config["op_cmd"].imageURL,cmd:"mceOpenPNE_op_cmd"},cm);}
     15if(n=="op_cmd"&&config["op_cmd"]&&config["op_cmd"].isEnabled){c=this._createOpenPNECmdButton(n,{title:"{#openpne.op_cmd}",image:config["op_cmd"].imageURL,cmd:"mceOpenPNE_op_cmd"},cm);}
    1616return c;},getInfo:function(){return{longname:'OpenPNE plugin',author:'Kousuke Ebihara',version:"1.0"}},_getTagName:function(elm){var tagname=elm.nodeName.toLowerCase();if(Prototype.Browser.WebKit&&tagname=="span"){if(elm.style.fontWeight=='bold'){return'b';}
    1717if(elm.style.textDecoration=='underline'){return'u';}
  • OpenPNE3/trunk/web/js/tiny_mce/plugins/openpne/editor_plugin.js.src

    r9151 r12821  
    6161
    6262                    n = DOM.add(n, 'img', {
    63                         src : "./skin/default/img/emoji/" + s.carrier + "/" + s.carrier + i + ".gif",
     63                        src : op_get_relative_uri_root() + "/images/emoji/" + s.carrier + "/" + s.carrier + i + ".gif",
    6464                        alt : "[" + s.carrier + ":" + i + "]"
    6565                    });
     
    136136    tinymce.PluginManager.requireLangPack('openpne');
    137137
    138     var config = pne_mce_editor_get_config();
     138    var config = op_mce_editor_get_config();
    139139
    140140    tinymce.create('tinymce.plugins.OpenPNEPlugin', {
     
    193193            });
    194194            ed.onNodeChange.add(function(ed, cm, n) {
    195                 cm.setActive('mce_editor_textarea_op_b', false);
    196                 cm.setActive('mce_editor_textarea_op_u', false);
    197                 cm.setActive('mce_editor_textarea_op_s', false);
    198                 cm.setActive('mce_editor_textarea_op_i', false);
    199                 cm.setActive('mce_editor_textarea_op_large', false);
    200                 cm.setActive('mce_editor_textarea_op_small', false);
     195                cm.setActive(this.id + '_op_b', false);
     196                cm.setActive(this.id + '_op_u', false);
     197                cm.setActive(this.id + '_op_s', false);
     198                cm.setActive(this.id + '_op_i', false);
     199                cm.setActive(this.id + '_op_large', false);
     200                cm.setActive(this.id + '_op_small', false);
    201201
    202202                var elm = n;
    203203                while (elm.parentNode) {
    204204                    var tagname = t._getTagName(elm);
    205                     if ((tagname == "large" || tagname == "small") && (cm.get('mce_editor_textarea_op_large').isActive() || cm.get('mce_editor_textarea_op_small').isActive())) {
     205                    if ((tagname == "large" || tagname == "small") && (cm.get(this.id + '_op_large').isActive() || cm.get(this.id + '_op_small').isActive())) {
    206206                        elm = elm.parentNode;
    207207                        continue;
    208208                    }
    209                     cm.setActive('mce_editor_textarea_op_' + tagname,  true);
     209                    cm.setActive(this.id + '_op_' + tagname,  true);
    210210                    elm = elm.parentNode;
    211211                }
     
    219219            }
    220220
    221             if (n == "op_emoji_docomo" || n == "op_emoji_au" && config["op_emoji_au"].isEnabled || n == "op_emoji_softbank" && config["op_emoji_softbank"].isEnabled) {
     221            if (n == "op_emoji_docomo" ||
     222                n == "op_emoji_au"  && config["op_emoji_au"] && config["op_emoji_au"].isEnabled ||
     223                n == "op_emoji_softbank" && config["op_emoji_softbank"] && config["op_emoji_softbank"].isEnabled) {
    222224                var emoji_config = {
    223225                    op_emoji_docomo : {
     
    243245            }
    244246
    245             if (n == "op_cmd" && config["op_cmd"].isEnabled) {
     247            if (n == "op_cmd" && config["op_cmd"] && config["op_cmd"].isEnabled) {
    246248                c = this._createOpenPNECmdButton(n, {title: "{#openpne.op_cmd}", image: config["op_cmd"].imageURL, cmd: "mceOpenPNE_op_cmd"}, cm);
    247249            }
Note: See TracChangeset for help on using the changeset viewer.