jQuery.extend(msnbc.document.settings, { shareServices: [ { name: "Newsvine", icon: "http://msnbcmedia.msn.com/i/MSNBC/Templates/cccTemplatesStory_v2/img/newsvine.gif", uri: "http://www.newsvine.com/_tools/seed", params: { u: "::MOD_URL::", popoff: "0" } }, { name: "Facebook", icon: "http://msnbcmedia.msn.com/i/MSNBC/Templates/cccTemplatesStory_v2/img/facebook.gif", uri: "http://www.facebook.com/share.php", params: { u: "::MOD_URL::" } }, { name: "Twitter", icon: "http://msnbcmedia.msn.com/i/MSNBC/Templates/cccTemplatesStory_v2/img/twitter.png", uri: "http://twitter.com/home", params: { status: "::MOD_URL::" + " on msnbc.com" } } ] }); msnbc.components.ShareMenu = msnbc.components.Component.extend({ setup: function(moduleTitle, cmdOrURL, dontShareList){ this.moduleTitle = moduleTitle; this.moduleURL = (cmdOrURL.toShareString) ? cmdOrURL.toShareString() : cmdOrURL; this.shareServices = msnbc.document.settings.shareServices; this.slot; // TODO: optional list to filter out services we don't want to share in this menu instance // if (dontShareList) this.filterArray(this.shareServices, dontShareList); // get the rss url for the page // this.rssURL = $(document.documentElement).find("link[rel='alternate']").attr('href'); this.type = this.moduleTitle.split(':'); if (this.type.length > 0) { this.type = this.type[0].replace(/\r\n\s/g,'').replace('Text','this story').toLowerCase(); } else { this.type = 'this story'; } }, insert: function(selectr){ var self = this; this.slot = selectr; /*add markup*/ var ss = ''; $(selectr).append(ss); }, /*renderFlyout: function(doToggle, parent, saveToCookie, timeout){ var self = this; //build click action for links var $links = $(this.slot).find('.share-feeds a'); $links.click(function(e) { //e.stopPropagation(); var shr = $(this).text(); var val = ''; jQuery.each(self.shareServices, function(i) { if (this.name == shr) {val = i;} }); if (saveToCookie) {self.handleCookie('sh', val);} }); } }, */ getShareList: function(){ var self = this; var list = '
  • Share via
  • '; jQuery.each(self.shareServices, function(i){ var p = self.matchToModule(this.params); var q = jQuery.param(p); list += '
  • '+this.name+'
  • '; }); list += '
  • '+this.getMailLink()+'
  • '; list += '
  • Print
  • '; return list; }, updateShareCommand: function(cmd){ this.moduleURL = cmd.toShareString(); //this.renderFlyout(false); }, getMailLink: function(textarea){ var msg = document.title +' ('+this.moduleURL+') on ' + document.domain; msg = msg.replace('&','and'); msg = msg.replace('\u2018','\''); msg = msg.replace('\u2019','\''); msg = msg.replace('\u201C','\"'); msg = msg.replace('\u201C','\"'); var m = 'Email'; return m; }, filterServices: function(source, blacklist){ //TODO //source = jQuery.grep(source, function(v, i){ // return jQuery.inArray(v, blacklist) == -1; //}); }, matchToModule: function(params){ /*match placeholders in object with title & url as appopriate*/ var urlMatch = /::MOD_URL::/i; var titleMatch = /::MOD_TITLE::/i; var url = this.moduleURL; var title = this.moduleTitle; var newParams = {}; jQuery.each(params, function(k,v){ var nv = v; nv = nv.replace(urlMatch, url); nv = nv.replace(titleMatch, title); newParams[k] = nv; }); return newParams; }, getCookiePref: function(cmd, slot) { var self = this; var link = ''; var svc = this.shareServices[cmd]; if (cmd != undefined && svc) { var p = self.matchToModule(svc.params); var q = jQuery.param(p); link = ''+svc.name+''; } else { link = this.getTextArea(); } $(slot).html(link); }, handleCookie: function(cmd, code){ if (msnbc.document.cookieMgr) { var cCmd = {}; cCmd[cmd] = code; msnbc.document.cookieMgr.addCookieCommand(msnbc.document.settings.DEFAULT_COOKIE_NAME, 'gx', cCmd); } } });