|
@@ -0,0 +1,704 @@
|
|
|
+/**
|
|
|
+ * 对公用JS库的补充
|
|
|
+ * @time 20190731
|
|
|
+ * @name test
|
|
|
+ */
|
|
|
+
|
|
|
+(function(PageH5) {
|
|
|
+
|
|
|
+ function tip(info, second, id, timerName) {
|
|
|
+ if (info === undefined || info === '') return;
|
|
|
+ second = second || 3;
|
|
|
+ id = id || id;
|
|
|
+ if (!G(id)) {
|
|
|
+ var dom = document.createElement('div');
|
|
|
+ dom.id = id;
|
|
|
+ document.body.appendChild(dom);
|
|
|
+ }
|
|
|
+ G(id).innerHTML = info;
|
|
|
+ S(id);
|
|
|
+ if (second > 0) {
|
|
|
+ if (PageH5[timerName]) clearTimeout(PageH5[timerName]);
|
|
|
+ PageH5[timerName] = setTimeout('H("' + id + '")', second * 1000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ PageH5.extend = function(params) {
|
|
|
+ for (var i in params) this[i] = params[i];
|
|
|
+ };
|
|
|
+
|
|
|
+ PageH5.extend({
|
|
|
+ tip: function(info, second) {
|
|
|
+ tip(info, second, 'default_tip_css', '_tip_timer');
|
|
|
+ },
|
|
|
+ ykqTip: function(info, second) {
|
|
|
+ tip(info, second, 'default_ykq_tip_css', '_ykq_tip_timer');
|
|
|
+ },
|
|
|
+ getBasePath: function() {
|
|
|
+ var contextPath = '/' + location.href.split('/')[3];
|
|
|
+ return contextPath;
|
|
|
+ },
|
|
|
+ isArray: function(obj) {
|
|
|
+ return Object.prototype.toString.call(obj) === '[object Array]' || (obj instanceof Array);
|
|
|
+ },
|
|
|
+ jump: function(href, f) {
|
|
|
+ if (f === undefined) f = PageH5.btn.current.id;
|
|
|
+ window.location.href = href + '&f=' + f;
|
|
|
+ },
|
|
|
+ trim: function(str) {
|
|
|
+ if (str) return str.replace(/^\s*(.*?)\s*$/g, '$1');
|
|
|
+ },
|
|
|
+ toHump: function(str, flag) {
|
|
|
+ return str.replace(new RegExp(flag + '(\\w)', 'g'),
|
|
|
+ function(m, $1, idx, str) {
|
|
|
+ return $1.toUpperCase();
|
|
|
+ });
|
|
|
+ },
|
|
|
+ hasClass: function(obj, cls) {
|
|
|
+ if (!obj) return;
|
|
|
+ return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
|
|
|
+ },
|
|
|
+ addClass: function(obj, cls) {
|
|
|
+ if (!obj) return;
|
|
|
+ var className = obj.className;
|
|
|
+ if (!this.hasClass(obj, cls)) obj.className += (className ? ' ': '') + cls;
|
|
|
+ },
|
|
|
+ removeClass: function(obj, cls) {
|
|
|
+ if (obj && this.hasClass(obj, cls)) {
|
|
|
+ obj.className = obj.className.replace(new RegExp('(\\s|^)' + cls + '(\\s|$)'),
|
|
|
+ function(m, $1, $2) {
|
|
|
+ return ($1 && $2) ? ' ': '';
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ on: function(obj, event, fn) {
|
|
|
+ var events = event.split(' ');
|
|
|
+ for (var i in events) obj.addEventListener(events[i], fn, false);
|
|
|
+ },
|
|
|
+ off: function(obj, event, fn) {
|
|
|
+ var events = event.split(' ');
|
|
|
+ for (var i in events) obj.removeEventListener(events[i], fn);
|
|
|
+ },
|
|
|
+ one: function(obj, event, fn) {
|
|
|
+ var tempFn = function() {
|
|
|
+ fn();
|
|
|
+ PageH5.off(obj, event, tempFn);
|
|
|
+ };
|
|
|
+ PageH5.on(obj, event, tempFn);
|
|
|
+ },
|
|
|
+ twinkle: {
|
|
|
+ start: function(id, time) {
|
|
|
+ this.stop();
|
|
|
+ id = id || PageH5.btn.current.id;
|
|
|
+ time = (typeof time === 'number') ? time: 200;
|
|
|
+ this._id = id;
|
|
|
+ this._is_hide = false;
|
|
|
+ this._timer = setInterval(function() {
|
|
|
+ if (PageH5.twinkle._is_hide) S(PageH5.twinkle._id);
|
|
|
+ else H(PageH5.twinkle._id);
|
|
|
+ PageH5.twinkle._is_hide = !PageH5.twinkle._is_hide;
|
|
|
+ },
|
|
|
+ time);
|
|
|
+ },
|
|
|
+ stop: function() {
|
|
|
+ if (this._timer) {
|
|
|
+ clearInterval(this._timer);
|
|
|
+ this._timer = undefined;
|
|
|
+ S(PageH5.twinkle._id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ var curCSS;
|
|
|
+ if (window.getComputedStyle) {
|
|
|
+ curCSS = function(elem, name) {
|
|
|
+ name = PageH5.toHump(name, '-');
|
|
|
+ var ret, computed = window.getComputedStyle(elem, null),
|
|
|
+ style = elem.style;
|
|
|
+ if (computed) ret = computed[name];
|
|
|
+ if (!ret) ret = style[name];
|
|
|
+ return ret;
|
|
|
+ };
|
|
|
+ } else if (document.documentElement.currentStyle) {
|
|
|
+ curCSS = function(elem, name) {
|
|
|
+ name = PageH5.toHump(name, '-');
|
|
|
+ var ret = elem.currentStyle && elem.currentStyle[name],
|
|
|
+ style = elem.style;
|
|
|
+ if (!ret && style && style[name]) {
|
|
|
+ ret = style[name];
|
|
|
+ }
|
|
|
+ return ret === '' ? 'auto': ret;
|
|
|
+ };
|
|
|
+ } else {
|
|
|
+ curCSS = function(elem, name) {
|
|
|
+ name = PageH5.toHump(name, '-');
|
|
|
+ var style = elem.style;
|
|
|
+ return style[name];
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ PageH5.css = function(obj, name, value) {
|
|
|
+ if (value === undefined) {
|
|
|
+ var temp = curCSS(obj, name);
|
|
|
+ if (temp === '' || temp === 'auto') temp = 0;
|
|
|
+ return temp;
|
|
|
+ } else {
|
|
|
+ var pxs = ['left', 'top', 'right', 'bottom', 'width', 'height', 'line-height', 'font-size'];
|
|
|
+ var isPx = pxs.indexOf(name) >= 0;
|
|
|
+ if (isPx && !/.*px$/g.test(value + '') && value !== 'auto') value += 'px';
|
|
|
+ obj.style[PageH5.toHump(name)] = value;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ PageH5.key = {
|
|
|
+ keys: {},
|
|
|
+ ids: {},
|
|
|
+ set: function(code, action) {
|
|
|
+ if (typeof code === 'string' && action !== undefined) {
|
|
|
+ var _code = code;
|
|
|
+ code = {};
|
|
|
+ code[_code] = action;
|
|
|
+ }
|
|
|
+ if (typeof code === 'object') {
|
|
|
+ var obj = code;
|
|
|
+ for (var i in obj) {
|
|
|
+ if (i.indexOf('KEY_') === 0 || i.indexOf('EVENT_') === 0) this.keys[i] = obj[i];
|
|
|
+ else this.ids[i] = obj[i];
|
|
|
+ }
|
|
|
+ } else if (typeof code === 'number') {}
|
|
|
+ return this;
|
|
|
+ },
|
|
|
+ add: function(code, action) {
|
|
|
+ return this.set(code, action);
|
|
|
+ },
|
|
|
+ del: function(code) {
|
|
|
+ if (! (code instanceof Array)) code = [code];
|
|
|
+ for (var i = 0; i < code.length; i++) {
|
|
|
+ if (this.ids[code[i]]) this.ids[code[i]] = 'PageH5.key.emptyFn()';
|
|
|
+ if (this.keys[code[i]]) this.keys[code[i]] = 'PageH5.key.emptyFn()';
|
|
|
+ }
|
|
|
+ return this;
|
|
|
+ },
|
|
|
+ emptyFn: function() {},
|
|
|
+ init: function() {
|
|
|
+ if (!PageH5.eventHandler) {
|
|
|
+ PageH5.eventHandler = function(code) {
|
|
|
+ for (var i in PageH5.key.ids) if (PageH5.Button.current.id === i) PageH5.call(PageH5.key.ids[i], code);
|
|
|
+ for (var i in PageH5.key.keys) if (code === window[i]) PageH5.call(PageH5.key.keys[i], code);
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ PageH5.cookie = {
|
|
|
+ get: function(cookieName, defaultValue, parseNumber, isUnescape) {
|
|
|
+ var temp = new RegExp('(^|;| )' + cookieName + '=([^;]*)(;|$)', 'g').exec(document.cookie);
|
|
|
+ if (temp != null) {
|
|
|
+ var value = temp[2];
|
|
|
+ if (value === '""') return defaultValue;
|
|
|
+ if (parseNumber == true) return parseFloat(value);
|
|
|
+ if (isUnescape) return unescape(value);
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+ return defaultValue;
|
|
|
+ },
|
|
|
+ set: function(name, value, day, path) {
|
|
|
+ day = day == undefined ? 30 : day;
|
|
|
+ path = path == undefined ? PageH5.getBasePath() : path;
|
|
|
+ var str = name + '=' + value + '; ';
|
|
|
+ if (day) {
|
|
|
+ var date = new Date();
|
|
|
+ date.setTime(date.getTime() + day * 24 * 3600 * 1000);
|
|
|
+ str += 'expires=' + date.toGMTString() + '; ';
|
|
|
+ }
|
|
|
+ if (path) str += 'path=' + path;
|
|
|
+ document.cookie = str;
|
|
|
+ },
|
|
|
+ del: function(name, path) {
|
|
|
+ this.set(name, null, -1, path);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ PageH5.marquee = {
|
|
|
+ start: function(maxLength, id, amount, delay, dir, behavior) {
|
|
|
+ maxLength = maxLength || 7;
|
|
|
+ id = id || PageH5.Button.current.id + '_txt';
|
|
|
+ amount = amount || 40;
|
|
|
+ delay = delay || 10;
|
|
|
+ dir = dir || 'left';
|
|
|
+ behavior = behavior || 'alternate';
|
|
|
+ if (!this.rollId) {
|
|
|
+ var marqueeParent = G(id);
|
|
|
+ var html = PageH5.trim(marqueeParent.innerHTML);
|
|
|
+ if (maxLength !== undefined && html.length > maxLength) {
|
|
|
+ this.rollId = id;
|
|
|
+ this.innerHTML = html;
|
|
|
+ marqueeParent.innerHTML = '<div id="' + id + '_marquee" class="common_marquee">' + html + '</div>';
|
|
|
+ var marqueeChild = G(id + '_marquee');
|
|
|
+ var width1 = parseInt(PageH5.css(marqueeParent, 'width'));
|
|
|
+ var width2 = parseInt(PageH5.css(marqueeChild, 'width'));
|
|
|
+ var maxLeft = width2 - width1;
|
|
|
+ if (maxLeft <= 0) return;
|
|
|
+ var marquee_idx = Math.ceil(maxLeft / 50) * 50;
|
|
|
+ marquee_idx = marquee_idx > 400 ? 400 : marquee_idx;
|
|
|
+ var time = (maxLeft / amount).toFixed(2);
|
|
|
+ if (maxLeft < 30) {
|
|
|
+ time = 0.7;
|
|
|
+ }
|
|
|
+ var animation = 'common_marquee_' + marquee_idx + ' ' + time + 's linear 50ms infinite alternate';
|
|
|
+ marqueeChild.style.webkitAnimation = animation;
|
|
|
+ marqueeChild.style.animation = animation;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ stop: function() {
|
|
|
+ if (this.rollId) {
|
|
|
+ G(this.rollId).innerHTML = this.innerHTML;
|
|
|
+ this.rollId = undefined;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ PageH5.fx = {
|
|
|
+ interval: 13,
|
|
|
+ tagIdx: 0,
|
|
|
+ animates: {},
|
|
|
+ start: function(obj, params, speed, easing, callback, tag) {
|
|
|
+ var speeds = {
|
|
|
+ fast: 200,
|
|
|
+ normal: 400,
|
|
|
+ slow: 600
|
|
|
+ };
|
|
|
+ speed = (typeof speed === 'string' ? speeds[speed] : speed) || speeds.normal;
|
|
|
+ if (typeof easing === 'function') {
|
|
|
+ tag = callback;
|
|
|
+ callback = easing;
|
|
|
+ easing = '';
|
|
|
+ }
|
|
|
+ easing = easing || 'swing';
|
|
|
+ tag = tag || 'default';
|
|
|
+ for (var i in this.animates) {
|
|
|
+ if (i.indexOf(tag) >= 0) this.stop(i);
|
|
|
+ }
|
|
|
+
|
|
|
+ var oldParams = params;
|
|
|
+ params = {};
|
|
|
+ var canContinue = false;
|
|
|
+ for (var i in oldParams) {
|
|
|
+ var p = oldParams[i];
|
|
|
+ if (!PageH5.isArray(p)) p = [PageH5.css(obj, i), p];
|
|
|
+ else PageH5.css(obj, i, p[0]);
|
|
|
+ params[i] = {
|
|
|
+ start: parseFloat(p[0]),
|
|
|
+ end: parseFloat(p[1])
|
|
|
+ };
|
|
|
+ if (params[i].start !== params[i].end) canContinue = true;
|
|
|
+ }
|
|
|
+ if (!canContinue) return;
|
|
|
+ tag += '_' + (++this.tagIdx);
|
|
|
+ this.animates[tag] = {
|
|
|
+ obj: obj,
|
|
|
+ params: params,
|
|
|
+ speed: speed,
|
|
|
+ easing: easing,
|
|
|
+ callback: callback,
|
|
|
+ startTime: Date.now(),
|
|
|
+ idx: 0,
|
|
|
+ timer: undefined
|
|
|
+ };
|
|
|
+ this.animates[tag].timer = setInterval(function() {
|
|
|
+ var animate = PageH5.fx.animates[tag];
|
|
|
+ animate.idx++;
|
|
|
+ var n = Date.now() - animate.startTime;
|
|
|
+ if (n > animate.speed) {
|
|
|
+ PageH5.fx.stop(tag);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var percent = n / animate.speed;
|
|
|
+ var pos = PageH5.fx.easing[animate.easing](percent, n, 0, 1, animate.speed);
|
|
|
+ for (var i in animate.params) {
|
|
|
+ var p = animate.params[i];
|
|
|
+ PageH5.css(animate.obj, i, p.start + (p.end - p.start) * pos);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ this.interval);
|
|
|
+ },
|
|
|
+ stop: function(tag) {
|
|
|
+ var animate = PageH5.fx.animates[tag];
|
|
|
+ if (!animate) return false;
|
|
|
+ clearInterval(animate.timer);
|
|
|
+ var ps = animate.params;
|
|
|
+ for (var i in ps) PageH5.css(animate.obj, i, ps[i].end);
|
|
|
+ PageH5.call(animate.callback);
|
|
|
+ delete PageH5.fx.animates[tag];
|
|
|
+ return true;
|
|
|
+ },
|
|
|
+ easing: {
|
|
|
+ linear: function(p, n, firstNum, diff) {
|
|
|
+ return firstNum + diff * p;
|
|
|
+ },
|
|
|
+ swing: function(p, n, firstNum, diff) {
|
|
|
+ return 0.5 - Math.cos(p * Math.PI) / 2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ PageH5.animate = function(obj, params, speed, easing, callback, tag) {
|
|
|
+ PageH5.fx.start(obj, params, speed, easing, callback, tag);
|
|
|
+ };
|
|
|
+
|
|
|
+})(PageH5);
|
|
|
+
|
|
|
+(function(PageH5) {
|
|
|
+ var positions = {};
|
|
|
+ function getBtn(cid, dir) {
|
|
|
+ var current = positions[cid];
|
|
|
+ var store = [];
|
|
|
+ var leftOrRight = (dir === 'left' || dir === 'right');
|
|
|
+ var hasFindDegIsZero = false;
|
|
|
+ for (var i in positions) {
|
|
|
+ if (i === cid) continue;
|
|
|
+ var next = positions[i];
|
|
|
+ if ((dir === 'left' && next.left >= current.left) || (dir === 'right' && next.right <= current.right) || (dir === 'up' && next.top >= current.top) || (dir === 'down' && next.bottom <= current.bottom)) continue;
|
|
|
+
|
|
|
+ if (leftOrRight && ((next.centerY >= current.top && next.centerY <= current.bottom) || (next.top <= current.centerY && next.bottom >= current.bottom) || (next.top <= current.top && next.bottom >= current.centerY))) {
|
|
|
+ store.push({
|
|
|
+ id: i,
|
|
|
+ distance: next.left,
|
|
|
+ deg: 0
|
|
|
+ });
|
|
|
+ hasFindDegIsZero = true;
|
|
|
+ } else if (!leftOrRight && ((next.centerX >= current.left && next.centerX <= current.right) || (next.left <= current.centerX && next.right >= current.right) || (next.left <= current.left && next.right >= current.centerX))) {
|
|
|
+ store.push({
|
|
|
+ id: i,
|
|
|
+ distance: next.top,
|
|
|
+ deg: 0
|
|
|
+ });
|
|
|
+ hasFindDegIsZero = true;
|
|
|
+ } else if (!hasFindDegIsZero) {
|
|
|
+ var key1 = leftOrRight ? dir: 'centerX';
|
|
|
+ var key2 = !leftOrRight ? (dir == 'up' ? 'top': 'bottom') : 'centerY';
|
|
|
+ var tan = (next[key1] - current[key1]) / (next[key2] - current[key2]);
|
|
|
+ var cdeg = Math.abs(Math.atan(leftOrRight ? (1 / tan) : tan) * 360 / 2 / Math.PI);
|
|
|
+ store.push({
|
|
|
+ id: i,
|
|
|
+ distance: next[leftOrRight ? 'left': 'top'],
|
|
|
+ deg: cdeg
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var tidu = [0, 30, 45, 60, 85];
|
|
|
+ var _store = [];
|
|
|
+ for (var i = 0; i < tidu.length; i++) {
|
|
|
+ _store = [];
|
|
|
+ for (var j = 0; j < store.length; j++) if (store[j].deg <= tidu[i]) _store.push(store[j]);
|
|
|
+ if (_store.length > 0) break;
|
|
|
+ }
|
|
|
+ store = _store.length ? _store: [];
|
|
|
+ store.sort(function(a, b) {
|
|
|
+ var desc = (dir === 'left' || dir === 'up') ? -1 : 1;
|
|
|
+ return (a.distance < b.distance ? -1 : (a.distance > b.distance ? 1 : 0)) * desc;
|
|
|
+ });
|
|
|
+ var nearest;
|
|
|
+ var result = '';
|
|
|
+ var key = leftOrRight ? 'top': 'left';
|
|
|
+ for (var i = 0; i < store.length; i++) {
|
|
|
+ if (i > 0 && store[i].distance != store[0].distance) break;
|
|
|
+ var distance = Math.abs(positions[store[i].id][key] - current[key]);
|
|
|
+ if (nearest === undefined || distance < nearest) {
|
|
|
+ nearest = distance;
|
|
|
+ result = store[i].id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ };
|
|
|
+
|
|
|
+ PageH5.getAbsolutePosition = function(elem) {
|
|
|
+ if (elem == null) return {
|
|
|
+ left: 0,
|
|
|
+ top: 0,
|
|
|
+ width: 0,
|
|
|
+ height: 0,
|
|
|
+ right: 0,
|
|
|
+ bottom: 0
|
|
|
+ };
|
|
|
+ var left = elem.offsetLeft,
|
|
|
+ top = elem.offsetTop,
|
|
|
+ width = elem.offsetWidth,
|
|
|
+ height = elem.offsetHeight;
|
|
|
+ while (elem = elem.offsetParent) {
|
|
|
+ left += elem.offsetLeft;
|
|
|
+ top += elem.offsetTop;
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ left: left,
|
|
|
+ top: top,
|
|
|
+ width: width,
|
|
|
+ height: height,
|
|
|
+ right: left + width,
|
|
|
+ bottom: top + height
|
|
|
+ };
|
|
|
+ };
|
|
|
+
|
|
|
+ PageH5.createButtonDir = function(allButtons) {
|
|
|
+ var start = new Date().getTime();
|
|
|
+ var btnGroups = {};
|
|
|
+ for (var i = 0; i < allButtons.length; i++) {
|
|
|
+ if (allButtons[i].autoDirGroup === false) continue;
|
|
|
+ var gname = 'group_' + (allButtons[i].autoDirGroup === undefined ? 'default': allButtons[i].autoDirGroup);
|
|
|
+ btnGroups[gname] = btnGroups[gname] || [];
|
|
|
+ btnGroups[gname].push(allButtons[i]);
|
|
|
+ }
|
|
|
+ for (var gname in btnGroups) {
|
|
|
+ positions = {};
|
|
|
+ var btns = btnGroups[gname];
|
|
|
+ for (var i = 0; i < btns.length; i++) {
|
|
|
+ if (btns[i].autoDir === false) continue;
|
|
|
+ var id = btns[i].id;
|
|
|
+ var obj = document.getElementById(id);
|
|
|
+ var position = PageH5.getAbsolutePosition(obj);
|
|
|
+ position.obj = obj;
|
|
|
+ position.centerX = position.left + position.width / 2;
|
|
|
+ position.centerY = position.top + position.height / 2;
|
|
|
+ positions[id] = position;
|
|
|
+ }
|
|
|
+ var dirs = ['left', 'right', 'up', 'down'];
|
|
|
+ for (var i = 0; i < btns.length; i++) {
|
|
|
+ for (var j = 0; j < dirs.length; j++) {
|
|
|
+ btns[i][dirs[j]] = btns[i][dirs[j]] || getBtn(btns[i].id, dirs[j]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var end = new Date().getTime();
|
|
|
+ };
|
|
|
+})(PageH5);
|
|
|
+
|
|
|
+(function() {
|
|
|
+ PageH5.scrollScreen = {
|
|
|
+ init: function(option) {
|
|
|
+ this.config.enable = true;
|
|
|
+ for (var i in option) {
|
|
|
+ if (option[i] !== undefined && option[i] !== "") {
|
|
|
+ this.config[i] = option[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.scroll(PageH5.getParamInt('scrollTop', 0));
|
|
|
+ },
|
|
|
+ check: function(button, dir) {
|
|
|
+ if (!this.config.enable) return;
|
|
|
+ if (button.restoreScroll) {
|
|
|
+ this.scroll( - this.config.scrollTop);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!this.config.enableToAllBtn && !button.scrollScreen) return;
|
|
|
+ var id = button.id;
|
|
|
+ var position = document.getElementById(id).getBoundingClientRect();
|
|
|
+ var target = document.getElementById(this.config.wrapperId);
|
|
|
+ var safePx = this.config.safePx;
|
|
|
+ var wrapperPosition = document.getElementById(this.config.wrapperId).getBoundingClientRect();
|
|
|
+ if (position.bottom >= (wrapperPosition.bottom - safePx)) {
|
|
|
+ this.scroll((position.bottom + safePx - wrapperPosition.bottom));
|
|
|
+ } else if (position.top - wrapperPosition.top < safePx) {
|
|
|
+ this.scroll((wrapperPosition.top - position.top + safePx) * -1);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ repair: function() {
|
|
|
+ if (!this.config.enable) return;
|
|
|
+ var target = document.getElementById(this.config.wrapperId);
|
|
|
+ if (PageH5.scrollScreen.config.scrollTop !== target.scrollTop) {
|
|
|
+ target.scrollTop = PageH5.scrollScreen.config.scrollTop;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ scroll: function(addScrollTop) {
|
|
|
+ var target = document.getElementById(this.config.wrapperId);
|
|
|
+ var from = this.config.scrollTop;
|
|
|
+ this.config.scrollTop += addScrollTop;
|
|
|
+ if (enable_animate === false || !this.config.animate || addScrollTop === 0) {
|
|
|
+ target.scrollTop = this.config.scrollTop;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var rate = 13,
|
|
|
+ speed = 600,
|
|
|
+ start = Date.now(),
|
|
|
+ easing = 'swing';
|
|
|
+ if (this.config._interval) {
|
|
|
+ clearInterval(this.config._interval);
|
|
|
+ this.config._interval = undefined;
|
|
|
+ }
|
|
|
+ this.config._interval = setInterval(function() {
|
|
|
+ var n = Date.now() - start;
|
|
|
+ if (n > speed) {
|
|
|
+ clearInterval(PageH5.scrollScreen.config._interval);
|
|
|
+ PageH5.scrollScreen.config._interval = undefined;
|
|
|
+ n = speed;
|
|
|
+ }
|
|
|
+ var pos = PageH5.fx.easing[easing](n / speed, n, 0, 1);
|
|
|
+ target.scrollTop = from + pos * addScrollTop;
|
|
|
+ },
|
|
|
+ rate);
|
|
|
+ },
|
|
|
+ config: {
|
|
|
+ animate: true,
|
|
|
+ enable: false,
|
|
|
+ enableToAllBtn: false,
|
|
|
+ wrapperId: 'wrapper',
|
|
|
+ scrollTop: 0,
|
|
|
+ safePx: 40,
|
|
|
+ topSafePx: 40
|
|
|
+ }
|
|
|
+ };
|
|
|
+})();
|
|
|
+
|
|
|
+(function() {
|
|
|
+ PageH5.scroll = {
|
|
|
+ init: function(option) {
|
|
|
+ this.config.enable = true;
|
|
|
+ for (var i in option) {
|
|
|
+ if (option[i] !== undefined && option[i] !== '') {
|
|
|
+ this.config[i] = option[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.scr(PageH5.getParamInt('scrollLeft', 0));
|
|
|
+ },
|
|
|
+ check: function(button, dir) {
|
|
|
+ if (!this.config.enable) return;
|
|
|
+ if (button.restoreScroll) {
|
|
|
+ this.scr( - this.config.scrollLeft);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!this.config.enableToAllBtn && !button.scrollScreen) return;
|
|
|
+ var id = button.id;
|
|
|
+ var position = document.getElementById(id).getBoundingClientRect();
|
|
|
+ var wrapperPosition = document.getElementById(this.config.wrapperId).getBoundingClientRect();
|
|
|
+ var safePx = this.config.safePx;
|
|
|
+ if (position.right >= (wrapperPosition.right - safePx)) {
|
|
|
+ this.scr((position.right + safePx - wrapperPosition.right));
|
|
|
+ } else if (position.left - wrapperPosition.left < safePx) {
|
|
|
+ this.scr((wrapperPosition.left - position.left + safePx) * -1);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ repair: function() {
|
|
|
+ if (!this.config.enable) return;
|
|
|
+ var target = document.getElementById(this.config.wrapperId);
|
|
|
+ if (PageH5.scroll.config.scrollLeft !== target.scrollLeft) {
|
|
|
+ target.scrollLeft = PageH5.scroll.config.scrollLeft;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ scr: function(addScrollLeft) {
|
|
|
+ var target = document.getElementById(this.config.wrapperId);
|
|
|
+ var form = this.config.scrollLeft;
|
|
|
+ this.config.scrollLeft += addScrollLeft;
|
|
|
+ if (enable_animate === false || !this.config.animate || addScrollLeft === 0) {
|
|
|
+ target.scrollLeft = this.config.scrollLeft;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var rate = 13,
|
|
|
+ speed = 600,
|
|
|
+ start = Date.now(),
|
|
|
+ easing = 'swing';
|
|
|
+ if (this.config._interval) {
|
|
|
+ clearInterval(this.config._interval);
|
|
|
+ this.config._interval = undefined;
|
|
|
+ }
|
|
|
+ this.config._interval = setInterval(function() {
|
|
|
+ var n = Date.now() - start;
|
|
|
+ if (n > speed) {
|
|
|
+ clearInterval(PageH5.scroll.config._interval);
|
|
|
+ PageH5.scroll.config._interval = undefined;
|
|
|
+ n = speed;
|
|
|
+ }
|
|
|
+ var pos = PageH5.fx.easing[easing](n / speed, n, 0, 1);
|
|
|
+ target.scrollLeft = form + pos * addScrollLeft;
|
|
|
+ },
|
|
|
+ rate);
|
|
|
+ },
|
|
|
+ config: {
|
|
|
+ animate: true,
|
|
|
+ enable: false,
|
|
|
+ enableToAllBtn: false,
|
|
|
+ wrapperId: 'wrapper',
|
|
|
+ scrollLeft: 0,
|
|
|
+ safePx: 40
|
|
|
+ }
|
|
|
+ };
|
|
|
+})();
|
|
|
+
|
|
|
+(function() {
|
|
|
+
|
|
|
+ PageH5.getCurrentURI = function() {
|
|
|
+ var currentURI = CONFIG.CURRENT_URI || (location.pathname + location.search);
|
|
|
+ if (!/^\//g.test(currentURI)) currentURI = CONFIG.CONTEXT_PATH + currentURI;
|
|
|
+ return currentURI + (currentURI.indexOf('?') > 0 ? '': '?1=1');
|
|
|
+ };
|
|
|
+
|
|
|
+ PageH5.go = function(url) {
|
|
|
+ var backURI = PageH5.getCurrentURI() + '&f=' + PageH5.btn.current.id;
|
|
|
+ if (PageH5.scrollScreen && PageH5.scrollScreen.config.enable) backURI += ('&scrollTop=' + PageH5.scrollScreen.config.scrollTop);
|
|
|
+ if (PageH5.scroll && PageH5.scroll.config.enable) backURI += ('&scrollLeft=' + PageH5.scroll.config.scrollLeft);
|
|
|
+ var backUriList = eval("(" + unescape(PageH5.cookie.get('back_page_list', '[]')) + ")");
|
|
|
+ backUriList.push(backURI);
|
|
|
+ var jStr = "";
|
|
|
+ for (var i = 0,
|
|
|
+ length = backUriList.length; i < length; i++) {
|
|
|
+ jStr += '"' + backUriList[i] + '",';
|
|
|
+ }
|
|
|
+ jStr = "[" + jStr.slice(0, -1) + "]";
|
|
|
+ PageH5.cookie.set('back_page_list', escape(jStr));
|
|
|
+ location.href = CONFIG.CONTEXT_PATH + url;
|
|
|
+ };
|
|
|
+
|
|
|
+ PageH5.getBackURI = function() {
|
|
|
+ var backUriList = eval("(" + unescape(PageH5.cookie.get('back_page_list', '[]')) + ")");
|
|
|
+ var backURI = backUriList.pop() || (CONFIG.CONTEXT_PATH + 'index.html');
|
|
|
+ var jStr = "";
|
|
|
+ for (var i = 0,
|
|
|
+ length = backUriList.length; i < length; i++) {
|
|
|
+ jStr += '"' + backUriList[i] + '",';
|
|
|
+ }
|
|
|
+ jStr = "[" + jStr.slice(0, -1) + "]";
|
|
|
+ PageH5.cookie.set('back_page_list', escape(jStr));
|
|
|
+ return backURI;
|
|
|
+ };
|
|
|
+
|
|
|
+ PageH5.goPlayVideo = function(url) {
|
|
|
+ var playEndURI = PageH5.getCurrentURI() + '&f=' + PageH5.btn.current.id;
|
|
|
+ if (PageH5.scrollScreen && PageH5.scrollScreen.config.enable) playEndURI += ('&scrollTop=' + PageH5.scrollScreen.config.scrollTop);
|
|
|
+ PageH5.cookie.set('play_end_page', escape(playEndURI));
|
|
|
+ location.href = CONFIG.CONTEXT_PATH + url;
|
|
|
+ };
|
|
|
+
|
|
|
+ PageH5.getPlayEndURI = function() {
|
|
|
+ var playEndURI = unescape(PageH5.cookie.get('play_end_page', CONFIG.CONTEXT_PATH + 'index.html'));
|
|
|
+ return playEndURI;
|
|
|
+ };
|
|
|
+})();
|
|
|
+
|
|
|
+PageH5.getParam = function(name, defaultValue) {
|
|
|
+ defaultValue = defaultValue === undefined ? '': defaultValue;
|
|
|
+ var result = new RegExp('(\\?|&)' + name + '=(.*?)(&|$)', 'g').exec(location.search);
|
|
|
+ return result ? result[2] : defaultValue;
|
|
|
+};
|
|
|
+
|
|
|
+PageH5.getParamInt = function(name, defaultValue) {
|
|
|
+ defaultValue = defaultValue === undefined ? 0 : defaultValue;
|
|
|
+ return parseInt(PageH5.getParam(name, defaultValue));
|
|
|
+};
|
|
|
+
|
|
|
+PageH5.focusHandler = function() {
|
|
|
+ PageH5.marquee.start();
|
|
|
+};
|
|
|
+PageH5.blurHandler = function() {
|
|
|
+ PageH5.marquee.stop();
|
|
|
+};
|
|
|
+
|
|
|
+(function() {
|
|
|
+ var aimg = document.createElement('img');
|
|
|
+ aimg.setAttribute('src', CONFIG.SPACER);
|
|
|
+ var atag = document.createElement('a');
|
|
|
+ atag.id = 'myDefaultLink';
|
|
|
+ atag.setAttribute('href', '#');
|
|
|
+ atag.appendChild(aimg);
|
|
|
+ document.body.appendChild(atag);
|
|
|
+ document.getElementById('myDefaultLink').focus();
|
|
|
+})();
|
|
|
+
|