function removeHash(){ var scrollV, scrollH, loc = window.location; if ("replaceState" in history) history.replaceState("", document.title, loc.pathname + loc.search); else { // Prevent scrolling by storing the page's current scroll offset scrollV = document.body.scrollTop; scrollH = document.body.scrollLeft; loc.hash = ""; // Restore the scroll offset, should be flicker free document.body.scrollTop = scrollV; document.body.scrollLeft = scrollH; } } /* test edit */ function isEmail(address) { address = typeof address !== 'undefined' ? address : ""; var pos = address.lastIndexOf("@"); return pos > 0 && (address.lastIndexOf(".") > pos) && (address.length - pos > 4); } function createCookie(name, value, days) { var expires; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toGMTString(); } else { expires = ""; } document.cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + expires + "; path=/"; } function readCookie(name) { var nameEQ = encodeURIComponent(name) + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) === ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length)); } return null; } function eraseCookie(name) { createCookie(name, "", -1); } function osf_pad_time(digit) { digit = String(digit); if (digit.length == 1) { digit = '0' + digit; } return digit; } function osf_format_time(duration) { var formatted_time = ""; var hours = Math.floor(duration / 3600); var mins = Math.floor((duration - (hours * 3600)) / 60); var secs = Math.floor((duration - (hours * 3600) - (mins * 60))); if (hours) { formatted_time = hours + ':' + osf_pad_time(mins) + ':' + osf_pad_time(secs); } else if (mins | secs) { formatted_time = mins + ':' + osf_pad_time(secs); } return formatted_time; } function test_a_or_b(){ var abtest = new Array(); abtest[0] = 'A'; abtest[1] = 'B'; var whichtest=Math.floor(Math.random()*(abtest.length)); return abtest[whichtest]; } if (typeof String.prototype.startsWith != 'function') { String.prototype.startsWith = function (str){ return this.slice(0, str.length) == str; }; } if (typeof String.prototype.endsWith != 'function') { String.prototype.endsWith = function(searchString, position) { var subjectString = this.toString(); if (position === undefined || position > subjectString.length) { position = subjectString.length; } position -= searchString.length; var lastIndex = subjectString.indexOf(searchString, position); return lastIndex !== -1 && lastIndex === position; }; } if (typeof String.prototype.capitalizeFirstLetter != 'function') { String.prototype.capitalizeFirstLetter = function() { return this.charAt(0).toUpperCase() + this.slice(1); } } function extractParamFromUri(uri, paramName) { if (!uri) { return; } var regex = new RegExp('[\\?&#]' + paramName + '=([^&#]*)'); var params = regex.exec(uri); if (params != null) { return unescape(params[1]); } return; } function get_bitly_url(long_url){ var short_url = ''; var bityurl = "https://api-ssl.bitly.com/v3/shorten"; jQuery.ajax({ url: bityurl, dataType: 'json', data: { "access_token": "5874f408c9a6900323ea3b13a5a4f3a59073a748", "longUrl": long_url }, cache: true }) .done(function(data) { var short_url = data.data.url; jQuery('button.social-twitter').attr('data-short-url', short_url); return short_url; }) .fail(function( jqxhr, textStatus, error ) { var err = textStatus + ', ' + error; console.log( "Request bit.ly url failed: " + err); }); } function trim(stringToTrim) { return stringToTrim.replace(/^\s+|\s+$/g,""); } function encodeURIpretty(s) { var pretty_uri = s; pretty_uri = pretty_uri.split(' ').join('-'); pretty_uri = pretty_uri.replace('&', 'and'); pretty_uri = pretty_uri.replace(/[^a-z0-9-]/gi,'').toLowerCase(); pretty_uri = encodeURIComponent(pretty_uri); return pretty_uri; } function setIFrameSrc(id, url) { var originalFrame = document.getElementById(id); var newFrame = document.createElement("iframe"); newFrame.id = originalFrame.getAttribute("id"); newFrame.frameborder = 0; newFrame.allowfullscreen = ''; newFrame.src = url; var parent = originalFrame.parentNode; parent.replaceChild(newFrame, originalFrame); } function get_prod_url(){ var full_url = 'https://www.opensocietyfoundations.org' + window.location.pathname; return full_url; } function get_prod_url_ssl(){ var full_url = 'https://www.opensocietyfoundations.org' + window.location.pathname; return full_url; } // generic add to segment routine function subscribe_email_segment(mid, segment) { var dataString = 'mid=' + encodeURIComponent(mid) + '&segment=' + encodeURIComponent(segment); jQuery.ajax({ type: "POST", context: this, url: "//apps.opensocietyfoundations.org/subscribe_super/", data: dataString, success: function(data) { console.log('Subscribed to ' + segment); }, error: function(xhr,err){ console.log("readyState: "+xhr.readyState+"\nstatus: "+xhr.status); console.log(xhr.responseText); } }); return false; } // Add to segment if subscriber is on Roma or Drug Policy content function add_to_email_segment(){ var subscriber_mid = readCookie('email_subscriber'); if(subscriber_mid) { var $content_topics = jQuery(".group_learn_more .field-type-taxonomy-term-reference"); if($content_topics.length){ $content_topics.each(function( index ) { var content_topic = jQuery(this).text(); if(jQuery.inArray(content_topic, ['Roma']) != -1) { subscribe_email_segment(subscriber_mid, 'roma'); } if(jQuery.inArray(content_topic, ['Drug Policy Reform', 'Harm Reduction', 'Drug Policy Reform in the United States']) != -1) { subscribe_email_segment(subscriber_mid, 'drug_policy'); } }) } } } /** * Wrapping function for ga social events so we can debug */ function gaTrackSocial(aCat, aAct, aFile) { if (typeof ga != "undefined"){ ga('send', 'social', aCat, aAct, aFile); } else { console.log("ga('send', 'social', '" + aCat + "', '" + aAct + "', '" + aFile + "'"); } } /** * Wrapping function for ga events so we can debug */ function gaTrackEvent(aCat, aAct, aFile, nonInteraction) { nonInteraction = typeof nonInteraction !== 'undefined' ? 1 : 0; aFile = typeof aFile !== 'undefined' ? aFile : "0"; aAct = typeof aAct !== 'undefined' ? aAct : "0"; if (typeof ga != "undefined"){ ga('send', { 'hitType': 'event', 'eventCategory': aCat.toString(), 'eventAction': aAct.toString(), 'eventLabel': aFile.toString(), 'nonInteraction': nonInteraction }); } else { console.log("ga('send', {'hitType': 'event', 'eventCategory': '" + aCat + "', 'eventAction': '" + aAct + "', 'eventLabel': '" + aFile + "', 'nonInteraction': " + nonInteraction + "});"); } } /** * Wrapping function for ga pageviews so we can debug */ function gaTrackPage(page_url) { page_url = typeof page_url === 'undefined' ? location.pathname : page_url; if (typeof ga != "undefined"){ ga('send', { 'hitType': 'pageview', 'page': page_url }); } else { console.log("ga('send', {'hitType': 'pageview', 'page': '" + page_url + "'});"); } } function trackOutboundLink(url) { if (typeof ga != "undefined"){ ga('send', 'event', 'outbound', 'click', url, {'hitCallback': function () { document.location = url; } }); } else { console.log("ga('send', 'event', 'outbound', 'click', '"+ url +"')"); setTimeout(function(){ document.location = url; }, 2000); } } // Extend contains: to be case-insensitive jQuery.expr[':'].contains = function(a, i, m) { return jQuery(a).text().toUpperCase() .indexOf(m[3].toUpperCase()) >= 0; }; // set up variable to hold scroll_depth toggle var osf_scroll_track = 1; // set up variable to hold our ab test toggle var abt = test_a_or_b(); jQuery(document).ready(function($){ // // MOVE BLOCKS AROUND // // Change social buttons if Hungarian $('body.osf_multilingual_hu button.social-facebook span.text-button-social').html(Drupal.t("Share")); $('body.osf_multilingual_hu button.social-linkedin span.text-button-social').html(Drupal.t("Share")); $('body.osf_multilingual_hu button.social-republish span.text-button-social').html(Drupal.t("Republish")); // Change Home link if Hungarian $('body.osf_multilingual_hu #section-header .branding').attr('href','/hu'); $('body.osf_multilingual_hu #section-footer a.logo').attr('href','/hu'); if (typeof enquire !== 'undefined' && !$('.osf_multilingual_hu').length) { // NAVBURGER SUBNAV if ($('.hamburger .menu').length) { $('.region-menu-inner .navigation').after(''); $('.hamburger .menu').appendTo('#navburger-subnav'); enquire.register("screen and (min-width:680px)", { match: function(){ $('#navburger-subnav').hide(); }, unmatch: function(){ $('#navburger-subnav').show(); } }); } if ($('.more .menu').length) { $('.region-menu-inner .navigation').after(''); $('.more .menu').appendTo('#navburger-subnav'); enquire.register("screen and (min-width:680px)", { match: function(){ $('#navburger-subnav').hide(); }, unmatch: function(){ $('#navburger-subnav').show(); } }); } // NEWSLETTER SIGNUP BLOCK if (!$('.grants-landing').length) { // save newsletter signup placement (so we can put it back) var newsletterParent; newsletterParent = $('.entity-boxes-newsletter-box').parent(); // newsletter signup at mobile enquire.register("screen and (max-width:679px)", { setup: function(){ // add newsletter signup menu if ($('.entity-boxes-newsletter-box').length || $('.homepage-newsletter-block').length) { $('#zone-menu').after('
'); } else { $('#toggle-signup-menu').remove(); } }, match: function(){ $('.entity-boxes-newsletter-box').appendTo('#zone-signup-menu'); $('.homepage-newsletter-block').appendTo('#zone-signup-menu'); } }); // newsletter signup at tablet (different pages behave differently // tablet on voices posts, events, publications, grants, (is that all?) move signup to title area if ($('.node-type-blog-entry').length || $('.node-type-work-product').length || $('.node-type-event').length || $('.node-type-grant').length || $('.node-type-section-front').length || $('.node-type-litigation').length || $('.node-type-news').length || $('.page-search').length || $('.page-termsearch').length || $('.node-type-profile.context-employment').length) { enquire.register("screen and (min-width:680px) and (max-width:819px)", { setup: function(){ $('.region-page-title-region .views-field-title').before('
'); }, match: function(){ $('.entity-boxes-newsletter-box').prependTo('#signup-in-title'); $('.homepage-newsletter-block').appendTo('#zone-menu .region-menu-inner'); $('#zone-signup-menu').attr('style', ''); } }); // tablet on contact page } else if ($('.global-contact-page').length) { enquire.register("screen and (min-width:680px) and (max-width:819px)", { setup: function(){ $('.region-page-title-region .block-title').before('
'); }, match: function(){ $('.entity-boxes-newsletter-box').prependTo('#signup-in-title'); $('#zone-signup-menu').attr('style', ''); } }); // tablet on work, writing ,appearances page } else if ($('.page-work-writing-appearances').length) { enquire.register("screen and (min-width:680px) and (max-width:819px)", { setup: function(){ $('#region-content .view-header').before('
'); }, match: function(){ $('.entity-boxes-newsletter-box').prependTo('#signup-in-title'); $('#zone-signup-menu').attr('style', ''); } }); // tablet on everything else (landing, etc) } else { enquire.register("screen and (min-width:680px) and (max-width:819px)", { match: function(){ var parentsThatNeedPrepend = ['block-boxes-newsletter-general']; if (parentsThatNeedPrepend.indexOf(newsletterParent.attr('id')) !== false) { $('.entity-boxes-newsletter-box').prependTo(newsletterParent); } else { $('.entity-boxes-newsletter-box').appendTo(newsletterParent); } $('#zone-signup-menu').attr('style', ''); } }); } // newsletter signup at desktops enquire.register("screen and (min-width:820px)", { match: function(){ var parentsThatNeedPrepend = ['block-boxes-newsletter-general']; if (parentsThatNeedPrepend.indexOf(newsletterParent.attr('id')) !== false) { $('.entity-boxes-newsletter-box').prependTo(newsletterParent); } else { $('.entity-boxes-newsletter-box').appendTo(newsletterParent); } $('.homepage-newsletter-block').appendTo('#zone-menu .region-menu-inner'); $('#zone-signup-menu').attr('style', ''); } }); } // END NEWSLETTER SIGNUP BLOCK // SEARCH FIELD & SOCIAL ICONS enquire.register("screen and (max-width:679px)", { setup: function(){ // add search menu $('#zone-menu').after('
'); }, match: function(){ $('#block-boxes-header-social').appendTo('#zone-menu'); $('#block-osf-search-global-site-search').prependTo('#zone-search-menu'); $('#block-boxes-global-language-title-en').prependTo('#region-branding .region-branding-inner'); }, unmatch: function(){ $('#block-boxes-header-social').prependTo('.region-user-first-inner'); $('#block-osf-search-global-site-search').prependTo('.region-user-first-inner'); $('#block-boxes-global-language-title-en').prependTo('.region-user-first-inner'); $('#zone-menu').attr('style', ''); $('#zone-search-menu').attr('style', ''); } }); // AUTHORS BLOCK if ($('#block-views-blog-blocks-block-3').length) { enquire.register("screen and (max-width:819px)", { setup: function(){ $('.group_learn_more').after('
'); $('#block-boxes-newsletter-general').after('
'); }, match: function(){ $('#block-views-blog-blocks-block-3').appendTo('#author-inline'); }, unmatch: function(){ $('#block-views-blog-blocks-block-3').appendTo($('#author-parent')); } }); } // GRANTS LANDING - CONNECT WITH US BLOCK if ($('.grants-landing .connect-with-us').length) { enquire.register("screen and (max-width:819px)", { match: function(){ $('.connect-with-us').prependTo('.region-sidebar-first-inner'); }, unmatch: function(){ $('.connect-with-us').prependTo($('.region-sidebar-second-inner')); } }); } // Hide Facebook Video player for small devices and show a message. if($('iframe[src^="https://www.facebook.com/plugins/video"]').length && $('.event-current').length){ enquire.register("screen and (max-width:679px)", { match: function(){ $('iframe[src^="https://www.facebook.com/plugins/video"]').hide(); $('.views-field-field-featured-media-free-form').css({'background-color':'#E7E7E7', 'position':'relative'}); $('.views-field-field-featured-media-free-form').prepend('
To watch this event live, please use the Facebook app.
'); }, unmatch: function(){ if($('.fb_live_message').length){ $('.fb_live_message').remove(); } $('iframe[src^="https://www.facebook.com/plugins/video"]').show(); $('.views-field-field-featured-media-free-form').css('background-color','#FFF'); } }); } } else if (typeof enquire !== 'undefined' && $('.osf_multilingual_hu').length) { // HUNGARIAN PAGES // SEARCH FIELD & SOCIAL ICONS enquire.register("screen and (max-width:679px)", { setup: function(){ // add search menu $('#zone-menu').after('
'); }, match: function(){ $('#block-osf-search-global-site-search').prependTo('#zone-search-menu'); $('#block-boxes-global-languge-toggle').prependTo('#region-branding .region-branding-inner'); }, unmatch: function(){ $('#block-osf-search-global-site-search').prependTo('.region-user-first-inner'); $('#block-boxes-global-languge-toggle').prependTo('.region-user-first-inner'); $('#zone-search-menu').attr('style', ''); } }); } // // END MOVE BLOCKS AROUND // // lefthand nav menu flyout var leftmenulink = $('.sidebar-link'), leftwrap = $('#zone-content-wrapper'); leftmenulink.click(function() { leftwrap.toggleClass('active'); // Enable swipe navigation. $('#zone-content-wrapper.active').swipe( { swipeLeft:function(event, direction, distance, duration, fingerCount) { //console.log("You swiped " + direction ); leftwrap.removeClass('active'); }, fingers:'all', allowPageScroll:'vertical', threshold:20 // excludedElements:$.fn.swipe.defaults.excludedElements+", .rotator-pager" }); return false; }); // set cookie for email subscribers var utm_medium = extractParamFromUri(document.URL,'utm_medium'); var utm_medium = (typeof utm_medium !== 'undefined') ? utm_medium : null; var utm_content = extractParamFromUri(document.URL,'utm_content'); var utm_content = (typeof utm_content !== 'undefined') ? utm_content : null; var utm_campaign = extractParamFromUri(document.URL,'utm_campaign'); var utm_campaign = (typeof utm_campaign !== 'undefined') ? utm_campaign : null; if(utm_medium == 'email'){ createCookie('email_subscriber', utm_content, 365); } // if email_campaign cookie exists, compare with current campaign, // if these values are different we know this is their second visit and // we add them to super user segments on visit to super user topics var old_campaign = readCookie('email_campaign'); if(old_campaign && utm_campaign){ if(old_campaign != utm_campaign){ createCookie('email_campaign_repeat', utm_campaign, 365); } } else if(utm_campaign) { createCookie('email_campaign', utm_campaign, 365); } if ($(".block-boxes-page-tools").length) { var social_mobile_header = '
' + ' ' + Drupal.t("Share")+ '' + ' Tweet' + '
'; $('header').prepend(social_mobile_header); //Use floating social header on mobile window.show_header = true; enquire.register("screen and (max-width:480px)", { match: function () { $(window).on("scroll.header", function() { if ($(this).scrollTop() > 50){ $('#social-mobile-header').addClass('mobile-header-show') if (window.show_header === true) { $('#social-mobile-header').trigger('mobileSocialHeader'); window.show_header = false; } } else { $('#social-mobile-header').removeClass('mobile-header-show'); } }); }, unmatch: function () { $(window).off("scroll.header"); $('#social-mobile-header').removeClass('mobile-header-show'); } }); } // show cookie notice to EU visitors. The cc (country code) meta tag is added by a CloudFlare worker if ($('meta[property=cc]').length) { var country_code = $('meta[property=cc]').attr("content"); var eu_country_codes = ['AT', 'BE', 'BG', 'CH', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE', 'IS', 'IT', 'LI', 'LT', 'LU', 'LV', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'SI', 'SK', 'T1']; // T1 for Tor var eu_country = eu_country_codes.includes(country_code); if(eu_country & readCookie('shown_cookie_notice') != 1){ var privacy_notice_html = '' + ''; $('body').append(privacy_notice_html); $('.privacy-container').slideToggle(); $('.btn-close-main').click( function(event) { event.preventDefault(); createCookie('shown_cookie_notice','1',365); $('.privacy-container').slideToggle(); }); } } // email lightbox disabled if (($(".entity-boxes-newsletter-box").length || $("body.front").length) && 1==0) { // toggle display of newsletter signup box var show_email_lightbox = true; // dont' show email popup on Hungarian pages if (window.location.pathname.startsWith('/hu')) { var show_email_lightbox = false; } // add class to body to ease css targeting $("body").addClass("email-lightbox-signup"); // the html for our lightbox signup var email_lightbox_signup = '' + ''; // add box to body, but its hidden by default $('body').append(email_lightbox_signup); // when scrollin swap out some classes to make our // regular newsletter box and lightbox newsletter box toggle visibility $(window).on("scroll.newsletter", function() { if (show_email_lightbox) { var shown_email_lightbox = readCookie('shown_email_lightbox'); if (!shown_email_lightbox) { if ($(this).scrollTop() > 30){ $(".signup-overlay").addClass('signup-overlay-show').fadeIn('fast'); $(".entity-boxes-newsletter-box").addClass('entity-boxes-newsletter-box-hide'); } } } }); // add action to close box $('.email-lightbox-signup .signup-lightbox .close-email-lightbox').click( function(event) { event.preventDefault(); $(".signup-overlay").removeClass('signup-overlay-show').hide(); $(".entity-boxes-newsletter-box").removeClass('entity-boxes-newsletter-box-hide'); show_email_lightbox = false; createCookie('shown_email_lightbox','1',365); }); // add esc keypress $(document).keydown(function(e){ if (e.keyCode == 27) { if ($('.signup-lightbox').is(":visible")) { $('.email-lightbox-signup .signup-lightbox .close-email-lightbox').click(); } } }); $("form#signup-lightbox-form").one( "submit", function(event) { event.preventDefault(); var email = $("form#signup-lightbox-form #email").val(); var dataString = 'email=' + encodeURIComponent(email) + '&type=News' + '&welcome=1' + '&src=email_lightbox'; // disable submit button on click $(this).find(':submit').attr('disabled','disabled'); if(email && isEmail(email)) { $.ajax({ type: "GET", context: this, url: "//apps.opensocietyfoundations.org/subscribe/", data: dataString, success: function(data) { gaTrackPage('/email-updates-thank-you?lightbox=1'); $("form.#signup-lightbox-form, .signup-lightbox-instructions, .signup-welcome").fadeOut( function (event) { $(".signup-lightbox-thanks").fadeIn(); setTimeout(function() { $('.email-lightbox-signup .signup-lightbox .close-email-lightbox').click(); }, 2000); }); }, error: function(xhr,err){ console.log("readyState: "+xhr.readyState+"\nstatus: "+xhr.status); console.log(xhr.responseText); $(this).find(':submit').attr('disabled','enabled'); } }); } return false; }); } $("form#signup-campaign-form").on( "submit", function(event) { event.preventDefault(); var email = $("form#signup-campaign-form #email").val(); var campaign = $("form#signup-campaign-form #campaign").val(); var dataString = 'email=' + encodeURIComponent(email) + '&type=News' + '&welcome=1' + '&src=' + encodeURIComponent(campaign); function displayChange() { setTimeout(function () { $("#signup-lightbox-placeholder").fadeOut( function (event) { $("#signup-lightbox-thanks").fadeIn(); $('form#signup-campaign-form').trigger("reset"); $('form#signup-campaign-form').find(':submit').prop('disabled', false); }); }, 1750); } // disable submit button on click $(this).find(':submit').prop('disabled', true); if($("#signup-lightbox-thanks").is(":visible")){ $("#signup-lightbox-thanks").fadeOut( function (event) { $("#signup-lightbox-placeholder").fadeIn(); }); } else { $("#signup-lightbox-instructions").fadeOut( function (event) { $("#signup-lightbox-placeholder").fadeIn(); }); } if(email && isEmail(email)) { $.ajax({ type: "POST", context: this, url: "//apps.opensocietyfoundations.org/subscribe/", data: dataString, success: function(data) { gaTrackPage('/email-updates-thank-you?campaign=' + encodeURIComponent(campaign)); displayChange(); }, error: function(xhr,err){ console.log("readyState: "+xhr.readyState+"\nstatus: "+xhr.status); console.log(xhr.responseText); $(this).find(':submit').prop('disabled', false); } }); } return false; }); // Use fitvids.js to make embedded videos responsive. $('iframe[src*="youtube"], iframe[src*="vimeo"], iframe[src*="pbs"], iframe[src*="facebook"], iframe[src*="nyt"], iframe[src*="livestream"]').parent().fitVids({ customSelector: "iframe[src*='pbs'], iframe[src*='facebook'], iframe[src*='nyt'], iframe[src*='livestream']"}); // grab our cached likes, plus ones, and tweets if (document.domain=='www.opensocietyfoundations.org' || document.domain=='dev.osfound.org' || document.domain.endsWith('.dev')) { if (jQuery(".block-boxes-page-tools").length) { var current_url = get_prod_url_ssl(); get_bitly_url(current_url); jQuery('button.social-more').click( function(event) { console.log("more click"); event.preventDefault(); jQuery('button.social-more').fadeOut('fast', function() { jQuery('button.social-linkedin').fadeIn('slow'); jQuery('button.social-email').fadeIn('slow'); jQuery('button.social-republish.can-republish').fadeIn('slow'); }); }); jQuery('button.social-facebook, a.facebook_mobile_header').click( function(event) { event.preventDefault(); var s_url_facebook = current_url; var s_options_facebook = 'width=550,height=330,status=no,scrollbars=yes,resizable=yes,location=yes'; var s_link_facebook = 'https://www.facebook.com/sharer.php?u=' + s_url_facebook; window.open(s_link_facebook, '', s_options_facebook); }); jQuery('button.social-twitter, a.twitter_mobile_header').click( function(event) { event.preventDefault(); var s_twitter_options = 'width=600,height=330,status=no,scrollbars=yes,resizable=yes,location=yes'; var s_hash_via = 'opensociety'; var s_short_link = jQuery('button.social-twitter').attr('data-short-url'); var s_msg_twitter = jQuery('meta[property="osf:tweet"]').attr('content'); if(!s_msg_twitter){ var s_msg_twitter = jQuery('meta[property="og:title"]').attr('content'); } var s_link_twitter = 'https://twitter.com/intent/tweet?text=' + encodeURIComponent(s_msg_twitter) + '&url=' + s_short_link + '&via=' + s_hash_via + '&original_referer=' + current_url; window.open(s_link_twitter, '', s_twitter_options); }); jQuery('button.social-google').click( function(event) { event.preventDefault(); var s_url_google = current_url; var s_options_google = 'width=600,height=500,status=no,scrollbars=yes,resizable=yes,location=yes'; var s_link_google = 'https://plus.google.com/share?url=' + s_url_google; window.open(s_link_google, '', s_options_google); }); jQuery('button.social-linkedin').click( function(event) { event.preventDefault(); var s_url_linkedin = current_url; var s_options_linkedin = 'width=600,height=500,status=no,scrollbars=yes,resizable=yes,location=yes'; var s_link_linkedin = 'https://www.linkedin.com/shareArticle?mini=true&url=' + s_url_linkedin; window.open(s_link_linkedin, '', s_options_linkedin); }); } } function attach_email_mailto() { jQuery('button.social-email').unbind("click.email"); jQuery("button.social-email").bind( "click.email", function(event) { event.preventDefault(); if (jQuery('body.toolbar-drawer ul.tabs.primary').length > 0) { jQuery('body.toolbar-drawer ul.tabs.primary').css('z-index', '0'); } var email_url = get_prod_url_ssl(); //var email_subject = jQuery('meta[property="og:title"]').attr('content'); var email_subject = encodeURIComponent(jQuery('title').text().split(' | ')[0]); var email_body = encodeURIComponent(jQuery('meta[property="og:description"]').attr('content')); var mailto_address = "mailto:?subject=" + email_subject + "&body=" + email_body + "%0A%0A" + email_url; gaTrackEvent('email to friend type', 'mailto', document.URL); window.location.href = mailto_address; }); } // depricated, we only use email client version now function attach_email_lightbox() { jQuery('button.social-email').unbind("click.email"); jQuery("button.social-email").bind( "click.email", function(event) { event.preventDefault(); if (jQuery('body.toolbar-drawer ul.tabs.primary').length > 0) { jQuery('body.toolbar-drawer ul.tabs.primary').css('z-index', '0'); } var dd = 'https://apps.opensocietyfoundations.org/sendtofriend/?url=https://www.opensocietyfoundations.org' + window.location.pathname + '&abt=' + abt; gaTrackEvent('email to friend type', 'lightbox', document.URL); jQuery.colorbox({width: "90%", height: "90%", maxWidth: "800px", iframe: true, href: dd}); }); // always show mailto for Hungary pages if ($('.osf_multilingual_hu').length) { attach_email_mailto(); } } // Attach initial mailto: action - mobile first! attach_email_mailto(); /* Multi-Video player styling */ if (jQuery(".vids .first").length > 0) { if (jQuery(".vids .selected").length == 0) { jQuery(".vids .first").addClass("selected"); } jQuery(".vids a").click(function() { jQuery(".vids div").removeClass("selected"); jQuery(this).parent().addClass("selected"); }); } /* Permalinks for multi-video player */ jQuery(".vids a").click(function(){ var new_hash = encodeURIpretty(jQuery(this).text()); window.location.hash = new_hash; }); if(window.location.hash) { jQuery(".vids a").each(function() { var slide_title_hashed = encodeURIpretty('#' + jQuery(this).text()); var window_hash_hashed = encodeURIpretty(decodeURIComponent(window.location.hash)); if(slide_title_hashed == window_hash_hashed){ var new_video_uri = jQuery(this).attr('href'); jQuery('iframe[name="the-video"]').attr('src', new_video_uri); jQuery(".vids div").removeClass("selected"); jQuery(this).parent().addClass("selected"); } }); } /* expanded contact form for org units */ if(window.location.hash && jQuery("body.node-type-org-unit").length) { if(window.location.hash == '#contact'){ jQuery('#block-webform-client-block-40648 fieldset.form-wrapper').removeClass('collapsed'); jQuery('#edit-submitted-your-name').focus(); } } function add_colon_webform_title(label){ var label = jQuery.trim(label); var last_str_label = label.substr(label.length - 1); var puctuation = "?.!"; if(puctuation.indexOf(last_str_label) == -1){ label = label + ':' } return label; } jQuery.each(jQuery("form .webform-component label"), function() { var full_label = jQuery(this).html(); if(jQuery('span', this).length){ required_label = jQuery('span', this)[0].outerHTML; var text_label = jQuery.trim(full_label.replace(required_label, '')); full_label = add_colon_webform_title(text_label) + ' ' + required_label; } else { full_label = add_colon_webform_title(full_label); } jQuery(this).html(full_label); }); jQuery("body.node-type-org-unit #block-webform-client-block-40648 fieldset.form-wrapper a").click(function(event){ event.preventDefault(); if(window.location.hash == ''){ window.location.hash = 'contact'; jQuery('#edit-submitted-your-name').focus(); } else { removeHash(); } }); /* Show more/Show less in content text */ if (jQuery(".show-more").length > 0) { jQuery(".show-more").click(function(){ jQuery(this).addClass("hidden"); jQuery(this).parent().children(".more-hidden").slideDown('fast'); jQuery(this).parent().parent().children(".more-hidden").slideDown('fast'); return false; }); jQuery(".show-less").click(function(){ jQuery(this).parent().parent().children(".more-hidden").slideUp('fast'); jQuery(this).parent().parent().children().children(".more-hidden").slideUp('fast'); jQuery(this).parent().parent().children(".show-more").removeClass("hidden"); jQuery(this).parent().parent().children().children(".show-more").removeClass("hidden"); return false; }); } /* Show more/Show less on topics page */ if (jQuery("#open-info-plus").length > 0) { jQuery("#open-info-plus").click(function(){ jQuery(this).hide(); jQuery("#close-info-plus").show(); jQuery("#info-plus").slideDown(); return false; }); jQuery("#close-info-plus").click(function(){ jQuery(this).hide(); jQuery("#open-info-plus").show(); jQuery("#info-plus").slideUp('fast'); return false; }); } /* Employment Page */ /* profiles scroller */ if (jQuery(".employment-profiles").length > 0) { var scrollerLeft = 0; var profilesCount = 6; jQuery(".button-prev").addClass("is-inactive"); var prevScroll = function () { jQuery(".button-next").removeClass("is-inactive"); // get the profiles width pWidth = jQuery(".employment-profiles").width(); // get the column width cWidth = jQuery("#profiles").width(); // figure out how much to move if (pWidth/cWidth >= profilesCount/2.5) { scrollerLeft += pWidth*(2.02/profilesCount); } else if (pWidth/cWidth >= profilesCount/3.5 && pWidth/cWidth < profilesCount/2.5) { scrollerLeft += pWidth*(3.03/profilesCount); } else { scrollerLeft = 0; } if (scrollerLeft > -40) { scrollerLeft = 0; jQuery(".button-prev").addClass("is-inactive"); } jQuery(".employment-profiles").css("left", (scrollerLeft+"px")); } var nextScroll = function () { jQuery(".button-prev").removeClass("is-inactive"); // get the profiles width pWidth = jQuery(".employment-profiles").width(); // get the column width cWidth = jQuery("#profiles").width(); // figure out how much to move if (pWidth/cWidth >= profilesCount/2.5) { scrollerLeft -= pWidth*(2.02/profilesCount); } else if (pWidth/cWidth >= profilesCount/3.5 && pWidth/cWidth < profilesCount/2.5) { scrollerLeft -= pWidth*(3.03/profilesCount); } else { scrollerLeft = (pWidth-cWidth)*-1; } if (scrollerLeft-40 < (pWidth-cWidth)*-1) { scrollerLeft = (pWidth-cWidth)*-1; jQuery(".button-next").addClass("is-inactive"); } jQuery(".employment-profiles").css("left", (scrollerLeft+"px")); } jQuery(".button-prev").click(function() { prevScroll(); }); jQuery(".button-next").click(function() { nextScroll(); }); $('.employment-profiles').swipe( { swipeLeft:function(event, direction, distance, duration, fingerCount) { //console.log("You swiped " + direction ); nextScroll(); }, swipeRight:function(event, direction, distance, duration, fingerCount) { //console.log("You swiped " + direction ); prevScroll(); }, fingers:'all', allowPageScroll:'vertical', threshold:20, excludedElements: "" }); // workaround to get links to swipe & click $('.employment-profile').swipe( { tap:function(event, direction, distance, duration, fingerCount) { window.location = $(this).attr('href'); }, fingers:'all', allowPageScroll:'vertical', threshold:20, excludedElements: "" }); } /* FELLOWS SCROLLER */ /* profiles scroller */ if ($(".fellow-profiles").length > 0) { // get the class number - need to split cause of multiple class names var profilesCount = 15; $(".fellow-profiles").filter(function() { var classNames = this.className.split(" "); for (var i=0; i= profilesCount/2.5) { scrollerLeft += pWidth*(2/profilesCount); } else if (pWidth/cWidth >= profilesCount/3.5 && pWidth/cWidth < profilesCount/2.5) { scrollerLeft += pWidth*(3/profilesCount); } else { scrollerLeft += pWidth*(4/profilesCount); } if (scrollerLeft > -40) { scrollerLeft = 0; $(".button-prev").addClass("is-inactive"); } $(".fellow-profiles").css("left", (scrollerLeft+"px")); } var nextScroll = function () { $(".button-prev").removeClass("is-inactive"); // get the profiles & column widths pWidth = $(".fellow-profiles").width(); cWidth = $("#profiles-scroller").width(); // is it 2, 3, or 4 columns of people? if (pWidth/cWidth >= profilesCount/2.5) { scrollerLeft -= pWidth*(2/profilesCount); } else if (pWidth/cWidth >= profilesCount/3.5 && pWidth/cWidth < profilesCount/2.5) { scrollerLeft -= pWidth*(3/profilesCount); } else { scrollerLeft -= pWidth*(4/profilesCount); } if (scrollerLeft-40 < (pWidth-cWidth)*-1) { scrollerLeft = (pWidth-cWidth)*-1; $(".button-next").addClass("is-inactive"); } $(".fellow-profiles").css("left", (scrollerLeft+"px")); } $(".button-prev").click(function() { prevScroll(); }); $(".button-next").click(function() { nextScroll(); }); $('.fellow-profiles').swipe( { swipeLeft:function(event, direction, distance, duration, fingerCount) { //console.log("You swiped " + direction ); nextScroll(); }, swipeRight:function(event, direction, distance, duration, fingerCount) { //console.log("You swiped " + direction ); prevScroll(); }, fingers:'all', allowPageScroll:'vertical', threshold:20, excludedElements: "" }); // workaround to get links to swipe & click $('.fellow-profile').swipe( { tap:function(event, direction, distance, duration, fingerCount) { window.location = $(this).attr('href'); }, fingers:'all', allowPageScroll:'vertical', threshold:20, excludedElements: "" }); } /* locations map */ if (jQuery(".map-cities").length > 0) { var cityCount = 0; var cities = ["brussels","london","newyork","washington"]; var cityClick = function(aCity, aAuto) { // console.log(aAuto); if (aAuto == false) { clearInterval(autoCity); } else { cityCount++ if (cityCount >= cities.length) { cityCount = 0; } aCity = cities[cityCount]; } jQuery(".info-city").not(".info-"+aCity).hide().removeClass("is-active"); jQuery(".info-"+aCity).fadeIn().addClass("is-active"); jQuery(".bubble-city").not(".bubble-"+aCity).removeClass("is-active"); jQuery(".bubble-"+aCity).addClass("is-active"); } // switch from absolute to relative positioning and back? jQuery(".bubble-brussels").click(function() { cityClick("brussels", false); return false; }); jQuery(".bubble-london").click(function() { cityClick("london", false); return false; }); jQuery(".bubble-newyork").click(function() { cityClick("newyork", false); return false; }); jQuery(".bubble-washington").click(function() { cityClick("washington", false); return false; }); var autoCity = setInterval(function(){cityClick("", true)}, 6000); } /* Possibly get rid of the clear issue #189 - MAY need commented parts as well */ if ((jQuery(".group-downloads").length > 0 /* || jQuery(".field-name-field-file-uploads-collection").length > 0 */) && jQuery(".views-field-field-featured-media").length == 0) { jQuery(".group-downloads").css('clear','none'); /* jQuery(".field-name-field-file-uploads-collection").css('clear','none'); */ } /* get rid of the empty quote block */ if (jQuery(".group-quote").length > 0) { if (trim(jQuery(".group-quote").html()) == "") { jQuery(".group-quote").hide(); } } /* get rid of empty left nav blocks */ if (jQuery("#block-views-left-menu-block .views-row").length > 0) { if (trim(jQuery("#block-views-left-menu-block .views-row").html()) == "") { jQuery("#block-views-left-menu-block").hide(); } } /* get rid of the empty Moving Walls h3 in menu */ jQuery('.collection-group h3') .filter(function() { return jQuery.trim(jQuery(this).text()) === '' }) .remove() /* IE7 clearfix fix test */ if(jQuery.browser.msie && parseInt(jQuery.browser.version, 10) == 7) { if (jQuery(".node-type-blog-entry #block-system-main .clearfix").length > 0) { jQuery(".node-type-blog-entry #block-system-main .clearfix").removeClass("clearfix"); } if (jQuery(".node-type-event #block-system-main .clearfix").length > 0) { jQuery(".node-type-event #block-system-main .clearfix").removeClass("clearfix"); } if (jQuery(".node-type-work-product #block-system-main .clearfix").length > 0) { jQuery(".node-type-work-product #block-system-main .clearfix").removeClass("clearfix"); } if (jQuery(".node-type-profile #block-system-main .clearfix").length > 0) { jQuery(".node-type-profile #block-system-main .clearfix").removeClass("clearfix"); } if (jQuery(".node-type-job #block-system-main .clearfix").length > 0) { jQuery(".node-type-job #block-system-main .clearfix").removeClass("clearfix"); } if (jQuery(".node-type-grant #block-system-main .clearfix").length > 0) { jQuery(".node-type-grant #block-system-main .clearfix").removeClass("clearfix"); } } /* change list style if download files column is present */ if (jQuery(".group-downloads").length > 0) { jQuery("article ul, article ol").not('.new-featured-work-block ul, .new-featured-work-block ol').css('display','inline-block'); jQuery("article ul, article ol, .node-type-work-product .group_learn_more").not('.new-featured-work-block ul, .new-featured-work-block ol').css('max-width','440px'); } /* re-org of grantees listing page */ if(jQuery(".view-grantee-search .view-header h2").length){ if(jQuery("section.block-open-society-institute-baltimore").length) { jQuery(".view-grantee-search .view-header h2").html('Grantees & Fellows'); } if(jQuery("section.block-u-s-programs").length) { jQuery(".view-grantee-search .view-header h2").html('Grantees & Fellows'); } if(jQuery("section.block-open-society-fellowship").length) { jQuery(".view-grantee-search .view-header h2").html('Fellows'); } if(jQuery("section.block-open-society-presidential-fellow").length) { jQuery(".view-grantee-search .view-header h2").html('Fellows'); } /* remove boxes on the left in lieu of facets */ jQuery('h2.block-title:contains("For Grant Seekers")').closest('section').hide(); //jQuery('h2.block-title:contains("Grantee Spotlight")').closest('section').hide(); jQuery('h2.block-title:contains("This program works on these topics")').closest('section').hide(); jQuery('h2.block-title:contains("This program works in these regions")').closest('section').hide(); jQuery('h2.block-title:contains("Open Society Jobs")').closest('section').hide(); } /* re-org of grantee page */ if(jQuery("body.node-type-grantee").length){ jQuery("div.block-client-block-40648").hide(); jQuery('h2.block-title:contains("For Grant Seekers")').closest('section').hide(); jQuery('h2.block-title:contains("Grantee Spotlight")').closest('section').hide(); jQuery('h2.block-title:contains("This program works on these topics")').closest('section').hide(); jQuery('h2.block-title:contains("This program works in these regions")').closest('section').hide(); jQuery('h2.block-title:contains("Open Society Jobs")').closest('section').hide(); jQuery('ul.menu li.grantees a').addClass('active-trail active'); jQuery('ul.menu li.granteesfellows a').addClass('active-trail active'); } /* pre-select subsciption checkbox */ if (jQuery("body.page-email-updates").length){ var preselect = extractParamFromUri(document.URL,'preselect'); if (preselect) { preselect = preselect.capitalizeFirstLetter(); var preselector = "input[name='" + preselect + "']"; var checkedbox = jQuery(preselector); if (checkedbox.length) { checkedbox.prop( "checked", true ); } } } /* remove left rail for project termsearch */ if(jQuery("body.page-termsearch").length){ if(!jQuery("body.logged-in").length){ if(jQuery("h1.field-content").html() == 'Projects'){ jQuery("aside#region-sidebar-first section").hide(); jQuery("div#region-content").css('width','100%'); } } } /* give a "nice" "not found" message for global search */ if(jQuery("body.page-search").length){ if(!jQuery('div.view-site-search li.views-row-1').length){ jQuery("aside#region-sidebar-first section").hide(); jQuery("section.block-search-api-sorts").hide(); jQuery("div#region-content").css('width','100%'); jQuery("div#region-content").html('

Your search did not return any results.

\

Please try one of the following tips to improve your results:

\

    • Check your spelling and try your search again
\     • Use fewer or alternate terms to conduct your search
\     • Use the navigation at the top of the site to browse for the information

'); } } /* remove offending org units */ var t_orgunits = [jQuery('.views-field-field-org-unit .field-content').not('.view-node-meta-data.view-id-node_meta_data .views-field-field-org-unit .field-content')]; // baseline to always remove var exclude_orgunits = ['New York', 'Budapest', 'Washington', 'GmbH', 'D.C.', 'London']; // get person type to remove board listings var person_type = jQuery('body.node-type-profile .views-field-field-osf-uplink a').html(); if(person_type === 'Boards'){ exclude_orgunits.push('/programs'); exclude_orgunits.push('/offices-foundations'); } else { exclude_orgunits.push('boards'); } // remove osife office exclude_orgunits.push('offices-foundations/open-society-initiative-europe'); for(var y=0; y 0) { jQuery(this).html(jQuery(this).text()); } var is_office = jQuery(this).html(); if( is_office.search('open-society-european-policy-institute') != -1 || is_office.search('open-society-policy-center') != -1) { if(display_org_units.length > 1) { var new_label = 'Program / Office'; } else { var new_label = 'Office'; } jQuery('body.node-type-profile #block-views-experts-block-4 .views-label-field-org-unit').html(new_label); } //Hide box if there are no org units left if(jQuery(this).html() == ''){ jQuery('body.node-type-profile #block-views-experts-block-4').hide(); } }); } /* Make blog filter only work one click deep */ function swapQueryStringParams(obj,prefix,hash){ var url = jQuery(obj).attr('href').split('?'); if(url[1]){ var qstring = url[1].split('&'); if(qstring[1]){ var qparam_0 = qstring[0].split('='); var qparam_1 = qstring[1].split('='); var qparam_new = prefix + '?' + qparam_0[0] + '=' + qparam_1[1]; } else { var qparam_new = prefix + '?' + qstring[0]; } if(hash){ var qparam_new = qparam_new + '#' + hash; } jQuery(obj).attr('href', qparam_new); } } jQuery("body.node-type-blog-front #block-facetapi-buvszc7noka575alclyqn06sy5yhwn5o .item-list li a").each(function(){ swapQueryStringParams(this,'/voices','main-content'); }); jQuery("body.node-type-blog-front #block-facetapi-fednlexkh5copndxqcra8ntoz0lyqsef .item-list li a").each(function(){ swapQueryStringParams(this,'/voices','main-content'); }); jQuery("body.page-about-experts #block-facetapi-thw3pzsghmu25wprg1huqevakesecqxl .item-list li a").each(function(){ swapQueryStringParams(this,'/about/experts','main-content'); }); jQuery("body.page-about-experts #block-facetapi-ve5ghlkxqsridm5zdijcig0yh5g7urfd .item-list li a").each(function(){ swapQueryStringParams(this,'/about/experts','main-content'); }); /* Remove empty sort_bef_combine= variable in query string */ jQuery("body.page-grants-search-results ul.pager li a").each(function(){ var pager_url = jQuery(this).attr('href'); pager_url = pager_url.replace('sort_bef_combine=&', ''); jQuery(this).attr('href',pager_url); }); /* Higlight correct grant search toggle when coming from home page */ if(jQuery("body.grants-landing input#edit-grant-type-38").length) { var grant_toggle = extractParamFromUri(document.URL,'t'); if(grant_toggle=='individual'){ jQuery("input#edit-grant-type-39").attr('checked',''); jQuery("input#edit-grant-type-38").attr('checked','checked'); } } /* Capitalize search button */ jQuery("input#edit-submit-site-search").attr('value','Search'); /* Fix search action on 404 page */ if(jQuery("body.page-node-40817").length) { jQuery("form#osf-search-global-search-form").attr('action','/404-error'); if(document.URL.match(/\/grants/gi)) { jQuery("title").html('Grant not found'); jQuery(".views-field-title span").html('Grant not found'); jQuery(".field-name-body div div").html('The grant page you are seeking no longer exists. Please visit our grants homepage for further information on our funding priorities.'); } } /* Remove social share widget if job isn't found */ if(document.URL.match(/\/jobs/gi)) { if(jQuery("h1.no-job-found").text() == 'Job not found'){ jQuery("#block-boxes-page-tools").hide(); } } /* Get about us link on the experts page */ if(jQuery("body.page-about-experts").length){ var uplink = ''; jQuery("section#block-boxes-experts-intro-box h2.block-title").parent().before(uplink); }; /* Hide superfluous email notification error message */ if(jQuery('body.node-type-blog-entry.logged-in div.error ul li:contains("Unable to send e-mail")').length){ jQuery('body.node-type-blog-entry.logged-in div.error').hide(); } // Make sure our heights are the same for program overlay var h1 = jQuery(".program-overlay").height(); jQuery(".program-overlay").hide(); var h2 = jQuery(".region-wrapper-second").height(); if (h1>h2) { jQuery(".region-wrapper-second").height(h1); } else { jQuery(".program-overlay").height(h2); } // Clean up margin on program overlay jQuery(".program-overlay").closest(".block").css('margin','0'); // Toggle related program open jQuery(".issue-related-programs-open").live('click', function(event) { jQuery('.issue-related-programs-open .close-icon').html("×"); jQuery(".region-wrapper-irt-middle").fadeToggle(); jQuery(".region-postscript-fourth").fadeToggle(); jQuery("#block-system-main--2").fadeToggle(function(event) { jQuery(".program-overlay").fadeToggle(); }); jQuery(this).removeClass("issue-related-programs-open"); jQuery(this).addClass("issue-related-programs-close"); event.preventDefault(); }); // Toggle related program close jQuery(".issue-related-programs-close").live('click', function(event) { jQuery('.issue-related-programs-close .close-icon').html("»"); jQuery(".program-overlay").fadeToggle(function(event) { jQuery("#block-system-main--2").fadeToggle(); jQuery(".region-wrapper-irt-middle").fadeToggle(); jQuery(".region-postscript-fourth").fadeToggle(); }); jQuery(this).removeClass("issue-related-programs-close"); jQuery(this).addClass("issue-related-programs-open"); event.preventDefault(); }); jQuery(".program-close").live('click', function(event) { jQuery(".issue-related-programs-close").click(); event.preventDefault(); }); // Retitle our offices-foundations grouping var offices_foundations_grouping = jQuery('.view-offices-foundations h3:contains("Offices-Foundations")'); if (offices_foundations_grouping.length) { offices_foundations_grouping.html('Offices & Foundations'); } // Retitle our offices-foundations grouping var staff_offices_foundations_grouping = jQuery('.view-display-id-staff_home h3:contains("Offices-Foundations")'); if (staff_offices_foundations_grouping.length) { staff_offices_foundations_grouping.html('Offices'); } // Add current or past class to event carousel items if(jQuery("div.view-section-front-featured [property='dc:date']").length){ var today = new Date(); var event_end = jQuery("div.view-section-front-featured .date-display-end[property='dc:date']"); var event_end_content = jQuery("div.view-section-front-featured .date-display-end[property='dc:date']").attr('content'); // If there's no end date set, use the start date if(!event_end.length){ event_end = jQuery("div.view-section-front-featured .date-display-start[property='dc:date']"); event_end_content = jQuery("div.view-section-front-featured .date-display-start[property='dc:date']").attr('content'); } if(event_end_content.length){ var event_end_date = new Date(event_end_content); if(today > event_end_date ){ event_end.parents('div.view-section-front-featured').addClass('event-past'); } else { event_end.parents('div.view-section-front-featured').addClass('event-current'); } } } // Remove pipe separator in carousels if there is no media icon to display, ugh jQuery('.view-section-front-featured .post-info .vertical-separator').each(function(){ if(!jQuery(this).next().length){ jQuery(this).hide(); } if(jQuery(this).next().hasClass('qa')){ jQuery(this).hide(); } if(jQuery(this).next().hasClass('grantee-spotlight')){ jQuery(this).hide(); } }); // Click and wait on form submission // Click and wait on contact submissions // 39558 - english, 57252 - hungarian // see: https://stackoverflow.com/questions/2830542/prevent-double-submission-of-forms-in-jquery jQuery("#comment-form, #webform-client-form-39558, #webform-client-form-57252").submit(function( event ) { var $form = $(this); if ($form.data('submitted') === true) { // Previously submitted - don't submit again console.log('Form already submitted. Please wait.'); event.preventDefault(); } else { // Mark it so that the next submit can be ignored // ADDED requirement that form be valid if($form.valid()) { $form.data('submitted', true); jQuery(this).find(':submit').attr('disabled', true); jQuery(this).find(':submit').attr('value', 'Please wait...'); jQuery(this).find(':submit').css('background-color', '#999'); } } }); // Add class to postscript-second region to dynamically adjust width if the next region doesn't exist on taxonomy pages if(!jQuery('body.page-taxonomy-term .region-postscript-third').length) { jQuery('body.page-taxonomy-term .region-postscript-second').addClass('three-fourth-region'); } // Sort learn more items at the bottom of publications and voices posts var learn_more = jQuery('.field-group-format.group_learn_more div span').sort(function (a, b) { return jQuery(a).text() > jQuery(b).text(); }); var learn_more_list = jQuery(learn_more).map(function(i, opt) { return jQuery(opt)[0].outerHTML; }).toArray().join(', '); jQuery('.field-group-format.group_learn_more div').html(learn_more_list); // VIDEOS PAGES // add no-touch class... see: www.nczonline.net/blog/2012/07/05/ios-has-a-hover-problem/ if (!("ontouchstart" in document.documentElement)) { document.documentElement.className += " no-touch"; } if ($('.context-videos .block-views-taxonomy-terms-video-topics').length) { // videos homepage if ($('.page-videos .view-display-id-video_home .view-header').length) { $('.context-videos .block-views-taxonomy-terms-video-topics h2').appendTo('.page-videos .view-display-id-video_home .view-header'); $('.context-videos .block-views-taxonomy-terms-video-topics .item-list').appendTo('.page-videos .view-display-id-video_home .view-header'); $('.page-videos .view-display-id-video_home .view-header h2').click(function() { $(this).toggleClass('clicked'); var positionTopics = $(this).position(); var topTopics = positionTopics.top; var placeTopics = $(this).height() + topTopics - 2; $('.page-videos .view-display-id-video_home .view-header .item-list').css('top', +'px'); $('.page-videos .view-display-id-video_home .view-header .item-list').toggle(); }); // videos topics pages } else if ($('.page-taxonomy .view-display-id-video_taxonomy .view-header').length) { $('.context-videos .block-views-taxonomy-terms-video-topics h2').appendTo('.page-taxonomy .view-display-id-video_taxonomy .view-header'); $('.context-videos .block-views-taxonomy-terms-video-topics .item-list').appendTo('.page-taxonomy .view-display-id-video_taxonomy .view-header'); $('.page-taxonomy .view-display-id-video_taxonomy .view-header h2').click(function() { $(this).toggleClass('clicked'); var positionTopics = $(this).position(); var topTopics = positionTopics.top; var placeTopics = $(this).height() + topTopics - 2; $('.page-videos .view-display-id-video_home .view-header .item-list').css('top', +'px'); $('.page-taxonomy .view-display-id-video_taxonomy .view-header .item-list').toggle(); }); // currently playing video pages } else if ($('.page-node .view-display-id-video_related_videos .view-header').length) { $('.context-videos .block-views-taxonomy-terms-video-topics h2').appendTo('.page-node .view-display-id-video_related_videos .view-header'); $('.context-videos .block-views-taxonomy-terms-video-topics .item-list').appendTo('.page-node .view-display-id-video_related_videos .view-header'); $('.page-node .view-display-id-video_related_videos .view-header h2').click(function() { $(this).toggleClass('clicked'); var positionTopics = $(this).position(); var topTopics = positionTopics.top; var placeTopics = $(this).height() + topTopics - 2; $('.page-videos .view-display-id-video_home .view-header .item-list').css('top', +'px'); $('.page-node .view-display-id-video_related_videos .view-header .item-list').toggle(); }); } } function repairRelatedVideoImages(){ if ($('.context-videos').length) { $('.region-content .views-field-field-osf-main-image img').each(function(index) { var img = $(this); var pic_real_width, pic_real_height; $("") .attr("src", $(img).attr("src")) .load(function() { pic_real_width = this.width; pic_real_height = this.height; if ((this.width / this.height) < 1.44) { img.addClass('tall-fix'); } else if ((this.width / this.height) > 1.54) { img.addClass('short-fix'); } img.addClass('show-fix'); }); }); } } // END VIDEOS PAGES // Add smooth scrolling to employment page if(window.location.pathname == '/employment'){ $("a[href=#profiles]").click(function(event) { event.preventDefault(); $('html, body').animate({ scrollTop: $("#profiles").offset().top }, 1000); }); $("a[href=#benefits]").click(function(event) { event.preventDefault(); $('html, body').animate({ scrollTop: $("#benefits").offset().top }, 1500); }); $("a[href=#locations]").click(function(event) { event.preventDefault(); $('html, body').animate({ scrollTop: $("#locations").offset().top }, 2000); }); } // Add some functionality to video page if(jQuery('body.node-type-osf-video').length) { function attachSocial() { // reattach social var current_url = get_prod_url_ssl(); jQuery('button.social-facebook').unbind("click"); jQuery('button.social-facebook').click( function(event) { event.preventDefault(); var s_options_facebook = 'width=550,height=330,status=no,scrollbars=yes,resizable=yes,location=yes'; var s_link_facebook = 'https://www.facebook.com/sharer.php?u=' + current_url; window.open(s_link_facebook, '', s_options_facebook); }); jQuery('button.social-linkedin').unbind("click"); jQuery('button.social-linkedin').click( function(event) { event.preventDefault(); var s_options_linkedin = 'width=600,height=500,status=no,scrollbars=yes,resizable=yes,location=yes'; var s_link_linkedin = 'https://www.linkedin.com/shareArticle?mini=true&url=' + current_url; window.open(s_link_linkedin, '', s_options_linkedin); }); jQuery('button.social-twitter').unbind("click"); jQuery('button.social-twitter').click( function(event) { event.preventDefault(); get_bitly_url(get_prod_url_ssl()); var s_twitter_options = 'width=600,height=330,status=no,scrollbars=yes,resizable=yes,location=yes'; var s_hash_via = 'opensociety'; var s_short_link = jQuery('button.social-twitter').attr('data-short-url'); var s_msg_twitter = jQuery('meta[property="osf:tweet"]').attr('content'); if(!s_msg_twitter){ var s_msg_twitter = jQuery('meta[property="og:title"]').attr('content'); } var s_link_twitter = 'https://twitter.com/intent/tweet?text=' + encodeURIComponent(s_msg_twitter) + '&url=' + s_short_link + '&via=' + s_hash_via + '&original_referer=' + current_url; window.open(s_link_twitter, '', s_twitter_options); }); } function swapVideo(data, player_url) { var node = data; jQuery('.video-main-metadata > .views-field-title').html(node['title']); jQuery('meta[property="nid"]').attr('content', node['nid']); jQuery('.video-main-metadata .views-field-created').html(node['date']); jQuery('.video-main-metadata .views-field-video-duration').html(osf_format_time(node['duration'])); jQuery('.video-main-metadata .views-field-body').html(node['body']); jQuery('meta[property="nid"]').attr('content', node['nid']); jQuery('meta[property="og:title"]').attr('content', node['title']); var tw_meta_tag = jQuery('meta[property="osf:tweet"]').attr('content'); if(tw_meta_tag && node['tweet']){ jQuery('meta[property="osf:tweet"]').attr('content', node['tweet']); } else if (node['tweet']) { jQuery('head').append( $('') .attr({property:"osf:tweet", content:node['tweet']}) ); } else { jQuery('meta[property="osf:tweet"]').remove(); } if(node.hasOwnProperty('video_url')){ var yt_url = node['video_url'].split("/"); var yt_id = yt_url[yt_url.length - 1]; var yt_id = yt_id.replace('watch?v=',''); var embed_src = jQuery('#player').attr('src'); var embed_start = embed_src.lastIndexOf('/'); var embed_end = embed_src.indexOf('?'); var embed_ytid = embed_src.substring(embed_start + 1, embed_end); if(embed_ytid != yt_id){ var new_embed = embed_src.replace(embed_ytid, yt_id); setIFrameSrc('player', new_embed); } } if(node.hasOwnProperty('related')){ jQuery('.view-display-id-video_home_node .view-display-id-video_related_content').replaceWith(node['related']); jQuery('.views-field-related').show(); } else { jQuery('.views-field-related').hide(); } // reset attention tracking jQuery.getScript('/sites/all/themes/osf_theme/js/ga_attention_seconds.js'); // reattach social attachSocial(); // add short link get_bitly_url(get_prod_url_ssl()); } function attachVideoAjax() { jQuery('.view-display-id-video_related_videos .view-content .views-row').click(function(event) { event.preventDefault(); var nid = jQuery(".data-nid", this).text(); var player_url = jQuery('.views-field-title span a', this).attr('href'); jQuery("html, body").animate({ scrollTop: 100 }, "slow"); // added to clicked overlay happens right away jQuery('.view-display-id-video_related_videos .views-field-field-osf-main-image a').removeClass('video-playing'); jQuery('.views-field-field-osf-main-image a', this).addClass('video-playing'); // stop current video playing if (typeof(current_player) != 'undefined'){ current_player.stopVideo(); } var endpoint = "/json/videos/node/" + nid; jQuery.ajax({ url: endpoint, dataType: 'json', cache: true }) .done(function(data) { History.pushState(data['nodes'][0]['node'], data['nodes'][0]['node']['title'] + ' | Open Society Foundations (OSF)', player_url); if (typeof ga != "undefined"){ gaTrackPage(location.pathname); } }) .fail(function( jqxhr, textStatus, error ) { console.log( "Request for video failed: " + nid); }); }); } function overlayVideoPlayButton(nid) { // overlay video play button var related_videos = jQuery('.view-display-id-video_related_videos .views-row'); jQuery.each(related_videos, function(index, value){ var thumbnail_nid = jQuery(".data-nid", jQuery(this)).text(); if(nid == thumbnail_nid){ jQuery('.views-field-field-osf-main-image a', jQuery(this)).addClass('video-playing'); } else { jQuery('.views-field-field-osf-main-image a', jQuery(this)).removeClass('video-playing'); } }) } // Reload video with back button var state_change_no_swap = false; History.Adapter.bind(window, 'statechange', function() { var State = History.getState(); var node = State.data; var player_url = node.path; overlayVideoPlayButton(node.nid); if(!state_change_no_swap){ swapVideo(node, player_url); } else { state_change_no_swap = false; } }); // need to create a way to get data and replace history state on first video load attachSocial(); get_bitly_url(get_prod_url_ssl()); var nid = jQuery('meta[property="nid"]').attr('content'); var endpoint = "/json/videos/node/" + nid; jQuery.ajax({ url: endpoint, dataType: 'json', cache: true }) .done(function(data) { attachVideoAjax(); state_change_no_swap = true; History.replaceState(data['nodes'][0]['node'], data['nodes'][0]['node'].title + ' | Open Society Foundations (OSF)', document.URL); }) .fail(function( jqxhr, textStatus, error ) { console.log( "Request for video failed: " + nid); }); // fire any events that need to be added after views load more pager click Drupal.behaviors.relatedVideos = { attach: function (context, settings) { var nid = jQuery('meta[property="nid"]').attr('content'); overlayVideoPlayButton(nid); jQuery('.view-display-id-video_related_videos .view-content .views-row').unbind( "click" ); attachVideoAjax(); } }; } repairRelatedVideoImages(); Drupal.behaviors.relatedVideosThumbFix = { attach: function (context, settings) { repairRelatedVideoImages(); } }; if(jQuery('body.page-publication-search-iframe').length) { // Add a target _blank to publication_iframe jQuery('.view-display-id-page_iframe .views-field-title a').attr('target','_blank'); // Change target of search form jQuery('#views-exposed-form-publication-search-page').attr('action','/publication-search-iframe'); } /* give a "nice" "not found" message for pubs search */ if(jQuery("body.page-publication-search-iframe").length || jQuery("body.page-publication-search").length){ // Change label of facet reveal jQuery('.sidebar-link a').text('Filter'); if(!jQuery('div.view-publication-search li.views-row-1').length){ jQuery("aside#region-sidebar-first section").hide(); jQuery("section.block-search-api-sorts").hide(); jQuery("div#region-content").css('width','100%'); jQuery("div#region-content").html('

Your search did not return any results.

\

Please try one of the following tips to improve your results:

\

• Check your spelling and try your search again.
\ • Use fewer or alternate terms to conduct your search.'); } } });