# HG changeset patch
# User veltr
# Date 1333477812 -7200
# Node ID 8da49ff273e06c29f99d55d2543c140079d31b79
# Parent ac66e2240e1edea53ba92e658b94c3ed34e5b766
Modifs cinecast
diff -r ac66e2240e1e -r 8da49ff273e0 src/js/libs/tracemanager.js
--- a/src/js/libs/tracemanager.js Fri Mar 30 18:00:26 2012 +0200
+++ b/src/js/libs/tracemanager.js Tue Apr 03 20:30:12 2012 +0200
@@ -2,9 +2,13 @@
* Modelled Trace API
*/
IriSP.TraceManager = function($) {
- /*
- * FIXME: Write proper representation functions (str, json, ...)
- */
+ // If there are more than MAX_FAILURE_COUNT synchronisation
+ // failures, then disable synchronisation
+ MAX_FAILURE_COUNT = 20;
+
+ // If there are more than MAX_BUFFER_SIZE obsels in the buffer,
+ // then "compress" them as a single "ktbsFullBuffer"
+ MAX_BUFFER_SIZE = 500;
var BufferedService_prototype = {
/*
@@ -14,15 +18,18 @@
// buffer: [],
// isReady: false,
// timer: null,
+ // failureCount: 0,
/* Flush buffer */
flush: function() {
- // FIXME: should add a counter to avoid starving the sync
- // process in case of too many generated obsels.
// FIXME: add mutex on this.buffer
if (! this.isReady)
{
- console.log("Sync service not ready");
+ if (window.console) window.console.log("Sync service not ready");
+ } else if (this.failureCount > MAX_FAILURE_COUNT)
+ {
+ // Disable synchronisation
+ this.set_sync_mode('none');
} else if (this.buffer.length) {
var temp = this.buffer;
this.buffer = [];
@@ -34,11 +41,13 @@
// prefixing it with c
var data = 'c' + JSON.stringify(temp.map(function (o) { return o.toCompactJSON(); }));
// Swap " (very frequent, which will be
- // serialized into %22) and / (rather rare), this
+ // serialized into %22) and ; (rather rare), this
// saves some bytes
- data = data.replace(/[\/"]/g, function(s){ return s == '/' ? '"' : '/'; }).replace('#','%23');
+ data = data.replace(/[;"]/g, function(s){ return s == ';' ? '"' : ';'; }).replace(/#/g, '%23');
// FIXME: check data length (< 2K is safe)
- var request=$('').attr('src', this.url + 'trace/?data=' + data);
+ var request=$('
').error( function() { this.failureCount += 1; })
+ .load( function() { this.failureCount = 0; })
+ .attr('src', this.url + 'trace/?data=' + data);
}
else
{
@@ -50,28 +59,52 @@
// Type of the returned data.
dataType: "html",
error: function(jqXHR, textStatus, errorThrown) {
- // FIXME: not called for JSONP/crossdomain
- console.log("Error when sending buffer:", textStatus);
+ if (window.console) window.console.log("Error when sending buffer:", textStatus);
+ this.failureCount += 1;
},
success: function(data, textStatus, jqXHR) {
- // FIXME: parse the returned JSON, and get
- // the updated properties (id, uri...) to apply them to temp items
+ // Reset failureCount to 0 as soon as there is 1 valid answer
+ this.failureCount = 0;
}
});
}
}
},
+ /* Sync mode: delayed, sync (immediate sync), none (no
+ * synchronisation with server, the trace has to be explicitly saved
+ * if needed */
+ set_sync_mode: function(mode) {
+ this.sync_mode = mode;
+ if (! this.isReady && mode !== "none")
+ this.init();
+ if (mode == 'delayed') {
+ this.start_timer();
+ } else {
+ this.stop_timer();
+ }
+ },
+
/* Enqueue an obsel */
enqueue: function(obsel) {
+ if (this.buffer.length > MAX_BUFFER_SIZE)
+ {
+ obsel = new Obsel('ktbsFullBuffer', this.buffer[0].begin,
+ this.buffer[this.buffer.length - 1].end, this.buffer[0].subject);
+ obsel.trace = this.buffer[0].trace;
+ this.buffer = [];
+ }
this.buffer.push(obsel);
+ if (this.sync_mode === 'sync') {
+ // Immediate sync of the obsel.
+ this.flush();
+ }
},
start_timer: function() {
var self = this;
if (this.timer === null) {
this.timer = window.setInterval(function() {
- console.log("Flushing timeout");
self.flush();
}, this.timeOut);
}
@@ -120,6 +153,9 @@
this.buffer = [];
this.isReady = false;
this.timer = null;
+ this.failureCount = 0;
+ // sync_mode is either "none", "sync" or "buffered"
+ this.sync_mode = "none";
/* mode can be either POST or GET */
if (mode == 'POST' || mode == 'GET')
this.mode = mode;
@@ -137,7 +173,6 @@
obsels: [],
/* Trace URI */
uri: "",
- sync_mode: "none",
default_subject: "",
/* baseuri is used as the base URI to resolve relative
* attribute-type names in obsels. Strictly speaking, this
@@ -159,16 +194,8 @@
* synchronisation with server, the trace has to be explicitly saved
* if needed */
set_sync_mode: function(mode) {
- this.sync_mode = mode;
- if (this.syncservice != null) {
- if (mode !== 'none') {
- this.syncservice.init();
- }
- if (mode == 'delayed') {
- this.syncservice.start_timer();
- } else {
- this.syncservice.stop_timer();
- }
+ if (this.syncservice !== null) {
+ this.syncservice.set_sync_mode(mode);
}
},
@@ -237,38 +264,10 @@
}
o.trace = this;
this.obsels.push(o);
- if (this.syncservice !== null && this.sync_mode != 'none') {
+ if (this.syncservice !== null)
this.syncservice.enqueue(o);
- if (this.sync_mode === 'sync') {
- // Immediate sync of the obsel.
- this.syncservice.flush();
- }
- }
},
- obselProbe : function(element, bindingEvent, ObselFunction) {
- console.log("!!!!!!!!- ICI -!!!!!!!!!");
- console.log(element);
- console.log(bindingEvent);
- console.log(ObselFunction);
-
- //var myOPI = self.setInterval("ObselProbeInterval("+element+","+bindingEvent+","+ObselFunction+")",1000);
- var myOPI = self.setInterval("ObselProbeInterval("+element+")",1000);
- //var ObselProbeInterval = function(element, bindingEvent, ObselFunction){
- var ObselProbeInterval = function(element) {
- console.log("!!!!!!!!- ObselProbeInterval -!!!!!!!!!");
- console.log($(element).length);
- /*
- if($(element).length!=0){
- $(element).bind(bindingEvent, ObselFunction );
- this.clearInterval();
- }else{ console.log("!!!!!!!!- EXISTE PAS -!!!!!!!!!")
- }
- */
- //
- };
-
- },
/* Helper methods */
/* Create a new obsel with the given attributes */
@@ -320,7 +319,6 @@
* purposes. They MUST be defined in the constructor
* function. */
trace: undefined,
- obselProbe: undefined,
type: undefined,
begin: undefined,
end: undefined,
@@ -334,7 +332,6 @@
},
get_obsel_type: function() {
- /* FIXME: maybe we should return a ObselType object. In the meantime, return the URI */
return this.type;
},
get_begin: function() {
@@ -350,7 +347,8 @@
list_attribute_types: function() {
var result = [];
for (var prop in this.attributes) {
- result.push(prop);
+ if (this.hasOwnProperty(prop))
+ result.push(prop);
}
/* FIXME: we return URIs here instead of AttributeType elements */
return result;
@@ -422,7 +420,8 @@
"subject": this.subject
};
for (var prop in this.attributes) {
- r[prop] = this.attributes[prop];
+ if (this.hasOwnProperty(prop))
+ r[prop] = this.attributes[prop];
}
return r;
},
@@ -434,15 +433,20 @@
toCompactJSON: function() {
var r = {
"@i": this.id,
- "@t": (this.trace.shorthands.hasOwnProperty(this.type)
- ? this.trace.shorthands[this.type] : this.type),
+ "@t": (this.trace.shorthands.hasOwnProperty(this.type) ? this.trace.shorthands[this.type] : this.type),
"@b": this.begin,
- "@e": this.end,
"@s": this.subject
};
+ // Store duration (to save some bytes) and only if it is non-null
+ if (this.begin !== this.end)
+ r["@d"] = this.end - this.begin;
+
for (var prop in this.attributes) {
- var v = this.attributes[prop];
- r[prop] = this.trace.shorthands.hasOwnProperty(v) ? this.trace.shorthands[v] : v;
+ if (this.hasOwnProperty(prop))
+ {
+ var v = this.attributes[prop];
+ r[prop] = this.trace.shorthands.hasOwnProperty(v) ? this.trace.shorthands[v] : v;
+ }
}
return r;
},
@@ -485,12 +489,14 @@
*/
init_trace: function(name, params)
{
- console.log("init_trace", params);
+ if (window.console) window.console.log("init_trace", params);
url = params.url ? params.url : "";
requestmode = params.requestmode ? params.requestmode : "POST";
syncmode = params.syncmode ? params.syncmode : "none";
+ default_subject = params.default_subject ? params.default_subject : "default";
var t = new Trace(url, requestmode);
t.set_sync_mode(syncmode);
+ t.set_default_subject(default_subject);
this.traces[name] = t;
return t;
}
@@ -501,5 +507,6 @@
};
TraceManager.prototype = TraceManager_prototype;
- return new TraceManager();
+ var tracemanager = new TraceManager();
+ return tracemanager;
};
diff -r ac66e2240e1e -r 8da49ff273e0 src/js/players/player.allocine.js
--- a/src/js/players/player.allocine.js Fri Mar 30 18:00:26 2012 +0200
+++ b/src/js/players/player.allocine.js Tue Apr 03 20:30:12 2012 +0200
@@ -13,49 +13,22 @@
this.playerFns = {
play : function() {
- if (_this.player) {
- // console.log("ask play _this.player = " + _this.player);
- return _this.player.sendToActionScript("play");
- } else {
- return false;
- }
+ return _this.apiCall("play");
},
pause : function() {
- if (_this.player) {
- // console.log("ask pause _this.player = " + _this.player);
- return _this.player.sendToActionScript("pause");
- } else {
- return false;
- }
+ return _this.apiCall("pause");
},
getPosition : function() {
- if (_this.player) {
- return _this.player.sendToActionScript("getSeek","return");
- } else {
- return 0;
- }
+ return _this.apiCall("getSeek","return") || 0;
},
seek : function(pos) {
- if (_this.player) {
- return _this.player.sendToActionScript("seek",pos);
- } else {
- return false;
- }
+ return _this.apiCall("seek",pos);
},
getMute : function() {
- if (_this.player) {
- return _this.player.sendToActionScript("getMute","return");
- } else {
- return false;
- }
+ return _this.apiCall("getMute","return");
},
setMute : function(p) {
- if (_this.player) {
- //return p ? _this.player.sendToActionScript("setMute") : _this.player.sendToActionScript("setMute");
- _this.player.sendToActionScript("setMute");
- } else {
- return false;
- }
+ return _this.apiCall("setMute", p);
}
}
@@ -75,12 +48,13 @@
var params = {
"allowScriptAccess" : "always",
"wmode": "opaque",
- "flashvars" : fv
+ "flashvars" : fv,
+ "allowfullscreen" : true
};
var atts = {
id : this.container
};
- swfobject.embedSWF(options.acPlayerUrl, this.container, options.width, options.height, "8", null, null, params, atts);
+ swfobject.embedSWF(options.acPlayerUrl, this.container, options.width, options.height, "10", null, null, params, atts);
};
@@ -89,7 +63,6 @@
IriSP.PopcornReplacement.allocine.prototype.ready = function() {
this.player = document.getElementById(this.container);
this.player.addEventListener("onStateChange", "onAllocineStateChange");
- this.player.addEventListener("onVideoProgress", "onAllocineVideoProgress");
this.player.cueVideoByUrl(this._options.video);
this.callbacks.onReady();
};
@@ -101,6 +74,23 @@
}
+IriSP.PopcornReplacement.allocine.prototype.apiCall = function(_method, _arg) {
+ if (this.player) {
+ try {
+ if (typeof _arg == "undefined") {
+ return this.player.sendToActionScript(_method);
+ } else {
+ return this.player.sendToActionScript(_method, _arg);
+ }
+ } catch(e) {
+ console.error('Exception while requesting AcPlayer for "' + _method + (typeof _arg == "undefined" ? '' : '" with argument "' + _arg ) + '"\n', e);
+ return false;
+ }
+ } else {
+ return false;
+ }
+}
+
IriSP.PopcornReplacement.allocine.prototype.stateHandler = function(state) {
console.log("stateHandler");
switch(state) {
diff -r ac66e2240e1e -r 8da49ff273e0 src/js/pop.js
--- a/src/js/pop.js Fri Mar 30 18:00:26 2012 +0200
+++ b/src/js/pop.js Tue Apr 03 20:30:12 2012 +0200
@@ -116,11 +116,11 @@
};
IriSP.PopcornReplacement.player.prototype.pause = function() {
- if ( !this.media.paused ) {
+// if ( !this.media.paused ) {
this.media.paused = true;
this.trigger( "pause" );
this.playerFns.pause();
- }
+// }
};
IriSP.PopcornReplacement.player.prototype.muted = function(val) {
diff -r ac66e2240e1e -r 8da49ff273e0 src/js/site.js.templ
--- a/src/js/site.js.templ Fri Mar 30 18:00:26 2012 +0200
+++ b/src/js/site.js.templ Tue Apr 03 20:30:12 2012 +0200
@@ -114,7 +114,7 @@
implementers.
Note that the player has to replace the variables between {{ and }} by its own values.
*/
- ajax_url: platform_url + "/ldtplatform/api/ldt/segments/{media}/{begin}/{end}",
+ ajax_url: platform_url + "/ldtplatform/api/ldt/segments/{{media}}/{{begin}}/{{end}}",
ajax_granularity: 10000, /* how much ms should we look before and after the
current timecode */
diff -r ac66e2240e1e -r 8da49ff273e0 src/js/widgets/annotationsListWidget.js
--- a/src/js/widgets/annotationsListWidget.js Fri Mar 30 18:00:26 2012 +0200
+++ b/src/js/widgets/annotationsListWidget.js Tue Apr 03 20:30:12 2012 +0200
@@ -7,6 +7,7 @@
this.checkOption('project_url');
this.checkOption('default_thumbnail');
this.checkOption("cinecast_version", false);
+ this.checkOption("ajax_url");
this.searchRe = null;
this._ajax_cache = [];
var _this = this;
@@ -73,7 +74,7 @@
};
IriSP.AnnotationsListWidget.prototype.transformAnnotation = function(a) {
- var _this = this
+ var _this = this;
return {
"id" : a.id,
"title": this.cinecast_version ? IriSP.get_aliased(a.meta, ['creator_name', 'creator']) : a.content.title,
@@ -82,6 +83,7 @@
"end" : IriSP.msToTime(a.end),
"thumbnail" : (typeof a.meta == "object" && typeof a.meta.thumbnail == "string") ? a.meta.thumbnail : this.default_thumbnail,
"url" : (typeof a.meta == "object" && typeof a.meta.url == "string") ? a.meta.url : null,
+ "created_at" :(typeof a.meta == "object" && typeof a.meta.created == "string") ? Date.parse(a.meta.created.replace(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}\:\d{2}\:\d{2}).*$/,"$2/$3/$1 $4 UTC+0000")) : null,
"tags": typeof a.tags == "object"
? IriSP.underscore(a.tags)
.chain()
@@ -140,7 +142,6 @@
this._Popcorn.trigger("IriSP.search.noMatchFound");
}
}
-
list = IriSP.underscore(list)
.chain()
.sortBy(function(_o) {
@@ -148,10 +149,9 @@
})
.first(10)
.sortBy(function(_o) {
- return _o.iterator;
+ return (_this.cinecast_version ? - _o.created_at : _o.iterator);
})
.value();
-
var idList = IriSP.underscore.pluck(list, "id").sort();
@@ -176,13 +176,11 @@
}
- /* the platform gives us a special url - of the type : http://path/{media}/{begin}/{end}
+ /* the platform gives us a special url - of the type : http://path/{{media}}/{{begin}}/{{end}}
we double the braces using regexps and we feed it to mustache to build the correct url
we have to do that because the platform only knows at run time what view it's displaying.
*/
- var platf_url = IriSP.widgetsDefaults.AnnotationsListWidget.ajax_url
- .replace(/\{/g, '{{').replace(/\}/g, '}}');
var media_id = this._serializer.currentMedia()["id"];
var duration = this._serializer.getDuration();
@@ -194,7 +192,7 @@
if (end_timecode > duration)
end_timecode = duration;
- var templ = Mustache.to_html(platf_url, {media: media_id, begin: begin_timecode,
+ var templ = Mustache.to_html(this.ajax_url, {media: media_id, begin: begin_timecode,
end: end_timecode});
/* we create on the fly a serializer to get the ajax */
diff -r ac66e2240e1e -r 8da49ff273e0 src/js/widgets/createAnnotationWidget.js
--- a/src/js/widgets/createAnnotationWidget.js Fri Mar 30 18:00:26 2012 +0200
+++ b/src/js/widgets/createAnnotationWidget.js Tue Apr 03 20:30:12 2012 +0200
@@ -13,7 +13,8 @@
"empty_annotation": "Your annotation is empty. Please write something before submitting.",
"annotation_saved": "Thank you, your annotation has been saved.",
"share_annotation": "Would you like to share it on social networks ?",
- "share_on": "Share on"
+ "share_on": "Share on",
+ "moar_tags": "More tags"
},
"fr": {
"submit": "Envoyer",
@@ -26,7 +27,8 @@
"empty_annotation": "Votre annotation est vide. Merci de rédiger un texte avant de l'envoyer.",
"annotation_saved": "Merci, votre annotation a été enregistrée.",
"share_annotation": "Souhaitez-vous la partager sur les réseaux sociaux ?",
- "share_on": "Partager sur"
+ "share_on": "Partager sur",
+ "moar_tagz": "Plus de mots-clés"
}
}
);
@@ -42,6 +44,8 @@
this.checkOption("api_endpoint_template");
this.checkOption("show_from_field", true);
this.checkOption("api_method");
+ this.checkOption("random_keywords");
+ this.checkOption("disable_share", false);
if (!IriSP.null_or_undefined(IriSP.user)) {
if (!IriSP.null_or_undefined(IriSP.user.avatar)) {
@@ -69,6 +73,20 @@
};
IriSP.createAnnotationWidget.prototype.draw = function() {
+ var _this = this;
+ if (typeof this._config.remote_keywords != "undefined" && typeof this._config.remote_keywords) {
+ IriSP.jQuery.getJSON(this._config.remote_keywords, function(_json) {
+ _this.keywords = IriSP.underscore(_json.tags).map(function(_tag) {
+ return _tag.meta.description;
+ });
+ _this.drawCallback();
+ });
+ } else {
+ this.drawCallback();
+ }
+}
+
+IriSP.createAnnotationWidget.prototype.drawCallback = function() {
var _this = this;
var annotationMarkup = IriSP.templToHTML(IriSP.createAnnotationWidget_template,
@@ -81,17 +99,25 @@
else {
this.showStartScreen();
}
-
+
+ if (this.random_keywords) {
+ this.selector.find(".Ldt-createAnnotation-keywords li").hide();
+ this.showMoarTagz();
+ this.selector.find('.Ldt-createAnnotation-moar-keywordz').click(function() {
+ _this.showMoarTagz();
+ })
+ }
// Add onclick event to both polemic and keywords buttons
- this.selector.find(".Ldt-createAnnotation-btnblock button").click(function() {
+ this.selector.find(".Ldt-createAnnotation-keyword-button, .Ldt-createAnnotation-polemic-button").click(function() {
_this.addKeyword(IriSP.jQuery(this).text());
+ return false;
});
// js_mod is a custom event because there's no simple way to test for a js
// change in a textfield.
this.selector.find(".Ldt-createAnnotation-Description")
- .bind("propertychange keyup input paste js_mod", IriSP.wrap(this, this.handleTextChanges));
+ .bind("propertychange keyup input paste click js_mod", IriSP.wrap(this, this.handleTextChanges));
/* the cinecast version of the player is supposed to pause when the user clicks on the button */
@@ -152,6 +178,21 @@
}
};
+IriSP.createAnnotationWidget.prototype.showMoarTagz = function() {
+ for (var j=0; j < this.random_keywords; j++) {
+ var _jq = this.selector.find(".Ldt-createAnnotation-keywords li:hidden");
+ if (_jq.length > 1) {
+ IriSP.jQuery(_jq[Math.floor(_jq.length*Math.random())]).show();
+ } else {
+ _jq.show();
+ break;
+ }
+ }
+ if (this.selector.find(".Ldt-createAnnotation-keywords li:hidden").length == 0) {
+ this.selector.find('.Ldt-createAnnotation-moar-keywordz').hide();
+ }
+}
+
/* Handles adding keywords and polemics */
IriSP.createAnnotationWidget.prototype.addKeyword = function(_keyword) {
var _field = this.selector.find(".Ldt-createAnnotation-Description"),
@@ -161,7 +202,7 @@
? _contents.replace(_rx,"").replace(" "," ").trim()
: _contents.trim() + " " + _keyword
);
- _field.val(_contents);
+ _field.val(_contents.trim());
_field.trigger("js_mod");
}
@@ -223,7 +264,7 @@
/** watch for changes in the textfield and change the buttons accordingly */
IriSP.createAnnotationWidget.prototype.handleTextChanges = function(event) {
var contents = this.selector.find(".Ldt-createAnnotation-Description").val();
- if (this.cinecast_version && !this._Popcorn.media.paused) {
+ if (this.cinecast_version) {
this._Popcorn.pause();
}
this.selector.find(".Ldt-createAnnotation-btnblock button").each(function() {
@@ -398,7 +439,17 @@
meta.created = Date().toString();
// All #hashtags are added to tags
- annotation.tags = contents.match(/#[^#\s]+\b/gim) || [];
+ var _tags = contents.toLowerCase().match(/#[^#\s]+\b/gim) || [];
+ this.selector.find('.Ldt-createAnnotation-keyword-button').each(function() {
+ var _tx = IriSP.jQuery(this).text(),
+ _rx = IriSP.regexpFromText(_tx);
+ if (_rx.test(contents)) {
+ _tags.push(_tx.toLowerCase())
+ }
+ });
+
+ annotation.tags = IriSP.underscore.uniq(_tags);
+
var jsonString = JSON.stringify(apiJson);
var project_id = this._serializer._data.meta.id;
@@ -436,8 +487,10 @@
annotation.meta = meta;
annotation.meta["id-ref"] = json.annotations[0]["type"];
+ } else {
+ annotation.type = "cinecast:UserAnnotation";
}
-
+ annotation.is_new = true;
// everything is shared so there's no need to propagate the change
_this._serializer._data.annotations.push(annotation);
diff -r ac66e2240e1e -r 8da49ff273e0 src/js/widgets/traceWidget.js
--- a/src/js/widgets/traceWidget.js Fri Mar 30 18:00:26 2012 +0200
+++ b/src/js/widgets/traceWidget.js Tue Apr 03 20:30:12 2012 +0200
@@ -127,6 +127,7 @@
}
this.lastEvent = _traceName;
this.tracer.trace(_traceName, _arg);
- console.log("trace('" + _traceName + "', " + JSON.stringify(_arg) + ");");
-
+ if (this._config.js_console) {
+ console.log("tracer.trace('" + _traceName + "', " + JSON.stringify(_arg) + ");");
+ }
}
diff -r ac66e2240e1e -r 8da49ff273e0 src/templates/createAnnotationWidget.html
--- a/src/templates/createAnnotationWidget.html Fri Mar 30 18:00:26 2012 +0200
+++ b/src/templates/createAnnotationWidget.html Tue Apr 03 20:30:12 2012 +0200
@@ -32,6 +32,9 @@
{{/keywords}}
+ {{#random_keywords}}
+
+ {{/random_keywords}}
{{/keywords.length}}
{{#polemic_mode}}
{{#polemics.length}}
@@ -58,12 +61,14 @@
{{/user_avatar}} {{#user_avatar}}
{{/user_avatar}} {{#user_avatar}} {{l10n.empty_annotation}}
"; +IriSP.loading_template = "