mirror of
https://github.com/processwire/processwire.git
synced 2025-08-11 17:24:46 +02:00
Update inputfields.js so that you can specify #find-fieldName as a URL fragment on pages containing an InputfieldForm and it will locate and highlight the field identified by fieldName. Also update $page->editUrl() function to accept a field name to find in the page editor, which uses the inputfields.js #find-fieldName added in this commit, i.e. $page->editUrl('body');
This commit is contained in:
@@ -3295,9 +3295,10 @@ class Page extends WireData implements \Countable, WireMatchable {
|
|||||||
*
|
*
|
||||||
* #pw-group-urls
|
* #pw-group-urls
|
||||||
*
|
*
|
||||||
* @param array|bool $options Specify boolean true to force URL to include scheme and hostname, or use $options array:
|
* @param array|bool|string $options Specify true for http option, specify name of field to find (3.0.151+), or use $options array:
|
||||||
* - `http` (bool): True to force scheme and hostname in URL (default=auto detect).
|
* - `http` (bool): True to force scheme and hostname in URL (default=auto detect).
|
||||||
* - `language` (Language|bool): Optionally specify Language to start editor in, or boolean true to force current user language.
|
* - `language` (Language|bool): Optionally specify Language to start editor in, or boolean true to force current user language.
|
||||||
|
* - `find` (string): Name of field to find in the editor (3.0.151+)
|
||||||
* @return string URL for editing this page
|
* @return string URL for editing this page
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -3327,6 +3328,18 @@ class Page extends WireData implements \Countable, WireMatchable {
|
|||||||
}
|
}
|
||||||
$append = $this->wire('session')->getFor($this, 'appendEditUrl');
|
$append = $this->wire('session')->getFor($this, 'appendEditUrl');
|
||||||
if($append) $url .= $append;
|
if($append) $url .= $append;
|
||||||
|
|
||||||
|
if($options) {
|
||||||
|
if(is_string($options)) {
|
||||||
|
$find = $options;
|
||||||
|
} else if(is_array($options) && !empty($options['find'])) {
|
||||||
|
$find = $options['find'];
|
||||||
|
} else $find = '';
|
||||||
|
if($find && strpos($url, '#') === false) {
|
||||||
|
$url .= '#find-' . $this->wire('sanitizer')->fieldName($find);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -448,23 +448,26 @@ var Inputfields = {
|
|||||||
* @param $inputfield
|
* @param $inputfield
|
||||||
* @param bool highlight Highlight temporily once found? (default=true)
|
* @param bool highlight Highlight temporily once found? (default=true)
|
||||||
* @param function callback Optional function to call upon completion
|
* @param function callback Optional function to call upon completion
|
||||||
|
* @param int level Recursion level (do not specify, for internal use only)
|
||||||
* @return Returns the Inputfield element
|
* @return Returns the Inputfield element
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
find: function($inputfield, highlight, callback) {
|
find: function($inputfield, highlight, callback, level) {
|
||||||
|
|
||||||
$inputfield = this.inputfield($inputfield);
|
$inputfield = this.inputfield($inputfield);
|
||||||
if(!$inputfield.length) return $inputfield;
|
if(!$inputfield.length) return $inputfield;
|
||||||
if(typeof highlight == "undefined") highlight = true;
|
if(typeof highlight == "undefined") highlight = true;
|
||||||
var Inputfields = this;
|
if(typeof level == "undefined") level = 0;
|
||||||
|
|
||||||
// locate th Inputfield
|
// locate the Inputfield
|
||||||
if($inputfield.hasClass('InputfieldStateCollapsed') || !$inputfield.is(':visible')) {
|
if($inputfield.hasClass('InputfieldStateCollapsed') || !$inputfield.is(':visible')) {
|
||||||
var hasNoFocus = $inputfield.hasClass('InputfieldNoFocus');
|
var hasNoFocus = $inputfield.hasClass('InputfieldNoFocus');
|
||||||
// Inputfields.toggle() can call Inputfields.focus(), so prevent the focus by adding this class
|
// Inputfields.toggle() can call Inputfields.focus(), so prevent the focus by adding this class
|
||||||
if(!hasNoFocus) $inputfield.addClass('InputfieldNoFocus');
|
if(!hasNoFocus) $inputfield.addClass('InputfieldNoFocus');
|
||||||
this.toggle($inputfield, true, 0, function($in, open, duration) {
|
this.toggle($inputfield, true, 0, function($in, open, duration) {
|
||||||
Inputfields.find($inputfield, callback);
|
if(level > 9) return;
|
||||||
|
var timeout = level > 0 ? 10 * level : 0;
|
||||||
|
setTimeout(function() { Inputfields.find($inputfield, highlight, callback, level + 1); }, timeout);
|
||||||
});
|
});
|
||||||
// remove the class we added
|
// remove the class we added
|
||||||
if(!hasNoFocus) $inputfield.removeClass('InputfieldNoFocus');
|
if(!hasNoFocus) $inputfield.removeClass('InputfieldNoFocus');
|
||||||
@@ -757,7 +760,42 @@ var Inputfields = {
|
|||||||
$inputfield = $inputfield.closest('.Inputfield');
|
$inputfield = $inputfield.closest('.Inputfield');
|
||||||
}
|
}
|
||||||
return $inputfield;
|
return $inputfield;
|
||||||
}
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute find, focus or highlight action from URL fragment/hash
|
||||||
|
*
|
||||||
|
* #find-field_name
|
||||||
|
* #focus-field_name
|
||||||
|
* #highlight-field_name
|
||||||
|
*
|
||||||
|
* @param hash
|
||||||
|
* @since 3.0.151
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
hashAction: function(hash) {
|
||||||
|
|
||||||
|
var pos, action, name;
|
||||||
|
|
||||||
|
if(hash.indexOf('#') === 0) hash = hash.substring(1);
|
||||||
|
pos = hash.indexOf('-');
|
||||||
|
if(pos < 3 || hash.length < pos + 2) return;
|
||||||
|
if(jQuery('#' + hash).length) return; // maps to existing element ID attribute
|
||||||
|
|
||||||
|
action = hash.substring(0, pos);
|
||||||
|
name = hash.substring(pos + 1);
|
||||||
|
|
||||||
|
if(action === 'find') {
|
||||||
|
Inputfields.find(name);
|
||||||
|
} else if(action === 'focus') {
|
||||||
|
Inputfields.focus(name);
|
||||||
|
} else if(action === 'highlight') {
|
||||||
|
Inputfields.highlight(name);
|
||||||
|
} else {
|
||||||
|
// some other action we do not recognize
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -2194,6 +2232,10 @@ jQuery(document).ready(function($) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(window.location.hash) {
|
||||||
|
Inputfields.hashAction(window.location.hash.substring(1));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// for testing:
|
// for testing:
|
||||||
$(document).on('reloaded', '.Inputfield', function(event) {
|
$(document).on('reloaded', '.Inputfield', function(event) {
|
||||||
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user