(function () { var k = window.Como = function (a, b) { return new k.fn.initialize(a, b) }; k.extend = function (a, b) { if (!a) a = {}; for (var c in b) { a[c] = b[c] } return a }; k.fun = { bind: function (b) { var c = arguments[1], args = []; for (var i = 2, il = arguments.length; i < il; i++) { args.push(arguments[i]) } return function () { var a = args.concat(); for (var i = 1, il = arguments.length; i < il; i++) { a.push(arguments[i]) } b.apply(c, a) } }, bindEvent: function (b) { var c = arguments[1], args = []; for (var i = 2, il = arguments.length; i < il; i++) { args.push(arguments[i]) } return function (e) { var a = args.concat(); a.unshift(e || window.event); b.apply(c, a) } } }; k.str = { trim: function (a) { return a.replace(/^\s+|\s+$/g, '') }, byteLength: function (a) { return a.replace(/[^\x00-\xff]/g, "**").length }, toLower: function (a) { return a.toLowerCase() }, removeHTML: function (a) { return a.replace(/<\/?[^>]+>/gi, '').replace(/[\r\n]/gi, '') } }; k.arr = { _each: function (a, b, c) { var r = []; for (var i = 0, il = a.length; i < il; i++) { var v = b(a[i], i); if (c && typeof(v) != 'undefined') r.push(v) } return r }, each: function (a, b) { this._each(a, b, false); return this }, include: function (a, b) { return this.index(a, b) != -1 }, index: function (a, b) { for (var i = 0, il = a.length; i < il; i++) { if (a[i] == b) return i } return -1 }, remove: function (a, o) { if (typeof o == 'number') { a.splice(o, 1) } else { var i = a.index(o); a.splice(i, 1) } return a }, collect: function (a, b) { return a._each(b, true) }, unique: function (a) { var b = a.length; for (var i = 0, il = b; i < il; i++) { var c = a[i]; for (var j = b - 1; j > i; j--) { if (a[j] == c) a.splice(j, 1) } } return a } }; k.fn = k.prototype = { length: 0, como: "1.0.0", initialize: function (a, b) { a = k.find(a, b); return this.setArray(k.makeArray(a)) }, setArray: function (a) { this.length = 0; Array.prototype.push.apply(this, a); return this }, size: function () { return this.length }, get: function (a) { return a == undefined ? k.makeArray(this) : this[a] }, each: function (a) { for (var i = 0, il = this.length; i < il; i++) { a(this[i], i) } return this }, index: function (a) { return k.inArray(a && a.como ? a[0] : a, this) }, attr: function (b, c) { if (typeof(c) == 'undefined') { var d = this[0]; switch (b) { case 'class': return d.className; case 'style': return d.style.cssText; default: return d.getAttribute(b) } } else { this.each(function (a) { switch (b) { case 'class': a.className = c; break; case 'style': a.style.cssText = c; break; default: a.setAttribute(b, c) } }); return this } }, prop: function (b, c) { if (typeof(c) == 'undefined') { return this[0][b] } else { this.each(function (a) { a[b] = c }); return this } }, remove: function () { this.each(function (a) { a.parentNode.removeChild(a) }) }, css: function (c, d) { if (typeof(d) == 'undefined') { var e = this[0]; if (c == 'opacity') { if (k.Browser.ie) { return e.filter && e.filter.indexOf("opacity=") >= 0 ? parseFloat(e.filter.match(/opacity=([^)]*)/)[1]) / 100 : 1 } else { return e.style.opacity ? parseFloat(e.style.opacity) : 1 } } else { function hyphenate(b) { return b.replace(/[A-Z]/g, function (a) { return '-' + k.str.toLower(a) }) } if (window.getComputedStyle) { return window.getComputedStyle(e, null).getPropertyValue(hyphenate(c)) } if (document.defaultView && document.defaultView.getComputedStyle) { var f = document.defaultView.getComputedStyle(e, null); if (f) return f.getPropertyValue(hyphenate(c)); if (c == "display") return "none" } if (e.currentStyle) { return e.currentStyle[c] } return e.style[c] } } else { this.each(function (a) { if (c == 'opacity') { if (k.Browser.ie) { a.style.filter = 'Alpha(Opacity=' + d * 100 + ');' } else { a.style.opacity = (d == 1 ? '' : '' + d) } } else { a.style[c] = d } }); return this } }, html: function (a) { return this.prop('innerHTML', a) }, val: function (a) { if (typeof(a) == 'undefined') { var b = this[0]; if (k.str.toLower(b.tagName) == 'input') { switch (b.type) { case 'checkbox': return b.checked ? true : false; break; case 'radio': return b.checked ? true : false; break } } return b.value } else { return this.prop('value', a) } }, up: function (b) { var c = k.find(b, document); var d = []; this.each(function (a) { while ((a = a.parentNode)) { if (k.arr.include(c, a)) { d.push(a) } } }); return k(d) }, upWithMe: function (b) { var c = k.find(b, document); var d = []; this.each(function (a) { while (a) { if (k.arr.include(c, a)) { d.push(a) } a = a.parentNode } }); return k(d) }, on: function (b, c) { this.each(function (a) { k.Event.on(a, b, c) }); return this }, un: function (b, c) { this.each(function (a) { k.Event.un(a, b, c) }); return this }, out: function (b, c, d) { this.each(function (a) { k.Event.out(a, b, c, d) }); return this }, unout: function (b, c) { this.each(function (a) { k.Event.unout(a, b, c) }); return this }, left: function (b) { if (typeof(b) == 'undefined') { return this.pos().left } else { this.each(function (a) { a.style.left = b + 'px' }) } }, top: function (b) { if (typeof(b) == 'undefined') { return this.pos().top } else { this.each(function (a) { a.style.top = b + 'px' }) } }, pos: function () { var a = 0, top = 0, el = this[0], de = document.documentElement, db = document.body, add = function (l, t) { a += l || 0; top += t || 0 }; if (el == document.body) { if (typeof(window.pageYOffset) == 'number') { top = window.pageYOffset; a = window.pageXOffset } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) { top = document.body.scrollTop; a = document.body.scrollLeft } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) { top = document.documentElement.scrollTop; a = document.documentElement.scrollLeft } } else { if (el.getBoundingClientRect) { var b = el.getBoundingClientRect(); add(b.left + Math.max(de.scrollLeft, db.scrollLeft) - de.clientLeft, b.top + Math.max(de.scrollTop, db.scrollTop) - de.clientTop) } else { var c = el.offsetParent, fixed = el.style.position == 'fixed', oc = el, parent = el.parentNode; add(el.offsetLeft, el.offsetTop); while (c) { add(c.offsetLeft, c.offsetTop); if (k.Browser.firefox && !/^t(able|d|h)$/i.test(c.tagName) || k.Browser.safari) { add(el.style.borderLeftWidth, el.style.borderTopWidth) } if (!fixed && c.style.position == 'fixed') fixed = true; oc = k.str.toLower(c.tagName) == 'body' ? oc : c; c = c.offsetParent } while (parent && parent.tagName && !/^body|html$/i.test(parent.tagName)) { if (!/^inline|table.*$/i.test(parent.style.display)) add(-parent.scrollLeft, -parent.scrollTop); if (k.Browser.firefox && parent.style.overflow != 'visible') add(parent.style.borderLeftWidth, parent.style.borderTopWidth); parent = parent.parentNode } if (k.Browser.firefox && oc.style.position != 'absolute') add(-db.offsetLeft, -db.offsetTop); if (fixed) add(Math.max(de.scrollLeft, db.scrollLeft), Math.max(de.scrollTop, db.scrollTop)) } }; return { left: a, top: top } }, height: function (a) { if (typeof(a) == 'undefined') { return this[0].offsetHeight } else { return this.css('height', a + 'px') } }, width: function (a) { if (typeof(a) == 'undefined') { return this[0].offsetWidth } else { return this.css('width', a + 'px') } }, show: function (a) { this.css('display', a ? a : ''); return this }, hide: function () { this.css('display', 'none'); return this }, prev: function () { var a = this[0], r; while ((a = a.previousSibling)) { if (a.nodeType && a.nodeType == 1) { r = a; break } } return r ? k(r) : null }, prevAll: function () { var a = [], el = this[0]; while ((el = el.previousSibling)) { if (el.nodeType && el.nodeType == 1) { a.push(el) } } return k(a) }, next: function () { var a = this[0], r; while ((a = a.nextSibling)) { if (a.nodeType && a.nodeType == 1) { r = a; break } } return r ? k(r) : null }, nextAll: function () { var a = [], el = this[0]; while ((el = el.nextSibling)) { if (el.nodeType && el.nodeType == 1) { a.push(el) } } return k(a) }, first: function () { var a = this[0].childNodes[0], el = null; while (a) { if (a.nodeType && a.nodeType == 1) { el = a; break } a = a.nextSibling } return k(el) }, last: function () { var a = this[0].childNodes[this[0].childNodes.length - 1]; var b = a; a = null; while (b) { if (b.nodeType && b.nodeType == 1) { a = b; break } b = b.previousSibling } return k(a) }, children: function () { var a = this[0].childNodes, els = [], it; for (var i = 0, il = a.length; i < il; i++) { it = a[i]; if (it.nodeType && it.nodeType == 1) els.push(it) } return k(els) }, parent: function () { return k([this[0].parentNode]) } }; k.fn.initialize.prototype = k.fn; k.Event = { on: function (a, b, c) { if (a.addEventListener) { a.addEventListener(b, c, false) } else { a.attachEvent('on' + b, c) } }, un: function (a, b, c) { if (a.removeEventListener) { a.removeEventListener(b, c, false) } else { a.detachEvent('on' + b, c) } }, out: function (d, f, g, h) { h = h || false; if (!d._Event) { d._Event = { out: [] } } var i = function (e) { var a = k.Event.element(e)[0]; var b = false; while (a) { if (a == d) { b = true; break } a = a.parentNode } if (!b) { g(e); if (h) { k.Event.unout(d, f, g) } } }; var c = i.bindEvent(window); d._Event.out.push({ name: f, fun: g, efun: c }); k.Event.on(document.body, f, c) }, unout: function (a, b, c) { if (a._Event && a._Event.out && a._Event.out.length) { var d = a._Event.out; for (var i = 0; i < d.length; i++) { if (b == d[i].name && c == d[i].fun) { k.Event.un(document.body, b, d[i].efun); d.splice(i, 1); return } } } }, stop: function (e) { e.returnValue = false; if (e.preventDefault) { e.preventDefault() } k.Event.stopPropagation(e) }, stopPropagation: function (e) { e.cancelBubble = true; if (e.stopPropagation) { e.stopPropagation() } }, element: function (e) { return k.fn.setArray(k.makeArray([e.target || e.srcElement])) }, pos: function (e) { if (e.pageX || e.pageY) { return { x: e.pageX, y: e.pageY } } return { x: e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft), y: e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) } } }; (function () { var a = /(?:MSIE.(\d+\.\d+))|(?:(?:Firefox|GranParadiso|Iceweasel).(\d+\.\d+))|(?:Opera.(\d+\.\d+))|(?:AppleWebKit.(\d+(?:\.\d+)?))/.exec(navigator.userAgent); var b = {}; if (a) { b._ie = a[1] ? parseFloat(a[1]) : NaN; if (b._ie >= 8 && !window.HTMLCollection) { b._ie = 7 } b._firefox = a[2] ? parseFloat(a[2]) : NaN; b._opera = a[3] ? parseFloat(a[3]) : NaN; b._safari = a[4] ? parseFloat(a[4]) : NaN } else { b._ie = b._firefox = b._opera = b._safari = NaN } k.Browser = { version: b._ie || b._firefox || b._opera || b._safari, safari: b._safari > 0, opera: b._opera > 0, ie: b._ie > 0, firefox: b._firefox > 0 } })(); k.fn.extend = function () { Object.each(arguments[0], function (a, b) { k.fn.initialize.prototype[b] = a }) }; k.extend(k, { makeArray: function (a) { var b = []; if (a != null) { var i = a.length; if (i == null) b[0] = a; else while (i) b[--i] = a[i] } return b }, inArray: function (a, b) { for (var i = 0, length = b.length; i < length; i++) if (b[i] === a) return i; return -1 }, find: function (t, a) { a = a || [document]; if (a.nodeType) { a = [a] } if (t instanceof Array) { return t } else { if (typeof t == 'object') { if (t.nodeType) { return [t] } else if (t.como) { return t } else { return [t] } } else { if (typeof t != 'string') return []; var b = this._formatSelectorStr(t); return this._getElements(b, a) } } }, _getElements: function (e, f) { var g = false; k.arr.each(e, function (b) { if (b.type == "id") { var c = document.getElementById(b.itemName); f = c ? [c] : [] } else { var d = [], childs; if (g) { var c = []; k.arr.each(f, function (a) { for (var j = 0, jl = a.childNodes.length; j < jl; j++) { if (a.childNodes[j].nodeType == 1) c.push(a.childNodes[j]) } }); f = c } if (b.type == "tag") { k.arr.each(f, function (a) { if (g) { if (a.tagName.toLower() == b.itemName) { d.push(a) } } else { childs = a.getElementsByTagName(b.itemName); for (var j = 0, jl = childs.length; j < jl; j++) { d.push(childs[j]) } } }); f = d } if (b.type == "class") { k.arr.each(f, function (a) { if (g) { childs = [a] } else childs = a.getElementsByTagName('*'); for (var j = 0, jl = childs.length; j < jl; j++) { var v = childs[j].className; if (v) { v = ' ' + v + ' '; if (v.indexOf(' ' + b.itemName + ' ') > -1) { d.push(childs[j]) } } } }); f = d } if (b.type == "child") { g = true } else { g = false } if (b.propName != "") { f = k.arr.collect(f, function (a) { var v = b.propName == 'class' ? a.className : a.getAttribute(b.propName); if (v != null) { if (b.propValue != '') { if (v == b.propValue) return a } else { return a } } }) } } }); return k.arr.unique(f) }, _formatSelectorStr: function (e) { var f = [], result = [], tmp = 0, m; var g = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|[^[\]]+)+\]|\\.|[^ >+~,(\[]+)+|[>+~])(\s*,\s*)?/g; while ((m = g.exec(e)) !== null) { f.push(m[1]) } k.arr.each(f, function (a, i) { var b = { type: '', itemName: '', propName: '', propValue: '' }; if (a == '>') { b.type = 'child' } else { var c = a.split('['); var d = c[0]; switch (d.charAt(0)) { case '#': { b.type = 'id'; b.itemName = d.substring(1); break } case '.': { b.type = 'class'; b.itemName = d.substring(1); break } default: { b.type = 'tag'; b.itemName = d; break } } if (c.length > 1) { d = c[1]; tmp = d.indexOf('='); if (tmp != -1) { d = d.split('='); b.propName = d[0]; b.propValue = d[1].substring(0, d[1].length - 1) } else { b.propName = d.substring(0, d.length - 1); b.propValue = '' } } } result.push(b) }); return result } }); k.range = { getSelectorText: function () { if (k.Browser.ie) { return this._getSelectionText() } else { var a = document.activeElement; if (a && (k.str.toLower(a.tagName) == 'input' || k.str.toLower(a.tagName) == 'textarea')) { return this._getInputSelectionText(a) } else { return this._getSelectionText() } } }, _getSelectionText: function () { if (window.getSelection) { return window.getSelection().toString() } else if (document.selection && document.selection.createRange) { return document.selection.createRange().text } return '' }, _getInputSelectionText: function (a) { if (a.selectionStart != undefined && a.selectionEnd != undefined) { return a.value.substring(a.selectionStart, a.selectionEnd) } return "" } }; k.Drag = function (a, b, c) { this.element = k(a); this.target = k(b); this.callback = c; this._status = 0; this._bind(); return this }; k.Drag.prototype._bind = function () { this._bindDown = k.fun.bindEvent(this._down, this); this.element.on('mousedown', this._bindDown) }; k.Drag.prototype._down = function (e) { this._mouseDown = this._getMouseXY(e); this._beginDown = k.extend({}, this._mouseDown); this._bindMove = k.fun.bindEvent(this._move, this); this._bindUp = k.fun.bindEvent(this._up, this); k(document).on('mousemove', this._bindMove); k(document).on('mouseup', this._bindUp); this._status = 1; k.Event.stop(e); return false }; k.Drag.prototype._move = function (e) { if (this._status == 0) return; this._status = 2; if (!this._hasMoving) { if (this._mouseDown.x - this._beginDown.x > 5 || this._mouseDown.y - this._beginDown.y) { this._hasMoving = true } } var a = this._getMouseXY(e); var b = { left: parseInt(this.target.css('left').replace('px', '')), top: parseInt(this.target.css('top').replace('px', '')) }; var c = b.left + a.x - this._mouseDown.x; var d = b.top + a.y - this._mouseDown.y; this._mouseDown = a; this.target.css('left', c + 'px').css('top', d + 'px'); k.Event.stop(e); return false }; k.Drag.prototype._up = function (e) { if (this._status != 2) { this._status = 0; return } k(document).un('mousemove', this._bindMove); k(document).un('mouseup', this._bindUp); this._status = 0; k.Event.stop(e); if (this.callback) this.callback(); return false }; k.Drag.prototype._getMouseXY = function (e) { if (e.pageX || e.pageY) { return { x: e.pageX, y: e.pageY } } return { x: e.clientX + document.body.scrollLeft - document.body.clientLeft, y: e.clientY + document.body.scrollTop - document.body.clientTop } }; k.click = {}; k.click.fix = function (a, b, c) { this.firstClick = false; this.timer = null; this.delay = 300; k(a).on('click', k.fun.bind(function () { this.firstClick == false ? this.timer = setTimeout(k.fun.bind(function () { b(); this.firstClick = false }, this), this.delay) : ''; this.firstClick = true }, this)).on('dblclick', k.fun.bind(function () { clearTimeout(this.timer); this.firstClick = false; c() }, this)) }; k.log = function (a) { if (!k.Browser.ie) console.log(a) }; var n = { url: 'http://yi.comsome.com/', init: function () { var b = document.createElement("div"); b.setAttribute('id', 'cs_someyi'); this._bodyTop = 30; with(b.style) { position = "absolute"; top = (k(document.body).pos().top + this._bodyTop) + 'px'; left = (k(document.body).width() - 30) + 'px'; textAlign = "left"; fontSize = "13px"; fontFamily = "Microsoft YaHei,'微软雅黑'"; zIndex = "10000"; lineHeight = "1.5"; color = "#FFFFFF"; overflow = 'visible' } b.innerHTML = '
' + '' + ''; document.body.appendChild(b); this.element = k(b); this.wallonEl = k("#cs_someyi_wallon"); this.contentEl = k("#cs_someyi_content"); this.loadEl = k("#cs_someyi_load"); this.timeEl = k('#cs_someyi_time'); this.pauseEl = k('#cs_someyi_pause'); this.closeEl = k('#cs_someyi_close'); if (k.Browser.ie) { var c = this.wallonEl.first().children(); this.span1El = k(c.get(0)); this.span2El = k(c.get(2)) } k.click.fix("#cs_someyi_icon", k.fun.bind(k.someyi.pause, k.someyi), k.fun.bind(k.someyi.close, k.someyi)); this.pauseEl.on('click', k.fun.bind(n.pause, this)); this.pauseEl.on('mouseover', function () { n.pauseEl.css('backgroundPosition', (n._pause ? '0' : '-17px') + ' -48px') }).on('mouseout', function () { n.pauseEl.css('backgroundPosition', (n._pause ? '0' : '-17px') + ' -64px') }); this.closeEl.on('click', k.fun.bind(n.close, this)); k(window).on('scroll', k.fun.bind(function () { this.element.css('top', (k(document.body).pos().top + this._bodyTop) + 'px') }, this)); this.drag = new k.Drag("#cs_someyi_icon", this.element, function () { var w = k(document.body).width(); var p = n.element.pos(); var x = p.left; var y = p.top; var a = n.wallonEl.first().children(); if (x > w / 2) { a.css('backgroundImage', 'url(' + n.url + 'images/wallon1.png)'); n.wallonEl.css('left', null).css('right', '50px'); n.contentEl.css('marginLeft', '5px') } else { a.css('backgroundImage', 'url(' + n.url + 'images/wallon2.png)'); n.wallonEl.css('left', '-10px').css('right', null); n.contentEl.css('marginLeft', '20px') } n._bodyTop = p.top - k(document.body).pos().top }) }, showLoad: function () { this.loadEl.show() }, hideLoad: function () { this.loadEl.hide() }, setTranslate: function (a, b) { this.time = 9; this._pause = false; this.hideLoad(); if (!this._walShowFun) { this._walShowFun = k.fun.bind(function () { if (!this._pause) this.time--; if (this.time < 0) { this.wallonEl.hide(); clearInterval(this._walShowTimer) } else { this.timeEl.html(this.time) } }, this) } if (this._walShowTimer) { clearInterval(this._walShowTimer) } var w = 300; var l = k.str.byteLength(a); var c = k.str.byteLength(b); if (l < c) l = c; if (l < 50) { w = l * 10 } if (w < 80) w = 80; if (w > 410) w = 410; this._walShowTimer = setInterval(this._walShowFun, 1000); this.wallonEl.width(w); this.timeEl.html(this.time); this.wallonEl.show(); this.contentEl.html(a + '
' + b); if (k.Browser.ie) { var h = this.contentEl.height(); this.span1El.height(h + 20); this.span2El.height(h + 20) } }, pause: function () { if (this._pause) { this._pause = false; this.pauseEl.css('backgroundPosition', '-17px -64px') } else { this._pause = true; this.pauseEl.css('backgroundPosition', '0 -64px') } }, close: function () { this.wallonEl.hide(); this._pause = false; clearInterval(this._walShowTimer) } }; k.someyi = { status: 0, init: function () { k.someyi.status = 1; k.someyi.open(); k.someyi.listener(); n.hideLoad() }, open: function () { if (this._isClose) { if (this._isPause) { this.pause() } n.element.show() } var a = k.str.trim(k.range.getSelectorText()); this.translate(a) }, _isPause: false, pause: function () { if (n.drag._hasMoving) { n.drag._hasMoving = false; return } if (this._isPause) { this._isPause = false; this.listener(); k("#cs_someyi_icon").css('backgroundPosition', '0 0') } else { this._isPause = true; this.unListener(); n.wallonEl.hide(); k("#cs_someyi_icon").css('backgroundPosition', '-45px 0') } }, _isClose: false, close: function () { this._isClose = true; n.element.hide(); this.unListener() }, translate: function (a) { a = k.str.removeHTML(a); if (!a) return; this.status = 2; n.showLoad(); this._translate({ text: a, success: function (r) { k.someyi.status = 3; n.setTranslate(a, r) }, failure: function () { k.someyi.status = 3; n.setTranslate(a, "There is some errors!") } }) }, _loadjs: function (a) { var b = document.createElement('script'); b.setAttribute('type', 'text/javascript'); b.setAttribute('src', a); document.getElementsByTagName('head')[0].appendChild(b); return b }, translate1: function (a) { k(this._ljs).remove(); if (a.responseStatus == 200) { var l = 'en'; var b = a.responseData.language; if (b != 'zh-CN') l = 'zh-CN'; this._ljs = this._loadjs('http://ajax.googleapis.com/ajax/services/language/translate?callback=Como.someyi.translate2&v=1.0&q=' + encodeURI(this._options.text) + '&langpair=' + b + '|' + l) } else { this._options.failure() } }, translate2: function (a) { k(this._ljs).remove(); if (a.responseStatus == 200) { this._options.success(a.responseData.translatedText) } else { this._options.failure() } }, _translate: function (a) { this._options = a; this._ljs = this._loadjs('http://ajax.googleapis.com/ajax/services/language/detect?callback=Como.someyi.translate1&v=1.0&q=' + encodeURI(a.text)) }, listener: function () { if (this._onMouseUp) { this.unListener() } else { this._onMouseUp = k.fun.bindEvent(this._mouseUp, this) } k(document.body).on('mouseup', this._onMouseUp) }, unListener: function () { k(document.body).un('mouseup', this._onMouseUp) }, _mouseUp: function (e) { if (n._pause) return; var a = k.str.trim(k.range.getSelectorText()); var b = k.Event.element(e); if (a) { if (b.upWithMe('#cs_someyi').length == 0) { this.translate(a) } } } }; n.init(); k.someyi.init() })()