Browse Source

WIP for bisect.

8.x-1.x
Alexander O'Neill 6 years ago
parent
commit
2e31f62636
  1. 2
      README.md
  2. 5
      bibcite_footnotes.module
  3. 32
      js/plugins/reference_footnotes/dialogs/footnotes.js
  4. 41
      src/Plugin/Filter/ReferenceFootnotesFilter.php

2
README.md

@ -13,7 +13,7 @@ Introduction
------------ ------------
Provides a CKEditor plugin that lets a user select from a list of citations which Provides a CKEditor plugin that lets a user select from a list of citations which
appear in a formatted list at the bottom of the text area that contains endnotes appear in a formatted list at the bottom of the text that contains endnotes
and references. and references.
Installation Installation

5
bibcite_footnotes.module

@ -155,9 +155,6 @@ function bibcite_footnotes_preprocess_bibcite_footnote_list(&$variables) {
$render = FALSE; $render = FALSE;
} }
if ($sort_references_by == 'alphabetical' && $variables['note_type'] == ReferenceFootnotesFilter::REFERENCE) {
usort($notes['#items'], '_bibcite_footnotes_reference_array_cmp');
}
$variables['notes'] = $notes; $variables['notes'] = $notes;
} }
@ -317,7 +314,7 @@ function bibcite_footnotes_get_ckeditor_select_item($entity): array {
/** /**
* Implementation of hook_preprocess_field(). * Implementation of hook_preprocess_field().
* Sor the works cited list by rendered text, which results in author(s) then title. * Sort the works cited list by rendered text, which results in author(s) then title.
* *
* @param $variables * @param $variables
* @param $hook * @param $hook

32
js/plugins/reference_footnotes/dialogs/footnotes.js

@ -66,27 +66,29 @@
} }
], ],
onShow : function() { onShow : function() {
if (isEdit) { if (isEdit) {
this.fakeObj = CKEDITOR.plugins.reference_footnotes.getSelectedFootnote( editor ); this.fakeObj = CKEDITOR.plugins.reference_footnotes.getSelectedFootnote(editor);
this.realObj = editor.restoreRealElement( this.fakeObj ); this.realObj = editor.restoreRealElement(this.fakeObj);
} }
var select = this.parts.contents.$.getElementsByTagName('select'); var select = this.parts.contents.$.getElementsByTagName('select');
var selectBox = select.item(0); var selectBox = select.item(0);
// Remove all but the default 'None' item from teh list. // Remove all but the default 'None' item from teh list.
var i; var i;
for (i = selectBox.options.length - 1 ; i >= 1 ; i--) { for (i = selectBox.options.length - 1; i >= 1; i--) {
selectBox.remove(i) selectBox.remove(i)
} }
// Re-add buttons from the current state of Settings. // Re-add buttons from the current state of Settings.
drupalSettings.bibcite_footnotes.references.forEach(function(reference) { if (typeof (drupalSettings.bibcite_footnotes) !== 'undefined') {
drupalSettings.bibcite_footnotes.references.forEach(function (reference) {
var newReference = document.createElement('option'); var newReference = document.createElement('option');
newReference.text = reference[0]; newReference.text = reference[0];
newReference.setAttribute("value", reference[1]); newReference.setAttribute("value", reference[1]);
selectBox.add(newReference); selectBox.add(newReference);
}); });
}
this.setupContent( this.realObj ); this.setupContent( this.realObj );
}, },
onOk : function() { onOk : function() {
var referenceNote = this.getValueOf('info', 'reference'); var referenceNote = this.getValueOf('info', 'reference');

41
src/Plugin/Filter/ReferenceFootnotesFilter.php

@ -20,14 +20,11 @@ use Drupal\footnotes\Plugin\Filter\FootnotesFilter;
* "footnotes_footnotefootnote_linkcollapse" = FALSE, * "footnotes_footnotefootnote_linkcollapse" = FALSE,
* "footnotes_ibid" = FALSE, * "footnotes_ibid" = FALSE,
* "notes_section_label" = "Notes", * "notes_section_label" = "Notes",
* "references_section_label" = "References"
* }, * },
* weight = 0 * weight = 0
* ) * )
*/ */
class ReferenceFootnotesFilter extends FootnotesFilter { class ReferenceFootnotesFilter extends FootnotesFilter {
const ENDNOTE = 0;
const REFERENCE = 1;
/** /**
* Object with configuration for reference footnotes. * Object with configuration for reference footnotes.
@ -80,34 +77,27 @@ class ReferenceFootnotesFilter extends FootnotesFilter {
]; ];
$settings['notes_section_label'] = [ $settings['notes_section_label'] = [
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Notes section label'), '#title' => t('Notes section heading label'),
'#default_value' => $this->settings['notes_section_label'], '#default_value' => $this->settings['notes_section_label'],
]; ];
$settings['references_section_label'] = [
'#type' => 'textfield',
'#title' => $this->t('References section label'),
'#description' => $this->t('E.g., "Works Cited" for MLA style.'),
'#default_value' => $this->settings['references_section_label'],
];
$settings['reference_dont_show_backlink_text'] = [ $settings['reference_dont_show_backlink_text'] = [
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => $this->t("Don't show note 'value' text in reference list."), '#title' => $this->t("Don't show note 'value' text in reference list."),
'#description' => $this->t("Suitable for MLA-style citations, like (Smith, 33-22)"), '#description' => $this->t("Suitable for MLA-style citations, like (Smith, 33-22)"),
'#default_value' => $this->settings['reference_dont_show_backlink_text'], '#default_value' => $this->settings['reference_dont_show_backlink_text'],
]; ];
$settings['reference_sort_by'] = [ $settings['works_cited_sort_by'] = [
'#type' => 'select', '#type' => 'select',
'#title' => $this->t("Sort references list by"), '#title' => $this->t("Sort Workd Cited list by"),
'#options' => [ '#options' => [
'order' => $this->t("Order in text"), 'weight' => $this->t("Manually"),
'alphabetical' => $this->t("Alphabetical"), 'alphabetical' => $this->t("Alphabetically"),
], ],
'#default_value' => $this->settings['reference_sort_by'], '#default_value' => $this->settings['works_cited_sort_by'],
]; ];
return $settings; return $settings;
} }
/** /**
* Helper function called from preg_replace_callback() above. * Helper function called from preg_replace_callback() above.
* *
@ -320,23 +310,4 @@ class ReferenceFootnotesFilter extends FootnotesFilter {
$prev_reference_id = $fn['reference']; $prev_reference_id = $fn['reference'];
} }
} }
protected function extractNotesByType($type, $footnotes) {
$notes = [];
foreach ($footnotes as $fn) {
switch ($type) {
case self::ENDNOTE:
if (!empty($fn['text'])) {
$notes[] = $fn;
}
break;
case self::REFERENCE:
if (!empty($fn['reference'])) {
$notes[] = $fn;
}
break;
}
}
return $notes;
}
} }

Loading…
Cancel
Save