1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Provides frequently used functions that load something, ususally CSS or JS
|
6
|
* files, or that provide assistance to those loaders.
|
7
|
*/
|
8
|
|
9
|
/**
|
10
|
* Set messages if files are not found
|
11
|
*
|
12
|
* Adaptivetheme makes heavy use of generated CSS files, if one or more are not
|
13
|
* found we set a message warning the user, and dump an error in watchdog.
|
14
|
*
|
15
|
* @param $filepath, path to the missing file.
|
16
|
* @param $theme_name, the active theme.
|
17
|
*/
|
18
|
function at_load_failure($filepath, $theme_name) {
|
19
|
$message = t('<p>One or more CSS files were not found or does not exist: <em>!files_list</em>. Did you delete any files or change a file name? You may need to save the theme settings or check all files names are correct in your theme. Please view the <a href="!docs_link" target="_blank">online documentation</a>.</p>', array('!files_list' => $filepath, '!docs_link' => 'http://adaptivethemes.com/documentation/file-generation-system'));
|
20
|
|
21
|
if (!empty($filepath)) {
|
22
|
watchdog($theme_name, 'CSS file missing or not found @filename', array('@filename' => $filepath), WATCHDOG_ERROR);
|
23
|
if (user_is_logged_in()) {
|
24
|
drupal_set_message($message, 'warning');
|
25
|
}
|
26
|
}
|
27
|
}
|
28
|
|
29
|
/**
|
30
|
* Conditionally load stylesheets to set the layout.
|
31
|
*
|
32
|
* Each time you save the theme settings AT builds 3 layout stylesheets:
|
33
|
* 1. themeName.default.layout.css
|
34
|
* 2. themeName.responsive.layout.css
|
35
|
* 3. themeName.lt-ie9.layout.css
|
36
|
*
|
37
|
* Now we need to load them, but only under certain conditions:
|
38
|
* a. Is the default layout the standard layout?
|
39
|
* b. Is the responsive capability disabled?
|
40
|
*
|
41
|
* If either a or b equate to TRUE, then we are NOT doing mobile first.
|
42
|
* If a is FALSE then this is mobile first.
|
43
|
* If b is FALSE then we are doing responsive design.
|
44
|
*
|
45
|
* @param $path
|
46
|
* @param $theme_name
|
47
|
*/
|
48
|
function at_load_layout_css($path, $theme_name) {
|
49
|
|
50
|
// Get the info file data
|
51
|
$info = at_get_info($theme_name);
|
52
|
|
53
|
// Set a boolean to test which IE stylesheet to load.
|
54
|
$load_ie8_css = TRUE;
|
55
|
|
56
|
// Load the default layout if Standard layout is default or responsive styles are disabled
|
57
|
if (at_get_setting('global_default_layout', $theme_name) === 'standard-layout' || at_get_setting('disable_responsive_styles', $theme_name) === 1) {
|
58
|
$file = $theme_name . '.default.layout.css';
|
59
|
$filepath = $path . '/' . $file;
|
60
|
if (file_exists($filepath)) {
|
61
|
drupal_add_css($filepath, array(
|
62
|
'preprocess' => TRUE,
|
63
|
'group' => CSS_THEME,
|
64
|
'media' => 'screen',
|
65
|
'every_page' => TRUE,
|
66
|
)
|
67
|
);
|
68
|
}
|
69
|
else {
|
70
|
at_load_failure($filepath, $theme_name);
|
71
|
}
|
72
|
}
|
73
|
|
74
|
// Next - check if we need to load the responsive layout
|
75
|
if (at_get_setting('disable_responsive_styles', $theme_name) === 0) {
|
76
|
|
77
|
// Responsiveness is not disabled, load the responsive layout
|
78
|
$filepath = $path . '/' . $theme_name . '.responsive.layout.css';
|
79
|
$media_query = 'only screen'; // keyword "only" hide this from unsupporting user agents
|
80
|
at_load_subtheme_responsive_styles($filepath, $media_query, $theme_name, $weight = 0);
|
81
|
|
82
|
// The lt-ie9.layout.css stylesheet loads under specific conditions:
|
83
|
// 1. Responsive capabilities are ON
|
84
|
// 2. Mobile first is ON
|
85
|
// 3. Respond.js is OFF
|
86
|
if (at_get_setting('global_default_layout', $theme_name) !== 'standard-layout') {
|
87
|
if (at_get_setting('load_respondjs', $theme_name) === 0) {
|
88
|
$load_ie8_css = FALSE;
|
89
|
$filepath = $path . '/' . $theme_name . '.lt-ie9.layout.css';
|
90
|
$ie_style['media'] = 'screen';
|
91
|
$ie_style['condition'] = 'lt IE 9';
|
92
|
at_load_conditional_styles($filepath, $ie_style, $theme_name);
|
93
|
}
|
94
|
}
|
95
|
}
|
96
|
|
97
|
// The lt-ie8.layout.css file loads under the exact opposite conditions to the
|
98
|
// lt-ie9 file. In other words, when lt-ie9 is loading, this is not, when it
|
99
|
// isn't, this loads. This file only ever holds panels layout overrides for
|
100
|
// legacy IE browsers and is disabled by default in theme settings.
|
101
|
if ($load_ie8_css == TRUE) {
|
102
|
if (at_get_setting('load_ltie8css', $theme_name) === 1) {
|
103
|
$filepath = $path . '/' . $theme_name . '.lt-ie8.layout.css';
|
104
|
$ie_style['media'] = 'screen';
|
105
|
$ie_style['condition'] = 'lt IE 8';
|
106
|
at_load_conditional_styles($filepath, $ie_style, $theme_name);
|
107
|
}
|
108
|
}
|
109
|
}
|
110
|
|
111
|
/**
|
112
|
* Load Responsive Styles.
|
113
|
*
|
114
|
* AT has two modes - Production and Development. Depending on the mode it
|
115
|
* will load different files. Production mode assume you have finished CSS
|
116
|
* development and will not need to update styles in the responsive
|
117
|
* stylesheets, if you do you will need to re-save the theme settings at
|
118
|
* least once to re-write your $theme_name.responsive.styles.css file which
|
119
|
* is in public files.
|
120
|
*
|
121
|
* @param $path
|
122
|
* @param $theme_name
|
123
|
*/
|
124
|
function at_load_responsive_css($path, $theme_name) {
|
125
|
|
126
|
// Set the mode, when CSS is aggregated by Drupal Production mode is TRUE
|
127
|
$mode = variable_get('preprocess_css', '') == 1 ? TRUE : FALSE;
|
128
|
|
129
|
// Development Mode
|
130
|
// These files are for "design style" only, the layout is handled
|
131
|
// seperately.
|
132
|
//
|
133
|
// We only load these files if:
|
134
|
// - 1: We're not in production mode
|
135
|
// - 2: Responsiveness is not disabled
|
136
|
//
|
137
|
// When in production mode these files are aggregated into one file
|
138
|
// and loaded using at_load_subtheme_responsive_styles().
|
139
|
//
|
140
|
// You can disable responsive capability using the theme settings - look under
|
141
|
// the Global settings. Do not delete or alter this - use the theme setting!
|
142
|
if ($mode == FALSE) {
|
143
|
|
144
|
// Build a keyed array of CSS file-names as key, and media query as value.
|
145
|
// The file names must match the files in your themes CSS directory, if
|
146
|
// you change them you must update to match.
|
147
|
$files = array(
|
148
|
// Maintian backwards compatibility with older themes that use smartphone
|
149
|
'responsive.smartphone.portrait' => at_get_setting('smalltouch_portrait_media_query', $theme_name) ? at_get_setting('smalltouch_portrait_media_query', $theme_name) : at_get_setting('smartphone_portrait_media_query', $theme_name),
|
150
|
'responsive.smartphone.landscape' => at_get_setting('smalltouch_landscape_media_query', $theme_name) ? at_get_setting('smalltouch_landscape_media_query', $theme_name) : at_get_setting('smartphone_landscape_media_query', $theme_name),
|
151
|
// Standard files for the 7.x-3.2 and beyond
|
152
|
'responsive.smalltouch.portrait' => at_get_setting('smalltouch_portrait_media_query', $theme_name),
|
153
|
'responsive.smalltouch.landscape' => at_get_setting('smalltouch_landscape_media_query', $theme_name),
|
154
|
'responsive.tablet.portrait' => at_get_setting('tablet_portrait_media_query', $theme_name),
|
155
|
'responsive.tablet.landscape' => at_get_setting('tablet_landscape_media_query', $theme_name),
|
156
|
'responsive.desktop' => at_get_setting('bigscreen_media_query', $theme_name),
|
157
|
);
|
158
|
|
159
|
// Add the custom responsive stylesheet if enabled
|
160
|
if (at_get_setting('enable_custom_media_queries', $theme_name) === 1) {
|
161
|
$item = array('responsive.custom' => 'only screen');
|
162
|
$files = array_merge($item, $files);
|
163
|
}
|
164
|
|
165
|
// Loop over the files array and load each CSS file.
|
166
|
// at_load_subtheme_responsive_styles() takes three parameters:
|
167
|
// - $css_file - the name of the css file
|
168
|
// - $media_query - the media query from theme settings
|
169
|
// - $theme_name - to generate the path-to-theme for drupal_add_css()
|
170
|
foreach ($files as $key => $value) {
|
171
|
$filepath = drupal_get_path('theme', $theme_name) . '/css/' . $key . '.css';
|
172
|
$media_query = $value;
|
173
|
at_load_subtheme_responsive_styles($filepath, $media_query, $theme_name, $weight = 100);
|
174
|
}
|
175
|
}
|
176
|
|
177
|
// Production Mode
|
178
|
// In Production mode we only load one file for our design styles.
|
179
|
// We use a media query to prevent non media query browsers from downloading it.
|
180
|
// The embedded media queries in this file take precedence always.
|
181
|
elseif ($mode == TRUE) {
|
182
|
$filepath = $path . '/' . $theme_name . '.responsive.styles.css';
|
183
|
$media_query = 'only screen'; // keyword "only" should hide this from older user agents
|
184
|
at_load_subtheme_responsive_styles($filepath, $media_query, $theme_name, $weight = 100);
|
185
|
}
|
186
|
}
|
187
|
|
188
|
/**
|
189
|
* Load Extension Settings CSS.
|
190
|
*
|
191
|
* @param $theme_name
|
192
|
*/
|
193
|
function at_load_extensions_css($theme_name) {
|
194
|
global $path_to_at_core;
|
195
|
$settings_css = array();
|
196
|
// Heading settings
|
197
|
if (at_get_setting('enable_heading_settings', $theme_name) === 1) {
|
198
|
$settings_css[] = 'at.settings.style.headings.css';
|
199
|
}
|
200
|
// Image alignment settings
|
201
|
if (at_get_setting('enable_image_settings', $theme_name) === 1) {
|
202
|
$settings_css[] = 'at.settings.style.image.css';
|
203
|
}
|
204
|
// Float block settings
|
205
|
if (at_get_setting('enable_float_region_blocks', $theme_name) === 1) {
|
206
|
$settings_css[] = 'at.settings.style.floatblocks.css';
|
207
|
}
|
208
|
// Login block settings
|
209
|
if (at_get_setting('horizontal_login_block_enable', $theme_name) === 'on') {
|
210
|
if (at_get_setting('horizontal_login_block', $theme_name) === 1) {
|
211
|
$settings_css[] = 'at.settings.style.login.css';
|
212
|
}
|
213
|
}
|
214
|
if (!empty($settings_css)) {
|
215
|
foreach ($settings_css as $css_file) {
|
216
|
$filepath = $path_to_at_core . '/css/' . $css_file;
|
217
|
drupal_add_css($filepath, array(
|
218
|
'preprocess' => TRUE,
|
219
|
'group' => CSS_THEME,
|
220
|
'media' => 'screen',
|
221
|
'every_page' => TRUE,
|
222
|
'weight' => -100,
|
223
|
)
|
224
|
);
|
225
|
}
|
226
|
}
|
227
|
else {
|
228
|
$settings_css = NULL;
|
229
|
}
|
230
|
}
|
231
|
|
232
|
/**
|
233
|
* Load Fonts
|
234
|
*
|
235
|
* @param $path
|
236
|
* @param $theme_name
|
237
|
*/
|
238
|
function at_load_fonts($path, $theme_name) {
|
239
|
// Google fonts
|
240
|
$google_font_string = &drupal_static(__FUNCTION__, array());
|
241
|
if (empty($google_font_string)) {
|
242
|
$google_font_string = at_load_google_fonts($theme_name);
|
243
|
}
|
244
|
if (!empty($google_font_string)) {
|
245
|
drupal_add_css($google_font_string, array(
|
246
|
'group' => CSS_THEME,
|
247
|
'type' => 'external',
|
248
|
'weight' => -100,
|
249
|
)
|
250
|
);
|
251
|
}
|
252
|
// Load the fonts CSS from public files
|
253
|
$filepath = $path . '/' . $theme_name . '.fonts.css';
|
254
|
if (file_exists($filepath)) {
|
255
|
drupal_add_css($filepath, array(
|
256
|
'preprocess' => TRUE,
|
257
|
'group' => CSS_THEME,
|
258
|
'media' => 'screen',
|
259
|
'every_page' => TRUE,
|
260
|
)
|
261
|
);
|
262
|
}
|
263
|
else {
|
264
|
at_load_failure($filepath, $theme_name);
|
265
|
}
|
266
|
}
|
267
|
|
268
|
/**
|
269
|
* Load custom css file.
|
270
|
*
|
271
|
* @param $path
|
272
|
* @param $theme_name
|
273
|
*/
|
274
|
function at_load_custom_css($path, $theme_name) {
|
275
|
$filepath = $path . '/' . $theme_name . '.custom.css';
|
276
|
if (file_exists($filepath)) {
|
277
|
drupal_add_css($filepath, array(
|
278
|
'preprocess' => TRUE,
|
279
|
'group' => CSS_THEME,
|
280
|
'weight' => 1000,
|
281
|
'media' => 'screen',
|
282
|
'every_page' => TRUE,
|
283
|
)
|
284
|
);
|
285
|
}
|
286
|
else {
|
287
|
at_load_failure($filepath, $theme_name);
|
288
|
}
|
289
|
}
|
290
|
|
291
|
/**
|
292
|
* Load Polyfill Scripts
|
293
|
* Conditional scripts are returned to the preprocess function - in AT Core that
|
294
|
* means adaptivetheme_preprocess_html() and adaptivetheme_preprocess_maintenance_page().
|
295
|
* There are two sources for conditional scripts - the subtheme info file and
|
296
|
* AT Core itself can load html5.js and respond.js.
|
297
|
* Unconditional scripts (those not printed within an IE conditioanl comment)
|
298
|
* load directly via drupal_add_js in this function, while the conditional scripts
|
299
|
* are returned as an array to preprocess, then rendered in process. This is done
|
300
|
* to allow themers to manipulate the data structure in preprocess if they feel
|
301
|
* the need to.
|
302
|
*
|
303
|
* @param $theme_name
|
304
|
*/
|
305
|
function at_load_polyfills($theme_name) {
|
306
|
global $path_to_at_core;
|
307
|
|
308
|
// Get the info file data
|
309
|
$info = at_get_info($theme_name);
|
310
|
|
311
|
// Build an array of polyfilling scripts
|
312
|
$polyfills = &drupal_static('adaptivetheme_preprocess_html_polyfills_array');
|
313
|
if (empty($polyfills)) {
|
314
|
|
315
|
$theme_path = drupal_get_path('theme', $theme_name);
|
316
|
$polyfills_array = array();
|
317
|
|
318
|
// Info file loaded conditional scripts
|
319
|
if (array_key_exists('ie_scripts', $info)) {
|
320
|
foreach ($info['ie_scripts'] as $condition => $ie_scripts_path) {
|
321
|
foreach ($ie_scripts_path as $key => $value) {
|
322
|
$filepath = $theme_path . '/' . $value;
|
323
|
$polyfills_array['ie'][$condition][] = at_theme_conditional_script($filepath);
|
324
|
}
|
325
|
}
|
326
|
}
|
327
|
|
328
|
// AT Core Conditional Scripts
|
329
|
if (at_get_setting('load_html5js') === 1) {
|
330
|
$polyfills_array['ie']['lt IE 9'][] = at_theme_conditional_script($path_to_at_core . '/scripts/html5.js');
|
331
|
}
|
332
|
if (at_get_setting('load_respondjs') === 1) {
|
333
|
$polyfills_array['ie']['lt IE 9'][] = at_theme_conditional_script($path_to_at_core . '/scripts/respond.js');
|
334
|
}
|
335
|
|
336
|
// AT Core Un-conditional Scripts
|
337
|
if (at_get_setting('load_scalefixjs') === 1) {
|
338
|
$polyfills_array['all'][] = 'scripts/scalefix.js';
|
339
|
}
|
340
|
if (at_get_setting('load_onmediaqueryjs') === 1) {
|
341
|
$polyfills_array['all'][] = 'scripts/onmediaquery.js';
|
342
|
}
|
343
|
if (at_get_setting('load_matchmediajs') === 1) {
|
344
|
$polyfills_array['all'][] = 'scripts/matchMedia.js';
|
345
|
$polyfills_array['all'][] = 'scripts/matchMedia.addListener.js';
|
346
|
}
|
347
|
|
348
|
// Load Polyfills
|
349
|
if (!empty($polyfills_array)) {
|
350
|
|
351
|
// Default query string for cache control finger printing
|
352
|
$query_string = variable_get('css_js_query_string', '0');
|
353
|
|
354
|
// "all" - no conditional comment needed, use drupal_add_js()
|
355
|
if (isset($polyfills_array['all'])) {
|
356
|
foreach ($polyfills_array['all'] as $script) {
|
357
|
drupal_add_js($path_to_at_core . '/' . $script, array(
|
358
|
'type' => 'file',
|
359
|
'scope' => 'header',
|
360
|
'group' => JS_THEME,
|
361
|
'preprocess' => TRUE,
|
362
|
'cache' => TRUE,
|
363
|
)
|
364
|
);
|
365
|
}
|
366
|
}
|
367
|
|
368
|
// IE conditional scripts, we need some semblance of structered data...
|
369
|
if (isset($polyfills_array['ie'])) {
|
370
|
$polyfills = array();
|
371
|
foreach ($polyfills_array['ie'] as $conditional_comment => $scripts) {
|
372
|
$ie_script = array(
|
373
|
'#type' => 'markup',
|
374
|
'#markup' => implode("\n", $scripts),
|
375
|
'#prefix' => "<!--[if " . $conditional_comment . "]>\n",
|
376
|
'#suffix' => "\n<![endif]-->\n",
|
377
|
);
|
378
|
$polyfills[$conditional_comment] = $ie_script;
|
379
|
}
|
380
|
}
|
381
|
}
|
382
|
else {
|
383
|
$polyfills = '';
|
384
|
}
|
385
|
}
|
386
|
|
387
|
return $polyfills;
|
388
|
}
|
389
|
|
390
|
|
391
|
/**
|
392
|
* Load debugging helper files.
|
393
|
*
|
394
|
* @param $theme_name
|
395
|
*/
|
396
|
function at_load_debuggers($theme_name) {
|
397
|
global $path_to_at_core;
|
398
|
|
399
|
// Do some debugging/development stuff
|
400
|
if (at_get_setting('expose_regions', $theme_name) === 1) {
|
401
|
drupal_add_css($path_to_at_core . '/css/debug-regions.css');
|
402
|
}
|
403
|
|
404
|
if (at_get_setting('load_all_panels', $theme_name) === 1) {
|
405
|
drupal_add_css($path_to_at_core . '/css/debug-panels.css', array(
|
406
|
'preprocess' => FALSE,
|
407
|
'group' => CSS_THEME,
|
408
|
'media' => 'screen',
|
409
|
'every_page' => FALSE,
|
410
|
'weight' => 2000,
|
411
|
)
|
412
|
);
|
413
|
}
|
414
|
|
415
|
// Load window size bookmarklet
|
416
|
if (at_get_setting('show_window_size', $theme_name) === 1) {
|
417
|
drupal_add_js($path_to_at_core . '/scripts/window-size.js', array(
|
418
|
'type' => 'file',
|
419
|
'scope' => 'footer',
|
420
|
'group' => JS_THEME,
|
421
|
'preprocess' => TRUE,
|
422
|
'cache' => TRUE,
|
423
|
)
|
424
|
);
|
425
|
drupal_add_css($path_to_at_core . '/css/debug-windowsize.css', array(
|
426
|
'preprocess' => FALSE,
|
427
|
'group' => CSS_THEME,
|
428
|
'media' => 'screen',
|
429
|
'every_page' => FALSE,
|
430
|
'weight' => 2000,
|
431
|
)
|
432
|
);
|
433
|
}
|
434
|
}
|
435
|
|
436
|
/**
|
437
|
* Load Sub-theme Responsive Stylesheets.
|
438
|
* Wrapper function for drupal_add_css() that takes advantage of Drupals's
|
439
|
* CSS aggregation logic to trick Drupal into always loading responsive
|
440
|
* stylesheets in link elements.
|
441
|
*
|
442
|
* This is almost always called from adaptivetheme_preprocess_html(), only in
|
443
|
* a rare instance might this be called from a sub-theme (to load additional
|
444
|
* responsive stylesheets).
|
445
|
*
|
446
|
* @param $filepath, path to the CSS file.
|
447
|
* @param $media_query, the media query from theme settings.
|
448
|
* @param $theme_name, the active theme.
|
449
|
* @param $weight, optional.
|
450
|
*/
|
451
|
function at_load_subtheme_responsive_styles($filepath, $media_query, $theme_name, $weight = 0) {
|
452
|
if (file_exists($filepath)) {
|
453
|
drupal_add_css($filepath, array(
|
454
|
'preprocess' => variable_get('preprocess_css', '') == 1 ? TRUE : FALSE,
|
455
|
'group' => CSS_THEME,
|
456
|
'media' => $media_query,
|
457
|
'every_page' => TRUE,
|
458
|
'weight' => $weight,
|
459
|
)
|
460
|
);
|
461
|
}
|
462
|
}
|
463
|
|
464
|
/**
|
465
|
* Build arrays of conditional styles to load
|
466
|
* Sub-themes can declare conditional stylesheets in the info file, we need to
|
467
|
* get this info file data and process it.
|
468
|
*
|
469
|
* @param $theme_name, the active theme.
|
470
|
*/
|
471
|
function at_load_subtheme_conditional_styles($theme_name) {
|
472
|
$info = &drupal_static(__FUNCTION__, array());
|
473
|
if (empty($info)) {
|
474
|
// Get the info file data
|
475
|
$info = at_get_info($theme_name);
|
476
|
|
477
|
// General IE stylesheets from the info file
|
478
|
if (array_key_exists('ie_stylesheets', $info)) {
|
479
|
$ie_style = '';
|
480
|
foreach ($info['ie_stylesheets'] as $media => $stylesheets) {
|
481
|
// Set default value for media in case the themer forgets, all is an
|
482
|
// "assumed" value and not printed in the output.
|
483
|
if (is_numeric($media)) {
|
484
|
$media = 'all';
|
485
|
}
|
486
|
foreach ($stylesheets as $condition => $file) {
|
487
|
foreach($file as $ie_styles_path) {
|
488
|
$ie_style['media'] = $media;
|
489
|
$ie_style['condition'] = $condition;
|
490
|
$ie_style['path'] = $ie_styles_path;
|
491
|
$filepath = drupal_get_path('theme', $theme_name) . '/' . $ie_style['path'];
|
492
|
at_load_conditional_styles($filepath, $ie_style, $theme_name);
|
493
|
}
|
494
|
}
|
495
|
}
|
496
|
}
|
497
|
}
|
498
|
}
|
499
|
|
500
|
/**
|
501
|
* Load Sub-theme IE Stylesheets.
|
502
|
* Wrapper function for drupal_add_css() that makes use the 'browser' option
|
503
|
* to load stylesheets for Internet Explorer.
|
504
|
*
|
505
|
* @param $filepath, path to the file.
|
506
|
* @param $ie_style, an arry containing the media attribute value and the IE
|
507
|
* conditional comment.
|
508
|
* @param $theme_name, the active theme.
|
509
|
* @param $weight, optional.
|
510
|
*/
|
511
|
function at_load_conditional_styles($filepath, $ie_style, $theme_name, $weight = 0) {
|
512
|
if (file_exists($filepath)) {
|
513
|
drupal_add_css($filepath, array(
|
514
|
'group' => CSS_THEME,
|
515
|
'browsers' => array(
|
516
|
'IE' => $ie_style['condition'],
|
517
|
'!IE' => FALSE,
|
518
|
),
|
519
|
'media' => $ie_style['media'],
|
520
|
'preprocess' => TRUE,
|
521
|
'weight' => $weight,
|
522
|
)
|
523
|
);
|
524
|
}
|
525
|
else {
|
526
|
at_load_failure($filepath, $theme_name);
|
527
|
}
|
528
|
}
|
529
|
|
530
|
/**
|
531
|
* Load scripts from the sub-theme
|
532
|
* Wrapper function for drupal_add_js(). In the core theme this is only used to
|
533
|
* load media_queries.js if the Responsive JavaScript plugin is enabled in theme
|
534
|
* settings. You can call this in your subtheme.
|
535
|
*
|
536
|
* @param $filepath, path to the file.
|
537
|
* @param $theme_name, the active theme.
|
538
|
* @param $scope, header or footer.
|
539
|
* @param $weight, optional.
|
540
|
*/
|
541
|
function at_load_subtheme_script($filepath, $theme_name, $scope, $weight = NULL) {
|
542
|
$filepath = drupal_get_path('theme', $theme_name) . '/' . $filepath;
|
543
|
if (file_exists($filepath)) {
|
544
|
drupal_add_js($filepath, array(
|
545
|
'type' => 'file',
|
546
|
'scope' => $scope,
|
547
|
'group' => JS_THEME,
|
548
|
'weight' => $weight,
|
549
|
'preprocess' => TRUE,
|
550
|
'cache' => TRUE,
|
551
|
)
|
552
|
);
|
553
|
}
|
554
|
}
|
555
|
|
556
|
/**
|
557
|
* Return a themed script.
|
558
|
* Since Drupal 7 does not (yet) support the 'browser' option in drupal_add_js()
|
559
|
* Adaptivetheme provides a way to load scripts inside conditional comments.
|
560
|
* This function wraps a file in script elements and returns a string.
|
561
|
*
|
562
|
* @param $filepath, path to the file.
|
563
|
*/
|
564
|
function at_theme_conditional_script($filepath) {
|
565
|
$script = '';
|
566
|
|
567
|
// We need the default query string for cache control finger printing
|
568
|
$query_string = variable_get('css_js_query_string', '0');
|
569
|
|
570
|
if (file_exists($filepath)) {
|
571
|
$file = file_create_url($filepath);
|
572
|
$script = '<script src="' . $file . '?' . $query_string . '"></script>';
|
573
|
}
|
574
|
|
575
|
return $script;
|
576
|
}
|
577
|
|
578
|
/**
|
579
|
* Google Font loader.
|
580
|
* Adaptivetheme can load websafe fonts, Google fonts, custom font stacks and
|
581
|
* integrate with @font-your-face module. All can be configured in the "Fonts"
|
582
|
* theme settings. Here we only need to load Google webfonts. Websafe and custom
|
583
|
* fonts are stored in a generated CSS file (in public files) and
|
584
|
* @font-your-face module takes care of loading its own fonts.
|
585
|
*
|
586
|
* @param $theme_name
|
587
|
*/
|
588
|
function at_load_google_fonts($theme_name) {
|
589
|
$google_font_string = &drupal_static(__FUNCTION__, array());
|
590
|
if (empty($google_font_string)) {
|
591
|
|
592
|
$used_fonts = array();
|
593
|
$font_elements = font_elements();
|
594
|
$charsets = google_font_charsets();
|
595
|
$styles = google_font_styles();
|
596
|
$used_styles = array();
|
597
|
$used_charsets = array();
|
598
|
|
599
|
foreach ($font_elements as $key => $value) {
|
600
|
$setting = $value['setting'];
|
601
|
if (at_get_setting($setting . '_type', $theme_name) === 'gwf') {
|
602
|
$used_settings[] = $setting . '_gwf';
|
603
|
$font_name = at_get_setting($setting . '_gwf', $theme_name);
|
604
|
$used_font = str_replace(' ', '+', $font_name);
|
605
|
$used_fonts[] = $used_font;
|
606
|
}
|
607
|
}
|
608
|
if (!empty($used_fonts)) {
|
609
|
$used_fonts = array_unique($used_fonts);
|
610
|
$google_fonts = implode('%7C', $used_fonts);
|
611
|
foreach ($used_settings as $used_setting) {
|
612
|
// Styles
|
613
|
if (at_get_setting($used_setting . '_add_styles', $theme_name) === 1) {
|
614
|
foreach ($styles as $styles_key => $styles_value) {
|
615
|
if (at_get_setting($used_setting . '_add_styles_' . $styles_key, $theme_name)) {
|
616
|
$used_styles[] = $styles_key;
|
617
|
}
|
618
|
}
|
619
|
}
|
620
|
// Charsets
|
621
|
if (at_get_setting($used_setting . '_add_charsets', $theme_name) === 1) {
|
622
|
foreach ($charsets as $charset_key => $charset_value) {
|
623
|
if (at_get_setting($used_setting . '_add_charsets_' . $charset_key, $theme_name)) {
|
624
|
$used_charsets[] = $charset_key;
|
625
|
}
|
626
|
}
|
627
|
}
|
628
|
}
|
629
|
if (!empty($used_styles)) {
|
630
|
$styles_array = array_unique($used_styles);
|
631
|
$google_styles = ':' . implode(',', $styles_array);
|
632
|
}
|
633
|
else {
|
634
|
$google_styles = '';
|
635
|
}
|
636
|
if (!empty($used_charsets)) {
|
637
|
$charset_array = array_unique($used_charsets);
|
638
|
$google_charsets = '&subset=' . implode(',', $charset_array);
|
639
|
}
|
640
|
else {
|
641
|
$google_charsets = '';
|
642
|
}
|
643
|
|
644
|
// Build the final string
|
645
|
$google_font_string = '//fonts.googleapis.com/css?family=' . $google_fonts . $google_styles . $google_charsets;
|
646
|
}
|
647
|
}
|
648
|
|
649
|
return $google_font_string;
|
650
|
}
|
651
|
|
652
|
/**
|
653
|
* Add js settings for the layout type and media query
|
654
|
*/
|
655
|
function at_load_layout_js_settings($theme_name) {
|
656
|
$breakpoints = array(
|
657
|
'bigscreen',
|
658
|
'tablet_landscape',
|
659
|
'tablet_portrait',
|
660
|
'smalltouch_landscape',
|
661
|
'smalltouch_portrait',
|
662
|
);
|
663
|
$cfg = array();
|
664
|
foreach ($breakpoints as $breakpoint) {
|
665
|
$layout = at_get_setting($breakpoint . '_layout', $theme_name);
|
666
|
$media_query = at_get_setting($breakpoint . '_media_query', $theme_name);
|
667
|
if ($layout) {
|
668
|
$layout = str_replace('_', '-', $layout);
|
669
|
$cfg[$theme_name]['layout_settings'][$breakpoint] = $layout;
|
670
|
}
|
671
|
if ($media_query) {
|
672
|
check_plain($media_query);
|
673
|
$cfg[$theme_name]['media_query_settings'][$breakpoint] = $media_query;
|
674
|
}
|
675
|
}
|
676
|
drupal_add_js(array('adaptivetheme' => $cfg), 'setting');
|
677
|
}
|
678
|
|
679
|
/**
|
680
|
* Return JS and CSS for the Menu Toggle for mobile.
|
681
|
*/
|
682
|
function at_load_menu_toggle($path, $theme_name) {
|
683
|
// Add JS settings for each enabled option (breakpoint)
|
684
|
$menu_toggle_settings = array(
|
685
|
'menu_toggle_tablet_portrait',
|
686
|
'menu_toggle_tablet_landscape',
|
687
|
);
|
688
|
$cfg = array();
|
689
|
foreach ($menu_toggle_settings as $toggle_setting) {
|
690
|
$setting = at_get_setting($toggle_setting, $theme_name);
|
691
|
if ($setting == 1) {
|
692
|
$cfg[$theme_name]['menu_toggle_settings'][$toggle_setting] = 'true';
|
693
|
}
|
694
|
else {
|
695
|
$cfg[$theme_name]['menu_toggle_settings'][$toggle_setting] = 'false';
|
696
|
}
|
697
|
}
|
698
|
drupal_add_js(array('adaptivetheme' => $cfg), 'setting');
|
699
|
|
700
|
$path_to_at_core = drupal_get_path('theme', 'adaptivetheme');
|
701
|
|
702
|
// Load additional plugins
|
703
|
drupal_add_js($path_to_at_core . '/scripts/outside-events.js', array(
|
704
|
'type' => 'file',
|
705
|
'scope' => 'header',
|
706
|
'group' => JS_THEME,
|
707
|
'weight'=> 999,
|
708
|
'preprocess' => TRUE,
|
709
|
'cache' => TRUE,
|
710
|
)
|
711
|
);
|
712
|
|
713
|
// Load the JS file
|
714
|
drupal_add_js($path_to_at_core . '/scripts/menu-toggle.js', array(
|
715
|
'type' => 'file',
|
716
|
'scope' => 'header',
|
717
|
'group' => JS_THEME,
|
718
|
'weight'=> 999,
|
719
|
'preprocess' => TRUE,
|
720
|
'cache' => TRUE,
|
721
|
)
|
722
|
);
|
723
|
|
724
|
// Load the generated CSS
|
725
|
$filepath = $path . '/' . $theme_name . '.menutoggle.css';
|
726
|
if (file_exists($filepath)) {
|
727
|
drupal_add_css($filepath, array(
|
728
|
'preprocess' => TRUE,
|
729
|
'group' => CSS_THEME,
|
730
|
'media' => 'all',
|
731
|
'every_page' => TRUE,
|
732
|
'weight' => 99,
|
733
|
)
|
734
|
);
|
735
|
}
|
736
|
}
|
737
|
|
738
|
//
|
739
|
// Functions to maintain 7.x-2.x backward compatibility,
|
740
|
// DO NOT use these for 7.x-3.x or greater.
|
741
|
// Note to self - do not namespace these, that will certainly break existing sites.
|
742
|
//
|
743
|
// Load sub-theme media queries, 7.x-2.x backward compatibility
|
744
|
function load_subtheme_media_queries($files, $theme_name) {
|
745
|
$path_to_theme = drupal_get_path('theme', $theme_name);
|
746
|
foreach ($files as $file) {
|
747
|
$filepath = $path_to_theme . '/css/' . $file;
|
748
|
if (file_exists($filepath)) {
|
749
|
drupal_add_css($filepath, array(
|
750
|
'preprocess' => variable_get('preprocess_css', '') == 1 ? TRUE : FALSE,
|
751
|
'group' => CSS_THEME,
|
752
|
'media' => 'all',
|
753
|
'every_page' => TRUE,
|
754
|
'weight' => 99,
|
755
|
)
|
756
|
);
|
757
|
}
|
758
|
else {
|
759
|
at_load_failure($filepath, $theme_name);
|
760
|
}
|
761
|
}
|
762
|
}
|
763
|
|
764
|
// Load subtheme IE stylesheets, 7.x-2.x backward compatibility
|
765
|
function load_subtheme_ie_styles($files, $theme_name) {
|
766
|
$path_to_theme = drupal_get_path('theme', $theme_name);
|
767
|
foreach ($files as $key => $value) {
|
768
|
$filepath = $path_to_theme . '/css/' . $value;
|
769
|
if (file_exists($filepath)) {
|
770
|
drupal_add_css($filepath, array(
|
771
|
'group' => CSS_THEME,
|
772
|
'browsers' => array(
|
773
|
'IE' => $key,
|
774
|
'!IE' => FALSE,
|
775
|
),
|
776
|
'media' => 'screen',
|
777
|
'preprocess' => TRUE,
|
778
|
)
|
779
|
);
|
780
|
}
|
781
|
else {
|
782
|
at_load_failure($filepath, $theme_name);
|
783
|
}
|
784
|
}
|
785
|
}
|