/
svc.Tranny.js
74 lines (58 loc) · 1.48 KB
/
svc.Tranny.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var languageCache = {};
angular.module( 'tranny', [] )
.directive( 'ngTranny', function ( $parse )
{
return function( scope, element, attrs )
{
var strName = "";
var update = function()
{
if ( !IN_ENGINE )
{
$(element).html( strName );
$(element).attr( "placeholder", strName );
return;
}
var outStr_old = languageCache[ strName ] || language.Update( strName, function( outStr )
{
languageCache[ strName ] = outStr;
$(element).html( outStr );
$(element).attr( "placeholder", outStr );
} );
if ( outStr_old )
{
// Compatibility with Awesomium
languageCache[ strName ] = outStr_old;
$(element).html( outStr_old );
$(element).attr( "placeholder", outStr_old );
}
}
scope.$watch( attrs.ngTranny, function( value )
{
strName = value;
update();
} );
scope.$on( 'languagechanged', function()
{
languageCache = {};
update();
} );
}
} )
.directive( 'ngSeconds', function ( $parse )
{
return function ( scope, element, attrs )
{
var strName = "";
scope.$watch( attrs.ngSeconds, function ( value )
{
if ( value < 60 )
return $(element).html( Math.floor( value ) + " sec" );
if ( value < 60 * 60 )
return $( element ).html( Math.floor( value / 60 ) + " min" );
if ( value < 60 * 60 * 24 )
return $( element ).html( Math.floor( value / 60 / 60 ) + " hr" );
$( element ).html( "a long time" );
});
}
} );