function CookieTool(branch, path) { var m = this, keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=', accept = false, callbacks = new Array(), testProcess = false, testCallbacks = new Array(); if('undefined' == typeof(jQuery)) { throw 'jQuery is required'; } jQuery.extend(m, { init: function() { if(!window._CT) { window._CT = this; } }, test: function(callback, forceSend) { var tested = false; m.addTestCallback(callback); if(!testProcess) { if(!forceSend && (data = m.getTestStorage())) { m.setAccept(data); m.runTestCallbacks(data); tested = true; } else { try { testProcess = true; m.write('3rd-part-test', 'test', null, function(data) { if(data && data.success) { m.read('3rd-part-test', function(data) { m.setAccept(data); m.setTestStorage(data); tested = true; testProcess = false; m.runTestCallbacks(data); }, m.pbid()); } }, m.pbid()); } catch(e) { tested = false; testProcess = false; } } } return tested; }, setAccept: function(data) { if(data && data.success && data.value && data.value == 'test') { accept = true; } }, setTestStorage: function(data) { if(data && !data.dev) { m.storageSet('semi-ct-test-data-count-' + branch, '5'); m.storageSet('semi-ct-test-data-' + branch, m.base64Encode(m.objectToString(data))); } }, getTestStorage: function() { var count = parseInt(m.storageGet('semi-ct-test-data-count-' + branch, '0')); var data = m.storageGet('semi-ct-test-data-' + branch, null); if(data && 0 < count - 1) { m.storageSet('semi-ct-test-data-count-' + branch, (count - 1).toString()); return m.stringToObject(m.base64Decode(data)); } else { return null; } }, receive: function(data) { if(data && data.cbid && callbacks[data.cbid]) { if(jQuery.isFunction(callbacks[data.cbid])) { callbacks[data.cbid].call(this, data); } delete callbacks[data.cbid]; } }, addCallback: function(callback) { var id = (new Date().getTime()).toString() + Math.random().toString().replace('0.', ''); callbacks[id] = callback; return id; }, addTestCallback: function(callback) { testCallbacks.push(callback); }, runTestCallbacks: function(data) { jQuery.each(testCallbacks, function(key, el) { if(jQuery.isFunction(testCallbacks[key])) { testCallbacks[key].call(this, data, this); } delete testCallbacks[key]; }); /* for(key in testCallbacks) { if(jQuery.isFunction(testCallbacks[key])) { testCallbacks[key].call(this, data, this); } delete testCallbacks[key]; }*/ }, write: function(name, value, expire, callback, pbid) { var cook = 'name=' + name + '&value=' + value; if(expire) { cook += '&expire=' + expire; } if(callback) { cook += '&cbid=' + m.addCallback(callback); } if (pbid) { cook += '&pbid=' + pbid; } m.send('1?' + cook); }, read: function(name, callback, pbid) { var cook = 'name=' + name; if(callback) { cook += '&cbid=' + m.addCallback(callback); } if (pbid) { cook += '&pbid=' + pbid; } m.send('2?' + cook); }, send: function(cookie) { jQuery .getScript(path + 'service/semi-widget/cookie/' + branch + '/' + cookie); }, isAccept: function() { return accept; }, localread: function(name) { name = name + '='; var ca = document.cookie.split(';'); for(var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0)==' ') { c = c.substring(1, c.length); } if (c.indexOf(name) == 0) { return c .substring(name.length, c.length) .replace(/\{plus\}/g, '+') .replace(/\{slash\}/g, '/') .replace(/\{eq\}/g, '='); } } return null; }, localwrite: function(name, value, expires, path, domain) { value = value .replace(/\+/g, '{plus}') .replace(/\//g, '{slash}') .replace(/=/g, '{eq}'); var cook = name + '=' + value; if(expires) { var date = new Date(); date.setTime(date.getTime() + (expires * 60 * 1000)); cook += '; expires=' + date.toGMTString(); } if(path) { cook += '; path=' + path; } if(domain) { cook += '; domain=' + domain; } document.cookie = cook; }, cookies: function() { if(console) { console.log(document.cookie); } }, storageSet: function(key, value, local) { if(!local && 'undefined' != typeof(sessionStorage)) { sessionStorage.setItem(key, value); } else if (local && 'undefined' != typeof(localStorage)) { localStorage.setItem(key, value); } else { value = m.localwrite(key, value); } }, storageGet: function(key, def, local) { var value = def; if(!local && 'undefined' != typeof(sessionStorage)) { value = sessionStorage.getItem(key) } else if (local && 'undefined' != typeof(localStorage)) { value = localStorage.getItem(key); } else { value = m.localread(key); } return value; }, stringToObject: function(data) { try { data = JSON.parse(data); } catch(e) { data = {}; } return data; }, objectToString: function(data) { return JSON.stringify(data); }, base64Decode: function(input) { if(input) { var output = ''; var chr1, chr2, chr3, enc1, enc2, enc3, enc4; var i = 0; input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ''); while (i < input.length) { enc1 = keyStr.indexOf(input.charAt(i++)); enc2 = keyStr.indexOf(input.charAt(i++)); enc3 = keyStr.indexOf(input.charAt(i++)); enc4 = keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output = output + String.fromCharCode(chr1); if (enc3 != 64) { output = output + String.fromCharCode(chr2); } if (enc4 != 64) { output = output + String.fromCharCode(chr3); } } output = m.utf8Decode(output); } else { output = null; } return output; }, base64Encode: function(input) { var output = ''; var chr1, chr2, chr3, enc1, enc2, enc3, enc4; var i = 0; input = m.utf8Encode(input); while (i < input.length) { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); enc1 = chr1 >> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; } output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4); } return output; }, utf8Decode: function(utftext) { var string = ''; var i = 0; var c = c1 = c2 = 0; while (i < utftext.length) { c = utftext.charCodeAt(i); if (c < 128) { string += String.fromCharCode(c); i++; } else if((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i+1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; } else { c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; } } return string; }, utf8Encode: function(string) { string = string.replace(/\r\n/g, "\n"); var utftext = ''; for (var n = 0; n < string.length; n++) { var c = string.charCodeAt(n); if (c < 128) { utftext += String.fromCharCode(c); } else if((c > 127) && (c < 2048)) { utftext += String.fromCharCode((c >> 6) | 192); utftext += String.fromCharCode((c & 63) | 128); } else { utftext += String.fromCharCode((c >> 12) | 224); utftext += String.fromCharCode(((c >> 6) & 63) | 128); utftext += String.fromCharCode((c & 63) | 128); } } return utftext; }, pbid: function() { var pbid = m.getQueryParam('pbid'); if (!pbid) { pbid = m.storageGet('widget-payback-id-' + branch, null, true); } else { m.storageSet('widget-payback-id-' + branch, pbid, true); } return pbid; }, getQueryParam: function(param) { if (param) { return decodeURIComponent((new RegExp('[?|&]' + param + '=' + '([^&;]+?)(&|#|;|$)').exec(window.location.search) || [null, ''])[1].replace(/\+/g, '%20')); } return null; }, requestData: function(data) { if (!data) { data = {}; } data['pbid'] = m.pbid(); return data; } }); m.init(); }; function SemiTooltip(conf) { var m = this; jQuery.extend(m, { init: function() { if(conf.selector.length) { var tip = jQuery(m.template(conf.content, conf.position || 'top-right', conf.width || null)); conf.selector.eq(0) .data('tooltip', tip) .bind('click.tt', function(ev) { return false; }) .bind('mouseenter.tt', function(ev) { m.show(ev); }) .bind('mouseleave.tt', function(ev) { m.hide(ev); }); if(conf.to) { conf.to.eq(0) .append(tip); } else { conf.selector.eq(0) .append(tip) } delete tip; } }, template: function(data, position, width) { return ( '
' ); }, position: function(tip, margin) { tip.css({ top: (margin.top?margin.top:0) + 'px', left: (margin.left?margin.left:0) + 'px' }); }, show: function(ev) { var tip = conf.selector.eq(0).data('tooltip'); m.position(tip, conf.margin || {}); tip.css({display: 'inline-block'}); delete tip; }, hide: function(ev) { conf.selector.eq(0).data('tooltip').css({display: 'none'}); } }); m.init(); }; function SemiScroll(conf) { var m = this; jQuery.extend(m, { init: function() { if(conf.selector.find('.semi-widget-scroll').length) { var scroll = conf.selector.find('.semi-widget-scroll').eq(0); var count = scroll.find('.semi-widget-scroll-item').length; scroll.find('.semi-widget-scroll-dots').empty(); scroll.find('.semi-widget-scroll-items').css({top: '0px'}); var dots = jQuery(m.dots(count)); dots.find('.semi-widget-scroll-dot').each(function(i, el) { jQuery(el) .data('item', i) .bind('click.sc', function(ev) { m.scroll(jQuery(this)); }); }); dots.css({ left: ((0 == scroll.width()?conf.width:scroll.width()) - (11 * count) - 12 ) + 'px'}); scroll.append(dots); delete dots; delete scroll; } }, dots: function(count) { var tmpl = ' '; return tmpl; }, scroll: function(dot) { var width = conf.selector.find('.semi-widget-scroll-item').width(); var height = 64; var current = m.dot(); var item = dot.data('item'); var scroll = conf.selector.find('.semi-widget-scroll').eq(0); dot.siblings('.semi-widget-scroll-dot').removeClass('semi-widget-scroll-dot-active'); conf.selector.find('.semi-widget-scroll-items').animate({top: ((-height * item)) + 'px'}, 400, 'swing', function() { dot.addClass('semi-widget-scroll-dot-active'); }); delete width; delete current; delete item; delete scroll; }, dot: function() { return conf.selector.find('.semi-widget-scroll-dot-active').eq(0).data('item'); } }); m.init(); }; function SemiEvents(conf) { var m = this; jQuery.extend(m, { events: new Array(), init: function() { if (conf.init) { jQuery .each(conf.init, function(i, event) { m.bind(event, function(ev) {}); }); } }, bind: function(event, func) { if (jQuery.isFunction(func)) { m.events[event] = func; } }, bindAll: function(events) { try { for (var ev in m.events) { eval('var func = events.' + ev); m.bind(ev, func); } } catch (e) { } }, trigger: function(event) { if ('undefined' != typeof(m.events[event])) { try { var args = [].slice.call(arguments, 1); m.events[event].apply(this, args); } catch (e) { } } } }); m.init(); }; function SemiPanels(conf) { "use strict"; var m = this, closeTimer = null; jQuery.extend(m, { init: function() { if (conf) { var close = jQuery(conf.btn) .off('click.wi') .on('click.wi', function(ev) { ev.preventDefault(); m.close(); }); if (conf.autoClose && !isNaN(parseInt(conf.autoClose))) { closeTimer = setTimeout( function() { m.close(); }, (parseInt(conf.autoClose) * 1000) ); } } }, show: function(showData) { jQuery(conf.btn).css({display: 'inline-block'}); var panel = jQuery(conf.panel).show(); if (conf.show && jQuery.isFunction(conf.show)) { conf.show.call(this, panel, this, (showData || {})); } }, close: function() { if (closeTimer) { clearTimeout(closeTimer); } jQuery(conf.btn).hide(); jQuery(conf.panel).hide().empty(); if (conf.close && jQuery.isFunction(conf.close)) { conf.close.call(this); } } }); m.init(); }; function SemiTools() { "use strict"; var m = this; jQuery.extend(m, { ieVersion: function() { var ie = navigator.userAgent.match(/MSIE \d+.\d+/i); if (ie) { var ver = ie[0].match(/\d+.\d+/i); return parseFloat(ver[0]); } return false; }, loadjs: function(file, callback, async) { var script = document.createElement('script'); script.type = 'text/javascript'; script.src = file; script.async = (async?true:false); if (false != (version = m.ieVersion()) && 8 >= version) { script.onreadystatechange = function() { if ('loaded' == this.readyState) { callback.call(this, true); } }; } else { script.onload = function() { callback.call(this, true); }; } document.getElementsByTagName('head')[0].appendChild(script); } }); }; function SemiGTM(w, d, s, l, i) { w[l] = w[l] || []; w[l].push({ 'gtm.start': new Date().getTime(), 'event': 'gtm.js' }); var f = d.getElementsByTagName(s)[0], j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : ''; j.async = true; j.src = '//www.googletagmanager.com/gtm.js?id=' + i + dl; f.parentNode.insertBefore(j, f); };