msnbc.modules.DefaultText = msnbc.modules.Module.extend({ setup: function(data, container){ this.SHORT_NAME = 'tx'; this.title = container.title; this.data = data; this.container = container; this.markup = $('#article'); /*activate pagination*/ this.breaks = $(this.markup).find('h3'); this.pages = $(this.markup).find("div[class^='p']"); this.enablePageBreaks(); this.backToTop(); /*add Text Tools*/ this.txtTools = this.addComponent("msnbc.components.TextTools"); this.txtTools.insert($(this.title).parent()); /*add Share Menu*/ this.shareMenu = this.addComponent("msnbc.components.ShareMenu"); this.shareMenu.setup($(this.title).text(), new msnbc.misc.URLCommand(this.SHORT_NAME)); this.shareMenu.insert($(this.title).parent()); /*setup Art*/ this.mainArt = this.addComponent("msnbc.components.MainArt"); this.inlineArt = this.addComponent("msnbc.components.InlineArt"); this.rendered = false; }, render: function(){ if (this.rendered) return; /*hide subsequent pages and subheads*/ $(this.pages).not('.p0').addClass('hide'); $(this.breaks).not('.p0').addClass('hide'); /*add title text on pagination*/ this.breaks.attr('title','Go to next page')/*.css('display','none')*/; /*add Main Art*/ var mainart = $("#noscriptimg img"); var grid8x3 = $("#imgurl").text().indexOf('.grid-8x3') > 0; var vert = (mainart.width() / mainart.height()) < 1; if ( (mainart.length > 0) && (!grid8x3 || vert) ) { /*main art, but not the right size; resize it*/ this.mainArt.insert($("#imgurl"), $(this.markup.parent()).find('#sidebar')); } else if ( (mainart.length > 0) && (grid8x3 && !vert) ) { /*let it lie*/ } else { /*no main art; hide slash*/ $("#main-art .slash").addClass("hide"); } /*correct Inline Art*/ if ($('#article .html-p img')) { this.inlineArt.insert($('#article .html-p img')); } /*move dateline into first pagination div*/ $("#dateline").addClass('inline').prependTo("#article div.p0"); /*add lead graph emPHAsis*/ $(this.markup).find('div.p0 p:first').addClass('first'); /*update various URLs*/ var urlCommand = new msnbc.misc.URLCommand(this.SHORT_NAME, null, [{page:1}]); this.shareMenu.updateShareCommand(urlCommand); this.rendered = true; }, enablePageBreaks: function(){ var self = this; // add click action to each pagination marker this.breaks.click(function(i){ /*get pagenumber and pass to URL commands and pageview*/ var pg = $(this).attr("class"); pg = pg.match(/[0-9]+/); pg = parseFloat(pg[0]) + 2; // clicked pagebreak $(this).removeClass('hide').addClass('show open'); // next pg graphs var graph = $(this).next('div'); $(graph).removeClass('hide').addClass('show'); // next pagebreak var hede = $(graph).next('h3'); $(hede).removeClass('hide').addClass('show'); // call pageview self.pageview(pg); }); }, pageview: function(pg){ var DapAd = new msnbc.ads.DapAd("msnbc.ads.DapAd"); var self = this; try { jQuery.each(this.ads, function() { //DapAd.refresh(self.slot, this); }); } catch(e) { msnbc.log(e); msnbc.log("Story pageview ad refresh error"); } //modify URL var urlCommand = new msnbc.misc.URLCommand(this.SHORT_NAME, null, [{page:pg}]); this.shareMenu.updateShareCommand(urlCommand); this.dispatchEvent("contextChange", urlCommand); }, getInterface: function(){ return { names: this.SHORT_NAME, commands: { generic: function(params) { this.handleURLParams(params); }, ff: function(isSans) { this.txtTools.setSans(isSans); }, fs: function(size) { this.txtTools.setTextSize(size); } } }; }, getNavTease: function(){ return { "label": "Text", "icon": "text", "abstract": msnbc.utils.truncate(this.markup.find('p:first').text(), 150), // don't "title": $(this.title).find('span.subhead').text(), "anchorName": "text", "source": "" }; }, toString: function(){ return '[Module DefaultText]'; }, backToTop: function() { var top = $(this.markup).find("#top"); var textModule = this.markup.parent(); var alpha = Math.ceil($(textModule).offset().top); top.click(function() { $('html,body').stop().animate({ scrollTop: alpha },800); }); //count as a pageview? //self.pageview(0); } });