Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

te

quit
  • Loading branch information...
commit dd5eafc5b450b641a02e64c9e7cff9070914fe5f 1 parent b73f4a5
@chetanankola authored
Showing with 1,098 additions and 126 deletions.
  1. +0 −72 README
  2. +15 −15 application.json
  3. +81 −0 mojits/flickr/assets/index.css
  4. +76 −0 mojits/flickr/binders/index.js
  5. +73 −0 mojits/flickr/controller.server.js
  6. +5 −0 mojits/flickr/definition.json
  7. +62 −0 mojits/flickr/models/foo.server.js
  8. +37 −0 mojits/flickr/tests/binders/index.common-tests.js
  9. +62 −0 mojits/flickr/tests/controller.server-tests.js
  10. +39 −0 mojits/flickr/tests/models/foo.server-tests.js
  11. +27 −0 mojits/flickr/views/index.mu.html
  12. +61 −2 mojits/instagram/assets/index.css
  13. +29 −8 mojits/instagram/binders/index.js
  14. +81 −9 mojits/instagram/controller.server.js
  15. +34 −3 mojits/instagram/models/foo.server.js
  16. +31 −9 mojits/instagram/views/index.mu.html
  17. +5 −8 mojits/main/views/index.mu.html
  18. +56 −0 mojits/search/assets/index.css
  19. +94 −0 mojits/search/binders/index.js
  20. +45 −0 mojits/search/controller.server.js
  21. +5 −0 mojits/search/definition.json
  22. +37 −0 mojits/search/models/foo.server.js
  23. +37 −0 mojits/search/tests/binders/index.common-tests.js
  24. +62 −0 mojits/search/tests/controller.server-tests.js
  25. +39 −0 mojits/search/tests/models/foo.server-tests.js
  26. +5 −0 mojits/search/views/index.mu.html
