root/branches/release-36/mt-static/js/widget.js @ 2052

Revision 2052, 4.8 kB (checked in by fumiakiy, 19 months ago)

Integrated Widget Manager to the core. BugId:68750

Now a widgetset is another type of template. The widgets contained in a widgetset is stored in a meta field.

  • Property svn:keywords set to Id Date Author Revision
Line 
1function edit_different_widgetmanager( blog_id ) {
2    var current = getByID('current-widgetmanager').value;
3    window.location = '?__mode=manage&blog_id='+blog_id+'&widgetmanager='+current;
4}
5
6// -------------------------------------------------------------------
7// selectAllOptions(select_object)
8//  This function takes a select box and selects all options (in a
9//  multiple select object). This is used when passing values between
10//  two select boxes. Select all options in the right box before
11//  submitting the form so the values will be sent to the server.
12// -------------------------------------------------------------------
13function selectAllOptions(obj) {
14        if (!hasOptions(obj)) { return; }
15        for (var i=0; i<obj.options.length; i++) {
16                obj.options[i].selected = true;
17        }
18}
19
20// -------------------------------------------------------------------
21// hasOptions(obj)
22//  Utility function to determine if a select object has an options array
23// -------------------------------------------------------------------
24function hasOptions(obj) {
25        if (obj!=null && obj.options!=null) { return true; }
26        return false;
27}
28
29// -------------------------------------------------------------------
30// swapOptions(select_object,option1,option2)
31//  Swap positions of two options in a select list
32// -------------------------------------------------------------------
33function swapOptions(obj,i,j) {
34        var o = obj.options;
35        var i_selected = o[i].selected;
36        var j_selected = o[j].selected;
37        var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
38        var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
39        o[i] = temp2;
40        o[j] = temp;
41        o[i].selected = j_selected;
42        o[j].selected = i_selected;
43}
44
45// -------------------------------------------------------------------
46// moveOptionUp(select_object)
47//  Move selected option in a select list up one
48// -------------------------------------------------------------------
49function moveOptionUp(obj) {
50        if (!hasOptions(obj)) { return; }
51        var i;
52        for (i=0; i<obj.options.length; i++) {
53                if (obj.options[i].selected) {
54                        if (i != 0 && !obj.options[i-1].selected) {
55                                swapOptions(obj,i,i-1);
56                                obj.options[i-1].selected = true;
57                        }
58                }
59        }
60}
61
62// -------------------------------------------------------------------
63// moveOptionDown(select_object)
64//  Move selected option in a select list down one
65// -------------------------------------------------------------------
66function moveOptionDown(obj) {
67        if (!hasOptions(obj)) { return; }
68        var i;
69        for (i=obj.options.length-1; i>=0; i--) {
70                if (obj.options[i].selected) {
71                        if (i != (obj.options.length-1) && ! obj.options[i+1].selected) {
72                                swapOptions(obj,i,i+1);
73                                obj.options[i+1].selected = true;
74                        }
75                }
76        }
77}
78
79<!-- Original:  Phil Webb (phil@philwebb.com) -->
80<!-- Web Site:  http://www.philwebb.com -->
81
82<!-- This script and many more are available free online at -->
83<!-- The JavaScript Source!! http://javascript.internet.com -->
84
85function move(fbox, tbox) {
86        var arrFbox = new Array();
87        var arrTbox = new Array();
88        var arrLookup = new Array();
89        var i;
90        for (i = 0; i < tbox.options.length; i++) {
91                arrLookup[tbox.options[i].text] = tbox.options[i].value;
92                arrTbox[i] = tbox.options[i].text;
93        }
94        var fLength = 0;
95        var tLength = arrTbox.length;
96        for(i = 0; i < fbox.options.length; i++) {
97                arrLookup[fbox.options[i].text] = fbox.options[i].value;
98                if (fbox.options[i].selected && fbox.options[i].value != "") {
99                        arrTbox[tLength] = fbox.options[i].text;
100                        tLength++;
101                } else {
102                        arrFbox[fLength] = fbox.options[i].text;
103                        fLength++;
104                }
105        }
106        arrFbox.sort();
107        //arrTbox.sort();
108        fbox.length = 0;
109        tbox.length = 0;
110        var c;
111        for(c = 0; c < arrFbox.length; c++) {
112                var no = new Option();
113                no.value = arrLookup[arrFbox[c]];
114                no.text = arrFbox[c];
115                fbox[c] = no;
116        }
117        for(c = 0; c < arrTbox.length; c++) {
118                var no = new Option();
119                no.value = arrLookup[arrTbox[c]];
120                no.text = arrTbox[c];
121                tbox[c] = no;
122        }
123}
124
125function move_item(val, fbox, tbox) {
126        var arrFbox = new Array();
127        var arrTbox = new Array();
128        var arrLookup = new Array();
129        var i;
130        for (i = 0; i < tbox.options.length; i++) {
131                arrLookup[tbox.options[i].text] = tbox.options[i].value;
132                arrTbox[i] = tbox.options[i].text;
133        }
134        var fLength = 0;
135        var tLength = arrTbox.length;
136        for(i = 0; i < fbox.options.length; i++) {
137                arrLookup[fbox.options[i].text] = fbox.options[i].value;
138                if (fbox.options[i].value == val) {
139                        arrTbox[tLength] = fbox.options[i].text;
140                        tLength++;
141                } else {
142                        arrFbox[fLength] = fbox.options[i].text;
143                        fLength++;
144                }
145        }
146        arrFbox.sort();
147        arrTbox.sort();
148        fbox.length = 0;
149        tbox.length = 0;
150        var c;
151        for(c = 0; c < arrFbox.length; c++) {
152                var no = new Option();
153                no.value = arrLookup[arrFbox[c]];
154                no.text = arrFbox[c];
155                fbox[c] = no;
156        }
157        for(c = 0; c < arrTbox.length; c++) {
158                var no = new Option();
159                no.value = arrLookup[arrTbox[c]];
160                no.text = arrTbox[c];
161                tbox[c] = no;
162        }
163}
Note: See TracBrowser for help on using the browser.