top

CAPH.DAL.PRELOADER

Preloader is a class that loads resources ahead of time. For example, a user can load an image, a text or an audio clip  in the background, which can be hidden to a user interface. Main APIs of Preloader are 'load', 'loadWithPriorityManifest' and 'loadWithDependencyManifest.' Using load method, a user can load URLs in the argument. Using loadWithPriorityManifest method, a user can load resources that have certain priority attributes. USing loadWithDependencyManifest method, a user can load resources with dependency constraints.


Constructor

Preloader

Description
Construct a BaseLoader
Emulator SupportY
SDK ConstraintNone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

Methods

Preloader

Description
(Constructor) Construct a Preloader
Parameters
■Void
Return■Preloader 
  - An instance of a Preloader
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

onCacheItemFound

Description
on a cache item found
Parameters
■jobItem
  - Object
  - An object represents a job item
  - [default : null]
■item
  - String
  - A data URL string represents a data
  - [default : null]
Return■Void
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

// Let's say jobItem and item is given
preloader.onCacheItemFound(jobItem, item);

processItem

Description
process an item
Parameters
■jobItem
  - Object
  - An object represents a job item
  - [default : null]
Return■Void
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

// Let's say jobItem is given
preloader.processItem(jobItem);

buildResultItem

Description
Build a JavaScript object as a result
Parameters
■loader
  - Object
  - A loader
  - [default : null]
■flagSuccess
  - Boolean
  - flag to indicate success or not
  - [default : null]
Return■Object
  - An object represents a result
   * flagSuccess: success or not
   * url : URL
   * id : unique ID
   * typeID : type ID
   * blob : Blob
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

// Let's say loader is given.
var resultItem = preloader.buildResultItem(loader, true);

onItemComplete

Description
on an item completion
Parameters
■preloader (Optional)
  - Object
  - An object represents a Preloader
  - [default : null]
Return■Void
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

// Let's say preloading item is completed.
preloader.onItemComplete(preloader);

onItemError

Description
on an item error
Parameters
■preloader (Optional)
  - Object
  - An object represents a Preloader
  - [default : null]
Return■Void
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

// Let's say there's an error on an item.
preloader.onItemError(preloader);

subscribe

Description
subscribe to an event
Parameters
■typeString
  - String 
  - K397:K403
  - type string of an event
  - [default : null]
■callback: 
  - Function
  - A callback function to be called
  - [default : null]
Return■Void
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

function foo() {
    console.log('in function foo');
}

preloader.subscribe('oncomplete', foo);
preloader.publish('oncomplete', window, 'foofoo');

unsubscribe

Description
unsubscribe to an event
Parameters
■typeString
  - String 
  - type string of an event
  - [default : null]
■callback: 
  - Function
  - A callback function to be called
  - [default : null]
Return■Void
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

function foo() {
    console.log('in function foo');
}

preloader.subscribe('oncomplete', foo);
preloader.publish('oncomplete', window, 'foofoo');
preloader.unsubscribe('oncomplete', foo);

cleanup

Description
Clean up itself.
Parameters
■Void
Return■Void
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

preloader.cleanup();

init

Description
Initialize Preloader
Parameters
■Void
Return■Void
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

preloader.init();

loadWithPriorityManifest

Description
load with a manifest. The manifest MUST contain priority attributes
Parameters
■manifest
  - Object
  - { files: [ {url: 'http://...', typeID: TYPE_....}, {url: 'http://...', typeID: TYPE_ } ] }
Return■Void
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

preloader.init(); 
var manifest = { files: [ {url: 'http://foo.com/a.jpg', typeID: caph.core.dal.Constant.TYPE_JPEG, priority:1}, 
                              {url: 'http://bar.com/b.jpg', typeID: caph.core.dal.Constant.TYPE_JPEG, priority:3} ] };
preloader.loadWithPriorityManifest(manifest);

loadWithDependencyManifest

Description
load with a manifest and a dependency graph
Parameters
■manifest
  - Object 
  - manifest {Preloader.DependencyGraph}    graph : Dependency Graph
Return■Void
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

preloader.init(); 
var manifest = { files: [ {url: 'http://foo.com/a.jpg', typeID: caph.core.dal.Constant.TYPE_JPEG, priority:1}, 
                              {url: 'http://bar.com/b.jpg', typeID: caph.core.dal.Constant.TYPE_JPEG, priority:3} ] };
var graph = new Preloader.DependencyGraph();
graph.init(6);
graph.addEdge(0,4);
graph.addEdge(0,5);
preloader.loadWithDependencyManifest(manifest, graph);

