Skip to content

Commit

Permalink
ADD: editableAtwhoQueryAttrs options
Browse files Browse the repository at this point in the history
for adding customize attrs to editable querying helper: `.atwho-query`
fix #253
  • Loading branch information
ichord committed Feb 24, 2015
1 parent 4c1048b commit 64ab00d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
6 changes: 4 additions & 2 deletions dist/js/jquery.atwho.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,8 @@ EditableController = (function(_super) {
matched = this.callbacks("matcher").call(this, this.at, _range.toString(), this.getOpt('startWithSpace'));
if ($query.length === 0 && typeof matched === 'string' && (index = range.startOffset - this.at.length - matched.length) >= 0) {
range.setStart(range.startContainer, index);
range.surroundContents(($query = $("<span class='atwho-query'/>", this.app.document))[0]);
$query = $("<span/>", this.app.document).attr(this.getOpt("editableAtwhoQueryAttrs")).addClass('atwho-query');
range.surroundContents($query.get(0));
lastNode = $query.contents().last().get(0);
if (/firefox/i.test(navigator.userAgent)) {
range.setStart(lastNode, lastNode.length);
Expand Down Expand Up @@ -1007,7 +1008,8 @@ $.fn.atwho["default"] = {
maxLen: 20,
displayTimeout: 300,
delay: null,
spaceSelectsMatch: false
spaceSelectsMatch: false,
editableAtwhoQueryAttrs: {}
};


Expand Down
2 changes: 1 addition & 1 deletion dist/js/jquery.atwho.min.js

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions spec/javascripts/content_editable.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ describe "content editable", ->

beforeEach ->
loadFixtures "inputors.html"
$inputor = $("#editable").atwho(at: "@", data: ["Jobs"])
$inputor = $("#editable").atwho
at: "@",
data: ["Jobs"]
editableAtwhoQueryAttrs: {class: "hello", "data-editor-verified":true}
app = getAppOf $inputor
afterEach ->
$inputor.atwho 'destroy'
Expand All @@ -19,11 +22,17 @@ describe "content editable", ->
app.controller().view.$el.find('ul').children().first().trigger('click')
expect($inputor.text()).toContain('@Jobs')

it "unwrapp span.atwho-query after match failed", ->
it "unwrap span.atwho-query after match failed", ->
simulateTypingIn $inputor
expect $('.atwho-query').length
.toBe 1
$('.atwho-query').html "@J "
simulateTypingIn $inputor, "@", 3
expect $('.atwho-query').length
.toBe 0

it "wrap span.atwho-query with customize attrs", ->
# for #235
simulateTypingIn $inputor
expect $('.atwho-query').data('editor-verified')
.toBe true
1 change: 1 addition & 0 deletions src/api.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ $.fn.atwho.default =
displayTimeout: 300
delay: null
spaceSelectsMatch: no
editableAtwhoQueryAttrs: {}
5 changes: 4 additions & 1 deletion src/editableController.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ class EditableController extends Controller
if $query.length == 0 and typeof matched is 'string' \
and (index = range.startOffset - @at.length - matched.length) >= 0
range.setStart range.startContainer, index
range.surroundContents ($query = $ "<span class='atwho-query'/>", @app.document)[0]
$query = $ "<span/>", @app.document
.attr @getOpt "editableAtwhoQueryAttrs"
.addClass 'atwho-query'
range.surroundContents $query.get 0
lastNode = $query.contents().last().get(0)
if /firefox/i.test navigator.userAgent
range.setStart lastNode, lastNode.length
Expand Down

0 comments on commit 64ab00d

Please sign in to comment.