Changeset 519

Show
Ignore:
Timestamp:
08/09/08 19:30:53 (3 months ago)
Author:
s.lewis
Message:

Added the selection caching logic to the SAPI

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/scott/0.6-a4/js/plugins/sapi/sapi.js

    r506 r519  
    2828            'H5', 'H6', 'BLOCKQUOTE' 
    2929        ], 
     30         
     31        // Cache for SAPI-sepecific data 
     32         
     33        cache: {}, 
    3034         
    3135        // Triggers is an array of UI events to listen for 
     
    217221    }; 
    218222     
     223    sapi.prototype.cacheSelection = function() { 
     224        var w = this.parent._iframe.contentWindow; 
     225        var d = this.parent._doc; 
     226        if (w.getSelection) { 
     227            var selection = w.getSelection(); 
     228            if (selection.rangeCount > 0) { 
     229              var selectedRange = selection.getRangeAt(0); 
     230              w._selection = selectedRange.cloneRange(); 
     231            } 
     232            else { 
     233              return null; 
     234            } 
     235          } 
     236          else if (d.selection) { 
     237            var selection = d.selection; 
     238            if (selection.type.toLowerCase() == 'text') { 
     239              w._selection = selection.createRange().getBookmark(); 
     240            } 
     241            else { 
     242              w._selection = null; 
     243            } 
     244          } 
     245          else { 
     246            w._selection = null; 
     247        } 
     248    }; 
     249     
     250    sapi.prototype.restoreSelection = function(index) { 
     251        var w = this.parent._iframe.contentWindow; 
     252        var d = this.parent._doc; 
     253        try {jQuery(d).focus();} catch(e) {} 
     254        if (w._selection) { 
     255            if (w.getSelection) { 
     256              var selection = w.getSelection(); 
     257              selection.removeAllRanges(); 
     258              selection.addRange(w._selection); 
     259              w._selection = null; 
     260            } 
     261            else if (d.selection && d.body.createTextRange) { 
     262              var range = d.body.createTextRange(); 
     263              range.moveToBookmark(w._selection); 
     264              range.select(); 
     265              w._selection = null; 
     266            } 
     267        } 
     268    }; 
     269     
    219270    sapi.prototype.getKeyBoardEvent = function () { 
    220271        return null;