程序员的资源宝库

网站首页 > gitee 正文

ckeditor在图像属性加入浏览图片

sanyeah 2024-04-09 20:00:09 gitee 5 ℃ 0 评论

<!DOCTYPE html>
<!--
Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.md or http://ckeditor.com/license
-->
<html>
<head>
 <meta charset="GB2312">
 <title>jLogic-CKEditor</title>
 <script src="../ckeditor/ckeditor.js"></script>
 <link rel="stylesheet" href="../ckeditorCfg/jLogic-ckeditor.css" charset="GB2312">
 <script>
  function getData()
  {
   var editor = CKEDITOR.instances.editor1;
   return editor.getData();
  }
  
  
  function setData(value)
  {
   var editor = CKEDITOR.instances.editor1;
   editor.setData( value );
  }
  
  
  function insertText(value)
  {
   var editor = CKEDITOR.instances.editor1;
   editor.insertText( value );
  }
  
  
  function insertHtml(value)
  {
   var editor = CKEDITOR.instances.editor1;
   editor.insertHtml( value );
  // if ( editor.mode == 'wysiwyg' )
  //  editor.insertHtml( value );
  // else
  //  alert( 'You must be in WYSIWYG mode!' );
  }
 </script>
 
</head>
<body>
 <textarea class="ckeditor" id="editor1" name="editor1">
  {jLogic-TextArea}
 </textarea>
 <script type="text/javascript">
          var editor = CKEDITOR.replace('editor1', addUploadButton(this));
          editor.on('instanceReady', function(event){
   event.editor.getCommand('maximize').exec();
  });
          
           function addUploadButton(editor){
           CKEDITOR.on('dialogDefinition', function( ev ){
               var dialogName = ev.data.name;
               var dialogDefinition = ev.data.definition;
               if ( dialogName == 'image' ){
                   var infoTab = dialogDefinition.getContents( 'info' );
                   infoTab.add({
                       type : 'button',
                       id : 'upload_image',
                       align : 'center',
                       label : '添加图片',
                       onClick : function( evt ){
                           var thisDialog = this.getDialog();
                           var txtUrlObj = thisDialog.getContentElement('info', 'txtUrl');
                           var txtUrlId = txtUrlObj.getInputElement().$.id;
                           addUploadImage(txtUrlId);
                       }
                   }, 'browse');
               }
           });
        }

        function addUploadImage(theURLElementId){
         var obj = new Object();
       obj.name="";
         var imgUrl = window.showModalDialog("../ckeditor/samples/uploadsFiles.html",obj,"dialogWidth=400px;dialogHeight=200px");
        var urlObj = document.getElementById(theURLElementId);
         urlObj.value = imgUrl;
         urlObj.fireEvent("onchange");
        }
    </script>
 
</body>
</html>

uploadsFiles.html:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
<html>  
  <head>  
    <base href="<%=basePath%>">  
      
    <title></title>  
    <meta http-equiv="pragma" content="no-cache">  
    <meta http-equiv="cache-control" content="no-cache">  
    <meta http-equiv="expires" content="0">      
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
    <meta http-equiv="description" content="This is my page">  
    <!--  
    <link rel="stylesheet" type="text/css" href="styles.css">  
    -->  
  </head>  
    
  <body>  
    
 
        <input type="file" name="imgFile" id="fuPhoto" title="选择图片" />  
        <input type="submit" value="确 定" id="btnUpload" onclick="yes()"/>  
    
 
    <script type="text/javascript">  
      function yes()
       {
        
      //  alert(document.getElementById("fuPhoto").value);
        //window.location.href="<%=path %>/replacebyclass.html";
        window.returnValue=document.getElementById("fuPhoto").value;
        window.close();
        }
       
    </script>     
  </body>  
 </html>  

 

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表