Saturday, September 21, 2019

jQuery UI Button

jQuery UI button() method is used to transform the HTML elements (like buttons, inputs and anchors etc.) It transforms HTML elements into themeable buttons, with automatic management of mouse movements on them. They areall managed transparently by jQuery UI.

Syntax:

You can use the button() method in two forms:

  1. $(selector, context).button (options) Method  
  1. $(selector, context).button ("action", params) Method  

First Method

The button (options) method specifies that an HTML element should be treated as button. Here the ?options? parameter is an object that specifies the behavior and appearance of the button.
Syntax:
  1. $(selector, context).button (options);  
You can use one or more options at a time using JavaScript object. In the case of more than one option, you have to separate them using a comma as follows:
  1. $(selector, context).button({option1: value1, option2: value2..... });  
Following is a list of options that can be used with this method:
OptionDescription
disabledIf you set this option to true, it deactivates the button. By default its value is false.
iconsThis option specifies that one or two icons are to be displayed in the button: Primary icons to the left, secondary icons to the right.Primary icon is identified by the primary property of the object, and the secondary icon is identified by the secondary property. By default its primary and seconadary value is set to NULL.
labelThis option specifies text to display on the button that overrides the natural label. In the case of radio buttons and checkboxes, the natural label is the <label> element associated with the control. By default its value is NULL.
textThis option specifies whether text is to be displayed on the button. If specified as false, text is suppressed if (and only if) the icons option specifies at least one icon. By default its value is true.

jQuery UI button() Example 1

Let's take an example to demonstrate the functionality of button widget, passing no parameter to the button() method.
  1. <!doctype html>  
  2. <html lang="en">  
  3.    <head>  
  4.       <meta charset="utf-8">  
  5.       <title>jQuery UI Buttons functionality</title>  
  6.       <link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">  
  7.       <script src="http://code.jquery.com/jquery-1.10.2.js"></script>  
  8.       <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>  
  9.       <script>  
  10.          $(function() {  
  11.             $( "#button-1, #button-2, #button-3, #button-4" ).button();  
  12.             $( "#button-5" ).buttonset();  
  13.          });  
  14.       </script>  
  15.    </head>  
  16.    <body>  
  17.       <button id="button-1">A button element</button>  
  18.       <input id="button-2" type="submit" value="A submit button">  
  19.       <a id="button-3" href="">An anchor</a>  
  20.       <input type="checkbox"  id="button-4" >  
  21.       <label for="button-4">Toggle</label>  
  22.       <br><br>  
  23.       <div id="button-5">  
  24.          <input type="checkbox" id="check1">  
  25.          <label for="check1">Left</label>  
  26.          <input type="checkbox" id="check2">  
  27.          <label for="check2">Middle</label>  
  28.          <input type="checkbox" id="check3">  
  29.          <label for="check3">Right</label>  
  30.       </div>  
  31. </body>  
  32. </html>  

jQuery UI button() example 2

Use of icons, text and disabled:
Let's take an example to demonstrate the usage of options icons, text and disabled in the button function of jQueryUI.
  1. <!doctype html>  
  2. <html lang="en">  
  3.    <head>  
  4.       <meta charset="utf-8">  
  5.       <title>jQuery UI Buttons functionality</title>  
  6.       <link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">  
  7.       <script src="http://code.jquery.com/jquery-1.10.2.js"></script>  
  8.       <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>  
  9.       <script>  
  10.          $(function() {  
  11.             $( "#button-6" ).button({  
  12.                icons: {  
  13.                   primary: "ui-icon-locked"  
  14.                },  
  15.                text: false  
  16.             });  
  17.             $( "#button-7" ).button({  
  18.                disabled:true  
  19.             });  
  20.             $( "#button-8" ).button({  
  21.                icons: {  
  22.                   primary: "ui-icon-gear",  
  23.                   secondary: "ui-icon-triangle-1-s"  
  24.                }  
  25.             });  
  26.          });  
  27.       </script>  
  28.    </head>  
  29.    <body>  
  30.       <button id="button-6">  
  31.          Button with icon only  
  32.       </button>  
  33.       <button id="button-7">  
  34.          Button Disabled  
  35.       </button>  
  36.       <button id="button-8">  
  37.          Button with two icons  
  38.       </button>  
  39.    </body>  
  40. </html>  

Second Method

The button ("action", params) method is used to perform an action on buttons, such as disabling the button. Here ?action? is specified as a string in the first argument (e.g., "disable" to disable button).
Syntax:
  1. $(selector, context).button ("action", params);  
Following is a list of different actions that can be used with this method:
ActionDescription
destroyThis action is used to remove the button functionality of an element completely and enforces the elements return to their pre-init state. This method does not accept any arguments.
disableThis action is used to disable the button functionality of an element. This method does not accept any arguments.
enableThis action is used to enable the button functionality of an element. This method does not accept any arguments.
option( optionName )This action retrieves the value of the option specified in optionName. Here optionName is a string.
optionThis action retrieves an object containing key/value pairs representing the current button options hash.
option( optionName, value )This action sets the value of the button option associated with the specified optionName.
option( options )This action sets one or more options for the button. Here options is map of option-value pairs to set.
refreshThis action refreshes the display of the button. This is useful when the buttons are handled by the program and the display does not necessarily correspond to the internal state. This method does not accept any arguments.
widgetThis action returns a jQuery object containing the button element. This method does not accept any arguments.

jQueryUI button() example 3

Let's take an example to deploy the above actions. In the following example, we demonstrate the use of destroy () and disable () methods.

  1. <!doctype html>  
  2. <html lang="en">  
  3.    <head>  
  4.       <meta charset="utf-8">  
  5.       <title>jQuery UI Buttons functionality</title>  
  6.       <link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">  
  7.       <script src="http://code.jquery.com/jquery-1.10.2.js"></script>  
  8.       <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>  
  9.       <script>  
  10.          $(function() {  
  11.             $( "#button-9" ).button({  
  12.                text: false,  
  13.                icons: {  
  14.                   primary: "ui-icon-seek-start"  
  15.                }  
  16.             });  
  17.             $( "#button-9" ).button('destroy');  
  18.             $( "#button-10" ).button({  
  19.                icons: {  
  20.                   primary: "ui-icon-seek-prev"  
  21.                }  
  22.             });  
  23.             $( "#button-10" ).button('disable');  
  24.             $( "#button-11" ).button({  
  25.                text: false,  
  26.                icons: {  
  27.                   primary: "ui-icon-play"  
  28.                }  
  29.             });  
  30.          });  
  31.       </script>  
  32.    </head>  
  33.    <body>  
  34.       <button id="button-9">  
  35.          I'm destroyed  
  36.       </button>  
  37.       <button id="button-10">     
  38.          I'm disabled  
  39.       </button>  
  40.       <button id="button-11">  
  41.          play  
  42.       </button>  
  43.    </body>  
  44. </html>  

No comments:

Post a Comment

How to register multiple implementations of the same interface in Asp.Net Core?

 Problem: I have services that are derived from the same interface. public interface IService { } public class ServiceA : IService { ...