scratch – Blame information for rev 134
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
134 | office | 1 | jQuery(function(){ |
2 | // Track downloads |
||
3 | $('#download-master').click(function(){ |
||
4 | _trackEvent('Downloads', 'master'); |
||
5 | }); |
||
6 | }); |
||
7 | |||
8 | jQuery(document).ready(function($) { |
||
9 | |||
10 | /* Docs scrollspy */ |
||
11 | $('body').scrollspy({ |
||
12 | target: '.bs-sidebar', |
||
13 | offset: 0 |
||
14 | }) |
||
15 | |||
16 | $(window).on('load', function () { |
||
17 | $('body').scrollspy('refresh') |
||
18 | }) |
||
19 | |||
20 | // back to top |
||
21 | setTimeout(function () { |
||
22 | var $sideBar = $('.bs-sidebar') |
||
23 | |||
24 | $sideBar.affix({ |
||
25 | offset: { |
||
26 | top: function () { |
||
27 | var offsetTop = $sideBar.offset().top |
||
28 | var sideBarMargin = parseInt($sideBar.children(0).css('margin-top'), 10) |
||
29 | |||
30 | return (this.top = offsetTop - sideBarMargin) |
||
31 | } |
||
32 | , bottom: function () { |
||
33 | return (this.bottom = $('.bs-footer').outerHeight(true)) |
||
34 | } |
||
35 | } |
||
36 | }) |
||
37 | }, 100) |
||
38 | |||
39 | /* Run examples */ |
||
40 | $('.token-example-field').tokenfield(); |
||
41 | |||
42 | $('#tokenfield-1').tokenfield({ |
||
43 | autocomplete: { |
||
44 | source: ['red','blue','green','yellow','violet','brown','purple','black','white'], |
||
45 | delay: 100 |
||
46 | }, |
||
47 | showAutocompleteOnFocus: true, |
||
48 | delimiter: [',',' ', '-', '_'] |
||
49 | }); |
||
50 | |||
51 | var engine = new Bloodhound({ |
||
52 | local: [{value: 'red'}, {value: 'blue'}, {value: 'green'} , {value: 'yellow'}, {value: 'violet'}, {value: 'brown'}, {value: 'purple'}, {value: 'black'}, {value: 'white'}], |
||
53 | datumTokenizer: function(d) { |
||
54 | return Bloodhound.tokenizers.whitespace(d.value); |
||
55 | }, |
||
56 | queryTokenizer: Bloodhound.tokenizers.whitespace |
||
57 | }); |
||
58 | engine.initialize(); |
||
59 | |||
60 | $('#tokenfield-typeahead').tokenfield({ |
||
61 | typeahead: [null, { source: engine.ttAdapter() }] |
||
62 | }); |
||
63 | |||
64 | $('#tokenfield-2') |
||
65 | .on('tokenfield:createtoken', function (e) { |
||
66 | var data = e.attrs.value.split('|') |
||
67 | e.attrs.value = data[1] || data[0] |
||
68 | e.attrs.label = data[1] ? data[0] + ' (' + data[1] + ')' : data[0] |
||
69 | }) |
||
70 | .on('tokenfield:createdtoken', function (e) { |
||
71 | // Über-simplistic e-mail validation |
||
72 | var re = /\S+@\S+\.\S+/ |
||
73 | var valid = re.test(e.attrs.value) |
||
74 | if (!valid) { |
||
75 | $(e.relatedTarget).addClass('invalid') |
||
76 | } |
||
77 | }) |
||
78 | .on('tokenfield:edittoken', function (e) { |
||
79 | if (e.attrs.label !== e.attrs.value) { |
||
80 | var label = e.attrs.label.split(' (') |
||
81 | e.attrs.value = label[0] + '|' + e.attrs.value |
||
82 | } |
||
83 | }) |
||
84 | .on('tokenfield:removedtoken', function (e) { |
||
85 | if (e.attrs.length > 1) { |
||
86 | var values = $.map(e.attrs, function (attrs) { return attrs.value }); |
||
87 | alert(e.attrs.length + ' tokens removed! Token values were: ' + values.join(', ')) |
||
88 | } else { |
||
89 | alert('Token removed! Token value was: ' + e.attrs.value) |
||
90 | } |
||
91 | }) |
||
92 | .tokenfield() |
||
93 | |||
94 | }); |