2012-02-07 62 views
2

我有我的一些屏幕的執行內聯以下:我可以簡化我的javascript函數的調用方式嗎?

tinyMCE.init({ 
    // General options 
    mode : "specific_textareas", 
    editor_selector : "mceEditor", 
    theme: "advanced", 
    plugins: "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template", 

    // Theme options 
    theme_advanced_buttons1: "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect", 
    theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor", 
    theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen", 
    theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage", 
    theme_advanced_toolbar_location: "top", 
    theme_advanced_toolbar_align: "left", 
    theme_advanced_statusbar_location: "bottom", 
    theme_advanced_resizing: true, 

    // Skin options 
    skin: "o2k7", 
    skin_variant: "silver", 

    // Example content CSS (should be your site CSS) 
    content_css: "css/example.css", 

    // Drop lists for link/image/media/template dialogs 
    template_external_list_url: "js/template_list.js", 
    external_link_list_url: "js/link_list.js", 
    external_image_list_url: "js/image_list.js", 
    media_external_list_url: "js/media_list.js", 

    // Replace values for the template plugin 
    template_replace_values: { 
     username: "Some User", 
     staffid: "991234" 
    } 
}); 

我想這個移動到文件中,然後調用它。有沒有簡單的方法可以做到這一點?

+0

屬於上:codereview.stackexchange.com – 2012-02-07 15:08:21

回答

1

類同Xander的答案,但我只會存儲選項全球對象。

window.tinyMCEOptions = { 
    // General options 
    mode : "specific_textareas", 
    /* Your other options here. 
    * Store in your favorite .js file and link your page to it. 
    */ 
} 

然後調用tinyMCE.init這樣的:

tinyMCE.init(window.tinyMCEOptions); 

這樣做的好處是,它可以讓你輕鬆地更改選項:

window.tinyMCEOptions.content_css: 'css/different.css' 
tinyMCE.init(window.tinyMCEOptions); 
1

base.js

window.pageinit = function(){ 

    tinyMCE.init({ 

     /* ... your initialization code ... */ 

    }); 
} 

在引用base.js頁:

<script type="text/javascript"> 

    pageinit(); 

</script> 
+0

感謝。我從未見過「窗戶」。用過的。它有什麼作用? – 2012-02-07 15:14:14

+0

窗口是瀏覽器中的全局對象。這是'document'對象和其他全局對象被定義的地方...... – xandercoded 2012-02-07 15:15:12

相關問題