Skip to content
Permalink
Browse files

Upgrade Select2

  • Loading branch information...
Luke Carbis
Luke Carbis committed May 30, 2016
1 parent c0024de commit c3f6c65c1bd95cebb26da7f00a720050a9144586
Showing with 12,862 additions and 5,987 deletions.
  1. +11 −52 classes/class-admin.php
  2. +0 −1 classes/class-export.php
  3. +9 −1 classes/class-list-table.php
  4. +0 −15 tests/tests/test-class-admin.php
  5. +49 −58 ui/js/admin.js
  6. +0 −107 ui/lib/select2/CONTRIBUTING.md
  7. +0 −18 ui/lib/select2/LICENSE
  8. +0 −115 ui/lib/select2/README.md
  9. +0 −8 ui/lib/select2/bower.json
  10. +0 −66 ui/lib/select2/component.json
  11. +0 −29 ui/lib/select2/composer.json
  12. +484 −0 ui/lib/select2/css/select2.css
  13. +1 −0 ui/lib/select2/css/select2.min.css
  14. +3 −0 ui/lib/select2/js/i18n/ar.js
  15. +3 −0 ui/lib/select2/js/i18n/az.js
  16. +3 −0 ui/lib/select2/js/i18n/bg.js
  17. +3 −0 ui/lib/select2/js/i18n/ca.js
  18. +3 −0 ui/lib/select2/js/i18n/cs.js
  19. +3 −0 ui/lib/select2/js/i18n/da.js
  20. +3 −0 ui/lib/select2/js/i18n/de.js
  21. +3 −0 ui/lib/select2/js/i18n/el.js
  22. +3 −0 ui/lib/select2/js/i18n/en.js
  23. +3 −0 ui/lib/select2/js/i18n/es.js
  24. +3 −0 ui/lib/select2/js/i18n/et.js
  25. +3 −0 ui/lib/select2/js/i18n/eu.js
  26. +3 −0 ui/lib/select2/js/i18n/fa.js
  27. +3 −0 ui/lib/select2/js/i18n/fi.js
  28. +3 −0 ui/lib/select2/js/i18n/fr.js
  29. +3 −0 ui/lib/select2/js/i18n/gl.js
  30. +3 −0 ui/lib/select2/js/i18n/he.js
  31. +3 −0 ui/lib/select2/js/i18n/hi.js
  32. +3 −0 ui/lib/select2/js/i18n/hr.js
  33. +3 −0 ui/lib/select2/js/i18n/hu.js
  34. +3 −0 ui/lib/select2/js/i18n/id.js
  35. +3 −0 ui/lib/select2/js/i18n/is.js
  36. +3 −0 ui/lib/select2/js/i18n/it.js
  37. +3 −0 ui/lib/select2/js/i18n/ja.js
  38. +3 −0 ui/lib/select2/js/i18n/km.js
  39. +3 −0 ui/lib/select2/js/i18n/ko.js
  40. +3 −0 ui/lib/select2/js/i18n/lt.js
  41. +3 −0 ui/lib/select2/js/i18n/lv.js
  42. +3 −0 ui/lib/select2/js/i18n/mk.js
  43. +3 −0 ui/lib/select2/js/i18n/ms.js
  44. +3 −0 ui/lib/select2/js/i18n/nb.js
  45. +3 −0 ui/lib/select2/js/i18n/nl.js
  46. +3 −0 ui/lib/select2/js/i18n/pl.js
  47. +3 −0 ui/lib/select2/js/i18n/pt-BR.js
  48. +3 −0 ui/lib/select2/js/i18n/pt.js
  49. +3 −0 ui/lib/select2/js/i18n/ro.js
  50. +3 −0 ui/lib/select2/js/i18n/ru.js
  51. +3 −0 ui/lib/select2/js/i18n/sk.js
  52. +3 −0 ui/lib/select2/js/i18n/sr-Cyrl.js
  53. +3 −0 ui/lib/select2/js/i18n/sr.js
  54. +3 −0 ui/lib/select2/js/i18n/sv.js
  55. +3 −0 ui/lib/select2/js/i18n/th.js
  56. +3 −0 ui/lib/select2/js/i18n/tr.js
  57. +3 −0 ui/lib/select2/js/i18n/uk.js
  58. +3 −0 ui/lib/select2/js/i18n/vi.js
  59. +3 −0 ui/lib/select2/js/i18n/zh-CN.js
  60. +3 −0 ui/lib/select2/js/i18n/zh-TW.js
  61. +6,436 −0 ui/lib/select2/js/select2.full.js
  62. +3 −0 ui/lib/select2/js/select2.full.min.js
  63. +5,725 −0 ui/lib/select2/js/select2.js
  64. +3 −0 ui/lib/select2/js/select2.min.js
  65. +0 −20 ui/lib/select2/package.json
  66. +0 −79 ui/lib/select2/release.sh
  67. +0 −87 ui/lib/select2/select2-bootstrap.css
  68. BIN ui/lib/select2/select2-spinner.gif
  69. +0 −692 ui/lib/select2/select2.css
  70. +0 −36 ui/lib/select2/select2.jquery.json
  71. +0 −3,558 ui/lib/select2/select2.js
  72. BIN ui/lib/select2/select2.png
  73. +0 −19 ui/lib/select2/select2_locale_ar.js
  74. +0 −20 ui/lib/select2/select2_locale_az.js
  75. +0 −20 ui/lib/select2/select2_locale_bg.js
  76. +0 −19 ui/lib/select2/select2_locale_ca.js
  77. +0 −51 ui/lib/select2/select2_locale_cs.js
  78. +0 −19 ui/lib/select2/select2_locale_da.js
  79. +0 −18 ui/lib/select2/select2_locale_de.js
  80. +0 −19 ui/lib/select2/select2_locale_el.js
  81. +0 −20 ui/lib/select2/select2_locale_en.js.template
  82. +0 −19 ui/lib/select2/select2_locale_es.js
  83. +0 −19 ui/lib/select2/select2_locale_et.js
  84. +0 −45 ui/lib/select2/select2_locale_eu.js
  85. +0 −21 ui/lib/select2/select2_locale_fa.js
  86. +0 −30 ui/lib/select2/select2_locale_fi.js
  87. +0 −18 ui/lib/select2/select2_locale_fr.js
  88. +0 −45 ui/lib/select2/select2_locale_gl.js
  89. +0 −19 ui/lib/select2/select2_locale_he.js
  90. +0 −24 ui/lib/select2/select2_locale_hr.js
  91. +0 −17 ui/lib/select2/select2_locale_hu.js
  92. +0 −21 ui/lib/select2/select2_locale_id.js
  93. +0 −17 ui/lib/select2/select2_locale_is.js
  94. +0 −17 ui/lib/select2/select2_locale_it.js
  95. +0 −17 ui/lib/select2/select2_locale_ja.js
  96. +0 −19 ui/lib/select2/select2_locale_ka.js
  97. +0 −19 ui/lib/select2/select2_locale_ko.js
  98. +0 −26 ui/lib/select2/select2_locale_lt.js
  99. +0 −19 ui/lib/select2/select2_locale_lv.js
  100. +0 −19 ui/lib/select2/select2_locale_mk.js
  101. +0 −21 ui/lib/select2/select2_locale_ms.js
  102. +0 −22 ui/lib/select2/select2_locale_nb.js
  103. +0 −17 ui/lib/select2/select2_locale_nl.js
  104. +0 −54 ui/lib/select2/select2_locale_pl.js
  105. +0 −18 ui/lib/select2/select2_locale_pt-BR.js
  106. +0 −17 ui/lib/select2/select2_locale_pt-PT.js
  107. +0 −17 ui/lib/select2/select2_locale_ro.js
  108. +0 −19 ui/lib/select2/select2_locale_rs.js
  109. +0 −23 ui/lib/select2/select2_locale_ru.js
  110. +0 −50 ui/lib/select2/select2_locale_sk.js
  111. +0 −19 ui/lib/select2/select2_locale_sv.js
  112. +0 −19 ui/lib/select2/select2_locale_th.js
  113. +0 −20 ui/lib/select2/select2_locale_tr.js
  114. +0 −16 ui/lib/select2/select2_locale_ug-CN.js
  115. +0 −25 ui/lib/select2/select2_locale_uk.js
  116. +0 −20 ui/lib/select2/select2_locale_vi.js
  117. +0 −16 ui/lib/select2/select2_locale_zh-CN.js
  118. +0 −16 ui/lib/select2/select2_locale_zh-TW.js
  119. BIN ui/lib/select2/select2x2.png
