var apiURL = "https://api.businesswire.com/contentapi"; var imageURL = "https://www.businesswire.com/images/restcontent_loading.gif"; /** * ensure all of the variables we need are here; load container page * @param uri */ function loadContainerPage(uri){ if(!varExists("apiURL")){ alert("No api URL provided - sleepycat-properties.js file must be included."); } var encodedURI = encodeURIComponent(uri); var containerSrc = apiURL + "/containerpage/" + encodedURI; replaceBwContent(containerSrc); } /** * returns true if variable defined; else false * @param varToCheck * @returns {Boolean} */ function varExists(varToCheck){ if(typeof(window[varToCheck]) == 'undefined'){ return false; }else{ return true; } } function replaceBwContent(src) { return replaceBwElement('#bwContent', src); } var bwComponents = { bwEventLinks: apiURL + '/profile/bwEventLinks/', bwPressKitLinks: apiURL + '/profile/bwPressKitLinks/', bwEventDetails: apiURL + '/event/bwEventDetails/', bwEventLogo: apiURL + '/event/bwEventLogo/', bwPressKitLogo: apiURL + '/presskit/bwPressKitLogo/', bwEventDesc: apiURL + '/event/bwEventDesc/', bwPressKitDesc: apiURL + '/presskit/bwPressKitDesc/', bwEventTitle: apiURL + '/event/bwEventTitle/', bwPressKitBooth: apiURL + '/presskit/bwPressKitBooth/', bwPressKitTitle: apiURL + '/presskit/bwPressKitTitle/', bwEventSharing: apiURL + '/event/bwEventSharing/', bwPressKitSharing: apiURL + '/presskit/bwPressKitSharing/', bwNewsHeadlines: apiURL + '/headlines/bwNewsHeadlines/', bwNewsRelease: apiURL + '/release/bwNewsRelease/', bwEventNavigation: apiURL + '/event/bwEventNavigation/', bwPressKitNavigation: apiURL + '/presskit/bwPressKitNavigation/', bwBackToEvent: apiURL + '/event/bwBackToEvent/', bwEventPressKits: apiURL + '/event/bwEventPressKits/', bwPressKitAddress: apiURL + '/profile/bwPressKitAddress/', bwPressKitFiles: apiURL + '/presskit/bwPressKitFiles/', bwPressKitContacts: apiURL + '/profile/bwPressKitContacts/', // The following are view only components, meaning they don't have an underlying model but are used // for the layout or presentation of the page only. Examples include search or backTo links bwSearch: apiURL + '/view/bwSearch/', bwBackTo: apiURL + '/view/bwBackTo/', bwNewPopularNavigation: apiURL + '/view/bwNewPopularNavigation/' }; function getBwComponentURL(component) { return bwComponents[component]; } /** * populate the bw Elements * criteria is in the parameters for the page. Each model has it's own criteria * * Example for a pressKit criteria * presskit=IBC2010/ibc2010 * * For headlines * headlines=event/IBC2010?headlines.page=3 * @param criteria */ function populateBwElements(criteria) { bwJQuery(function (){ bwJQuery('div[class^="bw"]').each(function() { var bwObj = this.className; // check if it's a known component if (bwObj in bwComponents) { // check if criteria is available for the component var criteriaValue = getCriteriaForComponent(criteria, bwObj); if (criteriaValue != null) { replaceBwElement('.' + bwObj, bwComponents[bwObj] + criteriaValue); } else if (isViewComponent(bwObj)) { replaceBwElement('.' + bwObj, bwComponents[bwObj]); } } }); }); } function populateTargetBwElements(releaseTargetClass, criteria) { bwJQuery(function (){ var bwObj = "bwNewsRelease"; var criteriaValue = getCriteriaForComponent(criteria, bwObj); if (criteriaValue != null) { replaceBwElement(releaseTargetClass, bwComponents[bwObj] + criteriaValue); } }); } function isViewComponent(component) { if (bwComponents[component] != null && bwComponents[component].indexOf(apiURL + '/view/') == 0) { return true; } else { return false; } } function getComponentCriteria(component) { return getCriteriaForComponent(containerPage.split('?')[1], component); } function getModelCriteria(model) { var criteria = containerPage.split('?')[1]; var criterias = criteria.split('&'); // Can not use foreach syntax - prototyped methods on Array will break // our code // for (idx in criterias) { var len = criterias.length; for(var i=0; i < len; i++){ var modelCriteria = criterias[i]; var split = modelCriteria.split('='); if (split[0] == model) { if ('view' == model){ return split[1] + getQueryParamsForModel(criteria, model); } else { return decodeURIComponent(split[1]) + getQueryParamsForModel(criteria, model); } } } } /** * Use this if you have a select box that changes the headline config. * @param selector jQuery type selector of select list */ function setVnsHeadlineSelect(selector) { if (containerPage.indexOf('headlines.searchTerm=') == -1) { var vnsPatt = /vns\/\d+\/(\d+)/; var vnsId = vnsPatt.exec(getModelCriteria('headlines')); if (vnsId != null && vnsId.length > 1) { bwJQuery(selector).val(vnsId[1]); } } } /** * TODO: Refactor this to put all criteria into an Object, then pull from that object. * Extract the specific criteria for a component from * the URL containing all the criteria for the page * @param criteria the entire page criteria such as 'event=IBC2010&headlines=event%2FIBC2010' * @param component the component such as 'bwEventTitle' * @returns criteria URL decoded for normal components, not decoded for view components */ function getCriteriaForComponent(criteria, component) { var criterias = criteria.split('&'); // Can not use foreach syntax - prototyped methods on Array will break // our code // for (idx in criterias) { var len = criterias.length; for(var i=0; i < len; i++){ var modelCriteria = criterias[i]; var split = modelCriteria.split('='); var criteriaModel = split[0]; // check if this model is appropriate for the Component OR it's a view component. if (bwComponents[component].indexOf(criteriaModel + "/" + component) != -1) { // console.log( decodeURIComponent(split[1]) + getQueryParamsForModel(criteria, criteriaModel)); return decodeURIComponent(split[1]) + getQueryParamsForModel(criteria, criteriaModel); } else if (bwComponents[component].indexOf("view/" + criteriaModel) != -1) { // console.log(split[1] + getQueryParamsForModel(criteria, 'view')); return split[1] + getQueryParamsForModel(criteria, 'view'); } } return null; } /** * Get any params for the model * Example: headlines.page=5 * @param criteria event=IBC2010&presskit=IBC2010/ibc2010&profile=IBC2010/ibc2010&headlines=presskit/IBC2010/ibc2010&bwTabContent=bwNewsHeadlines&headlines.page=2 * @param model headlines or view */ function getQueryParamsForModel(criteria, model) { var params = criteria.split('&'); var modelParams = new Array(); // Can not use foreach syntax - prototyped methods on Array will break // our code // for (idx in params) { var len = params.length; for(var i=0; i < len; i++){ if (params[i].indexOf(model + '.') == 0) { modelParams[modelParams.length] = params[i]; } } if (modelParams.length != 0) { return '?' + modelParams.join('&'); } else { return ''; } } /** * Replace the content of a bw (div) element, optionally adding a new element in the process * @param selector * @param src * @param newBwElement Optional - if specified, create this newBwElement in the selector. * This is currently used with tab navigation (the old content is removed and a new element is created) * @returns {Boolean} */ function replaceBwElement(selector, src, newBwElement) { var element = bwJQuery(selector); // verify the element if (!element.length) { // the bwTabContent may not exist //alert('Cannot find element: ' + selector); return false; } element.empty(); if (newBwElement != undefined) { element.append('