Details done except for syllabus
This commit is contained in:
@@ -36,5 +36,72 @@ CMS.Models.Settings.CourseDetails = Backbone.Model.extend({
|
||||
urlRoot: function() {
|
||||
var location = this.get('location');
|
||||
return '/' + location.get('org') + "/" + location.get('course') + '/settings/' + location.get('name') + '/section/details';
|
||||
},
|
||||
|
||||
_videoprefix : /\s*<video\s*youtube="/g,
|
||||
_videospeedparse : /\d+\.?\d*(?=:)/g,
|
||||
_videokeyparse : /([^,\/]+)/g,
|
||||
_videonosuffix : /[^\"]+/g,
|
||||
_getNextMatch : function (regex, string, cursor) {
|
||||
regex.lastIndex = cursor;
|
||||
return regex.exec(string);
|
||||
},
|
||||
// the whole string for editing
|
||||
getVideoSource: function() {
|
||||
if (this.get('intro_video')) {
|
||||
var cursor = 0;
|
||||
var videostring = this.get('intro_video');
|
||||
this._getNextMatch(this._videoprefix, videostring, cursor);
|
||||
cursor = this._videoprefix.lastIndex;
|
||||
return this._getNextMatch(this._videonosuffix, videostring, cursor);
|
||||
}
|
||||
else return "";
|
||||
},
|
||||
// the source closest to 1.0 speed
|
||||
videosourceSample: function() {
|
||||
if (this.get('intro_video')) {
|
||||
var cursor = 0;
|
||||
var videostring = this.get('intro_video');
|
||||
this._getNextMatch(this._videoprefix, videostring, cursor);
|
||||
cursor = this._videoprefix.lastIndex;
|
||||
|
||||
// parse from [speed:id,/s?]* to find 1.0 or take first
|
||||
var parsedspeed = this._getNextMatch(this._videospeedparse, videostring, cursor);
|
||||
var bestkey;
|
||||
if (parsedspeed) {
|
||||
cursor = this._videospeedparse.lastIndex + 1;
|
||||
var bestspeed = Number(parsedspeed);
|
||||
bestkey = this._getNextMatch(this._videokeyparse, videostring, cursor);
|
||||
cursor = this._videokeyparse.lastIndex + 1;
|
||||
while (cursor < videostring.length && bestspeed != 1.0) {
|
||||
parsedspeed = this._getNextMatch(this._videospeedparse, videostring, cursor);
|
||||
cursor = this._videospeedparse.lastIndex + 1;
|
||||
if (Math.abs(Number(parsedspeed) - 1.0) < Math.abs(bestspeed - 1.0)) {
|
||||
bestspeed = Number(parsedspeed);
|
||||
bestkey = this._getNextMatch(this._videokeyparse, videostring, cursor);
|
||||
}
|
||||
else this._getNextMatch(this._videokeyparse, videostring, cursor);
|
||||
cursor = this._videokeyparse.lastIndex + 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
bestkey = this._getNextMatch(this._videokeyparse, videostring, cursor);
|
||||
}
|
||||
if (bestkey) {
|
||||
// WTF? for some reason bestkey is an array [key, key] (same one repeated)
|
||||
if (_.isArray(bestkey)) bestkey = bestkey[0];
|
||||
return "http://www.youtube.com/embed/" + bestkey;
|
||||
}
|
||||
else return "";
|
||||
}
|
||||
},
|
||||
save_videosource: function(newsource) {
|
||||
// newsource either is <video youtube="speed:key, *"/> or just the "speed:key, *" string
|
||||
// returns the videosource for the preview which iss the key whose speed is closest to 1
|
||||
if (newsource == null) this.save({'intro_video': null});
|
||||
else if (this._getNextMatch(this._videoprefix, newsource, 0)) this.save('intro_video', newsource);
|
||||
else this.save('intro_video', '<video youtube="' + newsource + '"/>');
|
||||
|
||||
return this.videosourceSample();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user