luv-assets 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,313 @@
1
+ /**
2
+ * dropload
3
+ * 西门(http://ons.me/526.html)
4
+ * 0.9.1(161205)
5
+ */
6
+
7
+ ;(function($){
8
+ 'use strict';
9
+ var win = window;
10
+ var doc = document;
11
+ var $win = $(win);
12
+ var $doc = $(doc);
13
+ $.fn.dropload = function(options){
14
+ return new MyDropLoad(this, options);
15
+ };
16
+ var MyDropLoad = function(element, options){
17
+ var me = this;
18
+ me.$element = element;
19
+ // 上方是否插入DOM
20
+ me.upInsertDOM = false;
21
+ // loading状态
22
+ me.loading = false;
23
+ // 是否锁定
24
+ me.isLockUp = false;
25
+ me.isLockDown = false;
26
+ // 是否有数据
27
+ me.isData = true;
28
+ me._scrollTop = 0;
29
+ me._threshold = 0;
30
+ me.init(options);
31
+ };
32
+
33
+ // 初始化
34
+ MyDropLoad.prototype.init = function(options){
35
+ var me = this;
36
+ me.opts = $.extend(true, {}, {
37
+ scrollArea : me.$element, // 滑动区域
38
+ domUp : { // 上方DOM
39
+ domClass : 'dropload-up',
40
+ domRefresh : '<div class="dropload-refresh">↓下拉刷新</div>',
41
+ domUpdate : '<div class="dropload-update">↑释放更新</div>',
42
+ domLoad : '<div class="dropload-load"><span class="loading"></span>加载中...</div>'
43
+ },
44
+ domDown : { // 下方DOM
45
+ domClass : 'dropload-down',
46
+ domRefresh : '<div class="dropload-refresh">↑上拉加载更多</div>',
47
+ domLoad : '<div class="dropload-load"><span class="loading"></span>加载中...</div>',
48
+ domNoData : '<div class="dropload-noData">暂无数据</div>'
49
+ },
50
+ autoLoad : true, // 自动加载
51
+ distance : 50, // 拉动距离
52
+ threshold : '', // 提前加载距离
53
+ loadUpFn : '', // 上方function
54
+ loadDownFn : '' // 下方function
55
+ }, options);
56
+
57
+ // 如果加载下方,事先在下方插入DOM
58
+ if(me.opts.loadDownFn != ''){
59
+ me.$element.append('<div class="'+me.opts.domDown.domClass+'">'+me.opts.domDown.domRefresh+'</div>');
60
+ me.$domDown = $('.'+me.opts.domDown.domClass);
61
+ }
62
+
63
+ // 计算提前加载距离
64
+ if(!!me.$domDown && me.opts.threshold === ''){
65
+ // 默认滑到加载区2/3处时加载
66
+ me._threshold = Math.floor(me.$domDown.height()*1/3);
67
+ }else{
68
+ me._threshold = me.opts.threshold;
69
+ }
70
+
71
+ // 判断滚动区域
72
+ if(me.opts.scrollArea == win){
73
+ me.$scrollArea = $win;
74
+ // 获取文档高度
75
+ me._scrollContentHeight = $doc.height();
76
+ // 获取win显示区高度 —— 这里有坑
77
+ me._scrollWindowHeight = doc.documentElement.clientHeight;
78
+ }else{
79
+ me.$scrollArea = me.opts.scrollArea;
80
+ me._scrollContentHeight = me.$element[0].scrollHeight;
81
+ me._scrollWindowHeight = me.$element.height();
82
+ }
83
+ fnAutoLoad(me);
84
+
85
+ // 窗口调整
86
+ $win.on('resize',function(){
87
+ clearTimeout(me.timer);
88
+ me.timer = setTimeout(function(){
89
+ if(me.opts.scrollArea == win){
90
+ // 重新获取win显示区高度
91
+ me._scrollWindowHeight = win.innerHeight;
92
+ }else{
93
+ me._scrollWindowHeight = me.$element.height();
94
+ }
95
+ fnAutoLoad(me);
96
+ },150);
97
+
98
+ });
99
+
100
+ // 绑定触摸
101
+ me.$element.on('touchstart',function(e){
102
+ if(!me.loading){
103
+ fnTouches(e);
104
+ fnTouchstart(e, me);
105
+ }
106
+ });
107
+ me.$element.on('touchmove',function(e){
108
+ if(!me.loading){
109
+ fnTouches(e, me);
110
+ fnTouchmove(e, me);
111
+ }
112
+ });
113
+ me.$element.on('touchend',function(){
114
+ if(!me.loading){
115
+ fnTouchend(me);
116
+ }
117
+ });
118
+
119
+ // 加载下方
120
+ me.$scrollArea.on('scroll',function(){
121
+ me._scrollTop = me.$scrollArea.scrollTop();
122
+
123
+ // 滚动页面触发加载数据
124
+ if(me.opts.loadDownFn != '' && !me.loading && !me.isLockDown && (me._scrollContentHeight - me._threshold) <= (me._scrollWindowHeight + me._scrollTop)){
125
+ loadDown(me);
126
+ }
127
+ });
128
+ };
129
+
130
+ // touches
131
+ function fnTouches(e){
132
+ if(!e.touches){
133
+ e.touches = e.originalEvent.touches;
134
+ }
135
+ }
136
+
137
+ // touchstart
138
+ function fnTouchstart(e, me){
139
+ me._startY = e.touches[0].pageY;
140
+ // 记住触摸时的scrolltop值
141
+ me.touchScrollTop = me.$scrollArea.scrollTop();
142
+ }
143
+
144
+ // touchmove
145
+ function fnTouchmove(e, me){
146
+ me._curY = e.touches[0].pageY;
147
+ me._moveY = me._curY - me._startY;
148
+
149
+ if(me._moveY > 0){
150
+ me.direction = 'down';
151
+ }else if(me._moveY < 0){
152
+ me.direction = 'up';
153
+ }
154
+
155
+ var _absMoveY = Math.abs(me._moveY);
156
+
157
+ // 加载上方
158
+ if(me.opts.loadUpFn != '' && me.touchScrollTop <= 0 && me.direction == 'down' && !me.isLockUp){
159
+ e.preventDefault();
160
+
161
+ me.$domUp = $('.'+me.opts.domUp.domClass);
162
+ // 如果加载区没有DOM
163
+ if(!me.upInsertDOM){
164
+ me.$element.prepend('<div class="'+me.opts.domUp.domClass+'"></div>');
165
+ me.upInsertDOM = true;
166
+ }
167
+
168
+ fnTransition(me.$domUp,0);
169
+
170
+ // 下拉
171
+ if(_absMoveY <= me.opts.distance){
172
+ me._offsetY = _absMoveY;
173
+ // todo:move时会不断清空、增加dom,有可能影响性能,下同
174
+ me.$domUp.html(me.opts.domUp.domRefresh);
175
+ // 指定距离 < 下拉距离 < 指定距离*2
176
+ }else if(_absMoveY > me.opts.distance && _absMoveY <= me.opts.distance*2){
177
+ me._offsetY = me.opts.distance+(_absMoveY-me.opts.distance)*0.5;
178
+ me.$domUp.html(me.opts.domUp.domUpdate);
179
+ // 下拉距离 > 指定距离*2
180
+ }else{
181
+ me._offsetY = me.opts.distance+me.opts.distance*0.5+(_absMoveY-me.opts.distance*2)*0.2;
182
+ }
183
+
184
+ me.$domUp.css({'height': me._offsetY});
185
+ }
186
+ }
187
+
188
+ // touchend
189
+ function fnTouchend(me){
190
+ var _absMoveY = Math.abs(me._moveY);
191
+ if(me.opts.loadUpFn != '' && me.touchScrollTop <= 0 && me.direction == 'down' && !me.isLockUp){
192
+ fnTransition(me.$domUp,300);
193
+
194
+ if(_absMoveY > me.opts.distance){
195
+ me.$domUp.css({'height':me.$domUp.children().height()});
196
+ me.$domUp.html(me.opts.domUp.domLoad);
197
+ me.loading = true;
198
+ me.opts.loadUpFn(me);
199
+ }else{
200
+ me.$domUp.css({'height':'0'}).on('webkitTransitionEnd mozTransitionEnd transitionend',function(){
201
+ me.upInsertDOM = false;
202
+ $(this).remove();
203
+ });
204
+ }
205
+ me._moveY = 0;
206
+ }
207
+ }
208
+
209
+ // 如果文档高度不大于窗口高度,数据较少,自动加载下方数据
210
+ function fnAutoLoad(me){
211
+ if(me.opts.loadDownFn != '' && me.opts.autoLoad){
212
+ if((me._scrollContentHeight - me._threshold) <= me._scrollWindowHeight){
213
+ loadDown(me);
214
+ }
215
+ }
216
+ }
217
+
218
+ // 重新获取文档高度
219
+ function fnRecoverContentHeight(me){
220
+ if(me.opts.scrollArea == win){
221
+ me._scrollContentHeight = $doc.height();
222
+ }else{
223
+ me._scrollContentHeight = me.$element[0].scrollHeight;
224
+ }
225
+ }
226
+
227
+ // 加载下方
228
+ function loadDown(me){
229
+ me.direction = 'up';
230
+ me.$domDown.html(me.opts.domDown.domLoad);
231
+ me.loading = true;
232
+ me.opts.loadDownFn(me);
233
+ }
234
+
235
+ // 锁定
236
+ MyDropLoad.prototype.lock = function(direction){
237
+ var me = this;
238
+ // 如果不指定方向
239
+ if(direction === undefined){
240
+ // 如果操作方向向上
241
+ if(me.direction == 'up'){
242
+ me.isLockDown = true;
243
+ // 如果操作方向向下
244
+ }else if(me.direction == 'down'){
245
+ me.isLockUp = true;
246
+ }else{
247
+ me.isLockUp = true;
248
+ me.isLockDown = true;
249
+ }
250
+ // 如果指定锁上方
251
+ }else if(direction == 'up'){
252
+ me.isLockUp = true;
253
+ // 如果指定锁下方
254
+ }else if(direction == 'down'){
255
+ me.isLockDown = true;
256
+ // 为了解决DEMO5中tab效果bug,因为滑动到下面,再滑上去点tab,direction=down,所以有bug
257
+ me.direction = 'up';
258
+ }
259
+ };
260
+
261
+ // 解锁
262
+ MyDropLoad.prototype.unlock = function(){
263
+ var me = this;
264
+ // 简单粗暴解锁
265
+ me.isLockUp = false;
266
+ me.isLockDown = false;
267
+ // 为了解决DEMO5中tab效果bug,因为滑动到下面,再滑上去点tab,direction=down,所以有bug
268
+ me.direction = 'up';
269
+ };
270
+
271
+ // 无数据
272
+ MyDropLoad.prototype.noData = function(flag){
273
+ var me = this;
274
+ if(flag === undefined || flag == true){
275
+ me.isData = false;
276
+ }else if(flag == false){
277
+ me.isData = true;
278
+ }
279
+ };
280
+
281
+ // 重置
282
+ MyDropLoad.prototype.resetload = function(){
283
+ var me = this;
284
+ if(me.direction == 'down' && me.upInsertDOM){
285
+ me.$domUp.css({'height':'0'}).on('webkitTransitionEnd mozTransitionEnd transitionend',function(){
286
+ me.loading = false;
287
+ me.upInsertDOM = false;
288
+ $(this).remove();
289
+ fnRecoverContentHeight(me);
290
+ });
291
+ }else if(me.direction == 'up'){
292
+ me.loading = false;
293
+ // 如果有数据
294
+ if(me.isData){
295
+ // 加载区修改样式
296
+ me.$domDown.html(me.opts.domDown.domRefresh);
297
+ fnRecoverContentHeight(me);
298
+ fnAutoLoad(me);
299
+ }else{
300
+ // 如果没数据
301
+ me.$domDown.html(me.opts.domDown.domNoData);
302
+ }
303
+ }
304
+ };
305
+
306
+ // css过渡
307
+ function fnTransition(dom,num){
308
+ dom.css({
309
+ '-webkit-transition':'all '+num+'ms',
310
+ 'transition':'all '+num+'ms'
311
+ });
312
+ }
313
+ })(window.Zepto || window.jQuery);
@@ -0,0 +1,2 @@
1
+
2
+ !function(a){"use strict";function g(a){a.touches||(a.touches=a.originalEvent.touches)}function h(a,b){b._startY=a.touches[0].pageY,b.touchScrollTop=b.$scrollArea.scrollTop()}function i(b,c){c._curY=b.touches[0].pageY,c._moveY=c._curY-c._startY,c._moveY>0?c.direction="down":c._moveY<0&&(c.direction="up");var d=Math.abs(c._moveY);""!=c.opts.loadUpFn&&c.touchScrollTop<=0&&"down"==c.direction&&!c.isLockUp&&(b.preventDefault(),c.$domUp=a("."+c.opts.domUp.domClass),c.upInsertDOM||(c.$element.prepend('<div class="'+c.opts.domUp.domClass+'"></div>'),c.upInsertDOM=!0),n(c.$domUp,0),d<=c.opts.distance?(c._offsetY=d,c.$domUp.html(c.opts.domUp.domRefresh)):d>c.opts.distance&&d<=2*c.opts.distance?(c._offsetY=c.opts.distance+.5*(d-c.opts.distance),c.$domUp.html(c.opts.domUp.domUpdate)):c._offsetY=c.opts.distance+.5*c.opts.distance+.2*(d-2*c.opts.distance),c.$domUp.css({height:c._offsetY}))}function j(b){var c=Math.abs(b._moveY);""!=b.opts.loadUpFn&&b.touchScrollTop<=0&&"down"==b.direction&&!b.isLockUp&&(n(b.$domUp,300),c>b.opts.distance?(b.$domUp.css({height:b.$domUp.children().height()}),b.$domUp.html(b.opts.domUp.domLoad),b.loading=!0,b.opts.loadUpFn(b)):b.$domUp.css({height:"0"}).on("webkitTransitionEnd mozTransitionEnd transitionend",function(){b.upInsertDOM=!1,a(this).remove()}),b._moveY=0)}function k(a){""!=a.opts.loadDownFn&&a.opts.autoLoad&&a._scrollContentHeight-a._threshold<=a._scrollWindowHeight&&m(a)}function l(a){a._scrollContentHeight=a.opts.scrollArea==b?e.height():a.$element[0].scrollHeight}function m(a){a.direction="up",a.$domDown.html(a.opts.domDown.domLoad),a.loading=!0,a.opts.loadDownFn(a)}function n(a,b){a.css({"-webkit-transition":"all "+b+"ms",transition:"all "+b+"ms"})}var f,b=window,c=document,d=a(b),e=a(c);a.fn.dropload=function(a){return new f(this,a)},f=function(a,b){var c=this;c.$element=a,c.upInsertDOM=!1,c.loading=!1,c.isLockUp=!1,c.isLockDown=!1,c.isData=!0,c._scrollTop=0,c._threshold=0,c.init(b)},f.prototype.init=function(f){var l=this;l.opts=a.extend(!0,{},{scrollArea:l.$element,domUp:{domClass:"dropload-up",domRefresh:'<div class="dropload-refresh">refresh</div>',domUpdate:'<div class="dropload-update">update</div>',domLoad:'<div class="dropload-load"><span class="loading"></span>loading...</div>'},domDown:{domClass:"dropload-down",domRefresh:'<div class="dropload-refresh">load more</div>',domLoad:'<div class="dropload-load"><span class="loading"></span>loading...</div>',domNoData:'<div class="dropload-noData">empty</div>'},autoLoad:!0,distance:50,threshold:"",loadUpFn:"",loadDownFn:""},f),""!=l.opts.loadDownFn&&(l.$element.append('<div class="'+l.opts.domDown.domClass+'">'+l.opts.domDown.domRefresh+"</div>"),l.$domDown=a("."+l.opts.domDown.domClass)),l._threshold=l.$domDown&&""===l.opts.threshold?Math.floor(1*l.$domDown.height()/3):l.opts.threshold,l.opts.scrollArea==b?(l.$scrollArea=d,l._scrollContentHeight=e.height(),l._scrollWindowHeight=c.documentElement.clientHeight):(l.$scrollArea=l.opts.scrollArea,l._scrollContentHeight=l.$element[0].scrollHeight,l._scrollWindowHeight=l.$element.height()),k(l),d.on("resize",function(){clearTimeout(l.timer),l.timer=setTimeout(function(){l._scrollWindowHeight=l.opts.scrollArea==b?b.innerHeight:l.$element.height(),k(l)},150)}),l.$element.on("touchstart",function(a){l.loading||(g(a),h(a,l))}),l.$element.on("touchmove",function(a){l.loading||(g(a,l),i(a,l))}),l.$element.on("touchend",function(){l.loading||j(l)}),l.$scrollArea.on("scroll",function(){l._scrollTop=l.$scrollArea.scrollTop(),""!=l.opts.loadDownFn&&!l.loading&&!l.isLockDown&&l._scrollContentHeight-l._threshold<=l._scrollWindowHeight+l._scrollTop&&m(l)})},f.prototype.lock=function(a){var b=this;void 0===a?"up"==b.direction?b.isLockDown=!0:"down"==b.direction?b.isLockUp=!0:(b.isLockUp=!0,b.isLockDown=!0):"up"==a?b.isLockUp=!0:"down"==a&&(b.isLockDown=!0,b.direction="up")},f.prototype.unlock=function(){var a=this;a.isLockUp=!1,a.isLockDown=!1,a.direction="up"},f.prototype.noData=function(a){var b=this;void 0===a||1==a?b.isData=!1:0==a&&(b.isData=!0)},f.prototype.resetload=function(){var b=this;"down"==b.direction&&b.upInsertDOM?b.$domUp.css({height:"0"}).on("webkitTransitionEnd mozTransitionEnd transitionend",function(){b.loading=!1,b.upInsertDOM=!1,a(this).remove(),l(b)}):"up"==b.direction&&(b.loading=!1,b.isData?(b.$domDown.html(b.opts.domDown.domRefresh),l(b),k(b)):b.$domDown.html(b.opts.domDown.domNoData))}}(window.Zepto||window.jQuery);
package/dist/js/js.js ADDED
@@ -0,0 +1,552 @@
1
+ function isStrictMode() {
2
+ return (function () { return !this; })();
3
+ }
4
+ // console.log(isStrictMode()); // if true, strict mode is on
5
+ function isSurportedLoading() {
6
+ return 'loading' in HTMLImageElement.prototype;
7
+ }
8
+ // console.log(isSurportedLoading()); // if true, loading attribute is supported
9
+
10
+ function webLoadScript(url, callback) {
11
+ var script = document.createElement("script");
12
+ script.type = "text/javascript";
13
+ if (typeof (callback) != "undefined") {
14
+ if (script.readyState) {
15
+ script.onreadystatechange = function () {
16
+ if (script.readyState == "loaded" || script.readyState == "complete") {
17
+ script.onreadystatechange = null;
18
+ callback();
19
+ }
20
+ };
21
+ } else {
22
+ script.onload = function () {
23
+ callback();
24
+ };
25
+ }
26
+ }
27
+ script.src = url;
28
+ document.body.appendChild(script);
29
+ }
30
+ function check_email(email) {
31
+
32
+ if (!email || email == "") {
33
+ return false;
34
+ }
35
+
36
+ const myreg = /^([a-zA-Z0-9]+[_|\_|\.|-|\-]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.|-|\-]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
37
+ if (!myreg.test(email)) {
38
+ return false;
39
+ }
40
+
41
+ return true;
42
+ }
43
+ function check_pass(str) {
44
+ const re = /^\w{6,30}$/;
45
+ if (re.test(str)) {
46
+ return true;
47
+ } else {
48
+ return false;
49
+ }
50
+ }
51
+
52
+ //set cookie
53
+ function setCookie(name, value) {
54
+ const Days = 30;
55
+ const exp = new Date();
56
+ exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
57
+ document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
58
+ }
59
+
60
+ //get cookies
61
+ function getCookie(name) {
62
+ const arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
63
+ if (arr) {
64
+ return unescape(arr[2]);
65
+ } else {
66
+ return null;
67
+ }
68
+ }
69
+
70
+ $(document).ready(function () {
71
+
72
+ const currentBaseUrl = $("#currentBaseUrl").val();
73
+ if (currentBaseUrl) {
74
+ const loginInfoUrl = currentBaseUrl + "/member/ajax";
75
+ const product_id = $("#cart_product_spu").val();
76
+ product_id = product_id ? product_id : null;
77
+ if (product_id) {
78
+ const ajax_params = {
79
+ 'product_id': product_id
80
+ };
81
+ } else {
82
+ const ajax_params = {};
83
+ }
84
+ $.ajax({
85
+ async: true,
86
+ timeout: 6000,
87
+ dataType: 'json',
88
+ type: 'get',
89
+ data: ajax_params,
90
+ url: loginInfoUrl,
91
+ success: function (data, textStatus) {
92
+
93
+ if (data.loginStatus) {
94
+ $(".header_welcome").show();
95
+ $(".header_account").hide();
96
+ }
97
+
98
+ if (data.favorite) {
99
+ $('.product-favorite').addClass("icon-like");
100
+ $('.product-favorite').addClass("wish-pink");
101
+
102
+ }
103
+
104
+ if (data.favorite_product_count) {
105
+ // $(".header-right-user-wishlist-num-js").html(data.favorite_product_count);
106
+ }
107
+
108
+ if (data.affiliate) {
109
+ $(".affiliate_link-js").show();
110
+ }
111
+
112
+ if (data.cart_qty) {
113
+ $(".bag-count").text(data.cart_qty);
114
+ $(".num-tag").text(data.cart_qty);
115
+ }
116
+ },
117
+ error: function (XMLHttpRequest, textStatus, errorThrown) { }
118
+ });
119
+ }
120
+ $(".app-header-left .showMenu").click(function () {
121
+ $(".js-side-nav.side-nav").addClass("side-nav--visible");
122
+ $(".js-side-nav-container").css({ left: "-8rem" });
123
+ $(".js-side-nav-container").animate({ left: "0" }, 400);
124
+ });
125
+
126
+ $(".js-side-nav.side-nav").click(function () {
127
+ $(".js-side-nav.side-nav").removeClass("side-nav--visible");
128
+
129
+ });
130
+ $(".js-side-nav-container").click(function (e) {
131
+ e.stopPropagation();
132
+ });
133
+
134
+ $("body").on("click", ".span_click", function () {
135
+ url = $(this).attr('rel');
136
+ window.location.href = url;
137
+ });
138
+
139
+ // $(".span_click").click(function () {
140
+ // url = $(this).attr('rel');
141
+ // window.location.href = url;
142
+ // });
143
+ //ajax subscribe
144
+ $("#subscribe_btn").click(function () {
145
+ //disable button
146
+ $(this).prop('disabled', true);
147
+
148
+ email = $("#subscribe_email").val();
149
+ if (!check_email(email)) {
150
+ alert('Enter your email address');
151
+ //enable button
152
+ $('#subscribe_btn').prop('disabled', false);
153
+ return false;
154
+ }
155
+ $.ajax({
156
+ dataType: 'json',
157
+ type: 'post',
158
+ data: { 'email': email },
159
+ url: currentBaseUrl + "/member/account/subscribe",
160
+ success: function (data, textStatus) {
161
+ //enable button
162
+ $('#subscribe_btn').prop('disabled', false);
163
+ if (data.success) {
164
+ alert(data.message);
165
+ $("#subscribe_email").val("");
166
+ } else {
167
+ alert(data.message);
168
+ }
169
+ },
170
+ error: function (error) {
171
+
172
+ alert('Oops! Something went wrong. Please try again later.');
173
+ //enable button
174
+ $('#subscribe_btn').prop('disabled', false);
175
+ }
176
+ })
177
+ });
178
+ });
179
+
180
+
181
+ ///////////////////////////////
182
+
183
+ function isValidSearchKeyword(keyword, maxLength = 100) {
184
+ //
185
+ keyword = keyword.trim();
186
+ if (keyword === '') {
187
+ return false;
188
+ }
189
+ //
190
+ if (keyword.length > maxLength) {
191
+ return false;
192
+ }
193
+ // Unicode
194
+ // const safePattern = /^[\p{L}\p{N}\s.,;:'"!?-]+$/u;
195
+ const safePattern = /^[\p{L}\p{N}\s.;:'"!?-]+$/u;
196
+ if (!safePattern.test(keyword)) {
197
+ return false;
198
+ }
199
+ //
200
+ const escapedKeyword = keyword.replace(/&/g, "&amp;")
201
+ .replace(/</g, "&lt;")
202
+ .replace(/>/g, "&gt;")
203
+ .replace(/"/g, "&quot;")
204
+ .replace(/'/g, "&#039;");
205
+ //
206
+ return true;
207
+ }
208
+
209
+ const historyKey = 'search_history';
210
+ function pullSearchHistory(Url) {
211
+ // let localHistory = getSearchHistoryFromLocalStorage();
212
+ let localHistory = getCompatibleSearchHistoryFromLocalStorage();
213
+ if (!isSyncNeeded(localHistory)) {
214
+ return;
215
+ }
216
+ $.ajax({
217
+ async: true,
218
+ timeout: 6000,
219
+ dataType: 'json',
220
+ type: 'get',
221
+ url: Url,
222
+ success: function (data, textStatus) {
223
+ if (data.data.length > 0) {
224
+ // console.log(data.data);
225
+ mergeLocalSearchHistory(data.data);
226
+ }
227
+ },
228
+ error: function (XMLHttpRequest, textStatus, errorThrown) {
229
+
230
+ }
231
+ });
232
+ }
233
+ /**
234
+ * save search history to server
235
+ * @param {string} keyword
236
+ * @param {string} Url
237
+ */
238
+ function saveOneSearchHistory(keyword, Url) {
239
+ $.ajax({
240
+ async: true,
241
+ timeout: 6000,
242
+ dataType: 'json',
243
+ type: 'post',
244
+ url: Url,
245
+ data: {
246
+ keyword: keyword
247
+ },
248
+ success: function (data, textStatus) {
249
+
250
+ },
251
+ error: function (XMLHttpRequest, textStatus, errorThrown) {
252
+
253
+ }
254
+ });
255
+ }
256
+ /**
257
+ * save search history to local storage
258
+ * @param {string} keyword
259
+ */
260
+ function saveSearchToLocalStorage(keyword) {
261
+ // let searchHistory = JSON.parse(localStorage.getItem(historyKey)) || [];
262
+ let searchHistory = getCompatibleSearchHistoryFromLocalStorage();
263
+
264
+ // data
265
+ // data keyword exits
266
+ const index = searchHistory.data.indexOf(keyword);
267
+ if (index > -1) {
268
+ searchHistory.data.splice(index, 1);
269
+ }
270
+ searchHistory.data.unshift(keyword);
271
+ // data keywords max length
272
+ if (searchHistory.data.length > maxSearchHistoryLength) {
273
+ searchHistory.data = searchHistory.data.slice(0, maxSearchHistoryLength); // move
274
+ }
275
+
276
+ //update_time
277
+ searchHistory.update_time = new Date().toISOString();
278
+
279
+ // save local
280
+ localStorage.setItem(historyKey, JSON.stringify(searchHistory));
281
+ }
282
+
283
+ function removeSearchFromLocalStorage(keyword) {
284
+ // get local search history
285
+ let searchHistory = JSON.parse(localStorage.getItem(historyKey));
286
+ // search history exists
287
+ if (searchHistory && Array.isArray(searchHistory.data)) {
288
+ if (keyword) {
289
+ // if keyword exists in search history, remove it
290
+ searchHistory.data = searchHistory.data.filter(item => item !== keyword);
291
+ } else {
292
+ // // set search history to empty
293
+ // searchHistory.data = [];
294
+ // remove search history from local storage
295
+ localStorage.removeItem(historyKey);
296
+ return;
297
+ }
298
+ //update_time
299
+ searchHistory.update_time = new Date().toISOString();
300
+ // update local storage
301
+ localStorage.setItem(historyKey, JSON.stringify(searchHistory));
302
+ return;
303
+ } else {
304
+ // remove search history from local storage
305
+ localStorage.removeItem(historyKey);
306
+ return;
307
+ }
308
+
309
+ }
310
+
311
+ function getSearchHistoryFromLocalStorage() {
312
+ let searchHistory = JSON.parse(localStorage.getItem(historyKey)) || {
313
+ update_time: null,
314
+ last_sync_time: null,
315
+ data: []
316
+ };
317
+ return searchHistory;
318
+ }
319
+ function getCompatibleSearchHistoryFromLocalStorage() {
320
+ const rawHistory = localStorage.getItem(historyKey);
321
+ if (!rawHistory) {
322
+ // if no history, return default new structure
323
+ return {
324
+ update_time: null,
325
+ last_sync_time: null,
326
+ data: []
327
+ };
328
+ }
329
+
330
+ let history;
331
+ try {
332
+ history = JSON.parse(rawHistory);
333
+ } catch (e) {
334
+ console.error('Failed to parse history:', e);
335
+ return {
336
+ update_time: null,
337
+ last_sync_time: null,
338
+ data: []
339
+ };
340
+ }
341
+ // check if it's old array structure
342
+ if (Array.isArray(history)) {
343
+ // convert to new object structure
344
+ history = {
345
+ update_time: null, // assume old data has no update time
346
+ last_sync_time: null, // assume old data has no sync time
347
+ data: history
348
+ };
349
+ // update to localStorage, ensure subsequent use of new structure
350
+ localStorage.setItem(historyKey, JSON.stringify(history));
351
+ }
352
+
353
+ return history;
354
+ }
355
+ function isSyncNeeded(history) {
356
+ if (!history || !history.last_sync_time) return true;
357
+
358
+ const lastSyncTime = new Date(history.last_sync_time);
359
+ const currentTime = new Date();
360
+ const diffInMinutes = (currentTime - lastSyncTime) / (1000 * 60);
361
+
362
+ return diffInMinutes > 15;
363
+ }
364
+ function mergeLocalSearchHistory(serverHistory) {
365
+ // let localHistory = getSearchHistoryFromLocalStorage();
366
+ let localHistory = getCompatibleSearchHistoryFromLocalStorage();
367
+ //last_sync_time
368
+ localHistory.last_sync_time = new Date().toISOString();
369
+
370
+ // merge
371
+ let mergedData = Array.from(new Set([...localHistory.data, ...serverHistory]));
372
+ localHistory.data = mergedData;
373
+ // save
374
+ localStorage.setItem(historyKey, JSON.stringify(localHistory));
375
+ }
376
+
377
+
378
+ function getUrlParams() {
379
+ // get current page URL
380
+ const url = new URL(window.location.href);
381
+ // create URLSearchParams
382
+ const searchParams = new URLSearchParams(url.search);
383
+
384
+ // loop all params
385
+ // for (const [key, value] of searchParams.entries()) {
386
+ // // console.log(`Key: ${key}, Value: ${value}`);
387
+ // }
388
+
389
+ // return searchParams object;
390
+ return searchParams;
391
+ }
392
+
393
+
394
+ ///////////////////////
395
+
396
+ /////////////////////// start product
397
+ const product_history_key = 'viewed_products';
398
+ function saveProductToLocalStorage(product_id, maxHistoryLength = 30) {
399
+ let productHistory = JSON.parse(localStorage.getItem(product_history_key)) || [];
400
+ // product_id exits
401
+ const index = productHistory.indexOf(product_id);
402
+ if (index > -1) {
403
+ productHistory.splice(index, 1);
404
+ }
405
+ productHistory.unshift(product_id);
406
+ // max length
407
+ if (productHistory.length > maxHistoryLength) {
408
+ productHistory = productHistory.slice(0, maxHistoryLength); // move
409
+ }
410
+ // save local
411
+ localStorage.setItem(product_history_key, JSON.stringify(productHistory));
412
+ }
413
+ function fetchAndDisplayViewedProducts(history_url) {
414
+ let productHistory = JSON.parse(localStorage.getItem(product_history_key) || '[]');
415
+ if (productHistory.length === 0) {
416
+ return;
417
+ }
418
+ const viewedProductsElement = $('#viewed-products');
419
+ viewedProductsElement.empty();
420
+ // get products
421
+ $.ajax({
422
+ url: history_url,
423
+ method: 'POST',
424
+ data: { productIds: productHistory },
425
+ success: function (response) {
426
+ viewedProductsElement.html(response.html);
427
+ lazyLoadInstance.update(); // lazy load
428
+ },
429
+ error: function () {
430
+ viewedProductsElement.html('<p>Failed to load viewed products.</p>');
431
+ }
432
+ });
433
+
434
+ }
435
+ /////////////////////// end product
436
+
437
+ /**
438
+ * Checks if the provided URL is valid
439
+ *
440
+ * @param string url
441
+ *
442
+ * @return bool
443
+ *
444
+ */
445
+ function is_valid_url(url) {
446
+
447
+ var regex = new RegExp(/^(https?|s):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i);
448
+
449
+ return regex.test(url);
450
+
451
+ }
452
+ /**
453
+ * Checks if the two provided URLs are from the same domain
454
+ *
455
+ * @param string base_url
456
+ * @param string custom_url
457
+ *
458
+ * @return bool
459
+ *
460
+ */
461
+ function is_same_domain(base_url, custom_url) {
462
+
463
+ base_url = base_url.replace('http://', '').replace('https://', '').replace('www.', '').replace('m.', '').split(/[/?#]/)[0];
464
+ custom_url = custom_url.replace('http://', '').replace('https://', '').replace('www.', '').replace('m.', '').split(/[/?#]/)[0];
465
+
466
+ return (base_url == custom_url || base_url.indexOf(custom_url) != -1 || custom_url.indexOf(base_url) != -1);
467
+
468
+ }
469
+ /**
470
+ * Adds the the friendly affiliate parameters to the url
471
+ *
472
+ */
473
+ function process_friendly_url(param, value, url) {
474
+
475
+ // Save the hash, if it's present.
476
+ var hash = url.split('#')[1];
477
+
478
+ url = url.split('#')[0];
479
+
480
+ // Check if this is already an affiliate friendly url
481
+ var re = new RegExp("([\/]" + param + "[\/][^?]*)"),
482
+ match = re.exec(url);
483
+
484
+ // Check if we have any parameters in the url
485
+ var re2 = new RegExp("([?].*)"),
486
+ match2 = re2.exec(url);
487
+
488
+ // Remove the affiliate friendly endpoint
489
+ if (match && match[0])
490
+ url = url.replace(match[0], '');
491
+
492
+ // Remove the url parameters
493
+ if (match2 && match2[0])
494
+ url = url.replace(match2[0], '');
495
+
496
+ // Check if we have the affiliate parameter without affiliate id in the url
497
+ var re3 = new RegExp("([\/]" + param + "$)"),
498
+ match3 = re3.exec(url);
499
+
500
+ // Remove the affiliate parameter
501
+ if (match3 && match3[0])
502
+ url = url.replace(match3[0], '');
503
+
504
+ // Remove the trailing slash
505
+ url = url.replace(/\/+$/, '');
506
+
507
+ // Add the affiliate friendly endpoint
508
+ url = url + '/' + param + '/' + value + '/';
509
+
510
+ // Add back the parameters to the url
511
+ if (match2 && match2[0])
512
+ url = url + match2[0];
513
+
514
+ // Add back the hash if it exists.
515
+ if (hash)
516
+ url += '#' + hash;
517
+
518
+ return url;
519
+
520
+ }
521
+ /**
522
+ * Adds an argument name, value pair to a given URL string
523
+ *
524
+ */
525
+ function add_query_arg(param, value, url) {
526
+
527
+ var re = new RegExp("[\\?&]" + param + "=([^&#]*)"),
528
+ match = re.exec(url),
529
+ delimiter, newString;
530
+ var hash = url.split('#')[1];
531
+
532
+ url = url.split('#')[0];
533
+
534
+ if (match === null) {
535
+
536
+ var hasQuestionMark = /\?/.test(url);
537
+ delimiter = hasQuestionMark ? "&" : "?";
538
+ newString = url + delimiter + param + "=" + value;
539
+
540
+ } else {
541
+
542
+ delimiter = match[0].charAt(0);
543
+ newString = url.replace(re, delimiter + param + "=" + value);
544
+
545
+ }
546
+
547
+ if (hash) {
548
+ newString += '#' + hash;
549
+ }
550
+
551
+ return newString;
552
+ }
@@ -0,0 +1,483 @@
1
+ /**
2
+ * @preserve
3
+ * Sharer.js
4
+ *
5
+ * @description Create your own social share buttons
6
+ * @version 0.5.1
7
+ * @author Ellison Leao <ellisonleao@gmail.com>
8
+ * @license MIT
9
+ *
10
+ */
11
+
12
+ (function(window, document) {
13
+ 'use strict';
14
+ /**
15
+ * @constructor
16
+ */
17
+ var Sharer = function(elem) {
18
+ this.elem = elem;
19
+ };
20
+
21
+ /**
22
+ * @function init
23
+ * @description bind the events for multiple sharer elements
24
+ * @returns {Empty}
25
+ */
26
+ Sharer.init = function() {
27
+ var elems = document.querySelectorAll('[data-sharer]'),
28
+ i,
29
+ l = elems.length;
30
+
31
+ for (i = 0; i < l; i++) {
32
+ elems[i].addEventListener('click', Sharer.add);
33
+ }
34
+ };
35
+
36
+ /**
37
+ * @function add
38
+ * @description bind the share event for a single dom element
39
+ * @returns {Empty}
40
+ */
41
+ Sharer.add = function(elem) {
42
+ var target = elem.currentTarget || elem.srcElement;
43
+ var sharer = new Sharer(target);
44
+ sharer.share();
45
+ };
46
+
47
+ // instance methods
48
+ Sharer.prototype = {
49
+ constructor: Sharer,
50
+ /**
51
+ * @function getValue
52
+ * @description Helper to get the attribute of a DOM element
53
+ * @param {String} attr DOM element attribute
54
+ * @returns {String|Empty} returns the attr value or empty string
55
+ */
56
+ getValue: function(attr) {
57
+ var val = this.elem.getAttribute('data-' + attr);
58
+ // handing facebook hashtag attribute
59
+ if (val && attr === 'hashtag') {
60
+ if (!val.startsWith('#')) {
61
+ val = '#' + val;
62
+ }
63
+ }
64
+ return val === null ? '' : val;
65
+ },
66
+
67
+ /**
68
+ * @event share
69
+ * @description Main share event. Will pop a window or redirect to a link
70
+ * based on the data-sharer attribute.
71
+ */
72
+ share: function() {
73
+ var sharer = this.getValue('sharer').toLowerCase(),
74
+ sharers = {
75
+ facebook: {
76
+ shareUrl: 'https://www.facebook.com/sharer/sharer.php',
77
+ params: {
78
+ u: this.getValue('url'),
79
+ hashtag: this.getValue('hashtag'),
80
+ quote: this.getValue('quote'),
81
+ },
82
+ },
83
+ linkedin: {
84
+ shareUrl: 'https://www.linkedin.com/shareArticle',
85
+ params: {
86
+ url: this.getValue('url'),
87
+ mini: true,
88
+ },
89
+ },
90
+ twitter: {
91
+ shareUrl: 'https://twitter.com/intent/tweet',
92
+ params: {
93
+ text: this.getValue('title'),
94
+ url: this.getValue('url'),
95
+ hashtags: this.getValue('hashtags'),
96
+ via: this.getValue('via'),
97
+ related: this.getValue('related'),
98
+ in_reply_to: this.getValue('in_reply_to')
99
+ },
100
+ },
101
+ email: {
102
+ shareUrl: 'mailto:' + this.getValue('to'),
103
+ params: {
104
+ subject: this.getValue('subject'),
105
+ body: this.getValue('title') + '\n' + this.getValue('url'),
106
+ },
107
+ },
108
+ whatsapp: {
109
+ shareUrl: this.getValue('web') === 'true' ? 'https://web.whatsapp.com/send' : 'https://wa.me/',
110
+ params: {
111
+ phone: this.getValue('to'),
112
+ text: this.getValue('title') + ' ' + this.getValue('url'),
113
+ },
114
+ },
115
+ telegram: {
116
+ shareUrl: 'https://t.me/share',
117
+ params: {
118
+ text: this.getValue('title'),
119
+ url: this.getValue('url'),
120
+ },
121
+ },
122
+ viber: {
123
+ shareUrl: 'viber://forward',
124
+ params: {
125
+ text: this.getValue('title') + ' ' + this.getValue('url'),
126
+ },
127
+ },
128
+ line: {
129
+ shareUrl:
130
+ 'http://line.me/R/msg/text/?' + encodeURIComponent(this.getValue('title') + ' ' + this.getValue('url')),
131
+ },
132
+ pinterest: {
133
+ shareUrl: 'https://www.pinterest.com/pin/create/button/',
134
+ params: {
135
+ url: this.getValue('url'),
136
+ media: this.getValue('image'),
137
+ description: this.getValue('description'),
138
+ },
139
+ },
140
+ tumblr: {
141
+ shareUrl: 'http://tumblr.com/widgets/share/tool',
142
+ params: {
143
+ canonicalUrl: this.getValue('url'),
144
+ content: this.getValue('url'),
145
+ posttype: 'link',
146
+ title: this.getValue('title'),
147
+ caption: this.getValue('caption'),
148
+ tags: this.getValue('tags'),
149
+ },
150
+ },
151
+ hackernews: {
152
+ shareUrl: 'https://news.ycombinator.com/submitlink',
153
+ params: {
154
+ u: this.getValue('url'),
155
+ t: this.getValue('title'),
156
+ },
157
+ },
158
+ reddit: {
159
+ shareUrl: 'https://www.reddit.com/submit',
160
+ params: { url: this.getValue('url'), title: this.getValue('title') },
161
+ },
162
+ vk: {
163
+ shareUrl: 'http://vk.com/share.php',
164
+ params: {
165
+ url: this.getValue('url'),
166
+ title: this.getValue('title'),
167
+ description: this.getValue('caption'),
168
+ image: this.getValue('image'),
169
+ },
170
+ },
171
+ xing: {
172
+ shareUrl: 'https://www.xing.com/social/share/spi',
173
+ params: {
174
+ url: this.getValue('url'),
175
+ },
176
+ },
177
+ buffer: {
178
+ shareUrl: 'https://buffer.com/add',
179
+ params: {
180
+ url: this.getValue('url'),
181
+ title: this.getValue('title'),
182
+ via: this.getValue('via'),
183
+ picture: this.getValue('picture'),
184
+ },
185
+ },
186
+ instapaper: {
187
+ shareUrl: 'http://www.instapaper.com/edit',
188
+ params: {
189
+ url: this.getValue('url'),
190
+ title: this.getValue('title'),
191
+ description: this.getValue('description'),
192
+ },
193
+ },
194
+ pocket: {
195
+ shareUrl: 'https://getpocket.com/save',
196
+ params: {
197
+ url: this.getValue('url'),
198
+ },
199
+ },
200
+ mashable: {
201
+ shareUrl: 'https://mashable.com/submit',
202
+ params: {
203
+ url: this.getValue('url'),
204
+ title: this.getValue('title'),
205
+ },
206
+ },
207
+ mix: {
208
+ shareUrl: 'https://mix.com/add',
209
+ params: {
210
+ url: this.getValue('url'),
211
+ },
212
+ },
213
+ flipboard: {
214
+ shareUrl: 'https://share.flipboard.com/bookmarklet/popout',
215
+ params: {
216
+ v: 2,
217
+ title: this.getValue('title'),
218
+ url: this.getValue('url'),
219
+ t: Date.now(),
220
+ },
221
+ },
222
+ weibo: {
223
+ shareUrl: 'http://service.weibo.com/share/share.php',
224
+ params: {
225
+ url: this.getValue('url'),
226
+ title: this.getValue('title'),
227
+ pic: this.getValue('image'),
228
+ appkey: this.getValue('appkey'),
229
+ ralateUid: this.getValue('ralateuid'),
230
+ language: 'zh_cn',
231
+ },
232
+ },
233
+ blogger: {
234
+ shareUrl: 'https://www.blogger.com/blog-this.g',
235
+ params: {
236
+ u: this.getValue('url'),
237
+ n: this.getValue('title'),
238
+ t: this.getValue('description'),
239
+ },
240
+ },
241
+ baidu: {
242
+ shareUrl: 'http://cang.baidu.com/do/add',
243
+ params: {
244
+ it: this.getValue('title'),
245
+ iu: this.getValue('url'),
246
+ },
247
+ },
248
+ douban: {
249
+ shareUrl: 'https://www.douban.com/share/service',
250
+ params: {
251
+ name: this.getValue('name'),
252
+ href: this.getValue('url'),
253
+ image: this.getValue('image'),
254
+ comment: this.getValue('description'),
255
+ },
256
+ },
257
+ okru: {
258
+ shareUrl: 'https://connect.ok.ru/dk',
259
+ params: {
260
+ 'st.cmd': 'WidgetSharePreview',
261
+ 'st.shareUrl': this.getValue('url'),
262
+ title: this.getValue('title'),
263
+ },
264
+ },
265
+ mailru: {
266
+ shareUrl: 'http://connect.mail.ru/share',
267
+ params: {
268
+ share_url: this.getValue('url'),
269
+ linkname: this.getValue('title'),
270
+ linknote: this.getValue('description'),
271
+ type: 'page',
272
+ },
273
+ },
274
+ evernote: {
275
+ shareUrl: 'https://www.evernote.com/clip.action',
276
+ params: {
277
+ url: this.getValue('url'),
278
+ title: this.getValue('title'),
279
+ },
280
+ },
281
+ skype: {
282
+ shareUrl: 'https://web.skype.com/share',
283
+ params: {
284
+ url: this.getValue('url'),
285
+ title: this.getValue('title'),
286
+ },
287
+ },
288
+ delicious: {
289
+ shareUrl: 'https://del.icio.us/post',
290
+ params: {
291
+ url: this.getValue('url'),
292
+ title: this.getValue('title'),
293
+ },
294
+ },
295
+ sms: {
296
+ shareUrl: 'sms://',
297
+ params: {
298
+ body: this.getValue('body'),
299
+ },
300
+ },
301
+ trello: {
302
+ shareUrl: 'https://trello.com/add-card',
303
+ params: {
304
+ url: this.getValue('url'),
305
+ name: this.getValue('title'),
306
+ desc: this.getValue('description'),
307
+ mode: 'popup',
308
+ },
309
+ },
310
+ messenger: {
311
+ shareUrl: 'fb-messenger://share',
312
+ params: {
313
+ link: this.getValue('url'),
314
+ },
315
+ },
316
+ odnoklassniki: {
317
+ shareUrl: 'https://connect.ok.ru/dk',
318
+ params: {
319
+ st: {
320
+ cmd: 'WidgetSharePreview',
321
+ deprecated: 1,
322
+ shareUrl: this.getValue('url'),
323
+ },
324
+ },
325
+ },
326
+ meneame: {
327
+ shareUrl: 'https://www.meneame.net/submit',
328
+ params: {
329
+ url: this.getValue('url'),
330
+ },
331
+ },
332
+ diaspora: {
333
+ shareUrl: 'https://share.diasporafoundation.org',
334
+ params: {
335
+ title: this.getValue('title'),
336
+ url: this.getValue('url'),
337
+ },
338
+ },
339
+ googlebookmarks: {
340
+ shareUrl: 'https://www.google.com/bookmarks/mark',
341
+ params: {
342
+ op: 'edit',
343
+ bkmk: this.getValue('url'),
344
+ title: this.getValue('title'),
345
+ },
346
+ },
347
+ qzone: {
348
+ shareUrl: 'https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey',
349
+ params: {
350
+ url: this.getValue('url'),
351
+ },
352
+ },
353
+ refind: {
354
+ shareUrl: 'https://refind.com',
355
+ params: {
356
+ url: this.getValue('url'),
357
+ },
358
+ },
359
+ surfingbird: {
360
+ shareUrl: 'https://surfingbird.ru/share',
361
+ params: {
362
+ url: this.getValue('url'),
363
+ title: this.getValue('title'),
364
+ description: this.getValue('description'),
365
+ },
366
+ },
367
+ yahoomail: {
368
+ shareUrl: 'http://compose.mail.yahoo.com',
369
+ params: {
370
+ to: this.getValue('to'),
371
+ subject: this.getValue('subject'),
372
+ body: this.getValue('body'),
373
+ },
374
+ },
375
+ wordpress: {
376
+ shareUrl: 'https://wordpress.com/wp-admin/press-this.php',
377
+ params: {
378
+ u: this.getValue('url'),
379
+ t: this.getValue('title'),
380
+ s: this.getValue('title'),
381
+ },
382
+ },
383
+ amazon: {
384
+ shareUrl: 'https://www.amazon.com/gp/wishlist/static-add',
385
+ params: {
386
+ u: this.getValue('url'),
387
+ t: this.getValue('title'),
388
+ },
389
+ },
390
+ pinboard: {
391
+ shareUrl: 'https://pinboard.in/add',
392
+ params: {
393
+ url: this.getValue('url'),
394
+ title: this.getValue('title'),
395
+ description: this.getValue('description'),
396
+ },
397
+ },
398
+ threema: {
399
+ shareUrl: 'threema://compose',
400
+ params: {
401
+ text: this.getValue('text'),
402
+ id: this.getValue('id'),
403
+ },
404
+ },
405
+ kakaostory: {
406
+ shareUrl: 'https://story.kakao.com/share',
407
+ params: {
408
+ url: this.getValue('url'),
409
+ },
410
+ },
411
+ yummly: {
412
+ shareUrl: 'http://www.yummly.com/urb/verify',
413
+ params: {
414
+ url: this.getValue('url'),
415
+ title: this.getValue('title'),
416
+ yumtype: 'button',
417
+ },
418
+ },
419
+ },
420
+ s = sharers[sharer];
421
+
422
+ // custom popups sizes
423
+ if (s) {
424
+ s.width = this.getValue('width');
425
+ s.height = this.getValue('height');
426
+ }
427
+ return s !== undefined ? this.urlSharer(s) : false;
428
+ },
429
+ /**
430
+ * @event urlSharer
431
+ * @param {Object} sharer
432
+ */
433
+ urlSharer: function(sharer) {
434
+ var p = sharer.params || {},
435
+ keys = Object.keys(p),
436
+ i,
437
+ str = keys.length > 0 ? '?' : '';
438
+ for (i = 0; i < keys.length; i++) {
439
+ if (str !== '?') {
440
+ str += '&';
441
+ }
442
+ if (p[keys[i]]) {
443
+ str += keys[i] + '=' + encodeURIComponent(p[keys[i]]);
444
+ }
445
+ }
446
+ sharer.shareUrl += str;
447
+
448
+ var isLink = this.getValue('link') === 'true';
449
+ var isBlank = this.getValue('blank') === 'true';
450
+
451
+ if (isLink) {
452
+ if (isBlank) {
453
+ window.open(sharer.shareUrl, '_blank');
454
+ } else {
455
+ window.location.href = sharer.shareUrl;
456
+ }
457
+ } else {
458
+ console.log(sharer.shareUrl);
459
+ // defaults to popup if no data-link is provided
460
+ var popWidth = sharer.width || 600,
461
+ popHeight = sharer.height || 480,
462
+ left = window.innerWidth / 2 - popWidth / 2 + window.screenX,
463
+ top = window.innerHeight / 2 - popHeight / 2 + window.screenY,
464
+ popParams = 'scrollbars=no, width=' + popWidth + ', height=' + popHeight + ', top=' + top + ', left=' + left,
465
+ newWindow = window.open(sharer.shareUrl, '', popParams);
466
+
467
+ if (window.focus) {
468
+ newWindow.focus();
469
+ }
470
+ }
471
+ },
472
+ };
473
+
474
+ // adding sharer events on domcontentload
475
+ if (document.readyState === 'complete' || document.readyState !== 'loading') {
476
+ Sharer.init();
477
+ } else {
478
+ document.addEventListener('DOMContentLoaded', Sharer.init);
479
+ }
480
+
481
+ // exporting sharer for external usage
482
+ window.Sharer = Sharer;
483
+ })(window, document);
@@ -0,0 +1 @@
1
+ (function(m,r){"use strict";var s=function(t){this.elem=t};s.init=function(){var t=r.querySelectorAll("[data-sharer]"),e,a=t.length;for(e=0;e<a;e++){t[e].addEventListener("click",s.add)}};s.add=function(t){var e=t.currentTarget||t.srcElement;var a=new s(e);a.share()};s.prototype={constructor:s,getValue:function(t){var e=this.elem.getAttribute("data-"+t);if(e&&t==="hashtag"){if(!e.startsWith("#")){e="#"+e}}return e===null?"":e},share:function(){var t=this.getValue("sharer").toLowerCase(),e={facebook:{shareUrl:"https://www.facebook.com/sharer/sharer.php",params:{u:this.getValue("url"),hashtag:this.getValue("hashtag"),quote:this.getValue("quote")}},linkedin:{shareUrl:"https://www.linkedin.com/shareArticle",params:{url:this.getValue("url"),mini:true}},twitter:{shareUrl:"https://twitter.com/intent/tweet",params:{text:this.getValue("title"),url:this.getValue("url"),hashtags:this.getValue("hashtags"),via:this.getValue("via"),related:this.getValue("related"),in_reply_to:this.getValue("in_reply_to")}},email:{shareUrl:"mailto:"+this.getValue("to"),params:{subject:this.getValue("subject"),body:this.getValue("title")+"\n"+this.getValue("url")}},whatsapp:{shareUrl:this.getValue("web")==="true"?"https://web.whatsapp.com/send":"https://wa.me/",params:{phone:this.getValue("to"),text:this.getValue("title")+" "+this.getValue("url")}},telegram:{shareUrl:"https://t.me/share",params:{text:this.getValue("title"),url:this.getValue("url")}},viber:{shareUrl:"viber://forward",params:{text:this.getValue("title")+" "+this.getValue("url")}},line:{shareUrl:"http://line.me/R/msg/text/?"+encodeURIComponent(this.getValue("title")+" "+this.getValue("url"))},pinterest:{shareUrl:"https://www.pinterest.com/pin/create/button/",params:{url:this.getValue("url"),media:this.getValue("image"),description:this.getValue("description")}},tumblr:{shareUrl:"http://tumblr.com/widgets/share/tool",params:{canonicalUrl:this.getValue("url"),content:this.getValue("url"),posttype:"link",title:this.getValue("title"),caption:this.getValue("caption"),tags:this.getValue("tags")}},hackernews:{shareUrl:"https://news.ycombinator.com/submitlink",params:{u:this.getValue("url"),t:this.getValue("title")}},reddit:{shareUrl:"https://www.reddit.com/submit",params:{url:this.getValue("url"),title:this.getValue("title")}},vk:{shareUrl:"http://vk.com/share.php",params:{url:this.getValue("url"),title:this.getValue("title"),description:this.getValue("caption"),image:this.getValue("image")}},xing:{shareUrl:"https://www.xing.com/social/share/spi",params:{url:this.getValue("url")}},buffer:{shareUrl:"https://buffer.com/add",params:{url:this.getValue("url"),title:this.getValue("title"),via:this.getValue("via"),picture:this.getValue("picture")}},instapaper:{shareUrl:"http://www.instapaper.com/edit",params:{url:this.getValue("url"),title:this.getValue("title"),description:this.getValue("description")}},pocket:{shareUrl:"https://getpocket.com/save",params:{url:this.getValue("url")}},mashable:{shareUrl:"https://mashable.com/submit",params:{url:this.getValue("url"),title:this.getValue("title")}},mix:{shareUrl:"https://mix.com/add",params:{url:this.getValue("url")}},flipboard:{shareUrl:"https://share.flipboard.com/bookmarklet/popout",params:{v:2,title:this.getValue("title"),url:this.getValue("url"),t:Date.now()}},weibo:{shareUrl:"http://service.weibo.com/share/share.php",params:{url:this.getValue("url"),title:this.getValue("title"),pic:this.getValue("image"),appkey:this.getValue("appkey"),ralateUid:this.getValue("ralateuid"),language:"zh_cn"}},blogger:{shareUrl:"https://www.blogger.com/blog-this.g",params:{u:this.getValue("url"),n:this.getValue("title"),t:this.getValue("description")}},baidu:{shareUrl:"http://cang.baidu.com/do/add",params:{it:this.getValue("title"),iu:this.getValue("url")}},douban:{shareUrl:"https://www.douban.com/share/service",params:{name:this.getValue("name"),href:this.getValue("url"),image:this.getValue("image"),comment:this.getValue("description")}},okru:{shareUrl:"https://connect.ok.ru/dk",params:{"st.cmd":"WidgetSharePreview","st.shareUrl":this.getValue("url"),title:this.getValue("title")}},mailru:{shareUrl:"http://connect.mail.ru/share",params:{share_url:this.getValue("url"),linkname:this.getValue("title"),linknote:this.getValue("description"),type:"page"}},evernote:{shareUrl:"https://www.evernote.com/clip.action",params:{url:this.getValue("url"),title:this.getValue("title")}},skype:{shareUrl:"https://web.skype.com/share",params:{url:this.getValue("url"),title:this.getValue("title")}},delicious:{shareUrl:"https://del.icio.us/post",params:{url:this.getValue("url"),title:this.getValue("title")}},sms:{shareUrl:"sms://",params:{body:this.getValue("body")}},trello:{shareUrl:"https://trello.com/add-card",params:{url:this.getValue("url"),name:this.getValue("title"),desc:this.getValue("description"),mode:"popup"}},messenger:{shareUrl:"fb-messenger://share",params:{link:this.getValue("url")}},odnoklassniki:{shareUrl:"https://connect.ok.ru/dk",params:{st:{cmd:"WidgetSharePreview",deprecated:1,shareUrl:this.getValue("url")}}},meneame:{shareUrl:"https://www.meneame.net/submit",params:{url:this.getValue("url")}},diaspora:{shareUrl:"https://share.diasporafoundation.org",params:{title:this.getValue("title"),url:this.getValue("url")}},googlebookmarks:{shareUrl:"https://www.google.com/bookmarks/mark",params:{op:"edit",bkmk:this.getValue("url"),title:this.getValue("title")}},qzone:{shareUrl:"https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey",params:{url:this.getValue("url")}},refind:{shareUrl:"https://refind.com",params:{url:this.getValue("url")}},surfingbird:{shareUrl:"https://surfingbird.ru/share",params:{url:this.getValue("url"),title:this.getValue("title"),description:this.getValue("description")}},yahoomail:{shareUrl:"http://compose.mail.yahoo.com",params:{to:this.getValue("to"),subject:this.getValue("subject"),body:this.getValue("body")}},wordpress:{shareUrl:"https://wordpress.com/wp-admin/press-this.php",params:{u:this.getValue("url"),t:this.getValue("title"),s:this.getValue("title")}},amazon:{shareUrl:"https://www.amazon.com/gp/wishlist/static-add",params:{u:this.getValue("url"),t:this.getValue("title")}},pinboard:{shareUrl:"https://pinboard.in/add",params:{url:this.getValue("url"),title:this.getValue("title"),description:this.getValue("description")}},threema:{shareUrl:"threema://compose",params:{text:this.getValue("text"),id:this.getValue("id")}},kakaostory:{shareUrl:"https://story.kakao.com/share",params:{url:this.getValue("url")}},yummly:{shareUrl:"http://www.yummly.com/urb/verify",params:{url:this.getValue("url"),title:this.getValue("title"),yumtype:"button"}}},a=e[t];if(a){a.width=this.getValue("width");a.height=this.getValue("height")}return a!==undefined?this.urlSharer(a):false},urlSharer:function(t){var e=t.params||{},a=Object.keys(e),r,s=a.length>0?"?":"";for(r=0;r<a.length;r++){if(s!=="?"){s+="&"}if(e[a[r]]){s+=a[r]+"="+encodeURIComponent(e[a[r]])}}t.shareUrl+=s;var l=this.getValue("link")==="true";var i=this.getValue("blank")==="true";if(l){if(i){m.open(t.shareUrl,"_blank")}else{m.location.href=t.shareUrl}}else{console.log(t.shareUrl);var h=t.width||600,u=t.height||480,o=m.innerWidth/2-h/2+m.screenX,p=m.innerHeight/2-u/2+m.screenY,g="scrollbars=no, width="+h+", height="+u+", top="+p+", left="+o,n=m.open(t.shareUrl,"",g);if(m.focus){n.focus()}}}};if(r.readyState==="complete"||r.readyState!=="loading"){s.init()}else{r.addEventListener("DOMContentLoaded",s.init)}m.Sharer=s})(window,document);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "luv-assets",
3
3
  "description": "Include Bootstrap's source Sass and individual JavaScript plugins with Webpack.",
4
- "version": "1.0.3",
4
+ "version": "1.0.4",
5
5
  "private": false,
6
6
  "repository": {
7
7
  "type": "git",