OpenROV /
openrov-cockpit
| 1 | function msToTime(s) { |
||
| 2 | function addZ(n) { |
||
| 3 | return (n < 10 ? '0' : '') + n; |
||
| 4 | } |
||
| 5 | var ms = s % 1000; |
||
| 6 | s = (s - ms) / 1000; |
||
| 7 | var secs = s % 60; |
||
| 8 | s = (s - secs) / 60; |
||
| 9 | var mins = s % 60; |
||
| 10 | var hrs = (s - mins) / 60; |
||
| 11 | return addZ(hrs) + ':' + addZ(mins) + ':' + addZ(secs); // + '.' + ms; |
||
| 12 | } |
||
| 13 | // used to dynamically load plugin assets |
||
| 14 | function urlOfJsFile(jsfile) { |
||
| 15 | var scriptElements = document.getElementsByTagName('script'); |
||
| 16 | var i, element, myfile; |
||
| 17 | for (i = 0; element = scriptElements[i]; i++) { |
||
|
0 ignored issues
–
show
|
|||
| 18 | myfile = element.src; |
||
| 19 | if (myfile.indexOf(jsfile) >= 0) { |
||
| 20 | var myurl = myfile.substring(0, myfile.indexOf(jsfile)); |
||
| 21 | } |
||
| 22 | } |
||
| 23 | return myurl; |
||
|
0 ignored issues
–
show
The variable
myurl seems to be used out of scope.
This error can usually be fixed by declaring the variable in the scope where it is used: function someFunction() {
(function() {
var i = 0;
})();
// i is not defined.
alert(i);
}
// This can be fixed by moving the var statement to the outer scope.
function someFunction() {
var i;
(function() {
i = 1;
})();
alert(i);
};
Loading history...
|
|||
| 24 | } |
||
| 25 | function namespace(namespaceString) { |
||
| 26 | if (namespaceString === undefined) { |
||
| 27 | namespaceString = ''; |
||
| 28 | } |
||
| 29 | var parts = namespaceString.split('.'), parent = window, currentPart = ''; |
||
| 30 | if (window.OROV === undefined) { |
||
| 31 | window.OROV = {}; |
||
| 32 | } |
||
| 33 | parent = window.OROV; |
||
| 34 | for (var i = 0, length = parts.length; i < length; i++) { |
||
| 35 | currentPart = parts[i]; |
||
| 36 | parent[currentPart] = parent[currentPart] || {}; |
||
| 37 | parent = parent[currentPart]; |
||
| 38 | } |
||
| 39 | return parent; |
||
| 40 | } |
||
| 41 | //http://stackoverflow.com/posts/8809472/revisions |
||
| 42 | function generateUUID() { |
||
| 43 | var d = new Date().getTime(); |
||
| 44 | if (window.performance && typeof window.performance.now === 'function') { |
||
| 45 | d += performance.now(); //use high-precision timer if available |
||
| 46 | } |
||
| 47 | var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { |
||
| 48 | var r = (d + Math.random() * 16) % 16 | 0; |
||
| 49 | d = Math.floor(d / 16); |
||
| 50 | return (c == 'x' ? r : r & 3 | 8).toString(16); |
||
| 51 | }); |
||
| 52 | return uuid; |
||
| 53 | } |
||
| 54 | //http://balpha.de/2011/10/jquery-script-insertion-and-its-consequences-for-debugging/ |
||
| 55 | var loadScript = function (path) { |
||
| 56 | var result = $.Deferred(), script = document.createElement('script'); |
||
| 57 | script.async = 'async'; |
||
| 58 | script.type = 'text/javascript'; |
||
| 59 | script.src = path; |
||
| 60 | script.onload = script.onreadystatechange = function (_, isAbort) { |
||
| 61 | if (!script.readyState || /loaded|complete/.test(script.readyState)) { |
||
| 62 | if (isAbort) |
||
| 63 | result.reject(); |
||
| 64 | else |
||
| 65 | result.resolve(); |
||
| 66 | } |
||
| 67 | }; |
||
| 68 | script.onerror = function () { |
||
| 69 | result.reject(); |
||
| 70 | }; |
||
| 71 | $('head')[0].appendChild(script); |
||
| 72 | return result.promise(); |
||
| 73 | }; |
||
| 74 | //http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript |
||
| 75 | function getParameterByName(name, url) { |
||
| 76 | if (!url) |
||
| 77 | url = window.location.href; |
||
| 78 | name = name.replace(/[\[\]]/g, '\\$&'); |
||
| 79 | var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'), results = regex.exec(url); |
||
| 80 | if (!results) |
||
| 81 | return null; |
||
| 82 | if (!results[2]) |
||
| 83 | return ''; |
||
| 84 | return decodeURIComponent(results[2].replace(/\+/g, ' ')); |
||
| 85 | } |
Even if this assignment is intended here, we recommend to make this explicit in order to make your code more readable and your intention clear:
1. Assignment in
2. Assignment in
3. Uninitialized loop variable