| Server IP : 133.18.244.157 / Your IP : 216.73.217.20 Web Server : Apache System : Linux o4022v-135.kagoya.net 2.6.32-754.35.1.el6.x86_64 #1 SMP Sat Nov 7 12:42:14 UTC 2020 x86_64 User : main2 ( 81069) PHP Version : 5.6.34 Disable Function : NONE MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /install/web_root/html/js/component/ |
Upload File : |
mw.base.namespace('mw.Richedit');
if (typeof $.fn.tinymce == "undefined") {
throw new Error("tinyMCE must be included.");
}
(function() {
var ns = mw.Richedit;
$.fn.richedit = function($input, options){
var caller = this;
var component = new ns.Richedit(this, $input, options);
};
ns.Richedit = function($element, $input, options) {
var self = this;
this.$element_ = $element;
var $toggle = $('<div>');
var $toPlainText = $('<span><a href="#">≪ テキスト</a></span>');
var $toRichText = $('<span><a href="#">書式編集 ≫</a></span>');
this.$input_ = $input;
$toggle.append($toPlainText);
$toggle.append($toRichText);
if ($input.val() == "1") {
$toRichText.hide();
} else {
$toPlainText.hide();
}
$toPlainText.click(function(e) {
if( ! window.confirm( "テキスト編集に切り替えると全ての書式は失われます。失われた書式を復元することはできません。\nテキスト編集に切り替えますか?" ) )
{
return false;
}
var mce = $element.tinymce();
var data = ns.htmlToText(mce.getContent({format : 'raw'}));
mce.remove();
$element.val(data);
$toRichText.show();
$toPlainText.hide();
$input.val("0");
return false;
});
$toRichText.click(function(e) {
var data = $element.val();
data = ns.textToHtml(data);
$element.val(data);
$element.tinymce(self.setting_);
self.setMce();
$toPlainText.show();
$toRichText.hide();
$input.val("1");
return false;
});
$element.parent().prepend($toggle);
this.setting_ = {
// General options
//debug : true,
language : "ja",
convert_urls : false,
mode : "exact",
theme : "advanced",
plugins : "style",
script_url : mw.js('tiny_mce/tiny_mce'),
// Theme options
theme_advanced_buttons1 : "fontsizeselect,|,bold,italic,underline,|,justifyleft,justifycenter,justifyright,|,bullist,numlist,|,outdent,indent,blockquote,|,forecolor,backcolor,|,link,unlink",
theme_advanced_buttons2 : "",
theme_advanced_buttons3 : "",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
theme_advanced_blockformats : "h1,h2,h3,h4,h5,h6",
theme_advanced_path: false,
theme_advanced_more_colors: false,
// Example word content CSS (should be your site CSS) this one removes paragraph margins
body_class : 're-content',
content_css : mw.css('tinymce.css') + ',' + mw.css('std.css'),
theme_advanced_font_sizes: "8px,12px,14px,18px,22px,26px,32px",
font_size_style_values : "8px,12px,14px,18px,22px,26px,32px",
// Other options
element_format : 'html',
doctype : '<!DOCTYPE html>',
forced_root_block : 'div',
visual : false,
fix_table_elements : false,
link_func : function() { self.createLink_(); }
};
if ($input.val() == "1") {
$element.tinymce(this.setting_);
self.setMce();
}
};
ns.textToHtml = function( text ) {
/*if( ! text || text.length < 1 ) {
return "";
}*/
var html = text;
html = html.replace( /&/g, "&" );
html = html.replace( /</g, "<" );
html = html.replace( />/g, ">" );
html = html.replace( /\"/g, """ );
html = html.replace( / /g, " " );
html = html.replace( /(\r?\n)/g, "</DIV>$1<DIV>" );
html = "<DIV>"+html+"</DIV>";
html = html.replace( /<DIV><\/DIV>/ig, "<DIV> </DIV>" );
return html;
};
ns.insertNewLine = function( text ) {
text = text.replace( /[\r\n]/ig, "" );
text = text.replace( /(<BR[^>]*>)\n/ig, "$1" );
text = text.replace( /(<BR[^>]*>)/ig, "$1\n" );
return text;
};
ns.htmlToText = function( html ) {
var text = html;
text = text.replace( /[\r\n]/g, "" );
if( text.length == 17 && text.match( /<DIV> <\/DIV>/i ) )
{
text = "";
}
else
{
var oBlocks = {
"P":1,
"H1":1, "H2":1, "H3":1, "H4":1, "H5":1, "H6":1,
"OL":1, "UL":1, "DIR":1, "MENU":1, "DL":1,
"LI":1, "DT":1, "DD":1,
"PRE":1,
"DIV":1, "NOSCRIPT":1, "BLOCKQUOTE":1, "TABLE":1, "FIELDSET":1, "ADDRESS":1,
"CENTER":1
},
oInlines = {
"TT":1, "I":1, "B":1, "U":1, "S":1, "STRIKE":1, "BIG":1, "SMALL":1,
"EM":1, "STRONG":1, "DFN":1, "CODE":1, "SAMP":1, "KBD":1, "VAR":1, "CITE":1,
"ABBR":1, "ACRONYM":1,
"A":1, "IMG":1, "APPLET":1, "OBJECT":1, "FONT":1, "BASEFONT":1, "SCRIPT":1,
"MAP":1, "Q":1, "SUB":1, "SUP":1, "SPAN":1, "BDO":1, "IFRAME":1,
"INPUT":1, "SELECT":1, "TEXTAREA":1, "LABEL":1, "BUTTON":1,
"BLINK":1, "EMBED":1, "LAYER":1, "ILAYER":1, "NOLAYER":1, "NOBR":1,
"WBR":1, "RUBY":1, "RB":1, "RP":1, "RT":1,
"SPACER":1
},
elm, re, d, lt, gt, i, j, r, m;
function patBegin( e ) { return "[ \t\f\v]*<"+e+"((\\s+[^>]*>)|(\\s*>))[ \t\f\v]*"; }
function patEnd( e ) { return "[ \t\f\v]*</"+e+"\\s*>[ \t\f\v]*"; }
// インライン要素以外の直前のスペースを削除
d = [];
re = new RegExp( "[ \t\f\v]*</?([a-zA-Z]+)((\\s+[^>]*>)|(\\s*>))", "i" );
while( (m = text.match( re )) )
{
var match = m[0];
elm = RegExp.$1;
d.push( RegExp.leftContext );
text = RegExp.rightContext;
d.push( oInlines[elm.toUpperCase()] ? match : match.replace( /[ \t\f\v]*</g, "<" ) );
}
d.push( text );
text = d.join("");
// インライン要素以外の直後のスペースを削除
d = [];
re = new RegExp( "</?([a-zA-Z]+)((\\s+[^>]*>)|(\\s*>))[ \t\f\v]*", "i" );
while( (m = text.match( re )) )
{
var match = m[0];
elm = RegExp.$1;
d.push( RegExp.leftContext );
text = RegExp.rightContext;
d.push( oInlines[elm.toUpperCase()] ? match : match.replace( />[ \t\f\v]*/g, ">" ) );
}
d.push( text );
text = d.join("");
d = [];
re = new RegExp( "</?([a-zA-Z]+)((\\s+[^>]*>)|(\\s*>))", "i" );
while( (m = text.match( re )) )
{
d.push( RegExp.leftContext );
if( ! oInlines[RegExp.$1.toUpperCase()] ) d.push( m[0] );
text = RegExp.rightContext;
}
d.push( text );
text = d.join("");
for( elm in oBlocks )
{
if( ! text.match( new RegExp( elm, "i" ) ) ) continue;
re = new RegExp( patBegin(elm)+patEnd(elm), "ig" );
text = text.replace( re, "" );
d = [];
re = new RegExp( "[^<>\\s]"+patBegin(elm), "im" );
while( (m = text.match( re )) )
{
d.push( RegExp.leftContext );
m = m[0];
lt = m.lastIndexOf( "<" );
d.push( m.substring( 0, lt ) );
d.push( "\n" );
d.push( m.substr( lt ) );
text = RegExp.rightContext;
}
d.push( text );
text = d.join("");
d = [];
re = new RegExp( patEnd(elm)+"[^<\\s]", "im" );
while( (m = text.match( re )) )
{
d.push( RegExp.leftContext );
m = m[0];
if( oBlocks[RegExp.lastMatch] ) {
d.push( m );
} else {
gt = m.indexOf(">");
d.push( m.substring( 0, gt + 1 ) );
d.push( "\n" );
d.push( m.substr( gt + 1 ) );
}
text = RegExp.rightContext;
}
d.push( text );
text = d.join("");
d = [];
re = new RegExp( patEnd(elm)+patBegin("[a-zA-Z]+"), "im" );
while( (m = text.match( re )) )
{
d.push( RegExp.leftContext );
m = m[0];
gt = m.indexOf( ">" );
d.push( m.substring( 0, gt + 1 ) );
d.push( "\n" );
d.push( m.substr( gt + 1 ) );
text = RegExp.rightContext;
}
d.push( text );
text = d.join("");
}
if( text.match( /TABLE/i ) )
{
text = text.replace( /<\/TR\s*><TR((\s+[^>]*>)|(\s*>))/img, "\n" );
text = text.replace( /<\/T[DH]\s*><T[DH]((\s+[^>]*>)|(\s*>))/img, " " );
}
text = text.replace( /<BR((\s+[^>]*>)|(\s*>))/ig, "\n" );
text = text.replace( /<HR((\s+[^>]*>)|(\s*>))/ig, "\n" );
d = [];
var quote = new RegExp( "</?BLOCKQUOTE((\\s+[^>]*>)|(\\s*>))", "im" );
while( (m = text.match( quote )) )
{
d.push( RegExp.leftContext );
d.push(m[0]);
text = RegExp.rightContext;
if (m[0].indexOf("</") == 0) {
continue;
}
var depth = 1;
while( (m = text.match( quote )))
{
var leftContext = RegExp.leftContext;
var rightContext = RegExp.rightContext;
var content = "> " + leftContext.replace( /\n/ig, "\n> ");
d.push(content);
d.push(m[0]);
text = rightContext;
if (m[0].indexOf("</") == 0) {
depth--;
} else {
depth++;
}
if (depth == 0) break;
}
}
d.push( text );
text = d.join("");
text = text.replace( /<[^>]*>/img, "" );
text = text.replace( / /ig, " " );
text = text.replace( /</ig, "<");
text = text.replace( />/ig, ">");
text = text.replace( /"/ig, "\"");
text = text.replace( /&/ig, "&");
}
// remove last \n
if ( text.length > 0 && text.charAt(text.length-1) == "\n" ) {
text = text.substring( 0, text.length-1 );
}
if( text == " " )
{
text = "";
}
/*else if ( text == "\n" )
{
text = "";
}*/
else if( text.length > 0 && text.charAt(text.length-1) == ' ' )
{
if( html.length > 17 && html.substr(html.length-17) == "<DIV> </DIV>" )
text = text.substring( 0, text.length-1 );
}
return text;
};
ns.Richedit.prototype = {
setMce: function() {
var self = this;
// for templace selection
var t = setInterval(function() {
if (typeof tinyMCE != 'undefined') {
var mce = self.$element_.tinymce();
if (mce) {
self.$element_.get(0).tinyMCE = mce;
clearInterval(t);
}
}
}, 100);
},
storeSelection_: function() {
var ed = this.$element_.tinymce();
ed.windowManager.bookmark = ed.selection.getBookmark(1);
},
restoreSelection_: function() {
var ed = this.$element_.tinymce();
if (tinymce.isIE) {
ed.selection.moveToBookmark(ed.windowManager.bookmark);
}
},
execCommand_: function(cmd, ui, val, opt) {
var ed = this.$element_.tinymce();
opt = opt || {};
opt.skip_focus = 1;
this.restoreSelection_();
return ed.execCommand(cmd, ui, val, opt);
},
update_: function($dlg) {
var f = $dlg.find('FORM').get(0);
var ed = this.$element_.tinymce();
var href = f.href.value.replace(/ /g, '%20');
var target = $(f.target).val();
this.restoreSelection_();
var e = ed.dom.getParent(ed.selection.getNode(), 'A');
// Remove element if there is no href
if (!f.href.value || href == 'http://') {
if (e) {
b = ed.selection.getBookmark();
ed.dom.remove(e, 1);
ed.selection.moveToBookmark(b);
this.execCommand_("mceEndUndoLevel");
return;
}
}
// Create new anchor elements
if (e == null) {
ed.getDoc().execCommand("unlink", false, null);
this.execCommand_("mceInsertLink", false, "#mce_temp_url#", {skip_undo : 1});
tinymce.each(ed.dom.select("a"), function(n) {
if (ed.dom.getAttrib(n, 'href') == '#mce_temp_url#') {
e = n;
ed.dom.setAttribs(e, {
href : href,
target : target ? target : null
});
}
});
} else {
ed.dom.setAttribs(e, {
href : href,
target : target? target : null
});
}
// Don't move caret if selection was image
if (e.childNodes.length != 1 || e.firstChild.nodeName != 'IMG') {
ed.focus();
ed.selection.select(e);
ed.selection.collapse(0);
this.storeSelection_();
}
this.execCommand_("mceEndUndoLevel");
},
createLink_: function() {
var $linkDialog = $('#mce_link_dialog');
if ($linkDialog.size() > 0) {
$linkDialog.remove();
}
$linkDialog = $('<div style="display:none" id="mce_link_dialog"></div>');
$linkDialog.append(this.createForm_());
$('body').append($linkDialog);
var self = this;
var setting = {
modal: true,
buttons: {
"Ok": function() {
self.update_($linkDialog);
$( this ).dialog( "close" );
},
"キャンセル": function() {
$( this ).dialog( "close" );
}
}
};
setting.width = 400;
this.storeSelection_();
$linkDialog.attr('title', 'リンクの挿入/編集');
$linkDialog.dialog(setting);
},
createForm_: function($dlg) {
var $form = $('<form></form>');
var ed = this.$element_.tinymce();
var url = 'http://';
var target = '';
var e = ed.dom.getParent(ed.selection.getNode(), 'A');
if (e) {
url = ed.dom.getAttrib(e, 'href');
target = ed.dom.getAttrib(e, 'target');
}
var $table = $('<table></table>');
$table.append('<tr><td>リンクのURL</td><td><input type="text" style="width:250px" name="href" /></td></tr>');
$table.append('<tr><td>ターゲット</td><td><select name="target"><option value=""></option><option value="_blank">新しいウインドウで開く</option></select></td></tr>');
$table.find('INPUT').val(url);
if (target) {
$table.find('SELECT').val(target);
}
$form.append($table);
return $form;
}
};
})();