Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diff #52

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open

Diff #52

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
1 change: 0 additions & 1 deletion agents/Bonzi/sounds-mp3.js

This file was deleted.

1 change: 0 additions & 1 deletion agents/Bonzi/sounds-ogg.js

This file was deleted.

1 change: 0 additions & 1 deletion agents/Clippy/sounds-mp3.js

This file was deleted.

1 change: 0 additions & 1 deletion agents/Clippy/sounds-ogg.js

This file was deleted.

1 change: 0 additions & 1 deletion agents/F1/sounds-mp3.js

This file was deleted.

1 change: 0 additions & 1 deletion agents/F1/sounds-ogg.js

This file was deleted.

1 change: 0 additions & 1 deletion agents/Genie/sounds-mp3.js

This file was deleted.

1 change: 0 additions & 1 deletion agents/Genie/sounds-ogg.js

This file was deleted.

1 change: 0 additions & 1 deletion agents/Genius/sounds-mp3.js

This file was deleted.

1 change: 0 additions & 1 deletion agents/Genius/sounds-ogg.js

This file was deleted.

1 change: 0 additions & 1 deletion agents/Links/sounds-mp3.js

This file was deleted.

1 change: 0 additions & 1 deletion agents/Links/sounds-ogg.js

This file was deleted.

1 change: 0 additions & 1 deletion agents/Merlin/sounds-mp3.js

This file was deleted.

1 change: 0 additions & 1 deletion agents/Merlin/sounds-ogg.js

This file was deleted.

1 change: 0 additions & 1 deletion agents/Peedy/sounds-mp3.js

This file was deleted.

1 change: 0 additions & 1 deletion agents/Peedy/sounds-ogg.js

This file was deleted.

1 change: 0 additions & 1 deletion agents/Rocky/sounds-mp3.js

This file was deleted.

1 change: 0 additions & 1 deletion agents/Rocky/sounds-ogg.js

This file was deleted.

1 change: 0 additions & 1 deletion agents/Rover/sounds-mp3.js

This file was deleted.

1 change: 0 additions & 1 deletion agents/Rover/sounds-ogg.js

This file was deleted.

117 changes: 66 additions & 51 deletions build/clippy.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
/*
* Fork of ClippyJS needed to work with Drupal.org.
*
* @see https://github.com/mherchel/clippy.js/tree/drupal
*/

