www-thermferm/jqwidgets/jqxradiobutton.js

Sun, 07 Jul 2019 14:31:10 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 07 Jul 2019 14:31:10 +0200
branch
stable
changeset 603
fcff55324b84
parent 511
2d1d43c3a2c2
child 617
b216f9d4b917
permissions
-rw-r--r--

Merged fix from default

/*
jQWidgets v4.5.2 (2017-May)
Copyright (c) 2011-2017 jQWidgets.
License: http://jqwidgets.com/license/
*/
!function(a){a.jqx.jqxWidget("jqxRadioButton","",{}),a.extend(a.jqx._jqxRadioButton.prototype,{defineInstance:function(){var b={animationShowDelay:300,animationHideDelay:300,width:null,height:null,boxSize:"13px",checked:!1,hasThreeStates:!1,disabled:!1,enableContainerClick:!0,locked:!1,groupName:"",rtl:!1,changeType:null,aria:{"aria-checked":{name:"checked",type:"boolean"},"aria-disabled":{name:"disabled",type:"boolean"}},events:["checked","unchecked","indeterminate","change"]};return this===a.jqx._jqxRadioButton.prototype?b:(a.extend(!0,this,b),b)},createInstance:function(a){var b=this;b._createFromInput("RadioButton"),b.render()},_createFromInput:function(b){var c=this;if("input"==c.element.nodeName.toLowerCase()){c.field=c.element,c.field.className&&(c._className=c.field.className);var d={title:c.field.title};c.field.value&&(d.value=c.field.value),c.field.checked&&(d.checked=!0),c.field.id.length?d.id=c.field.id.replace(/[^\w]/g,"_")+"_"+b:d.id=a.jqx.utilities.createId()+"_"+b;var e=c.element.nextSibling,f=!1;!e||"#text"!=e.nodeName&&"span"!=e.nodeName||(f=!0);var g=0,h=a("<div></div>",d);if(f){h.append(e);var i=a("<span>"+a(e).text()+"</span>");i.appendTo(a(document.body)),g+=i.width(),i.remove()}h[0].style.cssText=c.field.style.cssText,c.width||(c.width=a(c.field).width()+g+10),c.height||(c.height=a(c.field).outerHeight()+10),a(c.field).hide().after(h);var j=c.host.data();if(c.host=h,c.host.data(j),c.element=h[0],c.element.id=c.field.id,c.field.id=d.id,c._className&&(c.host.addClass(c._className),a(c.field).removeClass(c._className)),c.field.tabIndex){var k=c.field.tabIndex;c.field.tabIndex=-1,c.element.tabIndex=k}}},render:function(){this.setSize();var b=this;this.propertyChangeMap.width=function(a,c,d,e){b.setSize()},this.propertyChangeMap.height=function(a,c,d,e){b.setSize()},this.radiobutton&&this.radiobutton.remove(),this.width||this.host.css("overflow-x","visible"),this.height||this.host.css("overflow-y","visible"),null==this.boxSize&&(this.boxSize=13);var c=parseInt(this.boxSize)+"px",d="13px",e=Math.floor((parseInt(this.boxSize)-13)/2),f=e;e+="px",f+="px";var g=parseInt(this.boxSize)/2+"px";"13px"!=this.boxSize?this.radiobutton=a('<div><div style="width: '+c+"; height: "+c+';"><span style="position: relative; left: '+e+"; top: "+f+"; width: "+d+"; height: "+d+';"></span></div></div>'):this.radiobutton=a('<div><div style="width: '+c+"; height: "+c+';"><span style="width: '+g+"; height: "+g+';"></span></div></div>'),this.host.attr("role","radio"),this.host.prepend(this.radiobutton),this.disabledContainer||(this.host.attr("tabIndex")||this.host.attr("tabIndex",0),this.clear=a('<div style="clear: both;"></div>'),this.host.append(this.clear)),this.checkMark=a(this.radiobutton[0].firstChild.firstChild),this.box=this.radiobutton,this._supportsRC=!0,a.jqx.browser.msie&&a.jqx.browser.version<9&&(this._supportsRC=!1),this.box.addClass(this.toThemeProperty("jqx-fill-state-normal")),this.box.addClass(this.toThemeProperty("jqx-radiobutton-default")),this.host.addClass(this.toThemeProperty("jqx-widget")),this.disabled&&this.disable(),this.host.addClass(this.toThemeProperty("jqx-radiobutton")),this.locked&&this.host.css("cursor","auto");var h=this.element.getAttribute("checked");"checked"!=h&&"true"!=h&&1!=h||(this.checked=!0),this._addInput(),this._render(),this._addHandlers(),a.jqx.aria(this),this._centerBox()},_centerBox:function(){if(this.height&&this.height.toString().indexOf("%")==-1&&this.box){var a=parseInt(this.height);this.host.css("line-height",a+"px");var b=a-parseInt(this.boxSize)-1;b/=2,this.box.css("margin-top",parseInt(b))}},_addInput:function(){var b=this.host.attr("name");this.input=a("<input type='hidden'/>"),this.host.append(this.input),b&&this.input.attr("name",b)},refresh:function(a){a||(this.setSize(),this._render())},resize:function(a,b){this.width=a,this.height=b,this.setSize()},setSize:function(){null!=this.width&&this.width.toString().indexOf("px")!=-1?this.host.width(this.width):void 0==this.width||isNaN(this.width)?null!=this.width&&this.width.toString().indexOf("%")!=-1&&(this.element.style.width=this.width):this.host.width(this.width),null!=this.height&&this.height.toString().indexOf("px")!=-1?this.host.height(this.height):void 0==this.height||isNaN(this.height)?null!=this.height&&this.height.toString().indexOf("%")!=-1&&(this.element.style.height=this.height):this.host.height(this.height),this._centerBox()},_addHandlers:function(){var a=this;this.addHandler(this.box,"click",function(b){if(!a.disabled&&!a.enableContainerClick)return a.changeType="mouse",a.toggle("click"),b.preventDefault(),!1}),this.addHandler(this.host,"keydown",function(b){if(!a.disabled&&!a.locked&&32==b.keyCode)return a.changeType="keyboard",a.toggle("click"),b.preventDefault(),!1}),this.addHandler(this.host,"click",function(b){if(!a.disabled&&a.enableContainerClick)return a.changeType="mouse",a.toggle("click"),b.preventDefault(),!1}),this.addHandler(this.host,"selectstart",function(b){!a.disabled&&a.enableContainerClick&&b.preventDefault()}),this.addHandler(this.host,"mouseup",function(b){!a.disabled&&a.enableContainerClick&&b.preventDefault()}),this.addHandler(this.host,"focus",function(b){if(!a.disabled&&a.enableContainerClick&&!a.locked)return a.box.addClass(a.toThemeProperty("jqx-radiobutton-hover")),a.box.addClass(a.toThemeProperty("jqx-fill-state-focus")),b.preventDefault(),!1}),this.addHandler(this.host,"blur",function(b){if(!a.disabled&&a.enableContainerClick&&!a.locked)return a.box.removeClass(a.toThemeProperty("jqx-radiobutton-hover")),a.box.removeClass(a.toThemeProperty("jqx-fill-state-focus")),b.preventDefault(),!1}),this.addHandler(this.host,"mouseenter",function(b){if(!a.disabled&&a.enableContainerClick&&!a.locked)return a.box.addClass(a.toThemeProperty("jqx-radiobutton-hover")),a.box.addClass(a.toThemeProperty("jqx-fill-state-hover")),b.preventDefault(),!1}),this.addHandler(this.host,"mouseleave",function(b){if(!a.disabled&&a.enableContainerClick&&!a.locked)return a.box.removeClass(a.toThemeProperty("jqx-radiobutton-hover")),a.box.removeClass(a.toThemeProperty("jqx-fill-state-hover")),b.preventDefault(),!1}),this.addHandler(this.box,"mouseenter",function(){a.disabled||a.enableContainerClick||(a.box.addClass(a.toThemeProperty("jqx-radiobutton-hover")),a.box.addClass(a.toThemeProperty("jqx-fill-state-hover")))}),this.addHandler(this.box,"mouseleave",function(){a.disabled||a.enableContainerClick||(a.box.removeClass(a.toThemeProperty("jqx-radiobutton-hover")),a.box.removeClass(a.toThemeProperty("jqx-fill-state-hover")))})},focus:function(){try{this.host.focus()}catch(a){}},_removeHandlers:function(){this.removeHandler(this.box,"click"),this.removeHandler(this.box,"mouseenter"),this.removeHandler(this.box,"mouseleave"),this.removeHandler(this.host,"click"),this.removeHandler(this.host,"mouseup"),this.removeHandler(this.host,"mousedown"),this.removeHandler(this.host,"selectstart"),this.removeHandler(this.host,"mouseenter"),this.removeHandler(this.host,"mouseleave"),this.removeHandler(this.host,"keydown"),this.removeHandler(this.host,"focus"),this.removeHandler(this.host,"blur")},_render:function(){null==this.boxSize&&(this.boxSize=13),this.box.width(this.boxSize),this.box.height(this.boxSize),this.disabled?this.disable():this.enableContainerClick?this.host.css("cursor","pointer"):this.host.css("cursor","auto"),this.rtl&&(this.box.addClass(this.toThemeProperty("jqx-radiobutton-rtl")),this.host.addClass(this.toThemeProperty("jqx-rtl"))),this.updateStates()},val:function(a){return 0==arguments.length||"object"==typeof a?this.checked:("string"==typeof a?("true"==a&&this.check("api"),"false"==a&&this.uncheck("api"),""==a&&this.indeterminate("api")):(1==a&&this.check("api"),0==a&&this.uncheck("api"),null==a&&this.indeterminate("api")),this.checked)},check:function(b){this.checked=!0;var c=this;this.checkMark.removeClass(),this.checkMark.addClass(this.toThemeProperty("jqx-fill-state-pressed")),a.jqx.browser.msie?this.disabled?(this.checkMark.addClass(this.toThemeProperty("jqx-radiobutton-check-disabled")),this.checkMark.addClass(this.toThemeProperty("jqx-radiobutton-check-checked"))):this.checkMark.addClass(this.toThemeProperty("jqx-radiobutton-check-checked")):(this.disabled?(this.checkMark.addClass(this.toThemeProperty("jqx-radiobutton-check-disabled")),this.checkMark.addClass(this.toThemeProperty("jqx-radiobutton-check-checked"))):this.checkMark.addClass(this.toThemeProperty("jqx-radiobutton-check-checked")),this.checkMark.css("opacity",0),this.checkMark.stop().animate({opacity:1},this.animationShowDelay,function(){}));var d=a.find(".jqx-radiobutton");if(null==this.groupName&&(this.groupName=""),a.each(d,function(){var b=a(this).jqxRadioButton("groupName");b==c.groupName&&this!=c.element&&a(this).jqxRadioButton("uncheck","api")}),this._raiseEvent("0"),this._raiseEvent("3",{type:b,checked:!0}),0==this.checkMark.height()){var e=parseInt(this.boxSize)/2;this.checkMark.height(e),this.checkMark.width(e)}else if("13px"!=this.boxSize){var e=parseInt(this.boxSize)/2;this.checkMark.height(e),this.checkMark.width(e),this.checkMark.css("margin-left",1+e/4),this.checkMark.css("margin-top",1+e/4)}this.input.val(this.checked),a.jqx.aria(this,"aria-checked",this.checked)},uncheck:function(b){var c=this.checked;this.checked=!1;var d=this;a.jqx.browser.msie?d.checkMark.removeClass():(this.checkMark.css("opacity",1),this.checkMark.stop().animate({opacity:0},this.animationHideDelay,function(){d.checkMark.removeClass()})),c&&(this._raiseEvent("1"),this._raiseEvent("3",{type:b,checked:!1})),this.input.val(this.checked),a.jqx.aria(this,"aria-checked",this.checked)},indeterminate:function(b){var c=this.checked;this.checked=null,this.checkMark.removeClass(),a.jqx.browser.msie?this.checkMark.addClass(this.toThemeProperty("jqx-radiobutton-check-indeterminate")):(this.checkMark.addClass(this.toThemeProperty("jqx-radiobutton-check-indeterminate")),this.checkMark.css("opacity",0),this.checkMark.stop().animate({opacity:1},this.animationShowDelay,function(){})),null!=c&&(this._raiseEvent("2"),this._raiseEvent("3",{type:b,checked:null})),this.input.val(this.checked),a.jqx.aria(this,"aria-checked","undefined")},toggle:function(a){if(!this.disabled&&!this.locked){var b=this.checked;1==this.checked?this.checked=!this.hasTreeStates||null:this.checked=!0,b!=this.checked&&this.updateStates(a),this.input.val(this.checked)}},updateStates:function(a){this.checked?this.check(a):0==this.checked?this.uncheck(a):null==this.checked&&this.indeterminate(a)},disable:function(){this.disabled=!0,1==this.checked?this.checkMark.addClass(this.toThemeProperty("jqx-radiobutton-check-disabled")):null==this.checked&&this.checkMark.addClass(this.toThemeProperty("jqx-radiobutton-check-indeterminate-disabled")),this.box.addClass(this.toThemeProperty("jqx-radiobutton-disabled")),this.host.addClass(this.toThemeProperty("jqx-fill-state-disabled")),a.jqx.aria(this,"aria-disabled",this.disabled)},enable:function(){this.host.removeClass(this.toThemeProperty("jqx-fill-state-disabled")),1==this.checked?this.checkMark.removeClass(this.toThemeProperty("jqx-radiobutton-check-disabled")):null==this.checked&&this.checkMark.removeClass(this.toThemeProperty("jqx-radiobutton-check-indeterminate-disabled")),this.box.removeClass(this.toThemeProperty("jqx-radiobutton-disabled")),this.disabled=!1,a.jqx.aria(this,"aria-disabled",this.disabled)},destroy:function(){this._removeHandlers(),this.host.remove()},_raiseEvent:function(b,c){var d=this.events[b],e=new a.Event(d);e.owner=this,c||(c={}),c.type=this.changeType,this.changeType=null,e.args=c;try{var f=this.host.trigger(e)}catch(a){}return f},propertiesChangedHandler:function(a,b,c){c.width&&c.height&&2==Object.keys(c).length&&a.setSize()},propertyChangedHandler:function(b,c,d,e){if(void 0!=this.isInitialized&&0!=this.isInitialized&&!(b.batchUpdate&&b.batchUpdate.width&&b.batchUpdate.height&&2==Object.keys(b.batchUpdate).length)){if(c!=this.enableContainerClick||this.disabled||this.locked||(e?this.host.css("cursor","pointer"):this.host.css("cursor","auto")),"rtl"==c&&(e?(b.box.addClass(b.toThemeProperty("jqx-radiobutton-rtl")),b.host.addClass(b.toThemeProperty("jqx-rtl"))):(b.box.removeClass(b.toThemeProperty("jqx-radiobutton-rtl")),b.host.removeClass(b.toThemeProperty("jqx-rtl")))),"boxSize"==c&&b.render(),"checked"==c)switch(e){case!0:this.check("api");break;case!1:this.uncheck("api");break;case null:this.indeterminate()}"theme"==c&&a.jqx.utilities.setTheme(d,e,this.host),"disabled"==c&&(e?this.disable():this.enable())}}})}(jqxBaseFramework);

mercurial