This repository has been archived by the owner on Oct 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 214
/
index.js
103 lines (99 loc) · 3.49 KB
/
index.js
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
/*
* Copyright (c) 2011-2012, Yahoo! Inc. All rights reserved.
* Copyrights licensed under the New BSD License.
* See the accompanying LICENSE file for terms.
*/
/*jslint anon:true, sloppy:true, nomen:true, node:true*/
YUI.add('PagerMojitBinder', function(Y, NAME) {
var API_KEY = '9cc79c8bf1942c683b0d4e30b838ee9c';
/**
* The PagerMojitBinder module.
* @module PagerMojitBinder
*/
/**
* Constructor for the Binder class.
*
* @param mojitProxy {Object} The proxy to allow
* the binder to interact with its owning mojit.
* @class Binder
* @constructor
*/
Y.namespace('mojito.binders')[NAME] = {
/**
* Binder initialization method, invoked
* after all binders on the page have
* been constructed.
*/
init: function(mojitProxy) {
this.mojitProxy = mojitProxy;
},
/**
* The binder method, invoked to allow the mojit
* to attach DOM event handlers.
* @param node {Node} The DOM node to which this
* mojit is attached.
*/
bind: function(node) {
var thatNode = node;
// define the action when user click on prev/next
var flipper = function(event) {
var target = event.target;
// get the link to the page
var page = parsePage(target.get('href'));
var updateDOM = function(markup) {
thatNode.set('innerHTML', markup);
thatNode.all('#nav a').on('click', flipper, this);
thatNode.all('#master ul li a').on('mouseover', showOverlay, this);
thatNode.all('#master ul li a').on('mouseout', showOverlay, this);
};
this.mojitProxy.invoke('index',
{
params: {page: page}
}, updateDOM
);
};
var showOverlay = function(event) {
var target = event.target;
var href = target.get('href');
var imageId = parseImageId(href);
if (target.hasClass('overlayed')) {
target.removeClass('overlayed');
thatNode.one('#display').setContent('');
} else {
target.addClass('overlayed');
// Query for the image metadata
var query = 'select * from flickr.photos.info where photo_id="' + imageId + '" and api_key="' + API_KEY + '"';
thatNode.one('#display').setContent('Loading ...');
Y.YQL(query, function(raw) {
if (!raw.query.results.photo) {
Y.log('No results found for photoId: ' + imageId);
return;
}
var props = raw.query.results.photo;
var snippet = '<ul style="list-style-type: square;">';
for (var key in props) {
if (typeof(props[key]) == 'object') {
continue;
}
snippet += '<li>' + key + ': ' + props[key] + '</li>';
}
snippet += '</ul>';
thatNode.one('#display').setContent(snippet); });
}
};
// Bind all the image links to showOverlay
thatNode.all('#master ul li a').on('mouseover', showOverlay, this);
thatNode.all('#master ul li a').on('mouseout', showOverlay, this);
// Bind the prev + next links to flipper
thatNode.all('#nav a').on('click', flipper, this);
}
};
function parseImageId(link) {
var matches = link.match(/com\/(\d+)\/(\d+)_([0-9a-z]+)\.jpg$/);
return matches[2];
}
function parsePage(link) {
var matches = link.match(/page=(\d+)/);
return matches[1];
}
}, '0.0.1', {requires: ['yql', 'io', 'dump','mojito-client']});