jquery-atwho-rails 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec1b0e0e1b0876d6881d5bc64f8a08ab858a3399
4
- data.tar.gz: 97e3bfd53d3df6ce4b6223d9532711563bc86510
3
+ metadata.gz: 24d19f42cd98cc9e875d75ceecfc3a876aae8b62
4
+ data.tar.gz: ff5e30310eb57d9c48645e646e1ad1f18f44ac7c
5
5
  SHA512:
6
- metadata.gz: c61673d1cb967107e63e150726e4b0780b5f349caa140b4460a0e8d20334054263f9dd3c85e95277de1af5f0afd64eb9c6a7115687849a8f21c65846509d59d8
7
- data.tar.gz: e02326f5c3ae2782022b11c349951efa636f80afb72549368f1a89c5bbd63995dafff2210e797e1af03286cd9722fa44b02e019a68f4b12b20a756e2b93bf161
6
+ metadata.gz: 0aec51b126719a9242cde57c459518cc3a3dd44ade8dd455d3fb9d4c389313a8f80d68bf6e028473ac85d0f3405882f55c6faf363633f3fd04532157881848d7
7
+ data.tar.gz: 2bb034a106b2d3a94911c24bf3aa36974eefc0becec36b03466c0de1ab22f39d417b76eb6daee5421ae338f9990c4fa7e7500bdafa45d30a839122f280641c4c
data/Rakefile CHANGED
@@ -14,18 +14,15 @@ task :sync do
14
14
  else
15
15
  Dir.chdir(at_dir) { puts %x{git pull -X theirs} }
16
16
  end
17
- end
18
-
19
- desc "load dependences"
20
- task :bower_install => :sync do
21
- unless Dir.exist? bower_dir
22
- Dir.chdir(at_dir) { puts %x{bower install} }
23
- end
17
+ Dir.chdir(at_dir) {
18
+ puts "* bower install..."
19
+ puts %x{bower install}
20
+ }
24
21
  end
25
22
 
26
23
  desc "copy assets"
27
- task :fresh => [:bower_install, :sync] do
28
- puts "", " * Copying..."
24
+ task fresh: :sync do
25
+ puts " * Copying..."
29
26
  source_dir = "tmp/At.js/dist"
30
27
  dist_dir = "lib/assets"
31
28
 
