PageSourceSearch

https://www.edigest.hk/wp-content/plugins/nmg-email-subscription/js/subscription.js?ver=2.0.19

js edigest.hk collected 2026-09-24 09:25:26 UTC 15,663 bytes, 307 lines download raw bytes

1var email_status = true;
2(function($) {
3
4    var display_list = $(".module-subcribe"),
5        display_mode = 1;// ed site 暫時只有after content 模式
6    if(display_list.length>0){
7        display_mode = $(display_list[0]).attr('display_mode');
8    }
9
10    subscription = {
11        popup : $(".popup_box_edm"),
12        sid : $("[name='subscription_id']").val(),
13        shadow : $(".shadow_edm"),
14        win_height : 0,
15        win_scroll_top : 0,
16        tmp_top: 0,
17        status : 1,
18        timer : null,
19        show_popup : function(){
20            //$("body").css({height: "100%", overflow: "hidden"});
21            $(window).unbind("touchmove");
22            $(window).bind("touchmove", function(e) {
23                e.preventDefault();
24            });
25            this.shadow.css({height: "100%"});
26            this.popup.css({top: this.win_height + "px"});
27            this.popup.stop(true).show();
28            this.popup.animate({top: (this.win_height - this.popup.height())/2 + 'px'}, 500);
29			var step = $(".step_num").attr('id').substr(5, 1);
30			show_virtual_page(step);
31        },    
32        hide_popup : function(){
33            var the = this;
34            $(window).unbind("touchmove");
35            $(window).bind("touchmove",function(e){
36                e.preventDefault = false;
37            });
38			the.shadow.css({height:0});
39            this.popup.animate({top: this.win_height + "px", bottom: "-" + this.win_height + "px"}, 500, function(){
40                the.popup.stop(true).hide();
41                // $("body").removeAttr("style");
42				//$("body").scrollTop(the.win_scroll_top);
43            });
44            if(!Cookies.get(subscriptionL10n.subscription_cookie_prefix+'_'+this.sid)){
45                if(parseInt(subscriptionL10n.subscription_guests_cookie_expiry)){
46                    Cookies.set(subscriptionL10n.subscription_cookie_prefix+'_'+this.sid, '1', { expires: parseInt(subscriptionL10n.subscription_guests_cookie_expiry) });
47                }else{
48                    //Cookies.set(subscriptionL10n.subscription_cookie_prefix+'_'+this.sid, '1');
49                }
50            }
51        },
52        loop : function(){
53            this.win_height = $(window).height();
54            this.win_scroll_top = $(window).scrollTop();
55            if(this.status==0){
56                return;
57            }
58            if(this.win_scroll_top+this.win_height>($('#nmg_subscription').offset().top)){
59                this.status = 0;
60                this.timer = setTimeout("subscription.show_popup();", subscriptionL10n.subscription_popup_delay*1000);
61            }
62        },
63        textFocus: function() {
64            if(!subscription.isAndroid())
65                return;
66            $(window).unbind("touchmove");
67            $(window).bind("touchmove",function(e){
68                e.preventDefault = false;
69            });
70            subscription.tmp_top = $(".popup_box_edm").css("top");
71            $(".popup_box_edm").css({"position": "absolute", "top": $(".popup_box_edm").offset().top + "px"});
72        },
73        textBlur: function() {
74            if(!subscription.isAndroid())
75                return;
76            $(window).unbind("touchmove");
77            $(window).bind("touchmove", function(e) {
78                e.preventDefault();
79            });
80            $(".popup_box_edm").css({"position": "fixed", "top": subscription.tmp_top});
81        },
82        isAndroid: function(){
83            var u = navigator.userAgent;
84            return (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1);
85        },
86        form : function(_the_form, step, nonce){
87            switch(step){
88                case 4:
89					if(!email_status){
90                        return false;
91                    }
92
93                    var sub_id = $(_the_form).parent().parent().attr('data-sub_id'),
94                        cat_name = subscriptionL10n.subscription_cat_name,
95                        tag_name = '';
96                    var tag_sub_form_element = $(_the_form).parent().parent();
97                    var tag_name_temp = tag_sub_form_element.data('cms_tag_name_list');
98                    if(tag_name_temp){
99                        cat_name = 'tag';//如果系tag for subscription 則 enews system中的 category 為固定的值'tag';
100                        tag_name = tag_name_temp;
101                        sub_id = tag_sub_form_element.data('sub_id'); //如果同時有cat and tag subscription,sid要區分
102                    }
103                    
104                    var _email_ct_bool = true;
105                    if(display_mode==1){//after content
106                        var _the_subscription_frame_id = $(_the_form).parent().parent().attr('id');
107                        console.log('_the_subscription_frame_id'+_the_subscription_frame_id);
108                        var email = $("#"+_the_subscription_frame_id+" [name='email']").val().trim();
109                    }else{
110                        var email = $("#subscription_frame [name='email']").val();
111                    }
112        
113                    //验证邮箱:
114                    if(!email){
115                         _email_ct_bool = false;
116                        error_msg = '電郵地址不能为空';
117                    }else{
118                        if (!(/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(email))) {
119                            _email_ct_bool = false;
120                            error_msg = '請輸入正確的電郵地址';
121                        }
122                    }
123
124                    if(_email_ct_bool && display_mode==1){
125                        var checkbox_list = $("#"+_the_subscription_frame_id).find(".ed-checkbox-input");
126                        if(checkbox_list.length > 0){
127                            $.each(checkbox_list, function(i,e){
128                                if($(this).is(':checked')){
129                                    _email_ct_bool = true;
130                                }else{
131                                    _email_ct_bool = false;
132                                    error_msg = '請同意以上條款及細則';
133                                    return false;
134                                }
135                            });
136                        }           
137                    }
138                    //console.log(email);return false;
139                    var subscription_email_template = $("input[name='subscription_email_template']").val();
140                    if(_email_ct_bool){
141                        email_status = false;
142                        var data = { 'action' : 'apply-subscription', 'step' : '4', 'email' : email, 'sid' : sub_id, '_ajax_nonce' : nonce, 'subscription_email_template' : subscription_email_template, 'cat_name' : cat_name, 'tag_name' : tag_name};
143                        $.ajax({
144                            type: "POST",
145                            url: subscriptionL10n.ajax_url,
146                            data:data,
147                            dataType:'json',
148                            success: function(response){
149                                if(response.status=='1'){
150                                    if(!Cookies.get(subscriptionL10n.subscription_cookie_prefix+'_'+subscription.sid)){
151                                        if(parseInt(subscriptionL10n.subscription_registered_cookie_expiry)){
152                                            Cookies.set(subscriptionL10n.subscription_cookie_prefix+'_'+subscription.sid, '1', { expires: parseInt(subscriptionL10n.subscription_registered_cookie_expiry) });
153                                        }else{
154                                            //Cookies.set(subscriptionL10n.subscription_cookie_prefix+'_'+subscription.sid, '1');
155                                        }
156                                    }
157                                    if(display_mode==1){//after content
158                                        $("#"+_the_subscription_frame_id).html(response.html);
159                                    }else{
160                                        $('#subscription_frame').empty();
161                                        $('.popup_edm').addClass('popup3_edm');
162                                        $('#subscription_frame').html(response.html).css('padding','20px');
163                                    }
164                                    //$('#subscription_frame').empty();
165                                    //$('.popup_edm').addClass('popup3_edm');
166                                    //$('#subscription_frame').html(response.html);
167                                    // $("#"+_the_subscription_frame_id).html(response.html);
168                                    email_status = true;
169                                }
170                            }
171                        });
172						show_virtual_page(step);
173                    }else{
174                       //alert(subscriptionL10n.text_invalid_email);
175                        alert(error_msg);
176                    }
177                    break;
178                default:
179            }
180        }
181    }
182	
183
184
185
186    //modify:2019.9.23
187    $(window).on('article.readmore', function(event, data){
188        //var post_id_subscribe =  NMGLazyLoad._post['currID'];
189        if(display_mode == 1){// show after content
190            var id_str = data.attr('id');
191            var post_id_subscribe = id_str.substr(5);
192            var sticky_subscribe_form_id = 'subcription_form_'+post_id_subscribe;
193            var subscription_form = $(".widget_subscribe_source");
194            //var tag_subscription_form = $(".tag_subscribe_source");
195            var post_tag_name_list_str = $("#tag_position_" + post_id_subscribe).data('tag_name_list');// post tag names
196            var post_tag_name_list_arr = (post_tag_name_list_str.toString()).split(",");
197
198            var tag_sub_bool = false,
199                cat_sub_bool = false,
200                not_tag_and_cat_bool = false,
201                prefix = '',
202                target_tag_name = [],//收集tag name list:
203                subscription_index = null,
204                not_tag_and_cat_subscription_index = null;
205
206            if(subscription_form.length > 0){
207
208                //1、check tag name 是否匹配
209                $.each( subscription_form, function( i, e ) {
210
211                    var cms_tag_name_list_str = $(e).data('cms_tag_name_list');//setting tag names
212                    var cms_cat_ids_list_str = $(e).data('cms_cat_ids_list');//setting cat ids:
213
214                    if(cms_tag_name_list_str == '' && cms_cat_ids_list_str == ''){//如果該subscription 的category AND tag 都係空值,則為一個默認的layout
215                        not_tag_and_cat_bool = true;
216                        not_tag_and_cat_subscription_index = i;
217                    }
218    
219                    var cms_tag_name_list_arr = (cms_tag_name_list_str.toString()).split(",");    
220
221                    $.each( cms_tag_name_list_arr, function( key, value ) {//subscription for tag
222                        if( $.inArray( value, post_tag_name_list_arr ) !== -1 ){
223                            tag_sub_bool = true;
224                            target_tag_name.push(value);
225                        }
226                    });
227                    if(tag_sub_bool){
228                        subscription_index = i;     
229                        return false;//相当 break
230                    }
231                });
232
233                /////////////////显示匹配到的tag name的subscription box:
234                if(tag_sub_bool){
235                    //console.log("tag checked");      
236                    $("#tag_position_" + post_id_subscribe).parent().find("._content_").after($(subscription_form[subscription_index]).clone().css('display','block').attr('id', sticky_subscribe_form_id).attr('data-cms_tag_name_list', target_tag_name.join(',')).removeClass('widget_subscribe_source'));
237                }
238
239                // 2、check cat id 是否匹配
240                if(!tag_sub_bool){
241                    $.each( subscription_form, function( i, e ) {
242                        var post_lazy_cat_id = $(e).data('lazy_category');//lazy cat id
243                        console.log('post_lazy_cat_id: '+post_lazy_cat_id);
244
245                        var cms_cat_ids_list_str = $(e).data('cms_cat_ids_list');//setting cat ids:
246                        var cms_cat_ids_list_str_arr = (cms_cat_ids_list_str.toString()).split(","); 
247                        console.log('cms_cat_ids_list_str_arr: '+cms_cat_ids_list_str_arr);               
248                        //注意:Value值得类型 如果Vlaue是int类型的值 判断时转换成字符串类型
249                        post_lazy_cat_id = post_lazy_cat_id.toString();
250                        if( $.inArray( post_lazy_cat_id, cms_cat_ids_list_str_arr ) !== -1 ){
251                            cat_sub_bool = true;
252                        }             
253                        if(cat_sub_bool){
254                            subscription_index = i;
255                            return false;
256                        }
257                    });
258                    if(cat_sub_bool){
259                        console.log("category checked");      
260                        $("#tag_position_" + post_id_subscribe).parent().find("._content_").after($(subscription_form[subscription_index]).clone().css('display','block').attr('id', sticky_subscribe_form_id).removeAttr('data-cms_tag_name_list').removeClass('widget_subscribe_source'));
261                    }
262                }
263
264                // 3.如果cat和tag都没有set,则出其中一个没set的:
265                if(!tag_sub_bool && !cat_sub_bool && not_tag_and_cat_bool){
266                    //console.log("not cat/tag checked");
267                    $("#tag_position_" + post_id_subscribe).parent().find("._content_").after($(subscription_form[not_tag_and_cat_subscription_index]).clone().css('display','block').attr('id', sticky_subscribe_form_id).removeAttr('data-cms_tag_name_list').removeClass('widget_subscribe_source'));
268                }
269            }   
270        }     
271    });
272
273    // ######### homepage subscription: ##############
274    if(subscriptionL10n.subscription_type == 'homepage'){
275        var homepage_subcription_form = $(".widget_subscribe_source");
276        var homepage_sticky_subcribe_form_id = '_homepage_subcription_form_01';
277        if(homepage_subcription_form.length>0){
278             if(is_mobile=='Mobile'){ //for mobile
279                $(".featured-area").eq(1).after($(homepage_subcription_form[0]).clone().css('display','block').attr('id', homepage_sticky_subcribe_form_id).removeClass('widget_subscribe_source'));;
280            }else{// for main sidebar
281                homepage_sticky_subcribe_form_id = '_homepage_subcription_form_02';
282                $(".widget_widget_for_homepage_subcription").empty().after($(homepage_subcription_form[0]).clone().css('display','block').attr('id', homepage_sticky_subcribe_form_id).removeClass('widget_subscribe_source'));
283            }
284            
285        }
286    }   
287    
288})(jQuery);
289
290function show_virtual_page(step){
291	var a_qa = ["01_question","02_request_email", "03_preference", "04_thankyou_page", "04_thankyou_page"];
292	if (typeof(_gaq) != 'undefined') {
293		_gaq.push(['_trackPageview', 'edm_subscription/'+a_qa[step]+window.location.pathname]);
294		//return;
295	}
296	if (typeof(__gaTracker) != 'undefined') {
297		__gaTracker('send', 'pageview', 'edm_subscription/'+a_qa[step]+window.location.pathname);
298		return;
299	}
300    if (typeof(dataLayer) != 'undefined') {
301        dataLayer.push({
302            'event':'VirtualPageview',
303            'virtualPageURL': 'edm_subscription/'+a_qa[step]+window.location.pathname
304        });
305        return;
306    }
307}

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.