-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
glade ad element with a single gladeReady listener #2
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<!-- | ||
@license | ||
Copyright (c) 2016 The Polymer Project Authors. All rights reserved. | ||
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt | ||
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | ||
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt | ||
Code distributed by Google as part of the polymer project is also | ||
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt | ||
--> | ||
<link rel="import" href="/bower_components/polymer/polymer.html"> | ||
<dom-module id="glade-ad"> | ||
<template> | ||
<style> | ||
:host { | ||
display: block; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
</style> | ||
<div class="ad_slot_placeholder"></div> | ||
</div> | ||
</template> | ||
<script> | ||
(function() { | ||
var ad_slot; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is used anywhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Left over from playing :) Fixed. |
||
var gladeReady = !!(window.glade && window.glade.run); // Maybe Glade has already loaded? | ||
var elementsWaitingForGlade = []; | ||
if (!gladeReady) { | ||
window.addEventListener('gladeReady', function listener() { | ||
window.removeEventListener('gladeReady', listener); | ||
gladeReady = true; | ||
for (var i = 0; i < elementsWaitingForGlade.length; i++) { | ||
elementsWaitingForGlade[i]._load(); | ||
} | ||
}); | ||
} | ||
|
||
Polymer({ | ||
is: 'glade-ad', | ||
properties: { | ||
adSlotId: { | ||
type: String, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Properties that only specify There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, much nicer! |
||
dataAdUnitPath: { | ||
type: String | ||
}, | ||
width: { | ||
type: String | ||
}, | ||
height: { | ||
type: String | ||
}, | ||
dataClickUrl: { | ||
type: String | ||
}, | ||
dataPageUrl: { | ||
type: String | ||
}, | ||
dataJson: { | ||
type: String | ||
} | ||
}, | ||
|
||
observers: [ | ||
'propertiesChanged(adSlotId, dataAdUnitPath, width, height)' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
(tangent) If I remember correctly, all of the attributes will have been set to their respective properties by the time There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it; removing the observers list. |
||
], | ||
|
||
ready: function() { | ||
if (gladeReady) { | ||
this._load(); | ||
} else { | ||
elementsWaitingForGlade.push(this); | ||
} | ||
}, | ||
|
||
_load: function() { | ||
Polymer.RenderStatus.afterNextRender(this, function() { | ||
|
||
var ad_slot = Polymer.dom(this.root).querySelector(".ad_slot_placeholder"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nicer too :) |
||
ad_slot.id = this.adSlotId; | ||
ad_slot.setAttribute("data-ad-unit-path", this.dataAdUnitPath); | ||
ad_slot.setAttribute("width", this.width); | ||
ad_slot.setAttribute("height", this.height); | ||
|
||
if (this.dataClickUrl) { | ||
ad_slot.setAttribute("data-click-url", this.dataClickUrl); | ||
} | ||
|
||
if (this.dataPageUrl) { | ||
ad_slot.setAttribute("data-page-url", this.dataPageUrl); | ||
} | ||
|
||
if (this.dataJson) { | ||
ad_slot.setAttribute("data-json", this.dataJson); | ||
} | ||
|
||
glade.run(ad_slot); | ||
}); | ||
}, | ||
}); | ||
})(); | ||
</script> | ||
</dom-module> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra
</div>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops; fixed.