first import

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-08 11:40:19 +02:00
commit 1bc61b12ad
8435 changed files with 1582817 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
Context UI
----------
Context UI provides an administrative interface for managing and editing
Contexts. It is not necessary for the proper functioning of contexts once they
are built and can be turned off on most production sites.
Requirements
------------
- Context, Context UI modules enabled (`admin/modules`)
- [jQuery UI 1.x][1] and [Admin 2.x][2] to use the inline context editor.
Optional.
Basic usage
-----------
As a site administrator you can manage your site's contexts at
`admin/structure/context`. The main page will show you a list of the contexts
on the site and give you some options for managing each context.
When editing or adding a new context, you will be presented with a form to
manage some basic information about the context and then alter its conditions
and reactions.
- `name`: The name of your context. This is the main identifier for your context
and cannot be changed after you've created it.
- `description`: A description or human-readable name for your context. This is
displayed in the inline editor if available instead of the name.
- `tag`: A category for organizing contexts in the administrative context
listing. Optional.
**Conditions**
When certain conditions are true, your context will be made active. You can
customize the conditions that trigger the activation of your context.
- **Condition mode**: you can choose to have your context triggered if **ANY**
conditions are met or only active when **ALL** conditions are met.
- **Adding/removing conditions**: you can add or remove to the conditions on
your context using the conditions dropdown.
- **Individual settings**: most conditions provide a simple form for selecting
individual settings for that condition. For example, the node type condition
allows you to choose which node types activate the context.
**Reactions**
Whenever a particular context is active, all of its reactions will be run.
Like conditions, reactions can be added or removed and have settings that can
be configured.
- **Reaction Block Groupings**: You can influence what "group" a block appears
in when listing all blocks available to be added to a region. This is done
by specifying $block->context_group via hook_block_info. If no group is
specified it will default to the module name, but if a group is specified
it will be grouped under that group name.
Using the inline editor
-----------------------
If you have installed jQuery UI and Admin, you can enable the inline context
editor:
1. As an administrative user go to `admin/settings/admin`.
2. Check the 'Context editor' block and save.
3. When viewing a page with one or more active contexts, you will see the
`Context editor` in the admin toolbar.
4. You can use the context editor to adjust the conditions under which each
context is active and alter its reactions.
[1]: http://drupal.org/project/jquery_ui
[2]: http://drupal.org/project/admin

View File

