|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Language" content="utf-8" /> <meta name="robots" content="all" /> <meta name="keywords" content="yaohaixiao.com,Javascript,ylightbox,论坛相册特效,focus on javascript" /> <meta name="description" content="yaohaixiao.com - Focus on javascript." /> <title>YLightBox - 论坛相册特效</title> <link href="http://www.yaohaixiao.com/css/yao.css" rel="stylesheet" type="text/css" media="all" /> <link href="css/ylightbox.css" rel="stylesheet" type="text/css" media="screen" /> <base target="_blank" /> </head> <body> <div id="hd"> <h1><strong>YAO</strong>HAIXIAO.COM</h1> <blockquote>FOCUS ON JAVASCRIPT</blockquote> <ul id="navigation"> <li><a href="http://www.yaohaixiao.com/index.html">网站首页</a></li> <li class="current"><a href="http://www.yaohaixiao.com/javascript/index.html">我的Javascript空间</a></li> <li><a href="http://www.yaohaixiao.com/tools/index.html">Javascript 开发工具</a></li> <li><a href="http://www.yaohaixiao.com/resource/index.html">Javascript 资源链接</a></li> <li><a href="http://www.yaohaixiao.com/books/index.html">Javascript 好书推荐</a></li> <li><a href="http://www.yaohaixiao.com/about/index.html">关于</a></li> </ul> </div> <div class="wrap"> <div id="script"> <h1>YLightBox - 论坛相册特效</h1> <div id="byline">程序开发:<a href="http://www.yaohaixiao.com/">YAOHAIXIAO.COM</a>发表时间:2010 - 01 - 27</div> <p class="image"><img src="samples/1.jpg" class="y-lightbox" alt="林志玲" /></p> <p class="image"><img src="samples/2.jpg" class="y-lightbox" alt="清纯的美眉" /></p> <p class="image"><img src="samples/3.jpg" class="y-lightbox" alt="小丑鱼" /></p> <p class="image"><img src="samples/4.jpg" class="y-lightbox" alt="HERA" /></p> <p class="image"><img src="samples/5.jpg" class="y-lightbox" alt="美丽的自然风景" /></p> <p class="image"><img src="samples/6.jpg" class="y-lightbox" alt="韩国美女" /></p> <p class="image"><img src="samples/7.jpg" class="y-lightbox" alt="莉亚迪桑" /></p> <p class="image"><img src="samples/8.jpg" class="y-lightbox" alt="红色法拉利" /></p> <p class="image"><img src="samples/9.jpg" class="y-lightbox" alt="女超人" /></p> <p class="image"><img src="samples/10.jpg" class="y-lightbox" alt="游戏壁纸" /></p> <p class="image"><img src="samples/11.jpg" class="y-lightbox" alt="魔兽争霸" /></p> <p class="image"><img src="samples/12.jpg" class="y-lightbox" alt="梦幻舞厅" /></p> <h2>程序简介</h2> <p> <strong>YLightBox - 论坛相册特效</strong>,我用我自己写个YaoUI代码库实现一个论坛的相册效果,这个特效很适合论坛题图板块的图片展示。调用简单,兼容性好。 </p> <h2>调用方法</h2> <p> <strong>第一步:</strong>在页面中调用yao.js文件,例如: </p> <p> <script type="text/javascript" src="js/yao.js"></script> </p> <p><strong>第二步:</strong>编写调用代码:<br /> <pre> YAO.YLightBox.init('y-lightbox', 'img', 'script'); </pre> </p> <h2>程序代码</h2> <textarea> 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(/<script[^>]*>([\\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, '<').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; }, on: function(el, sType, fn, obj, overrideContext, bCapture){ var oEl = null, context = null, wrappedFn = null; if(YAO.isString(el)){ el = YAO.getEl(el); } if(!el || !fn || !fn.call){ return false; } bCapture = bCapture || 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); }; if ('unload' != sType) { listeners[listeners.length] = [el, sType, fn, wrappedFn, bCapture]; } try { if (window.addEventListener) { el.addEventListener(sType, wrappedFn, bCapture); } else { if (window.attachEvent) { el.attachEvent('on' + sType, wrappedFn); } else { el['on' + sType] = wrappedFn; } } } catch (e) { alert('e'); lastError = e; this.removeListener(el, sType, wrappedFn, bCapture); return false; } }, 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; }, isMouseLeaveOrEnter: function(e, handler){ if (e.type !== 'mouseout' && e.type !== 'mouseover') { return false; } var reltg = e.relatedTarget ? e.relatedTarget : (e.type === 'mouseout' ? e.toElement : e.fromElement); while (reltg && reltg !== handler) { reltg = reltg.parentNode; } return (reltg !== handler); }, 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, rootId){ var elems = [], i, tempCnt = YAO.getEl(rootId).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 || YAO.ua.ie) { j = (k == "CSS1Compat") ? D.documentElement.clientWidth : D.body.clientWidth; } return j; }, getViewportHeight: function(){ var j = self.innerHeight; var k = D.compatMode; if ((k || YAO.ua.ie) && !YAO.ua.opera) { 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 + "></" + 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 (!YAO.getStyle(elem, 'left')) { YAO.setStyle(elem, 'left', 0); } if (!YAO.getStyle(elem, 'top')) { YAO.setStyle(elem, 'top', 0); } var xpos = parseInt(YAO.getStyle(elem, 'left'), 10); var ypos = parseInt(YAO.getStyle(elem, 'top'), 10); 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; } YAO.setStyle(elem, 'left', (xpos + 'px')); YAO.setStyle(elem, '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 = YAO.isString(oConfig.btnPrevious) ? YAO.getEl(oConfig.btnPrevious) : (oConfig.btnPrevious || null); this.lnkBtnPrevious = this.btnPrevious.getElementsByTagName('a')[0] || null; this.Container = YAO.isString(oConfig.Container) ? YAO.getEl(oConfig.Container) : (oConfig.Container || null); this.Scroller = YAO.isString(oConfig.Scroller) ? YAO.getEl(oConfig.Scroller) : (oConfig.Scroller || null); this.btnNext = YAO.isString(oConfig.btnNext) ? YAO.getEl(oConfig.btnNext) : (oConfig.btnNext || null); this.lnkBtnNext = this.btnNext.getElementsByTagName('a')[0] || null; this.items = YAO.isString(oConfig.items) ? this.Container.getElementsByTagName(oConfig.items) : (oConfig.items || null); if(!this.btnPrevious || !this.lnkBtnPrevious || !this.Container || !this.Scroller || !this.btnNext || !this.lnkBtnNext || !this.items){ return false; } 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.LNK_BTNS_DISABLED_CLASS = 'dis'; 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, this.LNK_BTNS_DISABLED_CLASS); } if (this.lnkBtnPrevious && this.movedNum === 0) { YAO.addClass(this.lnkBtnPrevious, this.LNK_BTNS_DISABLED_CLASS); } 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, this.LNK_BTNS_DISABLED_CLASS)) { YAO.removeClass(this.lnkBtnNext, this.LNK_BTNS_DISABLED_CLASS); } if (this.movedNum <= 0) { this.movedNum = 0; if (this.lnkBtnPrevious) { YAO.addClass(this.lnkBtnPrevious, this.LNK_BTNS_DISABLED_CLASS); } } 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, this.LNK_BTNS_DISABLED_CLASS)) { YAO.removeClass(this.lnkBtnPrevious, this.LNK_BTNS_DISABLED_CLASS); } if (this.movedNum >= this.maxMovedNum) { this.movedNum = this.maxMovedNum; if (this.lnkBtnNext) { YAO.addClass(this.lnkBtnNext, this.LNK_BTNS_DISABLED_CLASS); } } 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(oConfig){ var oSelf = this; this.oCarousel = new YAO.Carousel({ btnPrevious: (oConfig && oConfig.btnPrevious) ? oConfig.btnPrevious : oSelf.CARSOUEL_BTN_PREVIOUS, Container: (oConfig && oConfig.Container) ? oConfig.Container : oSelf.CARSOUEL_CONTAINER, Scroller: (oConfig && oConfig.Scroller) ? oConfig.Scroller : oSelf.CARSOUEL_SCROLLER, btnNext: (oConfig && oConfig.btnNext) ? oConfig.btnNext : oSelf.CARSOUEL_BTN_NEXT, items: (oConfig && oConfig.items) ? oConfig.items : oSelf.CARSOUEL_ITEM_TAG, stepWidth: (oConfig && oConfig.stepWidth) ? oConfig.stepWidth : oSelf.CARSOUEL_STEP_WIDTH }); this.oSamples = this.oCarousel.Scroller.getElementsByTagName('a') || null; this.length = this.oSamples.length || 0; this.lastSample = this.oSamples[0] || null; this.photoContainer = (oConfig && oConfig.photoContainer) ? (YAO.isString(oConfig.photoContainer) ? YAO.getEl(oConfig.photoContainer) : oConfig.photoContainer) : (YAO.getEl(this.PHOTO_CONTAINER_ID) || null); this.photo = (oConfig && oConfig.photo) ? (YAO.isString(oConfig.photo) ? YAO.getEl(oConfig.photo) : oConfig.photo) : (YAO.getEl(this.PHOTO_ID) || null); this.photoIntro = (oConfig && oConfig.photoIntro) ? (YAO.isString(oConfig.photoIntro) ? YAO.getEl(oConfig.photoIntro) : oConfig.photoIntro) : (YAO.getEl(this.PHOTO_INTRO_ID) || null); this.PHOTO_MAX_WIDTH = (oConfig && oConfig.photoMaxWidth) ? oConfig.photoMaxWidth : this.PHOTO_MAX_WIDTH; 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.btnPrevious = null; YAO.YAlbum.prototype.btnNext = 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 = 672; YAO.YAlbum.prototype.PHOTO_MAX_WIDTH = 800; 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.style.backgroundImage = 'none'; } 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) { this.btnNext.style.backgroundImage = 'none'; } this.btnNext.href = this.oSamples[this.lastIndex]; } } }; YAO.YAlbum.prototype.load = function(path){ var oImage = new Image(), oDf = document.createDocumentFragment(); oImage.src = path; if (oImage.complete) { this.resize(oImage); } else { this.isLoading = true; this.loadShardow = YAO.Builder.Node('div', { id: this.SHARDOW_ID }); this.loadImg = YAO.Builder.Node('img', { src: this.LOAD_IMG_PATH, id: this.LOAD_IMG_ID }); oDf.appendChild(this.loadShardow); if (YAO.ua.ie) { this.loadShardow.style.height = this.lastPhotoHeight ? this.lastPhotoHeight + 'px' : this.photoContainer.offsetHeight + 'px'; } oDf.appendChild(this.loadImg); this.photoContainer.appendChild(oDf); YAO.on(oImage, 'load', function(){ this.resize(oImage); }, oImage, this); } }; YAO.YAlbum.prototype.resize = function(oImage){ var oSelf = this; var width = oImage.width; var height = oImage.height; var percent = width / height; if (width > this.PHOTO_MAX_WIDTH) { width = this.PHOTO_MAX_WIDTH; height = width / percent; } if (YAO.ua.ie) { this.lastPhotoHeight = height; YAO.setStyles(this.btnPrevious, { height: height + 'px', backgroundImage: oSelf.IMG_BTN_PREVIOUS }); YAO.setStyles(this.btnNext, { height: height + 'px', backgroundImage: oSelf.IMG_BTN_NEXT }); } if (this.lastIndex === 0) { YAO.addClass(this.btnPrevious, this.BTN_DISABLED_CLASS); if (YAO.ua.ie) { this.btnPrevious.style.backgroundImage = 'none'; } } if (this.lastIndex === (this.length - 1)) { YAO.addClass(this.btnNext, this.BTN_DISABLED_CLASS); if (YAO.ua.ie) { this.btnNext.style.backgroundImage = 'none'; } } 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); } } } }; YAO.YLightBox = { isHidden: false, photos: null, length: 0, YOverlay: null, YBox: null, YBoxDefaultWidth: 500, YBoxDefaultHeight: 0, YBoxHd: null, YBoxHdHeight: 0, YBoxTitle: null, YBoxToolBar: null, closeable: true, YBoxCloseBar: null, maximizable: true, YBoxMaximizeBar: null, newindowable: true, YBoxNewWinBar: null, YBoxBd: null, YBoxBDefaultHeight: 0, YBoxPhoto: null, YBoxPhotoDefaultWidth: 0, YBoxPhotoDefaultHeight: 0, YBoxTips: null, YBoxIndex: null, YBoxLastIndex: 0, carouselable: true, YCarousel: null, YBoxCarousel: null, YBoxScroller: null, YBoxBtnLastGroup: null, YBoxBtnNextGroup: null, YBoxLastSample: null, albumabel: true, YAlbum: null, YBoxBtnPrevious: null, YBoxBtnNext: null, BTN_DISABLED_CLASS: 'dis', IMG_BTN_PREVIOUS: 'url(img/last-photo.gif)', IMG_BTN_NEXT: 'url(img/next-photo.gif)', init: function(itemClass, itemTag, rootId){ var i, oSelf = this; this.photos = YAO.getElByClassName(itemClass, itemTag, rootId); this.length = this.photos.length; for (i = 0; i < this.length; ++i) { YAO.on(this.photos[i], 'click', function(index){ return function(event){ var evt = event || window.event; this.YBoxLastIndex = index; this.YBoxPhotoDefaultWidth = this.photos[this.YBoxLastIndex].width; this.YBoxPhotoDefaultHeight = this.photos[this.YBoxLastIndex].height; this.initComponent(); this.zoom(); YAO.stopEvent(evt); } }(i), this.photos[i], oSelf); } }, initComponent: function(){ if (!this.YBox) { this.create(); this.initEvents(); } else { this.show(); } this.currentSample(); }, create: function(){ var D = document, i, oDfBox = D.createDocumentFragment(), oDfTip = D.createDocumentFragment(), docWidth = YAO.getDocumentWidth(), docHeight = YAO.getDocumentHeight(), oSelf = this; oImage = this.photos[this.YBoxLastIndex]; oDfBox.appendChild(YAO.Builder.Node('div', { id: 'yl-shardow' })); oDfBox.appendChild(YAO.Builder.Node('div', { id: 'yl-box' }, [YAO.Builder.Node('div', { id: 'yl-box-hd' }, [YAO.Builder.Node('h3', { id: 'yl-box-tlt' }, oImage.alt),YAO.Builder.Node('span',{ id: 'yl-box-toolbar' })]), YAO.Builder.Node('div', { id: 'yl-box-bd' }, [YAO.Builder.Node('img', { src: oImage.src, alt: oImage.alt, id: 'yl-photo' }), YAO.Builder.Node('div', { id: 'carousel' },YAO.Builder.Node('div', { id: 'carousel_container' }))])])); D.body.appendChild(oDfBox); this.YOverlay = YAO.getEl('yl-shardow'); YAO.setStyles(this.YOverlay, { height: docHeight + 'px' }); this.YBox = YAO.getEl('yl-box'); this.YBoxHd = YAO.getEl('yl-box-hd'); this.YBoxHdHeight = this.YBoxHd.offsetHeight; this.YBoxTitle = YAO.getEl('yl-box-tlt'); this.YBoxToolBar = YAO.getEl('yl-box-toolbar'); this.initTools(); this.YBoxBd = YAO.getEl('yl-box-bd'); this.YBoxCarousel = YAO.getEl('carousel'); this.YBoxCarouselCnt = YAO.getEl('carousel_container'); this.YBoxPhoto = YAO.getEl('yl-photo'); this.initPlgins(); oDfTip.appendChild(YAO.Builder.Node('div', { id: 'yl-tips' }, [YAO.Builder.Node('em', { id: 'yl-curIndex' }, (this.YBoxLastIndex + 1) + ''), ' / ' + this.length + ' pictures'])); this.YBoxCarousel.appendChild(oDfTip); this.YBoxTips = YAO.getEl('yl-tips'); this.YBoxIndex = YAO.getEl('yl-curIndex'); if (this.carouselable) { this.YBoxLastSample = this.YCarousel.items[this.YBoxLastIndex]; } this.isHidden = false; }, initTools: function(){ var D = document, oDfTools = D.createDocumentFragment(); oImage = this.photos[this.YBoxLastIndex]; if (this.newindowable) { oDfTools.appendChild(YAO.Builder.Node('a', { id: 'yl-box-newindow', href: oImage.src, target: '_blank', title: '新窗口打开' }, '新窗口打开')); } if (this.maximizable) { oDfTools.appendChild(YAO.Builder.Node('a', { id: 'yl-box-adjust', className: 'imgadjust', href: '#adjust', title: '显示实际尺寸' }, '显示实际尺寸')); } if (this.closeable) { oDfTools.appendChild(YAO.Builder.Node('a', { id: 'yl-box-closebar', className: 'imgclose', href: '#close', title: '关闭窗口' }, '关闭窗口')); } this.YBoxToolBar.appendChild(oDfTools); this.YBoxNewWinBar = YAO.getEl('yl-box-newindow'); this.YBoxMaximizeBar = YAO.getEl('yl-box-adjust'); this.YBoxCloseBar = YAO.getEl('yl-box-closebar'); }, initPlgins: function(){ var D = document, oSelf = this, oCConfig = {}, oAConfig = {}, i, oDfSamples = D.createDocumentFragment(), oDfBtnsGroups = D.createDocumentFragment(), oDfBtnsPhoto = D.createDocumentFragment(); if (this.carouselable) { this.YBoxCarouselCnt.appendChild(YAO.Builder.Node('ul', { id: 'samples_list' })); this.YBoxScroller = YAO.getEl('samples_list'); for (i = 0; i < this.length; ++i) { oDfSamples.appendChild(YAO.Builder.Node('li', { className: i === oSelf.YLastIndex ? 'current' : '' }, YAO.Builder.Node('a', { href: oSelf.photos[i].src, title: oSelf.photos[i].alt, target: 'blank' }, YAO.Builder.Node('img', { src: oSelf.photos[i].src, alt: oSelf.photos[i].alt })))); } this.YBoxScroller.appendChild(oDfSamples); oDfBtnsGroups.appendChild(YAO.Builder.Node('div', { id: 'carousel_btn_lastgroup' }, YAO.Builder.Node('a', { href: '#lastgroup', title: '上一组' }, '上一组'))); oDfBtnsGroups.appendChild(YAO.Builder.Node('div', { id: 'carousel_btn_nextgroup' }, YAO.Builder.Node('a', { href: '#nextgroup', title: '下一组' }, '下一组'))); this.YBoxCarousel.appendChild(oDfBtnsGroups); this.YBoxBtnLastGroup = YAO.getEl('carousel_btn_lastgroup'); this.YBoxBtnNextGroup = YAO.getEl('carousel_btn_nextgroup'); oCConfig = { btnPrevious: oSelf.YBoxBtnLastGroup, Container: oSelf.YBoxCarouselCnt, Scroller: oSelf.YBoxScroller, btnNext: oSelf.YBoxBtnNextGroup, stepWidth: 100, items: 'li' }; this.YCarousel = new YAO.Carousel(oCConfig); } if (this.albumabel) { oDfBtnsPhoto.appendChild(YAO.Builder.Node('a', { id: 'carousel_previous_photo', className: 'previous', href: (oSelf.YLastIndex - 1 > 0) ? oSelf.photos[oSelf.YLastIndex - 1].src : oSelf.photos[0].src, title: '上一张', target: '_blank' }, '上一张')); oDfBtnsPhoto.appendChild(YAO.Builder.Node('a', { id: 'carousel_next_photo', className: 'next', href: (oSelf.YLastIndex + 1 < oSelf.length - 1) ? oSelf.photos[oSelf.YLastIndex + 1].src : oSelf.photos[oSelf.length - 1].src, title: '下一张', target: '_blank' }, '下一张')); this.YBoxBd.appendChild(oDfBtnsPhoto); this.YBoxBtnPrevious = YAO.getEl('carousel_previous_photo'); this.YBoxBtnNext = YAO.getEl('carousel_next_photo'); } }, show: function(){ var oImage = this.photos[this.YBoxLastIndex]; if (this.YOverlay && this.YBox && this.isHidden) { this.YBoxTitle.innerHTML = oImage.alt; this.YBoxNewWinBar.href = oImage.src; YAO.Builder.Attributes(this.YBoxPhoto, { src: oImage.src, alt: oImage.alt }); this.YBoxIndex.innerHTML = (this.YBoxLastIndex + 1); YAO.setStyle(this.YOverlay, 'display', 'block'); YAO.setStyle(this.YBox, 'display', 'block'); this.isHidden = false; } }, initBtns: function(){ var oSelf = this; if (this.albumabel) { if (YAO.ua.ie) { YAO.setStyle(this.YBoxBtnPrevious, 'backgroundImage', oSelf.IMG_BTN_PREVIOUS); YAO.setStyle(this.YBoxBtnNext, 'backgroundImage', oSelf.IMG_BTN_NEXT); } if (this.YBoxLastIndex === 0) { YAO.addClass(this.YBoxBtnPrevious, this.BTN_DISABLED_CLASS); if (YAO.ua.ie) { YAO.setStyle(this.YBoxBtnPrevious, 'backgroundImage', 'none'); } } if (this.YBoxLastIndex === (this.length - 1)) { YAO.addClass(this.YBoxBtnNext, this.BTN_DISABLED_CLASS); if (YAO.ua.ie) { YAO.setStyle(this.YBoxBtnNext, 'backgroundImage', 'none'); } } } }, initEvents: function(){ var i; if (this.maximizable) { YAO.on(this.YBoxHd, 'dblclick', this.toggleMaximize, this.YBoxHd, this); YAO.on(this.YBoxMaximizeBar, 'click', this.toggleMaximize, this.YBoxMaximizeBar, this); } if (this.closeable) { YAO.on(this.YBoxCloseBar, 'click', this.close, this.YBoxCloseBar, this); } if (this.carouselable) { for (i = 0; i < this.length; ++i) { YAO.on(this.YCarousel.items[i], 'click', function(index){ return function(event){ var evt = event || window.event; this.YBoxLastIndex = index; this.btnsEnabled(); this.changePhoto(); YAO.stopEvent(evt); } }(i), this.YCarousel.items[i], this); } YAO.on(this.YBoxTips, 'click', this.showCarousel, this.YBoxTips, this); } if(this.albumabel){ YAO.on(this.YBoxBtnPrevious, 'click', this.previousPhoto, this.YBoxBtnPrevious, this); YAO.on(this.YBoxBtnNext, 'click', this.nextPhoto, this.YBoxBtnNext, this); } YAO.on(window, 'scroll', this.fixPosition, window, this); YAO.on(window, 'resize', this.fixPosition, window, this); }, close: function(event){ var evt = event || window.event; if (this.YOverlay && this.YBox && !this.isHidden) { YAO.setStyle(this.YOverlay, 'display', 'none'); YAO.setStyle(this.YBox, 'display', 'none'); this.minimize(); this.isHidden = true; this.YBoxLastIndex = 0; } YAO.stopEvent(evt); }, zoom: function(){ var percent = this.YBoxPhotoDefaultWidth / this.YBoxPhotoDefaultHeight, height = this.YBoxDefaultWidth / percent; this.YBoxDefaultHeight = height + this.YBoxHdHeight; this.YBoxBDefaultHeight = height; if (this.YBoxPhotoDefaultWidth > this.YBoxDefaultWidth) { this.minimize(); } else { this.restore(); } this.initBtns(); this.fixPosition(); }, minimize: function(){ var oSelf = this; YAO.setStyles(this.YBoxPhoto, { width: oSelf.YBoxDefaultWidth + 'px', height: oSelf.YBoxDefaultHeight + 'px' }); YAO.setStyles(this.YBoxBd, { width: oSelf.YBoxDefaultWidth + 'px', height: oSelf.YBoxBDefaultHeight + 'px' }); YAO.setStyles(this.YBox, { width: oSelf.YBoxDefaultWidth + 'px', height: oSelf.YBoxDefaultHeight + 'px' }); if (this.YBoxMaximizeBar) { this.YBoxMaximizeBar.title = '显示实际尺寸'; } if (YAO.ua.ie && this.albumable) { YAO.setStyle(this.YBoxBtnPrevious, 'height', (this.YBoxDefaultHeight + 'px')); YAO.setStyle(this.YBoxBtnNext, 'height', (this.YBoxDefaultHeight + 'px')); } }, restore: function(){ var oSelf = this; YAO.setStyles(this.YBoxPhoto, { width: oSelf.YBoxPhotoDefaultWidth + 'px', height: oSelf.YBoxPhotoDefaultHeight + 'px' }); YAO.setStyles(this.YBoxBd, { width: oSelf.YBoxPhotoDefaultWidth + 'px', height: oSelf.YBoxPhotoDefaultHeight + 'px' }); YAO.setStyles(this.YBox, { width: oSelf.YBoxPhotoDefaultWidth + 'px', height: (oSelf.YBoxPhotoDefaultHeight + oSelf.YBoxHdHeight) + 'px' }); if (this.YBoxMaximizeBar) { this.YBoxMaximizeBar.title = '显示缩略图'; } if (YAO.ua.ie && this.albumable) { YAO.setStyle(this.YBoxBtnPrevious, 'height', (this.YBoxPhotoDefaultWidth + 'px')); YAO.setStyle(this.YBoxBtnNext, 'height', (this.YBoxPhotoDefaultHeight + 'px')); } }, toggleMaximize: function(event){ var evt = event || window.event; if (this.YBoxPhotoDefaultWidth > this.YBoxDefaultWidth) { if (this.YBoxPhoto.width === this.YBoxDefaultWidth) { this.restore(); } else { this.minimize(); } this.fixPosition(); } YAO.stopEvent(evt); }, fixPosition: function(){ var documentWidth = YAO.getDocumentWidth(), documentHeight = YAO.getDocumentHeight(), viewportWidth = YAO.getViewportWidth(), viewportHeight = YAO.getViewportHeight(), xScroll = YAO.getXScroll(), yScroll = YAO.getYScroll(), YBoxWidth = this.YBox.offsetWidth, YBoxHeight = this.YBox.offsetHeight, left = xScroll + ((viewportWidth - YBoxWidth) / 2), top = yScroll + ((viewportHeight - YBoxHeight) / 2); if (YBoxWidth > viewportWidth) { if ((YBoxWidth < documentWidth) && ((YBoxWidth + xScroll) < documentWidth)) { left = xScroll; } else { left = documentWidth - YBoxWidth; } } else { if (YBoxWidth > documentWidth) { left = 0; } } if (YBoxHeight > viewportHeight) { if ((YBoxHeight < documentHeight) && ((YBoxHeight + yScroll) <= documentHeight)) { top = yScroll; } else { top = documentHeight - YBoxHeight; } } else { if (YBoxHeight > documentHeight) { top = 0; } } if (!this.isHidden) { YAO.setStyles(this.YBox, { margin: 0, left: left + 'px', top: top + 'px' }); } }, showCarousel: function(){ var top = parseInt(YAO.getStyle(this.YBoxCarousel, 'top'), 10); if (top === -120) { YAO.moveElement(this.YBoxCarousel, 0, 0, 50); YAO.setStyle(this.YBoxBtnLastGroup, 'display', 'block'); YAO.setStyle(this.YBoxBtnNextGroup, 'display', 'block'); } else { YAO.moveElement(this.YBoxCarousel, 0, -120, 50); YAO.setStyle(this.YBoxBtnLastGroup, 'display', 'none'); YAO.setStyle(this.YBoxBtnNextGroup, 'display', 'none'); } }, currentSample: function(){ var curSample = null; if (this.carouselable) { curSample = this.YCarousel.items[this.YBoxLastIndex]; if (curSample !== this.YBoxLastSample) { YAO.removeClass(this.YBoxLastSample, 'current'); } YAO.addClass(curSample, 'current'); this.YBoxLastSample = curSample; } }, scrollCarousel: function(){ if (this.carouselable) { var curScreen = Math.ceil(((this.YBoxLastIndex + 1) * this.YCarousel.itemWidth) / this.YCarousel.stepWidth) - 1; if (curScreen != this.YCarousel.movedNum) { this.YCarousel.scroll(curScreen); this.YCarousel.movedNum = curScreen; if (this.YCarousel.movedNum !== 0 && YAO.hasClass(this.YCarousel.lnkBtnPrevious, this.BTN_DISABLED_CLASS)) { YAO.removeClass(this.YCarousel.lnkBtnPrevious, this.BTN_DISABLED_CLASS); } else { if (this.YCarousel.movedNum === 0) { YAO.addClass(this.YCarousel.lnkBtnPrevious, this.BTN_DISABLED_CLASS); } } if (this.YCarousel.movedNum !== this.YCarousel.maxMovedNum && YAO.hasClass(this.YCarousel.lnkBtnNext, this.BTN_DISABLED_CLASS)) { YAO.removeClass(this.YCarousel.lnkBtnNext, this.BTN_DISABLED_CLASS); } else { if (this.YCarousel.movedNum === this.YCarousel.maxMovedNum) { YAO.addClass(this.YCarousel.lnkBtnNext, this.BTN_DISABLED_CLASS); } } } } }, btnsEnabled: function(){ if (this.albumabel) { if (this.YBoxLastIndex !== 0) { if (YAO.hasClass(this.YBoxBtnPrevious, this.BTN_DISABLED_CLASS)) { YAO.removeClass(this.YBoxBtnPrevious, this.BTN_DISABLED_CLASS); } if (YAO.ua.ie) { YAO.setStyle(this.YBoxBtnPrevious, 'backgroundImage', this.IMG_BTN_PREVIOUS); } this.YBoxBtnPrevious.href = this.photos[this.YBoxLastIndex - 1].src; } else { if (this.YBoxLastIndex === 0) { YAO.addClass(this.YBoxBtnPrevious, this.BTN_DISABLED_CLASS); if (YAO.ua.ie) { YAO.setStyle(this.YBoxBtnPrevious, 'backgroundImage', 'none'); } this.YBoxBtnPrevious.href = this.photos[this.YBoxLastIndex].src; } } if (this.YBoxLastIndex !== (this.length - 1)) { if (YAO.hasClass(this.YBoxBtnNext, this.BTN_DISABLED_CLASS)) { YAO.removeClass(this.YBoxBtnNext, this.BTN_DISABLED_CLASS); } if (YAO.ua.ie) { YAO.setStyle(this.YBoxBtnNext, 'backgroundImage', this.IMG_BTN_NEXT); } this.YBoxBtnNext.href = this.photos[this.YBoxLastIndex + 1].src; } else { if (this.YBoxLastIndex === (this.length - 1)) { YAO.addClass(this.YBoxBtnNext, this.BTN_DISABLED_CLASS); if (YAO.ua.ie) { YAO.setStyle(this.YBoxBtnNext, 'backgroundImage', 'none'); } this.YBoxBtnNext.href = this.photos[this.YBoxLastIndex].src; } } } }, previousPhoto: function(event){ var evt = event || window.event; this.YBoxLastIndex -= 1; if (YAO.hasClass(this.YBoxBtnNext, this.BTN_DISABLED_CLASS)) { YAO.removeClass(this.YBoxBtnNext, this.BTN_DISABLED_CLASS); } if (this.YBoxLastIndex >= 1) { this.YBoxBtnPrevious.href = this.photos[this.YBoxLastIndex - 1].src; } if (this.YBoxLastIndex < 0) { this.YBoxLastIndex = 0; YAO.addClass(this.YBoxBtnPrevious, this.BTN_DISABLED_CLASS); this.YBoxBtnPrevious.href = this.photos[this.YBoxLastIndex].src; } this.YBoxBtnNext.href = this.photos[this.YBoxLastIndex + 1].src; this.changePhoto(); YAO.stopEvent(evt); }, nextPhoto: function(event){ var evt = event || window.event; this.YBoxLastIndex += 1; if (YAO.hasClass(this.YBoxBtnPrevious, this.BTN_DISABLED_CLASS)) { YAO.removeClass(this.YBoxBtnPrevious, this.BTN_DISABLED_CLASS); } if (this.YBoxLastIndex <= (this.length - 2)) { this.YBoxBtnNext.href = this.photos[this.YBoxLastIndex + 1].src; } if (this.YBoxLastIndex > (this.length - 1)) { this.YBoxLastIndex = this.length - 1; YAO.addClass(this.YBoxBtnNext, this.BTN_DISABLED_CLASS); this.YBoxBtnNext.href = this.photos[this.YBoxLastIndex].src; } this.YBoxBtnPrevious.href = this.photos[this.YBoxLastIndex-1].src; this.changePhoto(); YAO.stopEvent(evt); }, changePhoto: function(){ this.YBoxPhotoDefaultWidth = this.photos[this.YBoxLastIndex].width; this.YBoxPhotoDefaultHeight = this.photos[this.YBoxLastIndex].height; this.YBoxTitle.innerHTML = this.photos[this.YBoxLastIndex].alt; this.YBoxIndex.innerHTML = (this.YBoxLastIndex + 1); this.YBoxPhoto.src = this.photos[this.YBoxLastIndex].src; this.YBoxPhoto.alt = this.photos[this.YBoxLastIndex].alt; if (this.YBoxNewWinBar) { this.YBoxNewWinBar.href = this.photos[this.YBoxLastIndex].src; } this.currentSample(); this.scrollCarousel(); this.zoom(); } }; </textarea> <p><strong>Download:</strong><a href="http://www.yaohaixiao.com/scripts/ylightbox/ylightbox.rar">ylightbox.rar</a></p> </div> <div id="side"> <div class="md" id="about"> <div class="hd"><h2>个人简介</h2></div> <div class="bd"> <img src="http://www.yaohaixiao.com/img/face.jpg" alt="yaohaixiao" /> <ul> <li>姓名:姚海啸</li> <li>年龄:28岁</li> <li>学历:大专</li> <li>职业:前端工程师</li> </ul> </div> <div class="ft">奋斗目标:成为顶尖的前端工程师</div> </div> <div class="md" id="works"> <div class="hd"><h2>我的作品</h2></div> <div class="bd"> <a href="http://www.fg114.com/" title="订餐小秘书官网"><img src="http://www.yaohaixiao.com/cover/fg114.jpg" alt="订餐小秘书官网" /></a> <a href="http://news.cnhubei.com/" title="荆楚网新闻频道首页"><img src="http://www.yaohaixiao.com/cover/news-cnhubei.jpg" alt="荆楚网新闻频道首页" /></a> <a href="http://cn.ising99.com/" title="爱唱久久官网"><img src="http://www.yaohaixiao.com/cover/ising99.jpg" alt="爱唱久久官网" /></a> <a href="http://unicom.fc510.com/" title="武汉联通互动CLUB"><img src="http://www.yaohaixiao.com/cover/unicom.jpg" alt="武汉联通互动CLUB" /></a> </div> </div> <div class="md" id="blogroll"> <div class="hd"><h2>友情链接</h2></div> <div class="bd"> <ul> <li><a href="http://www.xinrongshu.com/">上海人家</a></li> <li><a href="http://www.w3cool.com/">恐龙窝</a></li> <li><a href="http://www.lemongtree.com/">幻想曲.Net</a></li> <li><a href="http://www.ai-xue.com.cn/">Hello,Yang!</a></li> <li><a href="http://www.playgoogle.com/">Play Google</a></li> <li><a href="http://www.85design.net/">翅膀的天空</a></li> <li><a href="http://www.weilaixu.cn/">weilaixu</a></li> <li><a href="http://www.scriptlover.com/">脚本爱好者</a></li> <li><a href="http://www.hoopen.cn/">者也's blog</a></li> <li><a href="http://www.webdeveloping.cn/">WebDeveloping</a></li> <li><a href="http://www.y7l8.com/">Y7L8'Blog</a></li> <li><a href="http://byzuo.com/blog/">Made by Zuozuo</a></li> <li><a href="http://www.51obj.cn/">找对象</a></li> </ul> </div> </div> </div> </div> <div id="ft"><p>Copyright © 2008-2009 <a href="http://www.yaohaixiao.com/">yaohaixiao.com</a>, All right reserved.</p></div> <script language="javascript" type="text/javascript" src="js/yao.js"></script> <script language="javascript" type="text/javascript"> <!-- YAO.YLightBox.init('y-lightbox', 'img', 'script'); //--> </script> </body> </html> |