PageRenderTime 43ms CodeModel.GetById 32ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/library/platform/uiIE6.py

http://pyjamas.googlecode.com/
Python | 129 lines | 127 code | 1 blank | 1 comment | 0 complexity | 63af2c1f2ef84289244bdd880962349f MD5 | raw file
  1class PopupPanel:
  2    
  3    # PopupImpl.onShow
  4    def onShowImpl(self, popup):
  5        JS("""
  6        var frame = $doc.createElement('iframe');
  7        frame.scrolling = 'no';
  8        frame.frameBorder = 0;
  9        frame.style.position = 'absolute';
 10        
 11        popup.__frame = frame;
 12        frame.__popup = popup;
 13        frame.style.setExpression('left', 'this.__popup.offsetLeft');
 14        frame.style.setExpression('top', 'this.__popup.offsetTop');
 15        frame.style.setExpression('width', 'this.__popup.offsetWidth');
 16        frame.style.setExpression('height', 'this.__popup.offsetHeight');
 17        popup.parentElement.insertBefore(frame, popup);
 18        """)
 19
 20    # PopupImpl.onHide
 21    def onHideImpl(self, popup):
 22        JS("""
 23        var frame = popup.__frame;
 24        frame.parentElement.removeChild(frame);
 25        popup.__frame = null;
 26        frame.__popup = null;
 27        """)
 28
 29
 30class TextBoxBase:
 31    def getCursorPos(self):
 32        JS("""
 33        try {
 34            var elem = this.getElement();
 35            var tr = elem.document.selection.createRange();
 36            if (tr.parentElement().uniqueID != elem.uniqueID)
 37                return -1;
 38            return -tr.move("character", -65535);
 39        }
 40        catch (e) {
 41            return 0;
 42        }
 43        """)
 44
 45    def getSelectionLength(self):
 46        JS("""
 47        try {
 48            var elem = this.getElement();
 49            var tr = elem.document.selection.createRange();
 50            if (tr.parentElement().uniqueID != elem.uniqueID)
 51                return 0;
 52            return tr.text.length;
 53        }
 54        catch (e) {
 55            return 0;
 56        }
 57        """)
 58
 59    def setSelectionRange(self, pos, length):
 60        JS("""
 61        try {
 62            var elem = this.getElement();
 63            var tr = elem.createTextRange();
 64            tr.collapse(true);
 65            tr.moveStart('character', pos);
 66            tr.moveEnd('character', length);
 67            tr.select();
 68        }
 69        catch (e) {
 70        }
 71        """)
 72
 73class TextArea:
 74    def getCursorPos(self):
 75        JS("""
 76        try {
 77            var elem = this.getElement();
 78            var tr = elem.document.selection.createRange();
 79            var tr2 = tr.duplicate();
 80            tr2.moveToElementText(elem);
 81            tr.setEndPoint('EndToStart', tr2);
 82            return tr.text.length;
 83        }
 84        catch (e) {
 85            return 0;
 86        }
 87        """)
 88
 89
 90class FormPanel:
 91    def getTextContents(self, iframe):
 92        JS("""
 93        try {
 94            if (!iframe.contentWindow.document)
 95                return null;
 96        
 97            return iframe.contentWindow.document.body.innerText;
 98        } catch (e) {
 99            return null;
100        }
101        """)
102
103    def hookEvents(self, iframe, form, listener):
104        JS("""
105        if (iframe) {
106            iframe.onreadystatechange = function() {
107                if (!iframe.__formAction)
108                    return;
109        
110                if (iframe.readyState == 'complete') {
111                    listener.onFrameLoad();
112                }
113            };
114        }
115
116        form.onsubmit = function() {
117            if (iframe)
118                iframe.__formAction = form.action;
119            return listener.onFormSubmit();
120        };
121        """)
122
123    def unhookEvents(self, iframe, form):
124        JS("""
125        if (iframe)
126            iframe.onreadystatechange = null;
127        form.onsubmit = null;
128        """)
129