Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <style> .red { color:red; } </style>
- <script src="http://code.jquery.com/jquery-latest.min.js"></script>
- <script>
- // as found on http://gist.github.com/399624 (June 16th 2010)
- jQuery.fn.single_double_click = function(single_click_callback, double_click_callback, timeout) {
- return this.each(function(){
- var clicks = 0, self = this;
- jQuery(this).click(function(event){
- clicks++;
- if (clicks == 1) {
- setTimeout(function(){
- if(clicks == 1) {
- single_click_callback.call(self, event);
- } else {
- double_click_callback.call(self, event);
- }
- clicks = 0;
- $('#debug').html(clicks);
- }, timeout || 300);
- }
- $('#debug').html(clicks);
- });
- });
- }
- $(document).ready(function(){
- // this works as espected in FF and IE8
- // $('input').dblclick(function(){$('#toggle').toggleClass('red');});
- // this misses alot of clicks in IE8 (only one I have)
- $('input').single_double_click(
- function(){ $('#toggle').toggleClass('red'); }, // toggle class on single click
- function(){ $('#toggle').toggle(); } // toggle visibility
- );
- });
- </script>
- </head>
- <body>
- <div id="debug">0</div>
- <input type="button" value="Click me!" />
- <div id="toggle">Testing double clicks!</div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement