请选择 进入手机版 | 继续访问电脑版
查看: 195|回复: 0

[.NET开发] ASP 编写 TinyMCE编辑器 上传组件

3万

主题

3万

帖子

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
100197
发表于 2015-11-23 17:52:13
asp 页面如何调用TinyMC

asp 无组件上传类

点击查看,学会后,下面教你如何做个TinyMCE 上传的小插件,非常实用哦
  1. /**
  2. * $Id: editor_plugin.js 201 2008-02-2 Guangzhou $
  3. */
  4. (function() {
  5. tinymce.PluginManager.requireLangPack('upload_image');
  6. tinymce.create('tinymce.plugins.UploadImagePlugin', {
  7. createControl: function(n, cm) {
  8. switch (n) {
  9. case 'upload_image':
  10. var mlb = cm.createListBox('upload_image', {
  11. title : 'upload.title',
  12. onselect : function(v) {
  13. var arr = document.cookie.match(new RegExp("(^| )SID=([^;]*)(;|$)"));
  14. var site = (arr != null)?unescape(arr[2]):null;
  15. if(v=='insert')
  16. tinyMCE.activeEditor.execCommand('mceImage', true);
  17. else if(v=='upload'){
  18. var url = '/mceUpload.asp';
  19. tinyMCE.activeEditor.windowManager.open({file:url,width:400,height:230,inline:1});
  20. }}
  21. });
  22. // Add some values to the list box
  23. mlb.add('upload.upload_image', 'upload');
  24. mlb.add('upload.insert_image', 'insert');
  25. // Return the new listbox instance
  26. return mlb;
  27. }
  28. return null;
  29. },
  30. getInfo : function() {
  31. return {
  32. longname : 'Upload Image plugin',
  33. author : 'Winter Lau',
  34. authorurl : 'http://www.oschina.net/',
  35. version : "1.0"
  36. };
  37. }
  38. });
  39. // Register plugin
  40. tinymce.PluginManager.add('upload_image', tinymce.plugins.UploadImagePlugin);
  41. })();
复制代码
  1. tinyMCE.addI18n({en:{
  2. upload:{
  3. title: 'Insert Image',
  4. upload_image : 'Upload Image',
  5. insert_image : 'Insert Image'
  6. }}});
复制代码
  1. sub tinymce(textarea_id, buttons1, buttons2)
  2. response.write ("<script type='text/javascript' src='/scripts/tinymce_339/tiny_mce.js'></script>")
  3. response.write ("<script type='text/javascript'>tinyMCE.init({content_css : '/css/editor_content.css',language : 'zh',mode : 'exact',elements : '"&textarea_id&"',theme : 'advanced',plugins : 'safari,emotions,media,advimage,inlinepopups,noneditable,upload_image',relative_urls : false,remove_script_host : false,button_tile_map : true,invalid_elements : 'script,iframe',theme_advanced_buttons1 : '"&buttons1&"',theme_advanced_buttons2 : '"&buttons2&"',theme_advanced_buttons3 : '',theme_advanced_toolbar_location : 'top',theme_advanced_toolbar_align : 'left',theme_advanced_path_location : 'none',theme_advanced_statusbar_location: 'none',ask : false,tab_focus : ':prev,:next'});tinyMCE.baseURL = '/scripts/tinymce_339';</script>")
  4. end sub
复制代码
  1. <form action="UploadImages.asp" name="AddForm" id="AddForm" method="post">
  2. <table cellspacing="0" cellpadding="1" border="0" class="form_table" width="100%">
  3. <tr><th nowrap="nowrap">标题:</th><td><input name="etitle" size="30" type="text" value="" /></td></tr>
  4. <tr><th nowrap="nowrap">内容:</th><td><textarea name="econtent" id="f_content" style="width:100%;height:420px;">
  5. </table>
  6. <div class="form_submit"><input name="commit" type="submit" value="提交" /></div>
  7. </form>
  8. <%
  9. tinymce "f_content","bold,italic,underline,strikethrough,forecolor,backcolor,separator,justifyleft,justifycenter,justifyright,blockquote,separator,bullist,numlist,separator,undo,redo,separator,link,unlink,hr,media,emotions,separator,fontselect,fontsizeselect,upload_image",""
  10. %>
复制代码
  1. <!--#include file="upload_class.asp"-->
  2. <%
  3. Dim Upload,path,tempCls
  4. set Upload=new AnUpLoad
  5. Upload.SingleSize=1024*1024*1024
  6. Upload.MaxSize=1024*1024*1024
  7. Upload.Exe="jpg|gif|bmp|png"
  8. Upload.Charset="utf-8"
  9. Upload.openProcesser=false
  10. Upload.GetData()
  11. if Upload.ErrorID>0 then
  12. 'response.write Upload.Description
  13. else
  14. dim said,stitle,scontent
  15. if Upload.files(-1).count>0 then
  16. path=server.mappath("/uploads")&"/tinymce/"&Year(date())&"/"&Month(date())&"/"&Day(date())&"/"&uid&""
  17. set tempCls=Upload.files("eimage")
  18. tempCls.SaveToFile path,0
  19. simage_name=tempCls.FileName
  20. simage_path="/uploads/tinymce/"&Year(date())&"/"&Month(date())&"/"&Day(date())&"/"&uid&"/"
  21. 'response.write "文件:" & tempCls.FileName & "上传完毕,大小为" & Upload.getsize(tempCls.Size) & ";原文件名" & tempCls.LocalName & "!<br />"
  22. simage_url=simage_path & simage_name
  23. 'response.write simage_url
  24. set tempCls=nothing
  25. %>
  26. <script type="text/javascript" src="/styles/scripts/tinymce_339/tiny_mce_popup.js"></script>
  27. <script>
  28. <%if simage_url<>"" then%>
  29. var html = '<img src="<%=simage_url%>" border="0"/>';
  30. tinyMCE.execCommand('mceInsertContent', false, html);
  31. tinyMCEPopup.close();
  32. <%end if%>
  33. </script>
  34. <%
  35. end if
  36. end if
  37. set Upload=nothing
  38. %>
复制代码


回复

使用道具 举报