1.3.0 • Published 7 years ago

aemm-plugin-context v1.3.0

Weekly downloads
3
License
Apache 2.0
Repository
github
Last release
7 years ago

aemm-plugin-context

This plugin defines a global context object, which provides access to entity information within a given context. Although the object is in the global scope, it is not available until after the deviceready event.

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    console.log(cq.mobile.context.type);
}

Installation

cordova plugin add aemm-plugin-context

Context Properties

  • context.type
  • context.entity
  • context.collection
  • context.nextEntity
  • context.previousEntity

context.type

The context.type returns the type of the current context. The possible types are article, overlay, or card. :warning: card is not yet supported.

Supported Platforms

  • Android
  • iOS
  • Windows

Quick Example

var string = cq.mobile.context.type;

context.entity

The context.entity returns an Entity object that contains information about the entity in the current context.

Supported Platforms

  • Android
  • iOS
  • Windows

Quick Example

var currentEntity = cq.mobile.context.entity;

context.collection

The context.collection returns an Entity object representing the collection for the current context. This property can be null if the current context is an orphaned context.

Supported Platforms

  • Android
  • iOS
  • Windows

Quick Example

var currentCollection = cq.mobile.context.collection

context.nextEntity

The context.nextEntity returns an Entity object for the next available entity.

Supported Platforms

  • Android
  • iOS
  • Windows

Quick Example

var nextEntity = cq.mobile.context.nextEntity;

context.previousEntity

The context.previousEntity returns an Entity object for previous available entity.

Example

var prevEntity = cq.mobile.context.previousEntity;

Supported Platforms

  • Android
  • iOS
  • Windows

Context Methods

  • context.getEntity(entityName, entityType, forceUpdate, successCallback, errorCallback)
  • context.getEntitlementInfo(entityOrEntityList, successCallback, errorCallback)
  • context.getEntityStatus(entity, successCallback, errorCallback)
  • context.saveEntity(entity, isSilent, successCallback, errorCallback)
  • context.archiveEntity(entity, successCallback, errorCallback)
  • context.getSavedEntities(successCallback, errorCallback)

context.getEntity(entityName, entityType, forceUpdate, successCallback, errorCallback)

A method that returns an Entity object given the entityName and the entityType

ParameterTypeDescription
entityNameStringThe name of the entity. This must match the name found on Content Portal
entityTypeStringThe type of entity. Must match values found in Entity.type
forceUpdateBOOLIf 'true', always query the server for the latest version
successCallbackFunctionThe success callback
errorCallbackFunctionThe error callback

Supported Platforms

  • Android
  • iOS

context.getEntitlementInfo(entityOrEntityList, successCallback, errorCallback)

A method that returns entitlement information for an entity of type collection, or an EntityList object that contains collections. If a non collection Entity object is passed, then we will immediately return CQMContextError.WRONG_ENTITY_TYPE_ERROR. If an EntityList object is passed, only entitlementInfo for collection objects will be returned. If there are no collections, the returning array will be empty.

ParameterTypeDescription
entityOrEntityListEntity or EntityListThe entity to obtain entitlement information for. Or the entityList that contains a list of entities to obtain entitlement information for.
successCallbackFunctionThe success callback
errorCallbackFunctionThe error callback

Supported Platforms

  • Android
  • iOS

context.getEntityStatus(entity, successCallback, errorCallback)

A method that returns status for an Entity such as isSavable, downloadPercent, downloadState. (Currently only supports Collection)

ParameterTypeDescription
entityEntityEntity we want to get status for.
successCallbackFunctionThe success callback
errorCallbackFunctionThe error callback

Supported Platforms

  • Android
  • iOS

context.saveEntity(entity, isSilent, successCallback, errorCallback)

A method that saves an entity. (Currently only supports Collection)

ParameterTypeDescription
entityEntityEntity we want to save.
isSilentBOOLIf we want to save the entity in the background with no notification (Android only).
successCallbackFunctionThe success callback that will be called everytime there is a progress update. The callback is given an array that contains two values: 1. The latest known entity that was saved, 2. The download percentage
errorCallbackFunctionThe error callback

Supported Platforms

  • Android
  • iOS

context.archiveEntity(entity, successCallback, errorCallback)

A method that archives an entity. (Currently only supports Collection)

ParameterTypeDescription
entityEntityEntity we want to archive.
successCallbackFunctionThe success callback
errorCallbackFunctionThe error callback

Supported Platforms

  • Android
  • iOS

context.getSavedEntities(successCallback, errorCallback)

A method that returns all entities that can be archived. This includes entities that are completely saved, or partially saved. (Currently only supports Collection)

ParameterTypeDescription
successCallbackFunctionThe success callback
errorCallbackFunctionThe error callback

Supported Platforms

  • Android
  • iOS

Entity Properties

  • Entity.id
  • Entity.type
  • Entity.metadata

