Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: chrome/test/data/extensions/platform_apps/ad_view/ad_network_loaded/display_ad.js

Issue 12463015: Enable <adview> tag for packaged apps. (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: Rebasing Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 (function( window ) {
asargent_no_longer_on_chrome 2013/03/11 19:10:14 nit: Any reason you pass in window as a parameter
rpaquay 2013/03/12 19:56:48 Done.
2 "use strict";
3
4 var document = window.document;
5
6 // Random data
7 var publisher_data = {
8 id: "rpaquay_ads",
9 js: "afma-sdk-i-v6.2.0",
10 extras: {
11 color_text: "Red",
12 color_bg: "Default"
13 },
14 };
15
16 var timeout_sequence_id = 0;
asargent_no_longer_on_chrome 2013/03/11 19:10:14 style nit: we use variableNamesLikeThis for JS cod
rpaquay 2013/03/12 19:56:48 Done.
17 function displayStatus(statusText) {
18 timeout_sequence_id++;
19
20 var div = document.getElementById("my-status");
21 div.textContent = statusText;
22
23 var sequence_id = timeout_sequence_id;
24 setTimeout(function() {
25 if (sequence_id === timeout_sequence_id) {
26 div.textContent = "";
27 }
28 }, 15000);
29 }
30
31 function adDisplayed(source, appMessage) {
32 var adview = document.getElementById("my-adview");
33 adview.style.height = appMessage.data.ad_size.height;
34
35 displayStatus("Ad displayed( " + appMessage.sequence_number + "): " +
36 "height=" + appMessage.data.ad_size.height);
37 }
38
39 function adClicked(source, appMessage) {
40 displayStatus("Ad clicked(" + appMmessage.sequence_number + "): " +
41 "publisher id=" + appMessage.publisher_data.id);
42 }
43
44 function processAppMessage(source, appMessage) {
45 if (appMessage.message == "ad-displayed") {
46 adDisplayed(source, appMessage);
47 }
48 if (appMessage.message == "ad-clicked") {
49 adClicked(source, appMessage);
50 }
51 }
52
53 //
54 // Process 'message' event
55 //
56 function onPostMessage(event) {
57 processAppMessage(event.source, event.data);
58 }
59
60 //
61 // Process "DOMContentLoader" event.
62 //
63 function onDocumentReady() {
64 var button = document.getElementById('display-ad');
65 var adview = document.getElementById("my-adview");
66
67 // Enable "Display Ad" button when the adview content is loaded
68 adview.addEventListener('loadcommit', function() {
69 button.disabled = false;
70 button.value = "Display Ad";
71 button.addEventListener('click', function () {
72 adview.contentWindow.postMessage({
73 'message': "display-ad",
74 'publisher_data': publisher_data
75 }, "*");
76 }, false);
77 });
78 }
79
80 //
81 // Add global event listeners.
82 //
83 window.addEventListener("message", onPostMessage, false);
84 document.addEventListener('DOMContentLoaded', onDocumentReady, false);
85
86 })(window);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698