@@ -0,0 +1,182 @@
/**
* Editor =============================================================
*/
div.context-editor div.label {
float:left;
font-size: 14px;
}
div.context-editor div.links { float:right; }
div.context-editor div.bottom {
font-size: 12px;
font-style: italic;
font-weight:normal;
color: #999;
}
div.context-editor div.context-editable { display:none; }
div.context-editor div.links a.done { display:none; }
div.context-editor li.context-editing a.edit { display:none; }
div.context-editor li.context-editing a.done { display:block; }
/* Don't display form submission buttons initially or when editing */
body.context-editing div.context-editor div.links { display:none; }
body.context-editing div.context-editor li.context-editing div.links { display:block; }
div.context-editor div.buttons { display:none; }
form.edited div.context-editor div.buttons { display:block; }
body.context-editing form.edited div.context-editor div.buttons { display:none; }
/**
* Styles for visual integration with admin.
*/
#admin-toolbar div.context-editor div.links a:hover {
background:#eee;
color:#000;
}
#admin-toolbar div.context-editor div.links a {
float:left;
padding:0px 10px;
margin-right:5px;
background:#222;
font-size:11px;
-moz-border-radius:10px;
-webkit-border-radius:10px;
}
div.context-editor div.context-editable { padding:5px 0px; }
#admin-toolbar div.context-editor div.buttons {
padding:10px 0px;
text-align:center;
background:#111;
}
/**
* Horizontal
*/
#admin-toolbar.horizontal form.edited div.context-editor div.buttons,
#admin-toolbar.horizontal div.context-editor div.item-list {
float:left;
clear:left;
width:30%;
}
#admin-toolbar.horizontal div.context-editor div.contexts {
width:69.9%;
float:right;
}
#admin-toolbar.horizontal div.context-editor div.context-editable { padding-left:20px }
/**
* Admin listing page =================================================
*/
table.context-admin td.tag { font-style:italic; }
table.context-admin td.ctools-export-ui-name {
width:75%;
padding-left:20px;
}
table.context-admin td.ctools-export-ui-operations { white-space:nowrap; }
table.context-admin td.ctools-export-ui-storage { color:#999; }
table.context-admin div.description {
padding-left:10px;
margin:0px;
}
table.context-admin input.form-text { width:90%; }
/**
* Context form =======================================================
*/
.context-plugins {
position:relative;
margin:0px 0px 10px;
}
.context-plugins .context-plugin-info {
padding:10px 10px 9px;
border-bottom:1px solid #e8e8e8;
}
.context-plugins .context-plugin-info div.description {
margin:0px 0px 10px;
padding:0px;
}
.context-plugins .context-plugin-selector {
width:25%;
background:#fff;
}
.context-plugins .context-plugin-list .disabled { display:none; }
.context-plugins .context-plugin-list ul {
margin:0px;
padding:0px;
}
.context-plugins .context-plugin-list li {
list-style:none;
list-style-image:none;
background:transparent;
padding:0px;
margin:0px;
border:0px;
}
.context-plugins .context-plugin-list li a {
display:block;
position:relative;
padding:5px 10px 4px;
border-bottom:1px solid #e8e8e8;
}
.context-plugins .context-plugin-list li a.active-form {
background:#f8f8f8;
color:#333;
font-weight:bold;
}
.context-plugins .context-plugin-list li span.remove {
display:none;
position:absolute;
top:5px;
right:10px;
font-size:9px;
font-weight:normal;
-moz-border-radius:5px;
-webkit-border-radius:5px;
padding:0px 5px;
background:#fff;
}
.context-plugins .context-plugin-list li a:hover span.remove { display:block; }
.context-plugins .context-plugin-forms {
float:right;
width:75%;
background:#f8f8f8;
min-height:200px;
}
.context-plugins .context-plugin-forms .context-plugin-form {
padding:10px;
display:none;
}
.context-plugins .context-plugin-forms .active-form { display:block; }
.context-plugins .context-plugin-form .form-checkboxes {
max-height:300px;
overflow:auto;
}

View File

@@ -0,0 +1,16 @@
name = Context UI
description = "Provides a simple UI for settings up a site structure using Context."
dependencies[] = context
package = Context
core = "7.x"
configure = admin/structure/context
files[] = context.module
files[] = tests/context_ui.test
; Information added by drupal.org packaging script on 2012-12-19
version = "7.x-3.0-beta6"
core = "7.x"
project = "context"
datestamp = "1355879811"

View File

@@ -0,0 +1,9 @@
<?php
/**
* Update 6004: Placeholder update to ensure migrations from older versions
* in Aegir do not fail.
*/
function context_ui_update_6004() {
return array();
}

View File

@@ -0,0 +1,148 @@
(function($) {
/**
* Context plugin form.
*/
function DrupalContextPlugins(form) {
this.form = form;
// Sync the form selector and state field with the list of plugins currently enabled.
this.setState = function() {
var state = [];
$('.context-plugin-list > li', this.form).each(function() {
var plugin = $(this).attr('class').split('context-plugin-')[1].split(' ')[0];
if ($(this).is('.disabled')) {
$('.context-plugin-selector select option[value='+plugin+']', this.form).show();
}
else {
state.push(plugin);
$('.context-plugin-selector select option[value='+plugin+']', this.form).hide();
}
});
// Set the hidden plugin list state.
$('.context-plugin-selector input.context-plugins-state', this.form).val(state.join(','));
// Reset the selector.
$('.context-plugin-selector select', this.form).val(0);
return this;
};
// Add a plugin to the list.
this.addPlugin = function(plugin) {
$('.context-plugin-list > li.context-plugin-'+plugin, this.form).removeClass('disabled');
this.showForm(plugin).setState();
return this;
};
// Remove a plugin from the list.
this.removePlugin = function(plugin) {
$('.context-plugin-list > li.context-plugin-'+plugin, this.form).addClass('disabled');
this.hideForm(plugin).setState();
return this;
};
// Show a plugin form.
this.showForm = function(plugin) {
$('.context-plugin-forms > .context-plugin-form.active-form', this.form).removeClass('active-form');
$('.context-plugin-forms > .context-plugin-form-'+plugin, this.form).addClass('active-form');
$('.context-plugin-list > li > a').removeClass('active-form');
$('.context-plugin-list > li.context-plugin-'+plugin+' > a').addClass('active-form');
return this;
};
// Show a plugin form.
this.hideForm = function(plugin) {
$('.context-plugin-forms > .context-plugin-form-'+plugin, this.form).removeClass('active-form');
$('.context-plugin-list > li.context-plugin-'+plugin+' > a').removeClass('active-form');
return this;
};
// Select handler.
$('.context-plugin-selector select', this.form).change(function() {
var plugins = $(this).parents('div.context-plugins').data('contextPlugins');
if (plugins) {
var plugin = $(this).val();
plugins.addPlugin(plugin);
}
});
// Show form handler.
$('.context-plugin-list > li > a', this.form).click(function() {
var plugins = $(this).parents('div.context-plugins').data('contextPlugins');
if (plugins) {
var plugin = $(this).attr('href').split('#context-plugin-form-')[1];
plugins.showForm(plugin);
}
return false;
});
// Remove handler.
$('.context-plugin-list span.remove', this.form).click(function() {
var plugins = $(this).parents('div.context-plugins').data('contextPlugins');
if (plugins) {
var plugin = $(this).parent().attr('href').split('#context-plugin-form-')[1];
plugins.removePlugin(plugin);
}
return false;
});
// Set the plugin states.
this.setState();
}
Drupal.behaviors.context_ui = { attach: function(context) {
// Initialize context plugin form.
$('form div.context-plugins:not(.context-ui-processed)').each(function() {
$(this).addClass('context-ui-processed');
$(this).data('contextPlugins', new DrupalContextPlugins($(this)));
});
// Initialize context editor.
if (jQuery().pageEditor) {
$('form.context-editor:not(.context-ui-processed)')
.addClass('context-ui-processed')
.pageEditor()
.each(function() {
var editor = $(this);
var defaultContext = $('li.context-editable', this).attr('id').split('context-editable-trigger-')[1];
$(this).data('defaultContext', defaultContext);
// Attach start/end handlers to editable contexts.
$('li.context-editable a.edit', editor).click(function() {
var trigger = $(this).parents('li.context-editable').addClass('context-editing');
var context = trigger.attr('id').split('context-editable-trigger-')[1];
editor.pageEditor('start', context);
return false;
});
$('li.context-editable a.done', editor).click(function() {
editor.pageEditor('end');
return false;
});
$(editor).submit(function() {
if (editor.pageEditor('isEditing')) {
editor.pageEditor('end');
}
});
// Handler for start event.
editor.bind('start.pageEditor', function(event, context) {
// Fallback to first context if param is empty.
if (!context) {
context = $(this).data('defaultContext');
$('li#context-editable-trigger-'+context, this).addClass('context-editing');
}
$(document.body).addClass('context-editing');
$('#context-editable-'+context, this).show();
});
// Handler for end event.
editor.bind('end.pageEditor', function(event, context) {
$(document.body).removeClass('context-editing');
$('div.contexts div.context-editable', this).hide();
$('li.context-editable').removeClass('context-editing');
$('form.context-editor').addClass('edited');
});
});
}
}};
})(jQuery);

View File

@@ -0,0 +1,433 @@
<?php
/**
* Implementation of hook_ctools_plugin_directory().
*/
function context_ui_ctools_plugin_directory($module, $plugin) {
if ($module == 'ctools' && $plugin == 'export_ui') {
return 'export_ui';
}
}
/**
* Implementation of hook_theme().
*/
function context_ui_theme() {
$items = array();
$items['context_ui_form'] = array(
'render element' => 'form',
'path' => drupal_get_path('module', 'context_ui') .'/theme',
'template' => 'context-ui-form',
'file' => 'theme.inc',
);
$items['context_ui_plugins'] = array(
'render element' => 'form',
'path' => drupal_get_path('module', 'context_ui') .'/theme',
'template' => 'context-ui-plugins',
'file' => 'theme.inc',
);
$items['context_ui_editor'] = array(
'render element' => 'form',
'path' => drupal_get_path('module', 'context_ui') .'/theme',
'template' => 'context-ui-editor',
'file' => 'theme.inc',
);
return $items;
}
/**
* Implementation of hook_block_info().
*/
function context_ui_block_info() {
$blocks = array();
$blocks['editor'] = array('info' => t('Context editor'), 'admin' => TRUE);
if (module_exists('devel')) {
$blocks['devel'] = array('info' => t('Context inspector'), 'admin' => TRUE);
}
return $blocks;
}
/**
* Implementation of hook_block_view().
*/
function context_ui_block_view($delta = '') {
switch ($delta) {
case 'editor':
if (user_access('administer contexts') && strpos($_GET['q'], 'admin/structure/context') === FALSE && $contexts = context_active_contexts()) {
return array(
'subject' => t('Context editor'),
'content' => drupal_get_form('context_ui_editor', $contexts),
);
}
break;
case 'devel':
if (module_exists('devel') && $all = context_get()) {
return array(
'subject' => t('Context inspector'),
'content' => kdevel_print_object($all),
);
}
break;
}
}
/**
* Implementation of hook_permission().
*/
function context_ui_permission() {
$permissions = array();
$permissions['administer contexts'] = array(
'title' => 'Administer contexts',
'description' => 'Associate menus, views, blocks, etc. with different contexts to structure your site.'
);
return $permissions;
}
/**
* Implementation of hook_menu().
*/
function context_ui_menu() {
$items = array();
$items['admin/structure/context/settings'] = array(
'title' => 'Settings',
'access callback' => 'user_access',
'access arguments' => array('administer contexts'),
'page callback' => 'drupal_get_form',
'page arguments' => array('context_ui_settings'),
'type' => MENU_LOCAL_TASK,
'weight' => 3,
);
$items['context-ui/activate'] = array(
'title' => 'Activate Context UI',
'access arguments' => array('administer contexts'),
'page callback' => 'context_ui_activate',
'type' => MENU_CALLBACK
);
$items['context-ui/deactivate'] = array(
'title' => 'Deactivate Context UI',
'access arguments' => array('administer contexts'),
'page callback' => 'context_ui_deactivate',
'type' => MENU_CALLBACK
);
return $items;
}
/**
* Implementation of hook_help().
*/
function context_ui_help($path, $arg) {
switch ($path) {
case 'admin/help#context_ui':
$output = file_get_contents(drupal_get_path('module', 'context_ui') .'/README.txt');
return module_exists('markdown') ? filter_xss_admin(module_invoke('markdown', 'filter', 'process', 0, -1, $output)) : '<pre>'. check_plain($output) .'</pre>';
case 'admin/structure/context':
return '<p>'. t('Context allows you to manage contextual conditions and reactions for different portions of your site. You can think of each context as representing a "section" of your site. For each context, you can choose the conditions that trigger this context to be active and choose different aspects of Drupal that should react to this active context.') .'</p>';
}
}
/**
* Inline context editor form.
*/
function context_ui_editor($form, &$form_state, $contexts) {
$form = array(
'#attributes' => array('class' => array('context-editor')),
'#theme' => array('context_ui_editor'),
'editables' => array(),
'contexts' => array('#tree' => TRUE),
'buttons' => array('#tree' => FALSE),
);
$form['title'] = array(
'#prefix' => '<h2 class="context-editor-title">',
'#markup' => t('Select the Context/Layer to Edit'),
'#suffix' => '</h2>',
'#weight' => -2,
);
//add some help text to the top of the form
$form['help'] = array (
'#prefix' => '<p class="context-help help">',
'#markup' => t('Select which context, or layer of blocks, to edit.
Each context is configured to appear on different sets of pages so read the description carefully.
When you are done editing click Done and save your changes.
You may use the Stop Editing Layout link to close the editor.'),
'#suffix' => '</p>',
'#weight' => -1,
);
$items = array();
$form_context = array();
ksort($contexts);
foreach ($contexts as $context) {
$edit = l(t('Edit'), $_GET['q'], array('fragment' => $context->name, 'attributes' => array('class' => array('edit'))));
$done = l(t('Done'), $_GET['q'], array('fragment' => $context->name, 'attributes' => array('class' => array('done'))));
$readable_name = ucwords(str_replace('_', ' ', $context->name));
$description = empty($context->description) ? '' :
"<br/><div class='label bottom'>".check_plain($context->description)."</div>";
$items[] = array(
'data' => "<div class='label top'>" . $readable_name. "</div><div class='links'>{$edit} {$done}</div>" . $description,
'class' => array('context-editable clearfix'),
'id' => "context-editable-trigger-{$context->name}",
);
$form_context = array(
'#tree' => TRUE,
'#type' => module_exists('admin') ? 'admin_panes' : NULL,
'context' => array('#type' => 'value', '#value' => $context),
);
// Edit context reactions.
foreach (array_keys(context_reactions()) as $reaction) {
$plugin = context_get_plugin('reaction', $reaction);
if (method_exists($plugin, 'editor_form') && ($plugin_form = $plugin->editor_form($context))) {
$form_context["reaction-{$reaction}"] = $plugin_form + array('#title' => $plugin->title);
}
}
// Add to main form.
$form['contexts'][$context->name] = $form_context;
}
// Display editable contexts in list.
$form['editables']['#markup'] = theme('item_list', array('items' => $items));
// Buttons.
$form['buttons']['save'] = array(
'#type' => 'submit',
'#value' => t('Save changes'),
'#submit' => array('context_ui_editor_submit'),
);
$form['buttons']['cancel'] = array(
'#type' => 'submit',
'#value' => t('Reset'),
'#submit' => array('context_ui_editor_cancel'),
);
$form['stop'] = array(
'#markup' => l(t('Stop Editing Layout'), 'context-ui/deactivate', array(
'query' => array('destination' => current_path()),
'attributes' => array('class' => array('context_ui_dialog-stop')),
)
),
);
return $form;
}
/**
* Values processor for context_ui_editor_submit().
* Split out for reuse by overriding submit handlers.
*/
function context_ui_editor_process($values) {
$context = $values['context'];
foreach (array_keys(context_conditions()) as $condition) {
if (isset($values['condition'][$condition])) {
$plugin = context_get_plugin('condition', $condition);
if ($plugin && method_exists($plugin, 'editor_form_submit')) {
$context->conditions[$condition]['values'] = $plugin->editor_form_submit($context, $values['condition'][$condition]);
}
}
if (isset($context->conditions[$condition]) && context_empty($context->conditions[$condition]['values'])) {
unset($context->conditions[$condition]);
}
}
foreach (array_keys(context_reactions()) as $reaction) {
if (isset($values["reaction-{$reaction}"])) {
$plugin = context_get_plugin('reaction', $reaction);
if ($plugin && method_exists($plugin, 'editor_form_submit')) {
$context->reactions[$reaction] = $plugin->editor_form_submit($context, $values["reaction-{$reaction}"]);
}
}
if (isset($context->reactions[$reaction]) && context_empty($context->reactions[$reaction])) {
unset($context->reactions[$reaction]);
}
}
return $context;
}
/**
* Save handler for context_block_editor().
*/
function context_ui_editor_submit(&$form, &$form_state) {
foreach ($form_state['values']['contexts'] as $name => $values) {
$original_reactions = var_export($values['context']->reactions, TRUE);
$context = context_ui_editor_process($values);
//compare string values instead of actual objects to avoid problems with aliasing
if (($original_reactions !== var_export($context->reactions, TRUE))) {
if (context_save($context)) {
drupal_set_message(t('Saved %title.', array(
'%title' => (!empty($context->description) ? $context->description : $context->name)
)));
}
else {
drupal_set_message(t('Could not save context %title.', array('%title' => $context->name)), 'error');
}
}
}
return;
}
/**
* Cancel handler for context_block_editor().
*/
function context_ui_editor_cancel(&$form, &$form_state) {
return;
}
/**
* Settings form.
*/
function context_ui_settings($form, &$form_state) {
$form = array();
foreach (context_conditions() as $condition => $info) {
if ($plugin = context_get_plugin('condition', $condition)) {
$settings_form = $plugin->settings_form();
if ($settings_form) {
$form['conditions'][$condition] = $settings_form;
$form['conditions'][$condition]['#tree'] = FALSE;
$form['conditions'][$condition]['#type'] = 'fieldset';
$form['conditions'][$condition]['#title'] = $info['title'];
}
}
}
foreach (context_reactions() as $reaction => $info) {
if ($plugin = context_get_plugin('reaction', $reaction)) {
$settings_form = $plugin->settings_form();
if ($settings_form) {
$form['reactions'][$reaction] = $settings_form;
$form['reactions'][$reaction]['#tree'] = FALSE;
$form['reactions'][$reaction]['#type'] = 'fieldset';
$form['reactions'][$reaction]['#title'] = $info['title'];
}
}
}
$form['context_ui_dialog_enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Use Context Editor Dialog'),
'#default_value' => context_ui_dialog_is_enabled(),
'#description' => t('When enabled all contextual links will have a Edit Layout link that will refresh the page with the context editor in a dialog box.'),
);
$form = system_settings_form($form);
$form['#submit'][] = 'context_ui_settings_submit';
return $form;
}
/**
* Extra submit handler for context_ui_settings.
* Mark the menu cache as needing a rebuild.
*/
function context_ui_settings_submit($form, &$form_state) {
variable_set('menu_rebuild_needed', TRUE);
}
/**
* context_ui_dialog_is_enabled test if the dialog is enabled
*/
function context_ui_dialog_is_enabled() {
return variable_get("context_ui_dialog_enabled", FALSE);
}
/**
* Implementation of hook_page_alter().
*
* If we have the dialog enabled and active build the dialog
* and add to the page
*/
function context_ui_page_alter(&$page) {
$contexts = context_active_contexts();
if (
context_ui_dialog_is_enabled() &&
context_isset('context_ui', 'context_ui_editor_present')
) {
$contexts = context_active_contexts();
$form = drupal_get_form('context_ui_editor', $contexts);
$path = drupal_get_path('module', 'context_ui');
drupal_add_library('system', 'ui.dialog');
drupal_add_js($path . '/context_ui_dialog.js', array('type' => 'file', 'weight' => 50));
drupal_add_css($path . '/context_ui_dialog.css');
//figure out which region to put it in - allow it to be configured for themes using different regions
$placement = variable_get('context_ui_editor_block_region', 'content');
$page[$placement]['context_ui_editor'] = array(
0 => array(
'#type' => 'markup',
'#markup' => '<div style="display:none;" id="context_ui_dialog-context-ui">' . drupal_render($form) . '<!--[if IE 8 ]><div id="context_ui_dialog-shadow"></div><![endif]--></div>',
),
);
}
}
/**
* Implementation of hook_menu_contextual_links_alter().
*
* we we have the dialog enabled lets add a link to all contextual links
* to activate it.
*/
function context_ui_menu_contextual_links_alter(&$links, $router_item, $root_path) {
if(context_ui_dialog_is_enabled() &&
!context_isset('context_ui', 'context_ui_editor_present')) {
$links['layout'] = array(
'href' => 'context-ui/activate',
'title' => t('Configure Layout'),
'localized_options' => array(
'query' => array('destination'=> $_GET['q']),
'options' => array('html' => FALSE, 'attributes' => array()),
),
);
}
}
/**
* A page call back to activate the context_ui inline editor dialog.
*/
function context_ui_activate() {
$_SESSION['context_ui_active'] = $_GET['destination'];
drupal_goto($_GET['destination']);
}
/**
* A page call back to deactivate the context_ui inline editor dialog.
* This is semi unecessary as context editor will auto deactivate upon going to any
* page other than the destination from the start. However, its useful as a place
* to navigate to when deactivating context_ui_editor
*/
function context_ui_deactivate() {
$_SESSION['context_ui_active'] = FALSE;
drupal_goto($_GET['destination']);
}
/**
* Implemenation of hook_init().
*
* If the session says we should have an active dialog set a context variable to tell everything else
* Ignores ajax requests.
*/
function context_ui_init() {
if (!empty($_SESSION['context_ui_active'])) {
$path = $_SESSION['context_ui_active'];
if( $path == request_path() || $path == drupal_get_path_alias() || $path == drupal_get_normal_path(request_path()) ) {
context_set('context_ui', 'context_ui_editor_present', TRUE);
}
}
// Turn off functionality has been moved to hook_page_build() to prevent non-pages from triggering it
}
/**
* Implementation of hook_page_build().
* Turn off the context_ui functionality if we move to a different page
*/
function context_ui_page_build(&$page) {
if (!context_get('context_ui', 'context_ui_editor_present') && isset($_SESSION['context_ui_active'])) {
$_SESSION['context_ui_active'] = FALSE;
}
}
/**
* Ajax callback to get the list of available blocks
*
*/
function context_ui_get_available_blocks() {
drupal_json_output(array('lols' => 'testing'));
}

View File

@@ -0,0 +1,106 @@
#context_ui_dialog-context-ui .item-list {
overflow-y: auto;
overflow-x: hidden;
padding-right: 5px;
}
#context_ui_dialog-context-ui a, #context_ui_dialog-context-ui li a.active {
color: #222;
}
#context_ui_dialog-context-ui ul {
margin: 0;
}
#context_ui_dialog-context-ui ul li {
padding: 4px 0;
list-style: none;
}
#context_ui_dialog-context-ui .buttons {
padding-top:15px;
}
#context_ui_dialog-context-ui div.admin-pane-condition,
#context_ui_dialog-context-ui div.admin-pane-reaction-theme,
#context_ui_dialog-context-ui div.admin-pane-reaction-theme_html {
display: none;
}
.boxes-box-editing {
background: none repeat scroll 0 0 #EEEEDD;
display: inline-block;
padding: 3px;
}
body.context-editing div.contextual-links-wrapper {
right: 0;
top: 40px;
}
#context_ui_dialog-context-ui a.context_ui_dialog-stop,
#context_ui_dialog-context-ui a:link.context_ui_dialog-stop,
#context_ui_dialog-context-ui a:visited.context_ui_dialog-stop {
float:right;
padding-top:18px;
color: #ad3f00;
}
form.context-editing li.context-editable {
opacity: .2;
}
form.context-editing li.context-editing {
visibility : visible;
display : list-item;
opacity: 1;
}
#context_ui_dialog-shadow {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
background-color: #fff;
/* For IE 8 */
-ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#555555')";
/* For IE 5.5 - 7 */
filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#555555');
}
#context_ui_dialog-context-ui {
width: 550px;
position:fixed;
background:#fff;
color:#222;
top:140px;
display:none;
z-index:400;
padding:10px;
font-weight:bold;
border:1px solid #ddd;
border-left:0;
border-radius:0 6px 6px 0;
/* Shadow */
-moz-box-shadow: 3px 3px 4px #555;
-webkit-box-shadow: 3px 3px 4px #555;
box-shadow: 3px 3px 4px #555;
}
.context-ui-dialog-open {
border-radius:0 6px 6px 0;
position: absolute;
background:#fff;
color:#222;
top: 50px;
padding: 10px;
width: 55px;
right:-76px;
border:1px solid #ddd;
border-left:0;
font-size:12px;
/* Shadow */
-moz-box-shadow: 3px 3px 4px #555;
-webkit-box-shadow: 3px 3px 4px #555;
box-shadow: 3px 3px 4px #555;
/* For IE 8 */
-ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#555555')";
/* For IE 5.5 - 7 */
filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#555555');
}

