| author | hamidouk |
| Wed, 16 Nov 2011 11:40:57 +0100 | |
| branch | popcorn-port |
| changeset 253 | 95c6b77f005e |
| parent 252 | fd84e0fb26d8 |
| child 254 | cafaa694b709 |
| permissions | -rw-r--r-- |
| 31 | 1 |
/* utils.js - various utils that don't belong anywhere else */ |
2 |
||
3 |
/* trace function, for debugging */ |
|
4 |
||
5 |
IriSP.traceNum = 0; |
|
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 | 8 |
if( IriSP.config.gui.debug === true ) { |
9 |
IriSP.traceNum += 1; |
|
10 |
IriSP.jQuery( "<div>"+IriSP.traceNum+" - "+msg+" : "+value+"</div>" ).appendTo( "#Ldt-output" ); |
|
11 |
} |
|
|
73
a8192c57c87d
added a function to make closures (for use in callbacks).
hamidouk
parents:
60
diff
changeset
|
12 |
*/ |
| 31 | 13 |
}; |
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) { |
| 253 | 20 |
return function() { |
21 |
var args = Array.prototype.slice.call(arguments, 0); |
|
22 |
return fn.apply(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){ |
| 253 | 28 |
var time = Math.abs(time); |
29 |
var timetotal = Math.abs(timetotal); |
|
30 |
|
|
| 160 | 31 |
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
|
32 |
}; |
|
912f100fecb0
added a small utility function to convert a time to a progression percentage.
hamidouk
parents:
78
diff
changeset
|
33 |
|
|
252
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
160
diff
changeset
|
34 |
/* convert a number of seconds to a tuple of the form |
|
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
160
diff
changeset
|
35 |
[hours, minutes, seconds] |
|
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
160
diff
changeset
|
36 |
*/ |
|
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
160
diff
changeset
|
37 |
IriSP.secondsToTime = function(secs) { |
|
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
160
diff
changeset
|
38 |
var hours = Math.abs(parseInt( secs / 3600 ) % 24); |
|
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
160
diff
changeset
|
39 |
var minutes = Math.abs(parseInt( secs / 60 ) % 60); |
|
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
160
diff
changeset
|
40 |
var seconds = Math.abs(secs % 60); |
|
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
160
diff
changeset
|
41 |
|
|
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
160
diff
changeset
|
42 |
return [hours, minutes, seconds]; |
|
fd84e0fb26d8
added a function to convert a number of seconds to an hour, minutes, seconds.
hamidouk
parents:
160
diff
changeset
|
43 |
} |
| 60 | 44 |
/* for ie compatibility |
45 |
if (Object.prototype.__defineGetter__&&!Object.defineProperty) { |
|
46 |
Object.defineProperty=function(obj,prop,desc) { |
|
47 |
if ("get" in desc) obj.__defineGetter__(prop,desc.get); |
|
48 |
if ("set" in desc) obj.__defineSetter__(prop,desc.set); |
|
49 |
} |
|
50 |
} |
|
51 |
*/ |