Answerspace JS Events

Global Variables

BICv2 (MyAnswers)

MyAnswers

This is the primary global object for Answerspace manipulation. Use console.log to examine it's available properties.

Key properties

Property
Type
Usage
activityIndicatorDOM referenceUsed to show or hide the loading image.
getGeoLocation()FunctionAttempt to retrieve GPS data from the device.
goToDefaultScreen()FunctionNavigates to the A/S default screen
runningTasksPropertyCounter indicating how many background tasks are running.
storeObjectUsed to set/get Mojo's (see below).
loginAccountObjectList of login info from the Users Session. Only set after login.

siteVars

Contains the Answerspace configuration data. configformsmap and mojos can all be interrogated for further information.

Property
Type
Usage
siteVarsObjectContains all answerSpace object details
siteVars.idPropertyThe answerSpace Id
siteVars.answerSpacePropertyThe answerSpace name
siteVars.serverDomainPropertyThe answerSpace domain
siteVars.serverAppBranchPropertyThe answerSpace application branch
siteVars.serverAppVersionPropertyThe answerSpace application version
siteVars
console.log(siteVars); 
answerSpace: "pdh"
config: Object
forms: Object
hasLogin: true
id: 20127
map: Object
mojos: Object
requestsCounter: 7
serverAppBranch: "R"
serverAppPath: "/_R_/common/3"
serverAppVersion: "3"
serverDevicePath: "/_R_/ios/3"
serverDomain: "blinkm.co"
siteVars.config example
for(item in siteVars.config) {    if(item.substring(0,1) == 'a') { // find the A/S config item
        // echo out the A/S config settings
        console.log(siteVars.config[item].pertinent);
    }
}

 deviceVars

Contains information about the client device.

deviceVars
console.log(deviceVars); 
device: "ios"
engineVersion: "537"
features: Array[7]
isOnline: true
scrollProperty: "-webkit-transform"
scrollValue: "translateY($1px)"
useCSS3animations: true

_Blink & _SERVER

Server-side variables.

_Blink
console.log(_Blink); 
cdnp: a
cfg: Object
    CDN_PLATFORM: Object
    CDN_USER: Object
hasFontFor: function
isBlinkGap: false
isPhantomJS: false
preloadPage: function
stringifyDOM: function
_SERVER
console.log(_SERVER); 
HTTP_ACCEPT: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
HTTP_ACCEPT_ENCODING: "gzip,deflate,sdch"
HTTP_ACCEPT_LANGUAGE: "en-US,en;q=0.8"
HTTP_CONNECTION: "keep-alive"
HTTP_USER_AGENT: "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36"
REQUEST_URI: "/infobooth"
SERVER_PROTOCOL: "HTTP/1.1"

BIC-JQM (BMP.BIC3)

BMP.BIC3

This is the primary global object for Answerspace manipulation. Use console.log to examine it's available properties.

Key properties

Property
Type
Usage
BMP.BIC.currentInteraction()FunctionReturns the current interaction
BMP.BIC3.forms.get('myForm')FunctionReturns the forms object called "myForm"

siteVars

Contains the Answerspace configuration data. configformsmap and mojos can all be interrogated for further information.

Property
Type
Usage
BMP.BIC3.siteVarsObjectContains all answerSpace object details
MP.BIC3.siteVars.answerSpaceIdPropertyThe answerSpace Id
MP.BIC3.siteVars.answerSpacePropertyThe answerSpace name


Events

 

Event
Trigger
viewShowAnswerspace View transition completed, but not yet ready.
viewReadyAnswerspace View is configured and ready.
$(document).on('viewShow', function() {    // this = the .view element
    /* TODO: insert code to run after a view transition is completed */
});
 
$(document).on('viewReady', function() {
    // this = the .view element
    /* TODO: insert code to run after a view has been enhanced with Stars, Forms, Maps, etc */
});
 

 


 

Navigation