View File

@@ -0,0 +1,47 @@
(function ($) {
Drupal.behaviors.context_ui_dialog = {
attach: function(context) {
var selector = $('#context_ui_dialog-context-ui', context).not('context_ui_dialog-processed');
if(selector) {
selector.addClass('context_ui_dialog-processed');
selector.detach();
$('#page').prepend(selector);
var labelOpen = Drupal.t('Select Context');
var labelClose = Drupal.t('Hide');
// Create a tab to show/hide our edit area
var tab = $('<a href="javascript:" class="context-ui-dialog-open" title="Show Context Selector">'+labelClose+'</a>');
selector.append(tab);
selector.toggled = false;
var width = $(selector).outerWidth();
tab.click(function(e){
if(selector.toggled) {
selector.stop(true, false).animate({'left':0}, 400);
selector.toggled = false;
$(this).text(labelClose);
} else {
selector.stop(true, false).animate({'left':-width-4}, 400);
selector.toggled = true;
$(this).text(labelOpen);
}
});
$('#context_ui_dialog-context-ui').show();
// Make sure the UI is 60% of the size of the window
var context_ui_height = Math.round(6 * $(window).height() / 10);
var item_list_height = context_ui_height - 200;
item_list_height = (item_list_height < 50) ? 50 : item_list_height;
$('#context_ui_dialog-context-ui').height(context_ui_height);
$('#context_ui_dialog-context-ui .item-list').height(item_list_height);
// Add a class to body
$('body').once().addClass('context-field-editor');
}
}
};
})(jQuery);

