You can follow any responses to this entry through the feed RSS 2.0 . You can also write your own comments , or to link to this post on your page.
About the Author
What do I do
- (4 months) How about a MacBook Air for you and me? http://t.co/1uZXnVB4 via @ appsumo
- (5 months) http://www.youtube.com/watch?v=k1PhaOQ5JSU # ios # apple # appstore
- (5 months) # ios free quiz as early as in # appstore http://rdir.pl/1m82c4 # apple
- (6 months) in the app store :) # ios # appstore en / en # apple
- (1 year) # play # bielsko 3Mb/1Mb down / up - not bad
Categories
- . Net (21)
- asp.net (7)
- c # (20)
- interest (10)
- Index (1)
- other (7)
- iPhone (5)
- jquery (9)
- Conference (3)
- mobile (3)
- My site (4)
- tools (4)
- optimization (1)
- php (4)
- guides (10)
- projects (5)
- Silverlight (3)
- wpf (3)
- XNA (12)

















































jQuery: A confirmation window
We remain the subject of practical uses jQuery. Today I needed to write a window confirming an operation in the administration panel. The case seems to be simple and can be solved by the subject, forgetting about JavaScript (Confirm) or PHP, but the fun lies in how to do this so as not to cause, and even that was a really decent result?
I will try to present a sample solution to the problem, assuming that the element that we want is accompanied by confirmation by the user, is a link.
First Sample HTML File
We start with a file on which we perform our vile tests:
Sample text generator Lorem ipsum , went inside a p. Shortly before the closing body tag, put the div # confirm, within which there will be a code from our window to confirm.
Second The presentation layer
Let us focus on our window. In my case, the html code which will be responsible for the entire window, will look as follows:
The code inside the # confirm, is generated by JavaScript. But it is worth considering why it looks just like that and why is at the bottom of the page code?
Let's start with the reasons for including the code at the end. In determining the position: absolute, for # confirm, without z-index parameter, the sequence of objects from position: absolute, it will match the order in which they are generated by the browser. Last compiled, there will be more than a stack of layers with position: absolute, so if for example, will have the same dimensions, mask the layer, which appeared in the code earlier.
Why does confirm the inside, we placed two times a div? To clarify this point is, just read the section in your css code that you place inside the head section:
# Defines here confirm the background that will "cover" the entire page. The second line, (the one with a strange height and width), it is necessary in the case of Internet Explorer. # Confirm [id] is comprehensible only to modern browsers, and this was the plan to the background of our window was the size of 100% to 100% and runs throughout the time with the site (for IE is calculated in each case based on the current width and height of the window).
The first div is necessary to center the 2nd and to take a distance from the top window on the margin-top. The second div already provides our window to confirm that can be centered, as it is inside a block element with width: 100% (standard value for an element with display: block - which is a div)
Third Time for jQuery
It remains for us to react to clicks on the link that appears at the end of the block P, which put lorem ipsum'a:
<a href="http://poslinski.net" class="confirm"> Maecenas </ a>In our case, all links with class confirm, will react to the script. You could apply our acknowledgment to all links, for removing a value from the database.
It requires JavaScript code that is placed on the bottom of the page:
The first line load jQuery.
Then, the main branch of our code $ (document). Ready, activate your code, after a page loads.
We respond to clicking on the element with the class confirm, causing in this case a series of methods on the element with id = confirm. To begin, add a transparency (but still an element is set to display: none), then using the method fadeIn, jQuery seamlessly moves from display: none to opacity: 0.95 (in our case). Finally, inside the element of # confirm, load the html code of our two divami, which is placed inside the h1 header button and two buttons. As you probably, have noticed one of them, plus they are declared onClick event, which will react to a positive user confirmation, przekierowywując him to the place that showed clicked link.
Why return false at the end of this block of code? To the browser, we do not redirect automatically, by clicking on the link, our function must return false, otherwise it will redirect and windows will be confirming the threads.
If you click anywhere else than in the button of "YES", use event FadeOut (), the block will disappear seamlessly with our confirmation, which realizes $ ("# confirm"). Click (...).
The whole written code should look something like this:
Summary
Working example, you can see here .
This sample solution does not require all the possibilities. We can extend the code so as to affect the confirmation form, you would then send the form control, which also can be made from within jQuery. You can also, on the basis of the above code to create a plugin for jQuery. Feel free to discuss in the comments to this post.
Related entries