Changeset 1412


Ignore:
Timestamp:
02/22/18 08:45:18 (7 months ago)
Author:
gogo
Message:

FancySelects? and WebkitResize? had some problems with older browsers where the jQuery version fails to load. This fixes it (they won't do anything but they still allow Xinha to run).

Location:
trunk/plugins
Files:
2 edited

Legend:

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

    r1408 r1412  
    6464{ 
    6565    this.editor = editor; 
     66    this._isWorking = false; // Set true once everything is setup, or not if it fails (old browser) 
    6667} 
    6768 
     
    7273   
    7374  // Be sure we wait until jQuery is loaded 
    74   if(!(jQuery && jQuery.fn && jQuery.fn.select2 && jQuery(editor._htmlArea).find('.toolbarElement select').length)) 
     75  if(!(typeof jQuery != 'undefined' && jQuery && jQuery.fn && jQuery.fn.select2 && jQuery(editor._htmlArea).find('.toolbarElement select').length)) 
    7576  { 
    7677    var self = this; 
     
    99100  } 
    100101   
    101   jQuery(editor._htmlArea).find('.toolbarElement select').each(function(i,e){ 
    102     var txt = e.name; 
    103     var el  = e; 
    104      
    105     var width = 'resolve'; 
    106     if(typeof editor.config.FancySelects.widths[txt] != 'undefined') 
    107     { 
    108       width = editor.config.FancySelects.widths[txt]; 
    109     } 
    110      
    111     switch(txt) 
    112     { 
    113       case 'fontname': 
    114         jQuery(e).select2({dropdownAutoWidth: true, theme: 'default', templateResult: formatFontName, width: width}); 
    115         break; 
    116       case 'fontsize': 
    117         jQuery(e).select2({dropdownAutoWidth: true, theme: 'default', templateResult: formatFontSize, width: width}); 
    118         break; 
    119       default: 
    120         jQuery(e).select2({dropdownAutoWidth: true, theme: 'default', width: width}); 
    121     } 
    122      
    123     jQuery(e).on('select2:opening', function(){ 
    124       // IE11 needs this because opening the select2 de-selects the selected text 
    125       // so if we don't save and restore it nothing happens (except that the text is deselected) 
    126       // FF, Chrome and Edge are fine without this, but they also don't seem to care with it 
    127       // so I guess just do it across the board is safe enough 
    128       el._FancySelects_SavedSelection = editor.saveSelection(); 
     102  try 
     103  { 
     104    jQuery(editor._htmlArea).find('.toolbarElement select').each(function(i,e){ 
     105      var txt = e.name; 
     106      var el  = e; 
     107       
     108      var width = 'resolve'; 
     109      if(typeof editor.config.FancySelects.widths[txt] != 'undefined') 
     110      { 
     111        width = editor.config.FancySelects.widths[txt]; 
     112      } 
     113       
     114      switch(txt) 
     115      { 
     116        case 'fontname': 
     117          jQuery(e).select2({dropdownAutoWidth: true, theme: 'default', templateResult: formatFontName, width: width}); 
     118          break; 
     119        case 'fontsize': 
     120          jQuery(e).select2({dropdownAutoWidth: true, theme: 'default', templateResult: formatFontSize, width: width}); 
     121          break; 
     122        default: 
     123          jQuery(e).select2({dropdownAutoWidth: true, theme: 'default', width: width}); 
     124      } 
     125       
     126      jQuery(e).on('select2:opening', function(){ 
     127        // IE11 needs this because opening the select2 de-selects the selected text 
     128        // so if we don't save and restore it nothing happens (except that the text is deselected) 
     129        // FF, Chrome and Edge are fine without this, but they also don't seem to care with it 
     130        // so I guess just do it across the board is safe enough 
     131        el._FancySelects_SavedSelection = editor.saveSelection(); 
     132      }); 
     133       
     134      jQuery(e).on('select2:select', function(){ 
     135        if(el._FancySelects_SavedSelection)  
     136        { 
     137          editor.restoreSelection(el._FancySelects_SavedSelection); 
     138        } 
     139        el._FancySelects_SavedSelection = null; 
     140        editor._comboSelected(el, txt); 
     141      }); 
     142       
    129143    }); 
    130144     
    131     jQuery(e).on('select2:select', function(){ 
    132       if(el._FancySelects_SavedSelection)  
    133       { 
    134         editor.restoreSelection(el._FancySelects_SavedSelection); 
    135       } 
    136       el._FancySelects_SavedSelection = null; 
    137       editor._comboSelected(el, txt); 
    138     }); 
    139      
    140   }); 
     145    this._isWorking = true; 
     146  } 
     147  catch(e) 
     148  { 
     149    // Old browsers may fail and leave a partially constructed select2, remove that 
     150    // so just the original selects are left 
     151    var failed = Xinha.getElementsByClassName(editor._htmlArea,'select2-container'); 
     152    for(var i = 0; i < failed.length; i++) 
     153    { 
     154      failed[i].parentNode.removeChild(failed[i]); 
     155    } 
     156  } 
    141157}; 
    142158 
    143159FancySelects.prototype.onUpdateToolbar = function() 
    144160{ 
    145     var editor = this; 
     161    var editor = this.editor; 
     162     
     163    if(!this._isWorking) return false; 
    146164     
    147165    jQuery('.toolbarElement select').each(function(i,e){ 
    148166      jQuery(e).trigger('change'); 
    149167    }); 
    150      
    151168}; 
  • trunk/plugins/WebKitResize/WebKitResize.js

    r1388 r1412  
    7676  } 
    7777   
    78   if(Xinha.is_webkit) 
     78  try 
    7979  { 
    80     jQuery(this.editor._iframe).webkitimageresize(); 
     80    if(Xinha.is_webkit) 
     81    { 
     82      jQuery(this.editor._iframe).webkitimageresize(); 
     83    } 
     84     
     85    if(Xinha.is_webkit || Xinha.is_gecko && this.editor.config.WebKitResize.enableTABLEForGeckoAlso)  
     86    { 
     87      jQuery(this.editor._iframe).webkittableresize(); 
     88    } 
     89     
     90    if(Xinha.is_webkit || Xinha.is_gecko && this.editor.config.WebKitResize.enableTDForGeckoAlso)  
     91    { 
     92      jQuery(this.editor._iframe).webkittdresize(); 
     93    } 
    8194  } 
    82    
    83   if(Xinha.is_webkit || Xinha.is_gecko && this.editor.config.WebKitResize.enableTABLEForGeckoAlso)  
    84   { 
    85     jQuery(this.editor._iframe).webkittableresize(); 
    86   } 
    87    
    88   if(Xinha.is_webkit || Xinha.is_gecko && this.editor.config.WebKitResize.enableTDForGeckoAlso)  
    89   { 
    90     jQuery(this.editor._iframe).webkittdresize(); 
    91   } 
     95  catch(e) { } 
    9296} 
    9397 
Note: See TracChangeset for help on using the changeset viewer.