/war/src/main/webapp/js/admin/editorTinyMCE.js
http://github.com/b3log/b3log-solo · JavaScript · 126 lines · 75 code · 8 blank · 43 comment · 7 complexity · e030a805be08c5b46d2dfb93216b7222 MD5 · raw file
- /*
- * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- /**
- * @fileoverview tinyMCE editor
- *
- * @author <a href="mailto:LLY219@gmail.com">Liyuan Li</a>
- * @version 1.0.0.5, Jun 19, 2012
- */
- admin.editors.tinyMCE = {
- /*
- * @description ??????
- * @param conf ????????
- * @param conf.kind ?????
- * @param conf.id ??????? id
- * @param conf.fun ??????????????
- */
- init: function (conf) {
- var language = Label.localeString.substring(0, 2);
- if (language === "zh") {
- language = "zh-cn";
- }
-
- if (conf.kind && conf.kind === "simple") {
- try {
- tinyMCE.init({
- // General options
- language: language,
- mode : "exact",
- elements : conf.id,
- theme : "advanced",
-
- // Theme options
- theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,undo,redo,|,bullist,numlist",
- theme_advanced_buttons2 : "",
- theme_advanced_buttons3 : "",
- theme_advanced_toolbar_location : "top",
- theme_advanced_toolbar_align : "left",
-
- valid_children : "+body[style]"
- });
- } catch (e) {
- $("#tipMsg").text("TinyMCE load fail");
- }
- } else {
- try {
- tinyMCE.init({
- // General options
- language: language,
- mode : "exact",
- elements : conf.id,
- theme : "advanced",
- plugins : "autosave,style,advhr,advimage,advlink,preview,inlinepopups,media,paste,syntaxhl,wordcount",
-
- // Theme options
- theme_advanced_buttons1 : "formatselect,fontselect,fontsizeselect,|,bold,italic,underline,strikethrough,forecolor,|,advhr,blockquote,syntaxhl,",
- theme_advanced_buttons2 : "undo,redo,|,bullist,numlist,outdent,indent,|,justifyleft,justifycenter,justifyright,justifyfull,|,pastetext,pasteword,|,link,unlink,image,iespell,media,|,cleanup,code,preview,",
- theme_advanced_buttons3 : "",
- theme_advanced_toolbar_location : "top",
- theme_advanced_toolbar_align : "left",
- theme_advanced_resizing : true,
- theme_advanced_statusbar_location : "bottom",
-
- extended_valid_elements: "link[type|rel|href|charset],pre[name|class],iframe[src|width|height|name|align],+a[*]",
-
- valid_children : "+body[style]",
- relative_urls: false,
- remove_script_host: false,
- oninit : function () {
- // TODO: chrome bug
- window.onhashchange = admin.setCurByHash;
- if (typeof(conf.fun) === "function") {
- conf.fun();
- }
- }
- });
- } catch (e) {
- $("#tipMsg").text("TinyMCE load fail");
- }
- }
- },
-
- /*
- * @description ??????
- * @param {string} id ???id
- * @returns {string} ????
- */
- getContent: function (id) {
- var content = "";
- try {
- content = tinyMCE.get(id).getContent();
- } catch (e) {
- content = $("#" + id).val();
- }
- return content;
- },
-
- /*
- * @description ??????
- * @param {string} id ??? id
- * @param {string} content ??????
- */
- setContent: function (id, content) {
- try {
- if (tinyMCE.get(id)) {
- tinyMCE.get(id).setContent(content);
- } else {
- $("#" + id).val(content);
- }
- } catch (e) {
- $("#" + id).val(content);
- }
- }
- };