Changeset 9246
- Timestamp:
- 12/21/2014 11:08:39 AM (10 years ago)
- Location:
- trunk/src/bp-core/js
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/js/jquery.atwho.js
r9097 r9246 1 /*! jquery.atwho - v0.5. 1 - 2014-09-212 * Copyright (c) 2014 chord.luo <chord.luo@gmail.com>; 3 * homepage: http://ichord.github.com/At.js 1 /*! jquery.atwho - v0.5.2 %> 2 * Copyright (c) 2014 chord.luo <chord.luo@gmail.com>; 3 * homepage: http://ichord.github.com/At.js 4 4 * Licensed MIT 5 5 */ 6 7 (function() { 8 (function(factory) { 9 if (typeof define === 'function' && define.amd) { 10 return define(['jquery'], factory); 11 } else { 12 return factory(window.jQuery); 13 } 14 })(function($) { 6 (function (root, factory) { 7 if (typeof define === 'function' && define.amd) { 8 // AMD. Register as an anonymous module. 9 define(["jquery"], function ($) { 10 return (root.returnExportsGlobal = factory($)); 11 }); 12 } else if (typeof exports === 'object') { 13 // Node. Does not work with strict CommonJS, but 14 // only CommonJS-like enviroments that support module.exports, 15 // like Node. 16 module.exports = factory(require("jquery")); 17 } else { 18 factory(jQuery); 19 } 20 }(this, function ($) { 15 21 16 22 var Api, App, Controller, DEFAULT_CALLBACKS, KEY_CODE, Model, View, … … 116 122 })(this)).on('click.atwhoInner', (function(_this) { 117 123 return function(e) { 118 var _ref; 119 return (_ref = _this.controller()) != null ? _ref.view.hide(e) : void 0; 124 return _this.dispatch(); 120 125 }; 121 126 })(this)); … … 301 306 302 307 Controller.prototype.content = function() { 308 var range; 303 309 if (this.$inputor.is('textarea, input')) { 304 310 return this.$inputor.val(); 305 311 } else { 306 return this.$inputor.text(); 312 if (!(range = this.mark_range())) { 313 return; 314 } 315 return (range.startContainer.textContent || "").slice(0, range.startOffset); 307 316 } 308 317 }; … … 389 398 390 399 Controller.prototype.insert = function(content, $li) { 391 var $inputor, content_node, pos, range, sel, source, start_str, text, wrapped_content;400 var $inputor, node, pos, range, sel, source, start_str, text, wrapped_contents, _i, _len, _ref; 392 401 $inputor = this.$inputor; 393 wrapped_content = this.callbacks('inserting_wrapper').call(this, $inputor, content, this.get_opt("suffix"));402 wrapped_contents = this.callbacks('inserting_wrapper').call(this, $inputor, content, this.get_opt("suffix")); 394 403 if ($inputor.is('textarea, input')) { 395 404 source = $inputor.val(); 396 405 start_str = source.slice(0, Math.max(this.query.head_pos - this.at.length, 0)); 397 text = "" + start_str + wrapped_content + (source.slice(this.query['end_pos'] || 0));406 text = "" + start_str + wrapped_contents + (source.slice(this.query['end_pos'] || 0)); 398 407 $inputor.val(text); 399 $inputor.caret('pos', start_str.length + wrapped_content .length, {408 $inputor.caret('pos', start_str.length + wrapped_contents.length, { 400 409 iframe: this.app.iframe 401 410 }); … … 405 414 range.setEnd(range.endContainer, range.endOffset); 406 415 range.deleteContents(); 407 content_node = $(wrapped_content, this.app.document)[0]; 408 range.insertNode(content_node); 409 range.setEndAfter(content_node); 410 range.collapse(false); 416 _ref = $(wrapped_contents, this.app.document); 417 for (_i = 0, _len = _ref.length; _i < _len; _i++) { 418 node = _ref[_i]; 419 range.insertNode(node); 420 range.setEndAfter(node); 421 range.collapse(false); 422 } 411 423 sel = this.app.window.getSelection(); 412 424 sel.removeAllRanges(); … … 414 426 } else if (range = this.ie8_range) { 415 427 range.moveStart('character', this.query.end_pos - this.query.head_pos - this.at.length); 416 range.pasteHTML(wrapped_content );428 range.pasteHTML(wrapped_contents); 417 429 range.collapse(false); 418 430 range.select(); … … 542 554 $menu.find('.cur').removeClass('cur'); 543 555 return $(e.currentTarget).addClass('cur'); 544 }).on('click ', (function(_this) {556 }).on('click.atwho-view', 'li', (function(_this) { 545 557 return function(e) { 558 $menu.find('.cur').removeClass('cur'); 559 $(e.currentTarget).addClass('cur'); 546 560 _this.choose(e); 547 561 return e.preventDefault(); … … 594 608 next = this.$el.find('li:first'); 595 609 } 596 return next.addClass('cur'); 610 next.addClass('cur'); 611 return this.$el.animate({ 612 scrollTop: Math.max(0, cur.innerHeight() * (next.index() + 2) - this.$el.height()) 613 }, 150); 597 614 }; 598 615 … … 604 621 prev = this.$el.find('li:last'); 605 622 } 606 return prev.addClass('cur'); 623 prev.addClass('cur'); 624 return this.$el.animate({ 625 scrollTop: Math.max(0, cur.innerHeight() * (prev.index() + 2) - this.$el.height()) 626 }, 150); 607 627 }; 608 628 … … 616 636 if (!this.visible()) { 617 637 this.$el.show(); 638 this.$el.scrollTop(0); 618 639 this.context.trigger('shown'); 619 640 } … … 703 724 }, 704 725 matcher: function(flag, subtext, should_start_with_space) { 705 var match, regexp ;726 var match, regexp, _a, _y; 706 727 flag = flag.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); 707 728 if (should_start_with_space) { 708 729 flag = '(?:^|\\s)' + flag; 709 730 } 710 regexp = new RegExp(flag + '([A-Za-zÀ-ÿ0-9_\+\-]*)$|' + flag + '([^\\x00-\\xff]*)$', 'gi'); 731 _a = decodeURI("%C3%80"); 732 _y = decodeURI("%C3%BF"); 733 regexp = new RegExp("" + flag + "([A-Za-z" + _a + "-" + _y + "0-9_\+\-]*)$|" + flag + "([^\\x00-\\xff]*)$", 'gi'); 711 734 match = regexp.exec(subtext); 712 735 if (match) { … … 770 793 }, 771 794 inserting_wrapper: function($inputor, content, suffix) { 772 var new_suffix,wrapped_content;773 new_suffix = suffix === "" ? suffix : suffix || " ";795 var wrapped_content; 796 suffix = suffix === "" ? suffix : suffix || " "; 774 797 if ($inputor.is('textarea, input')) { 775 return '' + content + new_suffix;798 return '' + content + suffix; 776 799 } else if ($inputor.attr('contentEditable') === 'true') { 777 new_suffix = suffix === "" ? suffix : suffix || " ";800 suffix = suffix === " " ? " " : suffix; 778 801 if (/firefox/i.test(navigator.userAgent)) { 779 wrapped_content = "<span>" + content + new_suffix + "</span>";802 wrapped_content = "<span>" + content + suffix + "</span>"; 780 803 } else { 781 suffix = "<span contenteditable='false'>" + new_suffix + "<span>";804 suffix = "<span contenteditable='false'>" + suffix + "</span>"; 782 805 wrapped_content = "<span contenteditable='false'>" + content + suffix + "</span>"; 783 806 } … … 785 808 wrapped_content = "<span contenteditable='true'>" + content + "</span>"; 786 809 } 787 return wrapped_content ;810 return wrapped_content + "<span></span>"; 788 811 } 789 812 } … … 848 871 }; 849 872 850 }); 851 }).call(this); 873 874 875 })); -
trunk/src/bp-core/js/jquery.caret.js
r9097 r9246 85 85 86 86 EditableCaret.prototype.getOffset = function(pos) { 87 var clonedRange, offset, range, rect ;87 var clonedRange, offset, range, rect, shadowCaret; 88 88 if (oWindow.getSelection && (range = this.range())) { 89 if (range.endOffset - 1 < 0) { 90 return null; 89 if (range.endOffset - 1 > 0 && range.endContainer === !this.domInputor) { 90 clonedRange = range.cloneRange(); 91 clonedRange.setStart(range.endContainer, range.endOffset - 1); 92 clonedRange.setEnd(range.endContainer, range.endOffset); 93 rect = clonedRange.getBoundingClientRect(); 94 offset = { 95 height: rect.height, 96 left: rect.left + rect.width, 97 top: rect.top 98 }; 99 clonedRange.detach(); 91 100 } 92 clonedRange = range.cloneRange(); 93 clonedRange.setStart(range.endContainer, range.endOffset - 1); 94 clonedRange.setEnd(range.endContainer, range.endOffset); 95 rect = clonedRange.getBoundingClientRect(); 96 offset = { 97 height: rect.height, 98 left: rect.left + rect.width, 99 top: rect.top 100 }; 101 clonedRange.detach(); 101 if (!offset || (offset != null ? offset.height : void 0) === 0) { 102 clonedRange = range.cloneRange(); 103 shadowCaret = $(oDocument.createTextNode("|")); 104 clonedRange.insertNode(shadowCaret[0]); 105 clonedRange.selectNode(shadowCaret[0]); 106 rect = clonedRange.getBoundingClientRect(); 107 offset = { 108 height: rect.height, 109 left: rect.left, 110 top: rect.top 111 }; 112 shadowCaret.remove(); 113 clonedRange.detach(); 114 } 102 115 } else if (oDocument.selection) { 103 116 offset = this.getOldIEOffset(); … … 212 225 $inputor = this.$inputor; 213 226 format = function(value) { 214 return $('<div></div>').text(value).html() ;227 return $('<div></div>').text(value).html().replace(/\r\n|\r|\n/g, "<br/>").replace(/\s/g, " "); 215 228 }; 216 229 if (pos === void 0) {
Note: See TracChangeset
for help on using the changeset viewer.