This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ngx.js
3317 lines (2792 loc) · 116 KB
/
ngx.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* NGX - extension library for AngularJS
* @version v0.2.2 - 2013-04-23
* @link http://github.com/lmc-eu/ngx-library
* @license MIT License, http://www.opensource.org/licenses/MIT
*/
(function(angular) {
'use strict';
angular.module('ngx', [
'ngx.config',
'ngx.date',
'ngx.dictionary',
'ngx.loader',
'ngx.smap',
'ngx.utils',
'ngx.ui.addressInput',
'ngx.ui.checkboxlist',
'ngx.ui.ckeditor',
'ngx.ui.confirm',
'ngx.ui.dateInput',
'ngx.ui.dialog',
'ngx.ui.gallery',
'ngx.ui.geomap',
'ngx.ui.hashtagInput',
'ngx.ui.imageupload',
'ngx.ui.invalid',
'ngx.ui.lightbox',
'ngx.ui.rating',
'ngx.ui.scrollTo',
'ngx.ui.smap',
'ngx.ui.tagsInput',
'ngx.ui.textCurtain',
'ngx.ui.timeInput',
'ngx.ui.tooltip',
'ngx.ui.translate',
'ngx.ui.validate',
'ngx.ui.wwwInput',
'ngx.ui.wysiwyg'
]);
})(window.angular);
/**
* Missing ECMAScript Array functions
*/
(function(Array) {
'use strict';
if (!Array.prototype.indexOf) {
/**
* Searches the array for the specified item and returns its position
* @param search
* @return {Number}
*/
Array.prototype.indexOf = function(search) {
for (var i = 0; i < this.length; i++) {
if (this[i] === search) {
return i;
}
}
return -1;
};
}
})(window.Array);
/**
Head JS The only script in your <HEAD>
Copyright Tero Piirainen (tipiirai)
License MIT / http://bit.ly/mit-license
Version 0.96
http://headjs.com
*/
(function(doc, window) {
'use strict';
var head = doc.documentElement,
isHeadReady,
isDomReady,
domWaiters = [],
queue = [], // waiters for the "head ready" event
handlers = {}, // user functions waiting for events
scripts = {}, // loadable scripts in different states
isAsync = doc.createElement("script").async === true || "MozAppearance" in doc.documentElement.style || window.opera;
/*** public API ***/
var head_var = window.head_conf && window.head_conf.head || "head",
api = window[head_var] = (window[head_var] || function() { api.ready.apply(null, arguments); });
// states
var PRELOADED = 1,
PRELOADING = 2,
LOADING = 3,
LOADED = 4;
// Method 1: simply load and let browser take care of ordering
if (isAsync) {
api.js = function() {
var args = arguments,
fn = args[args.length -1],
els = {};
if (!isFunc(fn)) { fn = null; }
each(args, function(el, i) {
if (el != fn) {
el = getScript(el);
els[el.name] = el;
load(el, fn && i == args.length -2 ? function() {
if (allLoaded(els)) { one(fn); }
} : null);
}
});
return api;
};
// Method 2: preload with text/cache hack
} else {
api.js = function() {
var args = arguments,
rest = [].slice.call(args, 1),
next = rest[0];
// wait for a while. immediate execution causes some browsers to ignore caching
if (!isHeadReady) {
queue.push(function() {
api.js.apply(null, args);
});
return api;
}
// multiple arguments
if (next) {
// load
each(rest, function(el) {
if (!isFunc(el)) {
preload(getScript(el));
}
});
// execute
load(getScript(args[0]), isFunc(next) ? next : function() {
api.js.apply(null, rest);
});
// single script
} else {
load(getScript(args[0]));
}
return api;
};
}
api.ready = function(key, fn) {
// DOM ready check: head.ready(document, function() { });
if (key == doc) {
if (isDomReady) { one(fn); }
else { domWaiters.push(fn); }
return api;
}
// shift arguments
if (isFunc(key)) {
fn = key;
key = "ALL";
}
// make sure arguments are sane
if (typeof key != 'string' || !isFunc(fn)) { return api; }
var script = scripts[key];
// script already loaded --> execute and return
if (script && script.state == LOADED || key == 'ALL' && allLoaded() && isDomReady) {
one(fn);
return api;
}
var arr = handlers[key];
if (!arr) { arr = handlers[key] = [fn]; }
else { arr.push(fn); }
return api;
};
// perform this when DOM is ready
api.ready(doc, function() {
if (allLoaded()) {
each(handlers.ALL, function(fn) {
one(fn);
});
}
if (api.feature) {
api.feature("domloaded", true);
}
});
/*** private functions ***/
// call function once
function one(fn) {
if (fn._done) { return; }
fn();
fn._done = 1;
}
function toLabel(url) {
var els = url.split("/"),
name = els[els.length -1],
i = name.indexOf("?");
return i != -1 ? name.substring(0, i) : name;
}
function getScript(url) {
var script;
if (typeof url == 'object') {
for (var key in url) {
if (url[key]) {
script = { name: key, url: url[key] };
}
}
} else {
script = { name: toLabel(url), url: url };
}
var existing = scripts[script.name];
if (existing && existing.url === script.url) { return existing; }
scripts[script.name] = script;
return script;
}
function each(arr, fn) {
if (!arr) { return; }
// arguments special type
if (typeof arr == 'object') { arr = [].slice.call(arr); }
// do the job
for (var i = 0; i < arr.length; i++) {
fn.call(arr, arr[i], i);
}
}
function isFunc(el) {
return Object.prototype.toString.call(el) == '[object Function]';
}
function allLoaded(els) {
els = els || scripts;
var loaded;
for (var name in els) {
if (els.hasOwnProperty(name) && els[name].state != LOADED) { return false; }
loaded = true;
}
return loaded;
}
function onPreload(script) {
script.state = PRELOADED;
each(script.onpreload, function(el) {
el.call();
});
}
function preload(script, callback) {
if (script.state === undefined) {
script.state = PRELOADING;
script.onpreload = [];
scriptTag({ src: script.url, type: 'cache'}, function() {
onPreload(script);
});
}
}
function load(script, callback) {
if (script.state == LOADED) {
return callback && callback();
}
if (script.state == LOADING) {
return api.ready(script.name, callback);
}
if (script.state == PRELOADING) {
return script.onpreload.push(function() {
load(script, callback);
});
}
script.state = LOADING;
scriptTag(script.url, function() {
script.state = LOADED;
if (callback) { callback(); }
// handlers for this script
each(handlers[script.name], function(fn) {
one(fn);
});
// everything ready
if (allLoaded() && isDomReady) {
each(handlers.ALL, function(fn) {
one(fn);
});
}
});
}
function scriptTag(src, callback) {
var s = doc.createElement('script');
s.type = 'text/' + (src.type || 'javascript');
s.src = src.src || src;
s.async = false;
s.onreadystatechange = s.onload = function() {
var state = s.readyState;
if (!callback.done && (!state || /loaded|complete/.test(state))) {
callback.done = true;
callback();
}
};
// use body if available. more safe in IE
(doc.body || head).appendChild(s);
}
/*
The much desired DOM ready check
Thanks to jQuery and http://javascript.nwbox.com/IEContentLoaded/
*/
function fireReady() {
if (!isDomReady) {
isDomReady = true;
each(domWaiters, function(fn) {
one(fn);
});
}
}
// W3C
if (window.addEventListener) {
doc.addEventListener("DOMContentLoaded", fireReady, false);
// fallback. this is always called
window.addEventListener("load", fireReady, false);
// IE
} else if (window.attachEvent) {
// for iframes
doc.attachEvent("onreadystatechange", function() {
if (doc.readyState === "complete" ) {
fireReady();
}
});
// avoid frames with different domains issue
var frameElement = 1;
try {
frameElement = window.frameElement;
} catch(e) {}
if (!frameElement && head.doScroll) {
(function() {
try {
head.doScroll("left");
fireReady();
} catch(e) {
var a = arguments;
window.setTimeout(a.callee, 1);
return;
}
})();
}
// fallback
window.attachEvent("onload", fireReady);
}
// enable document.readyState for Firefox <= 3.5
if (!doc.readyState && doc.addEventListener) {
var handler;
doc.readyState = "loading";
doc.addEventListener("DOMContentLoaded", handler = function () {
doc.removeEventListener("DOMContentLoaded", handler, false);
doc.readyState = "complete";
}, false);
}
/*
We wait for 300 ms before script loading starts. for some reason this is needed
to make sure scripts are cached. Not sure why this happens yet. A case study:
https://github.com/headjs/headjs/issues/closed#issue/83
*/
window.setTimeout(function() {
isHeadReady = true;
each(queue, function(fn) { fn(); });
}, 300);
})(window.document, window);
(function(angular, document) {
'use strict';
// determine base path
var basePath = null,
re = /ngx(\.min)?\.js(.*)$/;
angular.forEach(document.getElementsByTagName('script'), function(script) {
if (script.src.match(re)) {
basePath = script.src.replace(re, '');
}
});
if (basePath === null) {
throw new Error('ngx base path cannot be determined.');
}
var module = angular.module('ngx.config', []);
/**
* Configuration
*/
module.value('ngxConfig', {
basePath: basePath,
libsPath: basePath + 'libs/',
templatesPath: basePath + 'templates/',
ui: {}
});
})(window.angular, window.document);
/**
* Date module
* @todo avoid implementations from phpjs.org
*/
(function(angular) {
'use strict';
var ngxDate = {};
/**
* Date formatter
* @param format
* @param timestamp
* @return {*}
*/
ngxDate.format = function(format, timestamp) {
// % note 2: Although the function potentially allows timezone info (see notes), it currently does not set
// % note 2: per a timezone specified by date_default_timezone_set(). Implementers might use
// % note 2: this.php_js.currentTimezoneOffset and this.php_js.currentTimezoneDST set by that function
// % note 2: in order to adjust the dates in this function (or our other date functions!) accordingly
// * example 1: date('H:m:s \\m \\i\\s \\m\\o\\n\\t\\h', 1062402400);
// * returns 1: '09:09:40 m is month'
// * example 2: date('F j, Y, g:i a', 1062462400);
// * returns 2: 'September 2, 2003, 2:26 am'
// * example 3: date('Y W o', 1062462400);
// * returns 3: '2003 36 2003'
// * example 4: x = date('Y m d', (new Date()).getTime()/1000);
// * example 4: (x+'').length == 10 // 2009 01 09
// * returns 4: true
// * example 5: date('W', 1104534000);
// * returns 5: '53'
// * example 6: date('B t', 1104534000);
// * returns 6: '999 31'
// * example 7: date('W U', 1293750000.82); // 2010-12-31
// * returns 7: '52 1293750000'
// * example 8: date('W', 1293836400); // 2011-01-01
// * returns 8: '52'
// * example 9: date('W Y-m-d', 1293974054); // 2011-01-02
// * returns 9: '52 2011-01-02'
var that = this,
jsdate, f, formatChr = /\\?([a-z])/gi,
formatChrCb,
// Keep this here (works, but for code commented-out
// below for file size reasons)
//, tal= [],
_pad = function (n, c) {
if ((n = n + '').length < c) {
return new Array((++c) - n.length).join('0') + n;
}
return n;
},
txt_words = ["Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
formatChrCb = function (t, s) {
return f[t] ? f[t]() : s;
};
f = {
// Day
d: function () { // Day of month w/leading 0; 01..31
return _pad(f.j(), 2);
},
D: function () { // Shorthand day name; Mon...Sun
return f.l().slice(0, 3);
},
j: function () { // Day of month; 1..31
return jsdate.getDate();
},
l: function () { // Full day name; Monday...Sunday
return txt_words[f.w()] + 'day';
},
N: function () { // ISO-8601 day of week; 1[Mon]..7[Sun]
return f.w() || 7;
},
S: function () { // Ordinal suffix for day of month; st, nd, rd, th
var j = f.j();
return j < 4 || j > 20 && ['st', 'nd', 'rd'][j%10 - 1] || 'th';
},
w: function () { // Day of week; 0[Sun]..6[Sat]
return jsdate.getDay();
},
z: function () { // Day of year; 0..365
var a = new Date(f.Y(), f.n() - 1, f.j()),
b = new Date(f.Y(), 0, 1);
return Math.round((a - b) / 864e5) + 1;
},
// Week
W: function () { // ISO-8601 week number
var a = new Date(f.Y(), f.n() - 1, f.j() - f.N() + 3),
b = new Date(a.getFullYear(), 0, 4);
return _pad(1 + Math.round((a - b) / 864e5 / 7), 2);
},
// Month
F: function () { // Full month name; January...December
return txt_words[6 + f.n()];
},
m: function () { // Month w/leading 0; 01...12
return _pad(f.n(), 2);
},
M: function () { // Shorthand month name; Jan...Dec
return f.F().slice(0, 3);
},
n: function () { // Month; 1...12
return jsdate.getMonth() + 1;
},
t: function () { // Days in month; 28...31
return (new Date(f.Y(), f.n(), 0)).getDate();
},
// Year
L: function () { // Is leap year?; 0 or 1
var j = f.Y();
return j%4===0 && j%100!==0 || j%400===0;
},
o: function () { // ISO-8601 year
var n = f.n(),
W = f.W(),
Y = f.Y();
return Y + (n === 12 && W < 9 ? -1 : n === 1 && W > 9);
},
Y: function () { // Full year; e.g. 1980...2010
return jsdate.getFullYear();
},
y: function () { // Last two digits of year; 00...99
return (f.Y() + "").slice(-2);
},
// Time
a: function () { // am or pm
return jsdate.getHours() > 11 ? "pm" : "am";
},
A: function () { // AM or PM
return f.a().toUpperCase();
},
B: function () { // Swatch Internet time; 000..999
var H = jsdate.getUTCHours() * 36e2,
// Hours
i = jsdate.getUTCMinutes() * 60,
// Minutes
s = jsdate.getUTCSeconds(); // Seconds
return _pad(Math.floor((H + i + s + 36e2) / 86.4) % 1e3, 3);
},
g: function () { // 12-Hours; 1..12
return f.G() % 12 || 12;
},
G: function () { // 24-Hours; 0..23
return jsdate.getHours();
},
h: function () { // 12-Hours w/leading 0; 01..12
return _pad(f.g(), 2);
},
H: function () { // 24-Hours w/leading 0; 00..23
return _pad(f.G(), 2);
},
i: function () { // Minutes w/leading 0; 00..59
return _pad(jsdate.getMinutes(), 2);
},
s: function () { // Seconds w/leading 0; 00..59
return _pad(jsdate.getSeconds(), 2);
},
u: function () { // Microseconds; 000000-999000
return _pad(jsdate.getMilliseconds() * 1000, 6);
},
// Timezone
e: function () { // Timezone identifier; e.g. Atlantic/Azores, ...
// The following works, but requires inclusion of the very large
// timezone_abbreviations_list() function.
/* return this.date_default_timezone_get();
*/
throw 'Not supported (see source code of date() for timezone on how to add support)';
},
I: function () { // DST observed?; 0 or 1
// Compares Jan 1 minus Jan 1 UTC to Jul 1 minus Jul 1 UTC.
// If they are not equal, then DST is observed.
var a = new Date(f.Y(), 0),
// Jan 1
c = Date.UTC(f.Y(), 0),
// Jan 1 UTC
b = new Date(f.Y(), 6),
// Jul 1
d = Date.UTC(f.Y(), 6); // Jul 1 UTC
return 0 + ((a - c) !== (b - d));
},
O: function () { // Difference to GMT in hour format; e.g. +0200
var tzo = jsdate.getTimezoneOffset(),
a = Math.abs(tzo);
return (tzo > 0 ? "-" : "+") + _pad(Math.floor(a / 60) * 100 + a % 60, 4);
},
P: function () { // Difference to GMT w/colon; e.g. +02:00
var O = f.O();
return (O.substr(0, 3) + ":" + O.substr(3, 2));
},
T: function () { // Timezone abbreviation; e.g. EST, MDT, ...
// The following works, but requires inclusion of the very
// large timezone_abbreviations_list() function.
/* var abbr = '', i = 0, os = 0, default = 0;
if (!tal.length) {
tal = that.timezone_abbreviations_list();
}
if (that.php_js && that.php_js.default_timezone) {
default = that.php_js.default_timezone;
for (abbr in tal) {
for (i=0; i < tal[abbr].length; i++) {
if (tal[abbr][i].timezone_id === default) {
return abbr.toUpperCase();
}
}
}
}
for (abbr in tal) {
for (i = 0; i < tal[abbr].length; i++) {
os = -jsdate.getTimezoneOffset() * 60;
if (tal[abbr][i].offset === os) {
return abbr.toUpperCase();
}
}
}
*/
return 'UTC';
},
Z: function () { // Timezone offset in seconds (-43200...50400)
return -jsdate.getTimezoneOffset() * 60;
},
// Full Date/Time
c: function () { // ISO-8601 date.
return 'Y-m-d\\Th:i:sP'.replace(formatChr, formatChrCb);
},
r: function () { // RFC 2822
return 'D, d M Y H:i:s O'.replace(formatChr, formatChrCb);
},
U: function () { // Seconds since UNIX epoch
return parseInt(jsdate / 1000, 10);
}
};
this.date = function (format, timestamp) {
that = this;
jsdate = (timestamp === null ? new Date() : // Not provided
(timestamp instanceof Date) ? new Date(timestamp) : // JS Date()
new Date(timestamp * 1000) // UNIX timestamp (auto-convert to int)
);
return format.replace(formatChr, formatChrCb);
};
return this.date(format, timestamp);
};
/**
* Date validator (from phpjs.org)
* @param year
* @param month
* @param day
* @return {Boolean}
*/
ngxDate.check = function(year, month, day) {
// http://kevin.vanzonneveld.net
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: Pyerre
// + improved by: Theriault
// * example 1: checkdate(12, 31, 2000);
// * returns 1: true
// * example 2: checkdate(2, 29, 2001);
// * returns 2: false
// * example 3: checkdate(3, 31, 2008);
// * returns 3: true
// * example 4: checkdate(1, 390, 2000);
// * returns 4: false
return (month > 0 && month < 13 && year > 0 && year < 32768 && day > 0 && day <= (new Date(year, month, 0)).getDate());
};
/**
* Date parser
* Accepts date in format DD.MM.YYYY or placeholder string "today" or relative number of days +1d / -1d
* @param inputValue Date (DD.MM.YYYY) or relative date placeholder
* @return {Date}
*/
ngxDate.parse = function(inputValue) {
var r = new RegExp('^([0-9]{1,2}). ?([0-9]{1,2}). ?([0-9]{4})').exec(inputValue);
var str = new RegExp('^([\\-|\\+]?)([0-9]+)d').exec(inputValue);
var now = new Date();
if (inputValue == 'today') {
// just return today's date
return new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0, 0);
} else if (r && ngxDate.check(r[3], r[2], r[1])) {
// parse exact date
return new Date(r[3], r[2] - 1, r[1]);
} else if (str) {
// parse relative date
var inc = str[2]*60*60*24*1000;
var timestamp = now.getTime();
if (str[1] == '-') {
timestamp -= inc;
} else {
timestamp += inc;
}
return new Date(timestamp);
}
return undefined;
};
angular.module('ngx.date', [])
.value('ngxDate', ngxDate);
})(window.angular);
(function(angular) {
'use strict';
var module = angular.module('ngx.dictionary', []);
/**
* Dictionary provider
*/
module.factory('ngxDictionary', function($locale) {
var dictionary = {},
currentLanguage = $locale.id.split('-')[0];
/**
* Returns items by current language
* @param key
* @param language
* @param params array of string elements for replace %s, depends on order
*/
function ngxDictionary(key, language, params) {
var string = dictionary[language ? language : currentLanguage][key];
if(params !== undefined) {
var re = /%s/;
angular.forEach(params, function(param) {
string = string.replace(re, param);
});
}
return string;
}
/**
* Sets dictionary current language
* @param language
*/
ngxDictionary.setLanguage = function(language) {
currentLanguage = language;
return this;
};
/**
* Adds items to dictionary
* @param language
* @param items
*/
ngxDictionary.addItems = function(language, items) {
if (angular.isUndefined(dictionary[language])) {
dictionary[language] = {};
}
angular.extend(dictionary[language], items);
return this;
};
return ngxDictionary;
});
})(window.angular);
(function(angular, head) {
'use strict';
var module = angular.module('ngx.loader', ['ngx.config']);
module.factory('ngxLoader', ['ngxConfig', function(ngxConfig) {
var loaded = [];
/**
* Loads external js/css files
* @param files
*/
return function(files, onload) {
var queue = {
js: [],
css: []
};
// group files to load by type
angular.forEach(typeof(files) === 'string' ? [files] : files, function(file) {
var type,
force = false;
// add base path
if (!file.match(/^(\/|http)/)) {
file = ngxConfig.basePath + file;
}
if (file.match(/\.css$/i)) {
type = 'css';
} else if (file.match(/\.js$/i)) {
type = 'js';
force = (onload ? true : false);
} else {
throw new Error('File type not supported');
}
// already loaded
if (loaded.indexOf(file) >= 0 && !force) {
return;
}
queue[type].push(file);
loaded.push(file);
});
// process queue
angular.forEach(queue, function(files, type) {
if (!files.length) {
return;
}
switch (type) {
case 'js':
// handle onload callback with head.js
if (onload) {
files.push(onload);
onload = null;
}
head.js.apply(this, files);
break;
case 'css':
angular.forEach(files, function(file) {
angular.element('head').append(angular.element('<link rel="stylesheet" type="text/css" href="' + file + '"></link>'));
});
break;
}
});
if (onload) {
onload();
}
};
}]);
})(window.angular, window.head);
(function(angular, $, window) {
'use strict';
var module = angular.module('ngx.smap', []);
module.config(function() {
// some Seznam library disables console debug mode :-/
window.console.DEBUG = true;
});
/**
* Seznam map service
*/
module.factory('ngxSmap', function() {
var SMap = window.SMap;
if (SMap === undefined) {
throw 'Seznam map API is not loaded, see http://api4.mapy.cz/view?page=instruction';
}
function NgxSmap(wrapper) {
var smap, card, markerLayer, geocoder,
self = this;
// api cache
var cache = {
coords: {},
query: {}
};
// SMap source code list
var typeList = {
'stre': 'street',
'addr': 'number',
'muni': 'city',
'dist': 'district',
'regi': 'region',
'ward': 'ward',
'coun': 'country',
'base': 'base',
'firm': 'firm'
};
// filter by source
var typeFilter = {
'street': '^ulice ',
'number': '^č\\.p\\. ',
'city': '^obec ',
'district': '^okres ',
'region': '^(kraj( Hlavní město)?|provincie) ',
'ward': '^(čtvrť|část obce) '
};
function smapCoords(coords) {
if (typeof(coords) === 'object') {
// convert into SMap.Coords
if (!coords.toWGS84) {
return SMap.Coords.fromWGS84(coords.lon !== undefined ? coords.lon : coords[0], coords.lon !== undefined ? coords.lat : coords[1]);
} else {
return coords;
}
} else if (typeof(coords) === 'string') {
coords = coords.split(',');
return smapCoords({
lat: coords[0],
lon: coords[1]
});
} else {
return undefined;
}
}
// initialize map