"),c.on("blur.tt",function(a){var e,f,g;e=document.activeElement,f=d.is(e),g=d.has(e).length>0,b.isMsie()&&(f||g)&&(a.preventDefault(),a.stopImmediatePropagation(),b.defer(function(){c.focus()}))}),d.on("mousedown.tt",function(a){a.preventDefault()})},_onSelectableClicked:function(a,b){this.select(b)},_onDatasetCleared:function(){this._updateHint()},_onDatasetRendered:function(a,b,c,d){if(this._updateHint(),this.autoselect){var e=this.selectors.cursor.substr(1);this.menu.$node.find(this.selectors.suggestion).first().addClass(e)}this.eventBus.trigger("render",b,c,d)},_onAsyncRequested:function(a,b,c){this.eventBus.trigger("asyncrequest",c,b)},_onAsyncCanceled:function(a,b,c){this.eventBus.trigger("asynccancel",c,b)},_onAsyncReceived:function(a,b,c){this.eventBus.trigger("asyncreceive",c,b)},_onFocused:function(){this._minLengthMet()&&this.menu.update(this.input.getQuery())},_onBlurred:function(){this.input.hasQueryChangedSinceLastFocus()&&this.eventBus.trigger("change",this.input.getQuery())},_onEnterKeyed:function(a,b){var c;(c=this.menu.getActiveSelectable())?this.select(c)&&(b.preventDefault(),b.stopPropagation()):this.autoselect&&this.select(this.menu.getTopSelectable())&&(b.preventDefault(),b.stopPropagation())},_onTabKeyed:function(a,b){var c;(c=this.menu.getActiveSelectable())?this.select(c)&&b.preventDefault():this.autoselect&&(c=this.menu.getTopSelectable())&&this.autocomplete(c)&&b.preventDefault()},_onEscKeyed:function(){this.close()},_onUpKeyed:function(){this.moveCursor(-1)},_onDownKeyed:function(){this.moveCursor(1)},_onLeftKeyed:function(){"rtl"===this.dir&&this.input.isCursorAtEnd()&&this.autocomplete(this.menu.getActiveSelectable()||this.menu.getTopSelectable())},_onRightKeyed:function(){"ltr"===this.dir&&this.input.isCursorAtEnd()&&this.autocomplete(this.menu.getActiveSelectable()||this.menu.getTopSelectable())},_onQueryChanged:function(a,b){this._minLengthMet(b)?this.menu.update(b):this.menu.empty()},_onWhitespaceChanged:function(){this._updateHint()},_onLangDirChanged:function(a,b){this.dir!==b&&(this.dir=b,this.menu.setLanguageDirection(b))},_openIfActive:function(){this.isActive()&&this.open()},_minLengthMet:function(a){return a=b.isString(a)?a:this.input.getQuery()||"",a.length>=this.minLength},_updateHint:function(){var a,c,d,e,f,h,i;a=this.menu.getTopSelectable(),c=this.menu.getSelectableData(a),d=this.input.getInputValue(),!c||b.isBlankString(d)||this.input.hasOverflow()?this.input.clearHint():(e=g.normalizeQuery(d),f=b.escapeRegExChars(e),h=new RegExp("^(?:"+f+")(.+$)","i"),(i=h.exec(c.val))&&this.input.setHint(d+i[1]))},isEnabled:function(){return this.enabled},enable:function(){this.enabled=!0},disable:function(){this.enabled=!1},isActive:function(){return this.active},activate:function(){return!!this.isActive()||!(!this.isEnabled()||this.eventBus.before("active"))&&(this.active=!0,this.eventBus.trigger("active"),!0)},deactivate:function(){return!this.isActive()||!this.eventBus.before("idle")&&(this.active=!1,this.close(),this.eventBus.trigger("idle"),!0)},isOpen:function(){return this.menu.isOpen()},open:function(){return this.isOpen()||this.eventBus.before("open")||(this.input.setAriaExpanded(!0),this.menu.open(),this._updateHint(),this.eventBus.trigger("open")),this.isOpen()},close:function(){return this.isOpen()&&!this.eventBus.before("close")&&(this.input.setAriaExpanded(!1),this.menu.close(),this.input.clearHint(),this.input.resetInputValue(),this.eventBus.trigger("close")),!this.isOpen()},setVal:function(a){this.input.setQuery(b.toStr(a))},getVal:function(){return this.input.getQuery()},select:function(a){var b=this.menu.getSelectableData(a);return!(!b||this.eventBus.before("select",b.obj,b.dataset))&&(this.input.setQuery(b.val,!0),this.eventBus.trigger("select",b.obj,b.dataset),this.close(),!0)},autocomplete:function(a){var b,c;return b=this.input.getQuery(),c=this.menu.getSelectableData(a),!(!(c&&b!==c.val)||this.eventBus.before("autocomplete",c.obj,c.dataset))&&(this.input.setQuery(c.val),this.eventBus.trigger("autocomplete",c.obj,c.dataset),!0)},moveCursor:function(a){var b,c,d,e,f,g;return b=this.input.getQuery(),c=this.menu.selectableRelativeToCursor(a),d=this.menu.getSelectableData(c),e=d?d.obj:null,f=d?d.dataset:null,g=c?c.attr("id"):null,this.input.trigger("cursorchange",g),!(this._minLengthMet()&&this.menu.update(b))&&!this.eventBus.before("cursorchange",e,f)&&(this.menu.setCursor(c),d?"string"==typeof d.val&&this.input.setInputValue(d.val):(this.input.resetInputValue(),this._updateHint()),this.eventBus.trigger("cursorchange",e,f),!0)},destroy:function(){this.input.destroy(),this.menu.destroy()}}),c}();!function(){"use strict";function e(b,c){b.each(function(){var b,d=a(this);(b=d.data(q.typeahead))&&c(b,d)})}function f(a,b){return a.clone().addClass(b.classes.hint).removeData().css(b.css.hint).css(m(a)).prop({readonly:!0,required:!1}).removeAttr("id name placeholder").removeClass("required").attr({spellcheck:"false",tabindex:-1})}function h(a,b){a.data(q.attrs,{dir:a.attr("dir"),autocomplete:a.attr("autocomplete"),spellcheck:a.attr("spellcheck"),style:a.attr("style")}),a.addClass(b.classes.input).attr({spellcheck:!1});try{!a.attr("dir")&&a.attr("dir","auto")}catch(a){}return a}function m(a){return{backgroundAttachment:a.css("background-attachment"),backgroundClip:a.css("background-clip"),backgroundColor:a.css("background-color"),backgroundImage:a.css("background-image"),backgroundOrigin:a.css("background-origin"),backgroundPosition:a.css("background-position"),backgroundRepeat:a.css("background-repeat"),backgroundSize:a.css("background-size")}}function n(a){var c,d;c=a.data(q.www),d=a.parent().filter(c.selectors.wrapper),b.each(a.data(q.attrs),function(c,d){b.isUndefined(c)?a.removeAttr(d):a.attr(d,c)}),a.removeData(q.typeahead).removeData(q.www).removeData(q.attr).removeClass(c.classes.input),d.length&&(a.detach().insertAfter(d),d.remove())}function o(c){var d,e;return d=b.isJQuery(c)||b.isElement(c),e=d?a(c).first():[],e.length?e:null}var p,q,r;p=a.fn.typeahead,q={www:"tt-www",attrs:"tt-attrs",typeahead:"tt-typeahead"},r={initialize:function(e,m){function n(){var c,n,r,s,t,u,v,w,x,y,z;b.each(m,function(a){a.highlight=!!e.highlight}),c=a(this),n=a(p.html.wrapper),r=o(e.hint),s=o(e.menu),t=!1!==e.hint&&!r,u=!1!==e.menu&&!s,t&&(r=f(c,p)),u&&(s=a(p.html.menu).css(p.css.menu)),r&&r.val(""),c=h(c,p),(t||u)&&(n.css(p.css.wrapper),c.css(t?p.css.input:p.css.inputWithNoHint),c.wrap(n).parent().prepend(t?r:null).append(u?s:null)),z=u?k:i,v=new d({el:c}),w=new g({hint:r,input:c,menu:s},p),x=new z({node:s,datasets:m},p),new j({$input:c,menu:x}),y=new l({input:w,menu:x,eventBus:v,minLength:e.minLength,autoselect:e.autoselect},p),c.data(q.www,p),c.data(q.typeahead,y)}var p;return m=b.isArray(m)?m:[].slice.call(arguments,1),e=e||{},p=c(e.classNames),this.each(n)},isEnabled:function(){var a;return e(this.first(),function(b){a=b.isEnabled()}),a},enable:function(){return e(this,function(a){a.enable()}),this},disable:function(){return e(this,function(a){a.disable()}),this},isActive:function(){var a;return e(this.first(),function(b){a=b.isActive()}),a},activate:function(){return e(this,function(a){a.activate()}),this},deactivate:function(){return e(this,function(a){a.deactivate()}),this},isOpen:function(){var a;return e(this.first(),function(b){a=b.isOpen()}),a},open:function(){return e(this,function(a){a.open()}),this},close:function(){return e(this,function(a){a.close()}),this},select:function(b){var c=!1,d=a(b);return e(this.first(),function(a){c=a.select(d)}),c},autocomplete:function(b){var c=!1,d=a(b);return e(this.first(),function(a){c=a.autocomplete(d)}),c},moveCursor:function(a){var b=!1;return e(this.first(),function(c){b=c.moveCursor(a)}),b},val:function(a){var c;return arguments.length?(e(this,function(c){c.setVal(b.toStr(a))}),this):(e(this.first(),function(a){c=a.getVal()}),c)},destroy:function(){return e(this,function(a,b){n(b),a.destroy()}),this}},a.fn.typeahead=function(a){return r[a]?r[a].apply(this,[].slice.call(arguments,1)):r.initialize.apply(this,arguments)},a.fn.typeahead.noConflict=function(){return a.fn.typeahead=p,this}}()});
\ No newline at end of file
diff --git a/js/workspace.js b/js/workspace.js
index 07df839..32a2ea2 100644
--- a/js/workspace.js
+++ b/js/workspace.js
@@ -22,8 +22,68 @@
$(function () {
$('#test').html(mm.display_name);
console.log(mm);
+
+ $("#cardloading").attr('src', mm.loading);
+ $("#loading90").attr('src', mm.loading);
+ $("#done").attr('src', mm.done);
+
+ init_clientname_input("#username");
});
+ function clientname_suggestions(){
+ return new Bloodhound({
+ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
+ queryTokenizer: Bloodhound.tokenizers.whitespace,
+ remote: {
+ url: mm.ajax_url + '?' + jQuery.param({
+ _ajax_nonce: mm.nonce, // nonce
+ action: "search_users", // action
+ pattern: "QUERY", // search pattern
+ }),
+ wildcard: 'QUERY' // %QUERY will be replace by users input in
+ }, // the url option.
+ });
+ }
+
+ function onUpdateClientID (e, suggestion)
+ {
+ console.log(suggestion);
+ console.log(e);
+ }
+ function init_clientname_input(selector){
+ //console.log('selector = ' + selector);
+ // init Typeahead
+ jQuery(selector).typeahead(
+ {
+ minLength: 0,
+ highlight: true,
+ hint:false,
+ },
+ {
+ name: 'clientnames',
+ source: clientname_suggestions(), // suggestion engine is passed as the source
+ display: function(item) { // display: 'name' will also work
+ //console.log('display' + item.userid);
+ return item.username;
+ },
+ limit: 5,
+ templates: {
+ suggestion: function(item) {
+ //console.log(item);
+ return '
'+ item.username +'-'+ item.userid +'
';
+ },
+ pending: function (query) {
+ return '

';
+ },
+ },
+ 'updater' : function(item) {
+ //console.log('selected +' + item);
+ return item;
+ }
+ }).bind('typeahead:select', onUpdateClientID
+ ).bind('typeahead:autocomplete', onUpdateClientID);
+ }
+
function errUserName(msg)
{
var el = $("#errUserName");
@@ -34,7 +94,7 @@
}, 2000);
}
-
+ //step1
$(document).on("click", "#step1", function(){
var input = $("#username").val();
if ( input == "" ){
@@ -47,11 +107,20 @@
action: "list_users", // action
client : input,
}, function(response, status, xhr){
- alert(response.id);
+ step2_verify_user(response);
}).fail(function(){
- alert('network error ');
+ errUserName("网络错误,请稍后尝试");
});
});
+ //step2
+ function step2_verify_user(response)
+ {
+ var el = $("#userpass");
+
+ el.slideToggle();
+ }
+
+
})(jQuery);
\ No newline at end of file
diff --git a/member.php b/member.php
index db792ca..d463ed5 100644
--- a/member.php
+++ b/member.php
@@ -32,6 +32,7 @@ class Member{
//
$this->ajax_hook('list_users');
+ $this->ajax_hook('search_users');
}
private function ajax_hook($code, $admin_only = false)
@@ -85,10 +86,13 @@ class Member{
{
//wp_enqueue_style( 'mm', plugins_url('css/workspace.css', __FILE__));
wp_enqueue_script('mm', plugins_url('js/workspace.js', __FILE__), array('jquery', 'jquery-ui-core'));
+ wp_enqueue_script('typeahead', plugins_url('js/typeahead.bundle.min.js', __FILE__), array('jquery'));
wp_localize_script( 'mm', 'mm', array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => $this->nonce, // It is common practice to comma after
'display_name' => wp_get_current_user()->display_name,
+ 'loading' => plugins_url('img/loading.gif', __FILE__),
+ 'done' => plugins_url('img/done.gif', __FILE__),
'anonymous' => !is_user_logged_in(),
) );
}
@@ -96,7 +100,7 @@ class Member{
function ajax_list_users()
{
- check_ajax_referer('medal');
+ //check_ajax_referer('medal');
$client = $_POST['client'];
$url = $_POST["action"];
@@ -111,6 +115,33 @@ class Member{
wp_send_json($response);
}
+ public function ajax_search_users(){
+ //check_ajax_referer('medal');
+ $pattern = $_GET['pattern'];
+
+ $args= array(
+ 'search' => "*$pattern*", // or login or nicename in this example
+ 'search_fields' => array('display_name'),
+ );
+
+ $users = new \WP_User_Query($args);
+ $count = $users->get_total();
+
+ //build response
+ $response = array(
+ 'count' => $count,
+ 'date' => date('Y-m-d H:i:s'),
+ 'users' => array(),
+ );
+ foreach ( $users->results as $u ) {
+ $response['users'][] = array(
+ 'userid' => $u->ID,
+ 'username' => html_entity_decode($u->display_name),
+ );
+ }
+ wp_send_json($response['users']);
+ }
+
}
$mm = new Member();
\ No newline at end of file