PageRenderTime 23ms CodeModel.GetById 16ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/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
Possible License(s): Apache-2.0, LGPL-2.1
  1/*
  2 * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
  3 *
  4 * Licensed under the Apache License, Version 2.0 (the "License");
  5 * you may not use this file except in compliance with the License.
  6 * You may obtain a copy of the License at
  7 *
  8 *     http://www.apache.org/licenses/LICENSE-2.0
  9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed under the License is distributed on an "AS IS" BASIS,
 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13 * See the License for the specific language governing permissions and
 14 * limitations under the License.
 15 */
 16/**
 17 * @fileoverview tinyMCE editor
 18 *
 19 * @author <a href="mailto:LLY219@gmail.com">Liyuan Li</a>
 20 * @version 1.0.0.5, Jun 19, 2012
 21 */
 22admin.editors.tinyMCE = {
 23    /*
 24     * @description ??????
 25     * @param conf ????????
 26     * @param conf.kind ?????
 27     * @param conf.id ??????? id
 28     * @param conf.fun ??????????????
 29     */
 30    init: function (conf) {
 31        var language = Label.localeString.substring(0, 2);
 32        if (language === "zh") {
 33            language = "zh-cn";
 34        }
 35        
 36        if (conf.kind && conf.kind === "simple") {
 37            try {
 38                tinyMCE.init({
 39                    // General options
 40                    language: language,
 41                    mode : "exact",
 42                    elements : conf.id,
 43                    theme : "advanced",
 44
 45                    // Theme options
 46                    theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,undo,redo,|,bullist,numlist",
 47                    theme_advanced_buttons2 : "",
 48                    theme_advanced_buttons3 : "",
 49                    theme_advanced_toolbar_location : "top",
 50                    theme_advanced_toolbar_align : "left",
 51                
 52                    valid_children : "+body[style]"
 53                });
 54            } catch (e) {
 55                $("#tipMsg").text("TinyMCE load fail");
 56            }
 57        } else {
 58            try {
 59                tinyMCE.init({
 60                    // General options
 61                    language: language,
 62                    mode : "exact",
 63                    elements : conf.id,
 64                    theme : "advanced",
 65                    plugins : "autosave,style,advhr,advimage,advlink,preview,inlinepopups,media,paste,syntaxhl,wordcount",
 66
 67                    // Theme options
 68                    theme_advanced_buttons1 : "formatselect,fontselect,fontsizeselect,|,bold,italic,underline,strikethrough,forecolor,|,advhr,blockquote,syntaxhl,",
 69                    theme_advanced_buttons2 : "undo,redo,|,bullist,numlist,outdent,indent,|,justifyleft,justifycenter,justifyright,justifyfull,|,pastetext,pasteword,|,link,unlink,image,iespell,media,|,cleanup,code,preview,",
 70                    theme_advanced_buttons3 : "",
 71                    theme_advanced_toolbar_location : "top",
 72                    theme_advanced_toolbar_align : "left",
 73                    theme_advanced_resizing : true,
 74                    theme_advanced_statusbar_location : "bottom",
 75                
 76                    extended_valid_elements: "link[type|rel|href|charset],pre[name|class],iframe[src|width|height|name|align],+a[*]",
 77
 78                    valid_children : "+body[style]",
 79                    relative_urls: false,
 80                    remove_script_host: false,
 81                    oninit : function () {
 82                        // TODO: chrome bug
 83                        window.onhashchange = admin.setCurByHash;
 84                        if (typeof(conf.fun) === "function") {
 85                            conf.fun();
 86                        }
 87                    }
 88                });
 89            } catch (e) {
 90                $("#tipMsg").text("TinyMCE load fail");
 91            }
 92        }
 93    },
 94    
 95    /*
 96     * @description ??????
 97     * @param {string} id ???id
 98     * @returns {string} ????
 99     */
100    getContent: function (id) {
101        var content = "";
102        try {
103            content = tinyMCE.get(id).getContent();
104        } catch (e) {
105            content = $("#" + id).val();
106        }
107        return content;
108    },
109    
110    /*
111     * @description ??????
112     * @param {string} id ??? id
113     * @param {string} content ??????
114     */
115    setContent: function (id, content) {
116        try {
117            if (tinyMCE.get(id)) {
118                tinyMCE.get(id).setContent(content);
119            } else {
120                $("#" + id).val(content);
121            }
122        } catch (e) {
123            $("#" + id).val(content);
124        }
125    }
126};