webiaoqin1.js
10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
// 原 swipe.js文件
window.Swipe = function(element, options) {
if (!element) return null;
var _this = this;
this.options = options || {};
this.index = this.options.startSlide || 0;
this.speed = this.options.speed || 300;
this.callback = this.options.callback ||
function() {};
this.container = element;
this.element = this.container.children[0];
this.element.style.listStyle = 'none';
this.setup();
this.begin();
if (this.element.addEventListener) {
this.element.addEventListener('mousedown', this, false);
this.element.addEventListener('touchstart', this, false);
this.element.addEventListener('touchmove', this, false);
this.element.addEventListener('touchend', this, false);
this.element.addEventListener('webkitTransitionEnd', this, false);
this.element.addEventListener('msTransitionEnd', this, false);
this.element.addEventListener('oTransitionEnd', this, false);
this.element.addEventListener('transitionend', this, false);
if (!this.unresize) {
window.addEventListener('resize', this, false)
}
}
};
Swipe.prototype = {
setup: function() {
this.slides = this.element.children;
this.length = this.slides.length;
if (this.length < 2) return null;
this.width = this.container.getBoundingClientRect().width || this.width;
if (!this.width) return null;
this.container.style.visibility = 'hidden';
this.element.style.width = (this.slides.length * this.width) + 'px';
var index = this.slides.length;
while (index--) {
var el = this.slides[index];
el.style.width = this.width + 'px';
el.style.display = 'table-cell';
el.style.verticalAlign = 'top'
}
this.slide(this.index, 0);
this.container.style.visibility = 'visible'
},
slide: function(index, duration) {
var style = this.element.style;
if (duration == undefined) {
duration = this.speed
}
style.webkitTransitionDuration = style.MozTransitionDuration = style.msTransitionDuration = style.OTransitionDuration = style.transitionDuration = duration + 'ms';
style.MozTransform = style.webkitTransform = 'translate3d(' + -(index * this.width) + 'px,0,0)';
style.msTransform = style.OTransform = 'translateX(' + -(index * this.width) + 'px)';
this.index = index
},
getPos: function() {
return this.index
},
prev: function(delay) {
this.delay = delay || 0;
clearTimeout(this.interval);
if (this.index) this.slide(this.index - 1, this.speed)
},
next: function(delay) {
this.delay = delay || 0;
clearTimeout(this.interval);
if (this.index < this.length - 1) this.slide(this.index + 1, this.speed);
else this.slide(0, this.speed)
},
begin: function() {
var _this = this;
this.interval = (this.delay) ? setTimeout(function() {
_this.next(_this.delay)
}, this.delay) : 0
},
stop: function() {
this.delay = 0;
clearTimeout(this.interval)
},
resume: function() {
this.delay = this.options.auto || 0;
this.begin()
},
handleEvent: function(e) {
var that = this;
if (!e.touches) {
e.touches = new Array(e);
e.scale = false
}
switch (e.type) {
case 'mousedown':
(function() {
that.element.addEventListener('mousemove', that, false);
that.element.addEventListener('mouseup', that, false);
that.element.addEventListener('mouseout', that, false);
that.onTouchStart(e)
})();
break;
case 'mousemove':
this.onTouchMove(e);
break;
case 'mouseup':
(function() {
that.element.removeEventListener('mousemove', that, false);
that.element.removeEventListener('mouseup', that, false);
that.element.removeEventListener('mouseout', that, false);
that.onTouchEnd(e)
})();
break;
case 'mouseout':
(function() {
that.element.removeEventListener('mousemove', that, false);
that.element.removeEventListener('mouseup', that, false);
that.element.removeEventListener('mouseout', that, false);
that.onTouchEnd(e)
})();
break;
case 'touchstart':
this.onTouchStart(e);
break;
case 'touchmove':
this.onTouchMove(e);
break;
case 'touchend':
this.onTouchEnd(e);
break;
case 'webkitTransitionEnd':
case 'msTransitionEnd':
case 'oTransitionEnd':
case 'transitionend':
this.transitionEnd(e);
break;
case 'resize':
this.setup();
break
}
},
transitionEnd: function(e) {
e.preventDefault();
if (this.delay) this.begin();
this.callback(e, this.index, this.slides[this.index])
},
onTouchStart: function(e) {
this.start = {
pageX: e.touches[0].pageX,
pageY: e.touches[0].pageY,
time: Number(new Date())
};
this.isScrolling = undefined;
this.deltaX = 0;
this.element.style.MozTransitionDuration = this.element.style.webkitTransitionDuration = 0
},
onTouchMove: function(e) {
if (e.touches.length > 1 || e.scale && e.scale !== 1) return;
this.deltaX = e.touches[0].pageX - this.start.pageX;
if (typeof this.isScrolling == 'undefined') {
this.isScrolling = !! (this.isScrolling || Math.abs(this.deltaX) < Math.abs(e.touches[0].pageY - this.start.pageY))
}
if (!this.isScrolling) {
e.preventDefault();
clearTimeout(this.interval);
this.deltaX = this.deltaX / ((!this.index && this.deltaX > 0 || this.index == this.length - 1 && this.deltaX < 0) ? (Math.abs(this.deltaX) / this.width + 1) : 1);
this.element.style.MozTransform = this.element.style.webkitTransform = 'translate3d(' + (this.deltaX - this.index * this.width) + 'px,0,0)'
}
},
onTouchEnd: function(e) {
var isValidSlide = Number(new Date()) - this.start.time < 250 && Math.abs(this.deltaX) > 20 || Math.abs(this.deltaX) > this.width / 2,
isPastBounds = !this.index && this.deltaX > 0 || this.index == this.length - 1 && this.deltaX < 0;
if (!this.isScrolling) {
this.slide(this.index + (isValidSlide && !isPastBounds ? (this.deltaX < 0 ? 1 : -1) : 0), this.speed)
}
}
};
// 原 input.js文件
var myInput = (function() {
var mi = function() {
this.maxLength = 500, this.currentLength = 0
}
mi.prototype = {
listen: function(thi, evt) {
var that = this;
//删除图片的功能
if ("/:del" == evt.value) {
var obj = document.getElementById("show_msg");
var b=$('#show_msg').html();
var longnum=b.length;
var num=b.substr(0,longnum-1);
$('#show_msg').html(num);
return
}
//点击图标 促发的功能
if (evt.keyCode && -10 == evt.keyCode) {
var r="<img src='"+evt.imgUrl+"' >";
var aa=$('#show_msg').html();
$('#show_msg').html(aa+r);
}
}
}
return new mi()
})();
// 原 dialog_min.js文件
var iDialog = (function() {
var a = function() {
this.options = {
id: "dialogWindow_",
classList: "",
type: "",
wrapper: "",
title: "",
close: "",
content: "",
cover: true,
btns: []
}
};
return a
})();
var iTemplate = (function() {
var a = function() {};
a.prototype = {
makeList: function(e, j, i) {
var g = [],
h = [],
c = /{(.+?)}/g,
d = {},
f = 0;
for (var b in j) {
if (typeof i === "function") {
d = i.call(this, b, j[b], f++) || {}
}
g.push(e.replace(c, function(k, l) {
return (l in d) ? d[l] : (undefined === j[b][l] ? j[b] : j[b][l])
}))
}
return g.join("")
}
};
return new a()
})();
// 原index.html文件内部js
$().ready(function() {
form_emotion.rend();
myInput.maxLength = 500
});
var form_emotion = (function() {
var fe = function() {
this.values = ["/::)", "/::~", "/::B", "/::|", "/:8-)", "/::<", "/::$", "/::X", "/::Z", "/::'(", "/::-|", "/::@", "/::P", "/::D", "/::O", "/::(", "/::+", "/:–b", "/::Q", "/::T", "/:,@P", "/:,@-D", "/::d", "/:,@o", "/::g", "/:|-)", "/::!", "/::L", "/::>", "/::,@", "/:,@f", "/::-S", "/:?", "/:,@x", "/:,@@", "/::8", "/:,@!", "/:!!!", "/:xx", "/:bye", "/:wipe", "/:dig", "/:handclap", "/:&-(", "/:B-)", "/:<@", "/:@>", "/::-O", "/:>-|", "/:P-(", "/::'|", "/:X-)", "/::*", "/:@x", "/:8*", "/:pd", "/:<W>", "/:beer", "/:basketb", "/:oo", "/:coffee", "/:eat", "/:pig", "/:rose", "/:fade", "/:showlove", "/:heart", "/:break", "/:cake", "/:li", "/:bome", "/:kn", "/:footb", "/:ladybug", "/:shit", "/:moon", "/:sun", "/:gift", "/:hug", "/:strong", "/:weak", "/:share", "/:v", "/:@)", "/:jj", "/:@@", "/:bad", "/:lvu", "/:no", "/:ok", "/:love", "/:<L>", "/:jump", "/:shake", "/:<O>", "/:circle", "/:kotow", "/:turn", "/:skip", "[挥手]", "/:#-0", "[街舞]", "/:kiss", "/:<&", "/:&>"].slice(0, -7);
this.spearate = 20
}
fe.prototype = {
rend: function() {
var that = this;
var TPL = '{seprateDiv}<dd><span data-key="{k}_{page}_{v}" style="background-position:{xPos}px 0;"></span></dd>{delHTML}';
var res = iTemplate.makeList(TPL, that.values, function(k, v) {
return {
k: k,
v: v,
page: Math.floor(k / that.spearate),
xPos: -24 * k,
seprateDiv: (0 == k % that.spearate && 0 != k && k != that.values.length) ? "</div><div>" : "",
delHTML: (19 == k % that.spearate || k == (that.values.length - 1)) ? '<dd><span data-key="-1_-1_/:del" class="del"></span></dd>' : ''
}
});
$("#list_emotion").html('<div>' + res + '</div>');
var nav_span = new Array(Math.ceil(that.values.length / that.spearate));
$("#nav_emotion").html('<span class="on">' + nav_span.join("</span><span>") + '</span>');
that.bind();
window.swiper = new Swipe(document.getElementById('page_emotion'), {
speed: 500,
callback: function() {
$("#nav_emotion span").removeClass("on").eq(this.index).addClass("on")
}
});
return that
},
bind: function() {
$("#list_emotion").on("click", function(evt) {
if ("SPAN" == evt.target.tagName) {
var val = evt.target.getAttribute("data-key").split('_');
myInput.listen(this, {
keyCode: -10,
srcElement: document.getElementById("form_article"),
value: val[2],
imgUrl: '/public/static/images/arclist/' + val[0] + ".png"
});
this.focus()
}
})
}
}
return new fe()
})();