window.__RebelMouseNS || (window.__RebelMouseNS = {}); (function (root, doc, RM) { RM.id = RM.id ? ++RM.id : 1; var Settings, postMessage = !!window.postMessage, Embed = function (settings) { this.settings = settings || {}; this.id = RM.id; this.el = doc.createElement('iframe'); this.buildIframe(); this.insertCSS(); this.insertIntoDOM(); this.appStatus = true; this.listenToScroll(); !this.settings.force_height && this.listenToFrameHeight(); this.settings.lightbox && this.insertLightboxIntoDOM(); }, Events = function (obj) { addListener(root, 'message', function () { obj.messageHandler.apply(obj, arguments); }); addListener(root, 'scroll', function (evnt) { obj.scrollHandler.apply(obj, arguments); }); addListener(root, 'resize', function () { obj.resizeHandler.apply(obj, arguments); }); }; function addListener(el, type, fn, ctx) { if (ctx) { fn = bind(fn, ctx); } if (root.addEventListener) { el.addEventListener(type, fn, false); } else if (doc.attachEvent) { // IE el.attachEvent('on' + type, function (e) { fn.call(this, e || root.e); }); } else { // older browsers el['on' + type] = function (e) { fn.call(this, e || root.e); }; } } function bind(fn, ctx) { return fn.bind ? fn.bind(ctx) : function() { return fn.apply(ctx, arguments); } } RM.addListener = RM.addListener || addListener; function calculateYOffset(el) { var top = el.offsetTop; while (el = el.offsetParent) { top += el.offsetTop; } return top; } function reportBottomBorder(evnt) { var bodyOffset = scrollTop() - calculateYOffset(this.el), viewportHeight = root.innerHeight || doc.documentElement.clientHeight; postMessage && this.el.contentWindow.postMessage('bottom-border:' + (bodyOffset + viewportHeight), '*'); } function scrollTop() { if (!!root.pageYOffset) { return root.pageYOffset; } else { return (doc.documentElement && doc.documentElement.scrollTop) || doc.body.scrollTop; } } function docHeight() { return Math.max( Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight), Math.max(doc.body.offsetHeight, doc.documentElement.offsetHeight), Math.max(doc.body.clientHeight, doc.documentElement.clientHeight) ); } function winHeight() { return root.innerHeight || doc.documentElement.clientHeight || doc.body.clientHeight; } try { Settings = {"images_background": 1, "domain": "https://togo.rbl.ms", "twitter_follow_lang": "en", "twitter_follow_width": "60%", "twitter_follow_align": "right", "script_url": "https://togo.rbl.ms/embed/Huffpostgreen/elite.js", "twitter_follow_size": "large", "display_body": 1, "use_post_url": 1, "images_background_big": 1, "theme": 6462, "display_image": 1, "flexible": 0, "footer_url": "http://www.huffingtonpost.com/green/", "twitter_follow_show_count": 1, "iframe_url": "https://togo.rbl.ms/embed/elite/Huffpostgreen", "dont_load_new_posts": 1, "display_source": 0, "default_domain": "https://togo.rbl.ms", "twitter_follow_show_screen_name": 0, "twitter_follow_dnt": 1, "twitter_follow": 1, "posts_count": 1, "footer_custom_html": "\u003cscript\u003e \r\n$(function(){\r\n$( \".headline\" ).each(function( index ) {\r\n if ($.trim($( this ).text()).length === 0) {\r\n $( this ).text( $.trim($(this).parent().find('.body').text()) );\r\n $(this).parent().find('.body').remove();\r\n }\r\n});\r\n});\r\n\u003c/script\u003e", "footer_title": "Dodo Web Partner: HuffPost Green", "embed_title": "Dodo Web Partners", "header_url": "http://www.huffingtonpost.com/green/", "load_video": 0, "all_posts": 2, "clamp_body": "2.2em", "clamp_headline": "2.2em"}; if (!!Settings.use_http) { var keys = ['iframe_url', 'domain', 'script_url'], key; while(key = keys.shift()) { Settings[key] = Settings[key].replace(/^https/, 'http'); } } } catch(e) { Settings = {} } Embed.prototype = { defaultFlexibleHeight: 300, isPushStateSupported: root.history && root.history.pushState, buildIframe: function () { var referrer, src; try { referrer = window.top && window.top.location && encodeURIComponent(window.top.location.href) || ''; } catch (e) { referrer = ''; } src = '?iframe_id=' + this.id; src += referrer ? '&referrer=' + referrer : ''; //WORKAROUND: save referrer if you really need it (ann curry the only one for now) if (this.settings.referrer_needed) { src += '&__rmsp=-1'; } var height_unit = (this.settings.height_unit || 'px'); this.el.height = (this.settings.flexible ? Math.min(this.defaultFlexibleHeight, this.settings.height || this.defaultFlexibleHeight) : this.settings.height || this.defaultFlexibleHeight) + height_unit; this.el.width = this.settings.width || '100%'; this.el.scrolling = (this.settings.flexible || this.settings.collapse_widget) ? 'no': 'auto'; this.el.allowTransparency = 'true'; this.el.seamless = 'seamless'; this.el.frameBorder = '0'; this.el.className = 'rebelmouse-embed-iframe ' + (this.settings.flexible ? 'rebelmouse-embed-flexible' : 'rebelmouse-embed-fixed'); if (this.settings.collapse_widget) { this.el.className += ' rebelmouse-embed-collapsable' } this.iframeSrc = src; return this; }, createStylesheet: function(src) { var css = doc.createElement('link'); css.rel = 'stylesheet'; css.type = 'text/css'; css.href = src; return css; }, insertCSS: function () { var main = this.createStylesheet('https://static.rbl.ms/static/css-build/elite-embed.css'); doc.getElementsByTagName('head')[0].appendChild(main); }, listenToScroll: function () { var embed = this; addListener(root, 'scroll', function () { if ((docHeight() - scrollTop() - winHeight()) < 600) { if (embed.appStatus) { embed.el.contentWindow.postMessage('get-new-post', '*'); embed.appStatus = false; } } }); }, listenToFrameHeight: function() { var embed = this; addListener(root, 'message', function (evnt) { var source = evnt.data.split(':'), callback = source[0], data = source[1], id = source[2]; if (callback === 'set-frame-height' && id === embed.id.toString()) { embed.el.style.height = data + 'px'; embed.appStatus = true; } }); }, insertIntoDOM: function () { var scripts = doc.getElementsByTagName('script'), i = 0, len = scripts.length, currentUrl, isUsingLegacyDomain; for (; i < len; ++i) { currentUrl = scripts[i].src; // Replace legacy domain currentUrl = currentUrl.replace(/^https?:\/\/www\.rebelmouse\.com/, Settings.default_domain); isUsingLegacyDomain = /^https:\/\/ads\.rbl\.ms/.test(currentUrl); if (Settings.use_ads_domain) { currentUrl = currentUrl.replace(Settings.default_domain, Settings.domain); } else if (isUsingLegacyDomain) { this.settings.script_url = this.settings.script_url.replace(Settings.default_domain, 'https://ads.rbl.ms'); } if (!!Settings.use_http) { currentUrl = currentUrl.replace(/^https/, 'http'); } currentUrl = currentUrl.split('?'); if ((currentUrl.shift()) === this.settings.script_url && !scripts[i].rmid) { // If there are params in elite.js, forward them. if (currentUrl.length) { this.iframeSrc += '&' + currentUrl.join(''); } this.el.src = this.settings.iframe_url + this.iframeSrc; scripts[i].rmid = RM.id; scripts[i].parentNode.appendChild(this.el, scripts[i]); return true; } } return false; }, insertLightboxIntoDOM: function() { var script = doc.createElement('script'), css = this.createStylesheet('https://static.rbl.ms/static/css/lightbox.css'); script.src = 'https://static.rbl.ms/static/js-build/embed/lightbox.js'; doc.getElementsByTagName('head')[0].appendChild(css); doc.body.appendChild(script); addListener(root, 'message', function (evnt) { var source = evnt.data.split(/:/g), args; if (source.shift() === 'lightbox') { if (!this.lightbox) { this.lightbox = new RM.Lightbox(); doc.body.appendChild(this.lightbox.render().el); doc.body.appendChild(this.lightbox.shadow); } args = JSON.parse(source.join(':')); this.lightbox[args.method](args); } }); } }; FlexMixin = (function () { var messageCalls = { 'get-current-offset': function (data) { var bodyOffset = scrollTop() - calculateYOffset(this.el); postMessage && bodyOffset > 0 && this.el.contentWindow.postMessage('body-offset:' + bodyOffset, '*'); }, 'set-frame-height': function (data) { this.el.style.height = data + 'px'; this.appStatus = true; }, 'get-border-report': function () { reportBottomBorder.call(this); }, 'scroll-to-top': function (data) { scrollTo(0, 0); }, 'refresh-window-href': function (data) { location.href = decodeURIComponent(data); }, 'set-current-offsetTop': function (data) { scrollTo(0, data); } } return function (context) { context || (context = this); this.resizeHandler = function () { reportBottomBorder.apply(context, arguments); } this.scrollHandler = function () { reportBottomBorder.apply(context, arguments); } this.messageHandler = function (evnt) { var source = evnt.data.split(':'), callback = source[0], data = source[1]; if (messageCalls[callback]) { messageCalls[callback].call(context, data); } } this.events = new Events(this); } }()); EmbedInst = new Embed(Settings); if (typeof console === "object") { console.log('settings---', Settings); } if (Settings.flexible) { FlexMixin.call(Embed.prototype, EmbedInst); } }(window, window.document, window.__RebelMouseNS));