src/js/utils.js
author hamidouk
Thu, 20 Oct 2011 10:19:00 +0200
branchpopcorn-port
changeset 99 912f100fecb0
parent 78 d77fe3283530
child 103 2dfd89e91c3a
permissions -rw-r--r--
added a small utility function to convert a time to a progression percentage.
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 */
912f100fecb0 added a small utility function to convert a time to a progression percentage.
hamidouk
parents: 78
diff changeset
    27
IriSP.timeToPourcent = function(time,timetotal){
912f100fecb0 added a small utility function to convert a time to a progression percentage.
hamidouk
parents: 78
diff changeset
    28
	return (parseInt(Math.round(time/timetotal*100)));
912f100fecb0 added a small utility function to convert a time to a progression percentage.
hamidouk
parents: 78
diff changeset
    29
};
912f100fecb0 added a small utility function to convert a time to a progression percentage.
hamidouk
parents: 78
diff changeset
    30
60
ffc038fdb8f1 commented ie8 helper function
hamidouk
parents: 31
diff changeset
    31
/* for ie compatibility
ffc038fdb8f1 commented ie8 helper function
hamidouk
parents: 31
diff changeset
    32
if (Object.prototype.__defineGetter__&&!Object.defineProperty) {
ffc038fdb8f1 commented ie8 helper function
hamidouk
parents: 31
diff changeset
    33
   Object.defineProperty=function(obj,prop,desc) {
ffc038fdb8f1 commented ie8 helper function
hamidouk
parents: 31
diff changeset
    34
      if ("get" in desc) obj.__defineGetter__(prop,desc.get);
ffc038fdb8f1 commented ie8 helper function
hamidouk
parents: 31
diff changeset
    35
      if ("set" in desc) obj.__defineSetter__(prop,desc.set);
ffc038fdb8f1 commented ie8 helper function
hamidouk
parents: 31
diff changeset
    36
   }
ffc038fdb8f1 commented ie8 helper function
hamidouk
parents: 31
diff changeset
    37
}
ffc038fdb8f1 commented ie8 helper function
hamidouk
parents: 31
diff changeset
    38
*/