Saturday, September 21, 2019

jQuery UI Dialog

The dialog boxes are used to present information in a nice way on the HTML pages. The jQuery UI dialog method is used to create a basic dialog window which is positioned into the viewport and protected from page content. It has a title bar and a content area, and can be moved, resized and closed with the 'x' icon by default.

Syntax:

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

  1. $(selector, context).dialog (options) Method  
  1. $(selector, context).dialog ("action", [params]) Method  

First Method

  1. $(selector, context).dialog (options) Method  
The dialog(options) method specifies that you can use an HTML element in the form of a dialog box. Here, options parameter is an object that specifies the appearance and behavior of that window.
Syntax:
  1. $(selector, context).dialog(options);  
You can use one or more options at a time using JavaScript object. In the case of more than one options, you must have to separate them using a comma as follows:
  1. $(selector, context).dialog({option1: value1, option2: value2..... });  
Following is a list of different options that can be used with this method:
OptionDescription
appendtoIf you set this option to false, it will prevent the UI-draggable class from being added in the list of selected DOM elements. By default its value is true.
autoopenIf you set this option to true, the dialog box is opened upon creation. when false, the dialog box will be opened upon a call to dialog('open'). By default its value is true.
buttonsThis option adds buttons in the dialog box. These are listed as objects, and each property is the text on the button. The value is a callback function called when the user clicks the button. By default its value is {}.
closeonescapeUnless you set this option to false, the dialog box will be closed when the user presses the escape key while the dialog box has focus. By default its value is true.
closetextThis option contains text to replace the default of close for the close button. by default its value is "close".
dialogclassIf you set this option to false, it will prevent the UI-draggable class from being added in the list of selected dom elements. By default its value is "".
draggableyou set this option to false, dialog box will be draggable by clicking and dragging the title bar. By default its value is true.
heightThis option sets the height of the dialog box. By default its value is "auto".
hideThis option is used to set the effect to be used when the dialog box is closed. By default its value is null.
maxheightThis option sets maximum height, in pixels, to which the dialog box can be resized. By default its value is false.
maxwidthThis option sets the maximum width to which the dialog can be resized, in pixels. By default its value is false.
minheightThis option is the minimum height, in pixels, to which the dialog box can be resized. By default its value is 150.
minwidthThis option is the minimum width, in pixels, to which the dialog box can be resized. By default its value is 150.
modalIf this option is set to true, the dialog will have modal behavior; other items on the page will be disabled, i.e., cannot be interacted with. modal dialogs create an overlay below the dialog but above other page elements. By default its value is false.
positionThis option specifies the initial position of the dialog box. can be one of the predefined positions: center (the default), left, right, top, or bottom. can also be a 2-element array with the left and top values (in pixels) as [left,top], or text positions such as ['right','top']. by default its value is { my: "center", at: "center", of: window }.
resizeableThis option unless set to false, the dialog box is resizable in all directions. by default its value is true.
showThis option is an effect to be used when the dialog box is being opened. by default its value is null.
titleThis option specifies the text to appear in the title bar of the dialog box. By default its value is null.
widthThis option specifies the width of the dialog box in pixels. By default its value is 300.

jQuery UI Dialog example 1

Let's take a simple example to demonstrate the usage of dialog functionality passing no parameter to the dialog() method.
  1. <!doctype html>  
  2. <html lang="en">  
  3.    <head>  
  4.       <meta charset="utf-8">  
  5.       <title>jQuery UI Dialog 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.       <!-- CSS -->  
  10.       <style>  
  11.          .ui-widget-header,.ui-state-default, ui-button{  
  12.             background:#b9cd6d;  
  13.             border: 1px solid #b9cd6d;  
  14.             color: #FFFFFF;  
  15.             font-weight: bold;  
  16.          }  
  17.       </style>  
  18.       <!-- Javascript -->  
  19.       <script>  
  20.          $(function() {  
  21.             $( "#dialog-1" ).dialog({  
  22.                autoOpen: false,    
  23.             });  
  24.             $( "#opener" ).click(function() {  
  25.                $( "#dialog-1" ).dialog( "open" );  
  26.             });  
  27.          });  
  28.       </script>  
  29.    </head>  
  30.    <body>  
  31.       <!-- HTML -->   
  32.       <div id="dialog-1" title="Movie Title:Psycho (1960)">"A boy's best friend is his mother." </div>  
  33.       <button id="opener">Open Dialog</button>  
  34.    </body>  
  35. </html>  

jQuery UI Dialog example 2