View File

@@ -0,0 +1,24 @@
<?php
$plugin = array(
'access' => 'administer contexts',
'schema' => 'context',
'menu' => array(
'menu prefix' => 'admin/structure',
'menu item' => 'context',
'menu title' => 'Context',
'menu description' => 'Associate menus, views, blocks, etc. with different contexts to structure your site.',
),
'title singular' => t('context'),
'title singular proper' => t('Context'),
'title plural' => t('contexts'),
'title plural proper' => t('Contexts'),
'form' => array(
'settings' => 'context_ui_form',
'submit' => 'context_ui_form_submit',
),
'handler' => array(
'class' => 'context_export_ui',
'parent' => 'ctools_export_ui',
),
);

View File

@@ -0,0 +1,326 @@
<?php
/**
* CTools export UI extending class. Slightly customized for Context.
*/
class context_export_ui extends ctools_export_ui {
function list_form(&$form, &$form_state) {
parent::list_form($form, $form_state);
$form['top row']['submit'] = $form['bottom row']['submit'];
$form['top row']['reset'] = $form['bottom row']['reset'];
$form['bottom row']['#access'] = FALSE;
// Invalidate the context cache.
context_invalidate_cache();
return;
}
function list_css() {
ctools_add_css('export-ui-list');
drupal_add_css(drupal_get_path("module", "context_ui") ."/context_ui.css");
}
function list_render(&$form_state) {
$table = array(
'header' => $this->list_table_header(),
'rows' => $this->rows,
'attributes' => array(
'class' => array('context-admin'),
'id' => 'ctools-export-ui-list-items',
),
);
return theme('table', $table);
}
function list_build_row($item, &$form_state, $operations) {
$name = $item->name;
// Add a row for tags.
$tag = !empty($item->tag) ? $item->tag : t('< Untagged >');
if (!isset($this->rows[$tag])) {
$this->rows[$tag]['data'] = array();
$this->rows[$tag]['data'][] = array('data' => check_plain($tag), 'colspan' => 3, 'class' => array('tag'));
$this->sorts["{$tag}"] = $tag;
}
// Build row for each context item.
$this->rows["{$tag}:{$name}"]['data'] = array();
$this->rows["{$tag}:{$name}"]['class'] = !empty($item->disabled) ? array('ctools-export-ui-disabled') : array('ctools-export-ui-enabled');
$this->rows["{$tag}:{$name}"]['data'][] = array(
'data' => check_plain($name) . "<div class='description'>" . check_plain($item->description) . "</div>",
'class' => array('ctools-export-ui-name')
);
$this->rows["{$tag}:{$name}"]['data'][] = array(
'data' => check_plain($item->type),
'class' => array('ctools-export-ui-storage')
);
$this->rows["{$tag}:{$name}"]['data'][] = array(
'data' => theme('links', array(
'links' => $operations,
'attributes' => array('class' => array('links inline'))
)),
'class' => array('ctools-export-ui-operations'),
);
// Sort by tag, name.
$this->sorts["{$tag}:{$name}"] = $tag . $name;
}
/**
* Override of edit_form_submit().
* Don't copy values from $form_state['values'].
*/
function edit_form_submit(&$form, &$form_state) {
if (!empty($this->plugin['form']['submit'])) {
$this->plugin['form']['submit']($form, $form_state);
}
}
/**
* Override default final validation for ctools. With import wizard
* it was possible to get default ctools export ui name validation
* rules, this ensures we always get ours.
*/
function edit_finish_validate(&$form, &$form_state) {
if ($form_state['op'] != 'edit') {
// Validate the name. Fake an element for form_error().
$export_key = $this->plugin['export']['key'];
$element = array(
'#value' => $form_state['item']->{$export_key},
'#parents' => array('name'),
);
$form_state['plugin'] = $this->plugin;
context_ui_edit_name_validate($element, $form_state);
}
}
}
/**
* Generates the omnibus context definition editing form.
*
* @param $form
* Form array to populate.
* @param $form_state
* Form state array
*/
function context_ui_form(&$form, &$form_state) {
$conditions = array_keys(context_conditions());
sort($conditions);
$reactions = array_keys(context_reactions());
sort($reactions);
$context = $form_state['item'];
if (!empty($form_state['input'])) {
$context = _context_ui_rebuild_from_input($context, $form_state['input'], $conditions, $reactions);
}
$form['#base'] = 'context_ui_form';
$form['#theme'] = 'context_ui_form';
// Core context definition
$form['info']['#type'] = 'fieldset';
$form['info']['#tree'] = FALSE;
$form['info']['name']['#element_validate'] = array('context_ui_edit_name_validate');
$form['info']['tag'] = array(
'#title' => t('Tag'),
'#type' => 'textfield',
'#required' => FALSE,
'#maxlength' => 255,
'#default_value' => isset($context->tag) ? $context->tag : '',
'#description' => t('Example: <code>theme</code>') .'<br/>'. t('A tag to group this context with others.'),
);
$form['info']['description'] = array(
'#title' => t('Description'),
'#type' => 'textfield',
'#required' => FALSE,
'#maxlength' => 255,
'#default_value' => isset($context->description) ? $context->description: '',
'#description' => t('The description of this context definition.'),
);
// Condition mode
$form['condition_mode'] = array(
'#type' => 'checkbox',
'#default_value' => isset($context->condition_mode) ? $context->condition_mode : FALSE,
'#title' => t('Require all conditions'),
'#description' => t('If checked, all conditions must be met for this context to be active. Otherwise, the first condition that is met will activate this context.')
);
// Condition plugin forms
$form['conditions'] = array(
'#theme' => 'context_ui_plugins',
'#title' => t('Conditions'),
'#description' => t('Trigger the activation of this context'),
'#tree' => TRUE,
'selector' => array(
'#type' => 'select',
'#options' => array(0 => '<'. t('Add a condition') .'>'),
'#default_value' => 0,
),
'state' => array(
'#attributes' => array('class' => array('context-plugins-state')),
'#type' => 'hidden',
),
'plugins' => array('#tree' => TRUE),
);
foreach ($conditions as $condition) {
if ($plugin = context_get_plugin('condition', $condition)) {
$form['conditions']['plugins'][$condition] = array(
'#tree' => TRUE,
'#plugin' => $plugin,
'#context_enabled' => isset($context->conditions[$condition]), // This flag is used at the theme layer.
'values' => $plugin->condition_form($context),
'options' => $plugin->options_form($context),
);
$form['conditions']['selector']['#options'][$condition] = $plugin->title;
}
}
// Reaction plugin forms
$form['reactions'] = array(
'#theme' => 'context_ui_plugins',
'#title' => t('Reactions'),
'#description' => t('Actions to take when this context is active'),
'#tree' => TRUE,
'selector' => array(
'#type' => 'select',
'#options' => array(0 => '<'. t('Add a reaction') .'>'),
'#default_value' => 0,
),
'state' => array(
'#attributes' => array('class' => array('context-plugins-state')),
'#type' => 'hidden',
),
'plugins' => array('#tree' => TRUE),
);
foreach ($reactions as $reaction) {
if ($plugin = context_get_plugin('reaction', $reaction)) {
$form['reactions']['plugins'][$reaction] = $plugin->options_form($context) + array(
'#plugin' => $plugin,
'#context_enabled' => isset($context->reactions[$reaction]), // This flag is used at the theme layer.
);
$form['reactions']['selector']['#options'][$reaction] = $plugin->title;
}
}
}
/**
* Handle the complex job of rebuilding a Context from submission data in the case of a validation error.
*
* @param $context
* The context object to modify.
* @param $input
* A form submission values
* @param $conditions
* The full list of condition plugins
* @param $reactions
* The full list of reaction plugins
*
* @return
* A context object
*/
function _context_ui_rebuild_from_input($context, $input, $conditions, $reactions) {
$condition_defaults = array();
foreach ($conditions as $condition) {
if ($plugin = context_get_plugin('condition', $condition)) {
$condition_defaults[$condition] = array(
'values' => $plugin->condition_form($context),
'options' => $plugin->options_form($context),
);
}
}
$input['conditions']['plugins'] = array_merge($condition_defaults, $input['conditions']['plugins']);
$reaction_defaults = array();
foreach ($reactions as $reaction) {
if ($plugin = context_get_plugin('reaction', $reaction)) {
$reaction_defaults[$reaction] = $plugin->options_form($context);
}
}
$input['reactions']['plugins'] = array_merge($reaction_defaults, $input['reactions']['plugins']);
return context_ui_form_process($context, $input, FALSE);
}
/**
* Modifies a context object from submitted form values.
*
* @param $context
* The context object to modify.
* @param $form
* A form array with submitted values
* @param $submit
* A flag indicating if we are building a context on submit. If on
* submit, it will clear out conditions/reactions that are empty.
*
* @return
* A context object
*/
function context_ui_form_process($context, $form, $submit = TRUE) {
$context->name = isset($form['name']) ? $form['name'] : $context->name;
$context->description = isset($form['description']) ? $form['description'] : NULL;
$context->tag = isset($form['tag']) ? $form['tag'] : NULL;
$context->condition_mode = isset($form['condition_mode']) ? $form['condition_mode'] : NULL;
$context->conditions = array();
$context->reactions = array();
if (!empty($form['conditions'])) {
$enabled = explode(',', $form['conditions']['state']);
foreach ($form['conditions']['plugins'] as $condition => $values) {
if (in_array($condition, $enabled, TRUE) && ($plugin = context_get_plugin('condition', $condition))) {
if (isset($values['values'])) {
$context->conditions[$condition]['values'] = $plugin->condition_form_submit($values['values']);
}
if (isset($values['options'])) {
$context->conditions[$condition]['options'] = $plugin->options_form_submit($values['options']);
}
if ($submit && context_empty($context->conditions[$condition]['values'])) {
unset($context->conditions[$condition]);
}
}
}
}
if (!empty($form['reactions'])) {
$enabled = explode(',', $form['reactions']['state']);
foreach ($form['reactions']['plugins'] as $reaction => $values) {
if (in_array($reaction, $enabled, TRUE) && ($plugin = context_get_plugin('reaction', $reaction))) {
if (isset($values)) {
$context->reactions[$reaction] = $plugin->options_form_submit($values);
}
if ($submit && context_empty($context->reactions[$reaction])) {
unset($context->reactions[$reaction]);
}
}
}
}
return $context;
}
/**
* Submit handler for main context_ui form.
*/
function context_ui_form_submit($form, &$form_state) {
$form_state['item'] = context_ui_form_process($form_state['item'], $form_state['values']);
}
/**
* Replacement for ctools_export_ui_edit_name_validate(). Allow dashes.
*/
function context_ui_edit_name_validate($element, &$form_state) {
$plugin = $form_state['plugin'];
// Check for string identifier sanity
if (!preg_match('!^[a-z0-9_-]+$!', $element['#value'])) {
form_error($element, t('The name can only consist of lowercase letters, underscores, dashes, and numbers.'));
return;
}
// Check for name collision
if ($form_state['op'] != 'edit') {
if (empty($form_state['item']->export_ui_allow_overwrite) && $exists = ctools_export_crud_load($plugin['schema'], $element['#value'])) {
form_error($element, t('A @plugin with this name already exists. Please choose another name or delete the existing item before creating a new one.', array('@plugin' => $plugin['title singular'])));
}
}
}

