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

source: OpenPNE/trunk/public_html/js/pne_decoration.js.src @ 10549

Last change on this file since 10549 was 10549, checked in by ebihara, 13 years ago

#3459:テキストモード時のカラーピッカー内の a 要素の href 属性値を # に戻し、 onMouseDown イベントに登録される処理内で false を返すように修正

File size: 6.3 KB
Line 
1function pne_toggle_mce_editor(id)
2{
3    var textmode_checked = document.getElementById("mce_editor_mode_changer_1").checked;
4    var previewmode_checked = document.getElementById("mce_editor_mode_changer_2").checked;
5
6    var editor = tinyMCE.get(id);
7    if (!editor && previewmode_checked) {
8        tinyMCE.execCommand('mceAddControl', 0, id);
9        document.getElementById('mce_editor_buttonmenu').style.display = "none";
10        return true;
11    }
12
13    if (editor.isHidden() && previewmode_checked) {
14        editor.show();
15        document.getElementById('mce_editor_buttonmenu').style.display = "none";
16    } else if (!editor.isHidden() && textmode_checked) {
17        editor.hide();
18        document.getElementById('mce_editor_buttonmenu').style.display = "block";
19    }
20}
21
22function pne_mce_editor_init()
23{
24    tinyMCE.init({
25        mode : "textareas",
26        theme : "advanced",
27        editor_selector : "mceEditor_dummy_selector",
28        plugins : "openpne",
29        theme_advanced_toolbar_location : "top",
30        theme_advanced_toolbar_align : "left",
31        theme_advanced_buttons1 : "op_b,op_u,op_s,op_i,op_large,op_small,op_color,op_image,op_emoji_docomo,op_emoji_au,op_emoji_softbank,op_cmd",
32        theme_advanced_buttons2 : "",
33        theme_advanced_buttons3 : "",
34        valid_elements : "b/strong,u,s/strike,i,font[color|size],br",
35        forced_root_block : false,
36        force_p_newlines : false,
37        force_br_newlines : true,
38        inline_styles : false,
39        language : "ja",
40        entity_encoding : "raw",
41        remove_linebreaks : false,
42        custom_undo_redo_levels : 0,
43        custom_undo_redo : false
44    });
45
46    var textmode_checkbox = document.getElementById("mce_editor_mode_changer_1");
47    var previewmode_checkbox = document.getElementById("mce_editor_mode_changer_2");
48    if (previewmode_checkbox.checked) {
49        textmode_checkbox.checked = true;
50        previewmode_checkbox.checked = false;
51    }
52}
53
54function pne_mce_insert_tagname(id, tagname, opt)
55{
56    var opt = opt || "";
57
58    var elm = document.getElementById(id);
59
60    if (tagname == "op:color" && !opt) {
61        pne_mce_show_color_table(id, tagname);
62        return;
63    }
64
65
66    var selection = new Selection(elm);
67    var pos = selection.create();
68    elm.focus();
69
70    var replace = "<" + tagname + opt + ">" + elm.value.substring(pos.start, pos.end) + "</" + tagname + ">";
71
72    var head = elm.value.substring(0, pos.start);
73    var tail = elm.value.substring(pos.end, elm.value.length);
74    elm.value =  head + replace + tail;
75}
76
77function pne_mce_show_color_table(id, tagname)
78{
79    var table = document.getElementById("mce_editor_color_table")
80    if (table) {
81        if (table.style.display == 'none') {
82            table.style.display = 'block';
83            Event.observe(document, 'mousedown', pne_mce_hide_color_table);
84        } else {
85            pne_mce_hide_color_table();
86        }
87        return;
88    }
89
90    Event.observe(document, 'mousedown', pne_mce_hide_color_table);
91
92    var color = null;
93    var settings = {
94        colors : ["000000","993300","333300","003300","003366","000080","333399","333333","800000","FF6600","808000","008000","008080","0000FF","666699","808080","FF0000","FF9900","99CC00","339966","33CCCC","3366FF","800080","999999","FF00FF","FFCC00","FFFF00","00FF00","00FFFF","00CCFF","993366","C0C0C0","FF99CC","FFCC99","FFFF99","CCFFCC","CCFFFF","99CCFF","CC99FF","FFFFFF"],
95        grid_width : 8,
96        default_color : "#888888"
97    };
98
99    var button = document.getElementById("mce_textmode_button_op_color");
100
101    var button_container = document.getElementById("mce_editor_buttonmenu");
102
103    var tbody = document.createElement("tbody");
104    Element.addClassName(tbody, 'disabledHideColorTable');
105
106    var tr;
107 
108    for (var i = 0; i < settings.colors.length; i++) {
109        var code = "#" + settings.colors[i];
110
111        if (i == 0 || i % settings.grid_width == 0) {
112            tr = document.createElement("tr");
113            Element.addClassName(tr, 'disabledHideColorTable');
114            tbody.appendChild(tr);
115        }
116
117        var td = document.createElement("td");
118        td.style.border = "0 none";
119        td.style.width = "12px";
120        td.style.padding = "2px";
121        td.style.margin = "0";
122        Element.addClassName(td, 'disabledHideColorTable');
123
124        var a = document.createElement("a");
125        a.setAttribute("href", "#");
126        a.colorCode = code;
127        a.style.width = "9px";
128        a.style.height = "9px";
129        a.style.display = "block";
130        a.style.overflow = "hidden";
131        a.style.border = "1px solid #808080";
132        a.style.backgroundColor = "#" + settings.colors[i];
133        Element.addClassName(a, 'disabledHideColorTable');
134        a.onmousedown = function() {
135            pne_mce_insert_tagname(id, tagname, ' code="' + this.colorCode + '"');
136            pne_mce_hide_color_table();
137            return false;
138        };
139
140        var span = document.createElement("span");
141        span.style.display = "none";
142        span.appendChild(document.createTextNode(code));
143
144        a.appendChild(span);
145        td.appendChild(a);
146        tr.appendChild(td);
147    }
148
149    var table = document.createElement("table");
150    table.id = "mce_editor_color_table";
151    table.style.width = "auto";
152    table.style.position = "absolute";
153    table.style.zIndex = 150;
154    table.style.border = "1px solid gray";
155    table.style.backgroundColor = "#fff";
156    table.appendChild(tbody);
157    Element.addClassName(table, 'disabledHideColorTable');
158
159    button_container.appendChild(table);
160
161    if (Prototype.Browser.IE) {
162        table.style.left = button.parentNode.offsetWidth + button.offsetWidth + "px";
163        table.style.top = table.offsetTop + button.offsetHeight;
164    } else {
165        table.style.left = button.offsetLeft + table.offsetLeft + "px";
166    }
167}
168
169function pne_mce_hide_color_table(e)
170{
171    if (e && Element.hasClassName(e.element(), 'disabledHideColorTable')) {
172        return;
173    }
174
175    var table = document.getElementById("mce_editor_color_table")
176    table.style.display = 'none';
177    Event.stopObserving(document, 'mousedown', pne_mce_hide_color_table);
178}
179
180function pne_insert_str_to_selection(elm, str)
181{
182    var selection = new Selection(elm);
183    var pos = selection.create();
184    elm.focus();
185
186    var head = elm.value.substring(0, pos.start);
187    var tail = elm.value.substring(pos.end, elm.value.length);
188    elm.value =  head + str + tail;
189}
190
Note: See TracBrowser for help on using the repository browser.