From 049c0f8054c9b1c38c60ec7841c3dfe47040b257 Mon Sep 17 00:00:00 2001 From: Chris Hallberg Date: Wed, 21 Sep 2016 17:56:07 -0400 Subject: [PATCH 01/21] Add polyfill. --- .../js/vendor/form-attr-polyfill.js | 77 +++++++++++++++++++ themes/bootstrap3/theme.config.php | 1 + 2 files changed, 78 insertions(+) create mode 100644 themes/bootstrap3/js/vendor/form-attr-polyfill.js diff --git a/themes/bootstrap3/js/vendor/form-attr-polyfill.js b/themes/bootstrap3/js/vendor/form-attr-polyfill.js new file mode 100644 index 00000000000..6a22acd5e51 --- /dev/null +++ b/themes/bootstrap3/js/vendor/form-attr-polyfill.js @@ -0,0 +1,77 @@ +/** + * From http://stackoverflow.com/questions/17742275/polyfill-html5-input-form-attribute/26696165#26696165 + * Recommended by https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-browser-Polyfills + * Adapted to eslint styling and updated detection by Chris Hallberg (@crhallberg) for VuFind + */ +(function formAttrPolyfill($) { + /** + * polyfill for html5 form attr + */ + + // every browser supports except IE + if (typeof document.documentMode == 'undefined') { + // any other browser? skip + return; + } + + /** + * Append a field to a form + * + */ + $.fn.appendField = function appendField(_data) { + var data = (!$.isArray(data) && data.name && data.value) + ? [_data] // wrap data + : _data; + + // for form only + if (!this.is('form')) { + return; + } + + var $form = this; + + // attach new params + $.each(data, function appendFieldEach(i, item) { + $('') + .attr('type', 'hidden') + .attr('name', item.name) + .val(item.value).appendTo($form); + }); + + return $form; + }; + + /** + * Find all input fields with form attribute point to jQuery object + * + */ + $('form[id]').submit(function locateFormAttr(/*e*/) { + // serialize data + var data = $('[form=' + this.id + ']').serializeArray(); + // append data to form + $(this).appendField(data); + }).each(function locateFormAttrEach() { + var form = this, + $fields = $('[form=' + this.id + ']'); + + $fields.filter('button, input').filter('[type=reset],[type=submit]').click(function formAttrButtonSubmit() { + var type = this.type.toLowerCase(); + if (type === 'reset') { + // reset form + form.reset(); + // for elements outside form + $fields.each(function formAttrGatherFieldData() { + this.value = this.defaultValue; + this.checked = this.defaultChecked; + }).filter('select').each(function formAttrGatherSelectData() { + $(this).find('option').each(function formAttrGatherOptionData() { + this.selected = this.defaultSelected; + }); + }); + } else if (type.match(/^submit|image$/i)) { + $(form).appendField({name: this.name, value: this.value}).submit(); + } + }); + }); + +})(jQuery); diff --git a/themes/bootstrap3/theme.config.php b/themes/bootstrap3/theme.config.php index 8ee821b92db..e94e89b7487 100644 --- a/themes/bootstrap3/theme.config.php +++ b/themes/bootstrap3/theme.config.php @@ -15,6 +15,7 @@ 'vendor/bootstrap.min.js', 'vendor/bootstrap-accessibility.min.js', 'vendor/validator.min.js', + 'vendor/form-attr-polyfill.js', // input[form] polyfill, cannot load conditionally, since we need all versions of IE 'autocomplete.js', 'common.js', 'lightbox.js', From 791a0a8863ec3dd244cddb44926204713d9e05d3 Mon Sep 17 00:00:00 2001 From: Chris Hallberg Date: Wed, 21 Sep 2016 18:41:28 -0400 Subject: [PATCH 02/21] Add form attributes to bottom buttons and checkboxes in search. --- module/VuFind/src/VuFind/View/Helper/Root/Record.php | 6 +++++- themes/bootstrap3/templates/record/checkbox.phtml | 4 ++-- .../templates/search/bulk-action-buttons.phtml | 12 ++++++------ themes/bootstrap3/templates/search/list-list.phtml | 4 ++-- themes/bootstrap3/templates/search/results.phtml | 8 ++++---- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/module/VuFind/src/VuFind/View/Helper/Root/Record.php b/module/VuFind/src/VuFind/View/Helper/Root/Record.php index 1054069909e..7dd53c668dd 100644 --- a/module/VuFind/src/VuFind/View/Helper/Root/Record.php +++ b/module/VuFind/src/VuFind/View/Helper/Root/Record.php @@ -410,16 +410,20 @@ public function getSearchResult($view) * Render an HTML checkbox control for the current record. * * @param string $idPrefix Prefix for checkbox HTML ids + * @param string $formAttr ID of form for [form] attribute * * @return string */ - public function getCheckbox($idPrefix = '') + public function getCheckbox($idPrefix = '', $formAttr = false) { static $checkboxCount = 0; $id = $this->driver->getSourceIdentifier() . '|' . $this->driver->getUniqueId(); $context = ['id' => $id, 'count' => $checkboxCount++, 'prefix' => $idPrefix]; + if ($formAttr) { + $context['formAttr'] = $formAttr; + } return $this->contextHelper->renderInContext( 'record/checkbox.phtml', $context ); diff --git a/themes/bootstrap3/templates/record/checkbox.phtml b/themes/bootstrap3/templates/record/checkbox.phtml index e6cba3addf1..f889038dbba 100644 --- a/themes/bootstrap3/templates/record/checkbox.phtml +++ b/themes/bootstrap3/templates/record/checkbox.phtml @@ -1,2 +1,2 @@ - - +formAttr)): ?> form="formAttr ?>"/> +formAttr)): ?> form="formAttr ?>"/> diff --git a/themes/bootstrap3/templates/search/bulk-action-buttons.phtml b/themes/bootstrap3/templates/search/bulk-action-buttons.phtml index 7122165f7c6..f19c97b3441 100644 --- a/themes/bootstrap3/templates/search/bulk-action-buttons.phtml +++ b/themes/bootstrap3/templates/search/bulk-action-buttons.phtml @@ -3,23 +3,23 @@
showBulkOptions) && $this->showBulkOptions): ?> - + idPrefix):?> form="search-cart-form"/> export()->getBulkOptions(); if (count($exportOptions) > 0): ?> - + idPrefix):?> form="search-cart-form"/> - + idPrefix):?> form="search-cart-form"/> userlist()->getMode() !== 'disabled'): ?> - + idPrefix):?> form="search-cart-form"/> showCartControls) && $this->showCartControls): ?> - + idPrefix):?> form="search-cart-form"/>
diff --git a/themes/bootstrap3/templates/search/list-list.phtml b/themes/bootstrap3/templates/search/list-list.phtml index b6adf0cd9e9..a01cfdd9541 100644 --- a/themes/bootstrap3/templates/search/list-list.phtml +++ b/themes/bootstrap3/templates/search/list-list.phtml @@ -7,7 +7,7 @@
@@ -16,4 +16,4 @@
record($current)->getSearchResult('list')?> - \ No newline at end of file + diff --git a/themes/bootstrap3/templates/search/results.phtml b/themes/bootstrap3/templates/search/results.phtml index c0fb8203084..5583dbf9843 100644 --- a/themes/bootstrap3/templates/search/results.phtml +++ b/themes/bootstrap3/templates/search/results.phtml @@ -109,12 +109,12 @@ -
+ context($this)->renderInContext('search/bulk-action-buttons.phtml', array('idPrefix' => ''))?> - render('search/list-' . $this->params->getView() . '.phtml')?> - context($this)->renderInContext('search/bulk-action-buttons.phtml', array('idPrefix' => 'bottom_'))?> - paginationControl($this->results->getPaginator(), 'Sliding', 'search/pagination.phtml', array('results' => $this->results, 'options' => isset($this->paginationOptions) ? $this->paginationOptions : []))?>
+ render('search/list-' . $this->params->getView() . '.phtml')?> + context($this)->renderInContext('search/bulk-action-buttons.phtml', array('idPrefix' => 'bottom_'))?> + paginationControl($this->results->getPaginator(), 'Sliding', 'search/pagination.phtml', array('results' => $this->results, 'options' => isset($this->paginationOptions) ? $this->paginationOptions : []))?>
transEsc('Search Tools')?>: From 67d5f0c9cdb11653a2144085187bc2f16580cdde Mon Sep 17 00:00:00 2001 From: Chris Hallberg Date: Wed, 21 Sep 2016 18:52:08 -0400 Subject: [PATCH 03/21] Adjust checkbox-select-all to allow for [form] attributes. --- themes/bootstrap3/js/common.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/themes/bootstrap3/js/common.js b/themes/bootstrap3/js/common.js index 0380d9ea3b8..801616a2c5a 100644 --- a/themes/bootstrap3/js/common.js +++ b/themes/bootstrap3/js/common.js @@ -303,10 +303,20 @@ $(document).ready(function commonDocReady() { // Checkbox select all $('.checkbox-select-all').change(function selectAllCheckboxes() { - $(this).closest('form').find('.checkbox-select-item').prop('checked', this.checked); + var $form = $(this).closest('form') + $form.find('.checkbox-select-item').prop('checked', this.checked); + $('[form="'+$form.attr('id')+'"]').prop('checked', this.checked); }); $('.checkbox-select-item').change(function selectAllDisable() { - $(this).closest('form').find('.checkbox-select-all').prop('checked', false); + var $form = $(this).closest('form'); + if ($form.length === 0 && this.form) { + $form = $(this.form); + } + if ($form.length === 0) { + return; + } + $form.find('.checkbox-select-all').prop('checked', false); + $('.checkbox-select-all[form="'+$form.attr('id')+'"]').prop('checked', false); }); // handle QR code links From fc0e2bc737483565a12a20905b56e804439dbd63 Mon Sep 17 00:00:00 2001 From: Chris Hallberg Date: Thu, 22 Sep 2016 10:59:12 -0400 Subject: [PATCH 04/21] Adjust unit test. --- .../unit-tests/src/VuFindTest/View/Helper/Root/RecordTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/RecordTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/RecordTest.php index 32434ba4980..33121548b7d 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/RecordTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/RecordTest.php @@ -271,10 +271,10 @@ public function testGetCheckbox() { $context = $this->getMockContext(); $context->expects($this->at(1))->method('renderInContext') - ->with($this->equalTo('record/checkbox.phtml'), $this->equalTo(['id' => 'Solr|000105196', 'count' => 0, 'prefix' => 'bar'])) + ->with($this->equalTo('record/checkbox.phtml'), $this->equalTo(['id' => 'Solr|000105196', 'count' => 0, 'prefix' => 'bar', 'formAttr' => 'foo'])) ->will($this->returnValue('success')); $context->expects($this->at(2))->method('renderInContext') - ->with($this->equalTo('record/checkbox.phtml'), $this->equalTo(['id' => 'Solr|000105196', 'count' => 1, 'prefix' => 'bar'])) + ->with($this->equalTo('record/checkbox.phtml'), $this->equalTo(['id' => 'Solr|000105196', 'count' => 1, 'prefix' => 'bar', 'formAttr' => 'foo'])) ->will($this->returnValue('success')); $record = $this->getRecord( $this->loadRecordFixture('testbug1.json'), [], $context From 246b2c4b3993f795d3552c8c7bb851d5c7ad5f56 Mon Sep 17 00:00:00 2001 From: Chris Hallberg Date: Thu, 22 Sep 2016 11:03:49 -0400 Subject: [PATCH 05/21] Remove magic script form retention hack. --- module/VuFind/src/VuFind/Service/ReCaptcha.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/VuFind/src/VuFind/Service/ReCaptcha.php b/module/VuFind/src/VuFind/Service/ReCaptcha.php index 2a8ff092584..a8152779436 100644 --- a/module/VuFind/src/VuFind/Service/ReCaptcha.php +++ b/module/VuFind/src/VuFind/Service/ReCaptcha.php @@ -66,7 +66,7 @@ public function getHtml($name = null) $divregex = '/]*id=[\'"]recaptcha_widget[\'"][^>]*>/'; $scriptRegex = '|]*>|'; - $scriptReplacement = ''; + $scriptReplacement = ''; // remove return preg_replace( [$divregex, $scriptRegex], From 233e16fcd31e06267f65725b6421cc57be0426a4 Mon Sep 17 00:00:00 2001 From: Chris Hallberg Date: Thu, 22 Sep 2016 11:14:55 -0400 Subject: [PATCH 06/21] Expand _clickedButton logic in lightbox to include [form] attrs. --- themes/bootstrap3/js/lightbox.js | 6 +++++- .../bootstrap3/templates/search/bulk-action-buttons.phtml | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/themes/bootstrap3/js/lightbox.js b/themes/bootstrap3/js/lightbox.js index 350dc71f491..e2a1a79252f 100644 --- a/themes/bootstrap3/js/lightbox.js +++ b/themes/bootstrap3/js/lightbox.js @@ -299,7 +299,11 @@ VuFind.register('lightbox', function Lightbox() { // Handle submit buttons attached to a form as well as those in a form. Store // information about which button was clicked here as checking focused button // doesn't work on all browsers and platforms. - $('form[data-lightbox] [type=submit]').click(_storeClickedStatus); + $('form[data-lightbox]').each(function bindFormSubmitsLightbox(i, form) { + console.log(form); + $(form).find('[type=submit]').click(_storeClickedStatus); + $('[type="submit"][form="' + form.id + '"]').click(_storeClickedStatus); + }); } function reset() { diff --git a/themes/bootstrap3/templates/search/bulk-action-buttons.phtml b/themes/bootstrap3/templates/search/bulk-action-buttons.phtml index f19c97b3441..f5950621ff5 100644 --- a/themes/bootstrap3/templates/search/bulk-action-buttons.phtml +++ b/themes/bootstrap3/templates/search/bulk-action-buttons.phtml @@ -1,6 +1,6 @@ showBulkOptions) && $this->showBulkOptions) || (isset($this->showCartControls) && $this->showCartControls)): ?> -
+