From 2e31f62636e004f6813b7102f63fe0668ff16e6b Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Fri, 12 Apr 2019 03:40:51 -0300 Subject: [PATCH] WIP for bisect. --- README.md | 2 +- bibcite_footnotes.module | 5 +-- .../reference_footnotes/dialogs/footnotes.js | 32 ++++++++------- .../Filter/ReferenceFootnotesFilter.php | 41 +++---------------- 4 files changed, 25 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index ed513be..7c0fe1d 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Introduction ------------ 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. Installation diff --git a/bibcite_footnotes.module b/bibcite_footnotes.module index 37ea5f6..274c79f 100644 --- a/bibcite_footnotes.module +++ b/bibcite_footnotes.module @@ -155,9 +155,6 @@ function bibcite_footnotes_preprocess_bibcite_footnote_list(&$variables) { $render = FALSE; } - if ($sort_references_by == 'alphabetical' && $variables['note_type'] == ReferenceFootnotesFilter::REFERENCE) { - usort($notes['#items'], '_bibcite_footnotes_reference_array_cmp'); - } $variables['notes'] = $notes; } @@ -317,7 +314,7 @@ function bibcite_footnotes_get_ckeditor_select_item($entity): array { /** * 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 $hook diff --git a/js/plugins/reference_footnotes/dialogs/footnotes.js b/js/plugins/reference_footnotes/dialogs/footnotes.js index bb5b37c..f844e82 100644 --- a/js/plugins/reference_footnotes/dialogs/footnotes.js +++ b/js/plugins/reference_footnotes/dialogs/footnotes.js @@ -66,27 +66,29 @@ } ], onShow : function() { - if (isEdit) { - this.fakeObj = CKEDITOR.plugins.reference_footnotes.getSelectedFootnote( editor ); - this.realObj = editor.restoreRealElement( this.fakeObj ); - } - var select = this.parts.contents.$.getElementsByTagName('select'); - var selectBox = select.item(0); - // Remove all but the default 'None' item from teh list. - var i; - for (i = selectBox.options.length - 1 ; i >= 1 ; i--) { - selectBox.remove(i) - } + if (isEdit) { + this.fakeObj = CKEDITOR.plugins.reference_footnotes.getSelectedFootnote(editor); + this.realObj = editor.restoreRealElement(this.fakeObj); + } + var select = this.parts.contents.$.getElementsByTagName('select'); + var selectBox = select.item(0); + // Remove all but the default 'None' item from teh list. + var i; + for (i = selectBox.options.length - 1; i >= 1; i--) { + selectBox.remove(i) + } - // Re-add buttons from the current state of Settings. - drupalSettings.bibcite_footnotes.references.forEach(function(reference) { + // Re-add buttons from the current state of Settings. + if (typeof (drupalSettings.bibcite_footnotes) !== 'undefined') { + + drupalSettings.bibcite_footnotes.references.forEach(function (reference) { var newReference = document.createElement('option'); newReference.text = reference[0]; newReference.setAttribute("value", reference[1]); selectBox.add(newReference); }); - - this.setupContent( this.realObj ); + } + this.setupContent( this.realObj ); }, onOk : function() { var referenceNote = this.getValueOf('info', 'reference'); diff --git a/src/Plugin/Filter/ReferenceFootnotesFilter.php b/src/Plugin/Filter/ReferenceFootnotesFilter.php index e803055..6890717 100644 --- a/src/Plugin/Filter/ReferenceFootnotesFilter.php +++ b/src/Plugin/Filter/ReferenceFootnotesFilter.php @@ -20,14 +20,11 @@ use Drupal\footnotes\Plugin\Filter\FootnotesFilter; * "footnotes_footnotefootnote_linkcollapse" = FALSE, * "footnotes_ibid" = FALSE, * "notes_section_label" = "Notes", - * "references_section_label" = "References" * }, * weight = 0 * ) */ class ReferenceFootnotesFilter extends FootnotesFilter { - const ENDNOTE = 0; - const REFERENCE = 1; /** * Object with configuration for reference footnotes. @@ -80,34 +77,27 @@ class ReferenceFootnotesFilter extends FootnotesFilter { ]; $settings['notes_section_label'] = [ '#type' => 'textfield', - '#title' => t('Notes section label'), + '#title' => t('Notes section heading 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'] = [ '#type' => 'checkbox', '#title' => $this->t("Don't show note 'value' text in reference list."), '#description' => $this->t("Suitable for MLA-style citations, like (Smith, 33-22)"), '#default_value' => $this->settings['reference_dont_show_backlink_text'], ]; - $settings['reference_sort_by'] = [ + $settings['works_cited_sort_by'] = [ '#type' => 'select', - '#title' => $this->t("Sort references list by"), + '#title' => $this->t("Sort Workd Cited list by"), '#options' => [ - 'order' => $this->t("Order in text"), - 'alphabetical' => $this->t("Alphabetical"), + 'weight' => $this->t("Manually"), + 'alphabetical' => $this->t("Alphabetically"), ], - '#default_value' => $this->settings['reference_sort_by'], + '#default_value' => $this->settings['works_cited_sort_by'], ]; return $settings; } - /** * Helper function called from preg_replace_callback() above. * @@ -320,23 +310,4 @@ class ReferenceFootnotesFilter extends FootnotesFilter { $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; - } }