~minos-archive/minos/firefox-minos-settings

« back to all changes in this revision

Viewing changes to mozilla/firefox/h5xyzl6e.default/extensions/lazarus@interclue.com/chrome/content/clipboard.js

  • Committer: Javier Lopez
  • Date: 2015-07-08 01:10:19 UTC
  • Revision ID: git-v1:d8c3500bae00a8a67d74f8f96235ec11d75231be
rename mozilla-minos-settings -> firefox-minos-settings

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
Lazarus.Clipboard = {
3
 
 
4
 
    /**
5
 
    * copies text to the clipboard
6
 
    */
7
 
    setText: function(text){
8
 
        var clipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper); 
9
 
        clipboardHelper.copyString(text);
10
 
    },
11
 
    
12
 
    
13
 
    /**
14
 
    * 
15
 
    */
16
 
    setHTML: function(html){
17
 
    
18
 
        // generate the text version of the html
19
 
        var text = html.replace(/<(\/)?\w+[^>]*>/g, ' ').replace(/ +/g, ' ');
20
 
        
21
 
        //convert to unicode String
22
 
        var nsiStringText = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);  
23
 
        nsiStringText.data = text;
24
 
        
25
 
        //convert the HTML  
26
 
        var nsiStringHTML = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);  
27
 
        nsiStringHTML.data = html;           
28
 
 
29
 
        // add Unicode & HTML flavors to the transferable widget  
30
 
        var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);  
31
 
        trans.addDataFlavor("text/unicode");  
32
 
        trans.setTransferData("text/unicode", nsiStringText, text.length * 2); // *2 because it's unicode  
33
 
 
34
 
        trans.addDataFlavor("text/html");  
35
 
        trans.setTransferData("text/html", nsiStringHTML, html.length * 2); // *2 because it's unicode   
36
 
 
37
 
        // and copy to clipboard
38
 
        var clipboard = Components.classes["@mozilla.org/widget/clipboard;1"].getService(Components.interfaces.nsIClipboard);  
39
 
        clipboard.setData(trans, null, Components.interfaces.nsIClipboard.kGlobalClipboard);  
40
 
    }
41
 
}