Moved h5p.js to library folder

namespaces
Svein-Tore Griff With 2013-01-17 09:01:43 +01:00
parent decfb609ab
commit 412a90964d
1 changed files with 94 additions and 0 deletions

94
js/h5p.js Normal file
View File

@ -0,0 +1,94 @@
window.H5P = window.H5P || {};
//
// Initialize H5P content
// Scans for ".h5p-content"
H5P.init = function () {
$(".h5p-content").each(function (idx, el) {
var $el = H5P.jQuery(el);
var obj = new (H5P.classFromName($el.data('class')))(H5P.jQuery.parseJSON(Drupal.settings.h5p.jsonContent));
obj.attach($el);
});
};
//
// Used from libraries to construct instances of other libraries' objects by
// name.
//
H5P.classFromName = function(name) {
var arr = name.split(".");
return this[arr[arr.length-1]];
};
// Helper object for keeping coordinates in the same format all over.
H5P.Coords = function(x, y, w, h) {
if ( !(this instanceof H5P.Coords) )
return new H5P.Coords(x, y, w, h);
this.x = 0;
this.y = 0;
this.w = 1;
this.h = 1;
if (typeof(x) == 'object') {
this.x = x.x;
this.y = x.y;
this.w = x.w;
this.h = x.h;
} else {
if (x !== undefined) {
this.x = x;
}
if (y !== undefined) {
this.y = y;
}
if (w !== undefined) {
this.w = w;
}
if (h !== undefined) {
this.h = h;
}
}
return this;
};
// We have several situations where we want to shuffle an array, extend array
// to do so.
Array.prototype.shuffle = function() {
var i = this.length, j, tempi, tempj;
if ( i === 0 ) return false;
while ( --i ) {
j = Math.floor( Math.random() * ( i + 1 ) );
tempi = this[i];
tempj = this[j];
this[i] = tempj;
this[j] = tempi;
}
return this;
};
// Add indexOf to browsers that lack them. (IEs)
if(!Array.prototype.indexOf) {
Array.prototype.indexOf = function(needle) {
for(var i = 0; i < this.length; i++) {
if(this[i] === needle) {
return i;
}
}
return -1;
};
}
// Simple 'contains' function. Easier to use than keep testing indexOf to -1.
Array.prototype.contains = function (needle) {
return (this.indexOf(needle) > -1);
};
// We want our own jQuery version, regardless of what the containing page is
// up to.
(function () {
document.writeln('<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>');
document.writeln('<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>');
document.writeln('<script>H5P.jQuery = jQuery.noConflict(); H5P.jQuery(document).ready(function(){H5P.init();});</script>');
})();