@@ -1,4 +1,4 @@
1
- /*! jquery.atwho - v0.5.0 - 2014-07-14
1
+ /*! jquery.atwho - v0.5.1 - 2014-09-16
2
2
  * Copyright (c) 2014 chord.luo <chord.luo@gmail.com>;
3
3
  * homepage: http://ichord.github.com/At.js
4
4
  * Licensed MIT
@@ -13,7 +13,7 @@
13
13
  }
14
14
  })(function($) {
15
15
 
16
- var $CONTAINER, Api, App, Controller, DEFAULT_CALLBACKS, KEY_CODE, Model, View,
16
+ var Api, App, Controller, DEFAULT_CALLBACKS, KEY_CODE, Model, View,
17
17
  __slice = [].slice;
18
18
 
19
19
  App = (function() {
@@ -22,20 +22,37 @@ App = (function() {
22
22
  this.controllers = {};
23
23
  this.alias_maps = {};
24
24
  this.$inputor = $(inputor);
25
- this.iframe = null;
26
25
  this.setIframe();
27
26
  this.listen();
28
27
  }
29
28
 
30
- App.prototype.setIframe = function(iframe) {
29
+ App.prototype.createContainer = function(doc) {
30
+ if ((this.$el = $("#atwho-container", doc)).length === 0) {
31
+ return $(doc.body).append(this.$el = $("<div id='atwho-container'></div>"));
32
+ }
33
+ };
34
+
35
+ App.prototype.setIframe = function(iframe, standalone) {
36
+ var _ref;
37
+ if (standalone == null) {
38
+ standalone = false;
39
+ }
31
40
  if (iframe) {
32
41
  this.window = iframe.contentWindow;
33
42
  this.document = iframe.contentDocument || this.window.document;
34
- return this.iframe = iframe;
43
+ this.iframe = iframe;
35
44
  } else {
36
45
  this.document = document;
37
46
  this.window = window;
38
- return this.iframe = null;
47
+ this.iframe = null;
48
+ }
49
+ if (this.iframeStandalone = standalone) {
50
+ if ((_ref = this.$el) != null) {
51
+ _ref.remove();
52
+ }
53
+ return this.createContainer(this.document);
54
+ } else {
55
+ return this.createContainer(document);
39
56
  }
40
57
  };
41
58
 
@@ -112,7 +129,8 @@ App = (function() {
112
129
  c.destroy();
113
130
  delete this.controllers[_];
114
131
  }
115
- return this.$inputor.off('.atwhoInner');
132
+ this.$inputor.off('.atwhoInner');
133
+ return this.$el.remove();
116
134
  };
117
135
 
118
136
  App.prototype.dispatch = function() {
@@ -225,7 +243,9 @@ Controller = (function() {
225
243
  this.pos = 0;
226
244
  this.cur_rect = null;
227
245
  this.range = null;
228
- $CONTAINER.append(this.$el = $("<div id='atwho-ground-" + this.id + "'></div>"));
246
+ if ((this.$el = $("#atwho-ground-" + this.id, this.app.$el)).length === 0) {
247
+ this.app.$el.append(this.$el = $("<div id='atwho-ground-" + this.id + "'></div>"));
248
+ }
229
249
  this.model = new Model(this);
230
250
  this.view = new View(this);
231
251
  }
@@ -313,14 +333,19 @@ Controller = (function() {
313
333
  };
314
334
 
315
335
  Controller.prototype.rect = function() {
316
- var c, scale_bottom;
336
+ var c, iframe_offset, scale_bottom;
317
337
  if (!(c = this.$inputor.caret('offset', this.pos - 1, {
318
338
  iframe: this.app.iframe
319
339
  }))) {
320
340
  return;
321
341
  }
342
+ if (this.app.iframe && !this.app.iframeStandalone) {
343
+ iframe_offset = $(this.app.iframe).offset();
344
+ c.left += iframe_offset.left;
345
+ c.top += iframe_offset.top;
346
+ }
322
347
  if (this.$inputor.attr('contentEditable') === 'true') {
323
- c = (this.cur_rect || (this.cur_rect = c)) || c;
348
+ c = this.cur_rect || (this.cur_rect = c);
324
349
  }
325
350
  scale_bottom = this.app.document.selection ? 0 : 2;
326
351
  return {
@@ -541,10 +566,14 @@ View = (function() {
541
566
  };
542
567
 
543
568
  View.prototype.reposition = function(rect) {
544
- var offset, _ref;
545
- if (rect.bottom + this.$el.height() - $(window).scrollTop() > $(window).height()) {
569
+ var offset, overflowOffset, _ref, _window;
570
+ _window = this.context.app.iframeStandalone ? this.context.app.window : window;
571
+ if (rect.bottom + this.$el.height() - $(_window).scrollTop() > $(_window).height()) {
546
572
  rect.bottom = rect.top - this.$el.height();
547
573
  }
574
+ if (rect.left > (overflowOffset = $(_window).width() - this.$el.width() - 5)) {
575
+ rect.left = overflowOffset;
576
+ }
548
577
  offset = {
549
578
  left: rect.left,
550
579
  top: rect.bottom
@@ -677,7 +706,7 @@ DEFAULT_CALLBACKS = {
677
706
  if (should_start_with_space) {
678
707
  flag = '(?:^|\\s)' + flag;
679
708
  }
680
- regexp = new RegExp(flag + '([A-Za-z0-9_\+\-]*)$|' + flag + '([^\\x00-\\xff]*)$', 'gi');
709
+ regexp = new RegExp(flag + '([A-Za-zÀ-ÿ0-9_\+\-]*)$|' + flag + '([^\\x00-\\xff]*)$', 'gi');
681
710
  match = regexp.exec(subtext);
682
711
  if (match) {
683
712
  return match[2] || match[1];
@@ -690,7 +719,7 @@ DEFAULT_CALLBACKS = {
690
719
  _results = [];
691
720
  for (_i = 0, _len = data.length; _i < _len; _i++) {
692
721
  item = data[_i];
693
- if (~item[search_key].toLowerCase().indexOf(query.toLowerCase())) {
722
+ if (~new String(item[search_key]).toLowerCase().indexOf(query.toLowerCase())) {
694
723
  _results.push(item);
695
724
  }
696
725
  }
@@ -705,7 +734,7 @@ DEFAULT_CALLBACKS = {
705
734
  _results = [];
706
735
  for (_i = 0, _len = items.length; _i < _len; _i++) {
707
736
  item = items[_i];
708
- item.atwho_order = item[search_key].toLowerCase().indexOf(query.toLowerCase());
737
+ item.atwho_order = new String(item[search_key]).toLowerCase().indexOf(query.toLowerCase());
709
738
  if (item.atwho_order > -1) {
710
739
  _results.push(item);
711
740
  }
@@ -766,8 +795,8 @@ Api = {
766
795
  return c.model.load(data);
767
796
  }
768
797
  },
769
- setIframe: function(iframe) {
770
- this.setIframe(iframe);
798
+ setIframe: function(iframe, standalone) {
799
+ this.setIframe(iframe, standalone);
771
800
  return null;
772
801
  },
773
802
  run: function() {
@@ -779,14 +808,11 @@ Api = {
779
808
  }
780
809
  };
781
810
 
782
- $CONTAINER = $("<div id='atwho-container'></div>");
783
-
784
811
  $.fn.atwho = function(method) {
785
812
  var result, _args;
786
813
  _args = arguments;
787
- $('body').append($CONTAINER);
788
814
  result = null;
789
- this.filter('textarea, input, [contenteditable=true]').each(function() {
815
+ this.filter('textarea, input, [contenteditable=""], [contenteditable=true]').each(function() {
790
816
  var $this, app;
791
817
  if (!(app = ($this = $(this)).data("atwho"))) {
792
818
  $this.data('atwho', (app = new App(this)));
@@ -37,11 +37,16 @@
37
37
  };
38
38
 
39
39
  EditableCaret.prototype.getIEPosition = function() {
40
- return $.noop();
40
+ return this.getPosition();
41
41
  };
42
42
 
43
43
  EditableCaret.prototype.getPosition = function() {
44
- return $.noop();
44
+ var inputor_offset, offset;
45
+ offset = this.getOffset();
46
+ inputor_offset = this.$inputor.offset();
47
+ offset.left -= inputor_offset.left;
48
+ offset.top -= inputor_offset.top;
49
+ return offset;
45
50
  };
46
51
 
47
52
  EditableCaret.prototype.getOldIEPos = function() {
@@ -98,7 +103,7 @@
98
103
  } else if (oDocument.selection) {
99
104
  offset = this.getOldIEOffset();
100
105
  }
101
- if (offset && !oFrame) {
106
+ if (offset) {
102
107
  offset.top += $(oWindow).scrollTop();
103
108
  offset.left += $(oWindow).scrollLeft();
104
109
  }
@@ -207,7 +212,7 @@
207
212
  var $inputor, at_rect, end_range, format, html, mirror, start_range;
208
213
  $inputor = this.$inputor;
209
214
  format = function(value) {
210
- return value.replace(/</g, '&lt').replace(/>/g, '&gt').replace(/`/g, '&#96').replace(/"/g, '&quot').replace(/\r\n|\r|\n/g, "<br />");
215
+ return $('<div></div>').text(value).html();
211
216
  };
212
217
  if (pos === void 0) {
213
218
  pos = this.getPos();
@@ -308,13 +313,8 @@
308
313
  }
309
314
  },
310
315
  offset: function(pos) {
311
- var iOffset, offset;
316
+ var offset;
312
317
  offset = this.getOffset(pos);
313
- if (oFrame) {
314
- iOffset = $(oFrame).offset();
315
- offset.top += iOffset.top;
316
- offset.left += iOffset.left;
317
- }
318
318
  return offset;
319
319
  }
320
320
  };
@@ -5,6 +5,7 @@
5
5
  display: none;
6
6
  margin-top: 18px;
7
7
  background: white;
8
+ color: black;
8
9
  border: 1px solid #DDD;
9
10
  border-radius: 3px;
10
11
  box-shadow: 0 0 5px rgba(0,0,0,0.1);
@@ -1,7 +1,7 @@
1
1
  module Jquery
2
2
  module Atwho
3
3
  module Rails
4
- VERSION = "0.5.0"
4
+ VERSION = "0.5.1"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jquery-atwho-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ichord
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-16 00:00:00.000000000 Z
11
+ date: 2014-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec