-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundle.js
5413 lines (4926 loc) · 252 KB
/
bundle.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
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"C:\\ksana2015\\node_modules\\ksana2015-webruntime\\downloader.js":[function(require,module,exports){
var userCancel=false;
var files=[];
var totalDownloadByte=0;
var targetPath="";
var tempPath="";
var nfile=0;
var baseurl="";
var result="";
var downloading=false;
var startDownload=function(dbid,_baseurl,_files) { //return download id
var fs = require("fs");
var path = require("path");
files=_files.split("\uffff");
if (downloading) return false; //only one session
userCancel=false;
totalDownloadByte=0;
nextFile();
downloading=true;
baseurl=_baseurl;
if (baseurl[baseurl.length-1]!='/')baseurl+='/';
targetPath=ksanagap.rootPath+dbid+'/';
tempPath=ksanagap.rootPath+".tmp/";
result="";
return true;
}
var nextFile=function() {
setTimeout(function(){
if (nfile==files.length) {
nfile++;
endDownload();
} else {
downloadFile(nfile++);
}
},100);
}
var downloadFile=function(nfile) {
var url=baseurl+files[nfile];
var tmpfilename=tempPath+files[nfile];
var mkdirp = require("./mkdirp");
var fs = require("fs");
var http = require("http");
mkdirp.sync(path.dirname(tmpfilename));
var writeStream = fs.createWriteStream(tmpfilename);
var datalength=0;
var request = http.get(url, function(response) {
response.on('data',function(chunk){
writeStream.write(chunk);
totalDownloadByte+=chunk.length;
if (userCancel) {
writeStream.end();
setTimeout(function(){nextFile();},100);
}
});
response.on("end",function() {
writeStream.end();
setTimeout(function(){nextFile();},100);
});
});
}
var cancelDownload=function() {
userCancel=true;
endDownload();
}
var verify=function() {
return true;
}
var endDownload=function() {
nfile=files.length+1;//stop
result="cancelled";
downloading=false;
if (userCancel) return;
var fs = require("fs");
var mkdirp = require("./mkdirp");
for (var i=0;i<files.length;i++) {
var targetfilename=targetPath+files[i];
var tmpfilename =tempPath+files[i];
mkdirp.sync(path.dirname(targetfilename));
fs.renameSync(tmpfilename,targetfilename);
}
if (verify()) {
result="success";
} else {
result="error";
}
}
var downloadedByte=function() {
return totalDownloadByte;
}
var doneDownload=function() {
if (nfile>files.length) return result;
else return "";
}
var downloadingFile=function() {
return nfile-1;
}
var downloader={startDownload:startDownload, downloadedByte:downloadedByte,
downloadingFile:downloadingFile, cancelDownload:cancelDownload,doneDownload:doneDownload};
module.exports=downloader;
},{"./mkdirp":"C:\\ksana2015\\node_modules\\ksana2015-webruntime\\mkdirp.js","fs":false,"http":false,"path":false}],"C:\\ksana2015\\node_modules\\ksana2015-webruntime\\html5fs.js":[function(require,module,exports){
/* emulate filesystem on html5 browser */
var get_head=function(url,field,cb){
var xhr = new XMLHttpRequest();
xhr.open("HEAD", url, true);
xhr.onreadystatechange = function() {
if (this.readyState == this.DONE) {
cb(xhr.getResponseHeader(field));
} else {
if (this.status!==200&&this.status!==206) {
cb("");
}
}
};
xhr.send();
}
var get_date=function(url,cb) {
get_head(url,"Last-Modified",function(value){
cb(value);
});
}
var get_size=function(url, cb) {
get_head(url,"Content-Length",function(value){
cb(parseInt(value));
});
};
var checkUpdate=function(url,fn,cb) {
if (!url) {
cb(false);
return;
}
get_date(url,function(d){
API.fs.root.getFile(fn, {create: false, exclusive: false}, function(fileEntry) {
fileEntry.getMetadata(function(metadata){
var localDate=Date.parse(metadata.modificationTime);
var urlDate=Date.parse(d);
cb(urlDate>localDate);
});
},function(){
cb(false);
});
});
}
var download=function(url,fn,cb,statuscb,context) {
var totalsize=0,batches=null,written=0;
var fileEntry=0, fileWriter=0;
var createBatches=function(size) {
var bytes=1024*1024, out=[];
var b=Math.floor(size / bytes);
var last=size %bytes;
for (var i=0;i<=b;i++) {
out.push(i*bytes);
}
out.push(b*bytes+last);
return out;
}
var finish=function() {
rm(fn,function(){
fileEntry.moveTo(fileEntry.filesystem.root, fn,function(){
setTimeout( cb.bind(context,false) , 0) ;
},function(e){
console.log("failed",e)
});
},this);
};
var tempfn="temp.kdb";
var batch=function(b) {
var abort=false;
var xhr = new XMLHttpRequest();
var requesturl=url+"?"+Math.random();
xhr.open('get', requesturl, true);
xhr.setRequestHeader('Range', 'bytes='+batches[b]+'-'+(batches[b+1]-1));
xhr.responseType = 'blob';
xhr.addEventListener('load', function() {
var blob=this.response;
fileEntry.createWriter(function(fileWriter) {
fileWriter.seek(fileWriter.length);
fileWriter.write(blob);
written+=blob.size;
fileWriter.onwriteend = function(e) {
if (statuscb) {
abort=statuscb.apply(context,[ fileWriter.length / totalsize,totalsize ]);
if (abort) setTimeout( cb.bind(context,false) , 0) ;
}
b++;
if (!abort) {
if (b<batches.length-1) setTimeout(batch.bind(context,b),0);
else finish();
}
};
}, console.error);
},false);
xhr.send();
}
get_size(url,function(size){
totalsize=size;
if (!size) {
if (cb) cb.apply(context,[false]);
} else {//ready to download
rm(tempfn,function(){
batches=createBatches(size);
if (statuscb) statuscb.apply(context,[ 0, totalsize ]);
API.fs.root.getFile(tempfn, {create: 1, exclusive: false}, function(_fileEntry) {
fileEntry=_fileEntry;
batch(0);
});
},this);
}
});
}
var readFile=function(filename,cb,context) {
API.fs.root.getFile(filename, {create: false, exclusive: false},function(fileEntry) {
fileEntry.file(function(file){
var reader = new FileReader();
reader.onloadend = function(e) {
if (cb) cb.call(cb,this.result);
};
reader.readAsText(file,"utf8");
});
}, console.error);
}
function createDir(rootDirEntry, folders, cb) {
// Throw out './' or '/' and move on to prevent something like '/foo/.//bar'.
if (folders[0] == '.' || folders[0] == '') {
folders = folders.slice(1);
}
rootDirEntry.getDirectory(folders[0], {create: true}, function(dirEntry) {
// Recursively add the new subfolder (if we still have another to create).
if (folders.length) {
createDir(dirEntry, folders.slice(1),cb);
} else {
cb();
}
}, cb);
};
var writeFile=function(filename,buf,cb,context){
var write=function(fileEntry){
fileEntry.createWriter(function(fileWriter) {
fileWriter.write(buf);
fileWriter.onwriteend = function(e) {
if (cb) cb.apply(cb,[buf.byteLength]);
};
}, console.error);
}
var getFile=function(filename){
API.fs.root.getFile(filename, {exclusive:true}, function(fileEntry) {
write(fileEntry);
}, function(){
API.fs.root.getFile(filename, {create:true,exclusive:true}, function(fileEntry) {
write(fileEntry);
});
});
}
var slash=filename.lastIndexOf("/");
if (slash>-1) {
createDir(API.fs.root, filename.substr(0,slash).split("/"),function(){
getFile(filename);
});
} else {
getFile(filename);
}
}
var readdir=function(cb,context) {
var dirReader = API.fs.root.createReader();
var out=[],that=this;
dirReader.readEntries(function(entries) {
if (entries.length) {
for (var i = 0, entry; entry = entries[i]; ++i) {
if (entry.isFile) {
out.push([entry.name,entry.toURL ? entry.toURL() : entry.toURI()]);
}
}
}
API.files=out;
if (cb) cb.apply(context,[out]);
}, function(){
if (cb) cb.apply(context,[null]);
});
}
var getFileURL=function(filename) {
if (!API.files ) return null;
var file= API.files.filter(function(f){return f[0]==filename});
if (file.length) return file[0][1];
}
var rm=function(filename,cb,context) {
var url=getFileURL(filename);
if (url) rmURL(url,cb,context);
else if (cb) cb.apply(context,[false]);
}
var rmURL=function(filename,cb,context) {
webkitResolveLocalFileSystemURL(filename, function(fileEntry) {
fileEntry.remove(function() {
if (cb) cb.apply(context,[true]);
}, console.error);
}, function(e){
if (cb) cb.apply(context,[false]);//no such file
});
}
function errorHandler(e) {
console.error('Error: ' +e.name+ " "+e.message);
}
var initfs=function(grantedBytes,cb,context) {
webkitRequestFileSystem(PERSISTENT, grantedBytes, function(fs) {
API.fs=fs;
API.quota=grantedBytes;
readdir(function(){
API.initialized=true;
cb.apply(context,[grantedBytes,fs]);
},context);
}, errorHandler);
}
var init=function(quota,cb,context) {
navigator.webkitPersistentStorage.requestQuota(quota,
function(grantedBytes) {
initfs(grantedBytes,cb,context);
}, errorHandler
);
}
var queryQuota=function(cb,context) {
var that=this;
navigator.webkitPersistentStorage.queryUsageAndQuota(
function(usage,quota){
initfs(quota,function(){
cb.apply(context,[usage,quota]);
},context);
});
}
var API={
init:init
,readdir:readdir
,checkUpdate:checkUpdate
,rm:rm
,rmURL:rmURL
,getFileURL:getFileURL
,writeFile:writeFile
,readFile:readFile
,download:download
,get_head:get_head
,get_date:get_date
,get_size:get_size
,getDownloadSize:get_size
,queryQuota:queryQuota
}
module.exports=API;
},{}],"C:\\ksana2015\\node_modules\\ksana2015-webruntime\\ksanagap.js":[function(require,module,exports){
var appname="installer";
if (typeof ksana=="undefined") {
window.ksana={platform:"chrome"};
if (typeof process!=="undefined" &&
process.versions && process.versions["node-webkit"]) {
window.ksana.platform="node-webkit";
}
}
var switchApp=function(path) {
var fs=require("fs");
path="../"+path;
appname=path;
document.location.href= path+"/index.html";
process.chdir(path);
}
var downloader={};
var rootPath="";
var deleteApp=function(app) {
console.error("not allow on PC, do it in File Explorer/ Finder");
}
var username=function() {
return "";
}
var useremail=function() {
return ""
}
var runtime_version=function() {
return "1.4";
}
//copy from liveupdate
var jsonp=function(url,dbid,callback,context) {
var script=document.getElementById("jsonp2");
if (script) {
script.parentNode.removeChild(script);
}
window.jsonp_handler=function(data) {
if (typeof data=="object") {
data.dbid=dbid;
callback.apply(context,[data]);
}
}
window.jsonp_error_handler=function() {
console.error("url unreachable",url);
callback.apply(context,[null]);
}
script=document.createElement('script');
script.setAttribute('id', "jsonp2");
script.setAttribute('onerror', "jsonp_error_handler()");
url=url+'?'+(new Date().getTime());
script.setAttribute('src', url);
document.getElementsByTagName('head')[0].appendChild(script);
}
var loadKsanajs=function(){
if (typeof process!="undefined" && !process.browser) {
var ksanajs=require("fs").readFileSync("./ksana.js","utf8").trim();
downloader=require("./downloader");
ksana.js=JSON.parse(ksanajs.substring(14,ksanajs.length-1));
rootPath=process.cwd();
rootPath=require("path").resolve(rootPath,"..").replace(/\\/g,"/")+'/';
ksana.ready=true;
} else{
var url=window.location.origin+window.location.pathname.replace("index.html","")+"ksana.js";
jsonp(url,appname,function(data){
ksana.js=data;
ksana.ready=true;
});
}
}
loadKsanajs();
var boot=function(appId,cb) {
if (typeof appId=="function") {
cb=appId;
appId="unknownapp";
}
if (!ksana.js && ksana.platform=="node-webkit") {
loadKsanajs();
}
ksana.appId=appId;
if (ksana.ready) {
cb();
return;
}
var timer=setInterval(function(){
if (ksana.ready){
clearInterval(timer);
cb();
}
},100);
}
var ksanagap={
platform:"node-webkit",
startDownload:downloader.startDownload,
downloadedByte:downloader.downloadedByte,
downloadingFile:downloader.downloadingFile,
cancelDownload:downloader.cancelDownload,
doneDownload:downloader.doneDownload,
switchApp:switchApp,
rootPath:rootPath,
deleteApp: deleteApp,
username:username, //not support on PC
useremail:username,
runtime_version:runtime_version,
boot:boot
}
module.exports=ksanagap;
},{"./downloader":"C:\\ksana2015\\node_modules\\ksana2015-webruntime\\downloader.js","fs":false,"path":false}],"C:\\ksana2015\\node_modules\\ksana2015-webruntime\\livereload.js":[function(require,module,exports){
var started=false;
var timer=null;
var bundledate=null;
var get_date=require("./html5fs").get_date;
var checkIfBundleUpdated=function() {
get_date("bundle.js",function(date){
if (bundledate &&bundledate!=date){
location.reload();
}
bundledate=date;
});
}
var livereload=function() {
if(window.location.origin.indexOf("//127.0.0.1")===-1) return;
if (started) return;
timer1=setInterval(function(){
checkIfBundleUpdated();
},2000);
started=true;
}
module.exports=livereload;
},{"./html5fs":"C:\\ksana2015\\node_modules\\ksana2015-webruntime\\html5fs.js"}],"C:\\ksana2015\\node_modules\\ksana2015-webruntime\\mkdirp.js":[function(require,module,exports){
function mkdirP (p, mode, f, made) {
var path = nodeRequire('path');
var fs = nodeRequire('fs');
if (typeof mode === 'function' || mode === undefined) {
f = mode;
mode = 0x1FF & (~process.umask());
}
if (!made) made = null;
var cb = f || function () {};
if (typeof mode === 'string') mode = parseInt(mode, 8);
p = path.resolve(p);
fs.mkdir(p, mode, function (er) {
if (!er) {
made = made || p;
return cb(null, made);
}
switch (er.code) {
case 'ENOENT':
mkdirP(path.dirname(p), mode, function (er, made) {
if (er) cb(er, made);
else mkdirP(p, mode, cb, made);
});
break;
// In the case of any other error, just see if there's a dir
// there already. If so, then hooray! If not, then something
// is borked.
default:
fs.stat(p, function (er2, stat) {
// if the stat fails, then that's super weird.
// let the original error be the failure reason.
if (er2 || !stat.isDirectory()) cb(er, made)
else cb(null, made);
});
break;
}
});
}
mkdirP.sync = function sync (p, mode, made) {
var path = nodeRequire('path');
var fs = nodeRequire('fs');
if (mode === undefined) {
mode = 0x1FF & (~process.umask());
}
if (!made) made = null;
if (typeof mode === 'string') mode = parseInt(mode, 8);
p = path.resolve(p);
try {
fs.mkdirSync(p, mode);
made = made || p;
}
catch (err0) {
switch (err0.code) {
case 'ENOENT' :
made = sync(path.dirname(p), mode, made);
sync(p, mode, made);
break;
// In the case of any other error, just see if there's a dir
// there already. If so, then hooray! If not, then something
// is borked.
default:
var stat;
try {
stat = fs.statSync(p);
}
catch (err1) {
throw err0;
}
if (!stat.isDirectory()) throw err0;
break;
}
}
return made;
};
module.exports = mkdirP.mkdirp = mkdirP.mkdirP = mkdirP;
},{}],"C:\\ksana2015\\node_modules\\reflux\\index.js":[function(require,module,exports){
module.exports = require('./src');
},{"./src":"C:\\ksana2015\\node_modules\\reflux\\src\\index.js"}],"C:\\ksana2015\\node_modules\\reflux\\node_modules\\eventemitter3\\index.js":[function(require,module,exports){
'use strict';
/**
* Representation of a single EventEmitter function.
*
* @param {Function} fn Event handler to be called.
* @param {Mixed} context Context for function execution.
* @param {Boolean} once Only emit once
* @api private
*/
function EE(fn, context, once) {
this.fn = fn;
this.context = context;
this.once = once || false;
}
/**
* Minimal EventEmitter interface that is molded against the Node.js
* EventEmitter interface.
*
* @constructor
* @api public
*/
function EventEmitter() { /* Nothing to set */ }
/**
* Holds the assigned EventEmitters by name.
*
* @type {Object}
* @private
*/
EventEmitter.prototype._events = undefined;
/**
* Return a list of assigned event listeners.
*
* @param {String} event The events that should be listed.
* @returns {Array}
* @api public
*/
EventEmitter.prototype.listeners = function listeners(event) {
if (!this._events || !this._events[event]) return [];
if (this._events[event].fn) return [this._events[event].fn];
for (var i = 0, l = this._events[event].length, ee = new Array(l); i < l; i++) {
ee[i] = this._events[event][i].fn;
}
return ee;
};
/**
* Emit an event to all registered event listeners.
*
* @param {String} event The name of the event.
* @returns {Boolean} Indication if we've emitted an event.
* @api public
*/
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
if (!this._events || !this._events[event]) return false;
var listeners = this._events[event]
, len = arguments.length
, args
, i;
if ('function' === typeof listeners.fn) {
if (listeners.once) this.removeListener(event, listeners.fn, true);
switch (len) {
case 1: return listeners.fn.call(listeners.context), true;
case 2: return listeners.fn.call(listeners.context, a1), true;
case 3: return listeners.fn.call(listeners.context, a1, a2), true;
case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
}
for (i = 1, args = new Array(len -1); i < len; i++) {
args[i - 1] = arguments[i];
}
listeners.fn.apply(listeners.context, args);
} else {
var length = listeners.length
, j;
for (i = 0; i < length; i++) {
if (listeners[i].once) this.removeListener(event, listeners[i].fn, true);
switch (len) {
case 1: listeners[i].fn.call(listeners[i].context); break;
case 2: listeners[i].fn.call(listeners[i].context, a1); break;
case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
default:
if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
args[j - 1] = arguments[j];
}
listeners[i].fn.apply(listeners[i].context, args);
}
}
}
return true;
};
/**
* Register a new EventListener for the given event.
*
* @param {String} event Name of the event.
* @param {Functon} fn Callback function.
* @param {Mixed} context The context of the function.
* @api public
*/
EventEmitter.prototype.on = function on(event, fn, context) {
var listener = new EE(fn, context || this);
if (!this._events) this._events = {};
if (!this._events[event]) this._events[event] = listener;
else {
if (!this._events[event].fn) this._events[event].push(listener);
else this._events[event] = [
this._events[event], listener
];
}
return this;
};
/**
* Add an EventListener that's only called once.
*
* @param {String} event Name of the event.
* @param {Function} fn Callback function.
* @param {Mixed} context The context of the function.
* @api public
*/
EventEmitter.prototype.once = function once(event, fn, context) {
var listener = new EE(fn, context || this, true);
if (!this._events) this._events = {};
if (!this._events[event]) this._events[event] = listener;
else {
if (!this._events[event].fn) this._events[event].push(listener);
else this._events[event] = [
this._events[event], listener
];
}
return this;
};
/**
* Remove event listeners.
*
* @param {String} event The event we want to remove.
* @param {Function} fn The listener that we need to find.
* @param {Boolean} once Only remove once listeners.
* @api public
*/
EventEmitter.prototype.removeListener = function removeListener(event, fn, once) {
if (!this._events || !this._events[event]) return this;
var listeners = this._events[event]
, events = [];
if (fn) {
if (listeners.fn && (listeners.fn !== fn || (once && !listeners.once))) {
events.push(listeners);
}
if (!listeners.fn) for (var i = 0, length = listeners.length; i < length; i++) {
if (listeners[i].fn !== fn || (once && !listeners[i].once)) {
events.push(listeners[i]);
}
}
}
//
// Reset the array, or remove it completely if we have no more listeners.
//
if (events.length) {
this._events[event] = events.length === 1 ? events[0] : events;
} else {
delete this._events[event];
}
return this;
};
/**
* Remove all listeners or only the listeners for the specified event.
*
* @param {String} event The event want to remove all listeners for.
* @api public
*/
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
if (!this._events) return this;
if (event) delete this._events[event];
else this._events = {};
return this;
};
//
// Alias methods names because people roll like that.
//
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
//
// This function doesn't apply anymore.
//
EventEmitter.prototype.setMaxListeners = function setMaxListeners() {
return this;
};
//
// Expose the module.
//
EventEmitter.EventEmitter = EventEmitter;
EventEmitter.EventEmitter2 = EventEmitter;
EventEmitter.EventEmitter3 = EventEmitter;
//
// Expose the module.
//
module.exports = EventEmitter;
},{}],"C:\\ksana2015\\node_modules\\reflux\\node_modules\\native-promise-only\\npo.js":[function(require,module,exports){
/*! Native Promise Only
v0.7.6-a (c) Kyle Simpson
MIT License: http://getify.mit-license.org
*/
!function(t,n,e){n[t]=n[t]||e(),"undefined"!=typeof module&&module.exports?module.exports=n[t]:"function"==typeof define&&define.amd&&define(function(){return n[t]})}("Promise","undefined"!=typeof global?global:this,function(){"use strict";function t(t,n){l.add(t,n),h||(h=y(l.drain))}function n(t){var n,e=typeof t;return null==t||"object"!=e&&"function"!=e||(n=t.then),"function"==typeof n?n:!1}function e(){for(var t=0;t<this.chain.length;t++)o(this,1===this.state?this.chain[t].success:this.chain[t].failure,this.chain[t]);this.chain.length=0}function o(t,e,o){var r,i;try{e===!1?o.reject(t.msg):(r=e===!0?t.msg:e.call(void 0,t.msg),r===o.promise?o.reject(TypeError("Promise-chain cycle")):(i=n(r))?i.call(r,o.resolve,o.reject):o.resolve(r))}catch(c){o.reject(c)}}function r(o){var c,u,a=this;if(!a.triggered){a.triggered=!0,a.def&&(a=a.def);try{(c=n(o))?(u=new f(a),c.call(o,function(){r.apply(u,arguments)},function(){i.apply(u,arguments)})):(a.msg=o,a.state=1,a.chain.length>0&&t(e,a))}catch(s){i.call(u||new f(a),s)}}}function i(n){var o=this;o.triggered||(o.triggered=!0,o.def&&(o=o.def),o.msg=n,o.state=2,o.chain.length>0&&t(e,o))}function c(t,n,e,o){for(var r=0;r<n.length;r++)!function(r){t.resolve(n[r]).then(function(t){e(r,t)},o)}(r)}function f(t){this.def=t,this.triggered=!1}function u(t){this.promise=t,this.state=0,this.triggered=!1,this.chain=[],this.msg=void 0}function a(n){if("function"!=typeof n)throw TypeError("Not a function");if(0!==this.__NPO__)throw TypeError("Not a promise");this.__NPO__=1;var o=new u(this);this.then=function(n,r){var i={success:"function"==typeof n?n:!0,failure:"function"==typeof r?r:!1};return i.promise=new this.constructor(function(t,n){if("function"!=typeof t||"function"!=typeof n)throw TypeError("Not a function");i.resolve=t,i.reject=n}),o.chain.push(i),0!==o.state&&t(e,o),i.promise},this["catch"]=function(t){return this.then(void 0,t)};try{n.call(void 0,function(t){r.call(o,t)},function(t){i.call(o,t)})}catch(c){i.call(o,c)}}var s,h,l,p=Object.prototype.toString,y="undefined"!=typeof setImmediate?function(t){return setImmediate(t)}:setTimeout;try{Object.defineProperty({},"x",{}),s=function(t,n,e,o){return Object.defineProperty(t,n,{value:e,writable:!0,configurable:o!==!1})}}catch(d){s=function(t,n,e){return t[n]=e,t}}l=function(){function t(t,n){this.fn=t,this.self=n,this.next=void 0}var n,e,o;return{add:function(r,i){o=new t(r,i),e?e.next=o:n=o,e=o,o=void 0},drain:function(){var t=n;for(n=e=h=void 0;t;)t.fn.call(t.self),t=t.next}}}();var g=s({},"constructor",a,!1);return s(a,"prototype",g,!1),s(g,"__NPO__",0,!1),s(a,"resolve",function(t){var n=this;return t&&"object"==typeof t&&1===t.__NPO__?t:new n(function(n,e){if("function"!=typeof n||"function"!=typeof e)throw TypeError("Not a function");n(t)})}),s(a,"reject",function(t){return new this(function(n,e){if("function"!=typeof n||"function"!=typeof e)throw TypeError("Not a function");e(t)})}),s(a,"all",function(t){var n=this;return"[object Array]"!=p.call(t)?n.reject(TypeError("Not an array")):0===t.length?n.resolve([]):new n(function(e,o){if("function"!=typeof e||"function"!=typeof o)throw TypeError("Not a function");var r=t.length,i=Array(r),f=0;c(n,t,function(t,n){i[t]=n,++f===r&&e(i)},o)})}),s(a,"race",function(t){var n=this;return"[object Array]"!=p.call(t)?n.reject(TypeError("Not an array")):new n(function(e,o){if("function"!=typeof e||"function"!=typeof o)throw TypeError("Not a function");c(n,t,function(t,n){e(n)},o)})}),a});
},{}],"C:\\ksana2015\\node_modules\\reflux\\src\\ActionMethods.js":[function(require,module,exports){
/**
* A module of methods that you want to include in all actions.
* This module is consumed by `createAction`.
*/
module.exports = {
};
},{}],"C:\\ksana2015\\node_modules\\reflux\\src\\Keep.js":[function(require,module,exports){
exports.createdStores = [];
exports.createdActions = [];
exports.reset = function() {
while(exports.createdStores.length) {
exports.createdStores.pop();
}
while(exports.createdActions.length) {
exports.createdActions.pop();
}
};
},{}],"C:\\ksana2015\\node_modules\\reflux\\src\\ListenerMethods.js":[function(require,module,exports){
var _ = require('./utils'),
maker = require('./joins').instanceJoinCreator;
/**
* Extract child listenables from a parent from their
* children property and return them in a keyed Object
*
* @param {Object} listenable The parent listenable
*/
var mapChildListenables = function(listenable) {
var i = 0, children = {}, childName;
for (;i < (listenable.children||[]).length; ++i) {
childName = listenable.children[i];
if(listenable[childName]){
children[childName] = listenable[childName];
}
}
return children;
};
/**
* Make a flat dictionary of all listenables including their
* possible children (recursively), concatenating names in camelCase.
*
* @param {Object} listenables The top-level listenables
*/
var flattenListenables = function(listenables) {
var flattened = {};
for(var key in listenables){
var listenable = listenables[key];
var childMap = mapChildListenables(listenable);
// recursively flatten children
var children = flattenListenables(childMap);
// add the primary listenable and chilren
flattened[key] = listenable;
for(var childKey in children){
var childListenable = children[childKey];
flattened[key + _.capitalize(childKey)] = childListenable;
}
}
return flattened;
};
/**
* A module of methods related to listening.
*/
module.exports = {
/**
* An internal utility function used by `validateListening`
*
* @param {Action|Store} listenable The listenable we want to search for
* @returns {Boolean} The result of a recursive search among `this.subscriptions`
*/
hasListener: function(listenable) {
var i = 0, j, listener, listenables;
for (;i < (this.subscriptions||[]).length; ++i) {
listenables = [].concat(this.subscriptions[i].listenable);
for (j = 0; j < listenables.length; j++){
listener = listenables[j];
if (listener === listenable || listener.hasListener && listener.hasListener(listenable)) {
return true;
}
}
}
return false;
},
/**
* A convenience method that listens to all listenables in the given object.
*
* @param {Object} listenables An object of listenables. Keys will be used as callback method names.
*/
listenToMany: function(listenables){
var allListenables = flattenListenables(listenables);
for(var key in allListenables){
var cbname = _.callbackName(key),
localname = this[cbname] ? cbname : this[key] ? key : undefined;
if (localname){
this.listenTo(allListenables[key],localname,this[cbname+"Default"]||this[localname+"Default"]||localname);
}
}
},
/**
* Checks if the current context can listen to the supplied listenable
*
* @param {Action|Store} listenable An Action or Store that should be
* listened to.
* @returns {String|Undefined} An error message, or undefined if there was no problem.
*/
validateListening: function(listenable){
if (listenable === this) {
return "Listener is not able to listen to itself";
}
if (!_.isFunction(listenable.listen)) {
return listenable + " is missing a listen method";
}
if (listenable.hasListener && listenable.hasListener(this)) {
return "Listener cannot listen to this listenable because of circular loop";
}
},
/**
* Sets up a subscription to the given listenable for the context object
*
* @param {Action|Store} listenable An Action or Store that should be
* listened to.
* @param {Function|String} callback The callback to register as event handler
* @param {Function|String} defaultCallback The callback to register as default handler
* @returns {Object} A subscription obj where `stop` is an unsub function and `listenable` is the object being listened to
*/
listenTo: function(listenable, callback, defaultCallback) {
var desub, unsubscriber, subscriptionobj, subs = this.subscriptions = this.subscriptions || [];
_.throwIf(this.validateListening(listenable));
this.fetchInitialState(listenable, defaultCallback);
desub = listenable.listen(this[callback]||callback, this);
unsubscriber = function() {
var index = subs.indexOf(subscriptionobj);
_.throwIf(index === -1,'Tried to remove listen already gone from subscriptions list!');
subs.splice(index, 1);
desub();
};
subscriptionobj = {
stop: unsubscriber,
listenable: listenable
};
subs.push(subscriptionobj);
return subscriptionobj;
},
/**
* Stops listening to a single listenable
*
* @param {Action|Store} listenable The action or store we no longer want to listen to
* @returns {Boolean} True if a subscription was found and removed, otherwise false.
*/
stopListeningTo: function(listenable){
var sub, i = 0, subs = this.subscriptions || [];
for(;i < subs.length; i++){
sub = subs[i];
if (sub.listenable === listenable){
sub.stop();
_.throwIf(subs.indexOf(sub)!==-1,'Failed to remove listen from subscriptions list!');