|
| 1 | +var EmbedlyDemo = module.exports = function() { |
| 2 | + var self = this; |
| 3 | + var hashTagActive = ""; |
| 4 | + $('.embedly-button').on('click', function(e){ |
| 5 | + // e.preventDefault(); |
| 6 | + embedlyDemo = new EmbedlyDemo(); |
| 7 | + var url = $('#url').val(); |
| 8 | + var encodedUrl = encodeURIComponent(url); |
| 9 | + var requestUrl = "http://api.embed.ly/1/extract?key=4d990bca1808406aa35f798781bc2c9b&url=" + encodedUrl; |
| 10 | + return self.sendRequest(requestUrl); |
| 11 | + }); |
| 12 | +}; |
| 13 | + |
| 14 | +EmbedlyDemo.prototype.sendRequest = function(requestUrl) { |
| 15 | + var self = this; |
| 16 | + |
| 17 | + $('spinner').addClass('loading-circle'); |
| 18 | + $.ajax(requestUrl).success(function(data) { |
| 19 | + self.data = data; |
| 20 | + var display = data.content || data.media.html || data.description; |
| 21 | + var htmlTitle = "<div class='embedly-title'><h1>" + data.title + "</h1></div>"; |
| 22 | + var content = htmlTitle + "<div class='embedly-content'>" + display + "</div>"; |
| 23 | + self.appendContent(content); |
| 24 | + self.appendImages(data.images); |
| 25 | + $('.style-buttons').removeClass('hide'); |
| 26 | + }).error(function(data) { |
| 27 | + var errorMessage = '<p class="ajax-error">Content not found, please try again. Be sure to use the full url like this: "http://www.wizard.codes/the-winnower-api/" or " http://blog.us.playstation.com/2015/08/09/the-drop-new-playstation-games-for-8112015/ "'; |
| 28 | + self.appendContent(errorMessage); |
| 29 | + }).complete(function(){ |
| 30 | + $('spinner').removeClass('loading-circle'); |
| 31 | + }); |
| 32 | +}; |
| 33 | + |
| 34 | +EmbedlyDemo.prototype.getVideo = function(requestUrl) { |
| 35 | + var self = this; |
| 36 | + |
| 37 | + $('spinner').addClass('loading-circle'); |
| 38 | + $.ajax(requestUrl).success(function(data) { |
| 39 | + self.data = data; |
| 40 | + var htmlTitle = "<div class='embedly-title'><h1>" + data.title + "</h1></div>"; |
| 41 | + var content = htmlTitle + "<div class='embedly-content'>" + data.content + "</div>"; |
| 42 | + self.appendContent(content); |
| 43 | + }).error(function(data) { |
| 44 | + var errorMessage = '<p class="ajax-error">Content not found, please try again. Be sure to use the full url like this: "http://www.wizard.codes/the-winnower-api/" or " http://blog.us.playstation.com/2015/08/09/the-drop-new-playstation-games-for-8112015/ "'; |
| 45 | + self.appendContent(errorMessage); |
| 46 | + }).complete(function(){ |
| 47 | + $('spinner').removeClass('loading-circle'); |
| 48 | + }); |
| 49 | +}; |
| 50 | + |
| 51 | +EmbedlyDemo.prototype.appendContent = function(content) { |
| 52 | + $('.preview-content').empty(); |
| 53 | + $('.preview-content').append(content); |
| 54 | +}; |
| 55 | + |
| 56 | +EmbedlyDemo.prototype.appendImages = function(images) { |
| 57 | + var imageDivs = ""; |
| 58 | + $.each(images, function(index, image) { |
| 59 | + imageDivs += "<img class='thumbnail' src='" + image.url + "' />"; |
| 60 | + }); |
| 61 | + |
| 62 | + var galleryDiv = "<div class='image-gallery'><h3>Images</h3>" + imageDivs + "</div>"; |
| 63 | + $('.preview-content').append(galleryDiv); |
| 64 | +}; |
| 65 | + |
| 66 | +EmbedlyDemo.mount = function() { |
| 67 | + if ($('.embedly-button').get(0)) { |
| 68 | + embedlyDemo = new EmbedlyDemo(); |
| 69 | + } |
| 70 | + return embedlyDemo; |
| 71 | +}; |
0 commit comments