/**
* configuration.js
*
* Created by Matthias Seemann on 7.01.2013.
* Copyright (c) 2013 Visisoft GbR. All rights reserved.
*
* @module configuration
* @desc internal module
*/
define(['underscore'], function(_)
{
/**
* The set of configuration options for the API
* @memberof LiveSupport.VisitorAPI
* @enum {Object}
*/
var configuration = {
/**
* @type {boolean}
*/
DEBUG : true,
/**
* @type {boolean}
*/
DEBUG_VERBOSE : false,
/**
* internal version number
* @type {number}
*/
VERSION : 2.0,
/**
* internal product development number
* @type {number}
*/
REVISION : 1099,
/**
* the yalst site id
* @type {string}
*/
PRODUCT_SITE : '1-1',
/**
* the location of the yalst directory in your Live Support product
* @type {string}
*/
PRODUCT_URL : '//blackhole.webpagetest.org/yalst/',
/**
* a particular yalst department id, if <tt>undefined</tt> any department applies
* @type {string}
*/
PRODUCT_DEPARTMENT : undefined,
/**
* @type {boolean}
*/
IS_ASSOCIATED : false,
/**
* Seconds needed to elapse before an unresponsive network request is timed out.
* @type {number}
*/
SERVER_TIMEOUT_SECS : 10.0,
/**
* @private
* @type {Number}
* @default milliseconds elapsed since 01 January, 1970 to the time when this configuration
* is first
* accessed by the browser
*/
API_LOAD_TIMESTAMP : (new Date()).getTime(),
/**
* the global namespace
* access the global Api object with <tt>window[Configuration.configuration.GLOBAL_NAMESPACE]</tt>.
* @type {string}
*/
GLOBAL_NAMESPACE: "LiveSupportDIY"
};
return {
/**
* Utility method to retrieve the API version including the revision number
* @return {string}
* @memberof LiveSupport.VisitorAPI
* @see LiveSupport.VisitorAPI.configuration
*/
getVersionString : function()
{
return configuration.VERSION.toString() + ' (rev.' + configuration.REVISION + ')';
},
/**
* Utility method to retrieve the release version as floating point number e.g. 1.2
* @return {number}
* @memberof LiveSupport.VisitorAPI
* @see LiveSupport.VisitorAPI.configuration
*/
getVersion : function()
{
return configuration.VERSION;
},
/**
* Associates the Visitor API with a site on a yalst server.<br/><br/>
* IMPORTANT: <em>The first method that must be called before calling any other method of
* the API.</em><br/><br/>
* Other API method calls prior to this method will
* return an Error with a code number
* <tt>LiveSupport.VisitorAPI.ErrorCode.ServerNotYetAssociated</tt>. The configuration is not
* checked for validity at this point.
* @param {string} productUrl The url to the yalst directory
* e.g. <tt>http://example.com/yalst</tt>. Must always
* include the correct scheme <tt>http:</tt> or <tt>https:</tt> corresponding your yalst
* server configuration. (If your server is hosted by <em>Visisoft</em>
* use <tt>https:</tt>, otherwise check
* <tt>yalst.ini</tt> in <tt>yalst/data/</tt> for the entry <tt>ssl2</tt>.)
* @param {string} siteId The code for the site as configured on the yalst server e.g. '1-1'
* @param {string} [defaultDepartmentId=undefined] Sets the default value of the
* department id for all subsequent calls to the Visitor API.
* Undefined means any department.
* @memberof LiveSupport.VisitorAPI
* @see LiveSupport.VisitorAPI.disassociateFromLiveSupportProduct
* @example
LiveSupport.VisitorAPI.invoke('associateWithLiveSupportProduct'
, ["https://" + YALST_INSTALLATION_URL, "YourYalstSiteId"]
, function(){
LiveSupport.VisitorAPI.getOperatorAvailability(function(status){
if (status == LiveSupport.VisitorAPI.Availability.AVAILABLE){
alert("Support department is available from \"YourYalstSiteId\"!");
}
});
});
*/
associateWithLiveSupportProduct: function(productUrl, siteId, defaultDepartmentId)
{
if (_(productUrl).last() != '/')
{
productUrl += '/';
}
configuration.PRODUCT_URL = productUrl;
configuration.PRODUCT_SITE = siteId;
configuration.PRODUCT_DEPARTMENT = defaultDepartmentId;
configuration.IS_ASSOCIATED = true;
},
/**
* Clears the association of the API to the particular yalst installation, site and
* default department
* @memberof LiveSupport.VisitorAPI
* @see LiveSupport.VisitorAPI.associateFromLiveSupportProduct
*/
disassociateFromLiveSupportProduct: function()
{
configuration.PRODUCT_DEPARTMENT = undefined;
configuration.IS_ASSOCIATED = false;
},
/**
* Retrieves the internal session id used by for user tracking
* @function module:configuration~getYalstSession
* @inner
* @return {string|null} the live support session id or null if no session issued yet
*/
getYalstSession : function()
{
var match = document.cookie.match(/\bYALSTSESSION=([0-9a-zA-Z]+)(;|$)/);
if (match)
{
return match[1];
}
return null;
},
configuration: configuration
};
});