Available Functions
goBackTocategoriesView();goBackToHome();
goBackToKeywordListView();
goBackToKeywordView();
goBackToMasterCategoriesView();
goBackToTopLevelAnswerView();
 
// note - these functions require arguments
showAnswerView();
showCategoriesView();
showLoginView();
showSecondLevelAnswerView();

Persistance Storage

BICv2 (MyAnswers.store)

MyAnswers.store object provides some key methods for interacting with the Blink Storage layer. Using the Chrome Resources tab will allow you view the contents of your local storage.

MyAnswers.store.set ( key, value )

// simple usage - store and forgetMyAnswers.store.set('fruit', 'apples');
 
// store, and then do something once the save operation is completed.
MyAnswers.store.set('meat', 'kangaroo').done(function () { console.log('Done!'); });

MyAnswers.store.get ( key )

 1MyAnswers.store.get('fruit').done(function () { 
    console.log('Done!'); 
});

MyAnswers.pendingStore.set ( key, value ) 

MyAnswers.pendingStore.set = (function(){
		var _original = MyAnswers.pendingStore.set;
		return function(key, str) {
			var dfd = new $.Deferred();
			if (!MyAnswers.pendingStore._cache) {
				MyAnswers.pendingStore._cache = {};
			}
			
			MyAnswers.pendingStore._cache[key] = str;
			_original(key, str).done(function(){
				var event = jQuery.Event("pendingStoreAdd");
				event.key = key;
				event.val = str;
				$(document).trigger(event);
				dfd.resolve();
			})
			.fail(dfd.reject);
      return dfd.promise();
		}
  })();

MyAnswers.pendingStore.get ( key )

     MyAnswers.pendingStore.set = (function() {
      var _original = MyAnswers.pendingStore.set;
      return function(key, str) {
        var dfd = new $.Deferred();
        if (!MyAnswers.pendingStore._cache) {
          MyAnswers.pendingStore._cache = {};
        }
        MyAnswers.pendingStore._cache[key] = str;
        _original(key, str).done(function() {
          var event = jQuery.Event("pendingStoreAdd");
          event.key = key;
          event.val = str;
          $(document).trigger(event);
          dfd.resolve();
        })
          .fail(dfd.reject);
        return dfd.promise();
      };
    })();

MyAnswers.pendingStore.remove ( key )

       MyAnswers.pendingStore.remove = (function() {
      var _original = MyAnswers.pendingStore.remove;
      return function(key) {
        var dfd = new $.Deferred();
        if (!MyAnswers.pendingStore._cache) {
          MyAnswers.pendingStore._cache = {};
        }
        if (MyAnswers.pendingStore._cache[key]) {
          delete MyAnswers.pendingStore._cache[key];
        }
        _original(key).done(function() {
          dfd.resolve();
        })
          .fail(dfd.reject);
        return dfd.promise();
      };
    })();

BIC-JQM 

 BIC-JQM uses reliable persistent storage collections.

For more information see BIC-JQM persistent storage for more details.

BMP.BIC.hasStorage()

Example (Check for Storage)
require(['bic'], function (bic) { // 1.
  bic.collections().then(function () { // 2.
    if (bic.hasStorage()) { // 3.
      // TODO: do something with a persistent collection
      // e.g. `bic.interactions`, `bic.pending`, etc
    }
  });
});

BIC-JQM (BMP.BIC3.pending)

 See BIC-jQM: Pending Queue for more details

$.when(BMP.BIC.pending.initialize).then(function () {

  /* here your Interaction code can safely manipulate the pending queue */

});


 

BIC-JQM code to run to check BIC Ready

 

BIC Ready Code
require(['bic'], function (BIC) { 

  BIC.whenPopulated().then(function () { 

    console.log('ready and populated');

    // TODO: do stuff!

  });

});
 
// Or
 
require(['bic'], function (BIC) {

  $(document).one('pageshow', function () {

    console.log('pageshow');

  });

});