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 = jQuery(elem); 33 34 self.api = 'https://api.instagram.com/v1', 35 36 self.accessData = jQuery.fn.spectragram.accessData, 37 38 self.options = jQuery.extend({}, jQuery.fn.spectragram.options, options); 39 }, 40 41 //Users 42 //Get the most recent media published by a user. 43 getRecentMedia: function (count) { 44 var self = this, 45 getData = '/users/self/media/recent/?access_token='+ self.accessData.accessToken +'&count='+ count; 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 self.getRecentMedia(self.options.max); 56 }, 57 58 //Media 59 //Get a list of what media is most popular at the moment 60 getPopular: function () { 61 var self = this, 62 getData = '/media/popular?client_id=' + self.accessData.clientID + '&access_token='+ self.accessData.accessToken + ''; 63 64 self.fetch(getData).done(function ( results ) { 65 self.display(results); 66 }); 67 }, 68 69 //Tags 70 //Get a list of recently tagged media 71 getRecentTagged: function () { 72 var self = this, 73 getData = '/tags/' + self.options.query + '/media/recent?client_id=' + self.accessData.clientID + '&access_token='+ self.accessData.accessToken + ''; 74 75 self.fetch(getData).done(function ( results ) { 76 if(results.data.length){ 77 self.display(results); 78 }else{ 79 jQuery.error('Spectagram.js - Error: the tag ' + self.options.query + ' does not have results.'); 80 }; 81 }); 82 }, 83 84 fetch: function (getData) { 85 var self = this, 86 getUrl = self.api + getData; 87 88 return jQuery.ajax({ 89 type: "GET", 90 dataType: "jsonp", 91 cache: false, 92 url: getUrl 93 }); 94 }, 95 96 display: function (results) { 97 var self = this, 98 setSize = self.options.size, 99 size, max = (self.options.max >= results.data.length) ? results.data.length : self.options.max; 100 101 if (results.data.length === 0) { 102 self.$elem.append(jQuery(self.options.wrapEachWith).append(self.options.notFoundMsg)); 103 } 104 else { 105 for (var i = 0; i < max; i++) { 106 if (setSize == "small") { 107 size = results.data[i].images.thumbnail.url; 108 } 109 else if (setSize == "medium") { 110 size = results.data[i].images.low_resolution.url; 111 } 112 else { 113 size = results.data[i].images.standard_resolution.url; 114 } 115 116 var titleIMG; 117 // Skip if the caption is empty. 118 if ( results.data[i].caption != null ) { 119 /** 120 * 1. First it creates a dummy element <span/> 121 * 2. And then puts the caption inside the element created previously. 122 * 3. Extracts the html caption (this allows html codes to be included). 123 * 4. Lastly, the most important part, create the Title attribute using double quotes 124 * to enclose the text. This fixes the bug when the caption retrieved from Instagram 125 * includes single quotes which breaks the Title attribute. 126 */ 127 titleIMG = 'title="' + jQuery('<span/>').text(results.data[i].caption.text).html() +'"'; 128 } 129 130 // Now concatenate the titleIMG generated. 131 self.$elem.append(jQuery(self.options.wrapEachWith).append("<a " + titleIMG + " target='_blank' href='" + results.data[i].link + "'><img src='" + size + "'></img></a>")); 132 } 133 } 134 135 if (typeof self.options.complete === 'function') { 136 self.options.complete.call(self); 137 } 138 } 139 }; 140 141 jQuery.fn.spectragram = function ( method, options ) { 142 143 if(jQuery.fn.spectragram.accessData.clientID){ 144 145 this.each( function () { 146 var instagram = Object.create( Instagram ); 147 instagram.init( options, this ); 148 if( instagram[method] ) { 149 return instagram[method]( this ); 150 }else{ 151 jQuery.error( 'Method ' + method + ' does not exist on jQuery.spectragram' ); 152 } 153 }); 154 155 }else{ 156 jQuery.error( 'You must define an accessToken and a clientID on jQuery.spectragram' ); 157 } 158 }; 159 160 //Plugin Default Options 161 jQuery.fn.spectragram.options = { 162 max: 10, 163 query: 'coffee', 164 size: 'medium', 165 wrapEachWith: '<li></li>', 166 complete : null 167 }; 168 169 //Instagram Access Data 170 jQuery.fn.spectragram.accessData = { 171 accessToken: null, 172 clientID: null 173 }; 174 175})(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.