var ed_temp = false; var editor = { href: "index.php?r=teacher/docs#Ajax", mUrl: "index.php?r=teacher/docs", loadEditorMin: function (id, rows) { rows = rows || 300; this.removeTinyMCE(id); tinymce.init({ selector: 'textarea#' + id, height: rows, theme: 'modern', language: 'vi_VN', branding: false, plugins: [ 'advlist autolink lists link image charmap print preview hr anchor pagebreak', 'searchreplace wordcount visualblocks visualchars code fullscreen', 'insertdatetime media nonbreaking save table contextmenu directionality', 'emoticons template textcolor colorpicker textpattern imagetools mathjax' ], toolbar1: 'styleselect | bold underline italic | alignleft aligncenter alignright alignjustify | bullist numlist | forecolor | media image btnVideo btnFlash btnPicture | math mathjax', setup: function (ed) { }, image_class_list: [ {title: 'Không dùng', value: ''}, {title: 'Tự co dãn theo chiều rộng', value: 'img-responsive img-c2f'}, ], image_advtab: false, relative_urls : false, remove_script_host : false, entity_encoding: 'raw', init_instance_callback: function (ed) { // ed.execCommand('mceImage'); } }); }, loadEditorMin2: function (id, rows) { rows = rows || 300; this.removeTinyMCE(id); tinymce.init({ selector: 'textarea#' + id, height: rows, theme: 'modern', language: 'vi_VN', branding: false, menubar: false, toolbar1: 'styleselect | bold underline italic | alignleft aligncenter alignright alignjustify | bullist numlist', image_advtab: false, image_class_list: [ {title: 'Không dùng', value: ''}, {title: 'Tự co dãn theo chiều rộng', value: 'img-responsive img-c2f'}, ], templates: [ {title: 'Test template 1', content: 'Test 1'}, {title: 'Test template 2', content: 'Test 2'} ], relative_urls : false, remove_script_host : false, entity_encoding: 'raw' }); }, loadEditorInline: function (id, callback_config) { this.removeTinyMCE(id); tinymce.init({ selector: '#' + id, inline: true, theme: 'modern', language: 'vi_VN', branding: false, plugins: [ 'advlist autolink lists link image charmap print preview hr anchor pagebreak', 'searchreplace wordcount visualblocks visualchars code fullscreen', 'insertdatetime media nonbreaking save table contextmenu directionality', 'emoticons template paste textcolor colorpicker textpattern imagetools', 'placeholder' ], valid_elements: "p[style],h3,h4,h5,h6,a[href|target],strong/b,br,table,tbody,thead,tr,td,ul,ol,li,img[src|class]", toolbar1: 'styleselect | bold underline italic | alignleft aligncenter alignright alignjustify | bullist numlist | media btnVideo btnFlash btnPicture | math', setup: function (ed) { if (callback_config) { callback_config(ed); } }, image_advtab: false, image_class_list: [ {title: 'Không dùng', value: ''}, {title: 'Tự co dãn theo chiều rộng', value: 'img-responsive img-c2f'}, ], relative_urls : false, remove_script_host : false, entity_encoding: 'raw', // document_base_url:document_base_url, file_picker_callback: filePicker }); }, addPreview: function () { var tex = $("#math-editor").val(); if (tex !== "") { $("#math-preview").html("$" + tex + "$"); } else { $("#math-preview").html(""); } MathJax.Hub.Queue(["Typeset", MathJax.Hub, $("#math-preview")[0]]); }, removeTinyMCE: function (id) { try { tinymce.execCommand('mceRemoveEditor', true, id); } catch (ex) { console.log(ex); //exception with Firefox } //remove editor from EditorManager var editors = tinymce.EditorManager.editors; for (var i = 0; i < editors.length; i++) { var editor = editors[i]; if (editor.id == id) { editors.splice(i, 1); } } delete(editors[id]); }, formAddVideo: function () { global.openModal(this.htmlLoading, true, "Quản lý video"); $.ajax({ url: this.href, type: 'POST', data: { formAddVideo: true }, success: function (data) { $("#myModalContent").html(data); } }); }, formAddVideo2: function (e) { var Search = $("input[name='TimKiemVideo']").val(); $(e).button("loading"); $.ajax({ url: this.href, type: 'POST', data: { formAddVideo: true, Search: Search }, success: function (data) { $("#myModalContent").html(data); $("input[name='TimKiemVideo']").val(Search); } }); }, addVideo: function (e) { var HTML = ""; ed_temp.insertContent(HTML); $("#myModal").modal("hide"); }, formAddFlash: function () { global.openModal(this.htmlLoading, true, "Quản lý bài giảng tương tác"); $.ajax({ url: this.href, type: 'POST', data: { formAddFlash: true }, success: function (data) { $("#myModalContent").html(data); } }); }, formAddFlash2: function (e) { var Search = $("input[name='TimKiemFlash']").val(); $(e).button("loading"); $.ajax({ url: this.href, type: 'POST', data: { formAddFlash: true, Search: Search }, success: function (data) { $("#myModalContent").html(data); $("input[name='TimKiemFlash']").val(Search); } }); }, addFlash: function (e) { var HTML = "

"; ed_temp.insertContent(HTML); $("#myModal").modal("hide"); } }; $("#math-editor").on("keyup", function () { editor.addPreview(); }); $("#math-ok").on("click", function () { if ($("#math-editor").val() !== "") { var tex = "$" + $("#math-editor").val() + "$"; } else { var tex = ""; } ed_temp.insertContent(tex); $("#mathEditor").modal("hide"); }); $("#math-refresh").on("click", function () { $("#math-editor").val(""); $("#math-preview").html(""); }); $(".btn-math").on("click", function () { var code = $(this).attr("data"); var cursorPos = $('#math-editor').prop('selectionStart'); var v = $('#math-editor').val(); var textBefore = v.substring(0, cursorPos); var textAfter = v.substring(cursorPos, v.length); $('#math-editor').val(textBefore + code + textAfter); editor.addPreview(); });