2009-09-11 13:30:49 +00:00
|
|
|
(function ($) {
|
|
|
|
|
2012-05-08 02:57:33 +00:00
|
|
|
"use strict";
|
|
|
|
|
2009-09-11 13:30:49 +00:00
|
|
|
/**
|
|
|
|
* Auto-hide summary textarea if empty and show hide and unhide links.
|
|
|
|
*/
|
2009-11-29 20:45:17 +00:00
|
|
|
Drupal.behaviors.textSummary = {
|
2009-09-11 13:30:49 +00:00
|
|
|
attach: function (context, settings) {
|
2012-04-07 07:19:30 +00:00
|
|
|
$(context).find('.text-summary').once('text-summary', function () {
|
2012-05-01 03:43:16 +00:00
|
|
|
var $widget = $(this).closest('.text-format-wrapper');
|
2009-09-11 13:30:49 +00:00
|
|
|
|
2012-05-01 03:43:16 +00:00
|
|
|
var $summary = $widget.find('.text-summary-wrapper');
|
|
|
|
var $summaryLabel = $summary.find('label');
|
|
|
|
var $full = $widget.find('.text-full').closest('.form-item');
|
|
|
|
var $fullLabel = $full.find('label');
|
2010-06-12 08:18:59 +00:00
|
|
|
|
2012-05-01 03:43:16 +00:00
|
|
|
// Create a placeholder label when the field cardinality is greater
|
|
|
|
// than 1.
|
|
|
|
if ($fullLabel.length === 0) {
|
|
|
|
$fullLabel = $('<label></label>').prependTo($full);
|
|
|
|
}
|
2010-06-12 08:18:59 +00:00
|
|
|
|
2012-05-01 03:43:16 +00:00
|
|
|
// Set up the edit/hide summary link.
|
2013-04-13 03:25:44 +00:00
|
|
|
var $link = $('<span class="field-edit-link"> (<button type="button" class="link link-edit-summary">' + Drupal.t('Hide summary') + '</button>)</span>');
|
|
|
|
var $button = $link.find('button');
|
2013-04-09 20:58:51 +00:00
|
|
|
var toggleClick = true;
|
|
|
|
$link.on('click', function (e) {
|
|
|
|
if (toggleClick) {
|
2012-05-01 03:43:16 +00:00
|
|
|
$summary.hide();
|
2013-04-13 03:25:44 +00:00
|
|
|
$button.html(Drupal.t('Edit summary'));
|
2012-05-01 03:43:16 +00:00
|
|
|
$link.appendTo($fullLabel);
|
2013-04-09 20:58:51 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-05-01 03:43:16 +00:00
|
|
|
$summary.show();
|
2013-04-13 03:25:44 +00:00
|
|
|
$button.html(Drupal.t('Hide summary'));
|
2012-05-01 03:43:16 +00:00
|
|
|
$link.appendTo($summaryLabel);
|
2010-06-12 08:18:59 +00:00
|
|
|
}
|
2013-04-09 20:58:51 +00:00
|
|
|
e.preventDefault();
|
|
|
|
toggleClick = !toggleClick;
|
|
|
|
}).appendTo($summaryLabel);
|
2012-05-01 03:43:16 +00:00
|
|
|
|
|
|
|
// If no summary is set, hide the summary field.
|
|
|
|
if ($widget.find('.text-summary').val() === '') {
|
|
|
|
$link.click();
|
|
|
|
}
|
2009-09-11 13:30:49 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
})(jQuery);
|