1/**
2 * Created by iamchenxin on 2015/3/14.
3 */
4/*
5 http://stackoverflow.com/questions/1038746/equivalent-of-string-format-in-jquery
6 */
7String.prototype.format = function () {
8    var args = arguments;
9    return this.replace(/\{(\d+)\}/g, function (m, n) { return args[n]; });
10};
11var WORDLIST_NAME = "user:admin:wordlist";
12
13//----------------------
14
15
16
17
18//Complement (set theory) ,conjuction
19function wComplement_w(main_sortlist,filter_words){
20
21    var main_map=make_map_w(main_sortlist);
22    var filt_sortlist=make_unique_list(filter_words);
23
24    var i=0;
25
26    for(;i<filt_sortlist.length;i++){
27        if(main_map[filt_sortlist[i]]!=null){ // exist both
28            delete main_map[filt_sortlist[i]]; //subtract the both in main_map
29
30        }
31    }
32
33    var words_out_list=[];
34    for (var x in main_map){
35        words_out_list.push(x);
36    }
37
38    return words_out_list; //the remaining is complement
39}
40
41function wIntersection_w(sortlistone,sortlisttwo){
42
43    var main_map = make_map_w(sortlistone);
44    var filt_sortlist=make_unique_list(sortlisttwo);
45
46    var intersect_list=[];
47    var i=0;
48    for(;i<filt_sortlist.length;i++){
49        if(main_map[filt_sortlist[i]]!=null){ // exist both
50            intersect_list[intersect_list.length]=filt_sortlist[i]; //store the same word
51        }
52    }
53    return intersect_list;
54}
55
56function wUnion_w(listone,listtwo){
57    var list_all =listone.concat(listtwo);
58    list_all.sort();
59    return make_unique_list(list_all);
60
61}
62
63function make_unique_list(ordered_list){
64    var i=1;
65    var count=1;
66    var unique_list=[];
67    var regx =new RegExp(/[^a-zA-Z]/);
68    //  count every word
69    for(;i<ordered_list.length;i++){
70        if(regx.test(ordered_list[i-1])!=true) {  //ignore number and symbol
71            if (ordered_list[i] != ordered_list[i - 1]) {
72                unique_list.push( ordered_list[i - 1] );
73                count = 1;
74            } else {
75                count += 1;
76            }
77        }
78    }
79    if(ordered_list[ordered_list.length - 1] != ordered_list[ordered_list.length - 2]){  // push the last def word
80        unique_list.push(ordered_list[ordered_list.length - 1]);
81    }
82    return unique_list;
83}
84// this function
85function make_map_w(ordered_list){  // make set ,and count the same words
86    var i=1;
87    var count=1;
88    var tx_countset={};
89    var regx =new RegExp("[^a-zA-Z]");
90    // count every word
91    for(;i<ordered_list.length;i++){
92        if(regx.test(ordered_list[i-1])!=true) {  //ignore number and symbol
93            if (ordered_list[i] != ordered_list[i - 1]) {
94                tx_countset[ordered_list[i - 1]] = count;
95                count = 1;
96            } else {
97                count += 1;
98            }
99        }
100    }
101    if(ordered_list[ordered_list.length - 1] != ordered_list[ordered_list.length - 2]){  // the last def word
102        tx_countset[ordered_list[ordered_list.length - 1]]=1;
103    }
104    return tx_countset;
105}
106// -----------------math2----------------------------
107
108function make_set(w_list){
109    var w_set={};
110    for(var i=0;i<w_list.length;i++){
111        if(w_set[w_list[i]]){
112            w_set[w_list[i]]+=1;
113        }else {
114            w_set[w_list[i]] = 1;
115        }
116    }
117    return w_set;
118}
119
120//--------------UI---------------------
121
122
123function tsshow(event){
124    event.data.fuc.call(event.data.obj);
125}
126
127
128
129
130
131/*
132var params={
133    top:
134    left:
135    width:
136    height:
137    subclass:
138    draggable:
139};
140*/
141function PTwindow(param_obj){
142
143    this.top=PTwindow.MakeDimen({value:param_obj.top ,default_v:"2%"});
144    this.left=PTwindow.MakeDimen({value:param_obj.left ,default_v:"2%"});
145    this.width=PTwindow.MakeDimen({value:param_obj.width ,default_v:"auto"});
146    this.height=PTwindow.MakeDimen({value:param_obj.height ,default_v:"auto"});
147    this.subclass=param_obj.subclass;
148    this.draggable=(param_obj.draggable!=undefined)?param_obj.draggable:true;
149    this.winid=param_obj.winid;
150
151    var divstr='<div class="pt_window {0}" id="{0}{1}" winid="{1}" ><div class="pt_clientwin"></div> <div style="clear: both"></div>\
152        <input name="close" class="pt_button_r ptclose" type="button" value="close"> </div> '.format(this.subclass,this.winid);
153    this.jqwin=jQuery(divstr);
154    jQuery('body').append(this.jqwin);
155    if(this.draggable){
156        this.jqwin.draggable();
157    }
158    this.jqwin.children("input[name='close']").click(function(){
159        jQuery(this).parent().slideUp(500);
160    });
161
162    if(jQuery("html").hasClass("phone")){
163        this.jqwin.css("width","100%");
164        this.jqwin.css("height",this.height);
165        this.jqwin.css("top",this.top);
166        this.jqwin.css("left","0%");
167    }else{
168        this.jqwin.css("width",this.width);
169        this.jqwin.css("height",this.height);
170        this.jqwin.css("top",this.top);
171        this.jqwin.css("left",this.left);
172    }
173}
174/*var param_obj_MakeDimen={
175 deft:1, //"default data",
176 value:0 //""
177 };*/
178PTwindow.MakeDimen=function(param_obj){
179
180    var deft=(param_obj.default_v!=undefined)?param_obj.default_v:"auto";
181    var outv = param_obj.value;
182    if(outv==null){
183        outv=deft;
184    }else{
185        if(outv.charAt(outv.length-1)!="%" ){
186            outv=outv+"px";
187        }
188    }
189    return outv;
190};
191PTwindow.Extract_ptparams=function(jwin){
192
193    var arg_txt=jwin.attr("pt_arg");
194    var out_params={};
195    if(arg_txt){
196        var arg_list=arg_txt.split(";");
197
198        for(var i=0;i<arg_list.length;i++){
199            var sub_arg=arg_list[i].split("=");
200            if(sub_arg.length>=2){
201                out_params[sub_arg[0].trim()]=sub_arg[1];
202            }else{
203                out_params["BAD"]=arg_list[i];
204            }
205        }
206    }
207
208    var winid=jwin.attr("id");
209    if(winid){
210        out_params.winid=winid;
211    }else{
212        throw "the dom who open ptwindow must has a id!";
213    }
214    return out_params;
215};
216PTwindow.ptw_list={};
217PTwindow.Factory=function(window_type,params_obj){
218    var winid= params_obj.winid;
219    if(winid==null){
220        throw "winid should not null!";
221    }
222    if(!PTwindow.GetObj(winid)){
223        PTwindow.ptw_list[winid]=new window_type(params_obj);
224    }
225    return PTwindow.ptw_list[winid];
226};
227PTwindow.Factory_byElement=function(window_type,element) {
228    var factory_win = jQuery(element);
229    var winid=factory_win.attr("id");
230    if(!PTwindow.GetObj(winid)){
231        var params = PTwindow.Extract_ptparams(factory_win);
232        PTwindow.Factory(window_type,params);
233    }
234
235    return PTwindow.ptw_list[winid];
236};
237
238PTwindow.GetObj=function(winid){
239    return PTwindow.ptw_list[winid];
240};
241
242
243
244PTwindow.prototype.get_closebt=function(){return this.jqwin.children(".ptclose");};
245PTwindow.prototype.getwin=function(){return this.jqwin;};
246PTwindow.prototype.getwinid=function(){return this.jqwin.attr("winid");};
247PTwindow.prototype.getclientwin=function(){return this.jqwin.children(".pt_clientwin");};
248PTwindow.prototype.show=function(speed){
249    if(speed!=true){speed=500;}
250
251    this.jqwin.slideDown(speed);
252};
253PTwindow.prototype.clickby= function(trigger){
254    jQuery(trigger).click({"obj":this,"fuc":this.show},tsshow);
255};
256PTwindow.prototype.gain_wlistarray=function(wordlists_txt){
257    var warr = wordlists_txt.split(",");
258    var outarr=[];
259    for(var i=0;i<warr.length;i++){
260        var wtmp=warr[i].trim();
261        if(wtmp){
262            outarr.push(wtmp);
263        }
264    }
265    return outarr;
266};
267
268PTwindow.prototype.ctwinScrollDown=function(){
269    this.getclientwin().scrollTop(this.getclientwin()[0].scrollHeight);
270};
271PTwindow.prototype.heightlight=function(class_name){
272    var thecl=this.getwin().find(class_name);
273    if(this.pre_heightlight){
274        var cl_list=this.pre_heightlight.attr("class").split(" ");
275        var new_list=[];
276        for(var i=0;i<cl_list.length;i++){
277            if(cl_list[i].trim()!="pt_heightlight"){
278                new_list.push(cl_list[i]);
279            }
280        }
281
282        this.pre_heightlight.attr("class",new_list.join(" "));
283
284    }
285    this.pre_heightlight=thecl;
286
287    thecl.attr("class",thecl.attr("class")+" pt_heightlight");
288
289};
290
291// ----------------------------log ---win ----------------
292function PTlog(){
293    PTwindow.call(this,{winid:"xxxptlog",subclass:"cccptlog",width:"auto",height:"auto"});
294
295    this.getwin().css({
296        position:"fixed",
297        top:"",
298        left:"",
299        bottom:"8px",
300        right:"8px"
301    });
302    this.getclientwin().css({
303        "overflow-y": "auto"
304    });
305
306}
307PTlog.prototype=Object.create(PTwindow.prototype);
308
309PTlog.prototype.log=function(txt){
310    this.getclientwin().html(txt);
311    this.getwin().stop().fadeIn(300).fadeTo(5000,0.5).slideUp(500);
312};
313PTlog.prototype.loga=function(txt){
314    var out_txt =this.getclientwin().html()+txt;
315    this.log(out_txt);
316};
317
318var ptlog;
319
320// ==============
321
322// ------------- english ---special
323function helper_build_opt(prefix,arr){
324    var opts="";
325    for(var i=0;i<arr.length;i++){
326        opts+='<option value="{0}">{1}</option>'.format(arr[i],prefix+arr[i]);
327    }
328    return opts;
329}
330
331function PTwindow_E(param_obj){
332    if(param_obj.subclass==null){
333        param_obj.subclass="PTwindow_E";
334    }
335    PTwindow.call(this,param_obj);
336
337    var g_pre="user:admin:";
338    this.g_wordlists=this.gain_wlistarray(JSINFO['g_wordlists']);
339    this.default_wordlist=g_pre+this.g_wordlists[0];
340    this.g_wordlist_select='<select class="g_w_selct" name="g_w_selct">{0}</select>'.format(helper_build_opt(g_pre,this.g_wordlists));
341
342    var u_pre = "user:{0}:".format(JSINFO['user']);
343    this.u_wordlists=this.gain_wlistarray(JSINFO['user_wordlists']);
344    this.u_wordlist_select='<select class="u_w_selct" name="u_w_selct">{0}\
345    </select>'.format('<option value="none">none</option>'+helper_build_opt(u_pre,this.u_wordlists));
346}
347PTwindow_E.prototype=Object.create( PTwindow.prototype);
348
349
350function helper_pe_gselect(jq_ob){
351    var g_wordlist = jq_ob.find("select.g_w_selct option:selected").html();
352    var u_wordlist = jq_ob.find("select.u_w_selct option:selected").html();
353    var outob={global:g_wordlist,user:u_wordlist};
354    return outob;
355}
356PTwindow_E.prototype.get_select_wordlist=function(){
357    var g_wordlist = this.getwin().find("select.g_w_selct option:selected").html();
358    var u_wordlist = this.getwin().find("select.u_w_selct option:selected").html();
359    var outob={global:g_wordlist,user:u_wordlist};
360    return outob;
361};
362PTwindow_E.prototype.ajax_get_select_wlist= function (xcallback){
363    var jqwin =this.getwin();
364    var sel_arr = this.get_select_wordlist();
365    var request_arr=[];
366    if(sel_arr.global){
367        request_arr.push({jsonrpc:"2.0",method:"ps.get_wordlist",params:[sel_arr.global],id: "global"});
368    }else{
369        return xcallback(null); // global wordlist must be exsit ! or die
370    }
371    if((sel_arr.user==true)&&(sel_arr.user!="none" )){
372        request_arr.push({jsonrpc:"2.0",method:"ps.get_wordlist",params:[sel_arr.user],id: "user"});
373    }
374    var xcall = xcallback;
375    ajax_batchcall(request_arr,function(data){
376        var ob_sel={global:null,user:null};
377        var re_arr=data;
378        for(var i=0;i<re_arr.length;i++){
379            switch (re_arr[i].id){
380                case "global":
381                    ob_sel.global=re_arr[i].result;
382                    break;
383                case "user":
384                    ob_sel.user=re_arr[i].result;
385                    break;
386            }
387        }
388        xcall(ob_sel);
389    });
390
391};
392
393PTwindow_E.prototype.ajax_get_defs_raw=function(words_arr,status,xcallback){
394    if(!status){status="MORE";}
395    ajax_xcall("ps.get_defs",[words_arr,status],function(data) {
396
397           var defs=data.result;
398           xcallback(defs);
399
400
401    });
402};
403
404function PTE_Olist_sbl(indent){
405    var out_txt="";
406    for(var i=0;i<indent;i++){
407        out_txt+="  ";
408    }
409    out_txt+="- ";
410    return out_txt;
411}
412function PTE_Ulist_sbl(indent){
413    var out_txt="";
414    for(var i=0;i<indent;i++){
415        out_txt+="  ";
416    }
417    out_txt+="* ";
418    return out_txt;
419}
420function PTE_make_voice(word){
421    return "<wrap vo>{0}</wrap>".format(word);
422}
423
424PTwindow_E.prototype.generate_def_more=function(word_def) {
425    var indent = 1;
426    var out_txt = "";
427
428
429    var word = word_def[0];
430    var pron = word_def[1];
431    var defsimp = word_def[2];
432    var defen_txt = word_def[3];
433    out_txt += "{0}{1} ({2}) \\\\ **{3}**\n".format(PTE_Olist_sbl(indent), PTE_make_voice(word), pron,defsimp);
434    indent++;
435//    out_txt += "{0}{1}\n".format(PTE_Ulist_sbl(indent), defsimp);
436    if (defen_txt) {
437        var defen=JSON.parse(defen_txt);
438        for (var key in defen) {
439            out_txt += "{0}{1}\n".format(PTE_Ulist_sbl(indent), key);
440            var subdefs = defen[key];
441            indent++;
442            for (var i = 0; i < subdefs.length; i++) {
443                var sdef = subdefs[i];
444                out_txt += "{0}''{1}''\\\\ {2}\n".format(PTE_Olist_sbl(indent), sdef.mean, sdef.sen);
445            }
446            indent--;
447        }
448    }
449    indent--;
450    return out_txt;
451};
452
453PTwindow_E.prototype.ajax_get_defs=function(words_arr,status,xcallback){
454    if(!status){status="MORE";}
455    var call_ob=this;
456    this.ajax_get_defs_raw(words_arr,status,function(defs){
457
458
459           var defs_map={};
460           for(var i=0;i<defs.length;i++){
461               defs_map[defs[i][0]]=defs[i];
462           }
463
464           var out_txt="";
465
466           for(i=0;i<words_arr.length;i++){
467               var word_def=defs_map[words_arr[i]];
468               if(word_def) {
469                   out_txt += call_ob.generate_def_more(word_def);
470               }else{
471                   out_txt += "  - {0} : !!!!!NO DEF!!!!!\n".format(words_arr[i]);
472               }
473           }
474           xcallback(out_txt);
475
476    });
477};
478
479
480
481// <<<<<<<<-------------------------
482
483// ---------------------Editwindow----------------
484function Editwindow(param_obj){
485    param_obj.subclass=param_obj.subclass?param_obj.subclass:"Editwindow";
486    PTwindow.call(this,param_obj);
487
488    var workdiv =jQuery('<div class="pt_edit_static"></div><textarea class="pt_edit_area" name="pt_edit" class="edit"></textarea> <div style="clear: both"></div>');
489    this.getclientwin().append(workdiv);
490}
491Editwindow.prototype=Object.create( PTwindow.prototype);
492
493
494Editwindow.prototype.get_edit_static=function(){
495    return this.getclientwin().children(".pt_edit_static");
496};
497
498Editwindow.prototype.get_edit_area=function(){
499    return this.getclientwin().children(".pt_edit_area");
500};
501// <<<<<<<<<<<--------Editwindow-----------------------------
502
503
504// ---------------------MulEditwindow----------------
505/*
506 param_obj.rt_win;
507* */
508function MulEditwindow(param_obj){
509    param_obj.subclass=param_obj.subclass?param_obj.subclass:"MulEditwindow";
510    PTwindow_E.call(this,param_obj);
511    this.edit_array=param_obj.rt_win;
512
513    var edit_array =this.edit_array;
514    var outtxt="";
515    for(var i=0;i<edit_array.length;i++){
516        var medit=edit_array[i];
517        var height = medit.height?medit.height:"auto";
518        var width = medit.width?medit.width:"auto";
519        var mfloat = medit.float?medit.float:"right";
520        var display = medit.display?medit.display:"block";
521
522        switch (medit.type){
523            case "static":
524                outtxt+='<div class="pt_mul_edit pt_edit_static {0}" style="height: {1};width: {2};display: {3}">\
525                </div>'.format(medit.nclass,height,width,display);
526                break;
527            case "area":
528                outtxt+='<textarea class="{0} pt_mul_edit pt_edit_area" name="{0}" style="height: {1};width: {2};display: {3}"></textarea>'.format(medit.nclass,height,width,display);
529                break;
530            case "button":
531                outtxt+='<input name="{0}" class="{0} button" type="button" value="{1}" style="float: {2};display: {3}">'.format(medit.nclass,medit.value,mfloat,display);
532                break;
533            case "wd_select":
534                outtxt+='<span>global word list: </span>'+this.g_wordlist_select+
535                '<span> your word list: </span>'+this.u_wordlist_select;
536                break;
537        }
538    }
539
540    outtxt+='<div class="pt_mul_edit pt_edit_static pt_edit_log" style="height: auto;width: 98%;display: block">';
541    outtxt+='<div style="clear: both"></div>';
542    var workdiv =jQuery(outtxt);
543    this.getclientwin().append(workdiv);
544}
545MulEditwindow.prototype=Object.create( PTwindow_E.prototype);
546
547
548MulEditwindow.prototype.ptlog=function(str){
549    var logblock= this.getwin().find(".pt_edit_log");
550    logblock.html(logblock.html()+str);
551};
552
553MulEditwindow.prototype.check_word=function(words_arr,out_jqwin,mcall_back){
554    var call_ob=this;
555    var call_back=mcall_back;
556    ajax_xcall("ps.check_word",[words_arr],function(data){
557
558        var headwords=data.result["headwords"];
559        var rwords=data.result["rwords"];
560        var unwords=data.result["unwords"];
561        if(headwords) {
562            var out_str = "[headwords]:\n" + headwords.join(",  ") + "\n";
563        }
564
565        if(rwords) {
566            var rstr = [];
567            var rw_ob = {};
568            for (var i = 0; i < rwords.length; i++) {
569                if (rw_ob[rwords[i][1]] != null) {
570                    rw_ob[rwords[i][1]] += ", " + rwords[i][0];
571                } else {
572                    rw_ob[rwords[i][1]] = rwords[i][0];
573                }
574            }
575            for (var key in rw_ob) {
576                rstr.push("  {0} ({1})".format(key, rw_ob[key]));
577            }
578            out_str += "\n[rwords]:\n" + rstr.join(",  ") + "\n";
579        }
580        if(unwords) {
581            out_str += "\n[unwords]:\n" + unwords.join(",  ") + "\n";
582        }
583        out_jqwin.val(out_str);
584        var out_log="headwords = {0} ,related words = {1} ,unwords(like location,name,etc..) = {2} <br/>".format(headwords.length,rstr.length,unwords.length);
585        call_ob.ptlog(out_log);
586        if(call_back){
587            call_back();
588        }
589    });
590};
591
592MulEditwindow.prototype.get_full_wordinf=function(words_arr,out_jqwin){
593    var call_ob=this;
594    ajax_xcall("ps.check_word",[words_arr,"FULL"],function(data){
595        var headwords=data.result["headwords"];
596        var rwords=data.result["rwords"];
597        var extwords=data.result["extwords"];
598        var unwords=data.result["unwords"];
599
600        var headrt=[];
601        for (var i=0;i<headwords.length;i++){
602            var hw=headwords[i];
603            headrt.push(" {0}( {1})".format(hw['word'],hw['relatedWords']));
604        }
605        out_jqwin.val(headrt.join(",  "));
606        var out_log=" headrt ={0}".format(headrt.length);
607        call_ob.ptlog(out_log);
608    });
609};
610
611MulEditwindow.prototype.sortword_inplace=function(inout_jqwin){
612    var call_ob=this;
613    var txt =inout_jqwin.val();
614    var w_list=extract_allwords(txt);
615    var w_set={};
616    for(var i in w_list){
617        if(w_list[i]) {
618            w_set[w_list[i]] = i;
619        }
620    }
621    var out_list=[];
622    for(var key in w_set){
623        out_list.push(key);
624    }
625    var out_log="words = {0} , unique words ={1}".format(w_list.length,out_list.length);
626
627    call_ob.ptlog(out_log);
628    inout_jqwin.val(out_list.join(","));
629};
630
631// <<<<<<<<<<<--------MulEditwindow-----------------------------
632
633
634// ============================UI END --=====================================
635// ============================UI END --=====================================
636// ============================UI END --=====================================
637// ============================UI END --=====================================
638
639function split_and_trim(txt,seprator){
640    var sep = seprator?seprator:",";
641    var t_list=txt.split(sep);
642    var out_list=[];
643    for (var x in t_list){
644        var tmp = t_list[x].trim();
645        if(tmp.length>=1){
646            out_list.push(tmp);
647        }
648    }
649    return out_list;
650}
651
652function extract_allwords(txt){
653    return txt.match(/[\w]+/g);
654}
655
656function extract_words_gt2(txt){
657    return txt.match(/[\w]{3,}/g);
658}
659
660//---------------
661
662
663
664function Analyze_Win(){
665    var rt_win=[
666        {type:"area",nclass:"al_subt_src",height:"60%",width:"100%"},
667        {type:"static",nclass:"al_edit_src",height:"auto",width:"100%"},
668        {type:"wd_select"},
669        {type:"button",nclass:"al_filtword",value:"filt word",float:"right"},
670        {type:"area",nclass:"al_edit_words",height:"48%",width:"100%",display:"none"},
671        {type:"button",nclass:"al_checkword",value:"check word",float:"right",display:"none"},
672        {type:"button",nclass:"al_generate",value:"generate words",float:"right",display:"none"},
673        {type:"area",nclass:"al_edit_more",height:"48%",width:"100%",display:"none"},
674        {type:"button",nclass:"al_makewords",value:"Make new wordlist",float:"right",display:"none"},
675    ];
676    var params={
677      top: "0%",left:"3%",width:"93%",height:"92%", rt_win:rt_win,subclass:"pt_analyze_win"
678    };
679    MulEditwindow.call(this,params);
680
681    self.subtitle=jQuery(".al_subt_src").val();
682
683    this.heightlight(".al_filtword");
684    var call_ob=this;
685
686    this.getwin().find("input.al_filtword").click(function(){
687        jQuery(this).hide();
688        call_ob.analyze_word();
689    });
690
691    this.getwin().find("input.al_checkword").click(function(){
692        jQuery(this).hide();
693
694        var txt_list=split_and_trim( call_ob.getwin().find(".al_edit_words").val());
695        txt_list.sort();
696        var thewin = call_ob.getwin().find(".al_edit_words");
697        call_ob.check_word(txt_list,thewin,function(){
698            call_ob.getwin().find("input.al_generate").show();
699            call_ob.heightlight(".al_generate");
700        });
701
702    });
703    this.getwin().find("input.al_generate").click(function(){
704        jQuery(this).val("Regenerate words");
705
706        call_ob.generate_words();
707    });
708
709    this.getwin().find("input.al_makewords").click(function(){
710        var in_jqwin=call_ob.getwin().find(".al_edit_more");
711        var out_jqwin=jQuery("#wiki__text");
712        call_ob.make_newwords(in_jqwin,out_jqwin);
713    });
714}
715Analyze_Win.prototype=Object.create( MulEditwindow.prototype);
716
717
718
719
720Analyze_Win.prototype.analyze_word=function(){
721    var call_ob=this;
722    var sel_wordlist =call_ob.get_select_wordlist();
723
724    ajax_xcall("ps.get_wordlist",[sel_wordlist["global"]],function(data){
725        jQuery(".al_edit_words").val("begin to analyze wos~~~");
726
727
728        var wordlisttxt = data.result;
729
730        var wd_filter = wordlisttxt.split(",");
731
732        self.subtitle=jQuery(".al_subt_src").val();
733        var texttmp = self.subtitle;
734        var text = texttmp.toLocaleLowerCase();
735        var txlist= extract_words_gt2(text);
736
737        var work_inf = "This page has " +txlist.length +" words.";
738        call_ob.txlist_unsort=txlist.concat();
739        txlist.sort();
740
741        var wordls_set =  make_map_w(txlist);
742        var word_sort_list=new Array();
743        for(var kk in wordls_set){
744            word_sort_list.push(kk);
745        }
746        word_sort_list.sort();
747
748
749        work_inf+="and "+word_sort_list.length+" unique words.<br/>";
750        var src_words = JSON.stringify(wordls_set,null,"\t")+"<br/><br/><br/>";
751        jQuery(".al_edit_src").html(src_words);
752
753        var newwords_list = wComplement_w(word_sort_list,wd_filter);
754        call_ob.newwords_list=newwords_list;
755
756        work_inf+= "Un match words = " +newwords_list.length+",Your filter conut="+wd_filter.length+"<br/>" ;
757        var rtstr=newwords_list.join(",    ");
758        jQuery(".al_edit_words").val(rtstr);
759
760        call_ob.ptlog(work_inf);
761        call_ob.getwin().find(".al_edit_words").show();
762        call_ob.getwin().find(".al_checkword").show();
763        call_ob.heightlight(".al_checkword");
764        call_ob.ctwinScrollDown();
765    });
766};
767
768
769
770Analyze_Win.prototype.generate_words=function(){
771    var call_ob=this;
772
773
774    var txt_edit_words = call_ob.getwin().find(".al_edit_words").val();
775    var txt_list = txt_edit_words.split(/\[[\w]+\]:/);
776
777    var head_tmp=txt_list[1];
778    var r_tmp=txt_list[2];
779    var un_tmp=txt_list[3];
780    var out_arr=[];
781    if(txt_list.length>1){ // has headwords
782        out_arr=extract_allwords(txt_list[1]);
783    }
784
785    if(txt_list.length>3){ // has unwords
786        out_arr=out_arr.concat(extract_allwords(txt_list[3]));
787
788    }
789
790    var out_list_set={};
791    for(var i=0;i<out_arr.length;i++){
792        out_list_set[out_arr[i]]=out_arr[i];
793    }
794
795
796    if(txt_list.length>2){ // has related words
797        var r_arr=txt_list[2].match(/[^,\(]+\([^\)]*\)|[\w]+/g);
798        var r_length = r_arr?r_arr.length:0;
799        for(var i=0;i<r_length;i++){
800            var tmp_words=r_arr[i].match(/[\w]+/g);
801            if(tmp_words){
802                if(tmp_words.length>1){
803                    out_list_set[tmp_words[1]]=tmp_words[0];
804                }else{
805                    out_list_set[tmp_words[0]]=tmp_words[0];
806                }
807            }
808        }
809
810    }
811
812
813//    console.log(JSON.stringify(txlist_unsort));
814    var txlist_unsort = call_ob.txlist_unsort;
815
816    var unsort_out_list = [];
817    for(var i=0;i<txlist_unsort.length;i++){
818        if(out_list_set[txlist_unsort[i]]){
819            unsort_out_list.push(out_list_set[txlist_unsort[i]]);
820            delete out_list_set[txlist_unsort[i]];
821//            console.log("i={0},word={1}".format(i,txlist_unsort[i]));
822        }
823    }
824
825    var uns_set = make_set(unsort_out_list);
826    var out_list=[];
827    for(var i=0;i<unsort_out_list.length;i++){
828        if(uns_set[unsort_out_list[i]]){
829            out_list.push(unsort_out_list[i]);
830            delete uns_set[unsort_out_list[i]];
831        }
832    }
833
834
835    var log_inf= "The finally new words (ordered by the order in document) = " +out_list.length+"<br/>" ;
836    call_ob.getwin().find(".al_edit_more").val(out_list.join(",    "));
837
838
839    call_ob.ptlog(log_inf);
840    call_ob.getwin().find(".al_edit_more").show();
841    call_ob.getwin().find(".al_makewords").show();
842    call_ob.heightlight(".al_makewords");
843    call_ob.ctwinScrollDown();
844};
845
846function get_pagename(){
847    if(JSINFO['id']){
848        var tmp_arr = JSINFO['id'].split(":");
849        var name = tmp_arr[tmp_arr.length-1];
850        return name;
851    }else{
852        return "ERR";
853    }
854}
855
856Analyze_Win.prototype.make_newwords=function(in_jqwin,out_jqwin){
857
858    var newwords = extract_allwords(in_jqwin.val());
859    var subtitle_id=JSINFO['id']+":"+JSINFO['subtitle_dst'];
860    var subt_name=get_pagename();
861    var wordmean_id=JSINFO['id']+":"+JSINFO['def_dst'];
862    var wordlist_id=JSINFO['id']+":"+JSINFO['wordlist_dst'];
863
864    var out_str="====== Movie Inf ======\n";
865    out_str+="\nLike genre,stars,director and more,please editor me\n";
866    out_str+="====== wordlist ======\n";
867    out_str+="The wordlist location [[{0}]]\n".format(wordlist_id);
868    out_str+="<BK open page={0} type=wordlist>Show wordlist of this page</BK>\n".format(wordlist_id);
869    out_str+="\n===== slice =====\n";
870    out_str+="\n====== Notice ======\n";
871    out_str+="\n some hard grammar or sentence in movie,please editor me\n";
872    out_str+="\n====== Words Meaning ======\n";
873    out_str+="The words meaning location [[{0}]]\n".format(wordmean_id);
874    out_str+="<BK open page={0} type=def>Show All New Word Meaning</BK>\n".format(wordmean_id);
875
876    out_str+="\n====== Subtitle ======\n";
877    out_str+="The srt file location [[{0}]]\\\\ \n".format(subtitle_id);
878    out_str+="<BK open page={0}>Show {1}.srt </BK>\n".format(subtitle_id,subt_name);
879
880
881    out_jqwin.val(out_str);
882    console.log(subt_name+"---"+JSINFO['id']);
883    ajax_xcall("ps.cp_defs",[JSINFO['id'],newwords],function(data){
884        console.dir(data);
885    });
886
887    ajax_xcall("ps.cp_subtitle",[JSINFO['id'],self.subtitle],function(data){
888        console.dir(data);
889    });
890
891    ajax_xcall("ps.cp_wordlist",[JSINFO['id'],newwords.join(",")],function(data){
892        console.dir(data);
893    });
894
895    this.getwin().slideUp(500);
896};
897
898
899
900function Init_english_edit_tool(){
901
902    var con_win= jQuery(".pt_pa_sub");
903
904
905    con_win.find(".xxpg_analyze").click(function(){
906        var ptana=PTwindow.Factory(Analyze_Win,{winid:"analyze_w"});
907        ptana.show(1000);
908        ptlog.log("hello,iam xxpg_analyze click : {0}".format(jQuery(this).html()));
909    });
910
911    con_win.find(".xxpg_merge").click(sort_wordlist);
912
913}
914
915
916
917
918//----------------------
919
920function ajax_get_words(){
921//    alert("ajax_get_words");
922    var mdata={};
923    mdata['pageid']=WORDLIST_NAME;
924    mdata['call']="ajaxpeon";
925    mdata['target']="rawpage";
926    var url = DOKU_BASE + 'lib/exe/ajax.php';
927    jQuery.ajax({url:url,data:mdata,success:words_analyze,dataType:"jsonp",crossDomain:true});
928    jQuery("#pagestat_rt").slideDown(1000);
929    jQuery("#pagestat_txtout").html("get filter list~~~");
930
931}
932
933
934function insert_words_todk(){
935
936    var anal_txt= jQuery("#pagestat_edit").val();
937    var anal_list=anal_txt.split(",");
938    var outstr="<WORDLIST>";
939    for (var x in anal_list){
940        anal_list[x]=anal_list[x].trim();
941    }
942    anal_list.sort();
943    outstr+=anal_list.join(",");
944    outstr+="</WORDLIST>"+anal_list.length+"\n\n";
945    var edit_txt = jQuery("#wiki__text").val();
946    jQuery("#wiki__text").val(outstr+edit_txt);
947    jQuery("#pagestat_edit").slideUp(500);
948    jQuery("#pagestat_rt").slideUp(1000);
949}
950
951function sort_wordlist(){
952    var edit_txt = jQuery("#wiki__text").val();
953    var word_list =edit_txt.split(",");
954    for(var jj=0;jj<word_list.length;jj++){
955        word_list[jj]=word_list[jj].trim();
956    }
957    word_list.sort();
958
959    var out_list = make_unique_list(word_list);
960
961    var rt_txt = out_list.join(",");
962
963    jQuery("#wiki__text").val(rt_txt);
964}
965
966//------------------------------------
967//--------------check words windows -----------------
968function Checkwords_Win(param_obj){
969    var rt_win=[
970        {type:"area",nclass:"ck_edit_words",height:"48%",width:"100%"},
971        {type:"button",nclass:"ckbt_checkword",value:"check word",float:"right"},
972        {type:"area",nclass:"ck_full_words",height:"48%",width:"100%"},
973        {type:"button",nclass:"ckbt_fullinf",value:"get full word inf",float:"right",display:"none"},
974        {type:"button",nclass:"ckbt_sort",value:"sort words",float:"right",display:"none"}
975    ];
976    param_obj.rt_win=rt_win;
977    param_obj.subclass="pt_checkwords_win";
978    MulEditwindow.call(this,param_obj);
979
980    var ctwin=this.getclientwin();
981    var call_ob=this;
982    call_ob.heightlight(".ckbt_checkword");
983    ctwin.find(".ckbt_checkword").click(function(){
984        var txt= ctwin.find(".ck_edit_words").val();
985        call_ob.check_word(extract_allwords(txt),ctwin.find(".ck_edit_words"));
986        jQuery(this).hide();
987        ctwin.find(".ckbt_fullinf").show();
988        call_ob.heightlight(".ckbt_fullinf");
989        call_ob.ctwinScrollDown();
990    });
991    ctwin.find(".ckbt_fullinf").click(function(){
992        var txt= ctwin.find(".ck_full_words").val();
993        call_ob.get_full_wordinf(extract_allwords(txt),ctwin.find(".ck_full_words"));
994        jQuery(this).hide();
995        ctwin.find(".ckbt_sort").show();
996        call_ob.heightlight(".ckbt_sort");
997    });
998    ctwin.find(".ckbt_sort").click(function(){
999        call_ob.sortword_inplace(ctwin.find(".ck_full_words"));
1000    });
1001}
1002Checkwords_Win.prototype=Object.create(MulEditwindow.prototype);
1003
1004
1005
1006function Make_Checkwords_Win(){
1007
1008    var params= PTwindow.Extract_ptparams(jQuery(this));
1009    var ptwin = PTwindow.Factory(Checkwords_Win,params);
1010    ptwin.show();
1011
1012}
1013
1014// ---------------------word card win -------------------------------
1015function WordCard_Win(param_obj){
1016    var rt_win=[
1017        {type:"static",nclass:"wc_wordcard",height:"75%",width:"100%"},
1018        {type:"static",nclass:"wc_inf",height:"8%",width:"100%"},
1019        {type:"button",nclass:"wc_pre",value:"previous",float:"left"},
1020        {type:"button",nclass:"wc_next",value:"next",float:"right"},
1021    ];
1022    var params={winid:param_obj.winid,subclass:"pt_wordcard_win",rt_win:rt_win,top:"0%",left:"0%",width:"100%",height:"92%"};
1023    MulEditwindow.call(this,params);
1024
1025    var w_from=param_obj.from;
1026    var w_to=param_obj.to;
1027
1028
1029    var ctwin=this.getclientwin();
1030    var call_ob=this;
1031    call_ob.heightlight(".wc_next");
1032    this.build_card(w_from,w_to);
1033    call_ob.card_itor(0);
1034    ctwin.find(".wc_pre").click(function(){
1035
1036        call_ob.card_itor(-1);
1037        ctwin.find(".wc_inf").html("<----previous ({0}/{1})".format(call_ob.card_index+1,call_ob.word_cards.length));
1038    });
1039
1040    ctwin.find(".wc_next").click(function(){
1041        call_ob.card_itor(1);
1042        ctwin.find(".wc_inf").html("next ----> ({0}/{1})".format(call_ob.card_index+1,call_ob.word_cards.length));
1043    });
1044
1045}
1046WordCard_Win.prototype=Object.create(MulEditwindow.prototype) ;
1047
1048
1049
1050WordCard_Win.prototype.build_card=function(w_from,w_to){
1051
1052    var ctwin=this.getclientwin();
1053
1054    var infowin= ctwin.find(".wc_inf");
1055    var jq_wordlist=jQuery(".wordlist");
1056    var word_list=[];
1057    if(jq_wordlist.length==0){
1058        infowin.html("there is no wordlist in this page!!");
1059        return
1060    }
1061
1062
1063    if(jq_wordlist.length>0) {
1064        var wd_txt = jq_wordlist.text();
1065
1066        var tmp="\\b{0}\\b.+\\b{1}\\b".format(w_from, w_to);
1067//            var tmp="\b"+s_from+"\b.+\b"+s_to+"\b";
1068
1069        var reg_sr = new RegExp(tmp);
1070        var rt = wd_txt.match(reg_sr);
1071
1072        if (rt) {
1073            word_list=extract_allwords(rt[0]);
1074        }else{
1075            infowin.html("!!! Maybe The slice words was deleted from the wordlist,please choose another word to slice");
1076        }
1077    }
1078
1079
1080
1081    var word_map={};
1082    for(var i=0;i<word_list.length;i++){
1083        word_map[word_list[i]]=i;
1084    }
1085
1086    var word_cards_tmp=[];
1087    var tran_list=jQuery(".xxbk_open ul li");
1088
1089    tran_list.each(function(index){
1090        var word=jQuery("div span.wrap_vo",this).text();
1091        if(word&&(word in word_map)) {
1092            word_cards_tmp[word_map[word]] = jQuery(this).html();
1093        }
1094    });
1095    var word_cards=[];
1096    for(var key in word_cards_tmp){
1097        word_cards.push(word_cards_tmp[key]);
1098    }
1099
1100
1101
1102    this.word_cards=word_cards;
1103    this.card_index=0;
1104};
1105WordCard_Win.prototype.card_itor=function(step){
1106    var ctwin=this.getclientwin();
1107    this.card_index+=step;
1108    if(this.card_index<0){this.card_index=this.word_cards.length-1;}
1109    if(this.card_index>=this.word_cards.length){this.card_index=0;}
1110    var word_c= this.word_cards[this.card_index];
1111    var div_wrap='<div class="wc_wordcard_wp">{0}</div>'.format(word_c);
1112    ctwin.find(".wc_wordcard").html(div_wrap);
1113    mxyd_voice_onclick(".wrap_vo",ctwin[0]);
1114    ctwin.find(".wrap_vo").click();
1115
1116    return word_c;
1117};
1118
1119function Make_wordcard_win(){
1120
1121    var jq_xxbk_wl=jQuery(".xxbk_type_wordlist");
1122    var jq_xxbk_def=jQuery(".xxbk_type_def");
1123    var call_ob=this;
1124    XXBK_base_ui.prototype.click_delay.call(this,[jq_xxbk_wl,jq_xxbk_def],function(){
1125        var params = PTwindow.Extract_ptparams(jQuery(call_ob));
1126        var ptwin=PTwindow.Factory(WordCard_Win, params);
1127        ptwin.show();
1128    });
1129
1130}
1131
1132// <<<<<<<<<<<<<<----------------------------------------------------
1133
1134//-----------------------------------test win -----------------------
1135function XXtest_Win(top,left,width,height){
1136    var rt_win=[
1137        {type:"area",nclass:"ck_test_input",height:"48%",width:"100%"},
1138        {type:"button",nclass:"ckbt_test",value:"test",float:"right"},
1139        {type:"area",nclass:"ck_test_out",height:"48%",width:"100%"}
1140    ];
1141    MulEditwindow.call(this,"pt_test_win",rt_win,top,left,width,height);
1142}
1143XXtest_Win.prototype=Object.create(MulEditwindow.prototype) ;
1144
1145
1146XXtest_Win.prototype.createwin=function(winid) {
1147    MulEditwindow.prototype.createwin.call(this, winid);
1148    var ctwin = this.getclientwin();
1149    var call_ob = this;
1150    call_ob.heightlight(".ckbt_test");
1151    ctwin.find(".ckbt_test").click(function(){
1152
1153        var wordtxt =ctwin.find(".ck_test_input").val();
1154        var word_arr = extract_allwords(wordtxt);
1155        call_ob.ajax_get_defs(word_arr,"MORE",function(def_txt){
1156
1157            ctwin.find(".ck_test_out").val(def_txt);
1158        });
1159    });
1160};
1161
1162function Make_XXtest_Win(){
1163    var winid = jQuery(this).attr("id");
1164    if(ptw_list[winid]==null){
1165        var top = jQuery(this).attr("arg1");
1166        var left = jQuery(this).attr("arg2");
1167        var width = jQuery(this).attr("arg3");
1168        var height = jQuery(this).attr("arg4");
1169        var ptwin =new XXtest_Win(top,left,width,height);
1170        ptwin.createwin(winid);
1171        ptw_list[winid]=ptwin;
1172    }
1173    ptw_list[winid].show();
1174    ptw_list[winid].getwin().draggable();
1175
1176}
1177
1178
1179// ----------- list windows --------------
1180
1181
1182function make_list( learn_list,backns,ptwinid ){
1183    var ckname="ck_"+ptwinid;
1184    var mystr="";
1185    mystr+='<ul><li><span class="back_ns show_learnlist" ns="{0}" winid="{1}">Back</span></li>'.format(backns,ptwinid);
1186
1187    if(learn_list['ns']){
1188        for(var ns in learn_list['ns']){
1189            var ckid="ckn_"+ns.replace(/:/g,"_");
1190            mystr+='<li class="bl_fold"><input type="checkbox" name="{1}" value="{2}" id="{3}" />\
1191            <label  class="lb_ns" for="{3}">{4}</label><span class="sp_fold show_learnlist" ns="{2}" winid="{0}"> </span></li>'.format(ptwinid,ckname,ns,ckid,ns);
1192        }
1193    }
1194    mystr+='<div style="clear: both"></div>';
1195    if(learn_list['files']){
1196        for(var i=0;i<learn_list['files'].length;i++){
1197            var filename = learn_list['files'][i];
1198            var ckid="ckf_"+filename.replace(/:/g,"_");
1199            mystr+='<li><input id="{2}" type="checkbox" name="{0}" value="{1}" /><label for="{2}">{3}</label></li>'.format(ckname,filename,ckid,filename);
1200        }
1201    }
1202    mystr+="</ul>";
1203    mystr+='<div style="clear: both"></div>';
1204    return mystr;
1205}
1206
1207function show_learnlist(arg_ns){
1208    var nowns=jQuery(this).attr("ns");
1209    if(nowns==null){
1210        nowns=arg_ns;
1211    }
1212    var nslist= nowns.substr(0,nowns.length-1).split(":");
1213    var winid = jQuery(this).attr("winid");
1214    var ptwin =ptw_list[winid];
1215    var learn_list = ptwin.learn_list;
1216    var cur_ns = nslist[0]+":";
1217    for(var i=1;i<nslist.length;i++){
1218        cur_ns+=nslist[i]+":";
1219        learn_list=learn_list["ns"][cur_ns];
1220    }
1221    var outwin = ptwin.getclientwin().children(".learnlist");
1222
1223    var ptwinid = winid;
1224    var backns="";
1225    for(var b=0;b<nslist.length-1;b++){
1226        backns+=nslist[b]+":";
1227    }
1228
1229    var mystr = make_list(learn_list,backns,ptwinid);
1230
1231    outwin.html(mystr);
1232    outwin.find(".show_learnlist").click(show_learnlist);
1233}
1234
1235
1236function handle_list(mdata){
1237    var learn_txt =mdata.content;
1238    var learn_list =JSON.parse(learn_txt);
1239    var ptwin =ptw_list[mdata.reflect];
1240
1241    ptwin.learn_list = learn_list;
1242    var outwin = ptwin.getclientwin().children(".learnlist");
1243    var ptwinid = mdata.reflect;
1244
1245    var mystr = make_list(learn_list,"learn:",ptwinid);
1246    outwin.html(mystr);
1247    outwin.find(".show_learnlist").click(show_learnlist);
1248}
1249
1250function Listwindow(param_obj){
1251    PTwindow.call(this,param_obj);
1252
1253    var winid=param_obj.winid;
1254    var learnlist=jQuery( '<div class="learnlist"> </div>');
1255
1256//    var learndir = jQuery('<input type="text" name="learndir">');
1257    var btckall = jQuery('<input name="ckall" class="button" type="button" value="ClickAll">');
1258    var btunckall = jQuery('<input name="unckall" class="button" type="button" value="UnClickAll">');
1259
1260    btckall.click(function(){
1261        jQuery(this).parent().find('input[type="checkbox"]').prop("checked",true);
1262    });
1263    btunckall.click(function(){
1264        jQuery(this).parent().find('input[type="checkbox"]').prop("checked",false);
1265    });
1266//    var user_filter_sel = jQuery('<select name="user_filter_sel"><option value="user_wordlist">uwords</option></select>');
1267
1268    this.getclientwin().append(learnlist);
1269//    this.getclientwin().append(learndir);
1270    this.getclientwin().append(btckall);
1271    this.getclientwin().append(btunckall);
1272//    this.getclientwin().append(user_filter_sel);
1273
1274    var mdata=new Object();
1275    mdata['call']="ajaxpeon";
1276    var url = DOKU_BASE + 'lib/exe/ajax.php';
1277    mdata['target']="learnlist";
1278    mdata['reflect']=winid;
1279    jQuery.ajax({url:url,data:mdata,success:handle_list,dataType:"jsonp",crossDomain:true});
1280}
1281Listwindow.prototype=Object.create( PTwindow.prototype);
1282
1283
1284function addfilter_aj(mdata){
1285    var ptwin =PTwindow.GetObj[mdata.reflect];
1286    var word_list_txt =mdata.content;
1287    var filter_sel = jQuery('<select name="filter_sel"><option value="none">none</option></select>');
1288    if(word_list_txt.length>5){
1289        var filter = word_list_txt.split(",");
1290        ptwin.filter = filter;
1291        var filter_sel = jQuery('<select name="filter_sel"><option value="{0}">wordlist</option></select>'.format(WORDLIST_NAME) );
1292    }
1293    ptwin.getclientwin().append(filter_sel);
1294}
1295
1296Listwindow.prototype.addfilter=function(){
1297
1298    var mdata=new Object();
1299    mdata['pageid']=WORDLIST_NAME;
1300    mdata['call']="ajaxpeon";
1301    var url = DOKU_BASE + 'lib/exe/ajax.php';
1302    mdata['target']="rawpage";
1303    mdata['reflect']=this.getwinid();
1304    jQuery.ajax({url:url,data:mdata,success:addfilter_aj,dataType:"jsonp",crossDomain:true});
1305};
1306
1307var USER_WORDLIST_NAME ;
1308
1309function add_userfilter_aj(mdata){
1310    var ptwin =PTwindow.GetObj[mdata.reflect];
1311    var user_list_txt =mdata.content;
1312    var user_filter_sel = jQuery('<select name="user_filter_sel"><option value="none">none</option></select>');
1313    if(user_list_txt.length>5){
1314        ptwin.user_filter=user_list_txt.split(",");
1315        user_filter_sel = jQuery('<select name="user_filter_sel"><option value="{0}">user_wordlist</option></select>'.format(USER_WORDLIST_NAME) );
1316    }
1317    ptwin.getclientwin().append(user_filter_sel);
1318}
1319
1320Listwindow.prototype.adduser_filter=function(){
1321    var mdata=new Object();
1322    mdata['pageid']=USER_WORDLIST_NAME;
1323    mdata['call']="ajaxpeon";
1324    var url = DOKU_BASE + 'lib/exe/ajax.php';
1325    mdata['target']="rawpage";
1326    mdata['reflect']=this.getwinid();
1327    jQuery.ajax({url:url,data:mdata,success:add_userfilter_aj,dataType:"jsonp",crossDomain:true});
1328};
1329
1330
1331Listwindow.prototype.getSublearnlist =function(sublearnlist,out_arr){
1332    if(sublearnlist["ns"] ){
1333        for(var subns in sublearnlist['ns']){
1334            this.getAllSublearnlist(sublearnlist['ns'][subns],out_arr);
1335        }
1336    }
1337    if(sublearnlist["files"]){
1338        for(var i=0;i<sublearnlist['files'].length;i++) {
1339            out_arr.push(sublearnlist['files'][i]);
1340        }
1341    }
1342};
1343
1344Listwindow.prototype.getsubNslearnlist =function(ns,out_arr){
1345
1346    var nslist= ns.substr(0,ns.length-1).split(":");
1347    var learn_list = this.learn_list;
1348    var cur_ns = nslist[0]+":";
1349    for(var i=1;i<nslist.length;i++){
1350        cur_ns+=nslist[i]+":";
1351        learn_list=learn_list["ns"][cur_ns];
1352    }
1353    this.getSublearnlist(learn_list,out_arr);
1354};
1355
1356Listwindow.prototype.getselect_learn = function(){
1357    var checkboxes = this.getclientwin().children(".learnlist").find('input[type="checkbox"]');
1358    var flat_learn_list=new Array();
1359    var ptwin = this;
1360    checkboxes.each(function(){
1361        if(jQuery(this).prop("checked")==true){
1362            var learnname = jQuery(this).val();
1363            if(learnname.charAt(learnname.length-1)==":" ){ // ns
1364                ptwin.getsubNslearnlist(learnname,flat_learn_list);
1365            }else{
1366                flat_learn_list.push(learnname);
1367            }
1368        }
1369    });
1370    return flat_learn_list;
1371};
1372
1373
1374
1375
1376function parse_learn_aj(mdata){
1377    var ptwin =PTwindow.GetObj[mdata.reflect];
1378    var pg_wordlist = mdata.content.toLowerCase().split(/[^\w\-_]+/);
1379    pg_wordlist.sort();
1380    if(ptwin.parse_count<2){
1381        ptwin.pb_pre_wordss=pg_wordlist;
1382    }else{
1383        var tmplist=ptwin.parse_learn_fuc(ptwin.pb_pre_wordss,pg_wordlist);
1384        ptwin.parse_logstr+="{0}({1},{2})->".format(tmplist.length,ptwin.pb_pre_wordss.length,pg_wordlist.length);
1385        ptwin.parse_str =tmplist.join(" ,  ")+"<br/><br/>" +ptwin.parse_str;
1386        ptwin.parse_output.html(ptwin.parse_logstr+"<br/><br/>"+ptwin.parse_str );
1387        ptwin.pb_pre_wordss =tmplist;
1388    }
1389
1390    if(ptwin.parse_count<ptwin.parse_learn_list.length){
1391        var mdata=new Object();
1392        mdata['pageid']=ptwin.parse_learn_list[ptwin.parse_count];
1393        mdata['call']="ajaxpeon";
1394        var url = DOKU_BASE + 'lib/exe/ajax.php';
1395        mdata['target']="rawpage";
1396        mdata['rev']='ori';
1397        mdata['reflect']=ptwin.getwinid();
1398        jQuery.ajax({url:url,data:mdata,success:parse_learn_aj,dataType:"jsonp",crossDomain:true});
1399    }
1400    ptwin.parse_count+=1;
1401}
1402
1403function parse_learn(event){
1404    var ptwin = event.data.ptwin;
1405    var parse_learn_list = ptwin.getselect_learn();
1406    var parse_fuc = ptwin.getclientwin().find('select[name="logic_sel"]').val();
1407    var parse_learn_fuc=null;
1408    switch(parse_fuc){
1409        case "wIntersection_w":
1410            parse_learn_fuc=wIntersection_w;
1411            break;
1412        case "wComplement_w":
1413            parse_learn_fuc=wComplement_w;
1414            break;
1415        case "wUnion_w":
1416            parse_learn_fuc=wUnion_w;
1417            break;
1418    }
1419    ptwin.parse_learn_fuc = parse_learn_fuc;
1420    ptwin.parse_learn_list=parse_learn_list;
1421    ptwin.parse_count =0;
1422    ptwin.pb_pre_wordss=null;
1423    ptwin.parse_str="";
1424    ptwin.parse_logstr="";
1425    if(parse_learn_list.length<2){
1426        return;
1427    }else{
1428        var buttonid= jQuery(this).attr("id");
1429        if(PTwindow.GetObj[buttonid]==null){
1430            var swin =new PTwindow("ptparse","2%","2%","90%","80%");
1431            PTwindow.GetObj[buttonid]=swin;
1432            swin.createwin(buttonid);
1433            ptwin.parse_output = PTwindow.GetObj[buttonid].getclientwin();
1434        }
1435        ptwin.parse_output.html("receiving learn data ...");
1436        PTwindow.GetObj[buttonid].show();
1437        var mdata=new Object();
1438        mdata['pageid']=parse_learn_list[ptwin.parse_count];
1439        mdata['call']="ajaxpeon";
1440        var url = DOKU_BASE + 'lib/exe/ajax.php';
1441        mdata['target']="rawpage";
1442        mdata['rev']='ori';
1443        mdata['reflect']=ptwin.getwinid();
1444        jQuery.ajax({url:url,data:mdata,success:parse_learn_aj,dataType:"jsonp",crossDomain:true});
1445        ptwin.parse_count+=1;
1446    }
1447}
1448
1449function parse_learn_win(){
1450
1451    var winid = jQuery(this).attr("id");
1452    var ptwin=PTwindow.GetObj(winid);
1453    if(!ptwin){
1454        var params = PTwindow.Extract_ptparams(jQuery(this));
1455        params.subclass="parse_learn";
1456        ptwin=PTwindow.Factory(Listwindow,params);
1457
1458        var logic_sel = jQuery('<select name="logic_sel"><option value="wIntersection_w">Intersection</option><option value="wComplement_w">Complement</option>\
1459    <option value="wUnion_w">Union</option></select>');
1460
1461        var parse_bt = jQuery('<input name="parse_bt" id="parse_{0}" class="button" type="button" value="Parse">'.format(winid));
1462        parse_bt.click({"ptwin":ptwin},parse_learn);
1463//        ptwin.addfilter();
1464//        ptwin.adduser_filter();
1465        ptwin.getclientwin().append(logic_sel);
1466        ptwin.getclientwin().append(parse_bt);
1467    }
1468    ptwin.show();
1469
1470}
1471
1472
1473function search_learn_aj(mdata){
1474    var ptwin =PTwindow.GetObj[mdata.reflect];
1475    var page_wordlists = mdata.content;
1476    var mystr="";
1477    var filter = ptwin.user_filter;
1478
1479    for(var learnname in page_wordlists){
1480        var wordarray = page_wordlists[learnname].split(",");
1481        var match_list = wIntersection_w(wordarray,filter);
1482        var unmatch_list = wComplement_w(wordarray,match_list);
1483        var match_rate = (match_list.length/wordarray.length)*100;
1484        var tmphh = match_rate.toString().split(".");
1485        var match_rate_str = tmphh[0];
1486        if(tmphh[1]!=null) {
1487            match_rate_str += "." + tmphh[1].substring(0, 2);
1488        }
1489        mystr+='<div class="match_rt" rate="{0}"><a href="{1}" target="_blank">{2}</a><span> , match rate:{0}% ({3}/{4}),</span><span class="match_show_dl">more detail...</span><br/>\
1490        <span class="mt_more_words">Unmatch list:[ {5} ]</span><br/><span class="mt_more_words">Match list : [ {6}]</span> </div>'.format(match_rate_str,DOKU_BASE+learnname,learnname,match_list.length,wordarray.length,unmatch_list.join(","),match_list.join(","));
1491    }
1492    ptwin.output.html(mystr);
1493    ptwin.output.find(".match_show_dl").click(function(){
1494        jQuery(this).siblings(".mt_more_words").toggle();
1495    });
1496}
1497
1498function search_learn(event){
1499    var ptwin = event.data.ptwin;
1500    var sl_learn_list = ptwin.getselect_learn();
1501    var parse_fuc = ptwin.getclientwin().find('select[name="logic_sel"]').val();
1502    if(sl_learn_list.length>0){
1503        var buttonid= jQuery(this).attr("id");
1504        var swin=PTwindow.GetObj(buttonid);
1505        if(!swin){
1506            swin=PTwindow.Factory(PTwindow,{winid:buttonid,subclass:"ptsearch",top:"2%",left:"2%",width:"90%",height:"80%"});
1507            ptwin.output=swin.getclientwin();
1508        }
1509
1510        ptwin.output.html("receiving learn data ...");
1511        swin.show();
1512
1513        var mdata=new Object();
1514        mdata['call']="ajaxpeon";
1515        var url = DOKU_BASE + 'lib/exe/ajax.php';
1516        mdata['target']="page_wordlists";
1517        mdata['pglist']=JSON.stringify(sl_learn_list);
1518        mdata['reflect']=ptwin.getwinid();
1519        jQuery.ajax({url:url,data:mdata,success:search_learn_aj,dataType:"jsonp",crossDomain:true});
1520    }
1521}
1522
1523function search_learn_win(){
1524    var winid = jQuery(this).attr("id");
1525    var ptwin=PTwindow.GetObj(winid);
1526    if(!ptwin){
1527        var params = PTwindow.Extract_ptparams(jQuery(this));
1528        params.subclass="search_learn";
1529        ptwin=PTwindow.Factory(Listwindow,params);
1530
1531        var search_bt = jQuery('<input name="search_bt" id="search_{0}" class="button" type="button" value="Search">'.format(winid));
1532        search_bt.click({"ptwin":ptwin},search_learn);
1533//        ptwin.addfilter();
1534        ptwin.adduser_filter();
1535        ptwin.getclientwin().append(search_bt);
1536    }
1537
1538    ptwin.show();
1539}
1540
1541// <<<<<<<<<<--------------------open_page ---------
1542
1543function open_page_worker(data){
1544
1545    var buttonid = data.reflect;
1546    var ptwin =PTwindow.GetObj(buttonid);
1547
1548    ptwin.show();
1549    if (data.content.length<3){ptwin.getclientwin().html("Missing word . . .");
1550    }else{
1551        ptwin.getclientwin().html(data.content);
1552    }
1553}
1554
1555function open_page_win(){
1556
1557    var params= PTwindow.Extract_ptparams(jQuery(this));
1558
1559    if(params.pageid==null){
1560        return;
1561    }
1562
1563    var ptwin=PTwindow.GetObj(params.winid);
1564    if(!ptwin){
1565        params.subclass="ptopen";
1566        ptwin=PTwindow.Factory(PTwindow,params);
1567    }
1568
1569
1570    var mdata=new Object();
1571    mdata['pageid']=params.pageid;
1572    mdata['call']="ajaxpeon";
1573    var url = DOKU_BASE + 'lib/exe/ajax.php';
1574    mdata['target']="page";
1575    mdata['reflect']=params.winid;
1576    jQuery.ajax({url:url,data:mdata,success:open_page_worker,dataType:"jsonp",crossDomain:true});
1577}
1578
1579
1580
1581
1582// ------------------edit wordlist -----------
1583
1584function addto_w_rt(mdata){
1585    var ptwin =ptw_list[mdata.reflect];
1586    var rttxt = mdata.content;
1587    ptwin.get_edit_static().html(rttxt);
1588}
1589
1590
1591function addto_wordlist(event){
1592    var ptwin = event.data.ptwin;
1593    var send_txt = ptwin.get_edit_area().val();
1594
1595    var mdata=new Object();
1596    mdata['call']="ajaxpeon";
1597    var url = DOKU_BASE + 'lib/exe/ajax.php';
1598    mdata['target']="writeraw";
1599    mdata['sub']="wordlist";
1600    mdata['txt']=send_txt;
1601    mdata['pageid']=JSINFO['userwords_ns']+JSINFO['user']+":"+ptwin.dst_page;
1602    mdata['reflect']=ptwin.getwinid();
1603    jQuery.ajax({url:url,data:mdata,success:addto_w_rt,dataType:"jsonp",crossDomain:true});
1604}
1605
1606
1607function addnewwords_win(){
1608    var winid = jQuery(this).attr("id");
1609    if(ptw_list[winid]==null){
1610        var top = jQuery(this).attr("arg2");
1611        var left = jQuery(this).attr("arg3");
1612        var width = jQuery(this).attr("arg4");
1613        var height = jQuery(this).attr("arg5");
1614        var ptwin =new Editwindow("addwords",top,left,width,height);
1615        ptwin.createwin(winid);
1616        ptwin.dst_page = jQuery(this).attr("arg1");
1617        ptw_list[winid]=ptwin;
1618
1619        var addw_bt = jQuery('<input name="add_wd" id="add_wd_{0}" class="button" type="button" value="Add">'.format(winid));
1620        addw_bt.click({"ptwin":ptwin},addto_wordlist);
1621        ptwin.getclientwin().append(addw_bt);
1622    }
1623    ptw_list[winid].show();
1624}
1625//  <<<<----------------edit wordlist------------------
1626
1627//----------------pg_convert_wordls------
1628var wls_ori_words_list =null;
1629var wls_filter_set=null;
1630
1631function addto_txt_rt(mdata){
1632//    alert(mdata.content);
1633    filt_page_wordls();
1634}
1635
1636function addto_wordlist_txt(words_txt){
1637    var mdata=new Object();
1638    mdata['call']="ajaxpeon";
1639    var url = DOKU_BASE + 'lib/exe/ajax.php';
1640    mdata['target']="writeraw";
1641    mdata['sub']="wordlist";
1642    mdata['txt']=words_txt;
1643    mdata['pageid']=USER_WORDLIST_NAME;
1644    jQuery.ajax({url:url,data:mdata,success:addto_txt_rt,dataType:"jsonp",crossDomain:true});
1645}
1646
1647function add_newwords(event){
1648    var wlsdiv = event.data.wlsdiv;
1649    var add_list=new Array();
1650    wlsdiv.find('input.wl_unm').each(function(i,v){
1651        if( jQuery(this).prop("checked")==true ){
1652            add_list.push(jQuery(this).val());
1653        }
1654    });
1655//    alert(add_list.join(","));
1656    addto_wordlist_txt(add_list.join(","));
1657}
1658
1659function pg_convert_wordls(mdata){
1660    var wordls_txt =mdata.content;
1661    if(wordls_txt.length<10){
1662        return;
1663    }
1664    var wlsdiv = jQuery(".wordlist");
1665    if(wlsdiv.length<1){
1666        alert("no wordlist");
1667        return;
1668    }
1669    var wlist="";
1670    if(wls_ori_words_list==null){
1671        var wlist =wlsdiv.text().split(",");
1672        wls_ori_words_list = wlist;
1673    }else{
1674        wlist = wls_ori_words_list;
1675    }
1676    var filter_list =wordls_txt.split(",");
1677    var filter_set=make_map_w(filter_list);
1678
1679    var outstr = "";
1680
1681    for(var i=0;i<wlist.length;i++){
1682        if(filter_set[wlist[i]]==null) {
1683            outstr += '<input class="wl_unm" id="{0}" type="checkbox" name="{1}" value="{2}" /><label class="wl_unm" for="{0}">{2},</label>'.format('wl' + wlist[i], 'wlck', wlist[i]);
1684        }else{
1685            outstr+='<span class="wl_match">{0},</span>'.format(wlist[i]);
1686        }
1687    }
1688    outstr+='<input name="wl_addwords" class="button" type="button" value="Add to word list">';
1689    wlsdiv.html(outstr);
1690    wlsdiv.children("input[name='wl_addwords']").click({"wlsdiv":wlsdiv},add_newwords);
1691
1692}
1693
1694function filt_page_wordls(){
1695
1696    var mdata=new Object();
1697    mdata['pageid']=USER_WORDLIST_NAME;
1698    mdata['call']="ajaxpeon";
1699    var url = DOKU_BASE + 'lib/exe/ajax.php';
1700    mdata['target']="rawpage";
1701    jQuery.ajax({url:url,data:mdata,success:pg_convert_wordls,dataType:"jsonp",crossDomain:true});
1702}
1703// <<<<<-----pg_convert_wordls------------
1704
1705function pg_show_wordlist(context){
1706    jQuery(" .pg_show_wl",context).click(function(){
1707        jQuery(".wordlist").toggle();
1708    });
1709    jQuery(" #pg_filt_wl",context).click(filt_page_wordls);
1710}
1711
1712function Two_edit_win(){
1713
1714
1715    var buttonid= jQuery(this).attr("id");
1716    if(ptw_list[buttonid]==null){
1717        var top = jQuery(this).attr("arg1");
1718        var left = jQuery(this).attr("arg2");
1719        var width = jQuery(this).attr("arg3");
1720        var height = jQuery(this).attr("arg4");
1721
1722        var swin =new MulEditwindow("twoedit","1 2 3",top,left,width,height);
1723        ptw_list[buttonid]=swin;
1724        swin.createwin(buttonid);
1725    }
1726    ptw_list[buttonid].show();
1727}
1728// <<<<<<<<<<<<---------------just wrap div- ------------------------
1729// <<<<<<<<<<<<---------------just wrap div- ----------------------
1730// <<<<<<<<<<<<---------------just wrap div- ----------------------
1731
1732
1733
1734// ===================================
1735
1736// <<<<<<<<<<<<---------------translation- block------------------------
1737// <<<<<<<<<<<<---------------translation- block-----------------------
1738// <<<<<<<<<<<<---------------translation- block-----------------------
1739// <<<<<<<<<<<<---------------translation- block-----------------------
1740
1741
1742
1743//<<<<<<<<<<<<<<---------------------xxbk_base-------------------------
1744// BK is inplace ui ,show content inplace
1745// {subclass:"",dom_me:""}
1746function XXBK_base_ui(params_obj){
1747
1748    this.subclass=params_obj.subclass;
1749    this.jdom_me=jQuery(params_obj.dom_me);
1750    this.create_ui(params_obj);
1751}
1752
1753XXBK_base_ui.Extract_bkparams=function(jwin){
1754
1755    var arg_txt=jwin.attr("xx_arg");
1756    var arg_list=arg_txt.split(";");
1757    var out_params={};
1758    for(var i=0;i<arg_list.length;i++){
1759        var sub_arg=arg_list[i].split("=");
1760        if(sub_arg.length>=2){
1761            out_params[sub_arg[0].trim()]=sub_arg[1];
1762        }else{
1763            out_params["BAD"]=arg_list[i];
1764        }
1765    }
1766    out_params.command=jwin.attr("command");
1767    return out_params;
1768};
1769
1770XXBK_base_ui.xxbk_list={};
1771//{dom_me:""}
1772XXBK_base_ui.Factory_byMe=function(ui_type,params_obj){
1773    var j_me = jQuery(params_obj.dom_me);
1774    var winid=j_me.attr("id");
1775    if(j_me.attr("init")!="n"){
1776        return XXBK_base_ui.xxbk_list[winid];
1777    }
1778
1779    j_me.attr("init","y");
1780    if(!XXBK_base_ui.GetObj(winid)){
1781        var params = XXBK_base_ui.Extract_bkparams(j_me);
1782
1783        params.dom_me=params_obj.dom_me;
1784        XXBK_base_ui.xxbk_list[winid]=new ui_type(params);
1785    }
1786    return XXBK_base_ui.xxbk_list[winid];
1787};
1788XXBK_base_ui.GetObj=function(winid){
1789    return XXBK_base_ui.xxbk_list[winid];
1790};
1791
1792
1793// javascript can use
1794XXBK_base_ui.prototype.create_ui=function(params_obj){
1795    var jdom_me=this.jdom_me;
1796    var winid=jdom_me.attr("id");
1797    var ori_txt = jdom_me.html();
1798
1799    var base_ui_txt='<span class="xxbk_base_title xxbk_tt_{0}" id="tt_{1}" >{2}</span> \
1800    <div class="xxbk_base_ct xxbk_ct_{0}" style="display: none" init="n"></div>\
1801    '.format(params_obj.command,winid,ori_txt);
1802    this.base_ui=jQuery(base_ui_txt);
1803
1804    jdom_me.html("");
1805    jdom_me.append(this.base_ui);
1806
1807    var call_ob=this;
1808    this.jdom_me.find("span.xxbk_base_title").click(function(){
1809
1810        var ct_div=call_ob.jdom_me.find("div.xxbk_base_ct");
1811        if(ct_div.length==0){
1812            call_ob.jdom_me.html("xxbk_base_ui was broken!please check the page!");
1813            return;
1814        }
1815        if(ct_div.attr("init")=='n') {
1816            call_ob.init_ct_div(ct_div,params_obj);
1817
1818        }
1819        ct_div.toggle();
1820    });
1821
1822};
1823
1824XXBK_base_ui.prototype.init_ct_div=function(ct_div_j){
1825    ct_div_j.html("how are you");
1826};
1827
1828XXBK_base_ui.prototype.getTitle=function(){
1829  return this.jdom_me.find(".xxbk_base_title").eq(0);
1830};
1831
1832XXBK_base_ui.prototype.getCTdiv=function(){
1833    return this.jdom_me.find(".xxbk_base_ct").eq(0);
1834};
1835
1836XXBK_base_ui.prototype.click_delay=function(xx_jq_list,call_back){
1837
1838    var call_ob=this;
1839    if(call_ob.wl_timer!=null){
1840        console.log("during timer");
1841        return;
1842    }
1843    console.log("click_delay");
1844
1845    // chick all object in jq_list ,and if they are all inited ,just  call_back and return
1846    var init_all=true;
1847    for(var i=0;i<xx_jq_list.length;i++){
1848        var jq_content=xx_jq_list[i].find("div.xxbk_base_ct");
1849        var jq_title=xx_jq_list[i].find(".xxbk_base_title");
1850
1851        if(jq_content.attr("init")!="y"){
1852            if(jq_title){
1853                jq_title.click();
1854            }
1855            init_all=false;
1856        }
1857    }
1858    if(init_all==true){
1859        call_back();
1860        return;
1861    }
1862
1863    // setInterval ,wait all ajax reday in jq_list
1864    call_ob.wl_timer=window.setInterval(function(){
1865        var init = true;
1866        for(var i=0;i<xx_jq_list.length;i++){
1867            var jq_content=xx_jq_list[i].find("div.xxbk_base_ct");
1868            if(jq_content.attr("init")!="y"){
1869                init=false;
1870                console.log("iam check init {0}".format(jq_content.attr("init")))
1871            }
1872
1873        }
1874        console.log("iam waiting")
1875
1876        if(init==true){
1877            call_back();
1878            window.clearInterval(call_ob.wl_timer);
1879            call_ob.wl_timer=null;
1880        }
1881
1882    },500);
1883
1884};
1885
1886
1887
1888// <<<<<<<<<<<<---------------syntax- block------------------------
1889// <<<<<<<<<<<<---------------syntax- block------------------------
1890// <<<<<<<<<<<<---------------syntax- block------------------------
1891// <<<<<<<<<<<<---------------syntax- block------------------------
1892
1893
1894function XXBK_slice(params_obj){
1895    XXBK_base_ui.call(this,params_obj);
1896    var jtitle=this.getTitle();
1897    var newtt = "{0} ~ {1} | {2}".format(params_obj.from,params_obj.to,jtitle.html());
1898    jtitle.html(newtt);
1899}
1900XXBK_slice.prototype=Object.create( XXBK_base_ui.prototype);
1901XXBK_slice.prototype.init_ct_div= function(ct_div_j,params_obj){
1902    var call_ob=this;
1903    var jq_xxbk_wl=jQuery(".xxbk_type_wordlist");
1904    this.click_delay([jq_xxbk_wl],function(){
1905        call_ob.show_slice(ct_div_j,params_obj);
1906    });
1907};
1908
1909
1910XXBK_slice.prototype.show_slice= function(ct_div_j,params_obj){
1911
1912    var jq_wordlist=jQuery(".wordlist");
1913    if(jq_wordlist.length>0) {
1914        var wd_txt = jq_wordlist.text();
1915        var s_from = params_obj.from;
1916        var s_to = params_obj.to;
1917        var tmp="\\b{0}\\b.+\\b{1}\\b".format(s_from, s_to);
1918
1919        var reg_sr = new RegExp(tmp);
1920        var rt = wd_txt.match(reg_sr);
1921        if (rt) {
1922            ct_div_j.html(rt[0]);
1923        }else{
1924            ct_div_j.html("!!! Maybe The slice words was deleted from the wordlist,please choose another word to slice");
1925        }
1926    }
1927};
1928
1929
1930
1931
1932// <<<<<<<<<<<<<<-----------------cp sidebar -------------------
1933
1934function XXBK_newTpl(params_obj){
1935    XXBK_base_ui.call(this,params_obj);
1936}
1937XXBK_newTpl.prototype=Object.create( XXBK_base_ui.prototype);
1938XXBK_newTpl.prototype.init_ct_div=function(ct_div_j,params_obj) {
1939    var tpl=params_obj.template;
1940    var call_ob=this;
1941
1942    ajax_xcall("tp.newtpl",[tpl],function(data){
1943        var dst_page=data.result;
1944        if(dst_page){
1945            window.location="/{0}?do=edit".format(dst_page);
1946        }else{
1947            if(data.error){
1948                ct_div_j.html(data.error.data);
1949            }
1950        }
1951        ct_div_j.attr("init",'y');
1952    });
1953};
1954
1955
1956//<<<<<<<<<<<<<<<<<<<-----------xxbk_open------------------------
1957
1958function XXBK_open(params_obj){
1959    XXBK_base_ui.call(this,params_obj);
1960}
1961XXBK_open.prototype=Object.create( XXBK_base_ui.prototype);
1962XXBK_open.prototype.init_ct_div=function(ct_div_j,params_obj){
1963    XXBK_base_ui.prototype.init_ct_div.call(this,ct_div_j);
1964    ct_div_j.html(ct_div_j.html()+" <br/> i am XXBK_open");
1965
1966    var pageid=params_obj.page;
1967    var call_ob=this;
1968
1969    // some init for framework
1970    switch (params_obj.type){
1971        case "wordlist":
1972            ct_div_j.addClass("wordlist");
1973            this.jdom_me.addClass("xxbk_wordlist");
1974            break;
1975        default :
1976            break;
1977    }
1978
1979    ajax_xcall("wiki.getPageHTML",[pageid],function(data){
1980
1981        ct_div_j.html(data.result);
1982        var js_div=ct_div_j[0];
1983
1984        // some init for content
1985        switch (params_obj.type){
1986            case "wordlist":
1987                break;
1988            default :
1989                init_ui(js_div);
1990                init_mxyd_voice(".wrap_vo","y");
1991                break;
1992        }
1993        ct_div_j.attr("init",'y');
1994    });
1995};
1996//<<<<<<<<<<<<<<<<<<<<<<
1997
1998
1999function syntax_BK_init(context) {
2000    var sel_txt = parent+".xxbk";
2001    jQuery(".xxbk",context).each(function (index, element) {
2002    //element == this
2003    //    var class_txt = jQuery(this).attr("class");
2004    //    var ctype = class_txt.match(/\bxxbk_[\w]+\b/);
2005        var command = jQuery(this).attr("command");
2006
2007        if(command){
2008            switch (command){
2009                case "slice":
2010                    XXBK_base_ui.Factory_byMe(XXBK_slice,{dom_me:element});
2011                    break;
2012                case "newtpl":
2013                    XXBK_base_ui.Factory_byMe(XXBK_newTpl,{dom_me:element});
2014                    break;
2015                case "open":
2016                    XXBK_base_ui.Factory_byMe(XXBK_open,{dom_me:element});
2017                    break;
2018            }
2019        }
2020    });
2021}
2022
2023//<<<<<<<<<<<<<<<<<<<< ------ things execute in php!!----------
2024function init_pagetools(){
2025    var jwin=jQuery(".pt_pa_sub");
2026    jwin.appendTo("body");
2027    var theul=jwin.find("ul").eq(0);
2028    theul.find("li").each(function(){
2029        var subdiv=jQuery(this).children("div");
2030        var subhm =subdiv.html();
2031        subdiv.remove();
2032        jQuery(this).html(subhm+jQuery(this).html());
2033    });
2034    theul.menu();
2035    var anck = jQuery(".pt_pagetools");
2036    var oset= anck.offset();
2037    oset.left+=anck.offsetParent().width()+10;
2038    jwin.offset(oset);
2039
2040
2041    jQuery(".pt_pagetools").click(function(event){
2042        event.preventDefault();
2043        event.stopPropagation();
2044        jQuery(".pt_pa_sub").toggle();
2045        jQuery(this).blur();
2046    });
2047}
2048
2049
2050
2051function init_ui(context){
2052    /*
2053    var divstr='<div id="{0}_rt"><div id="{0}_txtout"></div> <div style="clear: both"></div>\
2054     <input id="{0}_ok" name="ok" class="button" type="button" value="ok">\
2055        <input id="{0}_cancel" class="button" type="button" value="cancel"> </div> '.format("openpage");
2056        */
2057
2058//    alert(jQuery("html").hasClass("phone"));
2059
2060    USER_WORDLIST_NAME = 'user:'+JSINFO['user']+":wordlist";
2061    WORDLIST_NAME=JSINFO['wordlist_ns']+"wordlist";
2062
2063
2064    ptlog=new PTlog();
2065
2066    init_pagetools();
2067    syntax_BK_init(context);
2068    pg_show_wordlist(context);
2069    Init_english_edit_tool();
2070    jQuery(" .xxpg_learn",context).click(search_learn_win);
2071    jQuery(" .xxpg_parse",context).click(parse_learn_win);
2072    jQuery(" .xxpg_open",context).click(open_page_win);
2073    jQuery(" .xxpg_words",context).click(addnewwords_win);
2074    jQuery(" .xxpg_twoedit",context).click(Two_edit_win);
2075    jQuery(" .xxpg_checkwords",context).click(Make_Checkwords_Win);
2076    jQuery(" .xxpg_test",context).click(Make_XXtest_Win);
2077    jQuery(" .xxpg_card",context).click(Make_wordcard_win);
2078    ptlog.log("hello");
2079
2080}
2081
2082jQuery(function(){
2083
2084    // jQuery methods go here...
2085    init_ui();
2086});
2087