Created
May 19, 2017 13:17
-
-
Save druman/447b54718ce3b2d6216663207a6d8b41 to your computer and use it in GitHub Desktop.
Hide & collapsed items exposed filters with pass vars to JS
This file contains hidden or 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
<? | |
/** | |
* Impliment hook_menu(). | |
*/ | |
function myjspass_menu() { | |
$items = array(); | |
// Configuration Page | |
$items['admin/config/myjspass'] = array( | |
'title' => t('Hide & collapsed items exposed filters'), | |
'description' => t('Configuration hide & collapsed items exposed filters'), | |
'access arguments' => array('access myjspass settings'), | |
'page callback' => 'drupal_get_form', | |
'page arguments' => array('myjspass_form'), | |
'type' => MENU_NORMAL_ITEM, | |
); | |
return $items; | |
} | |
function myjspass_permission() { | |
return array( | |
'access myjspass settings' => array( | |
'title' => t('Access my JS pass selectors settings'), | |
) | |
); | |
} | |
function myjspass_form($form_state) { | |
$form = array(); | |
$form['hide_selectors'] = array ( | |
'#type' => 'textarea', | |
'#title' => t('Hide selectors'), | |
'#description' => t('Write selectors with comma for hide'), | |
'#default_value' => variable_get('myjspass_hide', ''), | |
'#rows' => 15, | |
); | |
$form['collapsed_selectors'] = array ( | |
'#type' => 'textarea', | |
'#title' => t('Collapsed selectors'), | |
'#description' => t('Write selectors with comma for collapsed'), | |
'#default_value' => variable_get('myjspass_collapsed', ''), | |
'#rows' => 15, | |
); | |
$form['onecolumn_selectors'] = array ( | |
'#type' => 'textarea', | |
'#title' => t('One column selectors'), | |
'#description' => t('Write selectors with comma for view in one column'), | |
'#default_value' => variable_get('myjspass_onecolumn', ''), | |
'#rows' => 15, | |
); | |
$form['submit'] = array( | |
'#type'=>'submit', | |
'#value'=>t('Update'), | |
); | |
return $form; | |
} | |
function myjspass_form_submit($form, &$form_state) { | |
str_replace(array("\r","\n"), "", variable_set('myjspass_hide', ($form_state['values']['hide_selectors']))); | |
str_replace(array("\r","\n"), "", variable_set('myjspass_collapsed', ($form_state['values']['collapsed_selectors']))); | |
str_replace(array("\r","\n"), "", variable_set('myjspass_onecolumn', ($form_state['values']['onecolumn_selectors']))); | |
drupal_set_message(t("Updated")); | |
} |
This file contains hidden or 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
<?php | |
/** | |
* @file | |
* Returns the HTML for a single Drupal page. | |
* | |
* Complete documentation for this file is available online. | |
* @see https://drupal.org/node/1728148 | |
*/ | |
?> | |
<?php | |
drupal_add_js( | |
array( | |
'myjspass' => array( | |
'hselectors' => str_replace(array("\r","\n"), "", variable_get('myjspass_hide', '')), | |
'colselectors' => str_replace(array("\r","\n"), "", variable_get('myjspass_collapsed', '')), | |
'onecolselectors' => str_replace(array("\r","\n"), "", variable_get('myjspass_onecolumn', '')), | |
) | |
), | |
'setting' | |
); | |
?> | |
<div class="layout-center"> | |
<header class="header" role="banner"> | |
<?php if ($logo): ?> | |
<a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home" class="header__logo"><img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" class="header__logo-image" /></a> | |
<?php endif; ?> | |
<?php if ($site_name || $site_slogan): ?> | |
<div class="header__name-and-slogan"> | |
<?php if ($site_name): ?> | |
<h1 class="header__site-name"> | |
<a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" class="header__site-link" rel="home"><span><?php print $site_name; ?></span></a> | |
</h1> | |
<?php endif; ?> | |
<?php if ($site_slogan): ?> | |
<div class="header__site-slogan"><?php print $site_slogan; ?></div> | |
<?php endif; ?> | |
</div> | |
<?php endif; ?> | |
<?php if ($secondary_menu): ?> | |
<nav class="header__secondary-menu" role="navigation"> | |
<?php print theme('links__system_secondary_menu', array( | |
'links' => $secondary_menu, | |
'attributes' => array( | |
'class' => array('links', 'inline', 'clearfix'), | |
), | |
'heading' => array( | |
'text' => $secondary_menu_heading, | |
'level' => 'h2', | |
'class' => array('visually-hidden'), | |
), | |
)); ?> | |
</nav> | |
<?php endif; ?> | |
<?php print render($page['header']); ?> | |
</header> | |
<div class="layout-3col layout-swap"> | |
<?php | |
// Render the sidebars to see if there's anything in them. | |
$sidebar_first = render($page['sidebar_first']); | |
$sidebar_second = render($page['sidebar_second']); | |
// Decide on layout classes by checking if sidebars have content. | |
$content_class = 'layout-3col__full'; | |
$sidebar_first_class = $sidebar_second_class = ''; | |
if ($sidebar_first && $sidebar_second): | |
$content_class = 'layout-3col__right-content'; | |
$sidebar_first_class = 'layout-3col__first-left-sidebar'; | |
$sidebar_second_class = 'layout-3col__second-left-sidebar'; | |
elseif ($sidebar_second): | |
$content_class = 'layout-3col__left-content'; | |
$sidebar_second_class = 'layout-3col__right-sidebar'; | |
elseif ($sidebar_first): | |
$content_class = 'layout-3col__right-content'; | |
$sidebar_first_class = 'layout-3col__left-sidebar'; | |
endif; | |
?> | |
<main class="<?php print $content_class; ?>" role="main"> | |
<?php print render($page['highlighted']); ?> | |
<?php print $breadcrumb; ?> | |
<a href="#skip-link" class="visually-hidden visually-hidden--focusable" id="main-content">Back to top</a> | |
<?php print render($title_prefix); ?> | |
<?php if ($title): ?> | |
<h1><?php print $title; ?></h1> | |
<?php endif; ?> | |
<?php print render($title_suffix); ?> | |
<?php print $messages; ?> | |
<?php print render($tabs); ?> | |
<?php print render($page['help']); ?> | |
<?php if ($action_links): ?> | |
<ul class="action-links"><?php print render($action_links); ?></ul> | |
<?php endif; ?> | |
<?php print render($page['content']); ?> | |
<?php print $feed_icons; ?> | |
</main> | |
<div class="layout-swap__top layout-3col__full"> | |
<a href="#skip-link" class="visually-hidden visually-hidden--focusable" id="main-menu" tabindex="-1">Back to top</a> | |
<?php if ($main_menu): ?> | |
<nav class="main-menu" role="navigation"> | |
<?php | |
// This code snippet is hard to modify. We recommend turning off the | |
// "Main menu" on your sub-theme's settings form, deleting this PHP | |
// code block, and, instead, using the "Menu block" module. | |
// @see https://drupal.org/project/menu_block | |
print theme('links__system_main_menu', array( | |
'links' => $main_menu, | |
'attributes' => array( | |
'class' => array('navbar', 'clearfix'), | |
), | |
'heading' => array( | |
'text' => t('Main menu'), | |
'level' => 'h2', | |
'class' => array('visually-hidden'), | |
), | |
)); ?> | |
</nav> | |
<?php endif; ?> | |
<?php print render($page['navigation']); ?> | |
</div> | |
<?php if ($sidebar_first): ?> | |
<aside class="<?php print $sidebar_first_class; ?>" role="complementary"> | |
<?php print $sidebar_first; ?> | |
</aside> | |
<?php endif; ?> | |
<?php if ($sidebar_second): ?> | |
<aside class="<?php print $sidebar_second_class; ?>" role="complementary"> | |
<?php print $sidebar_second; ?> | |
</aside> | |
<?php endif; ?> | |
</div> | |
<?php print render($page['footer']); ?> | |
</div> | |
<?php print render($page['bottom']); ?> |
This file contains hidden or 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
/** | |
* @file | |
* A JavaScript file for the theme. | |
* | |
* In order for this JavaScript to be loaded on pages, see the instructions in | |
* the README.txt next to this file. | |
*/ | |
(function ($, Drupal, window, document, undefined) { | |
Drupal.behaviors.my_custom_behavior = { | |
attach: function(context, settings) { | |
$(document).ready(function() { | |
if ($(window).width() > 767){ | |
// разворачиваем и скрываем пункты раскрытых фильтров кастомно | |
if ($('*').is(".catalog-filters")) { | |
var hselectors = Drupal.settings.myjspass.hselectors; | |
var colselectors = Drupal.settings.myjspass.colselectors; | |
var onecolselectors = Drupal.settings.myjspass.onecolselectors; | |
$(hselectors).remove(); | |
$(colselectors).show(); | |
$(onecolselectors).css('width', '99.9%'); | |
} | |
} | |
}); | |
})(jQuery, Drupal, this, this.document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment