Skip to content

Commit

Permalink
feat: CLIPPY_CDN
Browse files Browse the repository at this point in the history
  • Loading branch information
Pooya Parsa committed Jun 10, 2017
1 parent 97d9892 commit ff74722
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,14 @@ agent.stop();

## Custom CDN / Agents
By default all agents are being served from GitHub CDN (this repo) in order to customize loading base path,
Use 4rd argument of `load` function it can be absolute URL or relative to script. (**path should end with slash /**)
You can set `window.CLIPPY_CDN` or use 4rd argument of `load` function it can be absolute URL or relative to script.
(**path should end with slash /**)

```js
// Using global config
window.CLIPPY_CDN = './agents/'

// Or using 4rth argument
clippy.load('Marline', function() {
// ...
}, undefined, './agents/')
Expand Down
14 changes: 8 additions & 6 deletions lib/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import $ from 'jquery'
import Agent from './agent'

export class load {
constructor(name, successCb, failCb, base_path = './agents/') {
constructor (name, successCb, failCb, base_path) {
base_path = base_path || window.CLIPPY_CDN || 'https://gitcdn.xyz/repo/pi0/clippyjs/master/assets/agents/'

let path = base_path + name;
let mapDfd = load._loadMap(path);
let agentDfd = load._loadAgent(name, path);
Expand All @@ -28,7 +30,7 @@ export class load {
$.when(mapDfd, agentDfd, soundsDfd).done(cb).fail(failCb);
}

static _loadMap(path) {
static _loadMap (path) {
let dfd = load._maps[path];
if (dfd) return dfd;

Expand All @@ -47,7 +49,7 @@ export class load {
return dfd.promise();
}

static _loadSounds(name, path) {
static _loadSounds (name, path) {
let dfd = load._sounds[name];
if (dfd) return dfd;

Expand All @@ -69,7 +71,7 @@ export class load {
return dfd.promise()
}

static _loadAgent(name, path) {
static _loadAgent (name, path) {
let dfd = load._data[name];
if (dfd) return dfd;

Expand All @@ -82,7 +84,7 @@ export class load {
return dfd.promise();
}

static _loadScript(src) {
static _loadScript (src) {
let script = document.createElement('script');
script.setAttribute('src', src);
script.setAttribute('async', 'async');
Expand All @@ -91,7 +93,7 @@ export class load {
document.head.appendChild(script);
}

static _getAgentDfd(name) {
static _getAgentDfd (name) {
let dfd = load._data[name];
if (!dfd) {
dfd = load._data[name] = $.Deferred();
Expand Down

0 comments on commit ff74722

Please sign in to comment.