source: main/branches/64_bit_Greenstone/greenstone3/web/interfaces/default-client-xslt/js/ygDDPlayer.js@ 24007

Last change on this file since 24007 was 24007, checked in by sjm84, 13 years ago

Updating this branch to match the latest Greenstone3 changes

File size: 11.2 KB
Line 
1/* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
2
3function ygDDStack(id, sGroup) {
4 if (id) {
5 this.init(id, sGroup);
6 this.initFrame();
7 }
8}
9
10ygDDStack.prototype = new YAHOO.util.DDTarget();
11
12ygDDPlayer.TYPE = "ygDDPlayer";
13
14/**
15 * @class a YAHOO.util.DDFramed implementation. During the drag over event, the
16 * dragged element is inserted before the dragged-over element.
17 *
18 * @extends YAHOO.util.DDProxy
19 * @constructor
20 * @param {String} id the id of the linked element
21 * @param {String} sGroup the group of related DragDrop objects
22 */
23function ygDDPlayer(id, sGroup,bl) {
24 this.initPlayer(id, sGroup);
25 this.berryList = bl;
26
27}
28
29ygDDPlayer.prototype = new YAHOO.util.DDProxy();
30
31ygDDPlayer.prototype.berryList = new Array();
32
33ygDDPlayer.prototype.initPlayer = function(id, sGroup) {
34 if (!id) { return; }
35
36 this.init(id, sGroup);
37 this.initFrame();
38 var s = this.getDragEl().style;
39 s.borderColor = "transparent";
40 // s.backgroundColor = "#cccccc";
41 s.opacity = 0.76;
42 s.filter = "alpha(opacity=76)";
43
44 // specify that this is not currently a drop target
45 this.isTarget = false;
46
47 this.originalStyles = [];
48
49 this.type = ygDDPlayer.TYPE;
50 this.slot = null;
51 this.startPos = YAHOO.util.Dom.getXY( this.getEl() );
52
53}
54
55ygDDPlayer.prototype.startDrag = function(x, y) {
56
57 var dragEl = this.getDragEl();
58 var clickEl = this.getEl();
59
60 dragEl.innerHTML = clickEl.innerHTML;
61 //dragEl.className = clickEl.className;
62 //dragEl.style.color = clickEl.style.color;
63 //dragEl.style.backgroundColor = clickEl.style.backgroundColor;
64 //dragEl.style.visibility = clickEl.style.visibility;
65
66 while (dragEl.hasChildNodes()) {
67 dragEl.removeChild(dragEl.firstChild);
68 }
69
70 var img = document.createElement('img');
71 img.src = 'interfaces/default/images/berry3.png';
72 img.height = 15;
73 img.width = 15;
74 img.border = 0;
75 dragEl.appendChild(img);
76
77 var added = true;
78
79 var s = clickEl.style;
80 s.opacity = .1;
81 s.filter = "alpha(opacity=10)";
82
83 var targets = YAHOO.util.DDM.getRelated(this, true);
84
85 for (var i=0; i<targets.length; i++) {
86
87 var targetEl = this.getTargetDomRef(targets[i]);
88
89 if (!this.originalStyles[targetEl.id]) {
90 this.originalStyles[targetEl.id] = targetEl.className;
91 }
92
93 targetEl.className = "target";
94 }
95};
96
97ygDDPlayer.prototype.getTargetDomRef = function(oDD) {
98 if (oDD.player) {
99 return oDD.player.getEl();
100 } else {
101 return oDD.getEl();
102 }
103};
104
105ygDDPlayer.prototype.endDrag = function(e) {
106 // reset the linked element styles
107 var s = this.getEl().style;
108 s.opacity = 1;
109 s.filter = "alpha(opacity=100)";
110
111 this.resetTargets();
112};
113
114ygDDPlayer.prototype.resetTargets = function() {
115
116 // reset the target styles
117 var targets = YAHOO.util.DDM.getRelated(this, true);
118 for (var i=0; i<targets.length; i++) {
119 var targetEl = this.getTargetDomRef(targets[i]);
120 var oldStyle = this.originalStyles[targetEl.id];
121 if (oldStyle) {
122 targetEl.className = oldStyle;
123 }
124 }
125};
126
127var request_type = "GET";
128var addurlPath ="?a=pr&rt=r&ro=1&s=AddItem&c=&s1.id=2&o=XML&s1.item=";
129var delurlPath ="?a=pr&rt=r&ro=1&s=DeleteItem&c=&o=XML&s1.item=";
130var postdata = null;
131
132ygDDPlayer.prototype.onDragDrop = function(e, id) {
133 // get the drag and drop object that was targeted
134 var oDD;
135 var player = this;
136
137 if ("string" == typeof id) {
138 oDD = YAHOO.util.DDM.getDDById(id);
139 } else {
140 oDD = YAHOO.util.DDM.getBestMatch(id);
141 }
142
143
144 var el = this.getEl();
145
146 // check if the slot has a player in it already
147 if (oDD.player) {
148 // check if the dragged player was already in a slot
149 if (this.slot) {
150 // check to see if the player that is already in the
151 // slot can go to the slot the dragged player is in
152 // YAHOO.util.DDM.isLegalTarget is a new method
153 if ( YAHOO.util.DDM.isLegalTarget(oDD.player, this.slot) ) {
154 YAHOO.util.DDM.moveToEl(oDD.player.getEl(), el);
155 this.slot.player = oDD.player;
156 oDD.player.slot = this.slot;
157 } else {
158 YAHOO.util.Dom.setXY(oDD.player.getEl(), oDD.player.startPos);
159 this.slot.player = null;
160 oDD.player.slot = null
161 }
162 } else {
163 // the player in the slot will be moved to the dragged
164 // players start position
165 //oDD.player.slot = null;
166 //YAHOO.util.DDM.moveToEl(oDD.player.getEl(), el);
167 }
168 }else {
169 // Move the player into the emply slot
170 // I may be moving off a slot so I need to clear the player ref
171 if (this.slot) {
172 this.slot.player = null;
173 }
174 }
175
176 var addurl = addurlPath + el.id;
177 var addSuccess = function(o){
178 var text = o.responseText;
179 var result = o.responseXML;
180 var items = result.getElementsByTagName('item');
181 if (items.length > 0){
182 var item = items[0];
183 var berrybasket = YAHOO.util.Dom.get('berrybasket');
184 var berries = YAHOO.util.Dom.get('berries');
185 player.berryList[player.berryList.length]= item;
186
187 var itemID = item.getAttribute('collection')+":"+item.getAttribute('name');
188 var parent =el.parentNode;
189 parent.removeChild(el);
190
191 if (parent !=null && parent.id == "documentberries"){
192 var root = YAHOO.util.Dom.get(itemID+":root");
193 var section = YAHOO.util.Dom.get(itemID+":section");
194 if(root!=null && root.id.indexOf(itemID) !=-1){
195 parent.removeChild(root);
196 }
197
198 if(section!=null && section.id.indexOf(itemID) !=-1){
199 parent.removeChild(section);
200 }
201 }
202
203
204 if (!YAHOO.util.Dom.get('hideview') && player.berryList.length <13){
205
206 while (berries.hasChildNodes()) {
207 berries.removeChild(berries.firstChild);
208 }
209
210 for (var i =0; i < player.berryList.length; i++ ){
211 var img = document.createElement('img');
212 img.src = 'interfaces/default/images/berry3.png';
213 img.height = 15;
214 img.width = 15;
215 img.border = 0;
216 berries.appendChild(img);
217 }
218
219 }
220 else{
221
222
223 if (YAHOO.util.Dom.get('hideview')){
224
225 var berryBasket = YAHOO.util.Dom.get('berrybasket');
226 var berries = YAHOO.util.Dom.get('berries');
227 var doclist = YAHOO.util.Dom.get('doclist');
228 var tid = el.id;
229 var berryItem;
230 var berryElement = document.createElement('li');
231 for (var i in player.berryList){
232 berryItem = player.berryList[i];
233 var id = berryItem.getAttribute('collection')+":"+berryItem.getAttribute('name');
234 if (id == tid){
235 var title = berryItem.getAttribute('title');
236 var root_title = berryItem.getAttribute('root_title');
237 if (root_title != ""){
238 root_title +=":";
239 }
240
241 title = root_title+title;
242 if (title.length > 50){
243 title = title.substring(0,20)+" ... "+title.substr(title.length-35,35);
244 }
245
246 berryElement.appendChild(document.createTextNode(title));
247 berryElement.setAttribute("class","berryitem");
248 doclist.appendChild(berryElement);
249 var heightStr = berryBasket.style.height+"";
250 var height =parseInt(heightStr.substring(0,heightStr.length-2)) +18;
251 berryBasket.style.height = height;
252 berries.style.height = height;
253 break;
254 }
255 }
256 }
257
258 }
259 }
260
261
262
263 }
264
265 var addFailure = function(o){ }
266
267
268 var addcallback = {
269 success:addSuccess,
270 failure:addFailure,
271 argument:player
272 }
273
274
275 var delurl = delurlPath + el.id;
276 var delSuccess = function(o){
277 var result = o.responseXML;
278 var parent =el.parentNode;
279 if (parent == null) return;
280
281 parent.removeChild(el);
282
283 for (var i in player.berryList){
284 var berry = player.berryList[i];
285
286 var id = berry['collection']+":"+berry['name'];
287
288 if (id == el.id){
289 player.berryList.splice(i,1);
290
291 break;
292 }
293
294 }
295
296 if (!parent.hasChildNodes()){
297 var content = YAHOO.util.Dom.get('content');
298 while (content.hasChildNodes()) {
299 content.removeChild(content.firstChild);
300 }
301 content.appendChild(document.createTextNode('Your berry basket is empty.'));
302 }
303 var trashbin = YAHOO.util.Dom.get('trashbin');
304 if ( trashbin !=null){
305 trashbin.style.background = 'url("interfaces/default/images/trash-full.png") 0 0 no-repeat';
306 }
307 }
308
309
310 var delFailure = function(o){ }
311
312
313 var delcallback = {
314 success:delSuccess,
315 failure:delFailure,
316 argument:player
317 }
318
319
320 if (id == 'berrybasket'){
321 YAHOO.util.Connect.asyncRequest(request_type , addurl , addcallback);
322 }
323 else{
324 if (id == 'trashbin'){
325 YAHOO.util.Connect.asyncRequest(request_type , delurl , delcallback);
326 }
327 }
328
329 this.resetTargets();
330 this.slot = oDD;
331 this.slot.player = this;
332
333};
334
335ygDDPlayer.prototype.swap = function(el1, el2) {
336 var dom = YAHOO.util.Dom;
337 var pos1 = dom.getXY(el1);
338 var pos2 = dom.getXY(el2);
339 dom.setXY(el1, pos2);
340 dom.setXY(el2, pos1);
341};
342
343ygDDPlayer.prototype.onDragOver = function(e, id) {};
344
345ygDDPlayer.prototype.onDrag = function(e, id) {};
346
347
348
349
350
Note: See TracBrowser for help on using the repository browser.