PageSourceSearch

https://skyline.tw/assets/js/activity/_exploreActivity.js?v=1.14

js skyline.tw collected 2026-10-07 22:03:57 UTC 14,864 bytes, 322 lines download raw bytes

1(function (Skyline) {
2    Skyline.activity = Skyline.activity || {};
3    Skyline.activity.exploreActivity = Skyline.activity.exploreActivity || {};
4
5    Skyline.activity.exploreActivity = function ($App) {
6        this.$.$App = $App;
7    };
8
9    var typingTimer,
10        sortTimer;
11
12    Skyline.activity.exploreActivity.prototype = {
13        constructor: Skyline.activity.exploreActivity,
14
15        // DOM 物件
16        $ : {
17            template : {}
18        },
19        // 變數
20        variable: {
21            filter : {
22                category : [],
23                region : [],
24                price : [],
25                duration : [],
26                start_at : [],
27                end_at : [],
28                time_filter : [],
29                keywords : '',
30            }
31        },
32        // 初始化
33        init: function () {
34            this.initDom();
35            this.bind();
36        },
37        initDom: function () {
38            this.$.$datepicker = this.$.$App.find('.datepicker');
39            this.$.$StartAt = this.$.$App.find('#start_at');
40            this.$.$EndAt = this.$.$App.find('#end_at');
41            this.$.$TimeFilter = this.$.$App.find('#time_filter');
42            this.$.$Keywords = this.$.$App.find('.activity_keywords_filter')
43            this.$.$ActivityExploreBtn = this.$.$App.find('.activity_explore_btn');
44            // this.$.$AvatarImage = this.$.$App.find('#avatar_image');
45            // 過濾器
46            this.$.$ActivityExploreFilter = {};
47            this.$.$ActivityExploreFilter.category = this.$.$App.find('.activity_category_explore_filter');
48            this.$.$ActivityExploreFilter.region = this.$.$App.find('.activity_region_explore_filter');
49            this.$.$ActivityExploreFilter.price = this.$.$App.find('.activity_price_explore_filter');
50            this.$.$ActivityExploreFilter.duration = this.$.$App.find('.activity_duration_explore_filter');
51            
52
53        },
54        // 綁定事件
55        bind: function () {
56            var _this = this;
57            this.bindCollection.Datepicker.init(this);
58            this.bindCollection.ActivityExplore.init(this);
59        },
60        saveExploreParameter : function () {
61            var filter = this.variable.filter,
62                start_at = this.$.$StartAt.val(),
63                end_at = this.$.$EndAt.val();
64
65            if (start_at && end_at) {
66                var is_before_at = moment(start_at).isBefore(end_at);
67                if (!is_before_at) {
68                    alert('結束日期必須在開始日期之前');
69                    this.$.$EndAt.val(start_at);
70                    return;
71                }
72            }
73
74            this.variable.filter.start_at = this.$.$StartAt.val();
75            this.variable.filter.end_at = this.$.$EndAt.val();
76            this.variable.filter.time_filter = this.$.$TimeFilter.val();
77            this.variable.filter.keywords = this.$.$Keywords.val();
78            var saveExplore = {
79                category : filter.category,
80                region : filter.region,
81                price : filter.price,
82                duration : filter.duration,
83                time_filter : this.$.$TimeFilter.val(),
84                start_at : this.$.$StartAt.val(),
85                end_at : this.$.$EndAt.val(),
86                keywords : this.$.$Keywords.val()
87            };
88            // console.log(saveExplore);
89            store.set('activity_explore', saveExplore);
90            console.log(store.get('activity_explore'));
91        },
92        bindCollection : {
93            ActivityExplore : {
94                parent : null,
95                init : function (parent) {
96                    this.parent = parent;
97                    this.initStoreExplore();
98                    this.bindActivityExplore();
99                },
100                initStoreExplore : function () {
101                    var _this = this.parent;
102                    var saveExplore = store.get('activity_explore'),
103                        $ExploreSection, explore_section_name, type_name, type_id,
104                        url_param;
105
106                    // console.log(saveExplore);
107
108                    if (saveExplore) {
109                        for (type_name in saveExplore) {
110                            if (saveExplore.hasOwnProperty(type_name)) {
111                                // 類型編號
112                                type_id = saveExplore[type_name];
113
114                                if (typeof type_id == 'string') {
115                                    // 舊版單選,移除舊版資料
116                                    // store.remove('activity_explore');
117                                    type_id = [type_id];
118                                }
119
120                                // 取得網址列參數資料
121                                url_param = '?' + type_name;
122                                url_type_id = url(url_param);
123                                if (url_type_id) {
124                                    console.log(url_type_id);
125                                    // 網址有類型資料,將類型資料轉換為陣列
126                                    url_type_id = url_type_id.split(',');
127                                } else {
128                                    // 網址沒有類型資料
129                                    url_type_id = [];
130                                }
131
132                                if (url_type_id.length) {
133                                    // 網址有類型資料,以網址為主
134                                    type_id = url_type_id;
135                                }
136                                // console.log(type_id);
137                                // 設定最新參數
138                                _this.variable.filter[type_name] = type_id;
139
140                                if (type_id.length) {
141                                    // 有類型資料,移除不限
142                                    explore_section_name = 'activity_' + type_name + '_explore_filter_0';
143                                    $ExploreSection = _this.$.$App.find('#' + explore_section_name).removeClass('BodySelect');
144                                    // 有類型資料
145                                    type_id.forEach(function(val){
146                                        // console.log(val);
147                                        // 類型區塊名稱
148                                        explore_section_name = 'activity_' + type_name + '_explore_filter_' + val;
149                                        // 選擇該區塊
150                                        $ExploreSection = _this.$.$App.find('#' + explore_section_name).addClass('BodySelect');
151                                    });
152                                }
153
154                            }
155                        }
156
157                        // 儲存最新參數
158                        _this.saveExploreParameter();
159
160                        if (saveExplore.start_at) {
161                            _this.$.$StartAt.val(saveExplore.start_at);
162                        }
163                        if (saveExplore.end_at) {
164                            _this.$.$EndAt.val(saveExplore.end_at);
165                        }
166                        if (saveExplore.time_filter) {
167                            _this.$.$TimeFilter.val(saveExplore.time_filter);
168                        }
169                        if (saveExplore.keywords) {
170                            _this.$.$Keywords.val(saveExplore.keywords);
171                        }
172                    }
173
174                },
175                bindActivityExplore : function () {
176                    var _this = this.parent;
177
178                    Skyline.$.$document.on('click', ".activity_explore_btn", function (event) {
179                        Skyline.Util.eventStop(event); // 阻止冒泡
180                        filter = _this.variable.filter;
181                        console.log(filter);
182                        var param = [],
183                            param_item;
184                        for (type_name in filter) {
185                            if (filter.hasOwnProperty(type_name)) {
186                                param_item = '';
187                                console.log(typeof filter[type_name], filter[type_name]);
188                                if (typeof filter[type_name] == 'object' && filter[type_name].length) {
189                                    param_item = type_name + '=' + filter[type_name].join(',');
190                                }
191                                if (typeof filter[type_name] == 'string' && filter[type_name].length) {
192                                    param_item = type_name + '=' + filter[type_name];
193                                }
194                                if (param_item.length) {
195                                    param.push(param_item);
196                                }
197                            }
198                        }
199                        param = param.join('&');
200
201                        var url = location.origin + location.pathname + '?' + param;
202                        window.location = url;
203                    });
204
205                    Skyline.$.$document.on('change', "#time_filter", function (event) {
206                        Skyline.Util.eventStop(event); // 阻止冒泡
207                        _this.saveExploreParameter.bind(_this)();
208                        _this.$.$ActivityExploreBtn.trigger('click');
209                    });
210
211                    Skyline.$.$document.on('change', ".activity_time_explore_filter", function (event) {
212                        Skyline.Util.eventStop(event); // 阻止冒泡
213                        _this.saveExploreParameter.bind(_this)();
214                    });
215
216                    Skyline.$.$document.on('change', ".activity_keywords_filter", function (event) {
217                        Skyline.Util.eventStop(event); // 阻止冒泡
218                        _this.saveExploreParameter.bind(_this)();
219                    });
220
221                    Skyline.$.$document.on('click touchend', ".activity_explore_filter", function (event) {
222                        Skyline.Util.eventStop(event); // 阻止冒泡
223                        var type_name = this.dataset.type,
224                            type_id = this.dataset.id,
225                            explore_section_name;
226                        var $this = $(this);
227
228                        if ($this.hasClass('BodySelect')) {
229                            $action = 'remove';
230                        } else {
231                            $action = 'add';
232                        }
233
234
235                        // if (_this.$.$ActivityExploreFilter[type_name]) {
236                        //     // 將所有此類別選擇取消
237                        //     _this.$.$ActivityExploreFilter[type_name].removeClass('BodySelect');
238                        // }
239
240                        switch ($action) {
241                            // 移除
242                            case 'remove':
243                                if (type_id == 0) {
244                                    // 不能移除不限
245                                } else {
246                                    $this.removeClass('BodySelect');
247                                    _this.variable.filter[type_name] = Skyline.Util.splice(type_id, _this.variable.filter[type_name]);
248
249                                    if (!_this.variable.filter[type_name].length) {
250                                        // 如果沒有選擇任何類別,將設定為不限
251                                        explore_section_name = 'activity_' + type_name + '_explore_filter_0';
252                                        $ExploreSection = _this.$.$App.find('#' + explore_section_name).addClass('BodySelect');
253                                    }
254                                }
255                                // _this.variable.filter[type_name] = '';
256                                break;
257                            // 新增
258                            case 'add':
259                                if (type_id == 0) {
260                                    // 取消所有選擇,設定為不限
261                                    explore_section_name = 'activity_' + type_name + '_explore_filter';
262                                    $ExploreSection = _this.$.$App.find('.' + explore_section_name).removeClass('BodySelect');
263                                    _this.variable.filter[type_name] = [];
264
265                                    $this.addClass('BodySelect');
266                                } else {
267                                    // 移除不限
268                                    explore_section_name = 'activity_' + type_name + '_explore_filter_0';
269                                    $ExploreSection = _this.$.$App.find('#' + explore_section_name).removeClass('BodySelect');
270
271                                    $this.addClass('BodySelect');
272                                    _this.variable.filter[type_name].push(type_id);
273                                }
274                                break;
275                            default:
276                                break;
277                        }
278                        // console.log(_this.variable.filter);
279                        _this.saveExploreParameter.bind(_this)();
280                        // 選擇此項目
281                        // $this.addClass('BodySelect');
282                        // 設定目前值為查詢項目
283
284
285                        // console.log(111);
286                        // console.log(_this.variable.filter);
287                    });
288                }
289            },
290            Datepicker : {
291                parent : null,
292                init : function (parent) {
293                    this.parent = parent;
294                    this.bindDatepicker();
295                },
296                bindDatepicker : function () {
297                    var _this = this.parent;
298
299                    // datepicker trigger
300                    _this.$.$datepicker.datepicker({
301                        format: 'yyyy-mm-dd'
302                    });
303                    // datepicker 按鈕 trigger
304                    Skyline.$.$document.on('click', ".datepicker_btn", function () {
305                        var $this = $(this);
306                        $this.parent().find('.datepicker').trigger('focus');
307                    });
308                }
309            }
310        }
311    };
312
313    Skyline.$.$document.ready(function(){
314        var $App = Skyline.$.$document.find('#activity-explore-container');
315        if($App.length){
316            // 有到該頁面,初始化程式
317            Skyline.activity.exploreActivity = new Skyline.activity.exploreActivity($App);
318            Skyline.activity.exploreActivity.init();
319        }
320    });
321
322})(typeof Skyline !== 'undefined' ? Skyline : (this.Skyline = {}));

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.