Skip to content

Commit 97047e3

Browse files
committed
Updating samples / demo
1 parent 5f8a1e2 commit 97047e3

File tree

5 files changed

+48
-23
lines changed

5 files changed

+48
-23
lines changed

README.md

+12-9
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ JQuery Autohide plugin
33

44
Jquery plugin to show / hide / autohide elements, like shopping carts or help bubbles, megadrop menus. That elements' visibility is triggered from another element... usually a button, menu item, etc.
55

6+
<h3>[View demo]()<h3>
7+
68
![Smaple snapshop](https://raw.github.com/carloscabo/jquery-autohide-plugin/master/sample-image.png)
79

810
## 1. Concepts / naming
911

10-
`$source` elements originating the events. Usually button, menu items, etc.
12+
`$source` element(s) originating the events. Usually button, menu items, etc.
1113

12-
`$target` elements to be shown when the event is triggerered from a `$source` element. Usually a menu / information overlay... etc.
14+
`$target` elements **to be shown when the event is triggerered** from a `$source` element. Usually a menu / information overlay... etc.
1315

1416
`timeout` time (in miliseconds) until the `$target` element autohides.
1517

@@ -22,9 +24,9 @@ We have a `$souce` element ( `#element-to-click` ), that when the default event
2224
`$target` element will autohide with a timeout ( default is 1500ms ).
2325

2426
```javascript
25-
$('#element-to-click').autohide_timeout({
26-
// timeout: 1000,
27-
$target: $('#single-bubble-content')
27+
$('#element-to-be-clicked').autohide_timeout({
28+
// timeout: 1500, // Default
29+
$target: $('#conten-to-be-shown')
2830
});
2931
```
3032

@@ -41,6 +43,7 @@ $('#element-to-click').autohide_timeout({
4143
events: 'mouseenter',
4244

4345
// Timeout until the 'onTimeout' function is launched
46+
// Default is 1500
4447
timeout: 2000,
4548

4649
// $source is used to have several interactive children
@@ -91,8 +94,8 @@ $('#element-to-click').autohide_timeout({
9194

9295
### 3. Hidding $target element from JS
9396

94-
You can force the
95-
96-
## Demos
97+
You can force the closing event from JS using:
9798

98-
Take a look to the demos to see some typical usage scenarios.
99+
```javascript
100+
$(element).data('plugin_autohide_timeout').settings.onTimeout();
101+
```

css/application.css

+5-3
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ li.active {
5959
color: #000;
6060
}
6161

62-
#single-bubble-button {
62+
.single-bubble {
6363
position: relative;
64+
display: inline-block;
65+
margin-right: 20px;
6466
}
6567

66-
#single-bubble-content {
68+
.single-bubble-content {
6769
display: none;
6870
position: absolute;
6971
width: 300px; /* height: 150px; */
@@ -73,7 +75,7 @@ li.active {
7375
z-index: 9;
7476
}
7577

76-
#single-bubble-content p {
78+
.single-bubble-content p {
7779
margin: 0;
7880
}
7981

index.html

+11-3
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,20 @@
1717
<h3 id="section-sample-1">Sample #1. #single-bubble-button</h3>
1818
<p>Easiest sample, simple show / hide element binding link with #ID and content layer with another <b>unique #ID</b></p>
1919

20-
<span id="single-bubble-button"><a href="#">Simple bubble on-click</a>
21-
<div id="single-bubble-content">
20+
<span class="single-bubble" id="single-bubble-button-a"><a href="#">Simple bubble on-click</a>
21+
<div class="single-bubble-content" id="single-bubble-content-a">
2222
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Culpa, beatae. Tempore autem, eveniet nulla voluptate culpa commodi magni!</p>
2323
</div>
2424
</span>
2525

26+
<span class="single-bubble" id="single-bubble-button-b"><a href="#">Simple bubble on-click, timeout 10s</a>
27+
<div class="single-bubble-content" id="single-bubble-content-b">
28+
<p><b>Waits 10s then closes.</b><br>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Culpa, beatae. Tempore autem, eveniet nulla voluptate culpa commodi magni!</p>
29+
</div>
30+
</span>
31+
32+
<span id="close-both-bubbles">Force close both bubles!</span>
33+
2634
<hr>
2735

2836
<h3 id="section-sample-2">Sample #2</h3>
@@ -143,7 +151,7 @@ <h3 id="section-sample-4">Sample #4. Megadrop</h3>
143151
<br>
144152
<hr>
145153

146-
<h3 id="section-sample-4">Sample #5. Megadrop slide-up/down</h3>
154+
<h3 id="section-sample-4">Sample #5. Megadrop slide-down</h3>
147155
<p>Another common scenario, several megadrops, outside the nav container slided-down / up with jQuery</p>
148156

149157
<ul id="sample-5-megadrop">

js/jquery.autohide.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ $('.element-to-hide-show').autohide_timeout({
126126
return $target;
127127
}, // getTarget
128128

129-
close: function() {
130-
131-
} // close
129+
destroy: function() {
130+
// To do
131+
} // destroy
132132

133133
} );
134134

js/ready.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,21 @@ $(document).ready(function() {
44

55
// ----------------------------------
66
// Smaple #1
7-
$('#single-bubble-button > a').autohide_timeout({
7+
$('#single-bubble-button-a > a').autohide_timeout({
88
timeout: 1000,
9-
$target: $('#single-bubble-content')
9+
$target: $('#single-bubble-content-a')
10+
});
11+
12+
$('#single-bubble-button-b > a').autohide_timeout({
13+
timeout: 10000,
14+
events: 'click mouseenter',
15+
$target: $('#single-bubble-content-b')
16+
});
17+
18+
$('#close-both-bubbles').on('click', function(e){
19+
$('.single-bubble > a').each(function( idx, el ){
20+
$(el).data('plugin_autohide_timeout').settings.onTimeout();
21+
})
1022
});
1123

1224
// ----------------------------------
@@ -119,14 +131,14 @@ $(document).ready(function() {
119131
// console.log( $target );
120132
$source.closest('ul').find('.active').removeClass('active');
121133
$source.parent('li').addClass('active');
122-
$('.megadrop-wrapper-5 .megadrop').slideUp();
123-
$target.slideDown();
134+
$('.megadrop-wrapper-5 .megadrop').not($target).stop().fadeOut();
135+
$target.stop().slideDown();
124136
},
125137
// What to do when is timeout is triggered
126138
onTimeout: function( $source, $target, event ) {
127139
// console.log( $source );
128140
$source.parent('li').removeClass('active');
129-
$('.megadrop-wrapper-5 .megadrop').slideUp();
141+
$('.megadrop-wrapper-5 .megadrop').stop().slideUp();
130142
}
131143
});
132144

0 commit comments

Comments
 (0)