function initMCE()
{
var toolbars = "";
var toolbars2 = "";
console.log(SERVER.HTTP_USER_AGENT);
var UA = SERVER;
if( UA.match("iPhone|iPod|Android.*Mobile|Windows.*Phone") )
{ // if (preg_match("/iPhone|iPod|Android.*Mobile|Windows.*Phone/", $UA) ) {
toolbars = "savebyajax | mob | view | listmob | tb | hdmob | cp | PST | div | headerdiv ";
} else {
toolbars = "title | tb | savebyajax | save_image | hr | fontsizeselect forecolor backcolor | bold | alignleft aligncenter alignright | bullist numlist | removeformat";
toolbars2= "space_last | space_after | div | headerdiv | divdiv | cp|pst|KUT|KUT2 | visualblocks | code | cssadd |addstyle | addstyleblock| | clearstyle | p10 | mlminus | mlplus | mlpx";
// pdf | pb
}
tinymce.init({
selector: '#mce',
language: "ja", // 言語 = 日本語
force_br_newlines : false, // 改行時にP要素が追加される仕様を停止
force_p_newlines : false, // 同上
forced_root_block : '', // 同上
target_list: false, // リンクのターゲットのリストはいらない
link_title: false, // 同じくタイトル属性はいらない
apiKey: "1W1PDFLT",
default_link_target: "_blank" ,
paste_data_images: true, // 画像貼り付け base64
block_unsupported_drop: true,
//inline: true,
// extended_valid_elements: 'a[href|target=_blank]',
//content_css : '/css/ymnstyle.css',
branding: false, // Powered by TinyMCEを消す
entity_encoding: "raw",
force_hex_style_colors : true, // RGB形式ではなく16進形式で表記
fontsize_formats: "8px 10px 12px 14px 16px 18px 24px 36px ", // font sizeはptではなくpxに変更
toolbar: [ toolbars,toolbars2 ],
plugins: [
"","contextmenu","visualblocks",
"code","preview","image",
"imagetools","template", "lists","textcolor","link",
"table","hr","paste"
],
content_css : '/css/mce.css', // includes both CSS files in header
autoresize_bottom_margin: 50,
skin: 'oxide-dark',
minwidth: "10px",
width: "100%",
height: '100%', //window.outerHeight-187,
resize: 'both',
autoresize_overflow_padding: 0,
autoresize_bottom_margin: 0,
protect: [
/\<(script)\>/g ,
/\<\/?(script)\>/g ,
/\<\/?(style)\>/g
],
init_instance_callback: function (editor) {
editor.on("drop", function (event) {
var data = event.dataTransfer.getData("text");
var t= event.dataTransfer;
var type = t.items[0].type;
var name="";
if(type != "text/plain") {
name = event.dataTransfer.files[0].name;
} else {
if( typeof event.dataTransfer.files[0] == 'undefined' ) {
type="text";
console.log(event);
}
}
var id = $("#id").val();
var iconurl = "";
var reader = new FileReader();
if(type=="") {
type = "application/octet-stream";
}
alert(type);
switch(type) {
case "text/javascript":
case "text/x-python":
case "multipart/related":
if( iconurl == "") iconurl = "/images/js.png";
case "text/plain":
if( iconurl == "") iconurl = "/images/text.png";
case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
case "application/msword":
if( iconurl == "") iconurl = "/images/word.png";
case "application/vnd.ms-excel":
case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
if( iconurl == "") iconurl = "/images/excel.png";
case "application/vnd.openxmlformats-officedocument.presentationml.presentation":
case "application/wps-office.pptx":
case "application/wps-office.ppt":
if( iconurl == "") iconurl = "/img/4_0.png";
case "application/x-zip-compressed":
if( iconurl == "") iconurl = "/images/octat.png";
case "application/octet-stream":
if( iconurl == "") iconurl = "/images/octat.png";
case "application/pdf":
if( iconurl == "")iconurl = "/images/pdf.png";
event.preventDefault()
//img/evt.target.result;
// id_ミリタイム.ppt として アップロードする
// アップロードしたら 下記のリンクをはる
formData = new FormData();
formData.append('file', event.dataTransfer.files[0]);
formData.append('id', id);
formData.append('name', name);
console.log( event.dataTransfer.files[0]);
$.ajax({
url: '/docs/upload', // form action url
type: 'POST', // form submit method get/post
dataType: 'html', // request type html/json/xml
processData: false,
contentType: false,
data: formData,
beforeSend: function () {
},
success: function (data) {
insert = " " + name +" ";
insert = " " + name +" ";
tinyMCE.execCommand('mceInsertContent',false, insert);
console.log(data);
},
error: function (e) {
console.log(e)
}
});
break;
case "image/jpeg":
case "image/png":
case "image/gif":
break;
case "text":
console.log(event);
console.log(event);
break;
default:
console.log(type);
event.preventDefault()
reader.onloadend = function (evt) {
if (evt.target.readyState == FileReader.DONE) {
event.target.innerHTML+=evt.target.result;
}
var d = evt.target.result;
}
reader.readAsText(event.dataTransfer.files[0]);
break;
}
});
}, // init
setup: function(editor) {
editor.on('init', function(args) {
show_content();
$("#atxt").val($("#title").val());
$("#atxt").on("keyup",function() {
$("#title").val($("#atxt").val());
});
});
/*editor.on("focus", function () {
tinymce.activeEditor.dom.setAttrib(tinymce.activeEditor.dom.select('img'), 'height', 'auto'); tinymce.activeEditor.dom.setAttrib(tinymce.activeEditor.dom.select('img'), 'width', '100%');
});
*/
editor.ui.registry.addButton('title', {
text: "題名 : ",
image: "./skin/tinymce/plugin.png",
onAction: function () {
// tinyMCE.execCommand('mceInsertContent',false, "
h1 div
\n");
}
});
editor.ui.registry.addButton('hdmob', {
text: "H1+",
image: "./skin/tinymce/plugin.png",
onAction: function () {
tinyMCE.execCommand('mceInsertContent',false, "h1 div
\n");
}
});
editor.ui.registry.addButton('tb', {
text: "設定",
image: "./skin/tinymce/plugin.png",
onAction: function () {
toggleMenu();
}
});
editor.ui.registry.addButton('savebyajaxmob', {
//Ajaxで保存
text: "保存",
onAction: function () {
saveByAjax();
alert("保存完了");
}
});
editor.ui.registry.addButton('listmob', {
text: "一覧",
onAction: function () {
location.href = "/docs/";
}
});
editor.ui.registry.addMenuItem('basicitem', {
text: 'My basic menu item',
onAction: function() {
$("tox-collection__item-label").css('color','red');
alert('Menu item clicked');
alert('Menu item clicked');
}
}),
editor.on("focusin",function(e) {
current_selected = e.target;
}),
editor.on('SelectionChange',function(e) {
var s =document.activeElement;
var selObj = window.getSelection();
});
editor.on('NodeChange', function (e) {
var s = $('#fieldBody_ifr:focus'); //$("#fieldBody_ifr");
});
editor.ui.registry.addButton('pdf', {
text: "pdf",
image: "./skin/tinymce/plugin.png",
onAction: function () {
export_pdf();
}
});
editor.ui.registry.addButton('space_before', {
text: "空前",
image: "./skin/tinymce/plugin.png",
onAction: function () {
var b = editor.getContent();
nd = editor.selection.getNode();
console.log(nd.innerHTML);
//nd.innerHTML = "@@@ " + nd.innerHTML;
nd.parentNode.innerHTML = "*** Insert Text *** " + nd.parentNode.innerHTML;
return;
}
});
editor.ui.registry.addButton('space_after', {
text: "空後",
image: "./skin/tinymce/plugin.png",
onAction: function () {
var b = editor.getContent();
nd = editor.selection.getNode();
console.log(nd.innerHTML);
//nd.innerHTML = nd.innerHTML + " @@@";
nd.parentNode.innerHTML = nd.parentNode.innerHTML + " *** Insert Text ***";
// console.log(nd.parentNode.);
return;
}
});
editor.ui.registry.addButton('space_last', {
text: "最後",
image: "./skin/tinymce/plugin.png",
onAction: function () {
var b = editor.getContent();
editor.setContent( b + " **" );
return;
}
});
editor.ui.registry.addButton('list', {
text: "一覧 ",
image: "./skin/tinymce/plugin.png",
onAction: function () {
location.href = "/docs/";
// tinyMCE.execCommand('mceInsertContent',false, "div
");
}
});
editor.ui.registry.addButton('list', {
//一覧
text: " ",
image: "/img/list.png",
onAction: function () {
location.href = "/docs/";
// tinyMCE.execCommand('mceInsertContent',false, "div
");
}
});
editor.ui.registry.addButton('view', {
//回覧
text: "見る",
image: "./skin/tinymce/plugin.png",
onAction: function () {
var queryString = window.location.search;
var queryObject = new Object();
if(queryString){
queryString = queryString.substring(1);
var parameters = queryString.split('&');
for (var i = 0; i < parameters.length; i++) {
var element = parameters[i].split('=');
var paramName = decodeURIComponent(element[0]);
var paramValue = decodeURIComponent(element[1]);
queryObject[paramName] = paramValue;
}
}
location.href = "/docs/read?id=" + queryObject['id'];
}
});
editor.ui.registry.addButton('save', {
//保存
text: " ",
image: "./skin/tinymce/plugin.png",
onAction: function () {
//console.log($("#write #fm").prop("action");
$("#write #fm").submit();
}
});
editor.ui.registry.addButton('savebyajax', {
//Ajaxで保存
text: "保存",
onAction: function () {
saveByAjax();
}
});
editor.ui.registry.addButton('save_image', {
text: "画保",
image: "./skin/tinymce/plugin.png",
onAction: function () {
var queryString = window.location.search;
var queryObject = new Object();
if(queryString){
queryString = queryString.substring(1);
var parameters = queryString.split('&');
for (var i = 0; i < parameters.length; i++) {
var element = parameters[i].split('=');
var paramName = decodeURIComponent(element[0]);
var paramValue = decodeURIComponent(element[1]);
queryObject[paramName] = paramValue;
}
}
location.href="/docs/image_save?id=" + queryObject['id'];
}
});
editor.ui.registry.addButton('div', {
text: "div",
icon: "plugin",
image: "./skin/tinymce/plugin.png",
onAction: function () {
tinyMCE.execCommand('mceInsertContent',false, "div
");
}
});
editor.ui.registry.addButton('pb', {
text: "PB",
onAction: function () {
tinyMCE.execCommand('mceInsertContent',false, "
\n");
}
});
editor.ui.registry.addButton('headerdiv', {
text: "H1D",
image: "",
onAction: function () {
tinyMCE.execCommand('mceInsertContent',false, "h1 div
\n");
}
});
editor.ui.registry.addButton('divdiv', {
text: "dd",
icon: "plugin",
image: "./skin/tinymce/plugin.png",
onAction: function () {
tinyMCE.execCommand('mceInsertContent',false, "TITLE
***
\n");
}
});
editor.ui.registry.addButton('clearstyle', {
//スタイルシート変更 ノード(ブロック)
text: '削css',
tooltip: "ブロック要素のスタイルシートを削除します",
image: "https://ymn.red/images/youtube.png",
onAction: function () {
s = editor.selection.getNode();
nd = editor.selection.getNode();
nd.setAttribute("data-mce-style","");
nd.style['cssText'] = "";
nd.style=null;
}
});
editor.ui.registry.addButton('addstyle', {
//ス
text: '外css',
tooltip: "選択したブロック要素以外のCSS設定します",
image: "https://ymn.red/images/youtube.png",
onAction: function () {
nd = current_selected ;
//nd = editor.selection.getNode();
var ret;
ret = prompt("スタイルの変更",nd.style['cssText']);
if(ret!=null ) {
nd.style = null;
nd.style['cssText'] = ret;
nd.setAttribute("data-mce-style", ret);
}
}
});
editor.ui.registry.addButton('addstyleblock', {
// スブ
text: '中css',
tooltip: "ブロック要素(ノード)のスタイルシートを設定します。",
image: "https://ymn.red/images/youtube.png",
onAction: function () {
nd = editor.selection.getNode();
var ret;
ret = prompt("スタイルの変更",nd.style['cssText']);
if(ret !=null) {
nd.style = null;
nd.style['cssText'] = ret;
nd.setAttribute("data-mce-style", ret);
}
}
});
editor.ui.registry.addButton('p10', {
// スブ
text: 'p10',
tooltip: "ブロック要素(ノード)のスタイルシートを設定します。",
image: "https://ymn.red/images/youtube.png",
onAction: function () {
//nd = current_selected ;
nd = editor.selection.getNode();
var ret;
ret = nd.style['cssText'];
if(ret !=null) {
nd.style = null;
nd.style['cssText'] = ret + ";padding:10px;";
nd.setAttribute("data-mce-style", ret);
}
}
});
editor.ui.registry.addButton('cp', {
text: "コピ",
icon: "copy",
image: "https://www.tiny.cloud/docs-4x/images/for-base/logo-spaces-docs-for-base.png",
onAction: function () {
//nd = current_selected ;
o = tinyMCE.activeEditor.selection.getContent();
console.log(o);
nd = editor.selection.getNode()
$textarea = $('');
$("#TMP").val(o);
$("#TMP").select();
navigator.clipboard.writeText(o);
document.execCommand("copy");
document.execCommand("Copy");
}
});
editor.ui.registry.addButton('PST', {
text: "ペスト",
icon: "paste",
image: "./skin/tinymce/plugin.png",
onAction: function () {
var val = $("#TMP").val();
tinyMCE.execCommand('mceInsertContent',false, val);
}
});
editor.ui.registry.addButton('KUT', {
text: "",
icon: "cut",
image: "./skin/tinymce/plugin.png",
onAction: function () {
nd = editor.selection.getNode();
var newtxt = document.createTextNode("削");
// console.log(nd);
// var parentDiv = nd.parentNode; // 置換対象ノードの親要素
// console.log(parentDiv);
// parentDiv.replaceChild(nd, newtxt);
//
nd.replaceWith(newtxt);
// nd.remove();
// tinyMCE.execCommand('mceInsertContent',false, val);
}
});
editor.ui.registry.addButton('KUT2', {
text: "2",
icon: "cut",
image: "./skin/tinymce/plugin.png",
onAction: function () {
nd = current_selected ;
st = nd.toString();
console.log(st);
if(st.match(/.*?HTMLBodyElement.*?/)) {
console.log("BODY");
} else {
var newtxt = document.createTextNode("削");
nd.replaceWith(newtxt);
}
}
});
editor.ui.registry.addButton('cssadd', {
text: "クラス名",
image: "./skin/tinymce/plugin.png",
onAction: function () {
var ret;
nd = editor.selection.getNode();
var cl = nd.classList;
ret = prompt("クラス名",cl);
// クラス名を全部削除
nd.classList.remove(...nd.classList);
ret = ret.split(' ');
ret.forEach(function(o) {
nd.classList.add(o);
});
}
});
editor.ui.registry.addButton("setclass", {
text: "SC",
image: "./skin/tinymce/plugin.png",
onAction: function () {
// https://www.tiny.cloud/docs/api/tinymce.dom/tinymce.dom.selection/
var ret;
ret = prompt();
nd = editor.selection.getNode();
console.log( nd.classList);
nd.classList.forEach(function(o){
nd.classList.remove(o);
})
nd.classList.add("h1_"+ret);
}
});
editor.ui.registry.addButton('youtube', {
// ヨウツベ
text: '',
tooltip: "YoutubeのURLを張りつけると画像+リンクがインサートされます",
image: "https://ymn.red/images/youtube.png",
onAction: function () {
var ret;
ret = prompt();
if(ret.match(/.*?youtube.*?/)) {
//ret = "https://www.youtube.com/watch?v=yD1Rlli7cNk&ab_channel=%E3%81%95%E3%81%8D%E3%83%A8%E3%82%AC%E3%81%A1%E3%82%83%E3%82%93%E3%81%AD%E3%82%8B";
var id = ret.match(/[\/?=]([a-zA-Z0-9_-]{11})[&\?]?/)[1];
u = " ";
//var u = '';
//var u = ' ';
//var b = editor.getContent();
//editor.setContent(b + u);
tinyMCE.execCommand('mceInsertContent',false, u);
}
}
});
editor.ui.registry.addButton('divcodet', {
text: "コードT",
icon: "plugin",
image: "./skin/tinymce/plugin.png",
onAction: function () {
tinyMCE.execCommand('mceInsertContent',false, "");
return;
}
});
editor.ui.registry.addButton('mlplus', {
text: "→",
image: "./skin/tinymce/plugin.png",
onAction: function () {
// https://www.tiny.cloud/docs/api/tinymce.dom/tinymce.dom.selection/
nd = editor.selection.getNode();
var ml = nd.style.marginLeft;
if( ml=="") {
console.log("set 1px left-mergin");
nd.style.marginLeft = "1px";
} else {
ml=ml.replace(/px/,"");
console.log(ml);
ml++;
console.log(ml);
nd.style.marginLeft = ml + "px";
}
return;
}
});
editor.ui.registry.addButton('mlpx', {
text: "px",
image: "./skin/tinymce/plugin.png",
onAction: function () {
var ret;
ret = prompt();
nd = editor.selection.getNode();
var ml = nd.style.marginLeft;
if(ret) {
nd.style.marginLeft=ret + "px";
}else {
nd.style.marginLeft ="";
}
}
});
editor.ui.registry.addButton('mlminus', {
text: "←",
image: "./skin/tinymce/plugin.png",
onAction: function () {
// https://www.tiny.cloud/docs/api/tinymce.dom/tinymce.dom.selection/
nd = editor.selection.getNode();
var ml = nd.style.marginLeft;
if( ml=="") {
console.log("set 1px left-mergin");
nd.style.marginLeft = "0px";
} else {
ml=ml.replace(/px/,"");
console.log(ml);
ml--;
console.log(ml);
nd.style.marginLeft = ml + "px";
}
return;
}
});
editor.ui.registry.addButton('divcode', {
text: "コード",
icon: "plugin",
image: "./skin/tinymce/plugin.png",
onAction: function () {
tinyMCE.execCommand('mceInsertContent',false, "code
");
return;
var ret;
ret = prompt();
if(ret.match(/.*?youtube.*?/)) {
//ret = "https://www.youtube.com/watch?v=yD1Rlli7cNk&ab_channel=%E3%81%95%E3%81%8D%E3%83%A8%E3%82%AC%E3%81%A1%E3%82%83%E3%82%93%E3%81%AD%E3%82%8B";
var id = ret.match(/[\/?=]([a-zA-Z0-9_-]{11})[&\?]?/)[1];
u = " ";
//var u = '';
//var u = ' ';
var b = editor.getContent();
editor.setContent(b + u);
}
}
});
}, // setup
});
}
function saveByAjax() {
$("#atxt").val($("#title").val());
$("#rawdata").val( tinyMCE.activeEditor.getContent());
// var fm= $("#rawdata").parent().parent().parent().get(0);
var fm = $("#myform").get(0);
var f = new FormData(fm); //$("#rawdata").parent());//.get(0));
$.ajax({
url: '/index/savebyajax', // form action url
type: 'POST', // form submit method get/post
dataType: 'json', // request type html/json/xml
processData: false,
contentType: false,
data: f
}).done(function (data) {
var result=data;
if( data.success ) {
} else {
//alert(data.message);
}
console.log("SaveByAjax後の RESULT"); console.log(data);
//jAlert("success");
}).fail(function(data) {
console.log("***ERROR***");
console.log(data.responseText);
});
}
function cbcopy (e) {
e.select();
var val = e.value;
if (navigator.clipboard)
{
// chrome, firefox
navigator.clipboard.writeText(val); //.then(function, failed);
} else {
tagText.select() // inputタグを選択する
document.execCommand('copy') // クリップボードにコピーする
alert('tagSelect');
}
return true;
}
function onChange(e) { var itms = e.target.getBody(); return true; }
function show_content(){}
function getGetParam(){}
function setDocument(){}
function mobile_menu() {
$("#mmenu").css('background-color',"#337733").css('color','white')
.css('position','absolute').css('top','0')
.css('width','100%').css('height',"100vh").css('visibility','visible')
.css('vertical-align',"middle").css('margin',"auto")
;
//: 2px solid white; padding:10px;margin:5px;')
$('.tox-editor-container').css('visibility','hidden');
$("#mmenu > div").css('padding','10px').css('margin','5px').css('border-width','1px').css('border-style','solid').css('border-color','white');
}
function mobile_menu_close(obj) {
$("#title").val($("#atxt").val());
$('#mmenu').css('visibility','hidden');
$('.tox-editor-container').css('visibility','visible');
}