Add jQuery data table keyboard navigation
This commit is contained in:
@@ -10,6 +10,7 @@ function sportspress_admin_enqueue_scripts( $hook ) {
|
||||
|
||||
wp_enqueue_script( 'jquery' );
|
||||
wp_enqueue_script( 'chosen', SPORTSPRESS_PLUGIN_URL .'assets/js/chosen.jquery.min.js', array( 'jquery' ), '1.1.0', true );
|
||||
wp_enqueue_script( 'caret', SPORTSPRESS_PLUGIN_URL .'assets/js/jquery.caret.min.js', array( 'jquery' ), '1.02', true );
|
||||
|
||||
if ( $hook == 'edit-tags.php' && isset( $_GET['taxonomy'] ) && $_GET['taxonomy'] == 'sp_venue' ):
|
||||
wp_enqueue_script( 'google-maps', 'http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places' );
|
||||
|
||||
@@ -104,6 +104,44 @@ jQuery(document).ready(function($){
|
||||
}
|
||||
});
|
||||
|
||||
// Data table keyboard navigation
|
||||
$(".sp-data-table tbody tr td input").keydown(function(event) {
|
||||
if([37,38,39,40].indexOf(event.keyCode) > -1){
|
||||
$el = $(this).closest("td");
|
||||
var col = $el.parent().children().index($el)+1;
|
||||
var row = $el.parent().parent().children().index($el.parent())+1;
|
||||
if(event.keyCode == 37){
|
||||
if ( $(this).caret().start != 0 )
|
||||
return true;
|
||||
col -= 1;
|
||||
}
|
||||
if(event.keyCode == 38){
|
||||
row -= 1;
|
||||
}
|
||||
if(event.keyCode == 39){
|
||||
if ( $(this).caret().start != $(this).val().length )
|
||||
return true;
|
||||
col += 1;
|
||||
}
|
||||
if(event.keyCode == 40){
|
||||
row += 1;
|
||||
}
|
||||
$el.closest("tbody").find("tr:nth-child("+row+") td:nth-child("+col+") input").focus();
|
||||
}
|
||||
});
|
||||
|
||||
// Prevent data table from submitting form
|
||||
$(".sp-data-table tbody tr td input").keypress(function(event) {
|
||||
if(event.keyCode == 13){
|
||||
event.preventDefault();
|
||||
$el = $(this).closest("td");
|
||||
var col = $el.parent().children().index($el)+1;
|
||||
var row = $el.parent().parent().children().index($el.parent())+2;
|
||||
$el.closest("tbody").find("tr:nth-child("+row+") td:nth-child("+col+") input").focus();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// Total stats calculator
|
||||
$(".sp-data-table .sp-total input").on("updateTotal", function() {
|
||||
index = $(this).parent().index();
|
||||
|
||||
10
assets/js/jquery.caret.min.js
vendored
Normal file
10
assets/js/jquery.caret.min.js
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2010 C. F., Wong (<a href="http://cloudgen.w0ng.hk">Cloudgen Examplet Store</a>)
|
||||
* Licensed under the MIT License:
|
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
*
|
||||
*/
|
||||
(function(k,e,i,j){k.fn.caret=function(b,l){var a,c,f=this[0],d=k.browser.msie;if(typeof b==="object"&&typeof b.start==="number"&&typeof b.end==="number"){a=b.start;c=b.end}else if(typeof b==="number"&&typeof l==="number"){a=b;c=l}else if(typeof b==="string")if((a=f.value.indexOf(b))>-1)c=a+b[e];else a=null;else if(Object.prototype.toString.call(b)==="[object RegExp]"){b=b.exec(f.value);if(b!=null){a=b.index;c=a+b[0][e]}}if(typeof a!="undefined"){if(d){d=this[0].createTextRange();d.collapse(true);
|
||||
d.moveStart("character",a);d.moveEnd("character",c-a);d.select()}else{this[0].selectionStart=a;this[0].selectionEnd=c}this[0].focus();return this}else{if(d){c=document.selection;if(this[0].tagName.toLowerCase()!="textarea"){d=this.val();a=c[i]()[j]();a.moveEnd("character",d[e]);var g=a.text==""?d[e]:d.lastIndexOf(a.text);a=c[i]()[j]();a.moveStart("character",-d[e]);var h=a.text[e]}else{a=c[i]();c=a[j]();c.moveToElementText(this[0]);c.setEndPoint("EndToEnd",a);g=c.text[e]-a.text[e];h=g+a.text[e]}}else{g=
|
||||
f.selectionStart;h=f.selectionEnd}a=f.value.substring(g,h);return{start:g,end:h,text:a,replace:function(m){return f.value.substring(0,g)+m+f.value.substring(h,f.value[e])}}}}})(jQuery,"length","createRange","duplicate");
|
||||
Reference in New Issue
Block a user