var yao = function(){ var d = document, oa = '[object array]', fc = "[object function]", op = object.prototype, nt = "nodetype", listeners = [], webkitkeymap = { 63232: 38, // up 63233: 40, // down 63234: 37, // left 63235: 39, // right 63276: 33, // page up 63277: 34, // page down 25: 9 // shift-tab (safari provides a different key code in }, patterns = { hyphen: /(-[a-z])/i, root_tag: /body|html/i }, lasterror = null; return { isarray: function(obj){ return op.tostring.apply(obj) === oa; }, isstring: function(s){ return typeof s === 'string'; }, isboolean: function(b){ return typeof b === 'boolean'; }, isfunction: function(func){ return op.tostring.apply(func) === fc; }, isnull: function(obj){ return obj === null; }, isnumber: function(num){ return typeof num === 'number' && isfinite(num); }, isobject: function(str){ return (str && (typeof str === "object" || this.isfunction(str))) || false; }, isundefined: function(obj){ return typeof obj === 'undefined'; }, hasownproperty: function(obj, prper){ if (op.hasownproperty) { return obj.hasownproperty(prper); } return !this.isundefined(obj[prper]) && obj.constructor.prototype[prper] !== obj[prper]; }, ismobile: function(mobile){ return /^(13|15|18)\d{9}$/.test(yao.trim(mobile)); }, isname: function(name){ return /^[\w\u4e00-\u9fa5]{1}[\w\u4e00-\u9fa5 \.]{0,19}$/.test(yao.trim(name)); }, keys: function(obj){ var b = []; for (var p in obj) { b.push(p); } return b; }, values: function(obj){ var a = []; for (var p in obj) { a.push(obj[p]); } return a; }, isxmldoc: function(obj){ return obj.documentelement && !obj.body || obj.tagname && obj.ownerdocument && !obj.ownerdocument.body; }, formatnumber: function(b, e){ e = e || ''; b += ''; var d = b.split('.'); var a = d[0]; var c = d.length > 1 ? '.' + d[1] : ''; var f = /(\d+)(\d{3})/; while (f.test(a)) { a = a.replace(f, '$1,$2'); } return e + a + c; }, unformatnumber: function(a){ return a.replace(/([^0-9\.\-])/g, '') * 1; }, stringbuffer: function(){ var a = []; for (var i = 0; i < arguments.length; ++i) { a.push(arguments[i]); } return a.join(''); }, trim: function(str){ try { return str.replace(/^\s+|\s+$/g, ''); } catch (a) { return str; } }, striptags: function(str){ return str.replace(/<\/?[^>]+>/gi, ''); }, stripscripts: function(str){ return str.replace(/]*>([\\s\\s]*?)<\/script>/g, ''); }, isjson: function(obj){ obj = obj.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, ''); return (/^[,:{}\[\]0-9.\-+eaeflnr-u \n\r\t]*$/).test(obj); }, encodehtml: function(str){ return str.replace(/&/g, '&').replace(//g, '>'); }, decodehtml: function(str){ return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); }, tocamel: function(property){ if (!patterns.hyphen.test(property)) { return property; } if (propertycache[property]) { return propertycache[property]; } var converted = property; while (patterns.hyphen.exec(converted)) { converted = converted.replace(regexp.$1, regexp.$1.substr(1).touppercase()); } propertycache[property] = converted; return converted; }, cookie: { set: function(g, c, f, b){ var e = new date(); var a = new date(); if (f == null || f == 0) { f = 1; } a.settime(e.gettime() + 3600000 * 24 * f); d.cookie = g + '=' + encodeuri(c) + ';expires=' + a.togmtstring() + ';domain=' + b + '; path=/'; }, get: function(e){ var b = d.cookie; var d = e + '='; var c = b.indexof('; ' + d); if (c == -1) { c = b.indexof(d); if (c != 0) { return null; } } else { c += 2; } var a = d.cookie.indexof(';', c); if (a == -1) { a = b.length; } return decodeuri(b.substring(c + d.length, a)); }, clear: function(b, a){ if (this.get(b)) { d.cookie = b + '=' + ((domain) ? '; domain=' + a : '') + '; expires=thu, 01-jan-70 00:00:01 gmt'; } } }, ua: function(){ var c = { ie: 0, opera: 0, gecko: 0, webkit: 0, mobile: null, air: 0, caja: 0 }, b = navigator.useragent, a; if ((/khtml/).test(b)) { c.webkit = 1; } a = b.match(/applewebkit\/([^\s]*)/); if (a && a[1]) { c.webkit = parsefloat(a[1]); if (/ mobile\//.test(b)) { c.mobile = 'apple'; } else { a = b.match(/nokian[^\/]*/); if (a) { c.mobile = a[0]; } } a = b.match(/adobeair\/([^\s]*)/); if (a) { c.air = a[0]; } } if (!c.webkit) { a = b.match(/opera[\s\/]([^\s]*)/); if (a && a[1]) { c.opera = parsefloat(a[1]); a = b.match(/opera mini[^;]*/); if (a) { c.mobile = a[0]; } } else { a = b.match(/msie\s([^;]*)/); if (a && a[1]) { c.ie = parsefloat(a[1]); } else { a = b.match(/gecko\/([^\s]*)/); if (a) { c.gecko = 1; a = b.match(/rv:([^\s\)]*)/); if (a && a[1]) { c.gecko = parsefloat(a[1]); } } } } } a = b.match(/caja\/([^\s]*)/); if (a && a[1]) { c.caja = parsefloat(a[1]); } return c; }(), extend: function(subclass, superclass, override){ if (!superclass || !subclass) { throw new error('extend failed, please check that all dependencies are included.'); } var f = function(){}; f.prototype = superclass.prototype; subclass.prototype = new f(); subclass.prototype.constructor = subclass; subclass.superclass = superclass.prototype; if (superclass.prototype.constructor == object.prototype.constructor) { superclass.prototype.constructor = superclass; } if (override) { for (var p in override) { subclass.prototype[p] = override[p]; } } }, augmentproto: function(sub, sup){ if (!sub || !sup) { throw new error('augment failed, please check that all dependencies are included.'); } var d = sub.prototype, g = sup.prototype, b = arguments, c, h; if (b[2]) { for (c = 2; c < b.length; c += 1) { d[b[c]] = g[b[c]]; } } else { for (h in g) { if (!d[h]) { d[h] = g[h]; } } } }, augmentobject: function(e, d){ if (!d || !e) { throw new error('augment failed, please check that all dependencies are included.'); } var b = arguments, c, f; if (b[2]) { if (yao.isstring(b[2])) { e[b[2]] = d[b[2]]; } else { for (c = 0; c < b[2].length; c += 1) { e[b[2][c]] = d[b[2][c]]; } } } else { for (f in d) { e[f] = d[f]; } } return e; }, clone: function(d, f){ var e = function(){ }, b, c = arguments; e.prototype = d; b = new e; if (f) { for (p in f) { b[p] = f[p]; } } return b; }, addlistener: function(el, stype, fn, obj, overridecontext, bcapture){ var oel = null, context = null, wrappedfn = null; if(yao.isstring(el)){ oel = yao.getel(el); el = oel; } if(!el || !fn || !fn.call){ return false; } context = el; if (overridecontext) { if (overridecontext === true) { context = obj; } else { context = overridecontext; } } wrappedfn = function(e){ return fn.call(context, yao.getevent(e, el), obj); }; try { try { el.addeventlistener(stype, wrappedfn, bcapture); } catch (e) { try { el.attachevent('on' + stype, wrappedfn); } catch (e) { el['on' + stype] = wrappedfn; } } } catch (e) { lasterror = e; this.removelistener(el, stype, wrappedfn, bcapture); return false; } if ('unload' != stype) { // cache the listener so we can try to automatically unload listeners[listeners.length] = [el, stype, fn, wrappedfn, bcapture]; } return true; }, removelistener: function(el, stype, fn, bcapture){ try { if (window.removeeventlistener) { return function(el, stype, fn, bcapture){ el.removeeventlistener(stype, fn, (bcapture)); }; } else { if (window.detachevent) { return function(el, stype, fn){ el.detachevent("on" + stype, fn); }; } else { return function(){ }; } } } catch (e) { lasterror = e; return false; } return true; }, on: function(el, stype, fn, obj, overridecontext){ var oel = obj || el, scope = overridecontext || this; return yao.addlistener(el, stype, fn, oel, scope, false); }, stopevent: function(evt){ this.stoppropagation(evt); this.preventdefault(evt); }, stoppropagation: function(evt){ if (evt.stoppropagation) { evt.stoppropagation(); } else { evt.cancelbubble = true; } }, preventdefault: function(evt){ if (evt.preventdefault) { evt.preventdefault(); } else { evt.returnvalue = false; } }, getevent: function(e, boundel){ var ev = e || window.event; if (!ev) { var c = this.getevent.caller; while (c) { ev = c.arguments[0]; if (ev && event == ev.constructor) { break; } c = c.caller; } } return ev; }, getcharcode: function(ev){ var code = ev.keycode || ev.charcode || 0; // webkit key normalization if (yao.ua.webkit && (code in webkitkeymap)) { code = webkitkeymap[code]; } return code; }, _unload: function(e){ var j, l; if (listeners) { for (j = listeners.length - 1; j > -1; j--) { l = listeners[j]; if (l) { yao.removelistener(l[0], l[1], l[3], l[4]); } } l = null; } yao.removelistener(window, "unload", yao._unload); }, getel: function(elem){ var elemid, e, m, i, k, length, len; if (elem) { if (elem[nt] || elem.item) { return elem; } if (yao.isstring(elem)) { elemid = elem; elem = d.getelementbyid(elem); if (elem && elem.id === elemid) { return elem; } else { if (elem && elem.all) { elem = null; e = d.all[elemid]; for (i = 0, len = e.length; i < len; i += 1) { if (e[i].id === elemid) { return e[i]; } } } } return elem; } else { if (elem.dom_events) { elem = elem.get("element"); } else { if (yao.isarray(elem)) { m = []; for (k = 0, length = elem.length; k < length; k += 1) { m[m.length] = yao.getel(elem[k]); } return m; } } } } return null; }, hasclass: function(elem, classname){ var has = new regexp("(?:^|\\s+)" + classname + "(?:\\s+|$)"); return has.test(elem.classname); }, addclass: function(elem, classname){ if (yao.hasclass(elem, classname)) { return; } elem.classname = [elem.classname, classname].join(" "); }, removeclass: function(elem, classname){ var replace = new regexp("(?:^|\\s+)" + classname + "(?:\\s+|$)", "g"); if (!yao.hasclass(elem, classname)) { return; } var o = elem.classname; elem.classname = o.replace(replace, " "); if (yao.hasclass(elem, classname)) { yao.removeclass(elem, classname); } }, replaceclass: function(elem, newclass, oldclass){ if (newclass === oldclass) { return false; } var has = new regexp("(?:^|\\s+)" + newclass + "(?:\\s+|$)", "g"); if (!yao.hasclass(elem, newclass)) { yao.addclass(elem, oldclass); return; } elem.classname = elem.classname.replace(has, " " + oldclass + " "); if (yao.hasclass(elem, newclass)) { yao.replaceclass(elem, newclass, oldclass); } }, getelbyclassname: function(classname, tag, roottag){ var elems = [], i, tempcnt = yao.getel(roottag).getelementsbytagname(tag), len = tempcnt.length; for (i = 0; i < len; ++i) { if (yao.hasclass(tempcnt[i], classname)) { elems.push(tempcnt[i]); } } if (elems.length < 1) { return false; } else { return elems; } }, getstyle: function(el, property){ if (document.defaultview && document.defaultview.getcomputedstyle) { var value = null; if (property == 'float') { property = 'cssfloat'; } var computed = document.defaultview.getcomputedstyle(el, ''); if (computed) { value = computed[yao.tocamel(property)]; } return el.style[property] || value; } else { if (document.documentelement.currentstyle && yao.ua.ie) { switch (yao.tocamel(property)) { case 'opacity': var val = 100; try { val = el.filters['dximagetransform.microsoft.alpha'].opacity; } catch (e) { try { val = el.filters('alpha').opacity; } catch (e) { } } return val / 100; break; case 'float': property = 'stylefloat'; default: var value = el.currentstyle ? el.currentstyle[property] : null; return (el.style[property] || value); } } else { return el.style[property]; } } }, setstyle: function(el, property, val){ if (yao.ua.ie) { switch (property) { case 'opacity': if (yao.isstring(el.style.filter)) { el.style.filter = 'alpha(opacity=' + val * 100 + ')'; if (!el.currentstyle || !el.currentstyle.haslayout) { el.style.zoom = 1; } } break; case 'float': property = 'stylefloat'; default: el.style[property] = val; } } else { if (property == 'float') { property = 'cssfloat'; } el.style[property] = val; } }, setstyles: function(el, propertys){ for(var p in propertys){ yao.setstyle(el,p,propertys[p]); } return el; }, getelementsby: function(method, tag, root){ tag = tag || "*"; var m = []; if (root) { root = yao.getel(root); if (!root) { return m; } } else { root = document; } var oelem = root.getelementsbytagname(tag); if (!oelem.length && (tag === "*" && root.all)) { oelem = root.all; } for (var n = 0, j = oelem.length; n < j; ++n) { if (method(oelem[n])) { m[m.length] = oelem[n]; } } return m; }, getdocumentwidth: function(){ var k = yao.getscrollwidth(); var j = math.max(k, yao.getviewportwidth()); return j; }, getdocumentheight: function(){ var k = yao.getscrollheight(); var j = math.max(k, yao.getviewportheight()); return j; }, getscrollwidth: function(){ var j = (d.compatmode == "css1compat") ? d.body.scrollwidth : d.element.scrollwidth; return j; }, getscrollheight: function(){ var j = (d.compatmode == "css1compat") ? d.body.scrollheight : d.documentelement.scrollheight; return j; }, getxscroll: function(){ var j = self.pagexoffset || d.documentelement.scrollleft || d.body.scrollleft; return j; }, getyscroll: function(){ var j = self.pageyoffset || d.documentelement.scrolltop || d.body.scrolltop; return j; }, getviewportwidth: function(){ var j = self.innerwidth; var k = d.compatmode; if (k || c) { j = (k == "css1compat") ? d.documentelement.clientwidth : d.body.clientwidth; } return j; }, getviewportheight: function(){ var j = self.innerheight; var k = d.compatmode; if ((k || c) && !a) { j = (k == "css1compat") ? d.documentelement.clientheight : d.body.clientheight; } return j; }, removechildren: function(j){ if (!(prent = yao.getel(j))) { return false; } while (j.firstchild) { j.firstchild.parentnode.removechild(j.firstchild); } return j; }, prependchild: function(k, j){ if (!(k = yao.getel(k)) || !(j = yao.getel(j))) { return false; } if (k.firstchild) { k.insertbefore(j, k.firstchild); } else { k.appendchild(j); } return k; }, insertafter: function(l, j){ var k = j.parentnode; if (k.lastchild == j) { k.appendchild(l); } else { k.insertbefore(l, j.nextsibling); } }, setopacity: function(el, val){ yao.setstyle(el, 'opacity', val); }, builder: { nidx: 0, nodemap: { area: 'map', caption: 'table', col: 'table', colgroup: 'table', legend: 'fieldset', optgroup: 'select', option: 'select', param: 'object', tbody: 'table', td: 'table', tfoot: 'table', th: 'table', thead: 'table', tr: 'table' }, attr_map: { 'classname': 'class', 'htmlfor': 'for', 'readonly': 'readonly', 'maxlength': 'maxlength', 'cellspacing': 'cellspacing' }, empty_tag: /^(?:br|frame|hr|img|input|link|meta|range|spacer|wbr|area|param|col)$/i, // 追加link节点(添加css样式表) linknode: function(url, cssid, charset){ var c = charset || 'utf-8', link = null; var head = d.getelementsbytagname('head')[0]; link = this.node('link', { 'id': cssid || ('link-' + (yao.builder.nidx++)), 'type': 'text/css', 'charset': c, 'rel': 'stylesheet', 'href': url }); head.appendchild(link); return link; }, // 追加script节点 scriptnode: function(url, scriptid, win, charset){ var d = win || document.body; var c = charset || 'utf-8'; return d.appendchild(this.node('script', { 'id': scriptid || ('script-' + (yao.builder.nidx++)), 'type': 'text/javascript', 'charset': c, 'src': url })); }, // 创建元素节点 node: function(tag, attr, children){ tag = tag.touppercase(); // try innerhtml approach var parenttag = yao.builder.nodemap[tag] || 'div'; var parentelement = d.createelement(parenttag); var elem = null; try { // prevent ie "feature": http://dev.rubyonrails.org/ticket/2707 if (this.empty_tag.test(tag)) { //alert(tag); } else { parentelement.innerhtml = "<" + tag + ">"; } } catch (e) { } elem = parentelement.firstchild; // see if browser added wrapping tags if (elem && (elem.tagname.touppercase() != tag)) { elem = elem.getelementsbytagname(tag)[0]; } // fallback to createelement approach if (!elem) { if (yao.isstring(tag)) { elem = d.createelement(tag); } } // abort if nothing could be created if (!elem) { return; } else { if (attr) { this.attributes(elem, attr); } if (children) { this.child(elem, children); } return elem; } }, // 给节点添加属性 attributes: function(elem, attr){ var attrname = '', i; for (i in attr) { if (attr[i] && yao.hasownproperty(attr, i)) { attrname = i in yao.builder.attr_map ? yao.builder.attr_map[i] : i; if (attrname === 'class') { elem.classname = attr[i]; } else { elem.setattribute(attrname, attr[i]); } } } return elem; }, // 追加子节点 child: function(parent, child){ if (child.tagname) { parent.appendchild(child); return false; } if (yao.isarray(child)) { var i, length = child.length; for (i = 0; i < length; i += 1) { if (child[i].tagname) { parent.appendchild(child[i]); } else { if (yao.isstring(child[i])) { parent.appendchild(d.createtextnode(child[i])); } } } } else { if (yao.isstring(child)) { parent.appendchild(d.createtextnode(child)); } } } }, batch: function(el, method, o, override){ var id = el; el = yao.getel(el); var scope = (override) ? o : window; if (!el || el.tagname || !el.length) { if (!el) { return false; } return method.call(scope, el, o); } var collection = []; for (var i = 0, len = el.length; i < len; ++i) { if (!el[i]) { id = el[i]; } collection[collection.length] = method.call(scope, el[i], o); } return collection; }, fadeup: function(elem){ if (elem) { var level = 0, fade = function(){ var timer = null; level += 0.05; if (timer) { cleartimeout(timer); timer = null; } if (level > 1) { yao.setopacity(elem, 1); return false; } else { yao.setopacity(elem, level); } timer = settimeout(fade, 50); }; fade(); } }, zebra: function(){ var j, length = arguments.length; for (j = 0; j < length; ++j) { (function(config){ var root = yao.getel(config.roottag) || (config.root || null), rows = root.getelementsbytagname(config.rowtag) || (config.rows || null), i, len = rows.length, lastclass = []; if (root && rows && len > 1) { for (var i = 0; i < len; ++i) { rows[i].classname = i % 2 === 0 ? 'even' : 'odd'; lastclass[i] = rows[i].classname; yao.on(rows[i],'mouseover', function(index){ return function(){ yao.replaceclass(this, lastclass[index], 'hover'); } }(i),rows[i],true); yao.on(rows[i], 'mouseout', function(index){ return function(){ yao.replaceclass(this, 'hover', lastclass[index]); } }(i),rows[i],true); } } else { return false; } })(arguments[j]); } }, moveelement: function(element, finalx, finaly, speed){ var elem = yao.isstring(element) ? yao.getel(element) : element, style = null; if (elem) { if (elem.movement) { cleartimeout(elem.movement); } if (!elem.style.left) { elem.style.left = "0"; } if (!elem.style.top) { elem.style.top = "0"; } var xpos = parseint(elem.style.left); var ypos = parseint(elem.style.top); if (xpos == finalx && ypos == finaly) { return true; } if (xpos < finalx) { var dist = math.ceil((finalx - xpos) / 10); xpos = xpos + dist; } if (xpos > finalx) { var dist = math.ceil((xpos - finalx) / 10); xpos = xpos - dist; } if (ypos < finaly) { var dist = math.ceil((finaly - ypos) / 10); ypos = ypos + dist; } if (ypos > finaly) { var dist = math.ceil((ypos - finaly) / 10); ypos = ypos - dist; } elem.style.left = xpos + "px"; elem.style.top = ypos + "px"; elem.movement = settimeout(function(){ yao.moveelement(element, finalx, finaly, speed); }, speed); } }, ajax: function(config){ var oxhr, method = config.method ? config.method.touppercase() : 'get', url = config.url || '', fn = config.fn || null, postdata = config.data || null, elem = config.id ? yao.getel(config.id) : (config.element || null), load = config.loadfn ? config.loadfn : (config.loading || '正在获取数据,请稍后...'); if (!url) { return; } if (window.xmlhttprequest) { oxhr = new xmlhttprequest(); } else { if (window.activexobject) { oxhr = new activexobject("microsoft.xmlhttp"); } } if (oxhr) { try { oxhr.open(method, url, true); oxhr.onreadystatechange = function(){ if (oxhr.readystate !== 4) { return false } if (oxhr.readystate == 4) { if (oxhr.status == 200 || location.href.indexof('http') === -1) { if (fn) { fn.success(oxhr); } else { elem.innerhtml = oxhr.responsetext; } } else { if (fn) { fn.failure(oxhr.status); } else { if (yao.isfunction(load)) { load(); } else { elem.innerhtml = load; } } } } }; oxhr.setrequestheader('x-requested-with', 'xmlhttprequest'); if (postdata) { oxhr.setrequestheader('content-type', 'application/x-www-form-urlencoded; charset=utf-8'); } oxhr.send(postdata); } catch (e) { throw new error(e); return false; } } else{ throw new error("your browser does not support xmlhttp."); return false; } }, json: function(){ function f(n){ return n < 10 ? '0' + n : n; } date.prototype.tojson = function(){ return this.getutcfullyear() + '-' + f(this.getutcmonth() + 1) + '-' + f(this.getutcdate()) + 't' + f(this.getutchours()) + ':' + f(this.getutcminutes()) + ':' + f(this.getutcseconds()) + 'z'; }; var m = { '\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"': '\\"', '\\': '\\\\' }; function stringify(value, whitelist){ var a, i, k, l, r = /["\\\x00-\x1f\x7f-\x9f]/g, v; switch (typeof value) { case 'string': return r.test(value) ? '"' + value.replace(r, function(a){ var c = m[a]; if (c) { return c; } c = a.charcodeat(); return '\\u00' + math.floor(c / 16).tostring(16) + (c % 16).tostring(16); }) + '"' : '"' + value + '"'; case 'number': return isfinite(value) ? string(value) : 'null'; case 'boolean': case 'null': return string(value); case 'object': if (!value) { return 'null'; } if (typeof value.tojson === 'function') { return stringify(value.tojson()); } a = []; if (typeof value.length === 'number' && !(value.propertyisenumerable('length'))) { l = value.length; for (i = 0; i < l; i += 1) { a.push(stringify(value[i], whitelist) || 'null'); } return '[' + a.join(',') + ']'; } if (whitelist) { l = whitelist.length; for (i = 0; i < l; i += 1) { k = whitelist[i]; if (typeof k === 'string') { v = stringify(value[k], whitelist); if (v) { a.push(stringify(k) + ':' + v); } } } } else { for (k in value) { if (typeof k === 'string') { v = stringify(value[k], whitelist); if (v) { a.push(stringify(k) + ':' + v); } } } } return '{' + a.join(',') + '}'; } } return { stringify: stringify, parse: function(text, filter){ var j; function walk(k, v){ var i, n; if (v && typeof v === 'object') { for (i in v) { if (op.hasownproperty.apply(v, [i])) { n = walk(i, v[i]); if (n !== undefined) { v[i] = n; } else { delete v[i]; } } } } return filter(k, v); } if (/^[\],:{}\s]*$/.test(text.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[ee][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { j = eval('(' + text + ')'); return typeof filter === 'function' ? walk('', j) : j; } throw new syntaxerror('parsejson'); } }; }(), ytabs: function(){ var j, len = arguments.length, tabs = []; for (j = 0; j < len; ++j) { tabs[j] = new yao.singletab(arguments[j]); } return tabs; }, scrollnews: function(s, si, rt, ct){ var sn = new yao.scrollvertical(s, si, rt, ct); sn.speed = 4000; sn.ispause = true; var tm = settimeout(function(){ if (tm) { cleartimeout(tm); } sn.ispause = false; }, 2000); yao.on(sn.scrollarea, 'mouseover', function(){ sn.ispause = true; }); yao.on(sn.scrollarea, 'mouseout', function(){ sn.ispause = false; }); } }; yao.on(window, "unload", yao._unload); }(); yao.carousel = function(oconfig){ this.btnprevious = oconfig.btnprevious; this.lnkbtnprevious = this.btnprevious.getelementsbytagname('a')[0]; this.container = oconfig.containerid ? yao.getel(oconfig.containerid) : (oconfig.container || null); this.scroller = oconfig.scrollid ? yao.getel(oconfig.scrollid) : (oconfig.scroller || null); this.btnnext = oconfig.btnnext; this.lnkbtnnext = this.btnnext.getelementsbytagname('a')[0]; this.items = oconfig.itemtag ? this.container.getelementsbytagname(oconfig.itemtag) : (oconfig.items || null); this.length = this.items.length; this.itemwidth = this.items[0].offsetwidth; this.itemheight = this.items[0].offsetheight; this.scrollerwidth = this.itemwidth * this.length; this.scrollheight = this.itemheight * this.length; this.derection = oconfig.derection || 'h'; this.stepheight = oconfig.stepheight || this.itemheight; this.stepwidth = oconfig.stepwidth || this.itemwidth; this.groups = this.derection === 'h' ? math.ceil(this.scrollerwidth / this.stepwidth) : math.ceil(this.scrollheight / this.stepheight); this.maxmovednum = this.derection === 'h' ? (this.groups - (this.container.offsetwidth / this.stepwidth)) : (this.groups - (this.container.offsetheight / this.stepheight)); this.scrollspeed = oconfig.speed || 50; this.init(); }; yao.carousel.prototype.movednum = 0; yao.carousel.prototype.init = function(){ var oself = this; if (this.derection === 'h') { this.scroller.style.width = this.scrollerwidth + 'px'; } else { this.scroller.style.height = this.scrollerheight + 'px'; } this.container.style.overflow = 'hidden'; if (this.lnkbtnnext && this.movednum === this.maxmovednum) { yao.addclass(this.lnkbtnnext, 'dis'); } if (this.lnkbtnprevious && this.movednum === 0) { yao.addclass(this.lnkbtnprevious, 'dis'); } yao.on(this.btnprevious, 'click', this.scrollprevious, this.btnprevious, oself); yao.on(this.btnnext, 'click', this.scrollnext, this.btnnext, oself); }; yao.carousel.prototype.scrollprevious = function(event){ var evt = event || window.event; if (this.movednum > 0) { this.movednum -= 1; if (this.lnkbtnnext && yao.hasclass(this.lnkbtnnext, 'dis')) { yao.removeclass(this.lnkbtnnext, 'dis'); } if (this.movednum <= 0) { this.movednum = 0; if (this.lnkbtnprevious) { yao.addclass(this.lnkbtnprevious, 'dis'); } } this.scroll(this.movednum); } yao.stopevent(evt); }; yao.carousel.prototype.scrollnext = function(event){ var evt = event || window.event; if (this.movednum < this.maxmovednum) { this.movednum += 1; if (this.lnkbtnprevious && yao.hasclass(this.lnkbtnprevious, 'dis')) { yao.removeclass(this.lnkbtnprevious, 'dis'); } if (this.movednum >= this.maxmovednum) { this.movednum = this.maxmovednum; if (this.lnkbtnnext) { yao.addclass(this.lnkbtnnext, 'dis'); } } this.scroll(this.movednum); } yao.stopevent(evt); }; yao.carousel.prototype.scroll = function(steps){ var scrollwidth = 0, scrollheight = 0; if (this.derection === 'h') { if (this.stepwidth) { scrollwidth = -(this.stepwidth * steps); } else { scrollwidth = -(this.itemwidth * steps); } } else { if (this.stepheight) { scrollheight = -(this.stepheight * steps); } else { scrollheight = -(this.itemheight * steps); } } yao.moveelement(this.scroller, scrollwidth, scrollheight, this.scrollspeed); }; yao.yalbum = function(){ var oself = this; this.ocarousel = new yao.carousel({ btnprevious: oself.carsouel_btn_previous, container: oself.carsouel_container, scroller: oself.carsouel_scroller, btnnext: oself.carsouel_btn_next, itemtag: oself.carsouel_item_tag, stepwidth: oself.carsouel_step_width }) || null; this.osamples = this.ocarousel.scroller.getelementsbytagname('a') || null; this.length = this.osamples.length || 0; this.lastsample = this.osamples[0] || null; this.photocontainer = yao.getel(this.photo_container_id) || null; this.photo = yao.getel(this.photo_id) || null; this.photointro = yao.getel(this.photo_intro_id) || null; this.sintro = this.photo.alt || ''; this.init(); }; yao.yalbum.prototype.lastindex = 0; yao.yalbum.prototype.isloading = false; yao.yalbum.prototype.lastphotoheight = 0; yao.yalbum.prototype.loadshardow = null; yao.yalbum.prototype.loadimg = null; yao.yalbum.prototype.carsouel_btn_previous = yao.getel('carousel_btn_lastgroup'); yao.yalbum.prototype.carsouel_container = yao.getel('carousel_container'); yao.yalbum.prototype.carsouel_scroller = yao.getel('samples_list'); yao.yalbum.prototype.carsouel_btn_next = yao.getel('carousel_btn_nextgroup'); yao.yalbum.prototype.carsouel_item_tag = 'li'; yao.yalbum.prototype.carsouel_step_width = 60; yao.yalbum.prototype.photo_max_width = 60; yao.yalbum.prototype.photo_container_id = 'carousel_photo_container'; yao.yalbum.prototype.photo_id = 'carousel_photo'; yao.yalbum.prototype.photo_intro_id = 'carousel_photo_intro'; yao.yalbum.prototype.btn_next_id = 'carousel_next_photo'; yao.yalbum.prototype.btn_next_class = 'next'; yao.yalbum.prototype.btn_previous_id = 'carousel_previous_photo'; yao.yalbum.prototype.btn_previous_class = 'previous'; yao.yalbum.prototype.btn_disabled_class = 'dis'; yao.yalbum.prototype.img_btn_previous = 'url(img/last-photo.gif)'; yao.yalbum.prototype.img_btn_next = 'url(img/next-photo.gif)'; yao.yalbum.prototype.shardow_id = 'carousel_photo_shardow'; yao.yalbum.prototype.load_img_path = 'img/loading.gif'; yao.yalbum.prototype.load_img_id = 'carousel_photo_loading'; yao.yalbum.prototype.init = function(){ var oself = this, i; yao.addclass(this.lastsample, 'current'); this.btnprevious = yao.builder.node('a', { href: oself.osamples[oself.lastindex].href, id: oself.btn_previous_id, classname: oself.btn_previous_class, title: '上一张' }, '上一张'); this.photocontainer.appendchild(this.btnprevious); this.btnnext = yao.builder.node('a', { href: oself.osamples[oself.lastindex + 1].href, id: oself.btn_next_id, classname: oself.btn_next_class, title: '下一张' }, '下一张'); this.photocontainer.appendchild(this.btnnext); this.load(this.photo.src); yao.on(this.btnprevious, 'click', function(event){ var evt = event || window.event; this.previous(); yao.stopevent(evt); }, this.btnprevious, oself); yao.on(this.btnnext, 'click', function(event){ var evt = event || window.event; this.next(); yao.stopevent(evt); }, this.btnnext, oself); for (i = 0; i < this.length; ++i) { yao.on(this.osamples[i], 'click', function(index){ return function(event){ var evt = event || window.event, cursample = this.osamples[index]; if (this.lastsample !== cursample && !this.isloading) { this.lastindex = index; this.btnsenabled(); this.chgphoto(); } yao.stopevent(evt); } }(i), this.osamples[i], oself); } }; yao.yalbum.prototype.btnsenabled = function(){ if (this.lastindex !== 0 && yao.hasclass(this.btnprevious, this.btn_disabled_class)) { yao.removeclass(this.btnprevious, this.btn_disabled_class); if (yao.ua.ie) { this.btnprevious.style.backgroundimage = this.img_btn_previous; } this.btnprevious.href = this.osamples[this.lastindex - 1]; } else { if (this.lastindex === 0) { yao.addclass(this.btnprevious, this.btn_disabled_class); if (yao.ua.ie) { } this.btnprevious.href = this.osamples[this.lastindex]; } } if (this.lastindex !== (this.length - 1) && yao.hasclass(this.btnnext, this.btn_disabled_class)) { yao.removeclass(this.btnnext, this.btn_disabled_class); if (yao.ua.ie) { this.btnnext.style.backgroundimage = this.img_btn_next; } this.btnnext.href = this.osamples[this.lastindex + 1]; } else { if (this.lastindex === (this.length - 1)) { yao.addclass(this.btnnext, this.btn_disabled_class); if (yao.ua.ie) { } } if (this.lastindex === (this.length - 1)) { yao.addclass(this.btnnext, this.btn_disabled_class); if (yao.ua.ie) { } } this.photointro.innerhtml = this.sintro; yao.setstyle(this.photocontainer, 'width', (width + 'px')); yao.setstyles(this.photo, { width: width + 'px', height: height + 'px' }); if (this.loadimg && this.loadshardow) { this.isloading = false; this.photocontainer.removechild(this.loadimg); this.loadimg = null; this.photocontainer.removechild(this.loadshardow); this.loadshardow = null; } }; yao.yalbum.prototype.previous = function(){ if (this.lastindex !== 0) { this.lastindex -= 1; if (yao.hasclass(this.btnnext, this.btn_disabled_class)) { yao.removeclass(this.btnnext, this.btn_disabled_class); } if (this.lastindex >= 1) { this.btnprevious.href = this.osamples[this.lastindex - 1].href; } if (this.lastindex < 0) { this.lastindex = 0; yao.addclass(this.btnprevious, this.btn_disabled_class); this.btnprevious.href = this.osamples[this.lastindex].href; } this.btnnext.href = this.osamples[this.lastindex+1].href; this.chgphoto(); } }; yao.yalbum.prototype.next = function(){ if (this.lastindex < (this.length - 1)) { this.lastindex += 1; if (yao.hasclass(this.btnprevious, this.btn_disabled_class)) { yao.removeclass(this.btnprevious, this.btn_disabled_class); } if (this.lastindex <= (this.length - 2)) { this.btnnext.href = this.osamples[this.lastindex + 1].href; } if (this.lastindex > (this.length - 1)) { this.lastindex = (this.length - 1); yao.addclass(this.btnnext, this.btn_disabled_class); this.btnnext.href = this.osamples[this.lastindex].href; } this.btnprevious.href = this.osamples[this.lastindex-1].href; this.chgphoto(); } }; yao.yalbum.prototype.chgphoto = function(){ var path = ''; this.sintro = this.osamples[this.lastindex].title; path = this.osamples[this.lastindex].href; yao.removeclass(this.lastsample, 'current'); yao.addclass(this.osamples[this.lastindex], 'current'); this.lastsample = this.osamples[this.lastindex]; this.photo.src = path; this.load(path); this.scroll(); }; yao.yalbum.prototype.scroll = function(){ var curscreen = math.ceil(((this.lastindex + 1) * this.ocarousel.itemwidth) / this.ocarousel.stepwidth) - 1; if (curscreen != this.ocarousel.movednum) { this.ocarousel.scroll(curscreen); this.ocarousel.movednum = curscreen; if (this.ocarousel.movednum !== 0 && yao.hasclass(this.ocarousel.lnkbtnprevious, this.btn_disabled_class)) { yao.removeclass(this.ocarousel.lnkbtnprevious, this.btn_disabled_class); } else { if (this.ocarousel.movednum === 0) { yao.addclass(this.ocarousel.lnkbtnprevious, this.btn_disabled_class); } } if (this.ocarousel.movednum !== this.ocarousel.maxmovednum && yao.hasclass(this.ocarousel.lnkbtnnext, this.btn_disabled_class)) { yao.removeclass(this.ocarousel.lnkbtnnext, this.btn_disabled_class); } else { if (this.ocarousel.movednum === this.ocarousel.maxmovednum) { yao.addclass(this.ocarousel.lnkbtnnext, this.btn_disabled_class); } } } }; //一流素材网收藏整理:www.16sucai.com