View
72 README
@@ -1,72 +0,0 @@
-Install mojito first as:
-$ git clone git://github.com/yahoo/mojito.git
-$ cd mojito/source
-$ npm install -g .
-$ npm install .
-
-or check the http://github.com/yahoo/mojito for more details on installation
-
-enter mojito/source dir (cd ~/mojito/source)
-and do: git clone git://github.com/chetanankola/feather-application.git
-
-this will create a dir called feather-application with all the source files.
-
-cd feather-application
-
-run
- mojito start
- or
- mojito start --context "environment:dev"
-check your application running at http://localhost:8001/
-
-
-
-
-CHECKIN MOJIT AND LOGIN MOJIT:
-==============================
-These two mojit are facebook related mojits.
-Login mojit does authentication and puts the access_token in a cookie named "fb_access_token"
-All othe mojits including checkin mojit if need to pull data from facebook graph needs to use this access token.
- ================================
- What about APP KEY for Facebook:
- ================================
- As you would know that every facebook graph api needs an app key app secret etc? and its all tied to a host url.
- Currently for this scaffold mojito app all that details is stored in defaults.json of login mojit ["mojits/login/defaults.json"] and is tied to localhost:8001
-
- if you want to use this mojito on your own host url facebook related stuff will fail. so you need to get app key for ur url from facebook developer api and put ur information in the defaults.json.
-
-
-
-
-TWITTER MOJIT : how does this work
-===================================
-so go to the mojits/twitter/controller.server.js and to the index function
-thats where you start from.
- if(!ac.params.getFromRoute('defer')){
- var loaderImg1 = 'http://a.l.yimg.com/a/i/us/sch/mob/spinner-white-small.gif';
- var loaderImg2 = 'http://a.l.yimg.com/a/i/us/sch/mob/spinner-1.0.0.gif';
- return ac.done({'onload':{url:loaderImg2}});
- }
-So here I do my own custom lazy loading where the mojits execute later after the parent (main mojit) has finished execution
-here you check for any defer params passed to the controller by either mojits/twitter/binders/index.js or from url etc..
-
-if you see none then you just put a "loading gif" and return meaning no more code of twitter mojit runs.
-
-now lets go back to mojits/twitter/binders/index.js
-here since controller.server.js a while ago since finished itself.. this gets loaded..
-here I do
- var args = {params: {route: {
- coord:{lat:lat,lon:lon,radius:radius},defer:true
- }}};
- this.mojitProxy.refreshView(args);
-so what this does is basically refresh the mojit (passing the code execution control to controller back again.)
-now the controller.. again
-
-
-this time if(!ac.params.getFromRoute('defer')){ wont run.. instead runs the later part of the server code.. which is pulling the tweets..
-
-
-
-
-
-
View
30 application.json
@@ -26,23 +26,14 @@
"type" : "main",
"config" : {
"children" : {
- "checkin": {
- "base" : "checkin"
+ "instagram": {
+ "base" : "instagram"
},
- "login": {
- "base" : "login"
+ "flickr": {
+ "base": "flickr"
},
- "weather": {
- "base" : "weather"
- },
- "gmap" : {
- "base" : "gmap"
- },
- "twitter" : {
- "base" : "twitter"
- },
- "geocode" : {
- "base" : "geocode"
+ "search": {
+ "base": "search"
}
}
}
@@ -58,6 +49,15 @@
}
}
},
+ "search": {
+ "type": "search"
+ },
+ "instagram": {
+ "type": "instagram"
+ },
+ "flickr": {
+ "type": "flickr"
+ },
"checkin": {
"type" : "checkin"
},
View
81 mojits/flickr/assets/index.css
@@ -0,0 +1,81 @@
+.flickr{
+ position:absolute;
+ margin:0 auto;
+ margin-top:30px;
+ top:45%;
+ left:10px;
+}
+
+.wrap{
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ display:block;
+ overflow: hidden;
+}
+
+
+.splash {
+ text-align:center;
+ font-size:1.4em;padding:20px;width:320px;
+ border: 1px solid #9c9c9c; border: 1px solid rgba(0, 0, 0, 0.3); -webkit-border-radius: .5em;-webkit-border-top-left-radius: .5em;-webkit-border-top-right-radius: .5em;-webkit-border-bottom-left-radius: .5em;-webkit-border-bottom-right-radius: .5em;
+ -moz-border-radius: .5em;border-radius: .5em;
+ background: #fefefe;background: -moz-linear-gradient(top, #fefefe, #d8d8d8);background: -webkit-gradient(linear, left top, left bottom, from(#fefefe), to(#d8d8d8));
+ -moz-box-shadow: 1px 1px 3px #292929;-webkit-box-shadow: 1px 1px 3px #292929;box-shadow: 1px 1px 3px #292929;filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#656565', EndColorStr='#141414');
+}
+
+.flickfont{
+
+ margin-top:40px;
+ margin-left:10px;
+ width:320px;
+ text-align:center;
+ padding:2px;
+ font-family: 'Fredericka the Great', cursive;
+ font-size:50px;
+}
+
+#flickr-farm-container{
+ margin-top:20px;
+white-space:nowrap;
+ bottom:0px;
+ left:0px;
+}
+
+
+#flickr-farm-container ul{
+list-style-type: none;
+margin: 0;
+padding: 0;
+}
+
+#flickr-farm-container li {
+ display: inline-block;
+ position:relative;
+ height: inherit;
+}
+
+#flickr-farm-container img {
+ display: inline-block;
+ height:130px;
+ -webkit-transition:all 0.7s;
+ box-shadow:1px 1px 9px #000;
+ margin-left:6px;
+}
+
+#flickr-farm-container ul:hover{
+}
+
+#flickr-farm-container img:hover {
+ height:200px;
+
+ -webkit-transition:all 0.7s;
+}
+
+.flickr-farm{
+ margin: 0 auto;
+ padding: 0;
+}
+
+.flickr-farm {
+
+}
View
76 mojits/flickr/binders/index.js
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2012 Yahoo! Inc. All rights reserved.
+ */
+/*jslint anon:true, sloppy:true, nomen:true*/
+YUI.add('flickrBinderIndex', function(Y, NAME) {
+
+/**
+ * The flickrBinderIndex module.
+ *
+ * @module flickrBinderIndex
+ */
+
+ /**
+ * Constructor for the flickrBinderIndex class.
+ *
+ * @class flickrBinderIndex
+ * @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.
+ * ***FLICKR*****FLICKR*****FLICKR*****FLICKR*****FLICKR*****FLICKR*****FLICKR*****FLICKR*****FLICKR*****FLICKR**
+ * @param node {Node} The DOM node to which this mojit is attached.
+ */
+ bind: function(node) {
+ var me = this;
+ this.node = node;
+ Y.on('SEARCH_UPDATE', function(e, search) {
+ //alert(search.val);
+ console.log('on SEARCH_UPDATE:Flickr'+search.val);
+ var args = {
+ params: {
+ route: {
+ searchTerm:search.val,
+ numofImages:(search.num || 10 )
+ }
+ }
+ };
+ this.mojitProxy.refreshView(args);
+ }, this);
+
+ var scrollview_bookmarked_friends = new Y.ScrollView({
+ srcNode:this.node.one('#flickr-farm-container'),
+ deceleration: 0.9,
+ bounce:0.1,
+ flick: {
+ minDistance:10,
+ minVelocity:0.1,
+ axis: "x"
+ }
+ });
+ setTimeout(function(){
+ scrollview_bookmarked_friends.syncUI();
+ },4000);
+ scrollview_bookmarked_friends.render();
+ Y.on('resize', function (e) {
+ scrollview_bookmarked_friends.syncUI();
+ });
+
+
+ }
+
+
+ };
+
+}, '0.0.1', {requires: ['event-mouseenter', 'mojito-client', 'node', 'scrollview','scrollview-base', 'scrollview-paginator']});
View
73 mojits/flickr/controller.server.js
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2012 Yahoo! Inc. All rights reserved.
+ */
+/*jslint anon:true, sloppy:true, nomen:true*/
+YUI.add('flickr', function(Y, NAME) {
+
+/**
+ * The flickr module.
+ *
+ * @module flickr
+ */
+
+ /**
+ * Constructor for the Controller class.
+ *
+ * @class Controller
+ * @constructor
+ */
+ Y.namespace('mojito.controllers')[NAME] = {
+
+ init: function(config) {
+ this.config = config;
+ },
+
+ /**
+ * Method corresponding to the 'index' action.
+ *
+ * @param ac {Object} The ActionContext that provides access
+ * to the Mojito API.
+ */
+ index: function(ac) {
+ var searchTerm = ac.params.getFromRoute('searchTerm') || 'Yahoo';
+ var defaultnumofImages = 10;
+ var number = ac.params.getFromRoute('numofImages') || defaultnumofImages;
+ ac.assets.addCss('./index.css');
+
+
+ ac.models.flickrModelFoo.getPics(searchTerm,number, function(err, rsp) {
+
+ var jsonFlickrApi = function(rsp){
+ if(rsp && rsp.stat != "ok"){
+ return ac.done({searchTerm:searchTerm, error:'Flickr! you failed me!! '});
+
+ } else {
+ if(rsp.photos){
+ var photosArr = rsp.photos.photo;
+ console.log(photosArr);
+
+ ac.done({searchTerm:searchTerm,photosArr:photosArr});
+ }
+ }
+ };
+
+ if (err) {
+ ac.error(err);
+ return;
+ }
+
+ if(rsp && rsp._resp && rsp._resp.responseText){
+ console.log(rsp);
+ return eval(rsp._resp.responseText);
+ }
+
+ ac.done({
+ searchTerm:searchTerm,
+ error:'Flickr! you failed me!!'
+ });
+ });
+ }
+
+ };
+
+}, '0.0.1', {requires: ['mojito', 'flickrModelFoo','json-parse']});
View
5 mojits/flickr/definition.json
@@ -0,0 +1,5 @@
+[
+ {
+ "settings": [ "master" ]
+ }
+]
View
62 mojits/flickr/models/foo.server.js
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2012 Yahoo! Inc. All rights reserved.
+ */
+/*jslint anon:true, sloppy:true, nomen:true*/
+YUI.add('flickrModelFoo', function (Y, NAME) {
+
+/**
+ * The flickrModelFoo module.
+ *
+ * @module flickr
+ */
+
+ /**
+ * Constructor for the flickrModelFoo class.
+ *
+ * @class flickrModelFoo
+ * @constructor
+ */
+ Y.namespace('mojito.models')[NAME] = {
+
+ init: function (config) {
+ this.config = config;
+ },
+
+ /**
+ * Method that will be invoked by the mojit controller to obtain data.
+ *
+ * @param callback {function(err,data)} The callback function to call when the
+ * data has been retrieved.
+ */
+ getData: function (callback) {
+ callback(null, { some: 'data' });
+ },
+
+ getPics: function (searchTerm,num,callback){
+ var numofimages = num ;
+ searchTerm = encodeURIComponent(searchTerm);
+ var query = "http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=2821aea7d2727d35338d0660a0fe7c45&text="+searchTerm+"&per_page="+numofimages+"&format=json";
+ console.log(query);
+
+
+ function handler(err,response) {
+ if(err){
+ console.log('error results');
+ return callback(err, null);
+ } else if(response){
+ return callback(null,response);
+ }else {
+ console.log('no results or query failed');
+ return callback(null, null);
+ }
+ }
+ try{
+ Y.mojito.lib.REST.GET(query, {}, {}, handler);
+ }catch (err){
+ throw err;
+ }
+ }
+
+ };
+
+}, '0.0.1', {requires: ['mojito','mojito-rest-lib', 'json-parse','cookie']});
View
37 mojits/flickr/tests/binders/index.common-tests.js
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2012 Yahoo! Inc. All rights reserved.
+ */
+YUI.add('flickrBinderIndex-tests', function(Y, NAME) {
+
+ var suite = new YUITest.TestSuite(NAME),
+ binder,
+ A = YUITest.Assert;
+
+ suite.add(new YUITest.TestCase({
+
+ name: 'flickr index binder tests',
+
+ setUp: function() {
+ binder = Y.mojito.binders.flickrBinderIndex;
+ },
+ tearDown: function() {
+ binder = null;
+ },
+
+ 'TODO: test update id': function() {
+ var node = Y.Node.create("<div id='guid123'></div>");
+ binder.init({
+ _guid: 'guid123'
+ });
+ binder.bind(node);
+
+ // there is nothing to test in the binder initially
+ A.skip();
+
+ }
+
+ }));
+
+ YUITest.TestRunner.add(suite);
+
+}, '0.0.1', {requires: ['mojito-test', 'node', 'flickrBinderIndex']});
View
62 mojits/flickr/tests/controller.server-tests.js
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2012 Yahoo! Inc. All rights reserved.
+ */
+
+YUI.add('flickr-tests', function(Y) {
+
+ var suite = new YUITest.TestSuite('flickr-tests'),
+ controller = null,
+ A = YUITest.Assert;
+
+ suite.add(new YUITest.TestCase({
+
+ name: 'flickr user tests',
+
+ setUp: function() {
+ controller = Y.mojito.controllers.flickr;
+ },
+ tearDown: function() {
+ controller = null;
+ },
+
+ 'test mojit': function() {
+ var ac,
+ modelData,
+ assetsResults,
+ doneResults;
+ modelData = { x:'y' };
+ ac = {
+ assets: {
+ addCss: function(css) {
+ assetsResults = css;
+ }
+ },
+ models: {
+ flickrModelFoo: {
+ getData: function(cb) {
+ cb(null, modelData);
+ }
+ }
+ },
+ done: function(data) {
+ doneResults = data;
+ }
+ };
+
+ A.isNotNull(controller);
+ A.isFunction(controller.index);
+ controller.index(ac);
+ A.areSame('./index.css', assetsResults);
+ A.isObject(doneResults);
+ A.areSame('Mojito is working.', doneResults.status);
+ A.isObject(doneResults.data);
+ A.isTrue(doneResults.data.hasOwnProperty('x'));
+ A.areEqual('y', doneResults.data['x']);
+
+ }
+
+ }));
+
+ YUITest.TestRunner.add(suite);
+
+}, '0.0.1', {requires: ['mojito-test', 'flickr']});
View
39 mojits/flickr/tests/models/foo.server-tests.js
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2012 Yahoo! Inc. All rights reserved.
+ */
+
+YUI.add('flickrModelFoo-tests', function(Y, NAME) {
+
+ var suite = new YUITest.TestSuite(NAME),
+ model = null,
+ A = YUITest.Assert;
+
+ suite.add(new YUITest.TestCase({
+
+ name: 'flickrModelFoo user tests',
+
+ setUp: function() {
+ model = Y.mojito.models.flickrModelFoo;
+ },
+ tearDown: function() {
+ model = null;
+ },
+
+ 'test mojit model': function() {
+ var called = false;
+ A.isNotNull(model);
+ A.isFunction(model.getData);
+ model.getData(function(err, data) {
+ called = true;
+ A.isTrue(!err);
+ A.isObject(data);
+ A.areSame('data', data.some);
+ });
+ A.isTrue(called);
+ }
+
+ }));
+
+ YUITest.TestRunner.add(suite);
+
+}, '0.0.1', {requires: ['mojito-test', 'flickrModelFoo']});
View
27 mojits/flickr/views/index.mu.html
@@ -0,0 +1,27 @@
+<div id="{{mojit_view_id}}" class="flickr">
+
+
+ <div id="flickr-farm-container">
+ <h1 style="display:none;" class="splash wrap">
+ Flickr: {{searchTerm}}
+ </h1>
+ <h1 class='flickfont'>FLICKR</h1>
+ <ul>
+ {{#photosArr}}
+ <li class='flickr-img'>
+ <div class="image">
+ <a href='http://farm{{farm}}.static.flickr.com/{{server}}/{{id}}_{{secret}}.jpg' target="_blank">
+ <img title='{{title}}' src='http://farm{{farm}}.static.flickr.com/{{server}}/{{id}}_{{secret}}.jpg' />
+ </a>
+ </div>
+ </li>
+ {{/photosArr}}
+ </ul>
+ </div>
+
+ <div style="bottom:1px;postion:absolute;left:1px;">
+ {{debug}}
+ {{error}}
+ </div>
+
+</div>
View
63 mojits/instagram/assets/index.css
@@ -1,2 +1,61 @@
-dt { font-weight: bold; }
-.sel { background-color: #FF4; }
+.instagram{
+ position:absolute;
+ margin:0 auto;
+ margin-bottom:30px;
+ top:1%;
+ left:10px;
+}
+
+
+
+.image{padding:2px;text-align:center;background: -webkit-gradient(linear, left top, left bottom, from(#FEFEFE), to(#E8E8E8));}
+
+
+
+.instafont {
+ margin-top: -60px;
+ margin-bottom: 5px;
+ margin-left:10px;
+ width:320px;
+ text-align:center;
+ padding:2px;
+ font-family: 'Fredericka the Great', cursive;
+ font-size:50px;
+}
+
+
+
+#instagram-farm-container{
+ margin-top:100px;
+ top:10px;
+ white-space:nowrap;
+ left:0px;
+}
+
+
+#instagram-farm-container ul{
+list-style-type: none;
+margin: 0;
+padding: 0;
+}
+
+#instagram-farm-container li{
+ display: inline-block;
+ position:relative;
+ height: inherit;
+}
+
+#instagram-farm-container img {
+ display: inline-block;
+ height:150px;
+ -webkit-transition:all 0.7s;
+ box-shadow:1px 1px 9px #000;
+ margin-left:6px;
+
+}
+
+
+#instagram-farm-container img:hover {
+ height:250px;
+ -webkit-transition:all 0.7s;
+}
View
37 mojits/instagram/binders/index.js
@@ -29,22 +29,43 @@ YUI.add('instagramBinderIndex', function(Y, NAME) {
/**
* The binder method, invoked to allow the mojit to attach DOM event
* handlers.
- *
+ * ***INSTAGTAM**** ***INSTAGTAM**** ***INSTAGTAM**** ***INSTAGTAM**** ***INSTAGTAM**** ***INSTAGTAM**** ***INSTAGTAM**** ***INSTAGTAM***
* @param node {Node} The DOM node to which this mojit is attached.
*/
bind: function(node) {
var me = this;
+ var args;
this.node = node;
- node.all('dt').on('mouseenter', function(evt) {
- var dd = '#dd_' + evt.target.get('text');
- me.node.one(dd).addClass('sel');
+ Y.on('SEARCH_UPDATE', function(e, search) {
+ //alert(search.val);
+ console.log('on SEARCH_UPDATE:Instagram'+search.val);
+ args = {params: {route: {
+ searchTerm:search.val,
+ numofImages:(search.num || 10)}
+ }};
+ this.mojitProxy.refreshView(args);
+ }, this);
+
+ var scrollview_bookmarked_friends = new Y.ScrollView({
+ srcNode:this.node.one('#instagram-farm-container'),
+ deceleration: 0.9,
+ bounce:0.1,
+ flick: {
+ minDistance:10,
+ minVelocity:0.1,
+ axis: "y"
+ }
});
- node.all('dt').on('mouseleave', function(evt) {
- var dd = '#dd_' + evt.target.get('text');
- me.node.one(dd).removeClass('sel');
+ setTimeout(function(){
+ scrollview_bookmarked_friends.syncUI();
+ },4000);
+ scrollview_bookmarked_friends.render();
+ Y.on('resize', function (e) {
+ scrollview_bookmarked_friends.syncUI();
});
+
}
};
-}, '0.0.1', {requires: ['event-mouseenter', 'mojito-client']});
+}, '0.0.1', {requires: ['event-mouseenter', 'mojito-client', 'cookie','scrollview','scrollview-base', 'scrollview-paginator']});
View
90 mojits/instagram/controller.server.js
@@ -29,19 +29,91 @@ YUI.add('instagram', function(Y, NAME) {
* to the Mojito API.
*/
index: function(ac) {
- ac.models.instagramModelFoo.getData(function(err, data) {
- if (err) {
- ac.error(err);
- return;
- }
- ac.assets.addCss('./index.css');
- ac.done({
- status: 'Mojito is working.',
- data: data
+
+ ac.assets.addCss('./index.css');
+ var defaultnumofImages = 10;
+ var searchTerm = ac.params.getFromRoute('searchTerm')||'yahoo';
+ var numofImages = ac.params.getFromRoute('numofImages')|| defaultnumofImages;
+
+ console.log('access_code_instagram');
+ var code = ac.params.getFromUrl('code');
+
+
+ var instagram_accesstoken_url = 'https://api.instagram.com/oauth/access_token';
+
+ var params = {
+ client_id:'8f3ceb4a6aba4f9c8e699586de0c62b9',
+ client_secret:'477641c717464cb88f3223a55c7c7018',
+ grant_type:'authorization_code',
+ redirect_uri:'http://fatherbanker.corp.yahoo.com:8001/',
+ code:code
+ };
+ console.log('access_token');
+ console.log(instagram_accesstoken_url);
+ var self = this;
+ if(!ac.cookie.get('access_token')){
+ Y.mojito.lib.REST.POST(instagram_accesstoken_url, params, {}, function(err,response) {
+ if (err) {
+ console.log(err);
+ ac.done({error:{},login:{}});
+ }
+ else if(response) {
+ var rsp_txt = response._resp.responseText;
+
+ var access_token = Y.JSON.parse(rsp_txt).access_token;
+ console.log(access_token);
+ ac.cookie.set('access_token',access_token);
+ self.getPhotos(ac,searchTerm,numofImages,access_token);
+ } else {
+ ac.done({error:{msg:'Instagram fail!'}});
+ }
});
+
+ } else{
+
+ this.getPhotos(ac,searchTerm,numofImages,ac.cookie.get('access_token'));
+ }
+ },
+
+ getPhotos:function(ac,searchTerm,numofImages,access_token) {
+ console.log('cookieACcess_token:'+access_token);
+ var self = this;
+ ac.models.instagramModelFoo.getData(searchTerm,access_token,function(err, data) {
+ if(err){
+ ac.done({error:err});
+ }
+ else if(data){
+ jsonData = Y.JSON.parse(data._resp.responseText);
+ //console.log(jsonData);
+ var imageData = jsonData.data;
+
+
+ imageData = self.processImages(imageData,numofImages);
+ console.log(imageData[0]);
+
+ ac.done({instagram:imageData});
+ } else{
+ ac.done({});
+ }
});
+ },
+
+ processImages: function(imgs,n){
+ var nimgs = [];
+ if(n>=imgs.length)
+ return imgs;
+
+ for(i=0;i<n;i++){
+ nimgs[i] = imgs[i];
+ }
+ return nimgs;
+
+
}
+
+
+
};
}, '0.0.1', {requires: ['mojito', 'instagramModelFoo']});
View
37 mojits/instagram/models/foo.server.js
@@ -28,10 +28,41 @@ YUI.add('instagramModelFoo', function(Y, NAME) {
* @param callback {function(err,data)} The callback function to call when the
* data has been retrieved.
*/
- getData: function(callback) {
- callback(null, { some: 'data' });
+ getData: function(searchTerm,access_token,callback) {
+ //https://api.instagram.com/v1/media/popular?client_id=8f3ceb4a6aba4f9c8e699586de0c62b9
+
+ //var numofimages = num ;
+ searchTerm = encodeURIComponent(searchTerm);
+
+ //var query = 'https://api.instagram.com/v1/media/popular?client_id=8f3ceb4a6aba4f9c8e699586de0c62b9';
+ //var query = 'https://api.instagram.com/v1/tags/search?q='+searchTerm+access_token;
+
+ var query = 'https://api.instagram.com/v1/tags/'+searchTerm+'/media/recent?access_token='+access_token;
+ //var query = 'https://api.instagram.com/v1/tags/london/media/recent?client_id=8f3ceb4a6aba4f9c8e699586de0c62b9'+access_token;
+ console.log(query);
+
+ function handler(err,response) {
+ if(err){
+ console.log('Instagram errror');
+ console.log(err);
+ return callback(err, null);
+ } else if(response){
+ console.log('Instagram response');
+ //console.log(response);
+ return callback(null,response);
+ }else {
+ console.log('no results or query failed');
+ return callback(null, null);
+ }
+ }
+ try{
+ Y.mojito.lib.REST.GET(query, {}, {}, handler);
+ }catch (err){
+ throw err;
+ }
+
}
};
-}, '0.0.1', {requires: []});
+}, '0.0.1', {requires: ['mojito','mojito-rest-lib', 'json-parse','cookie']});
View
40 mojits/instagram/views/index.mu.html
@@ -1,10 +1,32 @@
-<div id="{{mojit_view_id}}">
- <dl>
- <dt>status</dt>
- <dd id="dd_status">{{status}}</dd>
- <dt>data</dt>
- <dd id="dd_data">
- <b>some:</b> {{#data}}{{some}}{{/data}}
- </dd>
- </dl>
+<div id="{{mojit_view_id}}" class="instagram">
+ <h1 style="display:none;" class="splash">Instagram:{{searchTerm}}</h1>
+
+ {{#login}}
+ <a href='https://instagram.com/oauth/authorize/?client_id=8f3ceb4a6aba4f9c8e699586de0c62b9&redirect_uri=http://fatherbanker.corp.yahoo.com:8001/&response_type=code' class="splash">LOGIN INSTAGRAM </a>
+ {{/login}}
+
+
+ <div id='instagram-farm-container'>
+ <h2 class='instafont'> Instagram</h2>
+ <ul>
+ {{#instagram}}
+
+ {{#images}}
+ <li>
+ {{#standard_resolution}}
+ <div class="image">
+ <a href='{{url}}' target="_blank">
+ <img title='{{created_time}}' src='{{url}}' />
+ </a>
+ </div>
+ {{/standard_resolution}}
+ </li>
+ {{/images}}
+ {{/instagram}}
+ </ul>
+ </div>
+
+ {{#error}}
+ {{msg}}
+ {{/error}}
</div>
View
13 mojits/main/views/index.mu.html
@@ -1,10 +1,7 @@
-<div id="{{mojit_view_id}}">
-
-{{{login}}}
-{{{gmap}}}
-{{{twitter}}}
-{{{weather}}}
-{{{checkin}}}
-
+<link href='http://fonts.googleapis.com/css?family=Fredericka+the+Great' rel='stylesheet' type='text/css'>
+<div id="{{mojit_view_id}}">
+{{{instagram}}}
+{{{flickr}}}
+{{{search}}}
</div>
View
56 mojits/search/assets/index.css
@@ -0,0 +1,56 @@
+.univ-search {
+ position:relative;
+ margin:0 auto;
+ margin-top:10px;
+ margin:0 auto;
+ margin-left:100px;
+ margin-right:20px;
+ margin-top:5px;
+}
+
+#searchfont{
+ text-align:center;
+ padding:2px;
+ font-family: 'Fredericka the Great', cursive;
+ font-size:35px;
+}
+
+
+
+#numofImages{
+ text-align:center;
+ padding:2px;
+ font-family: 'Fredericka the Great', cursive;
+ font-size:35px !important;
+ border-radius: 3px;
+ display:inline-block;
+ width: 50px;
+ height: 50px;
+ text-align: center;
+ font-size: 1.6em;
+ background:none;
+ border:1px solid #ccc;
+ background:#fff;
+}
+
+
+#search-box {
+
+ z-index:1000;
+ border-radius: 6px;
+ border: 4px solid #ddd;
+ width:400px;
+ height:50px;
+ font-size:1.0em;
+ color:#555;
+ font-weight:bold;
+ padding:7px;
+ -webkit-transition:all 0.9s;
+ outline:none;
+}
+
+#search-box:hover{
+ box-shadow: 7px 7px 6px rgba(68, 68, 68, 0.22);
+ -webkit-transition:all 0.9s;
+}
+
View
94 mojits/search/binders/index.js
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2012 Yahoo! Inc. All rights reserved.
+ */
+/*jslint anon:true, sloppy:true, nomen:true*/
+YUI.add('searchBinderIndex', function(Y, NAME) {
+
+/**
+ * The searchBinderIndex module.
+ *
+ * @module searchBinderIndex
+ */
+
+ /**
+ * Constructor for the searchBinderIndex class.
+ *
+ * @class searchBinderIndex
+ * @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 me = this;
+ this.node = node;
+ var self = this;
+ var num;
+
+
+
+ node.one('#numofImages').set('value',10);
+
+
+ num = node.one('#numofImages').get('value');
+ if(!num && num<=0 && num>20){
+ num=8;
+ }
+
+
+
+
+ node.one('#search-box').on('keypress',function(){
+ num = node.one('#numofImages').get('value');
+ if(num===null && num<=0 && num>20){
+ num=8;
+ }
+ Y.fire('SEARCH_UPDATE', {}, {
+ val:this.get('value'),
+ num:num
+ });
+ });
+
+ Y.on('key', function(e) {
+ num = node.one('#numofImages').get('value');
+ if(num===null && num<=0 && num>20){
+ num=8;
+ }
+ Y.fire('SEARCH_UPDATE', {}, {
+ val: node.one('#search-box').get('value'),
+ num:num
+ });
+ }, '#search-box', 'press:13');
+
+
+ node.one('#numofImages').on('keyup',function(){
+ num = node.one('#numofImages').get('value');
+ if(num===null && num<=0 && num>20){
+ num=8;
+ }
+ Y.fire('SEARCH_UPDATE', {}, {
+ val:node.one('#search-box').get('value'),
+ num:num
+ });
+ });
+
+
+
+ }
+
+ };
+
+}, '0.0.1', {requires: ['event-mouseenter', 'mojito-client','event-key']});
View
45 mojits/search/controller.server.js
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2012 Yahoo! Inc. All rights reserved.
+ */
+/*jslint anon:true, sloppy:true, nomen:true*/
+YUI.add('search', function(Y, NAME) {
+
+/**
+ * The search module.
+ *
+ * @module search
+ */
+
+ /**
+ * Constructor for the Controller class.
+ *
+ * @class Controller
+ * @constructor
+ */
+ Y.namespace('mojito.controllers')[NAME] = {
+
+ init: function(config) {
+ this.config = config;
+ },
+
+ /**
+ * Method corresponding to the 'index' action.
+ *
+ * @param ac {Object} The ActionContext that provides access
+ * to the Mojito API.
+ */
+ index: function(ac) {
+ ac.models.searchModelFoo.getData(function(err, data) {
+ if (err) {
+ ac.error(err);
+ return;
+ }
+ });
+
+ ac.assets.addCss('./index.css');
+ ac.done();
+ }
+
+ };
+
+}, '0.0.1', {requires: ['mojito', 'searchModelFoo']});
View
5 mojits/search/definition.json
@@ -0,0 +1,5 @@
+[
+ {
+ "settings": [ "master" ]
+ }
+]
View
37 mojits/search/models/foo.server.js
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2012 Yahoo! Inc. All rights reserved.
+ */
+/*jslint anon:true, sloppy:true, nomen:true*/
+YUI.add('searchModelFoo', function(Y, NAME) {
+
+/**
+ * The searchModelFoo module.
+ *
+ * @module search
+ */
+
+ /**
+ * Constructor for the searchModelFoo class.
+ *
+ * @class searchModelFoo
+ * @constructor
+ */
+ Y.namespace('mojito.models')[NAME] = {
+
+ init: function(config) {
+ this.config = config;
+ },
+
+ /**
+ * Method that will be invoked by the mojit controller to obtain data.
+ *
+ * @param callback {function(err,data)} The callback function to call when the
+ * data has been retrieved.
+ */
+ getData: function(callback) {
+ callback(null, { some: 'data' });
+ }
+
+ };
+
+}, '0.0.1', {requires: []});
View
37 mojits/search/tests/binders/index.common-tests.js
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2012 Yahoo! Inc. All rights reserved.
+ */
+YUI.add('searchBinderIndex-tests', function(Y, NAME) {
+
+ var suite = new YUITest.TestSuite(NAME),
+ binder,
+ A = YUITest.Assert;
+
+ suite.add(new YUITest.TestCase({
+
+ name: 'search index binder tests',
+
+ setUp: function() {
+ binder = Y.mojito.binders.searchBinderIndex;
+ },
+ tearDown: function() {
+ binder = null;
+ },
+
+ 'TODO: test update id': function() {
+ var node = Y.Node.create("<div id='guid123'></div>");
+ binder.init({
+ _guid: 'guid123'
+ });
+ binder.bind(node);
+
+ // there is nothing to test in the binder initially
+ A.skip();
+
+ }
+
+ }));
+
+ YUITest.TestRunner.add(suite);
+
+}, '0.0.1', {requires: ['mojito-test', 'node', 'searchBinderIndex']});
View
62 mojits/search/tests/controller.server-tests.js
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2012 Yahoo! Inc. All rights reserved.
+ */
+
+YUI.add('search-tests', function(Y) {
+
+ var suite = new YUITest.TestSuite('search-tests'),
+ controller = null,
+ A = YUITest.Assert;
+
+ suite.add(new YUITest.TestCase({
+
+ name: 'search user tests',
+
+ setUp: function() {
+ controller = Y.mojito.controllers.search;
+ },
+ tearDown: function() {
+ controller = null;
+ },
+
+ 'test mojit': function() {
+ var ac,
+ modelData,
+ assetsResults,
+ doneResults;
+ modelData = { x:'y' };
+ ac = {
+ assets: {
+ addCss: function(css) {
+ assetsResults = css;
+ }
+ },
+ models: {
+ searchModelFoo: {
+ getData: function(cb) {
+ cb(null, modelData);
+ }
+ }
+ },
+ done: function(data) {
+ doneResults = data;
+ }
+ };
+
+ A.isNotNull(controller);
+ A.isFunction(controller.index);
+ controller.index(ac);
+ A.areSame('./index.css', assetsResults);
+ A.isObject(doneResults);
+ A.areSame('Mojito is working.', doneResults.status);
+ A.isObject(doneResults.data);
+ A.isTrue(doneResults.data.hasOwnProperty('x'));
+ A.areEqual('y', doneResults.data['x']);
+
+ }
+
+ }));
+
+ YUITest.TestRunner.add(suite);
+
+}, '0.0.1', {requires: ['mojito-test', 'search']});
View
39 mojits/search/tests/models/foo.server-tests.js
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2012 Yahoo! Inc. All rights reserved.
+ */
+
+YUI.add('searchModelFoo-tests', function(Y, NAME) {
+
+ var suite = new YUITest.TestSuite(NAME),
+ model = null,
+ A = YUITest.Assert;
+
+ suite.add(new YUITest.TestCase({
+
+ name: 'searchModelFoo user tests',
+
+ setUp: function() {
+ model = Y.mojito.models.searchModelFoo;
+ },
+ tearDown: function() {
+ model = null;
+ },
+
+ 'test mojit model': function() {
+ var called = false;
+ A.isNotNull(model);
+ A.isFunction(model.getData);
+ model.getData(function(err, data) {
+ called = true;
+ A.isTrue(!err);
+ A.isObject(data);
+ A.areSame('data', data.some);
+ });
+ A.isTrue(called);
+ }
+
+ }));
+
+ YUITest.TestRunner.add(suite);
+
+}, '0.0.1', {requires: ['mojito-test', 'searchModelFoo']});
View
5 mojits/search/views/index.mu.html
@@ -0,0 +1,5 @@
+<div id="{{mojit_view_id}}" class="univ-search">
+ <span id='searchfont'> Search <input id="search-box" type="text" /> </span>
+ <span id='searchfont'>Showing <input id="numofImages" type="text" /> Images </span>
+
+</div>
Please sign in to comment.
Something went wrong with that request. Please try again.