Entity Methods

  • getThumbnailImage(width, height, successCallback, errorCallback)
  • getBackgroundImage(width, height, successCallback, errorCallback)
  • getSocialSharingImage(width, height, successCallback, errorCallback)
  • getChildren(successCallback, errorCallback)

Entity.id

The Entity.id the ID of the entity.

Supported Platforms

  • Android
  • iOS
  • Windows

Quick Example

var string = cq.mobile.context.entity.id;

Entity.type

The Entity.type returns the type of the entity. Current supported types are: 'article', 'collection', and 'banner'

Supported Platforms

  • Android
  • iOS
  • Windows

Quick Example

var string = cq.mobile.context.entity.type;

Entity.rootPath

The Entity.rootPath can be used as a reference to build a path to a resource contained within an article.

Supported Platforms

  • Android
  • iOS

Windows Quirks

On Windows, article content is not accessible through filesystem traversal. You can access them as absolute urls like this (or through XHR):

<img src="/anyAsset.png" />

Quick Example

var string = cq.mobile.context.entity.rootPath;

Entity.metadata

The Entity.metadata returns a metadata object with properties describing the entity.

Supported Platforms

  • Android
  • iOS
  • Windows

Quick Example

var metadata = cq.mobile.context.entity.metadata;

Metadata Properties

NameTypeSupport for Entity
departmentStringArticle, Collection, Banner
importanceStringArticle, Collection, Banner
keywordsArray of StringsArticle, Collection, Banner
titleStringArticle, Collection, Banner
shortTitleStringArticle, Collection, Banner
shortAbstractStringArticle, Collection, Banner
availabilityDateStringArticle, Collection, Banner
socialShareUrlStringArticle, Collection, Banner
categoryStringArticle, Collection, Banner
abstractStringArticle, Collection, Banner
publishedStringArticle, Collection, Banner
modifiedStringArticle, Collection, Banner
createdStringArticle, Collection, Banner
versionStringArticle, Collection, Banner
entityNameStringArticle, Collection, Banner
urlStringArticle, Collection, Banner
authorStringArticle
authorUrlStringArticle
articleTextStringArticle
accessStateStringArticle
hideFromBrowsePageBooleanArticle
isAdBooleanArticle
adTypeStringArticle
adCategoryStringArticle
advertiserStringArticle
isIssueBooleanCollection
allowDownloadBooleanCollection
openToStringCollection
readingPositionStringCollection
lateralNavigationBooleanCollection
productIdsArray of StringsCollection
tapActionStringBanner

Supported Platforms

  • Android
  • iOS
  • Windows

Quick Example

var string = cq.mobile.context.entity.metadata.department;

getThumbnailImage(width, height, successCallback, errorCallback)

A method that returns file url to the thumbnail image as argument of the success callback. Supported on the Article and Collection entities.

ParameterTypeDescription
widthNumberThe requested width
heightNumberThe requested height
successCallbackFunctionThe success callback
errorCallbackFunctionThe error callback

Supported Platforms

  • Android
  • iOS
  • Windows

getBackgroundImage(width, height, successCallback, errorCallback)

A method that returns file url to the background image as argument of the success callback. Supported on the Collection entity.

ParameterTypeDescription
widthNumberThe requested width
heightNumberThe requested height
successCallbackFunctionThe success callback
errorCallbackFunctionThe error callback

Supported Platforms

  • Android
  • iOS
  • Windows

getSocialSharingImage(width, height, successCallback, errorCallback)

A method that returns file url to the social sharing image as argument of the success callback. Supported on the Collection Entity.

ParameterTypeDescription
widthNumberThe requested width
heightNumberThe requested height
successCallbackFunctionThe success callback
errorCallbackFunctionThe error callback

Supported Platforms

  • Android
  • iOS
  • Windows

getChildren(successCallback, errorCallback)

A method that returns an EntityList object that will contain all the non-restricted child entities for this collection that are in the cache. If none exist, we will attempt to download the first server page of children Supported on the Collection Entity.

ParameterTypeDescription
successCallbackFunctionThe success callback
errorCallbackFunctionThe error callback

Supported Platforms

  • Android
  • iOS

EntityList Properties

  • EntityList.entities
  • EntityList.hasNextPage

EntityList Methods

  • getNextPage(successCallback, errorCallback)

EntityList.entities

The EntityList.entities is an array that contains Entity objects.

Supported Platforms

  • Android
  • iOS

EntityList.hasNextPage

The EntityList.hasNextPage is a BOOL determines if there are sibling entities yet to be retrieved.

Supported Platforms

  • Android
  • iOS

getNextPage(successCallback, errorCallback)

A method that updates the EntityList object with additional Entity items. It also updates the hasNextPage property.

ParameterTypeDescription
successCallbackFunctionThe success callback
errorCallbackFunctionThe error callback
1.3.0

7 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago