comparison johndyer-mediaelement-13fa20a/src/js/me-utility.js @ 0:032bc65ebafc

added core components
author George Fazekas <gyorgy.fazekas@eecs.qmul.ac.uk>
date Wed, 06 Mar 2013 15:45:48 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:032bc65ebafc
1
2 /*
3 Utility methods
4 */
5 mejs.Utility = {
6 encodeUrl: function(url) {
7 return encodeURIComponent(url); //.replace(/\?/gi,'%3F').replace(/=/gi,'%3D').replace(/&/gi,'%26');
8 },
9 escapeHTML: function(s) {
10 return s.toString().split('&').join('&amp;').split('<').join('&lt;').split('"').join('&quot;');
11 },
12 absolutizeUrl: function(url) {
13 var el = document.createElement('div');
14 el.innerHTML = '<a href="' + this.escapeHTML(url) + '">x</a>';
15 return el.firstChild.href;
16 },
17 getScriptPath: function(scriptNames) {
18 var
19 i = 0,
20 j,
21 path = '',
22 name = '',
23 script,
24 scripts = document.getElementsByTagName('script');
25
26 for (; i < scripts.length; i++) {
27 script = scripts[i].src;
28 for (j = 0; j < scriptNames.length; j++) {
29 name = scriptNames[j];
30 if (script.indexOf(name) > -1) {
31 path = script.substring(0, script.indexOf(name));
32 break;
33 }
34 }
35 if (path !== '') {
36 break;
37 }
38 }
39 return path;
40 },
41 secondsToTimeCode: function(seconds,forceHours) {
42 seconds = Math.round(seconds);
43 var hours,
44 minutes = Math.floor(seconds / 60);
45 if (minutes >= 60) {
46 hours = Math.floor(minutes / 60);
47 minutes = minutes % 60;
48 }
49 hours = hours === undefined ? "00" : (hours >= 10) ? hours : "0" + hours;
50 minutes = (minutes >= 10) ? minutes : "0" + minutes;
51 seconds = Math.floor(seconds % 60);
52 seconds = (seconds >= 10) ? seconds : "0" + seconds;
53 return ((hours > 0 || forceHours === true) ? hours + ":" :'') + minutes + ":" + seconds;
54 },
55 timeCodeToSeconds: function(timecode){
56 var tab = timecode.split(':');
57 return tab[0]*60*60 + tab[1]*60 + parseFloat(tab[2].replace(',','.'));
58 }
59 };