wp/wp-includes/js/jquery/jquery.table-hotkeys.js
changeset 18 be944660c56a
parent 5 5e2f62d02dcd
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    12 		return this.filter(is_visible);
    12 		return this.filter(is_visible);
    13 	};
    13 	};
    14 	$.table_hotkeys = function(table, keys, opts) {
    14 	$.table_hotkeys = function(table, keys, opts) {
    15 		opts = $.extend($.table_hotkeys.defaults, opts);
    15 		opts = $.extend($.table_hotkeys.defaults, opts);
    16 		var selected_class, destructive_class, set_current_row, adjacent_row_callback, get_adjacent_row, adjacent_row, prev_row, next_row, check, get_first_row, get_last_row, make_key_callback, first_row;
    16 		var selected_class, destructive_class, set_current_row, adjacent_row_callback, get_adjacent_row, adjacent_row, prev_row, next_row, check, get_first_row, get_last_row, make_key_callback, first_row;
    17 		
    17 
    18 		selected_class = opts.class_prefix + opts.selected_suffix;
    18 		selected_class = opts.class_prefix + opts.selected_suffix;
    19 		destructive_class = opts.class_prefix + opts.destructive_suffix;
    19 		destructive_class = opts.class_prefix + opts.destructive_suffix;
    20 		set_current_row = function (tr) {
    20 		set_current_row = function (tr) {
    21 			if ($.table_hotkeys.current_row) $.table_hotkeys.current_row.removeClass(selected_class);
    21 			if ($.table_hotkeys.current_row) $.table_hotkeys.current_row.removeClass(selected_class);
    22 			tr.addClass(selected_class);
    22 			tr.addClass(selected_class);
    23 			tr[0].scrollIntoView(false);
    23 			tr[0].scrollIntoView(false);
    24 			$.table_hotkeys.current_row = tr;
    24 			$.table_hotkeys.current_row = tr;
    25 		};
    25 		};
    26 		adjacent_row_callback = function(which) {
    26 		adjacent_row_callback = function(which) {
    27 			if (!adjacent_row(which) && $.isFunction(opts[which+'_page_link_cb'])) {
    27 			if (!adjacent_row(which) && typeof opts[which+'_page_link_cb'] === 'function' ) {
    28 				opts[which+'_page_link_cb']();
    28 				opts[which+'_page_link_cb']();
    29 			}
    29 			}
    30 		};
    30 		};
    31 		get_adjacent_row = function(which) {
    31 		get_adjacent_row = function(which) {
    32 			var first_row, method;
    32 			var first_row, method;
    33 			
    33 
    34 			if (!$.table_hotkeys.current_row) {
    34 			if (!$.table_hotkeys.current_row) {
    35 				first_row = get_first_row();
    35 				first_row = get_first_row();
    36 				$.table_hotkeys.current_row = first_row;
    36 				$.table_hotkeys.current_row = first_row;
    37 				return first_row[0];
    37 				return first_row[0];
    38 			}
    38 			}
    63 			return function() {
    63 			return function() {
    64 				if ( null == $.table_hotkeys.current_row ) return false;
    64 				if ( null == $.table_hotkeys.current_row ) return false;
    65 				var clickable = $(expr, $.table_hotkeys.current_row);
    65 				var clickable = $(expr, $.table_hotkeys.current_row);
    66 				if (!clickable.length) return false;
    66 				if (!clickable.length) return false;
    67 				if (clickable.is('.'+destructive_class)) next_row() || prev_row();
    67 				if (clickable.is('.'+destructive_class)) next_row() || prev_row();
    68 				clickable.click();
    68 				clickable.trigger( 'click' );
    69 			};
    69 			};
    70 		};
    70 		};
    71 		first_row = get_first_row();
    71 		first_row = get_first_row();
    72 		if (!first_row.length) return;
    72 		if (!first_row.length) return;
    73 		if (opts.highlight_first)
    73 		if (opts.highlight_first)
    77 		$.hotkeys.add(opts.prev_key, opts.hotkeys_opts, function() {return adjacent_row_callback('prev');});
    77 		$.hotkeys.add(opts.prev_key, opts.hotkeys_opts, function() {return adjacent_row_callback('prev');});
    78 		$.hotkeys.add(opts.next_key, opts.hotkeys_opts, function() {return adjacent_row_callback('next');});
    78 		$.hotkeys.add(opts.next_key, opts.hotkeys_opts, function() {return adjacent_row_callback('next');});
    79 		$.hotkeys.add(opts.mark_key, opts.hotkeys_opts, check);
    79 		$.hotkeys.add(opts.mark_key, opts.hotkeys_opts, check);
    80 		$.each(keys, function() {
    80 		$.each(keys, function() {
    81 			var callback, key;
    81 			var callback, key;
    82 			
    82 
    83 			if ($.isFunction(this[1])) {
    83 			if ( typeof this[1] === 'function' ) {
    84 				callback = this[1];
    84 				callback = this[1];
    85 				key = this[0];
    85 				key = this[0];
    86 				$.hotkeys.add(key, opts.hotkeys_opts, function(event) { return callback(event, $.table_hotkeys.current_row); });
    86 				$.hotkeys.add(key, opts.hotkeys_opts, function(event) { return callback(event, $.table_hotkeys.current_row); });
    87 			} else {
    87 			} else {
    88 				key = this;
    88 				key = this;