'),
// Configures and renders a scrollable DPP container.
//
render : function() {
this.key = 'dpp_instance_' + DPPCounter;
// Each DPP render will be wrapped in a container with a unique id
var $root = $('', { 'id': this.key }).addClass('dpp root');
// Alleviate weird Chrome/non-retina display bug
if (!!window.chrome && !!window.chrome.webstore) {
$root.css({
'transform': 'translateZ(1px)'
});
};
$root.appendTo(this.$wrap);
// Establish a list to add ad button items to
var $list = $('').addClass('dpp items');
// Establish a ist item template, to clone
var $itemTemplate = $('').addClass('dpp item');
// Create generic 'Weekly Ads' label for `on load` display and interleaving
var $labelItem = $itemTemplate.clone();
$('
', { 'src': 'http://stmedia.startribune.com/images/weeklyAdsLabel.png' })
.addClass('dpp')
.appendTo(
$('', { 'href': 'http://www.startribune.com/weekly-ads' })
.appendTo($labelItem)
);
// In reverse, due to `appendTo` use, place ad buttons in our list
var revArr = ad_AdvertiserArray.data.reverse();
for (var i = 0; i ', { 'src': adData.nav_button })
.addClass('dpp')
.appendTo(
$('', { 'href': 'http://www.startribune.com/weekly-ads/?dppAID=' + adId })
.appendTo($buttonItem)
);
$buttonItem
.appendTo($list);
// Interleave the generic label as well
$labelItem.clone(true)
.appendTo($list);
};
// Prepend generic label for `on load` display
$labelItem.prependTo($list);
// Create the scrollable scaffold:
var $dppTemplate = $('')
.addClass('dpp container')
.appendTo($root);
$list
.appendTo(
$('')
.addClass('dpp viewport')
.appendTo($dppTemplate)
);
// Render the result
document.write(this.$wrap.html());
// Kick off w/ delay
this._start();
},
// Initiates scrolling with a start delay.
//
_start : function() {
var scope = this;
this.timer = window.setTimeout(
function() {
scope._cycle(scope);
}, this.startAt );
},
// Scrolling cycle.
//
_cycle : function( scope ) {
clearTimeout(scope.timer);
this.timer = setInterval( function() {
scope._animate(scope);
}, scope.cycleAt );
},
// The actual scrolling applied to list items.
//
_animate : function( scope ) {
var isScope = $('#' + scope.key + ' ul');
if(isScope){
var $list = $('#' + scope.key + ' ul').first();
if ( Math.abs(parseInt($list.css('left'), 10)) + 98 >= ($list.children().length - 1) * 98 ) {
$list.css('left', '-98px');
};
$list.animate({ left: '-=98' }, 500);
}
},
};
DPP.render();
})();
< Prev | Next > |
---|