注意:为了演示,平滑代码转换的速度已经调至最低,每次处理1行代码
var $$ = function(){}; var IsIE = navigator.userAgent.toLowerCase().indexOf("msie") > -1 ? true:false; var IsOpera = navigator.userAgent.toLowerCase().indexOf("opera") > -1 ? true :false; var IsSafari = navigator.userAgent.toLowerCase().indexOf("safari") > -1 ? true :false; var IsFirefox = navigator.userAgent.toLowerCase().indexOf("firefox") > -1 ? true :false; var IsIE8 = navigator.userAgent.toLowerCase().indexOf("msie 8.0") > -1 ? true : false; var IsIE7 = navigator.userAgent.toLowerCase().indexOf("msie 7.0") > -1 ? true : false; $$.Window = function(){}; $$.Window.GetWidth = function() { return IsOpera ? document.body.parentNode.clientWidth : (document.body.parentNode.offsetWidth > document.body.parentNode.clientWidth ? document.body.parentNode.offsetWidth : document.body.parentNode.clientWidth); }; $$.Window.GetHeight = function() { if (IsSafari || IsFirefox) { return document.body.parentNode.clientHeight; } else if (IsOpera) { return document.body.clientHeight; } else { return document.body.parentNode.offsetHeight > document.body.parentNode.clientHeight ? document.body.parentNode.offsetHeight : document.body.parentNode.clientHeight } }; $$.Window.GetScrollHeight = function() { if (IsOpera) { return document.body.parentNode.scrollHeight; } else if (IsSafari) { return document.body.parentNode.scrollHeight > document.body.parentNode.clientHeight ? document.body.parentNode.scrollHeight : document.body.parentNode.clientHeight; } else if (IsFirefox) { return document.body.parentNode.scrollHeight > document.body.parentNode.clientHeight ? document.body.parentNode.scrollHeight : document.body.parentNode.clientHeight; } else { return document.body.parentNode.offsetHeight > document.body.parentNode.scrollHeight ? document.body.parentNode.offsetHeight : document.body.parentNode.scrollHeight } }; $$.Window.GetScrollTop = function() { if (IsSafari) { return document.body.scrollTop; } else { return document.body.parentNode.scrollTop; } }; /*---------------------------------------------*/ function Bool(boolvalue) { if (boolvalue != null && typeof boolvalue != "undefined") { if (boolvalue.toString().toLowerCase() == "false" || boolvalue.toString() == "0" || boolvalue.toString() == "" || boolvalue == null) { return false; } else { return true; } } else { return false; } }; /*---------------------------------------------*/ var $ = function(client_id) { return document.getElementById(client_id); }; /*---------------------------------------------*/ $.NodeValue = function(the_node) { if (typeof the_node.text != "undefined") { return the_node.text; } else if (typeof the_node.innerText != "undefined") { return the_node.innerText; } else if (typeof the_node.textContent != "undefined") { return the_node.textContent; } }; /*---------------------------------------------*/ String.prototype.AdaptForHTML = function() { return this.replace(/\r?\n/gim,"
");; }; String.prototype.RemoveHTML = function() { return this.replace(/
/gim,"\r\n").replace(/<.*?>/gim,""); }; String.prototype.SubHtml = function(cut_length) { var source_html = this; var cut_index = 0,cut_flag = true; for (var cot = 0,last_cut = 0;cot < source_html.length && last_cut < cut_length;cot++) { if (source_html.charAt(cot) == "<" || source_html.charAt(cot) == ">") { cut_flag = !cut_flag; } else if (cut_flag) { last_cut++; cut_index = cot } } var left_part = source_html.substr(0,cut_index); var right_part = source_html.substring(cut_index,source_html.length); right_part = right_part.replace(//g,"").replace(/<{2,}/,"<").replace(/>{2,}/,">").replace(/<(?:br|img|input)[^<>]*?>/gi,"").replace(/<[^<>]+?\/>/g,""); right_part = right_part.replace(/<([^\/][^ <>]*)[^<>]*?>/g,"<$1>"); right_part = right_part.match(/<[^<>]+?>/g).join(""); while(/<([^\/][^<>]*)><\/\1>/gi.test(right_part)) { right_part = right_part.replace(/<([^\/][^ <>]*)><\/\1>/gi,""); } return left_part + right_part; }; /*---------------------------------------------*/ var QueryString = new Array(); var query_str_regex = new RegExp("[^\\?&]+=[^&]+","gm"); var query_str_item_name_regex = new RegExp("^[^=]+"); var query_str_item_value_regex = new RegExp("[^=]+$"); var query_str_result = document.URL.match(query_str_regex); if (query_str_result != null) { for (var cot = 0;cot < query_str_result.length;cot++) { var query_str_name = query_str_result[cot].match(query_str_item_name_regex); var query_str_value = query_str_result[cot].match(query_str_item_value_regex); QueryString[query_str_name.toString()] = query_str_value[0]; } } /*---------------------------------------------*/ $.MaxDayofMonth = function(year,month) { year = parseInt(year); month = parseInt(month); if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { return 31; } else if (month == 4 || month == 6 || month == 9 || month == 11) { return 30; } else if (month == 2) { if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) { return 29; } else { return 28; } } }; /*---------------------------------------------*/ $$.Cookie = new Array(); $$.CookieParseRegex = new RegExp("[^(?:; )(?:;)=]+=[^;]+","gm"); $$.CookieNameParseRegex = new RegExp("[^;=]+"); $$.CookieValueParseRegex = new RegExp("=.+$"); $$.CookieParseMatch = document.cookie.match($$.CookieParseRegex); if ($$.CookieParseMatch != null) { for (var cot = 0;cot < $$.CookieParseMatch.length;cot++) { $$.Cookie[$$.CookieParseMatch[cot].match($$.CookieNameParseRegex)[0].toString()] = $$.CookieParseMatch[cot].match($$.CookieValueParseRegex)[0].toString() } } $$.Cookie.GetCookie = function(cookie_name) { var cookie_group = document.cookie.split(";"); for (var cot= 0;cot < cookie_group.length;cot++) { var current_cookie = cookie_group[cot].split("="); var current_cookie_name = current_cookie[0].replace(/^\s+|\s+$/g,""); if (current_cookie_name==cookie_name) { if (current_cookie.length > 1) { return unescape(current_cookie[1].replace(/^\s+|\s+$/g, '')); } return null; } } return null; }; $$.Cookie.SetCookie = function(cookie_name,cookie_value,expire_date) { if (typeof expire_date == "undefined") { var expire_date = new Date(); expire_date.setTime(expire_date.getTime() + 3 * 30 * 24 * 60 * 60 * 1000); } document.cookie = cookie_name + "=" + escape(cookie_value) + "; expires=" + expire_date.toGMTString(); }; $$.Cookie.DeleteCookie = function(cookie_name) { document.cookie = cookie_name + "=; expires=Thu, 01-Jan-1970 00:00:01 GMT"; }; /*---------------------------------------------*/ if (IsFirefox) { //Element.prototype.__defineGetter__("innerText", function() {if (typeof this.innerHTML != "undefined"){return this.innerHTML.RemoveHTML();}else{return null;}}); //Element.prototype.__defineSetter__("innerText", function(value) {if (typeof this.innerHTML != "undefined"){this.innerHTML = value.RemoveHTML();}}); } /*---------------------------------------------*/ if (!IsIE && !IsOpera) { XMLDocument.prototype.selectSingleNode = function(xpath_str) { var result_node =this.evaluate(xpath_str, this, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; return result_node; }; XMLDocument.prototype.selectNodes = function(xpath_str) { var oResult = this.evaluate(xpath_str, this, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null); var aNodes = new Array(); if (oResult != null) { var oElement = oResult.iterateNext(); while(oElement) { aNodes.push(oElement); oElement = oResult.iterateNext(); } return aNodes; } else { return null; } }; Element.prototype.selectSingleNode = function(xpath_str) { var xpath_evaluator = new XPathEvaluator(); var result_node = xpath_evaluator.evaluate(xpath_str, this, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); if (result_node != null) { return result_node.singleNodeValue; } else { return null; } }; Element.prototype.selectNodes = function(sXPath) { var oEvaluator = new XPathEvaluator(); var oResult = oEvaluator.evaluate(sXPath, this, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null); var aNodes = new Array(); if (oResult != null) { var oElement = oResult.iterateNext(); while(oElement) { aNodes.push(oElement); oElement = oResult.iterateNext(); } } return aNodes; }; } if (IsOpera) { Document.prototype.selectSingleNode = function(xpath_str) { var result_node =this.evaluate(xpath_str, this, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; return result_node; }; Element.prototype.selectSingleNode = function(xpath_str) { var result_node = this.ownerDocument.evaluate(xpath_str, this, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); if (result_node != null) { return result_node.singleNodeValue; } else { return null; } }; Document.prototype.selectNodes = function(xpath_str) { var oResult = this.evaluate(xpath_str, this, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null); var aNodes = new Array(); if (oResult != null) { var oElement = oResult.iterateNext(); while(oElement) { aNodes.push(oElement); oElement = oResult.iterateNext(); } } return aNodes; }; Element.prototype.selectNodes = function(xpath_str) { var oResult = this.ownerDocument.evaluate(xpath_str, this, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null); var aNodes = new Array(); if (oResult != null) { var oElement = oResult.iterateNext(); while(oElement) { aNodes.push(oElement); oElement = oResult.iterateNext(); } } return aNodes; }; } else if (IsIE) { } /*---------------------------------------------*/ function StringBuilder(value) { this.strings = new Array(""); var myself = this; this.Append = function(new_value) { if (new_value) { myself.strings.push(new_value); } }; this.Clear = function() { myself.strings.length = 1; }; this.ToString = function() { return myself.strings.join(""); }; this.Append(value); } /*---------------------------------------------*/ function Ajax() { var myself = this; this.IsAsync = true; this.SendData = new Array(); this.URL = ""; this.ErrorCode = null; this.OnInitialize = function(){return null;}; this.OnLoading = function(){return null;}; this.OnLoaded = function(){return null;}; this.OnInteractive = function(){return null;}; this.OnComplete = function(){return null;}; this.OnError = function(){return null;}; this.ResponseXML = null; this.ResponseText = null; this.ResponseStream = null; this.ResponseBody = null; this.Status = null; this.Method = "POST"; this.OtherArgs = new Array(); var Completed = false; this.xmlhttp_obj = null; this.Send = function() { try { myself.xmlhttp_obj = new ActiveXObject("Microsoft.XMLHTTP"); } catch(ex) { try { myself.xmlhttp_obj = new ActiveXObject("Msxml2.XMLHTTP"); } catch(ex) { myself.xmlhttp_obj = new XMLHttpRequest(); } } myself.xmlhttp_obj.onreadystatechange = function() { switch(myself.xmlhttp_obj.readyState) { case(0): { myself.OnInitialize(myself); break; } case(1): { myself.OnLoading(myself); break; } case(2): { myself.OnLoaded(myself); break; } case(3): { myself.OnInteractive(myself); break; } case(4): { myself.Status = myself.xmlhttp_obj.status; if (myself.xmlhttp_obj.status == 200 && !Completed) { Completed = true; myself.ResponseXML = myself.xmlhttp_obj.responseXML; myself.ResponseText = myself.xmlhttp_obj.responseText; myself.ResponseStream = myself.xmlhttp_obj.responseStream; myself.ResponseBody = myself.xmlhttp_obj.responseBody; myself.OnComplete(myself); } else if (myself.xmlhttp_obj.status != 200) { myself.ErrorCode = myself.xmlhttp_obj.status; myself.ResponseXML = myself.xmlhttp_obj.responseXML; myself.ResponseText = myself.xmlhttp_obj.responseText; myself.ResponseStream = myself.xmlhttp_obj.responseStream; myself.ResponseBody = myself.xmlhttp_obj.responseBody; myself.OnError(myself); } break; } } }; var send_data = new StringBuilder(""); var not_first = false; for (current_send_date in myself.SendData) { if (not_first) { send_data.Append("&"); } not_first = true; send_data.Append(current_send_date.toString()); send_data.Append("="); send_data.Append(escape(myself.SendData[current_send_date])); } myself.xmlhttp_obj.open(myself.Method,myself.URL,myself.IsAsync); myself.xmlhttp_obj.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); myself.xmlhttp_obj.send(send_data.ToString()); }; this.Initalize = function() { myself.Method = "POST"; myself.OnInitialize = function(){return null}; myself.OnLoading = function(){return null;}; myself.OnLoaded = function(){return null;}; myself.OnInteractive = function(){return null;}; myself.OnComplete = function(){return null;}; myself.OnError = function(){return null;}; }; }; /*---------------------------------------------*/ function TransformImage(img_id,target_src,duration,step,enable_filter) { var the_img = $(img_id); the_img.style.backgroundColor = "#000000"; var tmp_img = document.createElement("img"); tmp_img.style.position = "absolute"; tmp_img.src = target_src; if (IsIE && !IsIE8) { tmp_img.style.filter = "Alpha(Opacity=0)"; the_img.style.filter = "Alpha(Opacity=100)"; } else { tmp_img.style.MozOpacity = the_img.style.opacity = "0.0"; the_img.style.MozOpacity = tmp_img.style.opacity = "1.0"; } the_img.parentNode.insertBefore(tmp_img,the_img); var fade_interval = duration / step; var current_width = the_img.clientWidth,current_height = the_img.clientHeight,target_width = tmp_img.clientWidth,target_height = tmp_img.clientHeight; var width_step = Math.abs(current_width - target_width) / step,height_step = Math.abs(current_height - target_height) / step,opacity_step = 100 / step; the_img.style.width = tmp_img.style.width = the_img.clientWidth.toString() + "px"; the_img.style.height = tmp_img.style.height = the_img.clientHeight.toString() + "px"; if (IsIE && enable_filter) { //the_img.style.filter = "progid:DXImageTransform.Microsoft.Fade(duration=" + (duration / 1000).toString() + ")";//渐变滤镜 //the_img.style.filter = "progid:DXImageTransform.Microsoft.RadialWipe(duration=" + (duration / 1000).toString() + ")";//雷达滤镜 the_img.style.filter = "progid:DXImageTransform.Microsoft.Pixelate(duration=" + (duration / 1000).toString() + ")";//打散滤镜 //the_img.style.filter = "progid:DXImageTransform.Microsoft.RandomBars(duration=" + (duration / 1000).toString() + ")";//百叶窗滤镜 //the_img.style.filter = "progid:DXImageTransform.Microsoft.RandomDissolve(duration=" + (duration / 1000).toString() + ")";//溶解滤镜 //the_img.style.filter = "progid:DXImageTransform.Microsoft.Slide(duration=" + (duration / 1000).toString() + ")";//滑动滤镜 //the_img.style.filter = "progid:DXImageTransform.Microsoft.Spiral(duration=" + (duration / 1000).toString() + ")";//螺旋滤镜 //the_img.style.filter = "progid:DXImageTransform.Microsoft.Stretch(duration=" + (duration / 1000).toString() + ")";//拉伸滤镜 //the_img.style.filter = "progid:DXImageTransform.Microsoft.Strips(duration=" + (duration / 1000).toString() + ")";//翻转滤镜 //the_img.style.filter = "progid:DXImageTransform.Microsoft.Wheel(duration=" + (duration / 1000).toString() + ")";//旋转滤镜 //the_img.style.filter = "progid:DXImageTransform.Microsoft.Zigzag(duration=" + (duration / 1000).toString() + ")";//阶梯消除滤镜 //the_img.style.filter = "progid:DXImageTransform.Microsoft.Iris(duration=" + (duration / 1000).toString() + ")";//四向分离滤镜 //the_img.style.filter = "progid:DXImageTransform.Microsoft.Inset(duration=" + (duration / 1000).toString() + ")"; //the_img.style.filter = "progid:DXImageTransform.Microsoft.GradientWipe(duration=" + (duration / 1000).toString() + ")"; //the_img.style.filter = "progid:DXImageTransform.Microsoft.Blinds(duration=" + (duration / 1000).toString() + ")"; //the_img.style.filter = "progid:DXImageTransform.Microsoft.CheckerBoard(duration=" + (duration / 1000).toString() + ")"; //the_img.style.filter = "progid:DXImageTransform.Microsoft.Barn(duration=" + (duration / 1000).toString() + ")"; the_img.filters[0].apply(); the_img.src = target_src; the_img.filters[0].play(); TransformImage_Loop(the_img,tmp_img,0,opacity_step,current_width,target_width,width_step,current_height,target_height,height_step,duration / step,false); } else { TransformImage_Loop(the_img,tmp_img,0,opacity_step,current_width,target_width,width_step,current_height,target_height,height_step,duration / step,true); } }; function TransformImage_Loop(the_img,tmp_img,current_opacity,opacity_step,current_width,target_width,width_step,current_height,target_height,height_step,interval,do_fade) { if ((current_opacity <= 100 && do_fade) || Math.abs(current_width - target_width) > width_step || Math.abs(current_height - target_height) > height_step) { if (current_opacity <= 100 && do_fade) { if (IsIE) { tmp_img.style.filter = "Alpha(Opacity=" + current_opacity.toString() + ")"; the_img.style.filter = "Alpha(Opacity=" + (100 - current_opacity).toString() + ")"; } else if(!IsIE) { tmp_img.style.MozOpacity = tmp_img.style.opacity = parseFloat(current_opacity / 100).toString(); the_img.style.MozOpacity = the_img.style.opacity = parseFloat((100 - current_opacity) / 100).toString(); } current_opacity+=opacity_step; } if (Math.abs(current_width - target_width) > width_step) { if (current_width > target_width) { current_width-=width_step; } else { current_width+=width_step; } the_img.style.width = tmp_img.style.width = current_width.toString() + "px"; } if (Math.abs(current_height - target_height) > height_step) { if (current_height > target_height) { current_height-= height_step; } else { current_height+=height_step; } the_img.style.height = tmp_img.style.height = current_height.toString() + "px"; } window.setTimeout(function(){return TransformImage_Loop(the_img,tmp_img,current_opacity,opacity_step,current_width,target_width,width_step,current_height,target_height,height_step,interval,do_fade)},interval); } else { the_img.src = tmp_img.src; the_img.style.width = tmp_img.style.width = ""; the_img.style.height = tmp_img.style.height = ""; if (IsIE) { the_img.style.filter = "Alpha(Opacity=100)"; } else { the_img.style.MozOpacity = the_img.style.opacity = "1.0"; } tmp_img.parentNode.removeChild(tmp_img); } }; /*---------------------------------------------*/ function FadeObject(is_in,target_object,total_time) { var fade_interval = parseInt(total_time / 10); window.setTimeout(function(){FadeObject_Loop(is_in ? 100:0,is_in,target_object,fade_interval)},fade_interval); } function FadeObject_Loop(current_capacity,is_in,target_object,fade_interval) { if (IsIE) { target_object.style.filter = "Alpha(Opacity=" + current_capacity.toString() + ")"; } else { target_object.style.opacity = target_object.style.MozOpacity = parseFloat(current_capacity/100).toString(); } if (is_in) { if (current_capacity >= 10) { current_capacity-=10; target_object.style.visibility = ""; window.setTimeout(function(){FadeObject_Loop(current_capacity,is_in,target_object,fade_interval)},fade_interval); } else { target_object.style.visibility = "hidden"; } } else if (!is_in) { if (current_capacity <=90) { current_capacity+=10; target_object.style.visibility = ""; window.setTimeout(function(){FadeObject_Loop(current_capacity,is_in,target_object,fade_interval)},fade_interval); } else { target_object.style.visibility = ""; } } } /*---------------------------------------------*/ function ElementAnimator(target_object) { var myself = this; this.OriginalWidth = -1; this.OriginalHeight = -1; this.TargetWidth = -1; this.TargetHeight = -1; this.CurrentWidth = -1; this.CurrentHeight = -1; this.CurrentLeft = null; this.CurrentTop = null; this.CurrentZIndex = null; this.OriginalLeft = null; this.OriginalTop = null; this.TargetLeft = null; this.TargetTop = null; this.OriginalStyleLeft = ""; this.OriginalStyleTop = ""; this.OnAnimationComplete = null; this.OnAnimating = null; this.OnAnimationCompleteInvokedCount = 0; this.TargetObject = target_object; this.IsWidthEnlarge = true; this.IsHeightEnlarge = true; this.HorizontalResizeStep = 0; this.VerticalResizeStep = 0; this.HorizontalMoveStep = 0; this.VerticalMoveStep = 0; this.OriginalOpacity = -1; this.TargetOpacity = -1; this.CurrentOpacity = -1; this.FadeStep = 0; this.ShadowColor = "#000000"; this.HasShadow = false; this.AbsoluteScrollTop = null; this.AbsoluteScrollLeft = null; this.RelativeScrollTop = null; this.RelativeScrollLeft = null; this.Animating = function() { if (typeof myself.OnAnimating == "function") { myself.OnAnimating(); } }; this.BindAnimator = function() { myself.TargetObject.Animator = myself; }; this.AnimationComplete = function() { if (typeof myself.OnAnimationComplete == "function") { myself.OnAnimationComplete(); } }; this.Resize = function(resize_timeout) { if (resize_timeout > 0 && resize_timeout != null) { myself.IsWidthEnlarge = this.OriginalWidth < this.TargetWidth ? true:false; myself.IsHeightEnlarge = this.OriginalHeight < this.TargetHeight ? true:false; if (myself.OriginalWidth < 0 || myself.TargetWidth < 0) { myself.OriginalWidth = myself.TargetWidth = myself.TargetObject.scrollWidth; } if (myself.OriginalHeight < 0 || myself.TargetHeight < 0) { myself.OriginalHeight = myself.TargetHeight = myself.TargetObject.scrollHeight; } myself.HorizontalResizeStep = parseFloat(Math.abs(myself.TargetWidth - myself.OriginalWidth)) / resize_timeout; myself.VerticalResizeStep = parseFloat(Math.abs(myself.TargetHeight - myself.OriginalHeight)) / resize_timeout; myself.CurrentWidth = myself.OriginalWidth; myself.CurrentHeight = myself.OriginalHeight; myself.OnAnimationCompleteInvokedCount++; myself.HideShadow(); myself.BindAnimator(); //window.setTimeout(function(){myself.ResizeLoop();},1); myself.ResizeLoop(); } else { throw new Error("Positive resize timeout expected!"); } }; this.ResizeLoop = function() { var need_loop = false; var loop_finished = true; if (myself.IsWidthEnlarge) { if (parseFloat(myself.TargetWidth - myself.CurrentWidth) >= myself.HorizontalResizeStep && myself.HorizontalResizeStep > 0) { loop_finished = need_loop = true; myself.TargetObject.style.width = parseInt(myself.CurrentWidth+=myself.HorizontalResizeStep).toString() + "px"; } } else { if (parseFloat(myself.CurrentWidth - myself.TargetWidth) >= myself.HorizontalResizeStep && myself.HorizontalResizeStep > 0) { loop_finished = need_loop = true; myself.TargetObject.style.width = parseInt(myself.CurrentWidth-=myself.HorizontalResizeStep).toString() + "px"; } } if (myself.IsHeightEnlarge) { if (parseFloat(myself.TargetHeight - myself.CurrentHeight) >= myself.VerticalResizeStep && myself.VerticalResizeStep > 0) { loop_finished = need_loop = true; myself.TargetObject.style.height = parseInt(myself.CurrentHeight+=myself.VerticalResizeStep).toString() + "px"; } } else { if (parseFloat(myself.CurrentHeight - myself.TargetHeight) >= myself.VerticalResizeStep && myself.VerticalResizeStep > 0) { loop_finished = need_loop = true; myself.TargetObject.style.height = parseInt(myself.CurrentHeight-=myself.VerticalResizeStep).toString() + "px"; } } if (need_loop) { myself.Animating(); //window.setTimeout(function(){myself.ResizeLoop();},1); myself.AppendAnimation(myself.ResizeLoop); } else { if (myself.HorizontalResizeStep > 0) { myself.TargetObject.style.width = myself.TargetWidth.toString() + "px"; } if (myself.VerticalResizeStep > 0) { myself.TargetObject.style.height = myself.TargetHeight.toString() + "px"; } myself.CurrentWidth = myself.CurrentHeight = null; myself.OnAnimationCompleteInvokedCount--; if (myself.OnAnimationCompleteInvokedCount == 0) { if (myself.HasShadow) { myself.DropShadow(); } myself.Animating(); myself.AnimationComplete(); } } }; this.Nudge = function(offset,nudge_length) { myself.OriginalStyleLeft = myself.TargetObject.style.left; myself.OriginalStyleTop = myself.TargetObject.style.top; if (myself.CurrentLeft == null) { myself.CurrentLeft = myself.TargetObject.offsetLeft; } if (myself.CurrentTop == null) { myself.CurrentTop = myself.TargetObject.offsetTop; } myself.OnAnimationCompleteInvokedCount++; myself.HideShadow(); myself.BindAnimator(); myself.NudgeLoop(offset,nudge_length); }; this.NudgeLoop = function(offset,nudge_length) { if (nudge_length > 0) { myself.TargetObject.style.left = (myself.CurrentLeft + parseInt(offset * Math.random())).toString() + "px"; myself.TargetObject.style.top = (myself.CurrentTop + parseInt(offset * Math.random())).toString() + "px"; myself.Animating(); //window.setTimeout(function(){myself.NudgeLoop(offset,nudge_length-1)},1); myself.AppendAnimation(function(){myself.NudgeLoop(offset,nudge_length-1);}); } else { myself.TargetObject.style.left = myself.OriginalStyleLeft; myself.TargetObject.style.top = myself.OriginalStyleTop; myself.OnAnimationCompleteInvokedCount--; if (myself.OnAnimationCompleteInvokedCount == 0) { if (myself.HasShadow) { myself.DropShadow(); } myself.Animating(); myself.AnimationComplete(); } } }; this.Move = function(move_timeout) { if (move_timeout >0) { if (myself.OriginalLeft != null && myself.TargetLeft != null) { myself.TargetObject.style.left = (myself.CurrentLeft = myself.OriginalLeft).toString() + "px"; myself.HorizontalMoveStep = parseFloat(myself.TargetLeft - myself.OriginalLeft) / move_timeout; } if (myself.OriginalTop != null && myself.TargetTop != null) { myself.TargetObject.style.top = (myself.CurrentTop = myself.OriginalTop).toString() + "px"; myself.VerticalMoveStep = parseFloat(myself.TargetTop - myself.OriginalTop) / move_timeout; } myself.OnAnimationCompleteInvokedCount++; myself.HideShadow(); myself.BindAnimator(); //window.setTimeout(function(){myself.MoveLoop();},1); myself.MoveLoop(); } else { throw new Error("Positive moving timeout expected!"); } }; this.MoveLoop = function() { var need_loop = false; if (myself.OriginalLeft != null && myself.TargetLeft != null) { if (Math.abs(myself.TargetLeft - myself.CurrentLeft) - Math.abs(myself.HorizontalMoveStep) > 0) { myself.CurrentLeft+=myself.HorizontalMoveStep; myself.TargetObject.style.left = parseInt(myself.CurrentLeft).toString() + "px"; need_loop = true; } } if (myself.OriginalTop != null && myself.TargetTop != null) { if (Math.abs(myself.TargetTop - myself.CurrentTop) - Math.abs(myself.VerticalMoveStep) > 0) { myself.CurrentTop+=myself.VerticalMoveStep; myself.TargetObject.style.top = parseInt(myself.CurrentTop).toString() + "px"; need_loop = true; } } if (need_loop) { myself.Animating(); //window.setTimeout(function(){myself.MoveLoop();},1); myself.AppendAnimation(myself.MoveLoop); } else { if (myself.OriginalLeft != null && myself.TargetLeft != null) { myself.TargetObject.style.left = myself.TargetLeft.toString() + "px"; } if (myself.OriginalTop != null && myself.TargetTop != null) { myself.TargetObject.style.top = myself.TargetTop.toString() + "px"; } myself.OnAnimationCompleteInvokedCount--; if (myself.OnAnimationCompleteInvokedCount == 0) { if (myself.HasShadow) { myself.DropShadow(); } myself.Animating(); myself.AnimationComplete(); } } }; this.Fade = function(fade_timeout) { if (myself.OriginalOpacity < 0 || myself.OriginalOpacity > 100 || myself.TargetOpacity < 0 || myself.TargetOpacity > 100) { throw new Error("Opacity value between 0 and 100 must be specified!"); } myself.FadeStep = 10 * parseFloat(myself.TargetOpacity - myself.OriginalOpacity) / fade_timeout; myself.CurrentOpacity = myself.OriginalOpacity; myself.OnAnimationCompleteInvokedCount++; myself.HideShadow(); myself.BindAnimator(); //window.setTimeout(function(){myself.FadeLoop();},10); myself.FadeLoop(); }; this.FadeLoop = function() { if (Math.abs(parseFloat(myself.TargetOpacity - myself.CurrentOpacity)) >= Math.abs(myself.FadeStep)) { if (IsIE) { myself.TargetObject.style.filter = "Alpha(Opacity=" + parseInt(myself.CurrentOpacity+=myself.FadeStep).toString() + ")"; } else { myself.TargetObject.style.MozOpacity = myself.TargetObject.style.opacity = (parseFloat(parseInt(myself.CurrentOpacity+=myself.FadeStep)) / 100).toString(); } myself.Animating(); //window.setTimeout(function(){myself.FadeLoop();},10); myself.AppendAnimation(myself.FadeLoop); } else { if (IsIE) { myself.TargetObject.style.filter = "Alpha(Opacity=" + parseInt(myself.TargetOpacity).toString() + ")"; } else { myself.TargetObject.style.MozOpacity = myself.TargetObject.style.opacity = parseFloat(myself.TargetOpacity / 100).toString(); } myself.OnAnimationCompleteInvokedCount--; if (myself.OnAnimationCompleteInvokedCount == 0) { if (myself.HasShadow) { myself.DropShadow(); } myself.Animating(); myself.AnimationComplete(); } } }; this.ShadowFlag = [false,true,true,true]; this.CurrentMargin = [0,0,0,0];//up,right,bottom,left this.GetActualStyle = function() { var current_style = $$.Element.GetActualStyle(myself.TargetObject); myself.CurrentMargin[0] = isNaN(parseInt(current_style.marginTop)) ? 0 : parseInt(current_style.marginTop); myself.CurrentMargin[1] = isNaN(parseInt(current_style.marginRight)) ? 0 : parseInt(current_style.marginRight); myself.CurrentMargin[2] = isNaN(parseInt(current_style.marginBottom)) ? 0 : parseInt(current_style.marginBottom); myself.CurrentMargin[3] = isNaN(parseInt(current_style.marginLeft)) ? 0 : parseInt(current_style.marginLeft); myself.CurrentWidth = isNaN(parseInt(current_style.width)) ? myself.TargetObject.scrollWidth : parseInt(current_style.width); myself.CurrentHeight = isNaN(parseInt(current_style.height)) ? myself.TargetObject.scrollHeight : parseInt(current_style.height); myself.CurrentZIndex = isNaN(parseInt(current_style.zIndex)) ? 0 : parseInt(current_style.zIndex); myself.CurrentLeft = isNaN(parseInt(current_style.left)) ? 0 : parseInt(current_style.left); myself.CurrentTop = isNaN(parseInt(current_style.top)) ? 0 : parseInt(current_style.top); }; this.DropShadow = function(is_syn) { if (myself.TargetObject != null) { if (myself.TargetObject.ShadowArray == null) { is_syn = typeof is_syn == "undefined" ? true : is_syn; myself.TargetObject.ShadowArray = new Array(); myself.GetActualStyle(); if (is_syn) { for (var cot = 0;cot < 5;cot++) { myself.TargetObject.ShadowArray[cot] = document.createElement("div"); with(myself.TargetObject.ShadowArray[cot]) { style.backgroundColor = myself.ShadowColor; style.position = "absolute"; style.zIndex = myself.CurrentZIndex == null ? "" : myself.CurrentZIndex.toString(); style.left = myself.CurrentLeft == 0 ? "" : myself.CurrentLeft.toString() + "px"; style.top = myself.CurrentTop == 0 ? "" : myself.CurrentTop.toString() + "px"; style.marginLeft = (myself.CurrentMargin[3] - (myself.ShadowFlag[3] ? cot : 0)).toString() + "px"; style.marginRight = (myself.CurrentMargin[1] - (myself.ShadowFlag[1] ? cot : 0)).toString() + "px"; style.marginTop = (myself.CurrentMargin[0] - (myself.ShadowFlag[0] ? cot : 0)).toString() + "px"; style.marginBottom = (myself.CurrentMargin[2] - (myself.ShadowFlag[2] ? cot : 0)).toString() + "px"; style.width = (myself.CurrentWidth + (myself.ShadowFlag[1] ? cot : 0) + (myself.ShadowFlag[3] ? cot : 0)).toString() + "px"; style.height = (myself.CurrentHeight + (myself.ShadowFlag[0] ? cot : 0) + (myself.ShadowFlag[2] ? cot : 0)).toString() + "px"; } $$.Element.SetOpacity(myself.TargetObject.ShadowArray[cot],0.2); myself.TargetObject.parentNode.insertBefore(myself.TargetObject.ShadowArray[cot],myself.TargetObject); } } else { myself.OnAnimationCompleteInvokedCount++; myself.DropShadow_Loop(-1); } } } }; this.DropShadow_Loop = function(shadow_level) { shadow_level++; if (shadow_level < 5) { myself.TargetObject.ShadowArray[shadow_level] = document.createElement("div"); with(myself.TargetObject.ShadowArray[shadow_level]) { style.backgroundColor = myself.ShadowColor; style.position = "absolute"; style.zIndex = myself.CurrentZIndex == null ? "" : myself.CurrentZIndex.toString(); style.left = myself.CurrentLeft == 0 ? "" : myself.CurrentLeft.toString() + "px"; style.top = myself.CurrentTop == 0 ? "" : myself.CurrentTop.toString() + "px"; style.marginLeft = (myself.CurrentMargin[3] - (myself.ShadowFlag[3] ? shadow_level : 0)).toString() + "px"; style.marginRight = (myself.CurrentMargin[1] - (myself.ShadowFlag[1] ? shadow_level : 0)).toString() + "px"; style.marginTop = (myself.CurrentMargin[0] - (myself.ShadowFlag[0] ? shadow_level : 0)).toString() + "px"; style.marginBottom = (myself.CurrentMargin[2] - (myself.ShadowFlag[2] ? shadow_level : 0)).toString() + "px"; style.width = (myself.CurrentWidth + (myself.ShadowFlag[1] ? shadow_level : 0) + (myself.ShadowFlag[3] ? shadow_level : 0)).toString() + "px"; style.height = (myself.CurrentHeight + (myself.ShadowFlag[0] ? shadow_level : 0) + (myself.ShadowFlag[2] ? shadow_level : 0)).toString() + "px"; } $$.Element.SetOpacity(myself.TargetObject.ShadowArray[shadow_level],0.2); myself.TargetObject.parentNode.insertBefore(myself.TargetObject.ShadowArray[shadow_level],myself.TargetObject); myself.AppendAnimation(function(){myself.DropShadow_Loop(shadow_level);}); } else { myself.OnAnimationCompleteInvokedCount--; if (myself.OnAnimationCompleteInvokedCount == 0) { myself.Animating(); myself.AnimationComplete(); } } }; this.HideShadow = function() { if (myself.TargetObject.ShadowArray != null) { while (myself.TargetObject.ShadowArray[0] != null) { myself.TargetObject.ShadowArray[0].parentNode.removeChild(myself.TargetObject.ShadowArray[0]); myself.TargetObject.ShadowArray.shift(); } } }; this.RemoveShadow = function(is_syn) { if (myself.TargetObject.ShadowArray != null) { is_syn = typeof is_syn == "undefined" ? true : false; if (is_syn) { myself.HasShadow = false; while (myself.TargetObject.ShadowArray[0] != null) { myself.TargetObject.ShadowArray[0].parentNode.removeChild(myself.TargetObject.ShadowArray[0]); myself.TargetObject.ShadowArray.shift(); } myself.TargetObject.ShadowArray = null; } else { myself.OnAnimationCompleteInvokedCount++; myself.RemoveShadow_Loop(); } } }; this.RemoveShadow_Loop = function() { if (myself.TargetObject.ShadowArray[0] != null) { myself.TargetObject.ShadowArray[myself.TargetObject.ShadowArray.length - 1].parentNode.removeChild(myself.TargetObject.ShadowArray[myself.TargetObject.ShadowArray.length - 1]); myself.TargetObject.ShadowArray.pop(); myself.AppendAnimation(myself.RemoveShadow_Loop); } else { myself.HasShadow = false; myself.TargetObject.ShadowArray = null; myself.OnAnimationCompleteInvokedCount--; if (myself.OnAnimationCompleteInvokedCount == 0) { myself.Animating(); myself.AnimationComplete(); } } }; this.OriginalScrollTop = -1; this.CurrentScrollTop = -1; this.TargetScrollTop = -1; this.ScrollTo = function(y_offset) { myself.CurrentScrollTop = myself.OriginalScrollTop = $$.Window.GetScrollTop(); var max_scroll_top = $$.Window.GetScrollHeight() - $$.Window.GetHeight(); myself.GetAbsoluteScrollTop(); myself.TargetScrollTop = myself.AbsoluteScrollTop; if (typeof y_offset == "number") { myself.TargetScrollTop+= y_offset; } myself.TargetScrollTop = myself.TargetScrollTop > max_scroll_top ? max_scroll_top : myself.TargetScrollTop; myself.TargetScrollTop = myself.TargetScrollTop < 0 ? 0 : myself.TargetScrollTop; myself.ScrollStep = Math.ceil((myself.TargetScrollTop - myself.CurrentScrollTop) * 0.1); myself.OnAnimationCompleteInvokedCount++; myself.BindAnimator(); myself.ScrollTo_Loop(); }; this.ScrollStep = 0; this.ScrollTo_Loop = function() { if (myself.ScrollStep != 0) { myself.ScrollStep = myself.TargetScrollTop - myself.CurrentScrollTop > 0 ? Math.ceil((myself.TargetScrollTop - myself.CurrentScrollTop) * 0.1) : Math.floor((myself.TargetScrollTop - myself.CurrentScrollTop) * 0.1); window.scrollTo(0,myself.CurrentScrollTop+=myself.ScrollStep); myself.Animating(); //window.setTimeout(myself.ScrollTo_Loop,10); myself.AppendAnimation(myself.ScrollTo_Loop); } else { myself.OnAnimationCompleteInvokedCount--; if (myself.OnAnimationCompleteInvokedCount == 0) { myself.Animating(); myself.AnimationComplete(); } } }; this.GetAbsoluteScrollTop = function() { myself.AbsoluteScrollTop = myself.TargetObject.offsetTop; myself.GetAbsoluteScrollTop_Loop(myself.TargetObject); return myself.AbsoluteScrollTop; }; this.GetAbsoluteScrollTop_Loop = function(obj) { if (obj.offsetParent != null) { myself.AbsoluteScrollTop+=obj.offsetParent.offsetTop; myself.GetAbsoluteScrollTop_Loop(obj.offsetParent); } }; this.GetAbsoluteScrollLeft = function() { myself.AbsoluteScrollLeft = myself.TargetObject.offsetLeft; myself.GetAbsoluteScrollLeft_Loop(myself.TargetObject); return myself.AbsoluteScrollLeft; }; this.GetAbsoluteScrollLeft_Loop = function(obj) { if (obj.offsetParent != null) { myself.AbsoluteScrollLeft+=obj.offsetParent.offsetLeft; myself.GetAbsoluteScrollLeft_Loop(obj.offsetParent); } }; this.GetRelativeScrollTop = function() { myself.RelativeScrollTop = myself.TargetObject.offsetTop;//myself.TargetObject.offsetTop; myself.GetRelativeScrollTop_Loop(myself.TargetObject); return myself.RelativeScrollTop; }; this.GetRelativeScrollTop_Loop = function(obj) { if (obj.offsetParent != null) { if ($$.Element.GetActualStyle(obj.offsetParent).position != "relative" && $$.Element.GetActualStyle(obj.offsetParent).position != "absolute") { myself.RelativeScrollTop+=obj.offsetParent.offsetTop; myself.GetRelativeScrollTop_Loop(obj.offsetParent); } } }; this.GetRelativeScrollLeft = function() { myself.RelativeScrollLeft = myself.TargetObject.offsetLeft;//myself.TargetObject.offsetLeft; myself.GetRelativeScrollLeft_Loop(myself.TargetObject); return myself.RelativeScrollLeft; }; this.GetRelativeScrollLeft_Loop = function(obj) { if (obj.offsetParent != null) { //if (obj.offsetParent.scrollLeft == obj.offsetParent.offsetLeft && obj.offsetParent.scrollTop == obj.offsetParent.offsetTop) if ($$.Element.GetActualStyle(obj.offsetParent).position != "relative" && $$.Element.GetActualStyle(obj.offsetParent).position != "absolute") { myself.RelativeScrollLeft+=obj.offsetParent.offsetLeft; myself.GetRelativeScrollLeft_Loop(obj.offsetParent); } } }; this.AppendAnimation = function(new_ani) { if (ElementAnimator.Timer == null) { ElementAnimator.Timer = window.setInterval(ElementAnimator.Animate,10); } ElementAnimator.Animation.push(new_ani); }; }; ElementAnimator.Timer = null; ElementAnimator.Animation = new Array(); ElementAnimator.Animate = function() { var total_ani = ElementAnimator.Animation.length; for (var cot = 0;cot < total_ani;cot++) { (ElementAnimator.Animation[cot])(); } ElementAnimator.Animation.splice(0,total_ani); };
www.apoclast.org
版权所有 2006-2008