diff --git a/.gitignore b/.gitignore index 76da9d48..cf50acb3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ doc/ node_modules/ spec/javascripts/*.js _* +*.sublime* +CakeFile +.DS_Store diff --git a/src/jquery.atwho.coffee b/src/jquery.atwho.coffee index 906e8436..d101b157 100644 --- a/src/jquery.atwho.coffee +++ b/src/jquery.atwho.coffee @@ -70,6 +70,7 @@ ESC: 27 TAB: 9 ENTER: 13 + SHIFT: 16 # Controller 用于处理渲染数据的一组方法. #为了方便开发者可以自定义插件的部分功能而独立出来. @@ -102,7 +103,9 @@ # # @return [String] 匹配后得到的字符串 matcher: (flag, subtext) -> - regexp = new RegExp flag+'([A-Za-z0-9_\+\-]*)$|'+flag+'([^\\x00-\\xff]*)$','gi' + #排除email格式地址 + preFlag = "(?:[\\W]"+flag+"|^"+flag+")" + regexp = new RegExp preFlag+'([A-Za-z0-9_\+\-]*)$|'+preFlag+'([^\\x00-\\xff]*)$','gi' match = regexp.exec subtext matched = null if match @@ -187,7 +190,7 @@ class Controller # @param inputor [HTML DOM Object] 输入框 - constructor: (inputor) -> + constructor: (inputor,reg,options) -> @settings = {} @common_settings = {} @pos = 0 @@ -197,20 +200,21 @@ @$inputor = $(inputor) @mirror = new Mirror(@$inputor) - @common_settings = $.extend {}, $.fn.atWho.default + @common_settings = $.extend {}, $.fn.atwho.default + @reg reg ,options @view = new View(this, @$el) this.listen() # 绑定对输入框的各种监听事件 listen: -> @$inputor - .on 'keyup.atWho', (e) => + .on 'keyup.atwho', (e) => this.on_keyup(e) - .on 'keydown.atWho', (e) => + .on 'keydown.atwho', (e) => this.on_keydown(e) - .on 'scroll.atWho', (e) => + .on 'scroll.atwho', (e) => @view.hide() - .on 'blur.atWho', (e) => + .on 'blur.atwho', (e) => @view.hide(1000) # At.js 可以对每个输入框绑定不同的监听标记. 比如同时监听 "@", ":" 字符 @@ -224,6 +228,7 @@ # @param flag [String] 要监听的字符 # @param settings [Hash] 配置哈希值 reg: (flag, settings) -> + @inline_append=true if flag=="" current_settings = {} current_settings = if $.isPlainObject(flag) @common_settings = $.extend {}, @common_settings, flag @@ -257,7 +262,7 @@ # @return [?] 配置项的值 get_opt: (key, default_value) -> try - value = @settings[@current_flag][key] if @current_flag + value = if @settings[""] then @settings[""][key] else @settings[@current_flag][key] if @current_flag? value = @common_settings[key] if value is undefined value = if value is undefined then default_value else value catch e @@ -269,7 +274,7 @@ rect: -> $inputor = @$inputor if document.selection # for IE full - Sel = document.selection.createRange() + Sel = document.selection.createTextRange() x = Sel.boundingLeft + $inputor.scrollLeft() y = Sel.boundingTop + $(window).scrollTop() + $inputor.scrollTop() bottom = y + Sel.boundingHeight @@ -347,14 +352,14 @@ $inputor.val text $inputor.caretPos start_str.length + str.length + 1 - $inputor.change() + $inputor.change().focus() on_keyup: (e) -> switch e.keyCode when KEY_CODE.ESC e.preventDefault() @view.hide() - when KEY_CODE.DOWN, KEY_CODE.UP + when KEY_CODE.DOWN, KEY_CODE.UP, KEY_CODE.SHIFT $.noop() else this.look_up() @@ -402,7 +407,7 @@ q: query.text limit: this.get_opt("limit") # $.proxy(this.render_view, this) - this.callbacks('remote_filter').call(this, params, this.render_view) + this.callbacks('remote_filter').call(this, params, origin_data,this.render_view) else if (data = this.callbacks('filter').call(this, query.text, origin_data, search_key)) this.render_view data else @@ -425,17 +430,27 @@ create_view: -> return if this.exist() tpl = "