Use of buttons, title and position:
Let's take an example to demonstrate the usage of three options buttons, title and position in the dialog widget.
  1. <!doctype html>  
  2. <html lang="en">  
  3.    <head>  
  4.       <meta charset="utf-8">  
  5.       <title>jQuery UI Dialog 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.       <!-- CSS -->  
  10.       <style>  
  11.          .ui-widget-header,.ui-state-default, ui-button{  
  12.             background:lightgreen;  
  13.             border: 1px solid #b9cd6d;  
  14.             color: black;  
  15.             font-weight: bold;  
  16.          }  
  17.       </style>  
  18.       <!-- Javascript -->  
  19.       <script>  
  20.          $(function() {  
  21.             $( "#dialog-2" ).dialog({  
  22.                autoOpen: false,   
  23.                buttons: {  
  24.                   OK: function() {$(this).dialog("close");}  
  25.                },  
  26.                title: "Movie Title:Sholey",  
  27.                position: {  
  28.                   my: "left center",  
  29.                   at: "left center"  
  30.                }  
  31.             });  
  32.             $( "#opener-2" ).click(function() {  
  33.                $( "#dialog-2" ).dialog( "open" );  
  34.             });  
  35.          });  
  36.       </script>  
  37.    </head>  
  38.    <body>  
  39.       <!-- HTML -->   
  40.       <div id="dialog-2" title="Dialog Title goes here...">Are O Sambha:Kitna inaam rakhi hai re sarkar hum par.</div>  
  41.       <button id="opener-2">Open Dialog</button>  
  42.    </body>  
  43. </html>  

jQueryUI Dialog example 3

Use of hide, show and height:
Let's take an example to demonstrate the usage of these options hide, show and height.
  1. <!doctype html>  
  2. <html lang="en">  
  3.    <head>  
  4.       <meta charset="utf-8">  
  5.       <title>jQuery UI Dialog 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.       <!-- CSS -->  
  10.       <style>  
  11.          .ui-widget-header,.ui-state-default, ui-button{  
  12.             background: lightyellow;  
  13.             border: 1px solid #b9cd6d;  
  14.             color: black;  
  15.             font-weight: bold;  
  16.          }  
  17.       </style>  
  18.       <!-- Javascript -->  
  19.       <script>  
  20.          $(function() {  
  21.             $( "#dialog-3" ).dialog({  
  22.                autoOpen: false,   
  23.                hide: "slide",  
  24.                show : "slide",  
  25.                height: 200        
  26.             });  
  27.             $( "#opener-3" ).click(function() {  
  28.                $( "#dialog-3" ).dialog( "open" );  
  29.             });  
  30.          });  
  31.       </script>  
  32.    </head>  
  33.    <body>  
  34.       <!-- HTML -->   
  35.       <div id="dialog-3" title="This is a title.">This is a dialog.</div>  
  36.       <button id="opener-3">Open Dialog</button>  
  37.    </body>  
  38. </html>  

Second Method

  1. $(selector, context).dialog ("action", [params]) Method:  
The dialog (action, params) method is used to perform an action on the dialog box, such as closing the box. The action is specified as a string in the first argument and optionally, you can use one or more params one or more params based on the given action.
Syntax:
  1. $(selector, context).dialog ("action", [params]);  
Following is a list of actions that are used with this method:
ActionDescription
close()This action is used to close the dialog box. This method does not accept any arguments.
destroy()This action is used to removes the dialog box completely. This will return the element back to its pre-init state. This method does not accept any arguments.
isOpen()This action is used to check if the dialog box is open. This method does not accept any arguments.
moveToTop()This action is used to allocate position to the corresponding dialog boxes to the foreground (on top of the others). This method does not accept any arguments.
open()This action is used to opens the dialog box. This method does not accept any arguments.
option(optionName)this action gets the value currently associated with the specified optionName. where optionName is the name of the option to get.
option()This action gets an object containing key/value pairs representing the current dialog options hash. This method does not accept any arguments.
option(optionName,value)This action sets the value of the dialog option associated with the specified optionName.
option( options)This action sets one or more options for the dialog.
widget()This action is used to return the dialog box?s widget element; the element annotated with the ui-dialog class name. This method does not accept any arguments.

jQuery UI Dialog example 4

Let's take a simple example to demonstrate the use of isOpen(), open() and close() method.
  1. <!doctype html>  
  2. <html lang="en">  
  3.    <head>  
  4.       <meta charset="utf-8">  
  5.       <title>jQuery UI Dialog 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.       <!-- CSS -->  
  10.       <style>  
  11.          .ui-widget-header,.ui-state-default, ui-button{  
  12.             background:#b9cd6d;  
  13.             border: 1px solid #b9cd6d;  
  14.             color: #FFFFFF;  
  15.             font-weight: bold;  
  16.          }  
  17.       </style>  
  18.       <!-- Javascript -->  
  19.       <script type="text/javascript">  
  20.          $(function(){  
  21.             $("#toggle").click(function() {  
  22.           
  23.                ($("#dialog-5").dialog("isOpen") == false) ? $("#dialog-5").dialog("open") : $("#dialog-5").dialog("close") ;  
  24.             });  
  25.             $("#dialog-5").dialog({autoOpen: false});  
  26.          });  
  27.       </script>  
  28.    </head>  
  29.    <body>  
  30.       <button id="toggle">Toggle dialog!</button>  
  31.       <div id="dialog-5" title="Dialog Title!">  
  32.          Click on the Toggle button to open and cose this dialog box.  
  33.       </div>  
  34.    </body>  
  35. </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 { ...