forked from Dogfalo/materialize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.js
258 lines (235 loc) · 7.4 KB
/
init.js
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
(function($) {
$(function() {
var window_width = $(window).width();
// convert rgb to hex value string
function rgb2hex(rgb) {
if (/^#[0-9A-F]{6}$/i.test(rgb)) {
return rgb;
}
rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
if (rgb === null) {
return 'N/A';
}
function hex(x) {
return ('0' + parseInt(x).toString(16)).slice(-2);
}
return '#' + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}
$('.dynamic-color .col').each(function() {
$(this)
.children()
.each(function() {
var color = $(this).css('background-color'),
classes = $(this).attr('class');
$(this).html('<span>' + rgb2hex(color) + ' ' + classes + '</span>');
if (classes.indexOf('darken') >= 0 || $(this).hasClass('black')) {
$(this).css('color', 'rgba(255,255,255,.9');
}
});
});
// Floating-Fixed table of contents
setTimeout(function() {
var tocWrapperHeight = 260; // Max height of ads.
var tocHeight = $('.toc-wrapper .table-of-contents').length
? $('.toc-wrapper .table-of-contents').height()
: 0;
var socialHeight = 95; // Height of unloaded social media in footer.
var footerOffset = $('body > footer').first().length
? $('body > footer')
.first()
.offset().top
: 0;
var bottomOffset = footerOffset - socialHeight - tocHeight - tocWrapperHeight;
if ($('nav').length) {
$('.toc-wrapper').pushpin({
top: $('nav').height(),
bottom: bottomOffset
});
} else if ($('#index-banner').length) {
$('.toc-wrapper').pushpin({
top: $('#index-banner').height(),
bottom: bottomOffset
});
} else {
$('.toc-wrapper').pushpin({
top: 0,
bottom: bottomOffset
});
}
}, 100);
// BuySellAds Detection
var $bsa = $('.buysellads'),
$timesToCheck = 3;
function checkForChanges() {
if (!$bsa.find('#carbonads').length) {
$timesToCheck -= 1;
if ($timesToCheck >= 0) {
setTimeout(checkForChanges, 500);
} else {
var donateAd = $(
'<div id="carbonads"><span><a class="carbon-text" href="#!" onclick="document.getElementById(\'paypal-donate\').submit();"><img src="images/donate.png" /> Help support us by turning off adblock. If you still prefer to keep adblock on for this page but still want to support us, feel free to donate. Any little bit helps.</a></form></span></div>'
);
$bsa.append(donateAd);
}
}
}
checkForChanges();
// BuySellAds Demos close button.
$('.buysellads.buysellads-demo .close').on('click', function() {
$(this)
.parent()
.remove();
});
// Github Latest Commit
if ($('.github-commit').length) {
// Checks if widget div exists (Index only)
$.ajax({
url: 'https://api.github.com/repos/dogfalo/materialize/commits/v1-dev',
dataType: 'json',
success: function(data) {
var sha = data.sha,
date = jQuery.timeago(data.commit.author.date);
if (window_width < 1120) {
sha = sha.substring(0, 7);
}
$('.github-commit')
.find('.date')
.html(date);
$('.github-commit')
.find('.sha')
.html(sha)
.attr('href', data.html_url);
}
});
}
// Toggle Flow Text
var toggleFlowTextButton = $('#flow-toggle');
toggleFlowTextButton.click(function() {
$('#flow-text-demo')
.children('p')
.each(function() {
$(this).toggleClass('flow-text');
});
});
// Toggle Containers on page
var toggleContainersButton = $('#container-toggle-button');
toggleContainersButton.click(function() {
$('body .browser-window .container, .had-container').each(function() {
$(this).toggleClass('had-container');
$(this).toggleClass('container');
if ($(this).hasClass('container')) {
toggleContainersButton.text('Turn off Containers');
} else {
toggleContainersButton.text('Turn on Containers');
}
});
});
// Detect touch screen and enable scrollbar if necessary
function is_touch_device() {
try {
document.createEvent('TouchEvent');
return true;
} catch (e) {
return false;
}
}
if (is_touch_device()) {
$('#nav-mobile').css({ overflow: 'auto' });
}
// Set checkbox on forms.html to indeterminate
var indeterminateCheckbox = document.getElementById('indeterminate-checkbox');
if (indeterminateCheckbox !== null) indeterminateCheckbox.indeterminate = true;
// Pushpin Demo Init
if ($('.pushpin-demo-nav').length) {
$('.pushpin-demo-nav').each(function() {
var $this = $(this);
var $target = $('#' + $(this).attr('data-target'));
$this.pushpin({
top: $target.offset().top,
bottom: $target.offset().top + $target.outerHeight() - $this.height()
});
});
}
// CSS Transitions Demo Init
if ($('#scale-demo').length && $('#scale-demo-trigger').length) {
$('#scale-demo-trigger').click(function() {
$('#scale-demo').toggleClass('scale-out');
});
}
// Plugin initialization
$('.carousel').carousel();
$('.carousel.carousel-slider').carousel({
fullWidth: true,
indicators: true,
onCycleTo: function(item, dragged) {}
});
$('.collapsible').collapsible();
$('.collapsible.expandable').collapsible({
accordion: false
});
$('.dropdown-trigger').dropdown();
$('.slider').slider();
$('.parallax').parallax();
$('.materialboxed').materialbox();
$('.modal').modal();
$('.scrollspy').scrollSpy();
$('.datepicker').datepicker();
$('.tabs').tabs();
$('.timepicker').timepicker();
$('.tooltipped').tooltip();
$('select')
.not('.disabled')
.formSelect();
$('.sidenav').sidenav();
$('.tap-target').tapTarget();
$('input.autocomplete').autocomplete({
data: { Apple: null, Microsoft: null, Google: 'http://placehold.it/250x250' }
});
$('input[data-length], textarea[data-length]').characterCounter();
// Swipeable Tabs Demo Init
if ($('#tabs-swipe-demo').length) {
$('#tabs-swipe-demo').tabs({ swipeable: true });
}
// Chips
$('.chips').chips();
$('.chips-initial').chips({
readOnly: true,
data: [
{
tag: 'Apple'
},
{
tag: 'Microsoft'
},
{
tag: 'Google'
}
]
});
$('.chips-placeholder').chips({
placeholder: 'Enter a tag',
secondaryPlaceholder: '+Tag'
});
$('.chips-autocomplete').chips({
autocompleteOptions: {
data: {
Apple: null,
Microsoft: null,
Google: null
}
}
});
// Fab
$('.fixed-action-btn').floatingActionButton();
$('.fixed-action-btn.horizontal').floatingActionButton({
direction: 'left'
});
$('.fixed-action-btn.click-to-toggle').floatingActionButton({
direction: 'left',
hoverEnabled: false
});
$('.fixed-action-btn.toolbar').floatingActionButton({
toolbarEnabled: true
});
}); // end of document ready
})(jQuery); // end of jQuery name space