Ignore:
Timestamp:
11/10/09 09:21:50 (10 years ago)
Author:
gogo
Message:

Ticket #1093
Ticket #1377

Rewrite the InsertSmiley? plugin. Remains compatible with ray's changes in r904 if people have made a specific configuration.

Location:
trunk/plugins/InsertSmiley
Files:
4 added
1 deleted
2 edited
8 copied

Legend:

Unmodified
Added
Removed
  • trunk/plugins/InsertSmiley/InsertSmiley.js

    r1067 r1224  
    22 Insert Smiley Plugin for Xinha 
    33 ----------------------------------------- 
    4  author: Ki Master George 
    5  e-mail: kimastergeorge@gmail.com 
     4 original author: Ki Master George (kimastergeorge@gmail.com) 
     5 rewritten: James Sleeman (james@gogo.co.nz) 
    66\*---------------------------------------*/ 
    77 
     8InsertSmiley._pluginInfo = { 
     9  name          : "InsertSmiley", 
     10  version       : "2.0", 
     11  developer     : "V 1.0 Ki Master George, V2.0 James Sleeman", 
     12  developer_url : "http://www.gogo.co.nz/", 
     13  c_owner       : "Ki Master George, James Sleeman", 
     14  sponsor       : "Gogo Internet Services", 
     15  sponsor_url   : "http://www.gogo.co.nz/", 
     16  license       : "htmlArea" 
     17}; 
     18 
     19/** To configure the InsertSmiley plugin. 
     20 * 
     21 * Set xinha_config.InsertSmiley.smileys to EITHER 
     22 * 
     23 *  * A URL to a file called smileys.js, which follows the format 
     24 *    you can view in smileys/smileys.js 
     25 * 
     26 *  * A URL to a file called smileys.php (or whatever other language) 
     27 *    which outputs a file in the same way as smileys/smileys.php 
     28 * 
     29 *  * A javascript the same as you will find in smileys/smileys.js 
     30 * 
     31 *  By defaut the static smileys/smileys.js file is used, you may  
     32 *  wish to set this like so 
     33 * 
     34 *  xinha_config.InsertSmiley.smileys = _editor_url+'/plugins/InsertSmiley/smileys/smileys.php'; 
     35 *  
     36 *  And then you can add new smileys just by dumping all the images into the 
     37 *      /xinha/plugins/InsertSmiley/smileys/ 
     38 *  folder and they will automatically be made available. 
     39 *  
     40 */ 
     41  
     42Xinha.Config.prototype.InsertSmiley=  { 
     43  smileys : ''  
     44}; 
     45 
     46Xinha.loadStyle('dialog.css', 'InsertSmiley'); 
     47 
    848function InsertSmiley(editor) { 
    9   this.editor = editor; 
     49  this.editor  = editor; 
     50  this.smileys = false; 
     51  this.dialog  = false; 
     52    
    1053  var cfg = editor.config; 
    11   var self = this; 
    12  
     54  var self = this;   
     55   
    1356  // register the toolbar buttons provided by this plugin 
    1457  cfg.registerButton({ 
     
    2164               } 
    2265  }); 
     66   
    2367  cfg.addToolbarElement("insertsmiley", "inserthorizontalrule", 1); 
    2468} 
    2569 
    26 InsertSmiley._pluginInfo = { 
    27   name          : "InsertSmiley", 
    28   version       : "1.0", 
    29   developer     : "Ki Master George", 
    30   developer_url : "http://kimastergeorge.i4host.com/", 
    31   c_owner       : "Ki Master George", 
    32   sponsor       : "Ki Master George", 
    33   sponsor_url   : "http://kimastergeorge.i4host.com/", 
    34   license       : "htmlArea" 
     70InsertSmiley.prototype.onGenerateOnce = function() 
     71{ 
     72  // Back compat for ray's smiley config in changeset:904 ( ticket:1093 ) 
     73  if(this.editor.config.InsertSmiley.smileyURL) 
     74  { 
     75    var smileys = [ ]; 
     76    var smileylist = Xinha._geturlcontent(Xinha.getPluginDir("InsertSmiley") + '/smileys.txt'); 
     77    var smileyURL = this.editor.config.InsertSmiley.smileyURL; 
     78     
     79    smileylist = smileylist.match(/^.+$/mg); 
     80    for(var i = 0; i < smileylist.length; i++) 
     81    { 
     82      smileys[smileys.length] = { title: smileylist[i],  src:   smileyURL + encodeURIComponent(smileylist[i]) };                    
     83    } 
     84    this.editor.config.InsertSmiley.smileys = smileys; 
     85  } 
     86   
     87   
     88  this.loadAssets(); 
    3589}; 
    3690 
     
    3892  return Xinha._lc(string, 'InsertSmiley'); 
    3993}; 
    40 Xinha.Config.prototype.InsertSmiley=  { 
    41   smileyURL : "http://www.x-webservice.net/storage/xinha/plugins/InsertSmiley/" 
     94 
     95/** Load the dialog and js files. 
     96 *  
     97 */ 
     98  
     99InsertSmiley.prototype.loadAssets = function() 
     100{ 
     101  var self = this; 
     102  if (self.loading) return; 
     103   
     104  if(typeof this.editor.config.InsertSmiley.smileys != 'string') 
     105  { 
     106    // Must be a smiley definition itself 
     107    this.smileys     = this.editor.config.InsertSmiley.smileys; 
     108    this.smiley_base = _editor_url; // Doesn't make a lot of sense, we assume the smileys will have absolute paths anyway 
     109  } 
     110  else 
     111  { 
     112    var smileys_def =  
     113      this.editor.config.InsertSmiley.smileys  
     114        ? this.editor.config.InsertSmiley.smileys // URL to the smileys.js file, or somethign that creates it 
     115        : (Xinha.getPluginDir("InsertSmiley") + '/smileys/smileys.js'); // our own default one 
     116         
     117    Xinha._getback(  
     118      smileys_def,  
     119      function(sm) { self.smileys = eval(sm); self.smileys_base = smileys_def.replace(/\/[^\/]+(\?.*)?$/, '/'); }  
     120    );     
     121  } 
     122     
     123  Xinha._getback( Xinha.getPluginDir("InsertSmiley") + '/dialog.html', function(html) { self.makeDialog(html); } ); 
     124} 
     125 
     126/** Make the dialog 
     127 * 
     128 *  @note It is really important that this happens throuh the onGenerateOnce event 
     129 *   (in this case it goes onGenerateOnce -> loadAssets -> makeDialog) 
     130 *  because otherwise creating the dialog can fail in mysterious ways (silent  
     131 *  javascript exceptions in Gecko etc). 
     132 */ 
     133  
     134InsertSmiley.prototype.makeDialog = function(html) 
     135{ 
     136  var self = this; 
     137   
     138  // We can not make the dialog until the smileys are loaded, so wait a bit. 
     139  if(!this.smileys)  
     140  {   
     141    window.setTimeout(function() { self.makeDialog(html); }, 1000);  
     142    return;  
     143  } 
     144   
     145  var dialog = new Xinha.Dialog(this.editor, html, 'InsertSmiley', {width:155, height:100}, {modal:false}); 
     146     
     147  var src; 
     148  var s; 
     149  var a; 
     150   
     151  for(var i = 0; i < this.smileys.length; i++) 
     152  { 
     153    src = this.smileys[i].src.match(/^(([a-zA-Z]+:\/\/)|\/)/) ?  
     154          this.smileys[i].src : this.smileys_base + this.smileys[i].src; 
     155    s = document.createElement('img'); 
     156    s.src = src; 
     157    s.alt = dialog._lc(this.smileys[i].title);  
     158    s.style.border = 'none'; 
     159     
     160    a = document.createElement('a'); 
     161    a.href= 'javascript:void(0);'; 
     162    a.smiley_src = src; 
     163    a.title = dialog._lc(this.smileys[i].title); 
     164     
     165    // This is where we insert the smiley into the HTML 
     166    Xinha.addDom0Event(a, 'click', function(ev) { self.editor.insertHTML('<img src="'+this.smiley_src+'" alt="'+this.title+'" />'); Xinha._stopEvent(window.event ? event : ev); return false; }); 
     167     
     168    a.appendChild(s); 
     169    dialog.getElementById('smileys').appendChild(a); 
     170     
     171    a = null; s = null; src = null; 
     172  } 
     173   
     174  this.dialog = dialog; 
     175  return true; 
     176} 
     177 
     178/** Show the dialog. 
     179 */ 
     180  
     181InsertSmiley.prototype.buttonPress = function(editor) { 
     182  if(this.dialog)  
     183  { 
     184    this.dialog.show();     
     185  } 
     186  else 
     187  {  
     188    // Should put something here! 
     189  } 
     190  return; 
    42191}; 
    43  
    44 InsertSmiley.prototype.buttonPress = function(editor) { 
    45   var self = this; 
    46   var sel = editor.getSelectedHTML().replace(/(<[^>]*>|&nbsp;|\n|\r)/g,""); 
    47   var param = {}; 
    48   param.editor = editor; 
    49   editor._popupDialog("plugin://InsertSmiley/insertsmiley", function(param) { 
    50     editor.insertHTML("<img src=\"" + editor.config.InsertSmiley.smileyURL + param.smileyfile + "\" alt=\"Smiley\" />"); 
    51   }, param); 
    52 }; 
  • trunk/plugins/InsertSmiley/README.txt

    r904 r1224  
    1 By default the smileys are hosted on an external server. If you would like to put them on your own server, you can download a zip file from here: 
    2 http://www.x-webservice.net/storage/xinha/plugins/InsertSmiley/smileys.zip 
     1A small number of smileys are included in this release. 
    32 
    4 1. Extract the file to your server 
    5 2. Change xinha_config.InsertSmiley.smileyURL to the appropriate path (with trailing slash), e.g. 
    6     
    7    xinha_config.InsertSmiley.smileyURL = "/smileys/"; 
    8     
    9  You can also reduce/expand/replace the list of smileys with your own files by editing the file smileys.txt in the plugins's folder. 
     3To add more smileys,  
     4 
     5  1. Dump as many as you would like as image files into the smileys folder (gif, jpg, png). 
     6  2. EITHER: 
     7    a. Edit smileys/smileys.js as appropriate, or; 
     8    b. Set this Xinha configuration (if your server handles PHP ok) 
     9        
     10        xinha_config.InsertSmiley.smileys = _editor_url+'/plugins/InsertSmiley/smileys/smileys.php'; 
     11        
     12       it will automatically pickup the new smileys without you needing to edit the js file. 
     13       
Note: See TracChangeset for help on using the changeset viewer.