~ubuntu-marketing/ubuntu-stats/devel

« back to all changes in this revision

Viewing changes to frontend/scripts/main.js

  • Committer: felipelerena at gmail
  • Date: 2007-06-27 00:03:18 UTC
  • Revision ID: felipelerena@gmail.com-20070627000318-xcotjcfhexwpxla1
AJAX UI changes (drag and drop support), some styles refactores, som Javascript optimized

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
var items = Array();
8
8
var once = true;
9
9
var first = true;
 
10
var pendingBox = Array();
 
11
 
10
12
function onLoads()
11
13
{
 
14
        
 
15
        createBoxList();
 
16
        addBoxes();
12
17
        getData(true);
 
18
        refreshMenu();
 
19
        initializeDragDrop();
13
20
        createWatcher(getData,63);
14
21
        createWatcher(boxQueue,4);
15
22
}
70
77
                        }
71
78
                );
72
79
}
 
80
/*
 
81
function getInitialDataForBox()
 
82
{
 
83
        var dir = "getData.php";
 
84
        var pars = "?first";
 
85
        
 
86
        var fetcher = new Ajax.Request
 
87
                (
 
88
                        dir,
 
89
                        {
 
90
                                method:'post',
 
91
                                parameters: pars, 
 
92
                                onComplete: addInitialDataForBox
 
93
                        }
 
94
                );
 
95
}*/
 
96
function isPending(id)
 
97
{
 
98
        for(i = 0; i < pendingBox.length; i++)
 
99
        {
 
100
                if(pendingBox[i] == id)
 
101
                {
 
102
                        //alert(pendingBox[i] + "  " + id);
 
103
                        return true;
 
104
                }
 
105
        }
 
106
        return false;
 
107
}/*
 
108
function addInitialDataForBox(req)
 
109
{
 
110
        var json = eval('('+req.responseText+')');
 
111
 
 
112
        for (i in json)
 
113
        {
 
114
                try
 
115
                {
 
116
                        if(isPending(json[i].id_box))
 
117
                        {
 
118
                                boxAdd(json[i].id_box,json[i].text,json[i].link,json[i].id_items,blink);
 
119
                                setLastItem(json[i].id_box,json[i].id_items);
 
120
                        }
 
121
                }
 
122
                catch(e)
 
123
                {
 
124
                        //alert(e)
 
125
                }
 
126
        }
 
127
        makeBoxesVisible();
 
128
        pendingBox = Array();
 
129
}*/
73
130
 
74
131
function addAndDisplay(req)
75
132
{
79
136
        
80
137
        for (i in json)
81
138
        {
82
 
                blink = !evaluateFirst(json[i].id_box);
83
 
                                
84
 
                if( (blink == false) )
 
139
                try
85
140
                {
86
 
                        boxAdd(json[i].id_box,json[i].text,json[i].link,json[i].id_items,blink);
87
 
                        setLastItem(json[i].id_box,json[i].id_items);
 
141
                        blink = !evaluateFirst(json[i].id_box);
 
142
                                        
 
143
                        if( (blink == false) )
 
144
                        {
 
145
                                boxAdd(json[i].id_box,json[i].text,json[i].link,json[i].id_items,blink);
 
146
                                setLastItem(json[i].id_box,json[i].id_items);
 
147
                        }
 
148
                        else
 
149
                        {
 
150
                                //$('box'+json[i].id_box).style.display = "";
 
151
                                boxEnQueue(json[i].id_box,json[i].text,json[i].link,json[i].id_items);
 
152
                        }
88
153
                }
89
 
                else
 
154
                catch(e)
90
155
                {
91
 
                        boxEnQueue(json[i].id_box,json[i].text,json[i].link,json[i].id_items);
 
156
                        /**/
92
157
                }
93
158
        }
94
 
}
95
 
 
 
159
        hideLoadingData();
 
160
        makeBoxesVisible();
 
161
}
 
162
function hideLoadingData()
 
163
{
 
164
        $('loadingData').style.display = "none";
 
165
}
96
166
function boxEnQueue(container,data,link,boxid)
97
167
{
98
168
        box = [container,data,link,boxid];
121
191
{
122
192
        items[idContainer] = idItem;
123
193
}
124
 
        
125
 
function boxAdd(container,data,link,boxid, blink)
126
 
{
127
 
        try{
128
 
        var container = $('c'+container);
129
 
        var newBox = document.createElement('div');
130
 
        
131
 
        var firstBox = primerHijo(container)
132
 
        
133
 
        newBox.id = boxid;
134
 
        
135
 
        a = document.createElement("a");
136
 
        a.href = link;
137
 
        a.target = "_blank";
138
 
        Element.update(a,data);
139
 
 
140
 
        
141
 
        newBox.style.marginBottom = "5px";
142
 
        newBox.appendChild(a);
143
 
        
144
 
        container.insertBefore(newBox,firstBox);
145
 
        
146
 
        if( container.childNodes.length > 5 )
147
 
        {
148
 
                container.removeChild(container.lastChild);
149
 
        }
150
 
        if(firstBox.id == '-1')
151
 
        {
152
 
                container.removeChild(firstBox);
153
 
        }
154
 
        
155
 
        if(blink)
156
 
        {
157
 
                new Effect.Highlight(newBox,{startcolor:'#ffff99', endcolor:'#ffffff'});
158
 
        }
159
 
        b = document.createElement("a");
160
 
        b.href = link;
161
 
        b.target = "_blank";
162
 
        Element.update(b,data);
163
 
        addLastEvent(container,b);
164
 
        }
165
 
        catch (e)
166
 
        {
167
 
                alert(e);
168
 
        }
169
 
}
170
194
 
171
195
function addLastEvent(container,link)
172
196
{