diff options
author | Armen Kesablyan | 2012-05-14 11:45:11 -0700 |
---|---|---|
committer | Armen Kesablyan | 2012-05-14 11:45:11 -0700 |
commit | 9e6c0a247bd2f14d92278bcd97fff40277b71667 (patch) | |
tree | 4194388c03814b9168922dbf2907edf426295874 /node_modules/montage-google/feed-reader/feed-reader.reel/feed-reader.js | |
parent | 9fc3b70bf57e10846e71808c6041fbc339a435d1 (diff) | |
parent | 27f4cacb39de1c2e3910748dadc9fc16d0655480 (diff) | |
download | ninja-9e6c0a247bd2f14d92278bcd97fff40277b71667.tar.gz |
Merge branch 'refs/heads/masterDomArc' into binding
Diffstat (limited to 'node_modules/montage-google/feed-reader/feed-reader.reel/feed-reader.js')
-rw-r--r-- | node_modules/montage-google/feed-reader/feed-reader.reel/feed-reader.js | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/node_modules/montage-google/feed-reader/feed-reader.reel/feed-reader.js b/node_modules/montage-google/feed-reader/feed-reader.reel/feed-reader.js new file mode 100644 index 00000000..47a831eb --- /dev/null +++ b/node_modules/montage-google/feed-reader/feed-reader.reel/feed-reader.js | |||
@@ -0,0 +1,179 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | var Montage = require("montage").Montage, | ||
7 | Component = require("montage/ui/component").Component; | ||
8 | |||
9 | exports.FeedReader = Montage.create(Component, { | ||
10 | |||
11 | didCreate: { | ||
12 | value: function() { | ||
13 | var self = this; | ||
14 | var apiInit = function() { | ||
15 | console.log('google api initialized'); | ||
16 | |||
17 | google.load("feeds", "1", { | ||
18 | callback: function() { | ||
19 | console.log('google feeds api loaded'); | ||
20 | self.needsDraw = true; | ||
21 | window.initGoogleAPI = null; | ||
22 | } | ||
23 | }); | ||
24 | }; | ||
25 | |||
26 | // set up a global function | ||
27 | window.initGoogleAPI = apiInit; | ||
28 | } | ||
29 | }, | ||
30 | |||
31 | _feedURL: {value: null}, | ||
32 | feedURL: { | ||
33 | get: function() { | ||
34 | return this._feedURL; | ||
35 | }, | ||
36 | set: function(value) { | ||
37 | this._feedURL = value; | ||
38 | // execute the search and get the entries | ||
39 | this._fetchFeed(); | ||
40 | } | ||
41 | }, | ||
42 | |||
43 | // time in ms between slides | ||
44 | interval: {value: 3, distinct: true}, | ||
45 | |||
46 | maxEntries: {value: 10, distinct: true}, | ||
47 | |||
48 | entries: {value: null}, | ||
49 | |||
50 | _feedDisplayMode: {value: null}, | ||
51 | feedDisplayMode: { | ||
52 | get: function() { | ||
53 | return this._feedDisplayMode; | ||
54 | }, | ||
55 | set: function(value) { | ||
56 | |||
57 | this.removeEntryAnimation(); | ||
58 | this._feedDisplayMode = value; | ||
59 | |||
60 | this.addEntryAnimation(); | ||
61 | } | ||
62 | }, | ||
63 | |||
64 | |||
65 | feedEntryTimer: {enumerable: false, value: null}, | ||
66 | |||
67 | |||
68 | activeFeedEntry: {value: null}, | ||
69 | _activeIndex: {value: null}, | ||
70 | activeIndex: { | ||
71 | get: function() { | ||
72 | return this._activeIndex || 0; | ||
73 | }, | ||
74 | set: function(index) { | ||
75 | if(this.entries) { | ||
76 | var max = this.entries.length-1; | ||
77 | if(index > max) { | ||
78 | index = 0; | ||
79 | } | ||
80 | if(index < 0) { | ||
81 | index = 0; | ||
82 | } | ||
83 | this._activeIndex = index; | ||
84 | this.activeFeedEntry = this.entries[this._activeIndex]; | ||
85 | } else { | ||
86 | this._activeIndex = 0; | ||
87 | } | ||
88 | } | ||
89 | }, | ||
90 | |||
91 | _fetchFeed: { | ||
92 | value: function() { | ||
93 | |||
94 | var url = this.feedURL; | ||
95 | var feed = new google.feeds.Feed(url); | ||
96 | feed.setNumEntries(10); | ||
97 | |||
98 | var self = this; | ||
99 | self.entries = []; | ||
100 | |||
101 | feed.load(function(result) { | ||
102 | self.removeEntryAnimation(); | ||
103 | if(result.error) { | ||
104 | self.entries = []; | ||
105 | } else { | ||
106 | //console.log('entries: ', result.feed.entries); | ||
107 | self.addEntryAnimation(); | ||
108 | self.entries = result.feed.entries; | ||
109 | self.activeIndex = 0; | ||
110 | |||
111 | } | ||
112 | |||
113 | |||
114 | }); | ||
115 | } | ||
116 | }, | ||
117 | |||
118 | addEntryAnimation: { | ||
119 | value: function() { | ||
120 | var self = this; | ||
121 | if("animation" == this.feedDisplayMode) { | ||
122 | this.element.addEventListener('webkitAnimationStart', this); | ||
123 | this.element.addEventListener('webkitAnimationIteration', this); | ||
124 | this.element.addEventListener('webkitAnimationEnd', this); | ||
125 | } else { | ||
126 | // timer | ||
127 | this.feedEntryTimer = setInterval(function() { | ||
128 | self.activeIndex = self.activeIndex + 1; | ||
129 | }, (this.interval * 1000)); | ||
130 | } | ||
131 | } | ||
132 | }, | ||
133 | |||
134 | removeEntryAnimation: { | ||
135 | value: function() { | ||
136 | if("animation" == this.feedDisplayMode) { | ||
137 | this.element.removeEventListener('webkitAnimationStart', this); | ||
138 | this.element.removeEventListener('webkitAnimationIteration', this); | ||
139 | this.element.removeEventListener('webkitAnimationEnd', this); | ||
140 | |||
141 | } else { | ||
142 | if(this.feedEntryTimer) { | ||
143 | window.clearInterval(this.feedEntryTimer); | ||
144 | } | ||
145 | } | ||
146 | } | ||
147 | }, | ||
148 | |||
149 | handleWebkitAnimationStart: { | ||
150 | value: function() { | ||
151 | console.log('animation start'); | ||
152 | } | ||
153 | }, | ||
154 | |||
155 | handleWebkitAnimationIteration: { | ||
156 | value: function() { | ||
157 | console.log('animation iteration'); | ||
158 | this.activeIndex = this.activeIndex + 1; | ||
159 | } | ||
160 | }, | ||
161 | |||
162 | handleWebkitAnimationEnd: { | ||
163 | value: function() { | ||
164 | console.log('animation end'); | ||
165 | } | ||
166 | }, | ||
167 | |||
168 | prepareForDraw: { | ||
169 | value: function() { | ||
170 | } | ||
171 | }, | ||
172 | |||
173 | draw: { | ||
174 | value: function() { | ||
175 | |||
176 | } | ||
177 | } | ||
178 | |||
179 | }); | ||