PageSourceSearch

https://www.hkicpa.org.hk/js/bookmark.js

js hkicpa.org.hk collected 2026-09-24 19:25:03 UTC 8,057 bytes, 211 lines download raw bytes

1var bookmark = {
2    j:"", //"#fixtop .btbkmk,#mtophead+.lybkmk",
3    b:".jbtbkmk",
4    c:"cpabkmks", //cookie name
5    a:{}, //#url:#title
6    exp: 365, //cookie expire days
7    bts: "#recmd em.fa,#htabcts em.fa-bookmark-o,#breadcrumb>.ico em.fa,#module em.fa-bookmark-o,#newsidx em.fa-bookmark-o",
8    prop:function(b) { //{url,title}
9        var j = { url:"",title:""};
10        
11        if (b.closest("#htabcts").length>0) { //homepage <> blk bkmk
12            j.title = b.siblings("h4").html();
13            var a = b.siblings("a");
14            if (a.length>0 && a[0].hasAttribute("href")) j.url=a.attr('href');
15        } else if (b.closest("#recmd").length>0) { //homepage recmd
16            var p = b.parent();
17            j.title = p.find("div h3").html();
18            var a = p.find("div a");
19            if (a.length>0 && a[0].hasAttribute("href")) j.url=a.attr('href');
20        } else if (b.closest("#breadcrumb").length>0) { //inside|breadcrumb bk
21            j.url=location.pathname;
22            j.title=$("head>title").text();
23        } else if (b.closest("#module").length>0 && b.closest(".mbx").length>0) { 
24            //learn-index | module mbx
25            var a = b.closest(".mbx");
26            j.url = a.attr('href');
27            j.title = a.find("h3").text();            
28        } else if (b.closest("#module").length>0 && b.closest(".m").length>0) { 
29            //learn-index | module mlist item
30            var a = b.closest(".m");
31            j.url = a.attr('href');
32            j.title = a.find(".lay em").text();            
33        } else if (b.closest("#ntcframe").length>0) { 
34            //learn-index | notice board            
35            var a = b.closest(".itm");
36            j.url = a.attr('href');
37            j.title = a.find("div.intro").text();      
38        } else if (b.closest("#newsidx").length>0) { 
39            j.title = b.parent().text();
40            j.url = b.closest('div.wrap').parent().attr('href');
41        } else {
42            //console.log('bookmark prop def');
43        }
44        return j;
45    },
46    okopen:function() {
47        return ($(".btfind.open").length>0)?false:true;
48    },
49    open:function() {
50        if (this.okopen()) {
51            $(this.j).addClass('go');
52            //$(this.j).find("input").eq(0).focus();
53            $(this.b).addClass('open');
54        }
55    },
56    close:function() {
57        $(this.j).removeClass('go');
58        $(this.b).removeClass('open');
59    },
60    trigger:function(t) {
61        this.j=($(t).closest("#fixtop").length>0)?"#fixtop .lybkmk":"#mtophead+.ddsearch+.lybkmk";
62        if ($(this.j).hasClass('go'))  this.close();
63        else  { this.open();
64            if ($(t).is(":focus") && $(t).hasClass('smtopbkmk')) {
65                console.log('chkall focus');
66                $('#fixtop .ddsearch+.lybkmk input[name=chkall]').focus();
67            }
68        }
69    },
70    write:function() { //write to layer and cookie
71        var num = Object.keys(this.a).length;
72        $(".lybkmk>h3>p").html("<strong>TOTAL: </strong>" + num + " Bookmarks");
73        var h="";
74        for (var u in this.a) {
75            h+="<li><input type='checkbox' onclick='bookmark.trgchk(this);' value=\""+u+"\"/>";
76            h+="<a href='"+u+"'>"+this.a[u]+"</a></li>";
77        }
78        $(".lybkmk>ul").html(h);
79        $(".lybkmk>p>span").text(0);
80        $(".lybkmk>h3>input").prop('checked', false);
81        $.cookie(this.c,JSON.stringify(this.a), { expires:this.exp, path: "/" });
82    },
83    read:function(dow) {
84        var t = $.cookie(this.c);
85        if (t!=undefined) this.a=JSON.parse(t);
86        if (dow) this.write();
87        /*$(this.bts).each(function() {
88            var p = bookmark.prop($(this));
89            if (bookmark.a.hasOwnProperty(p.url) && !$(this).hasClass('sel')) {
90                $(this).addClass('sel');
91            }
92        });*/
93        this.chkbts();
94    },
95    add:function(bt,pty) {
96        if (!bt.hasClass('sel')) bt.addClass('sel');
97        if (!this.a.hasOwnProperty(pty.url)) this.a[pty.url]=pty.title;
98        this.write();
99        bookmark.chkbts();
100		if ("ga" in window) {
101			tracker = ga.getAll()[0];
102			if (tracker)
103				tracker.send('event', 'Bookmark', 'Click', 'Bookmark - '+pty.title+' - '+pty.url);
104		}
105    },
106    del:function(bt,pty) {
107        if (bookmark.a.hasOwnProperty(pty.url)) {
108            delete bookmark.a[pty.url];                
109            bookmark.write();
110            bookmark.chkbts();
111			if ("ga" in window) {
112				tracker = ga.getAll()[0];
113				if (tracker)
114					tracker.send('event', 'Bookmark', 'Click', 'UnBookmark - '+pty.title+' - '+pty.url);
115			}
116        }        
117    },
118    setbt:function(bt) {
119        if (isCookieAccepted()) {
120            bt.off('click keyup');
121            bt.on('click keyup',function(e) {
122                e.stopPropagation();
123                if (e.type=="click" || e.which==13) {
124                    if ($(this).hasClass('sel')) { //remove bookmark
125                        bookmark.del($(this),bookmark.prop($(this)));
126                    } else { //add to bookmark
127                        bookmark.add($(this),bookmark.prop($(this)));
128                    }
129                }
130            });
131        }
132    },
133    trgchk:function(t) {
134        var ul = $(t).closest('ul');
135        var lis = ul.find("li>input");
136        var all = ul.prev("h3").children("input");
137        var len = ul.find("li>input:checked").length;
138        if ($(t).is(":checked")) {
139            if (lis.length==len) all.prop('checked', true); 
140        } else {                
141            all.prop('checked', false); 
142        }
143        $(t).closest(".lybkmk").find("p>span").text(len);
144    },
145    setlayer:function() {
146        //set select all
147        $(".lybkmk>h3>input").on("click",function() {
148            var lis = $(this).parent().next("ul").find("input");
149            var len=0;
150            if ($(this).is(":checked")) {  
151                lis.prop('checked', true); //check all
152                len = lis.length;
153            } else {                
154                lis.prop('checked', false); //uncheck all
155            }            
156            var span = $(this).parent().next("ul").next('p').find("span");
157            span.text(len);
158        });
159        //set trash
160        $(".lybkmk>p>em.fa").on("click",function() {
161            var ul = $(this).parent().prev('ul');
162            
163            ul.find("li>input:checked").each(function() {
164                var a = $(this).next('a');
165                var u = "";
166                if (a[0].hasAttribute("href")) u=a.attr('href');
167                if (u!="" && bookmark.a.hasOwnProperty(u)) {
168					if ("ga" in window) {
169						tracker = ga.getAll()[0];
170						if (tracker) { 
171							tracker.send('event', 'Bookmark', 'Click', 'UnBookmark - '+bookmark.a[u]+' - '+u);
172                        }
173					}
174					delete bookmark.a[u];                
175				}
176            });
177            bookmark.write();
178            bookmark.chkbts();
179        });
180    },
181    genchkbts:function(bts) {
182        $(bts).each(function() {
183            var p = bookmark.prop($(this));            
184            if (bookmark.a.hasOwnProperty(p.url) && !$(this).hasClass('sel')) {
185                $(this).addClass('sel');
186            } else if (!bookmark.a.hasOwnProperty(p.url) && $(this).hasClass('sel')) {
187                $(this).removeClass('sel');
188            }
189        });
190    },    
191    chkbts:function() { this.genchkbts(this.bts);
192        /*$(this.bts).each(function() {
193            var p = bookmark.prop($(this));
194            if (bookmark.a.hasOwnProperty(p.url) && !$(this).hasClass('sel')) {
195                $(this).addClass('sel');
196            } else if (!bookmark.a.hasOwnProperty(p.url) && $(this).hasClass('sel')) {
197                $(this).removeClass('sel');
198            }
199        });*/
200    },    
201    init:function() { 
202        if (isCookieAccepted()) {    
203            //console.log('bkmk init');
204            //this.setbt($("#recmd i.fa,#breadcrumb i.fa-bookmark-o"));
205            this.setbt($(this.bts));
206            this.read(true);
207            this.setlayer();
208        }
209    }
210}
211

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.