|
0
|
1 |
YUI(yuiConfig).use('node', 'anim', 'dd', 'yql', 'slider', 'stylesheet', 'event-delegate', function(Y) { |
|
|
2 |
//Get a reference to the wrapper to use later and add a loading class to it. |
|
|
3 |
var wrapper = Y.get('#yui-main .yui-g ul').addClass('loading'); |
|
|
4 |
//Set it's height to the height of the viewport so we can scroll it. |
|
|
5 |
wrapper.setStyle('height', (wrapper.get('winHeight') - 50 )+ 'px'); |
|
|
6 |
Y.on('windowresize', function() { wrapper.setStyle('height', (wrapper.get('winHeight') - 50 )+ 'px'); }); |
|
|
7 |
//Make the YQL query. |
|
|
8 |
new Y.yql('select * from flickr.photos.search(100) where text="openhacklondon" and safe_search = 1 and media = "photos" and extras = "o_dims" and ((o_width = "1600" and o_height = "1200") or (o_width = "1200" and o_height = "1600") or (o_width = "800" and o_height = "600") or (o_width = "600" and o_height = "800"))', function(e) { |
|
|
9 |
if (e.query) { |
|
|
10 |
var photos = e.query.results.photo; |
|
|
11 |
//Walk the returned photos array |
|
|
12 |
Y.each(photos, function(v, k) { |
|
|
13 |
//Create our URL |
|
|
14 |
var url = 'http:/'+'/static.flickr.com/' + v.server + '/' + v.id + '_' + v.secret + '_m.jpg', |
|
|
15 |
//Create the image and the LI |
|
|
16 |
li = Y.Node.create('<li class="loading"><img src="' + url + '" title="' + v.title + '"></li>'), |
|
|
17 |
//Get the image from the LI |
|
|
18 |
img = li.get('firstChild'); |
|
|
19 |
//Append the li to the wrapper |
|
|
20 |
wrapper.appendChild(li); |
|
|
21 |
//This little hack moves the tall images to the bottom of the list |
|
|
22 |
//So they float better ;) |
|
|
23 |
img.on('load', function() { |
|
|
24 |
//Is the height longer than the width? |
|
|
25 |
var c = ((this.get('height') > this.get('width')) ? 'tall' : 'wide'); |
|
|
26 |
this.addClass(c); |
|
|
27 |
if (c === 'tall') { |
|
|
28 |
//Move it to the end of the list. |
|
|
29 |
this.get('parentNode.parentNode').removeChild(this.get('parentNode')); |
|
|
30 |
wrapper.appendChild(this.get('parentNode')); |
|
|
31 |
} |
|
|
32 |
this.get('parentNode').removeClass('loading'); |
|
|
33 |
}); |
|
|
34 |
}); |
|
|
35 |
//Get all the newly added li's |
|
|
36 |
wrapper.queryAll('li').each(function(node) { |
|
|
37 |
//Plugin the Drag plugin |
|
|
38 |
this.plug(Y.Plugin.Drag, { |
|
|
39 |
offsetNode: false |
|
|
40 |
}); |
|
|
41 |
//Plug the Proxy into the DD object |
|
|
42 |
this.dd.plug(Y.Plugin.DDProxy, { |
|
|
43 |
resizeFrame: false, |
|
|
44 |
moveOnEnd: false, |
|
|
45 |
borderStyle: 'none' |
|
|
46 |
}); |
|
|
47 |
}); |
|
|
48 |
//Create and render the slider |
|
|
49 |
var sl = new Y.Slider({ |
|
|
50 |
railSize: '200px', value: 40, max: 70, min: 5, |
|
|
51 |
thumbImage: assetsDir + 'css/thumb-classic-x.png' |
|
|
52 |
}).render('.horiz_slider'); |
|
|
53 |
//Listen for the change |
|
|
54 |
sl.after('valueChange',function (e) { |
|
|
55 |
//Insert a dynamic stylesheet rule: |
|
|
56 |
var sheet = new Y.StyleSheet('image_slider'); |
|
|
57 |
sheet.set('#yui-main .yui-g ul li', { |
|
|
58 |
width: (e.newVal / 2) + '%' |
|
|
59 |
}); |
|
|
60 |
}); |
|
|
61 |
//Remove the DDM as a bubble target.. |
|
|
62 |
sl._dd.removeTarget(Y.DD.DDM); |
|
|
63 |
//Remove the wrappers loading class |
|
|
64 |
wrapper.removeClass('loading'); |
|
|
65 |
Y.get('#ft').removeClass('loading'); |
|
|
66 |
} |
|
|
67 |
}); |
|
|
68 |
//Listen for all mouseup's on the document (selecting/deselecting images) |
|
|
69 |
Y.on('delegate', function(e) { |
|
|
70 |
if (!e.shiftKey) { |
|
|
71 |
//No shift key - remove all selected images |
|
|
72 |
wrapper.queryAll('img.selected').removeClass('selected'); |
|
|
73 |
} |
|
|
74 |
//Check if the target is an image and select it. |
|
|
75 |
if (e.target.test('#yui-main .yui-g ul li img')) { |
|
|
76 |
e.target.addClass('selected'); |
|
|
77 |
} |
|
|
78 |
}, document, 'mouseup', '*'); |
|
|
79 |
//Listen for all clicks on the '#photoList li' selector |
|
|
80 |
Y.on('delegate', function(e) { |
|
|
81 |
//Prevent the click |
|
|
82 |
e.halt(); |
|
|
83 |
//Remove all the selected items |
|
|
84 |
e.currentTarget.get('parentNode').queryAll('li.selected').removeClass('selected'); |
|
|
85 |
//Add the selected class to the one that one clicked |
|
|
86 |
e.currentTarget.addClass('selected'); |
|
|
87 |
//The "All Photos" link was clicked |
|
|
88 |
if (e.currentTarget.hasClass('all')) { |
|
|
89 |
//Remove all the hidden classes |
|
|
90 |
wrapper.queryAll('li').removeClass('hidden'); |
|
|
91 |
} else { |
|
|
92 |
//Another "album" was clicked, get it's id |
|
|
93 |
var c = e.currentTarget.get('id'); |
|
|
94 |
//Hide all items by adding the hidden class |
|
|
95 |
wrapper.queryAll('li').addClass('hidden'); |
|
|
96 |
//Now, find all the items with the class name the same as the album id |
|
|
97 |
//and remove the hidden class |
|
|
98 |
wrapper.queryAll('li.' + c).removeClass('hidden'); |
|
|
99 |
} |
|
|
100 |
}, document, 'click', '#photoList li'); |
|
|
101 |
//Stop the drag with the escape key |
|
|
102 |
Y.get(document).on('keypress', function(e) { |
|
|
103 |
//The escape key was pressed |
|
|
104 |
if ((e.keyCode === 27) || (e.charCode === 27)) { |
|
|
105 |
//We have an active Drag |
|
|
106 |
if (Y.DD.DDM.activeDrag) { |
|
|
107 |
//Stop the drag |
|
|
108 |
Y.DD.DDM.activeDrag.stopDrag(); |
|
|
109 |
} |
|
|
110 |
} |
|
|
111 |
}); |
|
|
112 |
//On the drag:mouseDown add the selected class |
|
|
113 |
Y.DD.DDM.on('drag:mouseDown', function(e) { |
|
|
114 |
e.target.get('node').queryAll('img').addClass('selected'); |
|
|
115 |
}); |
|
|
116 |
//On drag start, get all the selected elements |
|
|
117 |
//Add the count to the proxy element and offset it to the cursor. |
|
|
118 |
Y.DD.DDM.on('drag:start', function(e) { |
|
|
119 |
//How many items are selected |
|
|
120 |
var count = wrapper.queryAll('img.selected').size(); |
|
|
121 |
//Set the style on the proxy node |
|
|
122 |
e.target.get('dragNode').setStyles({ |
|
|
123 |
height: '25px', width: '25px' |
|
|
124 |
}).set('innerHTML', '<span>' + count + '</span>'); |
|
|
125 |
//Offset the dragNode |
|
|
126 |
e.target.deltaXY = [25, 5]; |
|
|
127 |
}); |
|
|
128 |
//We dropped on a drop target |
|
|
129 |
Y.DD.DDM.on('drag:drophit', function(e) { |
|
|
130 |
//get the images that are selected. |
|
|
131 |
var imgs = wrapper.queryAll('img.selected'), |
|
|
132 |
//The xy position of the item we dropped on |
|
|
133 |
toXY = e.drop.get('node').getXY(); |
|
|
134 |
|
|
|
135 |
imgs.each(function(node) { |
|
|
136 |
//Clone the image, position it on top of the original and animate it to the drop target |
|
|
137 |
node.get('parentNode').addClass(e.drop.get('node').get('id')); |
|
|
138 |
var n = node.cloneNode().set('id', '').setStyle('position', 'absolute'); |
|
|
139 |
Y.get('body').appendChild(n); |
|
|
140 |
n.setXY(node.getXY()); |
|
|
141 |
new Y.Anim({ |
|
|
142 |
node: n, |
|
|
143 |
to: { |
|
|
144 |
height: 20, width: 20, opacity: 0, |
|
|
145 |
top: toXY[1], left: toXY[0] |
|
|
146 |
}, |
|
|
147 |
from: { |
|
|
148 |
width: node.get('offsetWidth'), |
|
|
149 |
height: node.get('offsetHeight') |
|
|
150 |
}, |
|
|
151 |
duration: .5 |
|
|
152 |
}).run(); |
|
|
153 |
}); |
|
|
154 |
//Update the count |
|
|
155 |
var count = wrapper.queryAll('li.' + e.drop.get('node').get('id')).size(); |
|
|
156 |
e.drop.get('node').query('span').set('innerHTML', '(' + count + ')'); |
|
|
157 |
}); |
|
|
158 |
//Add drop support to the albums |
|
|
159 |
Y.all('#photoList li').each(function(node) { |
|
|
160 |
if (!node.hasClass('all')) { |
|
|
161 |
//make all albums Drop Targets except the all photos. |
|
|
162 |
node.plug(Y.Plugin.Drop); |
|
|
163 |
} |
|
|
164 |
}); |
|
|
165 |
}); |