1/*! 2 * jQuery - Spectragram by Adrian Quevedo 3 * http://adrianquevedo.com/ - http://lab.adrianquevedo.com/ - http://elnucleo.com.co/ 4 * 5 * Dual licensed under the MIT or GPL Version 2 licenses. 6 * You are free to use this plugin in commercial projects as long as the copyright header is left intact. 7 * 8 * This plugin uses the Instagram(tm) API and is not endorsed or certified by Instagram or Burbn, inc. 9 * All Instagram(tm) logos and trademarks displayed on this plugin are property of Burbn, Inc. 10 * 11 * Date: Thu Jul 15 14:05:02 2012 -0500 12 */ 13 14// Utility for older browsers 15if (typeof Object.create !== 'function') { 16 Object.create = function (obj) { 17 function F() {}; 18 F.prototype = obj; 19 return new F(); 20 }; 21} 22 23(function ($, window, document, undefined) { 24 25 var Instagram = { 26 27 //Initialize function 28 init: function (options, elem) { 29 var self = this; 30 31 self.elem = elem; 32 self.$elem = $(elem); 33 34 self.api = 'https://api.instagram.com/v1', 35 36 self.accessData = $.fn.spectragram.accessData, 37 38 self.options = $.extend({}, $.fn.spectragram.options, options); 39 }, 40 41 //Users 42 //Get the most recent media published by a user. 43 getRecentMedia: function ( userID ) { 44 var self = this, 45 getData = '/users/' + userID + '/media/recent/?' + self.accessData.clientID + '&access_token='+ self.accessData.accessToken +''; 46 47 self.fetch(getData).done(function ( results ) { 48 self.display(results); 49 }); 50 }, 51 52 //Search for a user by name. 53 getUserFeed: function () { 54 var self = this, 55 getData = '/users/search?q=' + self.options.query + '&count=' + self.options.max + '&access_token='+ self.accessData.accessToken + ''; 56 57 self.fetch(getData).done(function ( results ) { 58 if(results.data.length){ 59 self.getRecentMedia(results.data[0].id); 60 }else{ 61 $.error('Spectagram.js - Error: the username ' + self.options.query + ' does not exist.'); 62 }; 63 }); 64 }, 65 66 //Media 67 //Get a list of what media is most popular at the moment 68 getPopular: function () { 69 var self = this, 70 getData = '/media/popular?client_id=' + self.accessData.clientID + '&access_token='+ self.accessData.accessToken + ''; 71 72 self.fetch(getData).done(function ( results ) { 73 self.display(results); 74 }); 75 }, 76 77 //Tags 78 //Get a list of recently tagged media 79 getRecentTagged: function () { 80 var self = this, 81 getData = '/tags/' + self.options.query + '/media/recent?client_id=' + self.accessData.clientID + '&access_token='+ self.accessData.accessToken + ''; 82 83 self.fetch(getData).done(function ( results ) { 84 if(results.data.length){ 85 self.display(results); 86 }else{ 87 $.error('Spectagram.js - Error: the tag ' + self.options.query + ' does not have results.'); 88 }; 89 }); 90 }, 91 92 fetch: function (getData) { 93 var self = this, 94 getUrl = self.api + getData; 95 96 return $.ajax({ 97 type: "GET", 98 dataType: "jsonp", 99 cache: false, 100 url: getUrl 101 }); 102 }, 103 104 display: function (results) { 105 var self = this, 106 setSize = self.options.size, 107 size, max = (self.options.max >= results.data.length) ? results.data.length : self.options.max; 108 109 if (results.data.length === 0) { 110 self.$elem.append($(self.options.wrapEachWith).append(self.options.notFoundMsg)); 111 } 112 else { 113 for (var i = 0; i < max; i++) { 114 if (setSize == "small") { 115 size = results.data[i].images.thumbnail.url; 116 } 117 else if (setSize == "medium") { 118 size = results.data[i].images.low_resolution.url; 119 } 120 else { 121 size = results.data[i].images.standard_resolution.url; 122 } 123 124 var titleIMG; 125 // Skip if the caption is empty. 126 if ( results.data[i].caption != null ) { 127 /** 128 * 1. First it creates a dummy element <span/> 129 * 2. And then puts the caption inside the element created previously. 130 * 3. Extracts the html caption (this allows html codes to be included). 131 * 4. Lastly, the most important part, create the Title attribute using double quotes 132 * to enclose the text. This fixes the bug when the caption retrieved from Instagram 133 * includes single quotes which breaks the Title attribute. 134 */ 135 titleIMG = 'title="' + $('<span/>').text(results.data[i].caption.text).html() +'"'; 136 } 137 138 // Now concatenate the titleIMG generated. 139 self.$elem.append($(self.options.wrapEachWith).append("<a " + titleIMG + " target='_blank' href='" + results.data[i].link + "'><img src='" + size + "'></img></a>")); 140 } 141 } 142 143 if (typeof self.options.complete === 'function') { 144 self.options.complete.call(self); 145 } 146 } 147 }; 148 149 jQuery.fn.spectragram = function ( method, options ) { 150 151 if(jQuery.fn.spectragram.accessData.clientID){ 152 153 this.each( function () { 154 var instagram = Object.create( Instagram ); 155 instagram.init( options, this ); 156 if( instagram[method] ) { 157 return instagram[method]( this ); 158 }else{ 159 $.error( 'Method ' + method + ' does not exist on jQuery.spectragram' ); 160 } 161 }); 162 163 }else{ 164 $.error( 'You must define an accessToken and a clientID on jQuery.spectragram' ); 165 } 166 }; 167 168 //Plugin Default Options 169 jQuery.fn.spectragram.options = { 170 max: 10, 171 query: 'coffee', 172 size: 'medium', 173 wrapEachWith: '<li></li>', 174 complete : null 175 }; 176
177 //Instagram Access Data 178 jQuery.fn.spectragram.accessData = { 179 accessToken: null, 180 clientID: null 181 }; 182 183})(jQuery, window, document);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.