load

Description
load files in the argument, manifest.files.Here, any priority is ignored. All item has the same priority
Parameters
■manifest
  - Object
    - { files: [ {url: 'http://...', typeID: TYPE_....}, {url: 'http://...', typeID: TYPE_ } ] }
Return■Boolean
  - false, if fails; undefined, otherwise;
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

preloader.init(); 
var manifest = { files: [ {url: 'http://foo.com/a.jpg', typeID: caph.core.dal.Constant.TYPE_JPEG}, {url:
                               'http://bar.com/b.jpg', typeID: caph.core.dal.Constant.TYPE_JPEG} ] };
preloader.load(manifest);

processNext

Description
process the next item
Parameters
■Void
Return■Void
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

preloader.processNext();

publish

Description
publish an event
Parameters
■typeString
  - String 
  - type string of an event
  - [default : null]
■callbackThis: 
  - Any
  - A callback parameter to be transferred as this
  - [default : null]
■callbackData: 
  - Any 
  - A callback parameter to be transferred as data
  - [default : null]
Return■Void
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

preloader.publish('oncomplete', preloader, 'foo');

setCrossDomainAllowed

Description
set the cross-domain-allowed flag value from the value of the parameter flag
Parameters
■flag
  - Boolean
  - to set flag of cross-domain-allowed
  - [default : null]
Return■Void
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

preloader.setCrossDomainAllowed(true);

setFlagSync

Description
Set the synced -or-not flag
Parameters
■flagSync
  - boolean
  - synced-or-not flag. flagSync's default value is "false". this mean loader processes multiple commands. (not sync)     
  - [default : 'false']
Return■Void
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

preloader.setFlagSync(true);

setFlagThrottled

Description
Set the throttled -or-not flag
Parameters
■flagThrottled
  - Boolean
  - Throttled-or-not flag. flagThrottled's default value is "false". this mean not throttled
  - [default : 'false']
Return■Void
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

preloader.setFlagThrottled(true);

setFlagUseCache

Description
set the flag to use cache or not
Parameters
■flag
  - Boolean
  - to set flag of using caching
  - [default : null]
Return■Void
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

preloader.setFlagUseCache(true);

setMaxIssuePerTurn

Description
Set the max issue per turn.
Parameters
■maxIssuePerTurn  
  - Number
  - Max issue per turn. It must be greater than zero.
Return■Void
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

preloader.setMaxIssuePerTurn(1);

start

Description
start to load
Parameters
■Void
Return■Void
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

preloader.start();

startProcessing

Description
start preloader processing
Parameters
■Void
Return■Void
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

preloader.startProcessing();

getFlagThrottled

Description
get the throttled- or-not flag
Parameters
■Void
Return■Boolean 
 - Flag of throttled-or-not setting
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

var flag = preloader.getFlagThrottled();

isCaching

Description
Return true, if caching
Parameters
■Void
Return■Boolean 
 - A flag to indicate caching or not
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

var flag = preloader.isCahing();     //return true or false

isCrossDomainAllowed

Description
Return true, if cross-domain allowed
Parameters
■Void
Return■Boolean 
 - A flag to indicate cross-domain allowed or not
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

var flag = preloader.isCrossDomainAllowed();     //return true or false

isValidStateToStartProcessing

Description
is it in a valid state to start processing?
Parameters
■Void
Return■Boolean 
 - A flag to indicate a valid state or not
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

var flag = preloader.isValidStateToStartProcessing();  //return true or false

getFlagSync

Description
Get the synced -or-not flag
Parameters
■Void
Return■Boolean 
 - Flag of synced-or-not setting
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

var flagSync = preloader.getFlagSync();

setCache

Description
set the cache object. set the cache (a cache that inherits BaseCache).
Parameters
■cache
  - Object 
  - A cache that inherits BaseCache
  - [default : null]
Return■Void
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

var LocalStorageCache = caph.dal.LocalStorageCache();
var localstoragecache = new LocalStorageCache();

preloader.setCache(localstoragecache);

getMaxIssuePerTurn

Description
Get the max issue per turn
Parameters
■Void
Return■Number
  - Number of loaders
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

var maxValue = preloader.getMaxIssuePerTurn();

isStarted

Description
isStarted is check that preloader is started
Parameters
■Void
Return■Boolean
  - True : if preloader is started
  - false, otherwise.
Emulator SupportY
SDK Constraintnone
Example
var Preloader = caph.dal.Preloader;
var preloader = new Preloader();

var result = preloader.isStarted();                  //return true or false