(function ($) {

// Code to help debug Clippy (if necessary)
var urlSearchParams = (new URL(document.location)).searchParams;
if (urlSearchParams.get('debug') != null) {
console.log('Clippy\'s jQuery version: ' + window.jQueryNew.fn.jquery);;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?? very hacky

}

var clippy = {};

/******
*
*
* @constructor
*/
clippy.Agent = function (path, data, sounds) {
clippy.Agent = function (path, data) {
this.path = path;

this._queue = new clippy.Queue($.proxy(this._onQueueEmpty, this));
Expand All @@ -14,7 +28,7 @@ clippy.Agent = function (path, data, sounds) {

$(document.body).append(this._el);

this._animator = new clippy.Animator(this._el, path, data, sounds);
this._animator = new clippy.Animator(this._el, path, data);

this._balloon = new clippy.Balloon(this._el);

Expand Down Expand Up @@ -463,7 +477,7 @@ clippy.Agent.prototype = {
*
* @constructor
*/
clippy.Animator = function (el, path, data, sounds) {
clippy.Animator = function (el, path, data) {
this._el = el;
this._data = data;
this._path = path;
Expand All @@ -473,9 +487,9 @@ clippy.Animator = function (el, path, data, sounds) {
this._currentAnimation = undefined;
this._endCallback = undefined;
this._started = false;
this._sounds = {};
// this._sounds = {};
this.currentAnimationName = undefined;
this.preloadSounds(sounds);
// this.preloadSounds(sounds);
this._overlays = [this._el];
var curr = this._el;

Expand Down Expand Up @@ -510,13 +524,13 @@ clippy.Animator.prototype = {

preloadSounds:function (sounds) {

for (var i = 0; i < this._data.sounds.length; i++) {
var snd = this._data.sounds[i];
var uri = sounds[snd];
if (!uri) continue;
this._sounds[snd] = new Audio(uri);
// for (var i = 0; i < this._data.sounds.length; i++) {
// var snd = this._data.sounds[i];
// var uri = sounds[snd];
// if (!uri) continue;
// this._sounds[snd] = new Audio(uri);

}
// }
},
hasAnimation:function (name) {
return !!this._data.animations[name];
Expand Down Expand Up @@ -595,10 +609,10 @@ clippy.Animator.prototype = {
},

_playSound:function () {
var s = this._currentFrame.sound;
if (!s) return;
var audio = this._sounds[s];
if (audio) audio.play();
// var s = this._currentFrame.sound;
// if (!s) return;
// var audio = this._sounds[s];
// if (audio) audio.play();
},

_atLastFrame:function () {
Expand All @@ -617,7 +631,7 @@ clippy.Animator.prototype = {
}

this._draw();
this._playSound();
// this._playSound();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't comment out code. Remove it if not needed.


this._loop = window.setTimeout($.proxy(this._step, this), this._currentFrame.duration);

Expand Down Expand Up @@ -664,8 +678,8 @@ clippy.Balloon = function (targetEl) {

clippy.Balloon.prototype = {

WORD_SPEAK_TIME:320,
CLOSE_BALLOON_DELAY:2000,
WORD_SPEAK_TIME:300,
CLOSE_BALLOON_DELAY:15000,

_setup:function () {

Expand Down Expand Up @@ -810,7 +824,7 @@ clippy.Balloon.prototype = {
this.hide();
}
} else {
el.text(words.slice(0, idx).join(' '));
el.html(words.slice(0, idx).join(' '));
idx++;
this._loop = window.setTimeout($.proxy(this._addWord, this), time);
}
Expand Down Expand Up @@ -844,33 +858,33 @@ clippy.Balloon.prototype = {

};

clippy.BASE_PATH = '//s3.amazonaws.com/clippy.js/Agents/';
clippy.BASE_PATH = '/sites/all/libraries/clippy.js/agents/';

clippy.load = function (name, successCb, failCb) {
var path = clippy.BASE_PATH + name;

var mapDfd = clippy.load._loadMap(path);
var agentDfd = clippy.load._loadAgent(name, path);
var soundsDfd = clippy.load._loadSounds(name, path);
// var soundsDfd = clippy.load._loadSounds(name, path);

var data;
agentDfd.done(function (d) {
data = d;
});

var sounds;
// var sounds;

soundsDfd.done(function (d) {
sounds = d;
});
// soundsDfd.done(function (d) {
// sounds = d;
// });

// wrapper to the success callback
var cb = function () {
var a = new clippy.Agent(path, data,sounds);
var a = new clippy.Agent(path, data, null);
successCb(a);
};

$.when(mapDfd, agentDfd, soundsDfd).done(cb).fail(failCb);
$.when(mapDfd, agentDfd).done(cb).fail(failCb);
};

clippy.load._maps = {};
Expand All @@ -893,28 +907,28 @@ clippy.load._loadMap = function (path) {
return dfd.promise();
};

clippy.load._sounds = {};
// clippy.load._sounds = {};

clippy.load._loadSounds = function (name, path) {
var dfd = clippy.load._sounds[name];
if (dfd) return dfd;
// var dfd = clippy.load._sounds[name];
// if (dfd) return dfd;

// set dfd if not defined
dfd = clippy.load._sounds[name] = $.Deferred();

var audio = document.createElement('audio');
var canPlayMp3 = !!audio.canPlayType && "" != audio.canPlayType('audio/mpeg');
var canPlayOgg = !!audio.canPlayType && "" != audio.canPlayType('audio/ogg; codecs="vorbis"');

if (!canPlayMp3 && !canPlayOgg) {
dfd.resolve({});
} else {
var src = path + (canPlayMp3 ? '/sounds-mp3.js' : '/sounds-ogg.js');
// load
clippy.load._loadScript(src);
}
// // set dfd if not defined
// dfd = clippy.load._sounds[name] = $.Deferred();

// var audio = document.createElement('audio');
// var canPlayMp3 = !!audio.canPlayType && "" != audio.canPlayType('audio/mpeg');
// var canPlayOgg = !!audio.canPlayType && "" != audio.canPlayType('audio/ogg; codecs="vorbis"');

// if (!canPlayMp3 && !canPlayOgg) {
// dfd.resolve({});
// } else {
// var src = path + (canPlayMp3 ? '/sounds-mp3.js' : '/sounds-ogg.js');
// // load
// clippy.load._loadScript(src);
// }

return dfd.promise()
// return dfd.promise()
};


Expand Down Expand Up @@ -955,12 +969,11 @@ clippy.ready = function (name, data) {
};

clippy.soundsReady = function (name, data) {
var dfd = clippy.load._sounds[name];
if (!dfd) {
dfd = clippy.load._sounds[name] = $.Deferred();
}

dfd.resolve(data);
// var dfd = clippy.load._sounds[name];
// if (!dfd) {
// dfd = clippy.load._sounds[name] = $.Deferred();
// }
// dfd.resolve(data);
};

/******
Expand Down Expand Up @@ -1013,3 +1026,5 @@ clippy.Queue.prototype = {
}
};

window.clippy = clippy;
})(window.jQueryNew)
1 change: 0 additions & 1 deletion build/clippy.min.js

This file was deleted.

Loading