View File

@@ -0,0 +1,38 @@
/**
* Generic pageEditor plugin. Allows an editor DOM object to trigger
* init, start, and end events. Implementors can check whether the
* editor is currently editing and bind handlers for the events triggered
* by the editor.
*/
(function($) {
$.fn.pageEditor = function(method, data) {
this.each(function() {
switch (method) {
case 'isEditing':
return this.editing;
case 'start':
if (!this.inited) {
this.inited = true;
$(this).trigger('init.pageEditor', data);
}
this.editing = true;
$(this).trigger('start.pageEditor', data);
break;
case 'end':
if (!this.inited) {
this.inited = true;
$(this).trigger('init.pageEditor', data);
}
this.editing = false;
$(this).trigger('end.pageEditor', data);
break;
default:
this.inited = false;
this.editing = false;
break;
}
});
return this;
};
})(jQuery);

View File

@@ -0,0 +1 @@
if(!this.JSON){this.JSON={}}(function(){function f(n){return n<10?'0'+n:n}if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+f(this.getUTCMonth()+1)+'-'+f(this.getUTCDate())+'T'+f(this.getUTCHours())+':'+f(this.getUTCMinutes())+':'+f(this.getUTCSeconds())+'Z':null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf()}}var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+string+'"'}function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key)}if(typeof rep==='function'){value=rep.call(holder,key,value)}switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null'}gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||'null'}v=partial.length===0?'[]':gap?'[\n'+gap+partial.join(',\n'+gap)+'\n'+mind+']':'['+partial.join(',')+']';gap=mind;return v}if(rep&&typeof rep==='object'){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==='string'){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v)}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v)}}}}v=partial.length===0?'{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+mind+'}':'{'+partial.join(',')+'}';gap=mind;return v}}if(typeof JSON.stringify!=='function'){JSON.stringify=function(value,replacer,space){var i;gap='';indent='';if(typeof space==='number'){for(i=0;i<space;i+=1){indent+=' '}}else if(typeof space==='string'){indent=space}rep=replacer;if(replacer&&typeof replacer!=='function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify')}return str('',{'':value})}}if(typeof JSON.parse!=='function'){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v}else{delete value[k]}}}}return reviver.call(holder,key,value)}cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4)})}if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof reviver==='function'?walk({'':j},''):j}throw new SyntaxError('JSON.parse')}}}());

