mirror of
https://github.com/processwire/processwire.git
synced 2025-08-25 23:56:41 +02:00
Fix issue processwire/processwire-issues#1008
This commit is contained in:
@@ -49,7 +49,7 @@ function InputfieldToggleInit() {
|
|||||||
$label.removeClass(labelCheckedClass);
|
$label.removeClass(labelCheckedClass);
|
||||||
// if this de-select was the first selection in the request, it's necessary to remove
|
// if this de-select was the first selection in the request, it's necessary to remove
|
||||||
// the checked attribute again a short while later for some reason
|
// the checked attribute again a short while later for some reason
|
||||||
setTimeout(function() { $input.removeAttr('checked') }, 100);
|
setTimeout(function() { $input.removeAttr('checked').trigger('change'); }, 100);
|
||||||
} else {
|
} else {
|
||||||
// input was just checked (and wasn't before), so add our checked class to the input
|
// input was just checked (and wasn't before), so add our checked class to the input
|
||||||
$input.attr('checked', 'checked').prop('checked', 'checked');
|
$input.attr('checked', 'checked').prop('checked', 'checked');
|
||||||
|
@@ -1 +1 @@
|
|||||||
function InputfieldToggleInit(){var isClick=false;var inputCheckedClass="InputfieldToggleChecked";var labelCheckedClass="InputfieldToggleCurrent";function getLabelFromInput($input){var $label=$input.next("label");if(!$label.length)$label=$input.parent("label");if(!$label.length)$label=$("label[for="+$input.attr("id")+"]");return $label}function getInputFromLabel($label){var $input=$label.prev("input");if(!$input.length)$input=$label.find("input");if(!$input.length)$input=$("input[id="+$label.attr("for")+"]");return $input}function toggleInputEvent($input){var $label=getLabelFromInput($input);var $prevInput=$input.closest(".Inputfield").find("input."+inputCheckedClass);var $prevLabel=$prevInput.length?getLabelFromInput($prevInput):null;if($prevInput.length&&$prevInput.attr("id")!=$input.attr("id")){$prevInput.removeClass(inputCheckedClass).removeAttr("checked");if($prevLabel)$prevLabel.removeClass(labelCheckedClass)}if($input.hasClass(inputCheckedClass)&&$input.closest(".InputfieldToggleUseDeselect").length){$input.removeAttr("checked").removeClass(inputCheckedClass);$label.removeClass(labelCheckedClass);setTimeout(function(){$input.removeAttr("checked")},100)}else{$input.attr("checked","checked").prop("checked","checked");$input.addClass(inputCheckedClass);$label.addClass(labelCheckedClass);$input.trigger("change")}}function initEvents(){$(document).on("change",".InputfieldToggle input",function(){if(isClick)return false;toggleInputEvent($(this))}).on("click",".InputfieldToggle label:not(.InputfieldHeader)",function(event){if(isClick)return false;var $label=$(this);var $input=getInputFromLabel($label);if(!$input.length)return;isClick=true;toggleInputEvent($input);setTimeout(function(){isClick=false},200);if($input.closest(".InputfieldToggleGroup").length)return false})}function initColors(){var $button=$(".InputfieldToggleHelper > button");var $input=$(".InputfieldToggleHelper > input");if(!$button.length)$button=$(".InputfieldForm button.ui-priority-secondary:eq(0)");if(!$button.length)$button=$(".InputfieldForm button.ui-button:eq(0)");if(!$button.length)$button=$(".InputfieldForm button[type=submit]");if(!$input.length)$input=$(".InputfieldForm input[type=text]:eq(0)");if(!$button.length||!$input.length)return;InputfieldToggleSetColors({onBg:$button.css("background-color"),on:$button.css("color"),offBg:$input.css("background-color"),off:$input.css("color"),border:$input.css("border-bottom-color")})}initEvents();initColors()}function InputfieldToggleSetColors(customColors){var colors={on:"",onBg:"",off:"",offBg:"",border:"",hoverBg:"",hover:""};$.extend(colors,customColors);if(!colors.hoverBg&&colors.onBg){colors.hoverBg=colors.onBg.replace("rgb(","rgba(").replace(")",",.2)");if(!colors.hover)colors.hover=colors.off}var style="<style type='text/css'>"+".InputfieldToggleGroup label { "+(colors.offBg?"background-color: "+colors.offBg+"; ":"")+(colors.off?"color: "+colors.off+";":"")+(colors.border?"border-color: "+colors.border+";":"")+"} "+".InputfieldToggleGroup label.InputfieldToggleCurrent, "+".InputfieldToggleGroup input:checked + label { "+(colors.onBg?"background-color: "+colors.onBg+"; ":"")+(colors.on?"color: "+colors.on+";":"")+(colors.onBg?"border-color: "+colors.onBg+"; ":"")+"} "+".InputfieldToggleGroup label:not(.InputfieldToggleCurrent):hover,"+".InputfieldToggleGroup input:not(:checked) + label:not(.InputfieldToggleCurrent):hover { "+(colors.hoverBg?"background-color: "+colors.hoverBg+"; ":"")+(colors.hover?"color: "+colors.hover+"; ":"")+"}"+"</style>";$("head").append(style)}jQuery(document).ready(function($){InputfieldToggleInit()});
|
function InputfieldToggleInit(){var isClick=false;var inputCheckedClass="InputfieldToggleChecked";var labelCheckedClass="InputfieldToggleCurrent";function getLabelFromInput($input){var $label=$input.next("label");if(!$label.length)$label=$input.parent("label");if(!$label.length)$label=$("label[for="+$input.attr("id")+"]");return $label}function getInputFromLabel($label){var $input=$label.prev("input");if(!$input.length)$input=$label.find("input");if(!$input.length)$input=$("input[id="+$label.attr("for")+"]");return $input}function toggleInputEvent($input){var $label=getLabelFromInput($input);var $prevInput=$input.closest(".Inputfield").find("input."+inputCheckedClass);var $prevLabel=$prevInput.length?getLabelFromInput($prevInput):null;if($prevInput.length&&$prevInput.attr("id")!=$input.attr("id")){$prevInput.removeClass(inputCheckedClass).removeAttr("checked");if($prevLabel)$prevLabel.removeClass(labelCheckedClass)}if($input.hasClass(inputCheckedClass)&&$input.closest(".InputfieldToggleUseDeselect").length){$input.removeAttr("checked").removeClass(inputCheckedClass);$label.removeClass(labelCheckedClass);setTimeout(function(){$input.removeAttr("checked").trigger("change")},100)}else{$input.attr("checked","checked").prop("checked","checked");$input.addClass(inputCheckedClass);$label.addClass(labelCheckedClass);$input.trigger("change")}}function initEvents(){$(document).on("change",".InputfieldToggle input",function(){if(isClick)return false;toggleInputEvent($(this))}).on("click",".InputfieldToggle label:not(.InputfieldHeader)",function(event){if(isClick)return false;var $label=$(this);var $input=getInputFromLabel($label);if(!$input.length)return;isClick=true;toggleInputEvent($input);setTimeout(function(){isClick=false},200);if($input.closest(".InputfieldToggleGroup").length)return false})}function initColors(){var $button=$(".InputfieldToggleHelper > button");var $input=$(".InputfieldToggleHelper > input");if(!$button.length)$button=$(".InputfieldForm button.ui-priority-secondary:eq(0)");if(!$button.length)$button=$(".InputfieldForm button.ui-button:eq(0)");if(!$button.length)$button=$(".InputfieldForm button[type=submit]");if(!$input.length)$input=$(".InputfieldForm input[type=text]:eq(0)");if(!$button.length||!$input.length)return;InputfieldToggleSetColors({onBg:$button.css("background-color"),on:$button.css("color"),offBg:$input.css("background-color"),off:$input.css("color"),border:$input.css("border-bottom-color")})}initEvents();initColors()}function InputfieldToggleSetColors(customColors){var colors={on:"",onBg:"",off:"",offBg:"",border:"",hoverBg:"",hover:""};$.extend(colors,customColors);if(!colors.hoverBg&&colors.onBg){colors.hoverBg=colors.onBg.replace("rgb(","rgba(").replace(")",",.2)");if(!colors.hover)colors.hover=colors.off}var style="<style type='text/css'>"+".InputfieldToggleGroup label { "+(colors.offBg?"background-color: "+colors.offBg+"; ":"")+(colors.off?"color: "+colors.off+";":"")+(colors.border?"border-color: "+colors.border+";":"")+"} "+".InputfieldToggleGroup label.InputfieldToggleCurrent, "+".InputfieldToggleGroup input:checked + label { "+(colors.onBg?"background-color: "+colors.onBg+"; ":"")+(colors.on?"color: "+colors.on+";":"")+(colors.onBg?"border-color: "+colors.onBg+"; ":"")+"} "+".InputfieldToggleGroup label:not(.InputfieldToggleCurrent):hover,"+".InputfieldToggleGroup input:not(:checked) + label:not(.InputfieldToggleCurrent):hover { "+(colors.hoverBg?"background-color: "+colors.hoverBg+"; ":"")+(colors.hover?"color: "+colors.hover+"; ":"")+"}"+"</style>";$("head").append(style)}jQuery(document).ready(function($){InputfieldToggleInit()});
|
Reference in New Issue
Block a user