1 line
11 KiB
JavaScript
1 line
11 KiB
JavaScript
(function(d){var a=d.telerik;function c(f){var e=f?f.toLowerCase():"";return e&&e.indexOf("http")!==0&&e.indexOf("https")!==0}function b(e){if(d.browser.msie&&d.browser.version<7){e.find(".t-resize-e,.t-resize-w").css("height",e.height()).end().find(".t-resize-n,.t-resize-s").css("width",e.width()).end().find(".t-overlay").css({width:e.width(),height:e.height()})}}a.fx.zoom=function(e){this.element=e};a.fx.zoom.prototype={play:function(h,f){var i=this.element.show();var g=i.find("> .t-window-content");var e={width:g.width(),height:g.height(),left:parseInt(i.css("left")),top:parseInt(i.css("top"))};i.css({left:e.left+20,top:e.top+20}).animate({left:e.left,top:e.top},h.openDuration);g.css({width:e.width-40,height:e.height-40}).animate({width:e.width,height:e.height},h.openDuration)},rewind:function(h,f){var i=this.element;var g=i.find("> .t-window-content");var e={width:g.width(),height:g.height(),left:parseInt(i.css("left")),top:parseInt(i.css("top"))};g.animate({width:e.width-40,height:e.height-40},h.closeDuration);i.animate({left:e.left+20,top:e.top+20},h.closeDuration,function(){i.css({left:e.left,top:e.top}).hide();g.css({width:e.width,height:e.height});if(f){f()}})}};a.fx.zoom.defaults=function(){return{list:[{name:"zoom"}],openDuration:"fast",closeDuration:"fast"}};a.window=function(f,g){this.element=f;var h=d(f);if(!h.is(".t-window")){h.addClass("t-widget t-window");a.window.create(f,g)}d.extend(this,g);var e=".t-window-titlebar .t-window-action";h.delegate(".t-window-titlebar","dblclick",d.proxy(this.toggleMaximization,this)).delegate(e,"mouseenter",a.hover).delegate(e,"mouseleave",a.leave).delegate(e,"click",d.proxy(this.windowActionHandler,this));if(this.resizable){h.append(a.window.getResizeHandlesHtml());b(h);a.draganddrop(this.element.id+"Resize",d.extend({draggables:h.find(".t-resize-handle"),hitTestOffset:0},a.draganddrop.applyContext(a.draganddrop.windowResize,this)))}if(this.draggable){a.draganddrop(this.element.id+"Move",d.extend({draggables:h.find(".t-window-titlebar")},a.draganddrop.applyContext(a.draganddrop.windowMove,this)))}a.bind(this,{open:this.onOpen,close:this.onClose,refresh:this.onRefresh,resize:this.onResize,error:this.onError,load:this.onLoad,move:this.onMove});if(!h.parent().is("body")){h.css(h.offset()).appendTo(document.body)}if(this.modal&&d("body > .t-overlay").length==0){this.overlay(h.is(":visible"))}d(window).resize(d.proxy(this.onDocumentResize,this));if(c(this.contentUrl)){this.ajaxRequest()}};a.window.prototype={overlay:function(e){var f=d("body > .t-overlay");if(f.length==0){f=d('<div class="t-overlay" />').toggle(e).appendTo(this.element.ownerDocument.body)}var g=d(document);if(d.browser.msie&&d.browser.version<7){f.css({width:g.width()-21,height:g.height(),position:"absolute"})}return f},windowActionHandler:function(h){var g=d(h.target).closest(".t-window-action").find(".t-icon");var f=this;d.each({"t-close":this.close,"t-maximize":this.maximize,"t-restore":this.restore,"t-refresh":this.refresh},function(i,e){if(g.hasClass(i)){h.preventDefault();e.call(f);return false}})},center:function(){var e=d(this.element);var f=d(window);e.css({left:(f.width()-e.width())/2,top:(f.height()-e.height())/2});return this},title:function(f){var e=d(".t-window-titlebar > .t-window-title",this.element);if(!f){return e.text()}e.text(f);return this},content:function(e){var f=d("> .t-window-content",this.element);if(!e){return f.html()}f.html(e);return this},open:function(h){var f=d(this.element);if(!f.is(":visible")){if(!a.trigger(this.element,"open")){if(this.modal){var g=this.overlay(false);if(this.effects.list.length>0&&this.effects.list[0].name!="toggle"){g.css("opacity",0).show().animate({opacity:0.5},this.effects.openDuration)}else{g.css("opacity",0.5).show()}}a.fx.play(this.effects,f)}}return this},close:function(h){var f=d(this.element);if(f.is(":visible")){if(!a.trigger(this.element,"close")){var g=this.modal?this.overlay(true):d(undefined);g.animate({opacity:0},this.effects.closeDuration);a.fx.rewind(this.effects,f,null,function(){g.add(f[0]).hide()})}}if(this.isMaximized){d("html, body").css("overflow","")}return this},toggleMaximization:function(f){if(f&&d(f.target).closest(".t-window-action").length>0){return}this[this.isMaximized?"restore":"maximize"]()},restore:function(){if(!this.isMaximized){return}d(this.element).css({position:"absolute",left:this.restorationSettings.left,top:this.restorationSettings.top}).find("> .t-window-content").css({width:this.restorationSettings.width,height:this.restorationSettings.height}).end().find(".t-resize-handle").show().end().find(".t-window-titlebar .t-restore").addClass("t-maximize").removeClass("t-restore");d("html, body").css("overflow","");this.isMaximized=false;a.trigger(this.element,"resize");return this},maximize:function(h){if(this.isMaximized){return}var f=d(this.element);var g=f.find("> .t-window-content");this.restorationSettings={left:f.position().left,top:f.position().top,width:g.width(),height:g.height()};f.css({left:0,top:0,position:"fixed"}).find(".t-resize-handle").hide().end().find(".t-window-titlebar .t-maximize").addClass("t-restore").removeClass("t-maximize");d("html, body").css("overflow","hidden");this.isMaximized=true;this.onDocumentResize();return this},onDocumentResize:function(){if(!this.isMaximized){return}var e=d(this.element);var f=e.find("> .t-window-content");f.css({width:d(window).width()-(f.outerWidth()-f.width()+e.outerWidth()-e.width()),height:d(window).height()-(f.outerHeight()-f.height()+e.outerHeight()-e.height()+e.find("> .t-window-titlebar").outerHeight())});b(e);a.trigger(e,"resize")},refresh:function(){if(c(this.contentUrl)){this.ajaxRequest()}return this},ajaxRequest:function(e){var g=setTimeout(function(){d(".t-refresh",this.element).addClass("t-loading")},100);var f={};d.ajax({type:"GET",url:e||this.contentUrl,dataType:"html",data:f,error:d.proxy(function(i,h){if(a.ajaxError(this.element,"error",i,h)){return}},this),complete:function(){clearTimeout(g);d(".t-refresh",this.element).removeClass("t-loading")},success:d.proxy(function(h,i){d(".t-window-content",this.element).html(h);a.trigger(this.element,"refresh")},this)})},destroy:function(){d(this.element).remove();if(this.modal){this.overlay(false).remove()}}};d.extend(a.draganddrop,{windowMove:{shouldDrag:function(e){return !this.isMaximized&&e.closest(".t-window-action").length==0},onDragStart:function(f,g){this.initialWindowPosition=d(this.element).position();this.startPosition={left:f.pageX-this.initialWindowPosition.left,top:f.pageY-this.initialWindowPosition.top};d(".t-resize-handle",this.element).hide();d('<div class="t-overlay" />').appendTo(this.element);d(document.body).css("cursor",g.css("cursor"))},onDragMove:function(g){var f={left:g.pageX-this.startPosition.left,top:Math.max(g.pageY-this.startPosition.top,0)};d(this.element).css(f)},onDragCancelled:function(f,g){d(this.element).find(".t-resize-handle").show().end().find(".t-overlay").remove();d(document.body).css("cursor","");g.closest(".t-window").css(this.initialWindowPosition)},onDrop:function(g,h,f){d(this.element).find(".t-resize-handle").show().end().find(".t-overlay").remove();d(document.body).css("cursor","");return true}},windowResize:{shouldDrag:function(e){return true},onDragStart:function(g,h){var f=d(this.element);this.initialCursorPosition=f.offset();this.resizeDirection=h[0].className.replace("t-resize-handle t-resize-","").split("");this.resizeElement=f.find("> .t-window-content");this.initialSize={width:this.resizeElement.width(),height:this.resizeElement.height()};this.outlineSize={left:this.resizeElement.outerWidth()-this.resizeElement.width()+f.outerWidth()-f.width(),top:this.resizeElement.outerHeight()-this.resizeElement.height()+f.outerHeight()-f.height()+f.find("> .t-window-titlebar").outerHeight()};d('<div class="t-overlay" />').appendTo(this.element);f.find(".t-resize-handle").not(h).hide();d(document.body).css("cursor",h.css("cursor"))},onDragMove:function(h,i){var g=d(this.element);var f={e:function(){var e=h.pageX-this.initialCursorPosition.left-this.outlineSize.left;this.resizeElement.width((e<this.minWidth?this.minWidth:(this.maxWidth&&e>this.maxWidth)?this.maxWidth:e))},s:function(){var e=h.pageY-this.initialCursorPosition.top-this.outlineSize.top;this.resizeElement.height((e<this.minHeight?this.minHeight:(this.maxHeight&&e>this.maxHeight)?this.maxHeight:e))},w:function(){var j=this.initialCursorPosition.left+this.initialSize.width;g.css("left",h.pageX>(j-this.minWidth)?j-this.minWidth:h.pageX<(j-this.maxWidth)?j-this.maxWidth:h.pageX);var e=j-h.pageX;this.resizeElement.width((e<this.minWidth?this.minWidth:(this.maxWidth&&e>this.maxWidth)?this.maxWidth:e))},n:function(){var e=this.initialCursorPosition.top+this.initialSize.height;g.css("top",h.pageY>(e-this.minHeight)?e-this.minHeight:h.pageY<(e-this.maxHeight)?e-this.maxHeight:h.pageY);var j=e-h.pageY;this.resizeElement.height((j<this.minHeight?this.minHeight:(this.maxHeight&&j>this.maxHeight)?this.maxHeight:j))}};d.each(this.resizeDirection,d.proxy(function(j,e){f[e].call(this)},this));b(g);a.trigger(this.element,"resize")},onDragCancelled:function(g,h){var f=d(this.element);f.find(".t-overlay").remove().end().find(".t-resize-handle").not(h).show();b(f);d(document.body).css("cursor","");this.resizeElement.css(this.initialSize)},onDrop:function(g,h,f){d(this.element).find(".t-overlay").remove().end().find(".t-resize-handle").not(h).show();d(document.body).css("cursor","");return true}}});d.extend(a.window,{create:function(f,g){if(!f.nodeType){g=f;f=null}else{g.html=f.innerHTML}g=d.extend({title:"",html:"",actions:["Close"]},g);var e=new a.stringBuilder().catIf('<div class="t-widget t-window">',!f).cat('<div class="t-window-titlebar t-header">').cat(' <span class="t-window-title">').cat(g.title).cat("</span>").cat('<div class="t-window-actions t-header">');d.map(g.actions,function(h){e.cat('<a href="#" class="t-window-action t-link">').cat('<span class="t-icon t-').cat(h.toLowerCase()).cat('">').cat(h).cat("</span></a>")});e.cat("</div></div>").cat('<div class="t-window-content t-content" style="');if(g.width){e.cat("width:").cat(g.width).cat("px;")}if(g.height){e.cat("height:").cat(g.height).cat("px;")}e.cat('">').cat(g.html).cat("</div>").catIf("</div>",!f);if(f){d(f).html(e.string())}else{return d(e.string()).tWindow(g)}},getResizeHandlesHtml:function(){var e=new a.stringBuilder();d.each("n e s w se sw ne nw".split(" "),function(f,g){e.cat('<div class="t-resize-handle t-resize-').cat(g).cat('"></div>')});return e.string()}});d.fn.tWindow=function(e){return a.create(this,{name:"tWindow",init:function(f,g){return new a.window(f,g)},options:e})};d.fn.tWindow.defaults={effects:{list:[{name:"zoom"},{name:"property",properties:["opacity"]}],openDuration:"fast",closeDuration:"fast"},modal:false,resizable:true,draggable:true,minWidth:50,minHeight:50}})(jQuery); |