View File

@@ -0,0 +1,60 @@
<?php
/**
* Functional Test for Context UI
*
* TODO Test if menu and blocks respond.
*/
class ContextUiTestCase extends DrupalWebTestCase {
protected $profile = 'testing';
public static function getInfo() {
return array(
'name' => 'Context UI functional tests',
'description' => 'Create and save a context.',
'group' => 'Context UI',
);
}
function setUp() {
parent::setUp('ctools', 'context', 'context_ui', 'blog', 'menu');
// Create and login user
$admin_user = $this->drupalCreateUser(array(
'access administration pages',
'administer site configuration',
'access content',
'create blog content'
));
$this->drupalLogin($admin_user);
}
function testCreateContext() {
// Create context
$context = new stdClass();
$context->name = strtolower($this->randomName(15));
$context->description = strtolower($this->randomName(15));
$context->tag = strtolower($this->randomName(15));
$this->context = $context;
$this->drupalGet('admin');
$this->drupalGet('admin/structure');
$this->drupalGet('admin/structure/context');
$edit = array(
'name' => $context->name,
'description' => $context->description,
'tag' => $context->tag,
'conditions[plugins][node][values][blog]' => 'blog',
'reactions[plugins][menu]' => 'node/add/blog',
);
$this->drupalPost('admin/structure/context/add', $edit, 'Save');
$this->assertText($context->name . ' has been created.', 'Context saved.');
$edit = array();
// export_ui confirm delete
$this->drupalPost('admin/structure/context/list/' . $context->name . '/edit', $edit, 'Delete');
$this->assertTrue(strpos($this->getUrl(), 'admin/structure/context/list/' . $context->name . '/delete') !== FALSE, 'Context deletion confirmation page displayed');
}
}

