1/* 2 Copyright (c) Microsoft Corporation. All rights reserved. 3 Licensed under the MIT License. See License.txt in the project root for license information. 4*/ 5 6(function(adx, $) { 7 "use strict"; 8 9 adx.Ad = (function() { 10 var Ad = function(element) { 11 this._element = $(element); 12 this.url = this._element.data("url"); 13 14 this._element.data("ad", this); 15 }; 16 17 Ad.prototype.init = function() { 18 var $this = this; 19 20 this._element.hide(); 21 retrieveAsync.call(this).then(function() { 22 render.call($this); 23 $this._element.trigger({ type: "adplacement_ready", adplacement: $this }); 24 }, function(e) { 25 fail.call($this, e); 26 }); 27 }; 28 29 var fail = function(e) { 30 if (console && console.error) { 31 console.error({ error: e, ad: this }); 32 } 33 } 34 35 var retrieveAsync = function() { 36 var $this = this; 37 var d = $.Deferred(); 38 39 if (this.url) { 40 $.ajax({ 41 url: this.url, 42 type: 'GET' 43 }).then(function(html) { 44 $this.html = $(html.trim()); 45 d.resolve(); 46 }, d.fail); 47 } else { 48 this.html = $(this._element.html().trim()); 49 d.resolve(); 50 } 51 52 return d.promise(); 53 }; 54 55 var render = function() { 56 this._element.html(this.html).show(); 57 58 this._element.trigger({ type: "ad_ready", ad: this }); 59 } 60 61 return Ad; 62 }()); 63 64 adx.AdPlacement = (function() { 65 var AdPlacement = function(element) { 66 this._element = $(element); 67 this.url = this._element.data("url"); 68 69 this._element.data("adplacement", this); 70 }; 71 72 AdPlacement.prototype.init = function() { 73 var $this = this; 74 75 $this._element.hide(); 76 retrieveAsync.call(this).then(function() { 77 render.call($this); 78 }, function(e) { 79 fail.call($this, e); 80 }); 81 }; 82 83 var fail = function(e) { 84 if (console && console.error) { 85 console.error({ error: e, ad: this }); 86 } 87 } 88 89 var retrieveAsync = function() { 90 var $this = this; 91 var d = $.Deferred(); 92 93 if (this.url) { 94 $.ajax({ 95 url: this.url, 96 type: 'GET', 97 async: true 98 }).then(function(html) { 99 $this.html = html; 100 d.resolve(); 101 }, d.fail); 102 } else { 103 this.html = $(this._element.html().trim()); 104 d.resolve(); 105 } 106 107 return d.promise(); 108 }; 109 110 var render = function() { 111 this._element.html(this.html).show(); 112 } 113 114 return AdPlacement; 115 }()); 116 117 $(document).ready(function() { 118 $(".ad").each(function() { 119 var ad = new adx.Ad(this); 120 ad.init(); 121 }); 122 123 $(".adplacement").each(function() { 124 $(this).on("adplacement_ready", function(e, args) { 125 console.log(e); 126 console.log(args); 127 }); 128 129 var placement = new adx.AdPlacement(this); 130 placement.init(); 131 }); 132 }); 133}(window.adx || (window.adx = {}), window.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.