src/js/utils.js
author hamidouk
Mon, 07 Nov 2011 15:27:12 +0100
branchpopcorn-port
changeset 198 8ffb1b7a9c6b
parent 160 d3f336807ec3
child 238 6008172a0592
child 252 fd84e0fb26d8
permissions -rw-r--r--
activated youtube support.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
     1
/* utils.js - various utils that don't belong anywhere else */
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
     2
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
     3
/* trace function, for debugging */
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
     4
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
     5
IriSP.traceNum = 0;
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
     6
IriSP.trace = function( msg, value ) {
73
a8192c57c87d added a function to make closures (for use in callbacks).
hamidouk
parents: 60
diff changeset
     7
/*
31
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
     8
	if( IriSP.config.gui.debug === true ) {
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
     9
		IriSP.traceNum += 1;
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    10
		IriSP.jQuery( "<div>"+IriSP.traceNum+" - "+msg+" : "+value+"</div>" ).appendTo( "#Ldt-output" );
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    11
	}
73
a8192c57c87d added a function to make closures (for use in callbacks).
hamidouk
parents: 60
diff changeset
    12
*/
31
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    13
};
cbb1425bc769 begun breaking the code across multiple files.
hamidouk
parents:
diff changeset
    14
73
a8192c57c87d added a function to make closures (for use in callbacks).
hamidouk
parents: 60
diff changeset
    15
/* used in callbacks - because in callbacks we lose "this",
a8192c57c87d added a function to make closures (for use in callbacks).
hamidouk
parents: 60
diff changeset
    16
   we need to have a special function which wraps "this" in 
a8192c57c87d added a function to make closures (for use in callbacks).
hamidouk
parents: 60
diff changeset
    17
   a closure. This way, the 
a8192c57c87d added a function to make closures (for use in callbacks).
hamidouk
parents: 60
diff changeset
    18
*/   
a8192c57c87d added a function to make closures (for use in callbacks).
hamidouk
parents: 60
diff changeset
    19
IriSP.wrap = function (obj, fn) {
a8192c57c87d added a function to make closures (for use in callbacks).
hamidouk
parents: 60
diff changeset
    20
  return function() {
78
d77fe3283530 fixing global var bug.
hamidouk
parents: 73
diff changeset
    21
    var args = [].slice.call(this, arguments);
d77fe3283530 fixing global var bug.
hamidouk
parents: 73
diff changeset
    22
    return fn.call(obj, args);
73
a8192c57c87d added a function to make closures (for use in callbacks).
hamidouk
parents: 60
diff changeset
    23
  }
a8192c57c87d added a function to make closures (for use in callbacks).
hamidouk
parents: 60
diff changeset
    24
}
a8192c57c87d added a function to make closures (for use in callbacks).
hamidouk
parents: 60
diff changeset
    25
99
912f100fecb0 added a small utility function to convert a time to a progression percentage.
hamidouk
parents: 78
diff changeset
    26
/* convert a time to a percentage in the media */
103
2dfd89e91c3a added a method to sort the json annotations. changed the tests accordingly.
hamidouk
parents: 99
diff changeset
    27
IriSP.timeToPourcent = function(time, timetotal){
160
d3f336807ec3 a little tweak to timeToPourcent.
hamidouk
parents: 103
diff changeset
    28
	// return (parseInt(Math.round(time/timetotal*100)));
d3f336807ec3 a little tweak to timeToPourcent.
hamidouk
parents: 103
diff changeset
    29
	return Math.floor((time/timetotal) * 100);
99
912f100fecb0 added a small utility function to convert a time to a progression percentage.
hamidouk
parents: 78
diff changeset
    30
};
912f100fecb0 added a small utility function to convert a time to a progression percentage.
hamidouk
parents: 78
diff changeset
    31
60
ffc038fdb8f1 commented ie8 helper function
hamidouk
parents: 31
diff changeset
    32
/* for ie compatibility
ffc038fdb8f1 commented ie8 helper function
hamidouk
parents: 31
diff changeset
    33
if (Object.prototype.__defineGetter__&&!Object.defineProperty) {
ffc038fdb8f1 commented ie8 helper function
hamidouk
parents: 31
diff changeset
    34
   Object.defineProperty=function(obj,prop,desc) {
ffc038fdb8f1 commented ie8 helper function
hamidouk
parents: 31
diff changeset
    35
      if ("get" in desc) obj.__defineGetter__(prop,desc.get);
ffc038fdb8f1 commented ie8 helper function
hamidouk
parents: 31
diff changeset
    36
      if ("set" in desc) obj.__defineSetter__(prop,desc.set);
ffc038fdb8f1 commented ie8 helper function
hamidouk
parents: 31
diff changeset
    37
   }
ffc038fdb8f1 commented ie8 helper function
hamidouk
parents: 31
diff changeset
    38
}
ffc038fdb8f1 commented ie8 helper function
hamidouk
parents: 31
diff changeset
    39
*/