View File

@@ -0,0 +1,10 @@
<div class='context-editor clearfix'>
<?php print drupal_render_children($form) ?>
<div class='contexts'>
<?php foreach (element_children($contexts) as $context): ?>
<div class='context-editable' id='context-editable-<?php print $context ?>'><?php print drupal_render($contexts[$context]) ?></div>
<?php endforeach; ?>
<?php print drupal_render($contexts) ?>
</div>
<div class='buttons'><?php print drupal_render($buttons) ?></div>
</div>

View File

@@ -0,0 +1,2 @@
<?php print drupal_render_children($form) ?>
<div class='buttons'><?php print drupal_render($buttons) ?></div>

View File

@@ -0,0 +1,22 @@
<div class='context-plugins clearfix'>
<div class='context-plugin-forms'>
<?php foreach (element_children($form['plugins']) as $plugin): ?>
<div class='context-plugin-form context-plugin-form-<?php print $plugin ?>'>
<?php print drupal_render($form['plugins'][$plugin]) ?>
</div>
<?php endforeach; ?>
</div>
<div class='context-plugin-selector'>
<div class='context-plugin-info'>
<h2 class='context-plugin-title'><?php print $title ?></h2>
<div class='description'><?php print $description ?></div>
<?php print drupal_render($form['selector']) ?>
<?php print drupal_render($form['state']) ?>
</div>
<?php print theme('links', array('links' => $plugins, 'attributes' => array('class' => array('context-plugin-list')))) ?>
</div>
<?php print drupal_render_children($form) ?>
</div>

