+ /* setup onoff widgets */
+ // Add the correct class to the switcher according to the input
+ // value (On/Off)
+ $(".toggle input").each(function(){
+ // Get the value of the input element
+ val = $(this).val();
+ id = $(this).attr("id");
+
+ // The css classes for "on" and "off"
+ onstyle = "btn-primary";
+ offstyle = "btn-default off";
+
+ // Add the correct class in dependence of input value (On/Off)
+ toggleclass = (val == 0 ? offstyle : onstyle);
+ $("#"+id+"_onoff").addClass(toggleclass);
+
+ });
+
+ // Change the css class while clicking on the switcher elements
+ $(".toggle label, .toggle .toggle-handle").click(function(event){
+ event.preventDefault();
+ // Get the value of the input element
+ var input = $(this).siblings("input");
+ var val = 1-input.val();
+ var id = input.attr("id");
+
+ // The css classes for "on" and "off"
+ var onstyle = "btn-primary";
+ var offstyle = "btn-default off";
+
+ // According to the value of the input element we need to decide
+ // which class need to be added and removed when changing the switch
+ var removedclass = (val == 0 ? onstyle : offstyle);
+ var addedclass = (val == 0 ? offstyle : onstyle)
+ $("#"+id+"_onoff").addClass(addedclass).removeClass(removedclass);
+
+ // After changing the switch the input element is getting
+ // the newvalue
+ input.val(val);
+ });
+
+ // Set the padding for input elements with inline buttons
+ //
+ // In Frio we use some input elements where the submit button is visually
+ // inside the the input field (through css). We need to set a padding-right
+ // to the input element where the padding value would be at least the width
+ // of the button. Otherwise long user input would be invisible because it is
+ // behind the button.
+ $("body").on('click', '.form-group-search > input', function() {
+ // Get the width of the button (if the button isn't available
+ // buttonWidth will be null
+ var buttonWidth = $(this).next('.form-button-search').outerWidth();
+
+ if (buttonWidth) {
+ // Take the width of the button and ad 5px
+ var newWidth = buttonWidth + 5;
+ // Set the padding of the input element according
+ // to the width of the button
+ $(this).css('padding-right', newWidth);
+ }
+
+ });
+
+