1/*! 2 3 Name: Instagram Lite 4 Dependencies: jQuery 5 Author: Michael Lynch 6 Author URL: http://michaelynch.com 7 Date Created: January 14, 2014 8 Licensed under the MIT license 9 10 */ 11 12;(function($) { 13 14 $.fn.instagramLite = function(options) { 15 16 // return if no element was bound 17 // so chained events can continue 18 if(!this.length) { 19 return this; 20 } 21 22 // define plugin 23 plugin = this; 24 25 // define default parameters 26 plugin.defaults = { 27 accessToken: null, 28 limit: null, 29 list: true, 30 videos: false, 31 urls: false, 32 captions: false, 33 date: false, 34 likes: false, 35 comments_count: false, 36 element_class: '', 37 error: function() {}, 38 success: function() {} 39 } 40 41 // vars 42 var s = $.extend({}, plugin.defaults, options), 43 el = $(this); 44 45 var formatCaption = function(caption) { 46 47 var words = caption.split(' '), 48 newCaption = ''; 49 50 for(var i = 0; i < words.length; i++) { 51 52 var word; 53 54 if(words[i][0] == '@') { 55 var a = '<a href="http://twitter.com/'+words[i].replace('@', '').toLowerCase()+'" target="_blank" rel="noopener noreferrer">'+words[i]+'</a>'; 56 word = a; 57 } else if(words[i][0] == '#') { 58 var a = '<a href="http://twitter.com/hashtag/'+words[i].replace('#', '').toLowerCase()+'" target="_blank" rel="noopener noreferrer">'+words[i]+'</a>'; 59 word = a; 60 } else { 61 word = words[i] 62 } 63 64 newCaption += word + ' '; 65 } 66 67 return newCaption; 68 69 }; 70 71 var constructMedia = function(data) { 72 73 // for each piece of media returned 74 for(var i = 0; i < data.length; i++) { 75 76 // define media namespace 77 var thisMedia = data[i], 78 item; 79 80 // if media type is image or videos is set to false 81 if(thisMedia.type === 'image' || !s.videos) { 82 83 // construct image 84 item = '<img class="il-photo__img" src="'+thisMedia.images.standard_resolution.url+'" alt="Instagram Image" data-filter="'+thisMedia.filter+'" />'; 85 86 87 item += '<span class="il-photo__meta">'; 88 89 if(s.captions || s.date || s.likes || s.comments_count) { 90 item += '<span class="il-photo__metainner">'; 91 } 92 93 // if caption setting is true 94 if(s.captions && thisMedia.caption) { 95 item += '<span class="il-photo__caption" data-caption-id="'+thisMedia.caption.id+'">'+formatCaption(thisMedia.caption.text)+'</span>'; 96 } 97 98 // if date setting is true 99 if(s.date) { 100 101 var date = new Date(thisMedia.created_time * 1000), 102 day = date.getDate(), 103 month = date.getMonth() + 1, 104 year = date.getFullYear(), 105 hours = date.getHours(), 106 minutes = date.getMinutes(), 107 seconds = date.getSeconds(); 108 109 date = month +'/'+ day +'/'+ year; 110 111 item += '<span class="il-photo__date">'+date+'</span>'; 112 } 113 114 // if likes setting is true 115 if(s.likes) { 116 item += '<span class="il-photo__likes"><i class="fa fa-heart-o"></i> '+thisMedia.likes.count+'</span>'; 117 } 118 119 // if caption setting is true 120 if(s.comments_count && thisMedia.comments) { 121 item += '<span class="il-photo__comments"><i class="fa fa-comments-o"></i> '+thisMedia.comments.count+'</span>'; 122 } 123 124 if(s.captions || s.date || s.likes || s.comments_count) { 125 item += '</span>'; 126 } 127 128 item += '</span>'; 129 130 // if url setting is true 131 if(s.urls) { 132 item = '<a href="'+thisMedia.link+'" target="_blank" rel="noopener noreferrer">'+item+'</a>'; 133 } 134 } 135 136 if(thisMedia.type === 'video' && s.videos) { 137 138 if(thisMedia.videos) { 139 140 var src; 141 142 if(thisMedia.videos.standard_resolution) { 143 src = thisMedia.videos.standard_resolution.url; 144 } else if(thisMedia.videos.low_resolution) { 145 src = thisMedia.videos.low_resolution.url; 146 } else if(thisMedia.videos.low_bandwidth) { 147 src = thisMedia.videos.low_bandwidth.url; 148 } 149 150 item = '<video poster="'+thisMedia.images.standard_resolution.url+'" controls>'; 151 item += '<source src="'+src+'" type="video/mp4;"></source>'; 152 item += '</video>'; 153 } 154 } 155 156 // if list setting is true 157 if(s.list && item) { 158 159 // redefine item with wrapping list item 160 item = '<div class="il-item ' + s.element_class + '" data-instagram-id="'+thisMedia.id+'"><div class="il-item-inner">'+item+'</div></div>'; 161 } 162 163 // append image / video 164 if(item !== '') { 165 el.append(item); 166 } 167 } 168 } 169 170 var loadContent = function() { 171 172 // if access token 173 if(s.accessToken) { 174 175 // construct API endpoint 176 var url = 'https://api.instagram.com/v1/users/self/media/recent/?access_token='+s.accessToken+'&count='+s.limit; 177 178 $.ajax({ 179 type: 'GET', 180 url: url, 181 dataType: 'jsonp', 182 success: function(data) { 183 184 // if success status 185 if(data.meta.code === 200 && data.data.length) { 186 187 // construct media 188 constructMedia(data.data); 189 190 // execute success callback 191 s.success.call(this); 192 193 } else { 194 // execute error callback 195 s.error.call(this); 196 } 197 }, 198 error: function() { 199 // execute error callback 200 s.error.call(this); 201 } 202 }); 203 } 204 } 205 206 // init 207 loadContent(); 208 } 209})(jQuery);
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.