Ignore:
Timestamp:
02/22/18 08:45:18 (3 years 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).

File:
1 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}; 
Note: See TracChangeset for help on using the changeset viewer.