-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Call a method when an element becomes visible.
- Loading branch information
Showing
6 changed files
with
162 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,75 @@ | ||
<div> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" rel="stylesheet" /> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" rel="stylesheet" /> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script> | ||
|
||
<script> | ||
function callAlert(name) { | ||
alert("hello, " + name); | ||
} | ||
<script> | ||
function callAlert(name) { | ||
alert("hello, " + name); | ||
} | ||
|
||
var HelloJs = (function() { | ||
var self = {}; | ||
var HelloJs = (function () { | ||
var self = {}; | ||
|
||
self.hello = function(name){ | ||
alert("Hello " + name) | ||
} | ||
self.hello = function (name) { | ||
alert("Hello " + name) | ||
} | ||
|
||
return self; | ||
}()); | ||
</script> | ||
return self; | ||
}()); | ||
</script> | ||
|
||
<h2> | ||
<button unicorn:click="call_javascript">Component view calls JavaScript</button> | ||
<button unicorn:click="call_javascript_module">Component view calls JavaScript module</button> | ||
</h2> | ||
|
||
<div> | ||
<h2> | ||
<button unicorn:click="call_javascript">Component view calls JavaScript</button> | ||
<button unicorn:click="call_javascript_module">Component view calls JavaScript module</button> | ||
<code>javascript_exclude states</code> | ||
</h2> | ||
{% for state in states %} | ||
{{ state }} | ||
{% endfor %} | ||
</div> | ||
|
||
<div> | ||
<h2> | ||
<code>javascript_exclude states</code> | ||
</h2> | ||
{% for state in states %} | ||
{{ state }} | ||
{% endfor %} | ||
</div> | ||
<h2>Select2</h2> | ||
|
||
<h2>Select2</h2> | ||
<div u:ignore> | ||
<select unicorn:model="selected_state" class="form-control" id="select2-example" required | ||
onchange="Unicorn.call('js', 'select_state', this.value, this.selectedIndex);"> | ||
{% for state in states %} | ||
<option value="{{ state }}">{{ state }}</option> | ||
{% endfor %} | ||
</select> | ||
|
||
<div u:ignore> | ||
<select unicorn:model="selected_state" class="form-control" id="select2-example" required onchange="Unicorn.call('js', 'select_state', this.value, this.selectedIndex);"> | ||
{% for state in states %} | ||
<option value="{{ state }}">{{ state }}</option> | ||
{% endfor %} | ||
</select> | ||
States (in ignored div): {{ states }} | ||
</div> | ||
|
||
States (in ignored div): {{ states }} | ||
</div> | ||
selected_state: {{ selected_state }} | ||
|
||
selected_state: {{ selected_state }} | ||
<script> | ||
$(document).ready(function () { | ||
$('#select2-example').select2(); | ||
}); | ||
</script> | ||
|
||
<script> | ||
$(document).ready(function() { | ||
$('#select2-example').select2(); | ||
}); | ||
</script> | ||
<div> | ||
States (not in ignored div): {{ states }}<br /> | ||
<button type="submit" u:click="change_states">Change states</button> | ||
</div> | ||
|
||
<div> | ||
<input type="text" u:model="select2_datetime" /> | ||
<button type="submit" u:click="get_now">Get now</button> | ||
<div> | ||
States (not in ignored div): {{ states }}<br /> | ||
<button type="submit" u:click="change_states">Change states</button> | ||
select2_datetime: {{ select2_datetime }} | ||
</div> | ||
</div> | ||
|
||
<div> | ||
<input type="text" u:model="select2_datetime" /> | ||
<button type="submit" u:click="get_now">Get now</button> | ||
<div> | ||
select2_datetime: {{ select2_datetime }} | ||
</div> | ||
</div> | ||
<div unicorn:key="visibility"> | ||
<span unicorn:visible.threshold-25.debounce-1000="increase_counter" unicorn:partial="visibility"> | ||
Number of times this span was scrolled into view: {{ scroll_counter }} | ||
</span> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import test from "ava"; | ||
import { getComponent, getElement } from "../utils.js"; | ||
|
||
test("visible", (t) => { | ||
const html = "<span unicorn:visible='test_function1'></span>"; | ||
const element = getElement(html); | ||
|
||
const { visibility } = element; | ||
t.is(visibility.method, "test_function1"); | ||
t.is(visibility.threshold, 0); | ||
t.is(visibility.debounceTime, 0); | ||
}); | ||
|
||
test("visible threshold", (t) => { | ||
const html = "<span unicorn:visible.threshold-25='test_function2'></span>"; | ||
const element = getElement(html); | ||
|
||
const { visibility } = element; | ||
t.is(visibility.method, "test_function2"); | ||
t.is(visibility.threshold, 0.25); | ||
t.is(visibility.debounceTime, 0); | ||
}); | ||
|
||
test("visible debounce", (t) => { | ||
const html = "<span unicorn:visible.debounce-1000='test_function3'></span>"; | ||
const element = getElement(html); | ||
|
||
const { visibility } = element; | ||
t.is(visibility.method, "test_function3"); | ||
t.is(visibility.threshold, 0); | ||
t.is(visibility.debounceTime, 1000); | ||
}); | ||
|
||
test("visible chained", (t) => { | ||
const html = | ||
"<span unicorn:visible.threshold-50.debounce-2000='test_function4'></span>"; | ||
const element = getElement(html); | ||
|
||
const { visibility } = element; | ||
t.is(visibility.method, "test_function4"); | ||
t.is(visibility.threshold, 0.5); | ||
t.is(visibility.debounceTime, 2000); | ||
}); |