-
Notifications
You must be signed in to change notification settings - Fork 359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Form attribute support #802
Changes from 19 commits
049c0f8
791a0a8
67d5f0c
fc0e2bc
67fe24f
246b2c4
233e16f
ecdf8f0
f6e44e2
9b5572e
ceeb2a6
2d5763d
b228715
655f8c9
f1c6954
26db220
f158fee
3fb1d45
328cc82
4fb2cae
0088e6c
6ac9da3
fea6d6b
9d8d7bf
25fdfdf
649347a
e97311f
bc5be43
0fe706d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* 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; | ||
} | ||
|
||
$(document).ready(function formAttrReady() { | ||
/** | ||
* 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) { | ||
$('<input/>') | ||
.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); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
<input class="checkbox-select-item" type="checkbox" name="ids[]" value="<?=$this->escapeHtmlAttr($this->id) ?>"/> | ||
<input type="hidden" name="idsAll[]" value="<?=$this->escapeHtmlAttr($this->id) ?>"/> | ||
<input class="checkbox-select-item" type="checkbox" name="ids[]" value="<?=$this->escapeHtmlAttr($this->id) ?>"<? if(isset($this->formAttr)): ?> form="<?=$this->formAttr ?>"<? endif; ?>/> | ||
<input type="hidden" name="idsAll[]" value="<?=$this->escapeHtmlAttr($this->id) ?>"<? if(isset($this->formAttr)): ?> form="<?=$this->formAttr ?>"<? endif; ?>/> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
<? if((isset($this->showBulkOptions) && $this->showBulkOptions) | ||
|| (isset($this->showCartControls) && $this->showCartControls)): ?> | ||
<div class="bulkActionButtons hidden-print"> | ||
<div class="bulkActionButtons hidden-print<?if($this->idPrefix):?> form-inline<? endif; ?>"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think it might make more sense to include a separate attribute for form name, rather than checking idPrefix? We can rely on idPrefix based on current usage, but it's not really an intuitively logical trigger for form attribute functionality. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like you've changed most of the new idPrefix checks to formAttr checks, except for the one right above these comments. Is that intentional or a typo? |
||
<div class="checkbox"> | ||
<label> | ||
<input type="checkbox" class="checkbox-select-all" name="selectAll" id="<?=$this->idPrefix?>addFormCheckboxSelectAll"/> <?=$this->transEsc('select_page')?> | ||
<input type="checkbox" class="checkbox-select-all" name="selectAll" id="<?=$this->idPrefix?>addFormCheckboxSelectAll"<?if($this->formAttr):?> form="<?=$this->escapeHtmlAttr($this->formAttr) ?>"<? endif; ?>/> <?=$this->transEsc('select_page')?> | ||
| <?=$this->transEsc('with_selected')?>: | ||
</label> | ||
</div> | ||
<div class="btn-group"> | ||
<? if (isset($this->showBulkOptions) && $this->showBulkOptions): ?> | ||
<input id="ribbon-email" class="btn btn-default" type="submit" name="email" title="<?=$this->transEsc('bookbag_email_selected')?>" value="<?=$this->transEsc('Email')?>"/> | ||
<input id="ribbon-email" class="btn btn-default" type="submit" name="email" title="<?=$this->transEsc('bookbag_email_selected')?>" value="<?=$this->transEsc('Email')?>"<?if($this->formAttr):?> form="<?=$this->escapeHtmlAttr($this->formAttr) ?>"<? endif; ?>/> | ||
<? $exportOptions = $this->export()->getBulkOptions(); if (count($exportOptions) > 0): ?> | ||
<input id="ribbon-export" class="btn btn-default" type="submit" name="export" title="<?=$this->transEsc('bookbag_export_selected')?>" value="<?=$this->transEsc('Export')?>"/> | ||
<input id="ribbon-export" class="btn btn-default" type="submit" name="export" title="<?=$this->transEsc('bookbag_export_selected')?>" value="<?=$this->transEsc('Export')?>"<?if($this->formAttr):?> form="<?=$this->escapeHtmlAttr($this->formAttr) ?>"<? endif; ?>/> | ||
<? endif; ?> | ||
<input id="ribbon-print" class="btn btn-default" type="submit" name="print" title="<?=$this->transEsc('bookbag_print_selected')?>" value="<?=$this->transEsc('Print')?>"/> | ||
<input id="ribbon-print" class="btn btn-default" type="submit" name="print" title="<?=$this->transEsc('bookbag_print_selected')?>" value="<?=$this->transEsc('Print')?>"<?if($this->formAttr):?> form="<?=$this->escapeHtmlAttr($this->formAttr) ?>"<? endif; ?>/> | ||
<? if ($this->userlist()->getMode() !== 'disabled'): ?> | ||
<input id="ribbon-save" class="btn btn-default" type="submit" name="saveCart" title="<?=$this->transEsc('bookbag_save_selected')?>" value="<?=$this->transEsc('Save')?>"/> | ||
<input id="ribbon-save" class="btn btn-default" type="submit" name="saveCart" title="<?=$this->transEsc('bookbag_save_selected')?>" value="<?=$this->transEsc('Save')?>"<?if($this->formAttr):?> form="<?=$this->escapeHtmlAttr($this->formAttr) ?>"<? endif; ?>/> | ||
<? endif; ?> | ||
<? endif; ?> | ||
<? if (isset($this->showCartControls) && $this->showCartControls): ?> | ||
<input id="<?=$this->idPrefix?>updateCart" type="submit" class="btn btn-default" name="add" value="<?=$this->transEsc('Add to Book Bag')?>"/> | ||
<input id="<?=$this->idPrefix?>updateCart" type="submit" class="btn btn-default" name="add" value="<?=$this->transEsc('Add to Book Bag')?>"<?if($this->formAttr):?> form="<?=$this->escapeHtmlAttr($this->formAttr) ?>"<? endif; ?>/> | ||
<? endif; ?> | ||
</div> | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this really belong in the vendor directory if you wrote it? At very least, should it get its own repo somewhere in addition to being dropped here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not write it, I found it online and updated it. I think maybe we need a new folder for the elements that stand alone, but are custom to VuFind. They exist between vendor and regular scripting. Like autocomplete and the new channels slider. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might "lib" be an appropriate directory name for this sort of thing? |
||
'autocomplete.js', | ||
'common.js', | ||
'lightbox.js', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This captcha-related change appears to pop up several times in this PR. Is this related to the form change, or is this an unrelated improvement? Do we perhaps want a
resetReCaptcha(form)
function in common.js so we don't have to repeat the same four lines of code multiple times, or is that overkill?