Skip to:
Content

BuddyPress.org

Changeset 9246


Ignore:
Timestamp:
12/21/2014 11:08:39 AM (10 years ago)
Author:
djpaul
Message:

Update atwho.js and caret.js to versions 0.5.2 and 0.2.1, respectively.

These libraries are used in the @mentions suggestions UI.

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-21
    2 * 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
    44* Licensed MIT
    55*/
    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 ($) {
    1521
    1622var Api, App, Controller, DEFAULT_CALLBACKS, KEY_CODE, Model, View,
     
    116122    })(this)).on('click.atwhoInner', (function(_this) {
    117123      return function(e) {
    118         var _ref;
    119         return (_ref = _this.controller()) != null ? _ref.view.hide(e) : void 0;
     124        return _this.dispatch();
    120125      };
    121126    })(this));
     
    301306
    302307  Controller.prototype.content = function() {
     308    var range;
    303309    if (this.$inputor.is('textarea, input')) {
    304310      return this.$inputor.val();
    305311    } else {
    306       return this.$inputor.text();
     312      if (!(range = this.mark_range())) {
     313        return;
     314      }
     315      return (range.startContainer.textContent || "").slice(0, range.startOffset);
    307316    }
    308317  };
     
    389398
    390399  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;
    392401    $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"));
    394403    if ($inputor.is('textarea, input')) {
    395404      source = $inputor.val();
    396405      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));
    398407      $inputor.val(text);
    399       $inputor.caret('pos', start_str.length + wrapped_content.length, {
     408      $inputor.caret('pos', start_str.length + wrapped_contents.length, {
    400409        iframe: this.app.iframe
    401410      });
     
    405414      range.setEnd(range.endContainer, range.endOffset);
    406415      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      }
    411423      sel = this.app.window.getSelection();
    412424      sel.removeAllRanges();
     
    414426    } else if (range = this.ie8_range) {
    415427      range.moveStart('character', this.query.end_pos - this.query.head_pos - this.at.length);
    416       range.pasteHTML(wrapped_content);
     428      range.pasteHTML(wrapped_contents);
    417429      range.collapse(false);
    418430      range.select();
     
    542554      $menu.find('.cur').removeClass('cur');
    543555      return $(e.currentTarget).addClass('cur');
    544     }).on('click', (function(_this) {
     556    }).on('click.atwho-view', 'li', (function(_this) {
    545557      return function(e) {
     558        $menu.find('.cur').removeClass('cur');
     559        $(e.currentTarget).addClass('cur');
    546560        _this.choose(e);
    547561        return e.preventDefault();
     
    594608      next = this.$el.find('li:first');
    595609    }
    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);
    597614  };
    598615
     
    604621      prev = this.$el.find('li:last');
    605622    }
    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);
    607627  };
    608628
     
    616636    if (!this.visible()) {
    617637      this.$el.show();
     638      this.$el.scrollTop(0);
    618639      this.context.trigger('shown');
    619640    }
     
    703724  },
    704725  matcher: function(flag, subtext, should_start_with_space) {
    705     var match, regexp;
     726    var match, regexp, _a, _y;
    706727    flag = flag.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
    707728    if (should_start_with_space) {
    708729      flag = '(?:^|\\s)' + flag;
    709730    }
    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');
    711734    match = regexp.exec(subtext);
    712735    if (match) {
     
    770793  },
    771794  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 || " ";
    774797    if ($inputor.is('textarea, input')) {
    775       return '' + content + new_suffix;
     798      return '' + content + suffix;
    776799    } else if ($inputor.attr('contentEditable') === 'true') {
    777       new_suffix = suffix === "" ? suffix : suffix || "&nbsp;";
     800      suffix = suffix === " " ? "&nbsp;" : suffix;
    778801      if (/firefox/i.test(navigator.userAgent)) {
    779         wrapped_content = "<span>" + content + new_suffix + "</span>";
     802        wrapped_content = "<span>" + content + suffix + "</span>";
    780803      } else {
    781         suffix = "<span contenteditable='false'>" + new_suffix + "<span>";
     804        suffix = "<span contenteditable='false'>" + suffix + "</span>";
    782805        wrapped_content = "<span contenteditable='false'>" + content + suffix + "</span>";
    783806      }
     
    785808        wrapped_content = "<span contenteditable='true'>" + content + "</span>";
    786809      }
    787       return wrapped_content;
     810      return wrapped_content + "<span></span>";
    788811    }
    789812  }
     
    848871};
    849872
    850   });
    851 }).call(this);
     873
     874
     875}));
  • trunk/src/bp-core/js/jquery.caret.js

    r9097 r9246  
    8585
    8686      EditableCaret.prototype.getOffset = function(pos) {
    87         var clonedRange, offset, range, rect;
     87        var clonedRange, offset, range, rect, shadowCaret;
    8888        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();
    91100          }
    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          }
    102115        } else if (oDocument.selection) {
    103116          offset = this.getOldIEOffset();
     
    212225        $inputor = this.$inputor;
    213226        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, "&nbsp;");
    215228        };
    216229        if (pos === void 0) {
Note: See TracChangeset for help on using the changeset viewer.