@@ -171,15 +171,6 @@ public function __construct( $plugin ) {
// Ajax users list.
add_action( 'wp_ajax_wp_stream_filters', array( $this, 'ajax_filters' ) );
// Ajax user's name by ID.
add_action( 'wp_ajax_wp_stream_get_filter_value_by_id', array( $this, 'get_filter_value_by_id' ) );
// Ajax users list.
add_action( 'wp_ajax_wp_stream_filters', array( $this, 'ajax_filters' ) );
// Ajax user's name by ID.
add_action( 'wp_ajax_wp_stream_get_filter_value_by_id', array( $this, 'get_filter_value_by_id' ) );
}
/**
@@ -347,8 +338,8 @@ public function register_menu() {
* @return void
*/
public function admin_enqueue_scripts( $hook ) {
wp_register_script( 'wp-stream-select2', $this->plugin->locations['url'] . 'ui/lib/select2/select2.js', array( 'jquery' ), '3.5.2', true );
wp_register_style( 'wp-stream-select2', $this->plugin->locations['url'] . 'ui/lib/select2/select2.css', array(), '3.5.2' );
wp_register_script( 'wp-stream-select2', $this->plugin->locations['url'] . 'ui/lib/select2/js/select2.js', array( 'jquery' ), '3.5.2', true );
wp_register_style( 'wp-stream-select2', $this->plugin->locations['url'] . 'ui/lib/select2/css/select2.css', array(), '3.5.2' );
wp_register_script( 'wp-stream-timeago', $this->plugin->locations['url'] . 'ui/lib/timeago/jquery.timeago.js', array(), '1.4.1', true );
$locale = strtolower( substr( get_locale(), 0, 2 ) );
@@ -855,6 +846,12 @@ public function filter_role_caps( $allcaps, $cap, $role ) {
* @action wp_ajax_wp_stream_filters
*/
public function ajax_filters() {
if ( ! defined( 'DOING_AJAX' ) || ! current_user_can( $this->plugin->admin->settings_cap ) ) {
return;
}
check_ajax_referer( 'stream_filters_user_search_nonce', 'nonce' );
switch ( wp_stream_filter_input( INPUT_GET, 'filter' ) ) {
case 'user_id':
$users = array_merge(
@@ -884,47 +881,9 @@ function( $user ) use ( $search ) {
}
if ( isset( $results ) ) {
echo wp_stream_json_encode( array_values( $results ) ); // xss ok
}
if ( defined( 'WP_STREAM_TESTS' ) && WP_STREAM_TESTS ) {
return;
echo wp_stream_json_encode( $results ); // xss ok
}
die();
}
/**
* @action wp_ajax_wp_stream_get_filter_value_by_id
*/
public function get_filter_value_by_id() {
$filter = wp_stream_filter_input( INPUT_POST, 'filter' );
switch ( $filter ) {
case 'user_id':
$id = wp_stream_filter_input( INPUT_POST, 'id' );
if ( '0' === $id ) {
$value = 'WP-CLI';
break;
}
$user = get_userdata( $id );
if ( ! $user || is_wp_error( $user ) ) {
$value = '';
} else {
$value = $user->display_name;
}
break;
default:
$value = '';
}
echo wp_stream_json_encode( $value ); // xss ok
if ( defined( 'WP_STREAM_TESTS' ) && WP_STREAM_TESTS ) {
return;
}
@@ -936,11 +895,11 @@ public function get_users_record_meta( $authors ) {
$authors_records = array();
foreach ( $authors as $user_id => $args ) {
$author = new Author( $user_id );
$author = new Author( $args->ID );
$authors_records[ $user_id ] = array(
'text' => $author->get_display_name(),
'id' => $user_id,
'id' => $author->id,
'label' => $author->get_display_name(),
'icon' => $author->get_avatar_src( 32 ),
'title' => '',
@@ -20,7 +20,6 @@ class Export {
* Class constructor
*
* @param Plugin $plugin The plugin object.
* @return void
*/
public function __construct( $plugin ) {
$this->plugin = $plugin;
@@ -457,7 +457,13 @@ function assemble_records( $column ) {
$total_users = $user_count['total_users'];
if ( $total_users > $this->plugin->admin->preload_users_max ) {
return array();
$selected_user = wp_stream_filter_input( INPUT_GET, 'user_id' );
if ( $selected_user ) {
$user = new Author( $selected_user );
return array( $selected_user => $user->get_display_name() );
} else {
return array();
}
}
$users = array_map(
@@ -621,6 +627,8 @@ function filters_form() {
$filters_string .= sprintf( '<input type="submit" id="record-query-submit" class="button" value="%s" />', __( 'Filter', 'stream' ) );
$filters_string .= wp_nonce_field( 'stream_filters_user_search_nonce', 'stream_filters_user_search_nonce' );
// Parse all query vars into an array
$query_vars = array();
@@ -389,21 +389,6 @@ public function test_ajax_filters() {
$this->assertInternalType( 'array', $data );
}
public function test_get_filter_value_by_id() {
$_POST['filter'] = 'user_id';
$_POST['id'] = get_current_user_id();
ob_start();
$this->admin->get_filter_value_by_id();
$json = ob_get_clean();
$this->assertNotEmpty( $json );
$data = json_decode( $json );
$this->assertNotFalse( $data );
$this->assertNotEmpty( $data );
$this->assertInternalType( 'string', $data );
}
public function test_get_users_record_meta() {
$user_id = get_current_user_id();
$authors = array(
@@ -15,39 +15,39 @@ jQuery( function( $ ) {

$( '.toplevel_page_wp_stream :input.chosen-select' ).each( function( i, el ) {
var args = {},
formatResult = function( record, container ) {
var result = '',
$elem = $( record.element ),
icon = '';

if ( '- ' === record.text.substring( 0, 2 ) ) {
record.text = record.text.substring( 2 );
}

if ( undefined !== record.icon ) {
icon = record.icon;
} else if ( undefined !== $elem.attr( 'data-icon' ) ) {
icon = $elem.data( 'icon' );
}
if ( icon ) {
result += '<img src="' + icon + '" class="wp-stream-select2-icon">';
}

result += record.text;

// Add more info to the container
container.attr( 'title', $elem.attr( 'title' ) );

return result;
},
formatSelection = function( record ) {
if ( '- ' === record.text.substring( 0, 2 ) ) {
record.text = record.text.substring( 2 );
}
return record.text;
};

if ( $( el ).find( 'option' ).length > 0 ) {
formatResult = function( record, container ) {
var result = '',
$elem = $( record.element ),
icon = '';

if ( '- ' === record.text.substring( 0, 2 ) ) {
record.text = record.text.substring( 2 );
}

if ( undefined !== record.icon ) {
icon = record.icon;
} else if ( undefined !== $elem.attr( 'data-icon' ) ) {
icon = $elem.data( 'icon' );
}
if ( icon ) {
result += '<img src="' + icon + '" class="wp-stream-select2-icon">';
}

result += record.text;

// Add more info to the container
container.attr( 'title', $elem.attr( 'title' ) );

return result;
},
formatSelection = function( record ) {
if ( '- ' === record.text.substring( 0, 2 ) ) {
record.text = record.text.substring( 2 );
}
return record.text;
};

if ( $( el ).find( 'option' ).not( ':selected' ).not( ':empty' ).length > 0 ) {
args = {
minimumResultsForSearch: 10,
formatResult: formatResult,
@@ -62,40 +62,31 @@ jQuery( function( $ ) {
width: '165px',
ajax: {
url: ajaxurl,
datatype: 'json',
dataType: 'json',
quietMillis: 100,
data: function( term ) {
return {
action: 'wp_stream_filters',
nonce: $( '#stream_filters_user_search_nonce' ).val(),
filter: $( el ).attr( 'name' ),
q: term
q: term.term
};
},
results: function( data ) {
return { results: data };
processResults: function( data ) {
var results = [];
$.each( data, function( index, item ){
results.push({
id: item.id,
text: item.label
});
});
return {
results: results
};
}
},
formatResult: formatResult,
formatSelection: formatSelection,
initSelection: function( element, callback ) {
var id = $( element ).val();
if ( '' !== id ) {
$.post(
ajaxurl,
{
action: 'wp_stream_get_filter_value_by_id',
filter: $( element ).attr( 'name' ),
id: id
},
function( response ) {
callback({
id: id,
text: response
});
},
'json'
);
}
}
formatSelection: formatSelection
};
}

This file was deleted.

0 comments on commit c3f6c65

Please sign in to comment.
You can’t perform that action at this time.