File: spellui.js

package info (click to toggle)
python-jtoolkit 0.7.8-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,436 kB
  • ctags: 2,536
  • sloc: python: 15,143; makefile: 20
file content (202 lines) | stat: -rwxr-xr-x 5,936 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
var slyrtop = 0;
var slyrleft = 0;

function findPosX(obj)
{
    var curleft = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj)
{
    var curtop = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}

function setLyr(obj,lyr)
{
    var newX = findPosX(obj);
    var newY = findPosY(obj);
    var newwidth = obj.offsetWidth;
    var newheight = obj.offsetHeight;
    lyr.style.top = newY + 'px';
    lyr.style.left = newX + 'px';
    slyrtop = newY;
    slyrleft = newX;
    lyr.style.width = newwidth;
    lyr.style.height = newheight;
    lyr.style.clip.height = newheight;
}

function findlayer(layername, searchdoc)
{
    if (searchdoc == undefined)
        searchdoc = document;
    if (searchdoc.getElementById)
        return searchdoc.getElementById(layername);
    else if (searchdoc.all)
        return searchdoc.all[layername];
    else if (searchdoc.layers)
        return searchdoc.layers[layername];
}

function ToggleSpellChecker(obj,button)
{
    var layername = obj.name + '.spellchecklayer';
    var lyr = findlayer(layername);
    var standby_url = lyr.getAttribute("standby_url");
    var target_url = lyr.getAttribute("target_url");

    //if we are starting a spellcheck
    if (button.value == "spellcheck")
    {
        lyr.style.visibility = 'visible';
        lyr.style.background = '#D5E6F7';
        lyr.style.border = 'solid black 1px';
        lyr.style.position = 'absolute';
        setLyr(obj,lyr);

        var framename = obj.name + '.spellcheckframe';
        var spellcheckframe = document.getElementById(framename);
        spellcheckframe.height = lyr.style.height;
        spellcheckframe.width = lyr.style.width;


        //set the form to a new action, then set it back
        theform = obj.form;
        var previousaction = theform.action;
        var previoustarget = theform.target;
        var previousmethod = theform.method;
        var previousencoding = theform.encoding;
        theform.method = 'POST';
        theform.encoding = 'multipart/form-data';
        theform.target = framename;

        //set the action for the form
        var fieldname = obj.name;
        var targeturl = target_url + '?spellcheckfield=' + fieldname;
        theform.action = targeturl;

        theform.submit();

        //return to previous values
        theform.method = previousmethod;
        theform.encoding = previousencoding;
        theform.target = previoustarget;
        theform.action = previousaction;
        
        //toggle the text on the button
        button.value = "resume editing";
    }
    else //if we are ending a spellcheck
    {
        //find the spellchecking iframe
        var framename = obj.name + '.spellcheckframe';
        var spellcheckframe = frames[framename];
        spellcheckframe.location.href = standby_url;
        //var spellcheckframe = document.getElementById(framename);
        //spellcheckframe.src = 'spellingstandby.htm';

        //extract only the text we want
        var newtext = "";
        var debug="";
        var childnodes = spellcheckframe.document.body.firstChild.childNodes;
        
        //Act according to the type of node. This is where we convert from html to plain text
        for(var i=0;i<childnodes.length;i++)
        {
            debug+=childnodes[i].nodeName;
            if (childnodes[i].nodeName == '#text')
            {
                newtext += childnodes[i].data;
            }
            if (childnodes[i].nodeName == 'A')
            {
                newtext += childnodes[i].innerHTML;
            }
        }
        
        obj.value = newtext;

        //hide the iframe
        lyr.style.visibility = 'hidden';

        //hide the suggestions layer in case it is shown
        var suggestionslayer = findlayer('suggestionslayer');
        suggestionslayer.style.visibility = 'hidden';

        //toggle the text on the button
        button.value = "spellcheck";
    }
};

function MakeSelection(anchor,wordindex,selection,layerid)
{
    var lyr = findlayer('suggestionslayer');
    lyr.style.visibility = 'hidden';
    lyr.innerHTML = "";

    //change the anchor
    lyr.obj.innerHTML = selection;
};

function ShowOptions(anchor,index)
{
    //show the suggestions for a word
    var lyr = findlayer('suggestionslayer', parent.document);

    lyr.style.background = '#D5E6F7';
    lyr.style.border = 'solid black 1px';
    lyr.style.position = 'absolute';
    lyr.style.height = 100;
    lyr.style.zindex = 1;
    lyr.style.overflow = 'scroll';
    lyr.style.visibility = 'visible';
    lyr.obj = anchor;
    setLyr(anchor,lyr);

    //we need to modify the position of the layer by the position of the iframe
    var iframe = window.frameElement;
    var modx = iframe.offsetParent.offsetLeft - document.body['scrollLeft'];
    var mody = iframe.offsetParent.offsetTop - document.body['scrollTop'];
    lyr.style.top = slyrtop + mody + 'px';
    lyr.style.left = slyrleft + modx + 'px';

    //modify the size of the layer
    lyr.style.width = anchor.offsetWidth + 50 + 'px';
    lyr.style.height = 100;
    lyr.style.clip.height = 80;

    //set the options
    innerhtml = "<pre>";
    for (i=0; i<wordlist[index][2].length; i++)
    {
        newword = wordlist[index][2][i];
        quotedword = "'" + newword.replace("'", "\\'") + "'";
        innerhtml +=  "<a href=javascript:MakeSelection(this,"+index+","+quotedword+",'suggestionslayer')>"+
                        wordlist[index][2][i] +
                      "</a>\n";
    }
    innerhtml += "</pre>";
    lyr.innerHTML = innerhtml;
};