View File

@@ -0,0 +1,66 @@
/**
* create a simple search filter thing for a list
*/
(function ($) {
Drupal.Filter = function (list, title, type, parent){
this.list = list;
this.title = title;
//provide defaults for type and parent so bad things don't happen
if (!type) { var type = '*'; }
this.type = type;
if (!parent) { var parent = list; }
this.parent = parent;
this.init();
}
Drupal.Filter.prototype = {
init : function(){
this.wrapper = $('<div class="filter-wrapper"></div>');
if(this.title){
this.title = '<h3>' + this.title + '</h3>';
this.wrapper.append(this.title);
}
this.input = $('<input type="text" class="filter" />');
this.wrapper.append(this.input);
$(this.parent).append(this.wrapper);
this.createHandlers();
},
createHandlers : function(){
var self = this;
$(this.input).keyup(function(e){
self.filter();
});
},
filter : function(){
//show all first off
$('*', this.list).show();
//hide ignored items
if(this.input.val()) {
$('*', this.list).not(this.type).hide();
}
var regex = new RegExp(this.input.val(), 'i');
var self = this;
$(this.type, this.list).each(function(ind, el) {
var string = self.strip(el.innerHTML);
if(!regex.test(string)){
$(el).hide();
} else { //show the parent and any labels or whatever in the parent
var parent = $(el).parent().show();
$('*', parent).not(self.type).show();
}
});
},
strip : function(string){
var strip = /<([^<|^>]*)>/i;
while(strip.test(string)){
var matches = string.match(strip);
string = string.replace(strip, '');
}
return string;
}
};
})(jQuery);

View File

@@ -0,0 +1,54 @@
<?php
/**
* Preprocessor for theme('context_ui_editor').
*/
function template_preprocess_context_ui_editor(&$vars) {
drupal_add_css(drupal_get_path('module', 'context_ui') . '/context_ui.css');
drupal_add_js(drupal_get_path('module', 'context_ui') . '/context_ui.js');
drupal_add_js(drupal_get_path('module', 'context_ui') . '/jquery.pageEditor.js');
$vars['contexts'] = $vars['form']['contexts'];
unset($vars['form']['contexts']);
$vars['buttons'] = $vars['form']['buttons'];
unset($vars['form']['buttons']);
}
/**
* Preprocessor for theme('context_ui_plugins').
*/
function template_preprocess_context_ui_plugins(&$vars) {
drupal_add_css(drupal_get_path("module", "context_ui") . "/context_ui.css");
drupal_add_js(drupal_get_path("module", "context_ui") . "/context_ui.js");
drupal_add_js(drupal_get_path('module', 'context_ui') . '/jquery.pageEditor.js');
// Provide title & desc.
$vars['title'] = check_plain($vars['form']['#title']);
$vars['description'] = check_plain($vars['form']['#description']);
// Build list of plugins.
$plugins = array();
$vars['plugins'] = array();
foreach (element_children($vars['form']['plugins']) as $plugin) {
$link = array(
'title' => $vars['form']['plugins'][$plugin]['#plugin']->title . "<span class='remove'>" . t('Remove') . "</span>",
'href' => $_GET['q'],
'html' => TRUE,
'fragment' => "context-plugin-form-{$plugin}",
);
$class = $vars['form']['plugins'][$plugin]['#context_enabled'] ? "context-plugin-{$plugin}" : "context-plugin-{$plugin} disabled";
$vars['plugins'][$class] = $link;
}
}
/**
* Preprocessor for theme('context_ui_form').
*/
function template_preprocess_context_ui_form(&$vars) {
drupal_add_css(drupal_get_path("module", "context_ui") . "/context_ui.css");
drupal_add_js(drupal_get_path("module", "context_ui") . "/context_ui.js");
drupal_add_js(drupal_get_path('module', 'context_ui') . '/jquery.pageEditor.js');
$vars['buttons'] = $vars['form']['buttons'];
unset($vars['form']['buttons']);
}