/*!
* @file CN.utilities.js
* @author Prakash Narasimhamoorthy
* @comment Built using Komodo Edit ...
* @copyright (c) Conde Nast Digital
*/
if (typeof CN === 'undefined' || !CN) {
var CN = {};
}
/**
* CN Utilities Object for STYLE.COM
* @class CN Utilities Object
* @description CN Utilities API implementation
* @public
* @author Prakash Narasimhamoorthy
**/
CN.utilities = CN.utilities || {};
/**
* CN Utilities Socialmedia Object for STYLE.COM
* @class CN Utilities Socialmedia Object
* @description CN Utilities Socialmedia API implementation
* @public
* @author Prakash Narasimhamoorthy
**/
CN.utilities.socialmedia = (function($){
/**
* Default Configuration for Utility Bar.
**/
var defaultConfig = {
/**
* General Configuration for Utility Bar.
**/
general : {
containerId : 'scrolling-utilities',
parentDOMId : 'maincontent',
appendOrPrependInsideParent : 'prepend',
scrollable : false,
featureBarId : 'feature-bar',
pageHeaderId : 'hdr_holder'
},
/**
* Facebook Social Media Plugin Configuration for Utility Bar.
**/
fbPlugin : {
containerClass : 'fb-container',
siteURL : location.href,
sendButton : false,
layout : 'box_count',
width : 48,
height : 61,
iframeWidth : "100%",
iframeHeight : "100%",
showFaces : false,
action : 'like',
colorScheme : 'light',
scrolling : 'no',
frameBorder : 0,
allowTransparency : true,
horizontalContainerClass : 'fb-container',
horizontalSiteURL : location.href,
horizontalSendButton : false,
horizontalLayout : 'button_count',
horizontalWidth : 48,
horizontalHeight : 61,
horizontalIframeWidth : "100%",
horizontalIframeHeight : "100%",
horizontalShowFaces : false,
horizontalAction : 'like',
horizontalColorScheme : 'light',
horizontalScrolling : 'no',
horizontalFrameBorder : 0,
horizontalAllowTransparency : true,
OGImage : "/images/feature/promo/placeholder_96x96.gif"
},
/**
* Twitter Tweet Social Media Plugin Configuration for Utility Bar.
**/
tweet : {
containerClass : 'tw-container',
countURL : location.href,
language : 'en',
count : 'vertical',
twittingURL : location.href,
scrolling : 'no',
frameBorder : 0,
allowTransparency : true,
iframeWidth : "100%",
iframeHeight : "100%",
horizontalContainerClass : 'tw-container',
horizontalCountURL : location.href,
horizontalLanguage : 'en',
horizontalCount : 'horizontal',
horizontalTwittingURL : location.href,
horizontalScrolling : 'no',
horizontalFrameBorder : 0,
horizontalAllowTransparency : true,
horizontalIframeWidth : "100%",
horizontalIframeHeight : "100%"
},
/**
* Google Plus One Social Media Plugin Configuration for Utility Bar.
**/
plusOne : {
containerClass : 'gpo-container',
size : 'tall',
annotation : 'bubble',
plusOnedURL : location.href,
width : 50,
height : 60,
scriptSourceURL : '//apis.google.com/js/plusone.js',
asynchronous : true,
horizontalContainerClass : 'gpo-container',
horizontalSize : 'medium',
horizontalAnnotation : 'bubble',
horizontalPlusOnedURL : location.href,
horizontalWidth : 59,
horizontalHeight : 20
},
/**
* Pinterest's Pinit Social Media Plugin Configuration for Utility Bar.
**/
pinIt : {
pinningImageURL : $("body img").eq(0).attr("src"),
containerClass : 'pit-container',
pinningURL : location.href,
countLayout : 'vertical',
buttonImageURL : '//assets.pinterest.com/images/PinExt.png',
buttonTitle : 'Pin It',
scriptSourceURL : '//assets.pinterest.com/js/pinit.js',
horizontalPinningImageURL : $("body img").eq(0).attr("src"),
horizontalContainerClass : 'pit-container',
horizontalPinningURL : location.href,
horizontalCountLayout : 'horizontal',
horizontalButtonImageURL : '//assets.pinterest.com/images/PinExt.png',
horizontalButtonTitle : 'Pin It'
},
/**
* Vertical Scrolling Utility Bar & Horizontal(Non-Scrolling) Utility Bar Display Configuration.
**/
scrollingUtilityBar : {
className : 'fixed',
hideClassName : 'hide',
completeScrolling : true,
showHorizontalOnResize : true,
horizontalParentDOMId : 'canvas',
horizontalAppendOrPrependInsideParent : 'prepend',
horizontalContainerId : 'horizontal-utilities',
horizontalHideClassName : 'hide',
firstElementClassName : 'first',
lastElementClassName : 'last',
horizontalFirstElementClassName : 'first',
horizontalLastElementClassName : 'last'
}
},
patterns = {
alphaNumeric: {
alphaGlobalCaseInSensitive : /[a-z]/gi,
alphaGlobalCaseSensitive : /[a-z]/g,
alphaNonGlobalCaseInSensitive : /[a-z]/i
},
spaceCharacters : {
startSpaceEndSpaceSelection : /^\s+|\s+$/g,
singleSpaceSelection : " "
}
},
/**
* Trim Spaces in a String.
**/
trim = function(str){
if(str) {
str = str.replace(patterns.spaceCharacters.startSpaceEndSpaceSelection,"");
}
return str;
},
/**
* Normalize Relative Paths with Absolute URLs
**/
normalizeURL = function(url) {
if(url) {
var checkURL = url.toLowerCase();
if(checkURL.indexOf("http") === 0) {
return url;
} else if(url.indexOf("//") === 0) {
return location.protocol + url;
} else if(url.indexOf("/") === 0) {
return location.protocol +"//"+ location.host + url;
} else {
return location.protocol +"//"+ url;
}
}
return url;
},
/**
* Check whether the script file is already included in the page
**/
isScriptIncluded = function(scriptFile) {
var scriptIncluded = false;
if(scriptFile) {
$("script").each(function(){
if($(this).attr('src') && (($(this).attr('src')).indexOf(scriptFile) !== -1)) {
scriptIncluded = true;
}
});
}
return scriptIncluded;
},
/**
* Get Numeric Value
**/
getNumericValue = function(val) {
if(val && !isNaN(val)) {
return parseInt(val, 10);
}
return 0;
},
/**
* Toggle Horizontal(Non Scroll) and Vertical Social Media Scroll Bar
**/
toggleScrollingUtilityBar = function(resizeParams){
if(resizeParams.windowWidth < (resizeParams.horizontalParentWidth - (2 * resizeParams.sidebarContainerMarginLeft))) {
$("#"+ defaultConfig.general.containerId).removeClass(defaultConfig.scrollingUtilityBar.hideClassName).addClass(defaultConfig.scrollingUtilityBar.hideClassName);
$("#"+ defaultConfig.scrollingUtilityBar.horizontalContainerId).removeClass(defaultConfig.scrollingUtilityBar.horizontalHideClassName);
} else {
$("#"+ defaultConfig.scrollingUtilityBar.horizontalContainerId).removeClass(defaultConfig.scrollingUtilityBar.horizontalHideClassName).addClass(defaultConfig.scrollingUtilityBar.horizontalHideClassName);
$("#"+ defaultConfig.general.containerId).removeClass(defaultConfig.scrollingUtilityBar.hideClassName);
}
},
/**
* Monitor Social Media Bar on Window Resize
**/
monitorWindowResize = function() {
var windowWidth = $(window).width(),
horizontalParentWidth = $("#"+ defaultConfig.scrollingUtilityBar.horizontalContainerId).parent().width(),
sidebarContainerMarginLeft = ($("#"+defaultConfig.general.containerId).css('margin-left'));
horizontalParentWidth = getNumericValue(horizontalParentWidth);
if(sidebarContainerMarginLeft) {
sidebarContainerMarginLeft = sidebarContainerMarginLeft.replace(patterns.alphaNumeric.alphaGlobalCaseInSensitive, "");
} else {
sidebarContainerMarginLeft = 0;
}
sidebarContainerMarginLeft = getNumericValue(sidebarContainerMarginLeft);
$(window).resize(function(){
windowWidth = $(window).width();
toggleScrollingUtilityBar({'windowWidth' : windowWidth,
'horizontalParentWidth' : horizontalParentWidth,
'sidebarContainerMarginLeft' : sidebarContainerMarginLeft});
});
toggleScrollingUtilityBar({'windowWidth' : windowWidth,
'horizontalParentWidth' : horizontalParentWidth,
'sidebarContainerMarginLeft' : sidebarContainerMarginLeft});
},
/**
* Set Scrolling for Vertical Social Media Bar.
**/
setScrolling = function(){
var scrollingSocialBarHeight = 0,
windowTop = 0,
mainContentHeight = 0,
trimLastSpace = 0,
mainLastMarginBottom = $("#"+ defaultConfig.general.parentDOMId +" > *").last().css("margin-bottom");
if(defaultConfig.general.scrollable) {
$("#"+ defaultConfig.general.containerId).removeClass(defaultConfig.scrollingUtilityBar.className).addClass(defaultConfig.scrollingUtilityBar.className);
}
if(defaultConfig.general.scrollable && !defaultConfig.scrollingUtilityBar.completeScrolling) {
$(window).scroll(function(){
scrollingSocialBarHeight = $("#"+ defaultConfig.general.containerId).height();
mainContentHeight = $("#"+ defaultConfig.general.parentDOMId).height();
windowTop = $(this).scrollTop();
if(mainLastMarginBottom){
trimLastSpace = parseInt(mainLastMarginBottom.replace(patterns.alphaNumeric.alphaGlobalCaseInSensitive, ""), 10);
}
if((scrollingSocialBarHeight + windowTop) >= (mainContentHeight - trimLastSpace)) {
$("#"+ defaultConfig.general.containerId).removeClass(defaultConfig.scrollingUtilityBar.hideClassName).addClass(defaultConfig.scrollingUtilityBar.hideClassName);
} else {
$("#"+ defaultConfig.general.containerId).removeClass(defaultConfig.scrollingUtilityBar.hideClassName);
}
});
}
if(defaultConfig.general.scrollable && defaultConfig.scrollingUtilityBar.showHorizontalOnResize) {
monitorWindowResize();
}
},
/**
* Create Utility Bar Container and Append to its parent.
**/
getUtilityBarContainer = function(params) {
if($("#"+ params.containerId +" > ul").length === 0) {
if($("#"+ defaultConfig.general.pageHeaderId +" #"+ defaultConfig.general.featureBarId).length === 0) {
if(params.appendOrPrepend === 'append') {
$("#"+ params.parentDOMId).append("
");
} else {
$("#"+ params.parentDOMId).prepend("");
}
} else {
$("#"+ defaultConfig.general.featureBarId).after("");
}
}
return $("#"+ params.containerId +" > ul");
},
/**
* Override Default Configuration for the plugin object
**/
overrideConfig = function(config, pluginObj) {
var objName;
for(objName in config) {
defaultConfig[pluginObj][objName] = config[objName];
}
};
return {
/**
* Override All Default Configuration
**/
setConfig : function(config){
var objName;
for(objName in config) {
overrideConfig(config[objName], objName);
}
return this;
},
/**
* Get All Default Configuration
**/
getConfig : function(){
return defaultConfig;
},
/**
* Override General Configuration for the objects
**/
setGeneralConfig : function(generalConfig) {
if(typeof generalConfig === "object") {
overrideConfig(generalConfig, 'general');
}
return this;
},
/**
* Render Iframed Facebook Plugin (Like/Recommend ...etc).. Includes all facebook plugins
**/
getFBPlugin : function(fbPluginConfig) {
var liDOM,
liDOMOpen = "",
liHDOM = "",
liHDOMOpen = "";
if(typeof fbPluginConfig === "object") {
overrideConfig(fbPluginConfig, 'fbPlugin');
}
// Append og:image meta tag in the head
if($('meta[property="og:image"]').length !== 0){
$('meta[property="og:image"]').attr("content", normalizeURL(defaultConfig.fbPlugin.OGImage));
}else{
$('head').append('');
}
liDOMOpen += defaultConfig.fbPlugin.containerClass;
if($("#"+ defaultConfig.general.containerId +" ul li").length === 0) {
liDOMOpen += " "+ defaultConfig.scrollingUtilityBar.firstElementClassName +" "+ defaultConfig.scrollingUtilityBar.lastElementClassName;
} else {
$("#"+ defaultConfig.general.containerId +" ul li").each(function(){
if($(this).hasClass(defaultConfig.scrollingUtilityBar.lastElementClassName)) {
$(this).removeClass(" "+ defaultConfig.scrollingUtilityBar.lastElementClassName);
}
});
liDOMOpen += " "+defaultConfig.scrollingUtilityBar.lastElementClassName;
}
liDOM = liDOMOpen + liDOMClose;
getUtilityBarContainer({
containerId : defaultConfig.general.containerId,
parentDOMId : defaultConfig.general.parentDOMId,
appendOrPrepend : defaultConfig.general.appendOrPrependInsideParent
}).append(liDOM +"");
if(defaultConfig.general.scrollable && defaultConfig.scrollingUtilityBar.showHorizontalOnResize) {
liHDOMOpen += defaultConfig.fbPlugin.horizontalContainerClass;
if($("#"+ defaultConfig.scrollingUtilityBar.horizontalContainerId +" ul li").length === 0) {
liHDOMOpen += " "+ defaultConfig.scrollingUtilityBar.horizontalFirstElementClassName +" "+ defaultConfig.scrollingUtilityBar.horizontalLastElementClassName;
} else {
$("#"+ defaultConfig.scrollingUtilityBar.horizontalContainerId +" ul li").each(function(){
if($(this).hasClass(defaultConfig.scrollingUtilityBar.horizontalLastElementClassName)) {
$(this).removeClass(" "+defaultConfig.scrollingUtilityBar.horizontalLastElementClassName);
}
});
liHDOMOpen += " "+defaultConfig.scrollingUtilityBar.horizontalLastElementClassName;
}
liHDOM = liHDOMOpen + liHDOMClose;
getUtilityBarContainer({
containerId : defaultConfig.scrollingUtilityBar.horizontalContainerId,
parentDOMId : defaultConfig.scrollingUtilityBar.horizontalParentDOMId,
appendOrPrepend : defaultConfig.scrollingUtilityBar.horizontalAppendOrPrependInsideParent
}).append(liHDOM +"");
}
if(defaultConfig.general.scrollable) {
setScrolling();
}
return this;
},
/**
* Render Iframed Tweet Plugin (Tweet, Follow ...etc).. Includes all twitter plugins
**/
getTWTweet : function(tweetConfig) {
var liDOM,
liDOMOpen = "",
liHDOM = "",
liHDOMOpen = "";
if(typeof tweetConfig === "object") {
overrideConfig(tweetConfig, 'tweet');
}
liDOMOpen += defaultConfig.tweet.containerClass;
if($("#"+ defaultConfig.general.containerId +" ul li").length === 0) {
liDOMOpen += " "+ defaultConfig.scrollingUtilityBar.firstElementClassName +" "+ defaultConfig.scrollingUtilityBar.lastElementClassName;
} else {
$("#"+ defaultConfig.general.containerId +" ul li").each(function(){
if($(this).hasClass(defaultConfig.scrollingUtilityBar.lastElementClassName)) {
$(this).removeClass(" "+ defaultConfig.scrollingUtilityBar.lastElementClassName);
}
});
liDOMOpen += " "+ defaultConfig.scrollingUtilityBar.lastElementClassName;
}
liDOM = liDOMOpen + liDOMClose;
getUtilityBarContainer({
containerId : defaultConfig.general.containerId,
parentDOMId : defaultConfig.general.parentDOMId,
appendOrPrepend : defaultConfig.general.appendOrPrependInsideParent
}).append(liDOM +"");
if(defaultConfig.general.scrollable && defaultConfig.scrollingUtilityBar.showHorizontalOnResize) {
liHDOMOpen += defaultConfig.tweet.horizontalContainerClass;
if($("#"+ defaultConfig.scrollingUtilityBar.horizontalContainerId +" ul li").length === 0) {
liHDOMOpen += " "+ defaultConfig.scrollingUtilityBar.horizontalFirstElementClassName +" "+ defaultConfig.scrollingUtilityBar.horizontalLastElementClassName;
} else {
$("#"+ defaultConfig.scrollingUtilityBar.horizontalContainerId +" ul li").each(function(){
if($(this).hasClass(defaultConfig.scrollingUtilityBar.horizontalLastElementClassName)) {
$(this).removeClass(" "+ defaultConfig.scrollingUtilityBar.horizontalLastElementClassName);
}
});
liHDOMOpen += " "+ defaultConfig.scrollingUtilityBar.horizontalLastElementClassName;
}
liHDOM = liHDOMOpen + liHDOMClose;
getUtilityBarContainer({
containerId : defaultConfig.scrollingUtilityBar.horizontalContainerId,
parentDOMId : defaultConfig.scrollingUtilityBar.horizontalParentDOMId,
appendOrPrepend : defaultConfig.scrollingUtilityBar.horizontalAppendOrPrependInsideParent
}).append(liHDOM +"");
}
if(defaultConfig.general.scrollable) {
setScrolling();
}
return this;
},
/**
* Render Google Plusone Plugin..
**/
getGGPlusOne : function(plusOneConfig) {
if(!$.browser.msie || $.browser.version >= 8.0) { // Google Plus one - IE Compatibility Issue : google plus-one doesnot support any version below IE-8
var gPlusOneObj = document.createElement('g:plusone'),
horizontalGPlusOneObj = document.createElement('g:plusone'),
gPlusOneCont = document.createElement('li'),
horizontalGPlusOneCont = document.createElement('li'),
attributeName = ["size",
"annotation",
"href",
"width",
"height"],
attributeValue,
horizontalAttributeValue,
liFirstLastClass = "";
if(typeof plusOneConfig === "object") {
overrideConfig(plusOneConfig, 'plusOne');
}
attributeValue = [defaultConfig.plusOne.size,
defaultConfig.plusOne.annotation,
encodeURIComponent(defaultConfig.plusOne.plusOnedURL),
defaultConfig.plusOne.width,
defaultConfig.plusOne.height];
horizontalAttributeValue = [defaultConfig.plusOne.horizontalSize,
defaultConfig.plusOne.horizontalAnnotation,
encodeURIComponent(defaultConfig.plusOne.horizontalPlusOnedURL),
defaultConfig.plusOne.horizontalWidth,
defaultConfig.plusOne.horizontalHeight];
if($("#"+ defaultConfig.general.containerId +" ul li").length === 0) {
liFirstLastClass = " "+ defaultConfig.scrollingUtilityBar.firstElementClassName +" "+ defaultConfig.scrollingUtilityBar.lastElementClassName;
} else {
$("#"+ defaultConfig.general.containerId +" ul li").each(function(){
if($(this).hasClass(defaultConfig.scrollingUtilityBar.lastElementClassName)) {
$(this).removeClass(" "+ defaultConfig.scrollingUtilityBar.lastElementClassName);
}
});
liFirstLastClass = " "+defaultConfig.scrollingUtilityBar.lastElementClassName;
}
gPlusOneCont.setAttribute("class", defaultConfig.plusOne.containerClass + liFirstLastClass);
getUtilityBarContainer({
containerId : defaultConfig.general.containerId,
parentDOMId : defaultConfig.general.parentDOMId,
appendOrPrepend : defaultConfig.general.appendOrPrependInsideParent
}).append(gPlusOneCont);
if(defaultConfig.general.scrollable && defaultConfig.scrollingUtilityBar.showHorizontalOnResize) {
if($("#"+ defaultConfig.scrollingUtilityBar.horizontalContainerId +" ul li").length === 0) {
liFirstLastClass = " "+ defaultConfig.scrollingUtilityBar.horizontalFirstElementClassName +" "+ defaultConfig.scrollingUtilityBar.horizontalLastElementClassName;
} else {
$("#"+ defaultConfig.scrollingUtilityBar.horizontalContainerId +" ul li").each(function(){
if($(this).hasClass(defaultConfig.scrollingUtilityBar.horizontalLastElementClassName)) {
$(this).removeClass(" "+ defaultConfig.scrollingUtilityBar.horizontalLastElementClassName);
}
});
liFirstLastClass = " "+ defaultConfig.scrollingUtilityBar.horizontalLastElementClassName;
}
horizontalGPlusOneCont.setAttribute("class", defaultConfig.plusOne.horizontalContainerClass + liFirstLastClass);
getUtilityBarContainer({
containerId : defaultConfig.scrollingUtilityBar.horizontalContainerId,
parentDOMId : defaultConfig.scrollingUtilityBar.horizontalParentDOMId,
appendOrPrepend : defaultConfig.scrollingUtilityBar.horizontalAppendOrPrependInsideParent
}).append(horizontalGPlusOneCont);
}
for(var ind=0; ind");
}
if(defaultConfig.general.scrollable) {
setScrolling();
}
}
return this;
},
/**
* Render Pinterest's Pinit Plugin..
**/
getPIPinIt : function(pinItConfig) {
var liDOM,
liDOMOpen = "",
liHDOM = "",
liHDOMOpen = "";
if(typeof pinItConfig === "object") {
overrideConfig(pinItConfig, 'pinIt');
}
if(defaultConfig.pinIt.pinningImageURL && typeof defaultConfig.pinIt.pinningImageURL === "string" && defaultConfig.scrollingUtilityBar.showHorizontalOnResize && (typeof defaultConfig.pinIt.horizontalPinningImageURL !== "string" || defaultConfig.pinIt.horizontalPinningImageURL === "")) {
defaultConfig.pinIt.horizontalPinningImageURL = defaultConfig.pinIt.pinningImageURL;
}
liDOMOpen += defaultConfig.pinIt.containerClass;
if($("#"+ defaultConfig.general.containerId +" ul li").length === 0) {
liDOMOpen += " "+ defaultConfig.scrollingUtilityBar.firstElementClassName +" "+ defaultConfig.scrollingUtilityBar.lastElementClassName;
} else {
$("#"+ defaultConfig.general.containerId +" ul li").each(function(){
if($(this).hasClass(defaultConfig.scrollingUtilityBar.lastElementClassName)) {
$(this).removeClass(" "+ defaultConfig.scrollingUtilityBar.lastElementClassName);
}
});
liDOMOpen += " "+ defaultConfig.scrollingUtilityBar.lastElementClassName;
}
liDOM = liDOMOpen + liDOMClose;
getUtilityBarContainer({
containerId : defaultConfig.general.containerId,
parentDOMId : defaultConfig.general.parentDOMId,
appendOrPrepend : defaultConfig.general.appendOrPrependInsideParent
}).append(liDOM +"
");
if(defaultConfig.general.scrollable && defaultConfig.scrollingUtilityBar.showHorizontalOnResize) {
liHDOMOpen += defaultConfig.pinIt.horizontalContainerClass;
if($("#"+ defaultConfig.scrollingUtilityBar.horizontalContainerId +" ul li").length === 0) {
liHDOMOpen += " "+ defaultConfig.scrollingUtilityBar.horizontalFirstElementClassName +" "+ defaultConfig.scrollingUtilityBar.horizontalLastElementClassName;
} else {
$("#"+ defaultConfig.scrollingUtilityBar.horizontalContainerId +" ul li").each(function(){
if($(this).hasClass(defaultConfig.scrollingUtilityBar.horizontalLastElementClassName)) {
$(this).removeClass(" "+ defaultConfig.scrollingUtilityBar.horizontalLastElementClassName);
}
});
liHDOMOpen += " "+ defaultConfig.scrollingUtilityBar.horizontalLastElementClassName;
}
liHDOM = liHDOMOpen + liHDOMClose;
getUtilityBarContainer({
containerId : defaultConfig.scrollingUtilityBar.horizontalContainerId,
parentDOMId : defaultConfig.scrollingUtilityBar.horizontalParentDOMId,
appendOrPrepend : defaultConfig.scrollingUtilityBar.horizontalAppendOrPrependInsideParent
}).append(liHDOM +"
");
}
if(!isScriptIncluded(defaultConfig.pinIt.scriptSourceURL)) {
$("script").eq(0).before("");
}
if(defaultConfig.general.scrollable) {
setScrolling();
}
return this;
},
/**
* Remove all Social Media Utility Bar.
**/
clearAll : function(config) {
if(typeof config === "object") {
CN.utilities.socialmedia.setConfig(config);
}
$("#"+ defaultConfig.general.containerId).remove();
if(defaultConfig.general.scrollable && defaultConfig.scrollingUtilityBar.showHorizontalOnResize) {
$("#"+ defaultConfig.scrollingUtilityBar.horizontalContainerId).remove();
}
return this;
},
/**
* Reload All Social Media Utility Plugins.
**/
refreshAll : function(config){
if(typeof config === "object") {
CN.utilities.socialmedia.setConfig(config);
}
CN.utilities.socialmedia.clearAll().getFBPlugin().getTWTweet().getGGPlusOne().getPIPinIt();
return this;
},
/**
* Initialize Social Media Plugins.
**/
init : function(config){
if(typeof config === "object") {
CN.utilities.socialmedia.setConfig(config);
}
CN.utilities.socialmedia.getFBPlugin().getTWTweet().getGGPlusOne().getPIPinIt();
return this;
}
};
}(jQuery));
/**
* CN Utilities General Object for STYLE.COM
* @class CN Utilities General Object
* @description CN Utilities General API implementation
* @public
* @author Prakash Narasimhamoorthy
**/
CN.utilities.general = (function($){
/**
* Default Configuration for Utility Bar.
**/
var defaultConfig = {
/**
* General Configuration for Utility Bar.
**/
general : {
containerId : 'scrolling-utilities',
parentDOMId : 'maincontent',
appendOrPrependInsideParent : 'prepend',
scrollable : false
},
link : {
text : "link",
textContentShrinkGrow : false,
URL : location.href,
target : "_blank",
containerClass : "link-container",
className : "link-class",
titleText : "Link"
},
lookBook : {
text : "lookBook",
containerClass : "addTolookbook-container",
className : "addToLookBook",
titleText : "Add to Look Book",
lbParams : "no-params"
},
textContentShrinkGrow : {
wrapperParentDOMClass : 'link-parent',
wrapperChildDOMClass : 'link-child'
},
/**
* Vertical Scrolling Utility Bar & Horizontal(Non-Scrolling) Utility Bar Display Configuration.
**/
scrollingUtilityBar : {
className : 'fixed',
hideClassName : 'hide',
completeScrolling : true,
showHorizontalOnResize : true,
horizontalParentDOMId : 'canvas',
horizontalAppendOrPrependInsideParent : 'prepend',
horizontalContainerId : 'horizontal-utilities',
horizontalHideClassName : 'hide'
}
},
/**
* Create Utility Bar Container and Append to its parent.
**/
getUtilityBarContainer = function(params) {
if($("#"+ params.containerId +" > ul").length === 0) {
if(params.appendOrPrepend === 'append') {
$("#"+ params.parentDOMId).append("");
} else {
$("#"+ params.parentDOMId).prepend("");
}
}
return $("#"+ params.containerId +" > ul");
},
/**
* Override Default Configuration for the plugin object
**/
overrideConfig = function(config, pluginObj) {
var objName;
for(objName in config) {
defaultConfig[pluginObj][objName] = config[objName];
}
};
return {
/**
* Override All Default Configuration
**/
setConfig : function(config){
var objName;
for(objName in config) {
overrideConfig(config[objName], objName);
}
return this;
},
getLink : function(linkConfig){
var liDOMOpen = "",
liDOMClose = "";
if(typeof linkConfig === "object" && typeof linkConfig.link === "object") {
overrideConfig(linkConfig.link, 'link');
}
if(typeof linkConfig === "object" && typeof linkConfig.textContentShrinkGrow === "object") {
overrideConfig(linkConfig.textContentShrinkGrow, 'textContentShrinkGrow');
}
liDOMOpen += "";
if(defaultConfig.link.textContentShrinkGrow){
liDOMOpen += "";
liDOMClose +="";
}
liDOMClose += "";
getUtilityBarContainer({
containerId : defaultConfig.general.containerId,
parentDOMId : defaultConfig.general.parentDOMId,
appendOrPrepend : defaultConfig.general.appendOrPrependInsideParent
}).append(liDOMOpen + defaultConfig.link.text + liDOMClose);
return this;
},
getLookBook : function(lbConfig){
var liDOMOpen = "",
liDOMClose = "";
if(typeof lbConfig === "object") {
overrideConfig(lbConfig, 'lookBook');
}
liDOMOpen += "";
liDOMClose += "";
getUtilityBarContainer({
containerId : defaultConfig.general.containerId,
parentDOMId : defaultConfig.general.parentDOMId,
appendOrPrepend : defaultConfig.general.appendOrPrependInsideParent
}).append(liDOMOpen + defaultConfig.lookBook.text + liDOMClose);
return this;
},
/**
* Get All Default Configuration
**/
getConfig : function(){
return defaultConfig;
},
/**
* Remove all General Utilities Utility Bar.
**/
clearAll : function(config) {
if(typeof config === "object") {
CN.utilities.general.setConfig(config);
}
$("#"+ defaultConfig.general.containerId).remove();
if(defaultConfig.general.scrollable && defaultConfig.scrollingUtilityBar.showHorizontalOnResize) {
$("#"+ defaultConfig.scrollingUtilityBar.horizontalContainerId).remove();
}
return this;
},
/**
* Reload All Social Media Utility Plugins.
**/
refreshAll : function(config){
if(typeof config === "object") {
CN.utilities.general.setConfig(config);
}
CN.utilities.general.clearAll().getLink();
return this;
},
/**
* Initialize Social Media Plugins.
**/
init : function(config){
if(typeof config === "object") {
CN.utilities.general.setConfig(config);
}
CN.utilities.general.getLink();
return this;
}
};
}(jQuery));