2012-09-19 83 views
1

我正在開發一個nicEdit插件來上傳圖像以外的文件。爲此,我採用了nicUpload插件,並對其進行了調整。在nicEdit中選擇元素

正如您在下面的代碼中看到的,我首先插入一張圖片,然後嘗試將該圖片封裝在鏈接中,但它不起作用。

如果我刪除了//Insert the image部分,我可以包裝選定的文本,但我想創建圖像,然後選擇該圖像作爲要包裝的文本。

//Insert the image部分存在時,//Insert the link部分根本不起作用。

onUploaded:function(B){ 
     this.removePane(); 
     // Insert the image. 
     if(!this.im) { 
      var tmp = 'javascript:nicImTemp();'; 
      this.ne.nicCommand("insertImage",tmp); 
      this.im = this.findElm('IMG','src',tmp); 
     } 
     if(this.im) { 
      this.im.setAttributes({ 
       src : 'http://127.0.0.1/nicEditDev/src/nicFile/images/pdf.png', 
       alt : 'PDF' 
      }); 
     } 
     // Insert the link wrapping the image. 
     console.log(this.im); 
     var url=B.links.original; 
     if(!this.ln) { 
      var tmp = 'javascript:nicTemp();'; 
      this.ne.nicCommand("createlink",tmp); 
      this.ln = this.findElm('A','href',tmp); 
     } 
     if(this.ln) { 
      this.ln.setAttributes({ 
       href : url, 
       title : 'PDF', 
       innerHTML : this.im 
      }); 
     } 
    } 

回答

0

試試這個,它爲我工作:

onUploaded: function(a) { this.removePane(); var c = a.url; if (this.im) { this.im || (this.ne.selectedInstance.restoreRng(), this.ne.nicCommand("insertImage", c), this.im = this.findElm("IMG", "src", c)); var b = parseInt(this.ne.selectedInstance.elm.getStyle("width")); this.im && this.im.setAttributes({ src: c, width: b && a.width ? Math.min(b, a.width) : "", alt: a.alt }) } else { this.ln || (this.ne.selectedInstance.restoreRng(), this.ne.nicCommand("createlink", c), this.ln = this.findElm('A', 'href', c)); this.ln && this.ln.setAttributes({ href: c, title: 'PDF' }); } }