demo.js
3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* ===========================================================
*
* Name: global.js
* Updated: 2014-04-15
* What?: Random crap for the Select or Die demo
*
* Beards, Rock & Loud Guns | Cogs 'n Kegs
* =========================================================== */
function random_word() {
var $words = ['Frightened', 'By', 'Your', 'Own', 'Smell', 'Bitterness', 'Will', 'Run', 'You', 'Through']; // In FLames - Bullet Ride (http://www.youtube.com/watch?v=lDwqzGtjGMU)
var $randomizer = $words[Math.floor(Math.random() * $words.length)];
return $randomizer;
}
jQuery(document).ready(function ($) {
$(".basic").selectOrDie();
$(".well_hello_there").selectOrDie({
onChange: function() {
var $target = $(this).val(),
$position = $($target).position().top - 40 + "px";
$("html, body").animate({scrollTop: $position}, 500);
}
});
$(".callback").selectOrDie({
onChange: function() {
alert($(this).val());
}
});
$(".trigger").click(function(){
var $method = $(this).data("method").replace(/'/g, '"'),
$subMethod = $(this).data("sub-method"),
$parent = $(this).closest("section"),
$parentID = $parent.prop("id"),
$parentSelect = $parent.find("select"),
$preMethod;
if( $method === "update" ) {
var $randomWord = random_word();
$("#" + $parentID + " select").append('<option value="' + $randomWord + '" selected="selected">' + $randomWord + '</option>');
$("#" + $parentID + " select").selectOrDie($method);
$("#" + $parentID + " pre").html('$("select").append("<option value=\\"' + $randomWord + '\\">' + $randomWord + '</option>");\n$("select").selectOrDie("update");').show();
} else if ( $method === "destroy" && !$parentSelect.is(":hidden") ) {
$("#" + $parentID + " pre").html("$(\"select\").selectOrDie();").show();
$("#" + $parentID + " select").selectOrDie();
} else {
if ( $subMethod === "group" ) {
$("#" + $parentID + " select").selectOrDie($method, 'Option Group Label');
$preMethod = $method + "\", \"Option Group Label";
} else if ( $subMethod === "option" ) {
$("#" + $parentID + " select").selectOrDie($method, 'three');
$preMethod = $method + "\", \"three";
} else {
$("#" + $parentID + " select").selectOrDie($method);
$preMethod = $method;
}
$("#" + $parentID + " pre").html("$(\"select\").selectOrDie(\"" + $preMethod + "\");").show();
if ( $method === "disable" ) {
$(this).data("method", "enable");
} else if ( $method === "enable" ) {
$(this).data("method", "disable");
}
}
$("span", this).toggle();
$("#" + $parentID + " pre").litelighter('enable');
});
/* - - - */
$("a:not(.external)").click(function(){
var $target = $(this).attr("href"),
$position = $($target).position().top - 40 + "px";
$("html, body").animate({scrollTop: $position}, 500);
});
$("pre").litelighter({
style: 'light',
language: 'js'
});
});