From e85442b8fef42d3496a2191c1bef6f661c41fc2a Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 14 Jan 2022 08:30:06 +0000 Subject: [PATCH] Update content of files --- .../decryptedMessageActionAcceptKey.html | 160 -- data/corefork.telegram.org/api/pin.html | 149 ++ data/promote.telegram.org/js/jquery-ex.js | 1683 +++++++++++++++++ data/translations.telegram.org.html | 297 +++ data/translations.telegram.org/en.html | 333 ++++ .../translations.telegram.org/en/android.html | 388 ++++ .../en/android_x.html | 388 ++++ data/translations.telegram.org/en/ios.html | 388 ++++ data/translations.telegram.org/en/macos.html | 388 ++++ .../en/tdesktop.html | 388 ++++ data/tsf.telegram.org/js/jquery.min.js | 4 - 11 files changed, 4402 insertions(+), 164 deletions(-) delete mode 100644 data/core.telegram.org/constructor/decryptedMessageActionAcceptKey.html create mode 100644 data/corefork.telegram.org/api/pin.html create mode 100644 data/promote.telegram.org/js/jquery-ex.js create mode 100644 data/translations.telegram.org.html create mode 100644 data/translations.telegram.org/en.html create mode 100644 data/translations.telegram.org/en/android.html create mode 100644 data/translations.telegram.org/en/android_x.html create mode 100644 data/translations.telegram.org/en/ios.html create mode 100644 data/translations.telegram.org/en/macos.html create mode 100644 data/translations.telegram.org/en/tdesktop.html delete mode 100644 data/tsf.telegram.org/js/jquery.min.js diff --git a/data/core.telegram.org/constructor/decryptedMessageActionAcceptKey.html b/data/core.telegram.org/constructor/decryptedMessageActionAcceptKey.html deleted file mode 100644 index 5f0a67096d..0000000000 --- a/data/core.telegram.org/constructor/decryptedMessageActionAcceptKey.html +++ /dev/null @@ -1,160 +0,0 @@ - - - - - decryptedMessageActionAcceptKey - - - - - - - - - - - - - -
- -
-
-
- -

decryptedMessageActionAcceptKey

- -

Accept new key

-

- -
-
===20===
-decryptedMessageActionAcceptKey#6fe1735b exchange_id:long g_b:bytes key_fingerprint:long = DecryptedMessageAction;

-

Parameters

- - - - - - - - - - - - - - - - - - - - - - - - - -
NameTypeDescription
exchange_idlongExchange ID
g_bbytesB parameter, see rekeying process
key_fingerprintlongKey fingerprint, see rekeying process
-

Type

-

DecryptedMessageAction

-

Related pages

-

Perfect Forward Secrecy

- -
- -
-
- -
- - - - - - diff --git a/data/corefork.telegram.org/api/pin.html b/data/corefork.telegram.org/api/pin.html new file mode 100644 index 0000000000..501034af11 --- /dev/null +++ b/data/corefork.telegram.org/api/pin.html @@ -0,0 +1,149 @@ + + + + + Pinned messages + + + + + + + + + + + + + +
+ +
+
+
+ +

Pinned messages

+ +
+ +

Telegram allows pinning multiple messages on top of a specific chat.

+
message#85d6cbe2 flags:# out:flags.1?true mentioned:flags.4?true media_unread:flags.5?true silent:flags.13?true post:flags.14?true from_scheduled:flags.18?true legacy:flags.19?true edit_hide:flags.21?true pinned:flags.24?true id:int from_id:flags.8?Peer peer_id:Peer fwd_from:flags.2?MessageFwdHeader via_bot_id:flags.11?long reply_to:flags.3?MessageReplyHeader date:int message:string media:flags.9?MessageMedia reply_markup:flags.6?ReplyMarkup entities:flags.7?Vector<MessageEntity> views:flags.10?int forwards:flags.10?int replies:flags.23?MessageReplies edit_date:flags.15?int post_author:flags.16?string grouped_id:flags.17?long restriction_reason:flags.22?Vector<RestrictionReason> ttl_period:flags.25?int = Message;
+
+updatePinnedMessages#ed85eab5 flags:# pinned:flags.0?true peer:Peer messages:Vector<int> pts:int pts_count:int = Update;
+updatePinnedChannelMessages#5bb98608 flags:# pinned:flags.0?true channel_id:long messages:Vector<int> pts:int pts_count:int = Update;
+
+---functions---
+
+messages.updatePinnedMessage#d2aaf7ec flags:# silent:flags.0?true unpin:flags.1?true pm_oneside:flags.2?true peer:InputPeer id:int = Updates;
+messages.unpinAllMessages#f025bc8b peer:InputPeer = messages.AffectedHistory;
+
+messages.getMessages#63c66506 id:Vector<InputMessage> = messages.Messages;
+channels.getMessages#ad8c9a23 channel:InputChannel id:Vector<InputMessage> = messages.Messages;
+

The messages.updatePinnedMessage method can be used to pin or unpin a specific message in an arbitrary chat.
+The unpin flags specifies whether to unpin or pin the message, and pm_oneside specifies whether the message should only be pinned on the local side of a one-to-one chat.

+

messages.unpinAllMessages can be used to unpin all messages in a chat.

+

When (un)pinning messages, a updatePinnedMessages or updatePinnedChannelMessages update will be emitted, containing IDs of pinned or unpinned messages.

+

Pinned messages will also have the will also have the pinned flag of message set.

+

Getting pinned messages

+
userFull#d697ff05 flags:# blocked:flags.0?true phone_calls_available:flags.4?true phone_calls_private:flags.5?true can_pin_message:flags.7?true has_scheduled:flags.12?true video_calls_available:flags.13?true user:User about:flags.1?string settings:PeerSettings profile_photo:flags.2?Photo notify_settings:PeerNotifySettings bot_info:flags.3?BotInfo pinned_msg_id:flags.6?int common_chats_count:int folder_id:flags.11?int ttl_period:flags.14?int theme_emoticon:flags.15?string = UserFull;
+chatFull#4dbdc099 flags:# can_set_username:flags.7?true has_scheduled:flags.8?true id:long about:string participants:ChatParticipants chat_photo:flags.2?Photo notify_settings:PeerNotifySettings exported_invite:flags.13?ExportedChatInvite bot_info:flags.3?Vector<BotInfo> pinned_msg_id:flags.6?int folder_id:flags.11?int call:flags.12?InputGroupCall ttl_period:flags.14?int groupcall_default_join_as:flags.15?Peer theme_emoticon:flags.16?string = ChatFull;
+channelFull#e9b27a17 flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_set_location:flags.16?true has_scheduled:flags.19?true can_view_stats:flags.20?true blocked:flags.22?true id:long about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:flags.23?ExportedChatInvite bot_info:Vector<BotInfo> migrated_from_chat_id:flags.4?long migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int folder_id:flags.11?int linked_chat_id:flags.14?long location:flags.15?ChannelLocation slowmode_seconds:flags.17?int slowmode_next_send_date:flags.18?int stats_dc:flags.12?int pts:int call:flags.21?InputGroupCall ttl_period:flags.24?int pending_suggestions:flags.25?Vector<string> groupcall_default_join_as:flags.26?Peer theme_emoticon:flags.27?string = ChatFull;
+
+inputMessagesFilterPinned#1bb00451 = MessagesFilter;
+
+---functions---
+
+messages.search#a0fda762 flags:# peer:InputPeer q:string from_id:flags.0?InputPeer top_msg_id:flags.1?int filter:MessagesFilter min_date:int max_date:int offset_id:int add_offset:int limit:int max_id:int min_id:int hash:long = messages.Messages;
+

The pinned_msg_id of userFull, chatFull, channelFull contains the ID of only the latest pinned message.
+To obtain a full list, use messages.search with inputMessagesFilterPinned filter.

+ +
+ +
+
+ +
+ + + + + + + + diff --git a/data/promote.telegram.org/js/jquery-ex.js b/data/promote.telegram.org/js/jquery-ex.js new file mode 100644 index 0000000000..99da06fcf5 --- /dev/null +++ b/data/promote.telegram.org/js/jquery-ex.js @@ -0,0 +1,1683 @@ +(function($) { + $.fn.redraw = function() { + return this.map(function(){ this.offsetTop; return this; }); + }; + $.fn.prepareSlideX = function(callback) { + return this.map(function(){ + $(this).css({width: this.scrollWidth, overflow: 'hidden'}); + return this; + }).one('transitionend', function(){ + $(this).css({width: '', overflow: ''}); + callback && callback.call(this); + }).redraw(); + }; + $.fn.prepareSlideY = function(callback) { + return this.map(function(){ + $(this).css({height: this.scrollHeight, overflow: 'hidden'}); + return this; + }).one('transitionend', function(){ + $(this).css({height: '', overflow: ''}); + callback && callback.call(this); + }).redraw(); + }; + $.fn.animOff = function(this_el) { + if (this_el) { + return this.css('transition', 'none').redraw(); + } + return this.addClass('no-transition').redraw(); + }; + $.fn.animOn = function(this_el) { + if (this_el) { + return this.redraw().css('transition', ''); + } + return this.redraw().removeClass('no-transition'); + }; + $.fn.fadeShow = function(callback) { + return this.fadeToggle(true, callback); + }; + $.fn.fadeHide = function(callback) { + return this.fadeToggle(false, callback); + }; + $.fn.isFadeHidden = function() { + return this.hasClass('ohide'); + }; + $.fn.isFixed = function() { + return this.parents().map(function(){ return $(this).css('position'); }).get().indexOf('fixed') != -1; + }; + $.fn.focusAndSelect = function(select_all) { + var field = this.get(0), len = this.value().length; + if (field) { + field.focus(); + if (len > 0) { + if (this.is('[contenteditable]')) { + var range = document.createRange(), sel; + range.selectNodeContents(field); + if (!select_all) { + range.collapse(); + } + sel = window.getSelection(); + sel.removeAllRanges(); + sel.addRange(range); + } else if (field.setSelectionRange) { + if (select_all) { + field.setSelectionRange(0, len); + } else { + field.setSelectionRange(len, len); + } + } + } + } + return this; + }; + $.fn.focusAndSelectAll = function() { + return this.focusAndSelect(true); + }; + $.fn.fadeToggle = function(state, callback) { + if (state === true || state === false) { + state = !state; + } + if (callback == 'remove') { + callback = function(){ $(this).remove(); }; + } + if (callback) { + this.one('transitionend', callback); + } + return this.toggleClass('ohide', state); + }; + $.fn.slideShow = function(callback) { + return this.prepareSlideY(callback).removeClass('shide'); + }; + $.fn.slideHide = function(callback) { + if (callback == 'remove') { + callback = function(){ $(this).remove(); }; + } + return this.prepareSlideY(callback).addClass('shide'); + }; + $.fn.slideXShow = function(callback) { + return this.prepareSlideX(callback).removeClass('sxhide'); + }; + $.fn.slideXHide = function(callback) { + if (callback == 'remove') { + callback = function(){ $(this).remove(); }; + } + return this.prepareSlideX(callback).addClass('sxhide'); + }; + $.fn.isSlideHidden = function() { + return this.hasClass('shide'); + }; + $.fn.slideToggle = function(state, callback) { + if (state === true || state === false) { + state = !state; + } + return this.prepareSlideY(callback).toggleClass('shide', state); + }; + $.fn.highlight = function(delay) { + var $this = this; + $this.addClass('highlight'); + setTimeout(function() { $this.removeClass('highlight'); }, delay); + return $this; + }; + $.fn.scrollIntoView = function(options) { + options = options || {}; + return this.first().each(function() { + var position = options.position || 'auto', + padding = options.padding || 0, + duration = options.duration || 0; + var $item = $(this), + $cont = $item.scrollParent(), + scrollTop = $cont.scrollTop(), + positionTop = 0, + paddingTop = 0, + itemHeight = $item.outerHeight(), + isBody = false; + if ($cont.get(0) === document) { + isBody = true; + $cont = $(window); + positionTop = $item.offset().top; + paddingTop = $('header').height() + 1; + } else { + positionTop = $item.offset().top - $cont.offset().top + scrollTop; + } + if (options.slidedEl) { + if (options.slidedEl === 'this') { + options.slidedEl = this; + } + $(options.slidedEl, this).each(function() { + itemHeight += (this.scrollHeight - this.clientHeight); + }); + } + var itemTop = positionTop, + itemBottom = itemTop + itemHeight, + contHeight = $cont.height(), + contTop = scrollTop + padding + paddingTop, + contBottom = scrollTop + contHeight - padding, + scrollTo = null; + if (position == 'auto') { + if (itemTop < contTop) { + scrollTo = itemTop - padding - paddingTop; + } else if (itemBottom > contBottom) { + if (itemHeight > contHeight - padding - padding) { + scrollTo = itemTop - padding - paddingTop; + } else { + scrollTo = itemBottom - contHeight + padding; + } + } + } else if (position == 'top' || position == 'center') { + if (position == 'center' && + contHeight > itemHeight) { + padding = (contHeight - paddingTop - itemHeight) / 2; + } + scrollTo = itemTop - padding - paddingTop; + } else if (position == 'bottom') { + if (itemHeight > contHeight - padding - padding) { + scrollTo = itemTop - padding - paddingTop; + } else { + scrollTo = itemBottom - contHeight + padding; + } + } + if (scrollTo) { + if (duration) { + if (isBody) { + $cont = $('html'); + } + $cont.stop().animate({scrollTop: scrollTo}, duration); + } else { + $cont.scrollTop(scrollTo); + } + } + }); + }; + $.fn.initSearch = function(options) { + return this.map(function(){ + var $field = $(this); + var curValue = $field.value(); + var curSelectedIndex = false; + var curResult = []; + var curRenderedIndex = 0; + var dataWaiting = false; + var keyUpTimeout = null; + var blurTimeout = null; + var isFocused = false; + options = options || {}; + if (!options.searchEnabled) { + options.searchEnabled = function(){ return true; }; + } + if (!options.enterEnabled) { + options.enterEnabled = function(){ return true; }; + } + if (!options.prepareQuery) { + options.prepareQuery = function(str){ return str.toLowerCase(); }; + } + $field.data('searchOptions', options); + + function onKeyDown(e) { + switch (e.which) { + case Keys.ESC: + $field.blur(); + break; + case Keys.RETURN: + select(curSelectedIndex); + break; + case Keys.UP: + var index; + if (!curSelectedIndex) { + if (options.enterEnabled()) { + index = false; + } else { + break; + } + } else { + index = curSelectedIndex - 1; + } + hover(index, true); + break; + case Keys.DOWN: + var index; + if (curSelectedIndex === false) { + index = 0; + } else { + index = curSelectedIndex + 1; + } + if (index > curResult.length - 1) { + break; + } + hover(index, true); + break; + default: + return; + } + e.stopImmediatePropagation(); + e.preventDefault(); + } + + function onKeyUp(e) { + clearTimeout(blurTimeout); + var value = $field.value(); + clearTimeout(keyUpTimeout); + if (curValue !== value) { + // if (e.type == 'keyup') { + // keyUpTimeout = setTimeout(function() { + // valueChange(); + // }, 50); + // } else { + options.onInputBeforeChange && options.onInputBeforeChange(value); + valueChange(); + options.onInput && options.onInput(value); + open(); + // } + } + } + + function onClick(e) { + open(); + } + + function check(item, queryLower) { + if (!queryLower.length) { + return 0; + } + for (var j = 0; j < item._values.length; j++) { + var valueLower = item._values[j]; + if (valueLower == queryLower) { + item._fullmatch = true; + return valueLower.length; + } + } + for (var j = 0; j < item._values.length; j++) { + var valueLower = item._values[j]; + var index = valueLower.indexOf(queryLower); + var found = options.prefixOnly ? index === 0 : index !== -1; + if (found) { + return valueLower.length; + } + } + return false; + } + + function search(data, query) { + var result = []; + result.fullMatchIndex = null; + if (!options.emptyQueryEnabled && !query.length) { + return result; + } + var time = +(new Date); + var queryLower = options.prepareQuery(query); + for (var i = 0; i < data.length; i++) { + var item = data[i]; + var valueScore = check(item, queryLower); + if (valueScore !== false) { + item._score = valueScore; + if (item._top) item._score -= 10000000; + else if (item._bottom) item._score += 10000000; + item._i = i; + result.push(item); + } + } + result.sort(function(item1, item2) { + return (item1._score - item2._score) || (item1._i - item2._i); + }); + for (i = 0; i < result.length; i++) { + var item = result[i]; + if (item._fullmatch) { + delete item._fullmatch; + if (result.fullMatchIndex === null) { + result.fullMatchIndex = i; + } + } + delete item._score; + delete item._i; + } + console.log('search: ' + (((new Date) - time) / 1000) + 's'); + return result; + } + + function render(result, query, from_index) { + if (from_index && from_index >= result.length) { + return; + } + var time = +(new Date); + var queryLower = options.prepareQuery(query); + from_index = from_index || 0; + var html = ''; + var render_limit = options.renderLimit || 50; + if (result.length > 0) { + for (var i = from_index, j = 0; i < result.length && j < render_limit; i++, j++) { + var item = result[i]; + var tagName = options.itemTagName || 'div'; + var className = 'search-item' + (options.itemClass ? ' ' + options.itemClass : '') + (item.className ? ' ' + item.className : ''); + var item_html = '<' + tagName + ' class="' + className + '" data-i="' + i + '">' + options.renderItem(item, query) + ''; + html += item_html; + } + curRenderedIndex = i; + } else { + html = options.renderNoItems ? options.renderNoItems(query) : ''; + curRenderedIndex = 0; + } + if (curRenderedIndex >= result.length) { + html += options.appendToItems ? options.appendToItems(query) : ''; + } + if (!result.length && html == '') { + options.$results.fadeHide(function() { + if (options.$results.isFadeHidden()) { + options.$results.html(html); + } + }); + } else { + if (options.$results.isFadeHidden()) { + options.$results.fadeShow(); + } + if (!from_index) { + options.$results.html(html); + } else if (html) { + options.$results.append(html); + } + } + updateScrollState(); + console.log('render: from ' + from_index + ', ' + j + ' lines, ' + (((new Date) - time) / 1000) + 's'); + } + + function renderLoading() { + curRenderedIndex = 0; + options.$results.html(options.renderLoading ? options.renderLoading() : ''); + updateScrollState(); + } + + function renderEmpty() { + curRenderedIndex = 0; + options.$results.html(''); + updateScrollState(); + } + + function close(no_anim) { + console.log(+new Date, 'close', no_anim); + clearTimeout(keyUpTimeout); + if (!options.$results.hasClass('collapsed')) { + if (options.$enter && options.enterEnabled()) { + options.$enter.removeClass('selected'); + } + if (no_anim) { + options.$results.animOff(); + } + options.$results.addClass('collapsed'); + options.onClose && options.onClose(); + if (no_anim) { + options.$results.animOn(); + } + } + } + + function open() { + clearTimeout(blurTimeout); + hover(curSelectedIndex, true); + if (options.$results.hasClass('collapsed')) { + options.$results.removeClass('collapsed'); + options.onOpen && options.onOpen(); + } + } + + function onFocus() { + isFocused = true; + var value = $field.value(); + if (curValue != value || + options.searchEnabled() && options.getData() === false) { + valueChange(); + } + open(); + } + + function onBlur() { + if (!isFocused) return; + console.log(+new Date, 'onblur'); + isFocused = false; + clearTimeout(blurTimeout); + blurTimeout = setTimeout(close, 100, false); + options.onBlur && options.onBlur(curValue); + } + + function valueChange() { + clearTimeout(blurTimeout); + clearTimeout(keyUpTimeout); + var value = $field.value(); + curValue = value; + console.log('valueChange', options.searchEnabled()); + if (options.searchEnabled()) { + var data = options.getData(); + if (data === false) { + if (!dataWaiting) { + dataWaiting = true; + $field.one('dataready.search', function() { + dataWaiting = false; + valueChange(); + }); + } + if (curValue.length || options.emptyQueryEnabled) { + renderLoading(); + } else { + renderEmpty(); + } + return; + } + curResult = search(data, curValue); + var index = false; + var $scrollableEl = options.resultsNotScrollable ? $(window) : options.$results; + $scrollableEl.scrollTop(0); + if (curValue.length || options.emptyQueryEnabled) { + render(curResult, curValue); + if (curResult.length && (!options.enterEnabled())) { + index = 0; + } + if (options.selectFullMatch && curResult.fullMatchIndex !== null) { + index = curResult.fullMatchIndex; + } + } else { + renderEmpty(); + } + } else { + curResult = []; + var index = false; + renderEmpty(); + } + hover(index, true); + } + + function hover(i, adjust_scroll, middle) { + $('.search-item.selected', options.$results).removeClass('selected'); + curSelectedIndex = i; + if (curSelectedIndex !== false) { + var selectedEl = $('.search-item', options.$results).get(curSelectedIndex); + if (!selectedEl) { + curSelectedIndex = false; + } else { + $(selectedEl).addClass('selected'); + if (adjust_scroll) { + adjustScroll($(selectedEl), middle); + } + if (Math.abs(curSelectedIndex - curRenderedIndex) < 5) { + render(curResult, curValue, curRenderedIndex); + } + } + } + if (options.$enter && options.enterEnabled()) { + options.$enter.toggleClass('selected', curSelectedIndex === false); + } + } + + function select(i) { + if (i === false) { + if (options.enterEnabled()) { + if (!options.noCloseOnEnter) { + $field.blur(); + } + options.onEnter && options.onEnter(curValue); + if (!options.noCloseOnEnter) { + close(true); + } + } + return; + } + if (!options.noCloseOnSelect) { + $field.blur(); + } + options.onSelect && options.onSelect(curResult[i]); + if (!options.noCloseOnSelect) { + close(true); + } + } + + function onItemHover() { + hover($(this).data('i'), true, true); + } + + function onItemMouseOver() { + hover($(this).data('i')); + } + + function updateScrollState() { + var results = options.$results.get(0); + if (results) { + options.$results.toggleClass('topscroll', results.scrollTop > 0); + options.$results.toggleClass('bottomscroll', results.scrollTop < results.scrollHeight - results.clientHeight); + } + } + + function onResultsScroll(e) { + updateScrollState(); + if (options.resultsNotScrollable) { + var bottom = options.$results.offset().top + options.$results.height() - $(window).scrollTop(); + if (bottom < $(window).height() * 2) { + render(curResult, curValue, curRenderedIndex); + } + } else { + if (this.scrollTop > this.scrollHeight - this.clientHeight - 1000) { + render(curResult, curValue, curRenderedIndex); + } + } + } + + function onItemClick(e) { + if (e.metaKey || e.ctrlKey) return true; + clearTimeout(blurTimeout); + e.stopImmediatePropagation(); + e.preventDefault(); + select($(this).data('i')); + } + + function adjustScroll($itemEl, middle) { + var scrollTop = options.$results.scrollTop(), + itemTop = $itemEl.position().top + scrollTop, + itemHeight = $itemEl.outerHeight(), + itemBottom = itemTop + itemHeight, + contHeight = options.$results.height() || 300; + + if (middle) { + options.$results.scrollTop(itemTop - (contHeight - itemHeight) / 2); + } else if (itemTop < scrollTop) { + options.$results.scrollTop(itemTop); + } else if (itemBottom > scrollTop + contHeight) { + options.$results.scrollTop(itemBottom - contHeight); + } + } + + if (options.$enter && options.enterEnabled()) { + options.$enter.on('mouseover.search', onItemMouseOver); + options.$enter.on('mousedown.search', onItemClick); + options.$enter.data('i', false); + } + options.$results.on('hover.search', '.search-item', onItemHover); + options.$results.on('mouseover.search', '.search-item', onItemMouseOver); + options.$results.on('mousedown.search', '.search-item', onItemClick); + if (options.resultsNotScrollable) { + $(window).on('scroll.search', onResultsScroll); + } else { + options.$results.on('scroll.search', onResultsScroll); + if (options.$results.isFixed()) { + options.$results.blockBodyScroll(); + } + } + if (options.initTextarea) { + $field.initTextarea(options.initTextarea); + } + $field.on('keydown.search', onKeyDown); + $field.on('keyup.search', onKeyUp); + $field.on('focus.search', onFocus); + $field.on('blur.search', onBlur); + $field.on('input.search', onKeyUp); + $field.on('click.search', onClick); + + $field.on('datachange.search', function() { + valueChange(); + }); + $field.on('contentchange.search', function() { + if (options.resultsNotScrollable) { + var scrolltop = $(window).scrollTop(); + } else { + var scrolltop = options.$results.scrollTop(); + } + var limit = options.renderLimit; + options.renderLimit = curRenderedIndex; + valueChange(); + options.renderLimit = limit; + if (options.resultsNotScrollable) { + $(window).scrollTop(scrolltop); + } else { + options.$results.scrollTop(scrolltop); + } + }); + + options.$results.addClass('collapsed'); + + if (options.updateOnInit) { + valueChange(); + } + return this; + }); + }; + $.fn.destroySearch = function() { + return this.map(function() { + var $field = $(this); + var options = $field.data('searchOptions'); + if (options) { + if (options.$enter && options.enterEnabled()) { + options.$enter.off('.search'); + } + options.$results.off('.search'); + if (options.resultsNotScrollable) { + $(window).off('.search'); + } + if (options.initTextarea) { + $field.destroyTextarea(); + } + } + $field.off('.search'); + return this; + }); + }; + $.fn.initSelect = function(options) { + return this.map(function() { + var $select = $(this); + var $field = $('.form-control', $select); + var $selected = $('.selected-items', $select); + var $results = $('.items-list', $select); + var selectedVal = [], selectedMap = {}; + + $select.data('options', options); + + function getValue(full) { + if (options.multiSelect) { + return full ? $.extend({}, selectedMap) : [].concat(selectedVal); + } else { + return selectedVal.length > 0 ? (full ? selectedMap[selectedVal[0]] : selectedVal[0]) : (full ? false : ''); + } + } + function setValue() { + var selValue = getValue(), selValueFull = getValue(true); + $select.data('value', selValue); + $select.data('valueFull', selValueFull); + options.onChange && options.onChange(selValue, selValueFull); + } + + function toggleDD(open) { + $select.toggleClass('open', open); + } + function addSelected(item, noupdate) { + var val = (item.prefix || '') + item.val; + if (!selectedMap[val]) { + if (!options.multiSelect) { + for (var i = 0; i < selectedVal.length; i++) { + delete selectedMap[selectedVal[i]]; + } + selectedVal = []; + } + else if (item.group) { + for (var i = selectedVal.length - 1; i >= 0; i--) { + if (selectedMap[selectedVal[i]].group == item.group) { + delete selectedMap[selectedVal[i]]; + selectedVal.splice(i, 1); + } + } + } + selectedVal.push(val); + selectedMap[val] = item; + if (!noupdate) { + setValue(); + updateSelected(); + } + } + } + function delSelected(val) { + if (selectedMap[val]) { + delete selectedMap[val]; + for (var i = 0; i < selectedVal.length; i++) { + if (selectedVal[i] == val) { + selectedVal.splice(i, 1); + break; + } + } + setValue(); + updateSelected(); + } + } + function clearSelected() { + for (var i = 0; i < selectedVal.length; i++) { + var val = selectedVal[i]; + delete selectedMap[val]; + } + selectedVal = []; + setValue(); + updateSelected(); + } + function updateSelected() { + var html = ''; + for (var i = 0; i < selectedVal.length; i++) { + var val = selectedVal[i]; + var item = selectedMap[val]; + html += options.renderSelectedItem ? options.renderSelectedItem(val, item) : '
' + item.name + '
'; + } + $('.selected-item', $selected).remove(); + $selected.prepend(html); + options.onUpdate && options.onUpdate(getValue(), getValue(true)); + } + + var initTextarea = null; + var isContentEditable = $field.is('[contenteditable]'); + if (isContentEditable) { + initTextarea = options.noSearch ? { + singleLine: true, + checkText: function() { return ''; } + } : { + singleLine: true + }; + } + $field.initSearch($.extend({ + $results: $results, + emptyQueryEnabled: true, + noCloseOnSelect: options.multiSelect, + updateOnInit: true, + renderItem: function(item) { + return '
' + item.name + '
'; + }, + prepareQuery: function(str) { + str = str.toLowerCase(); + if (options.searchByLastWord) { + str = str.split(/\s+/).pop(); + } + return str; + }, + onOpen: function() { + toggleDD(true); + }, + onClose: function() { + toggleDD(false); + } + }, options, { + getData: function() { + var data = options.getData(); + if (data === false) { + return false; + } + var filtered_data = []; + for (var i = 0; i < data.length; i++) { + if (data[i].hidden) continue; + var val = (data[i].prefix || '') + data[i].val; + if (!selectedMap[val] || !options.multiSelect) { + filtered_data.push(data[i]); + } + } + return filtered_data; + }, + onSelect: function(item) { + var newValue = ''; + if (options.searchByLastWord) { + var oldValue = $field.value(); + var lastWord = oldValue.split(/\s+/).pop(); + newValue = oldValue; + if (lastWord.length > 0) { + newValue = oldValue.substr(0, oldValue.length - lastWord.length); + } + newValue = newValue.replace(/^\s+/, ''); + } + $field.value(newValue); + addSelected(item); + if (options.multiSelect) { + $field.trigger('contentchange').focusAndSelect(); + } + }, + initTextarea: initTextarea + })); + if (options.noSearch) { + $select.addClass('no-search'); + } + if (!isContentEditable) { + $field.on('keydown.select', function(e) { + if (!e.metaKey && !e.ctrlKey && !e.shiftKey && !e.altKey && + (e.which == Keys.BACKSPACE) && + this.selectionStart == this.selectionEnd && + !this.selectionStart) { + $(this).trigger('backspaceonleft'); + } + }); + } + var defValue = $select.defaultValue(); + var defSelected = defValue.length ? defValue.split(';') : [], dataMap = {}; + if (defSelected.length) { + var data = options.getData(); + if (data !== false) { + for (var i = 0; i < data.length; i++) { + var val = (data[i].prefix || '') + data[i].val; + dataMap[val] = data[i]; + } + } + for (var i = 0, item; i < defSelected.length; i++) { + if (item = dataMap[defSelected[i]]) { + addSelected(item, true); + } + } + } + $select.data('value', getValue()); + $select.data('valueFull', getValue(true)); + $select.on('selectval.select', function(e, val, clear) { + addSelected(val); + if (clear) { + $field.value(''); + } + $field.trigger('datachange'); + }); + $select.on('deselectval.select', function(e, val) { + delSelected(val); + $field.trigger('datachange'); + }); + $select.on('reset.select', function(e) { + $('.selected-item', $selected).each(function() { + var val = $(this).attr('data-val'); + delSelected(val); + }); + $field.trigger('datachange'); + }); + $field.on('backspaceonleft.select', function(e) { + if (options.focusSelectedBeforeDelete) { + var $focused = $('.selected-item.focused', $selected); + if ($focused.size() > 0) { + var val = $focused.eq(-1).attr('data-val'); + delSelected(val); + $field.trigger('datachange'); + } else { + $('.selected-item', $selected).eq(-1).addClass('focused'); + } + } else { + var $items = $('.selected-item', $selected); + if ($items.size() > 0) { + var val = $items.eq(-1).attr('data-val'); + delSelected(val); + $field.trigger('datachange'); + } + } + }); + $field.on('focus.select', function() { + $('.selected-item.focused', $selected).removeClass('focused'); + }); + $selected.on('click.select', '.selected-item', function(e) { + $('.selected-item.focused', $selected).removeClass('focused'); + $(this).addClass('focused'); + e.stopImmediatePropagation(); + }); + $selected.on('click.select', '.selected-item .close', function(e) { + var val = $(this).parents('.selected-item').attr('data-val'); + delSelected(val); + if (options.multiSelect) { + $field.trigger('datachange').focusAndSelectAll(); + } + e.stopImmediatePropagation(); + }); + $select.on('click.select', '.select-clear', function(e) { + if ($field.value().length > 0) { + $field.value('').trigger('input').focus(); + options.onClear && options.onClear(); + } else { + clearSelected(); + $field.focus(); + } + e.stopImmediatePropagation(); + }); + $select.on('click.select', function(e) { + if ($(e.target).is('.select')) { + $field.focus(); + } + }); + if (selectedVal.length) { + updateSelected(); + $field.trigger('datachange'); + } + $select.data('inited', true); + return this; + }); + }; + $.fn.destroySelect = function() { + return this.map(function() { + var $select = $(this); + var $field = $('.form-control', $select); + var $selected = $('.selected-items', $select); + $field.destroySearch(); + $field.off('.select'); + $selected.off('.select'); + return this; + }); + } + $.fn.hasField = function(name) { + return this.first().map(function() { + if (this.tagName == 'FORM') { + if (this[name]) { + return true; + } + return $('.input[data-name]', this).filter(function() { + return ($(this).attr('data-name') == name); + }).size() > 0; + } + return false; + }).get(0) || false; + }; + $.fn.field = function(name) { + return this.first().map(function() { + if (this.tagName == 'FORM') { + if (this[name]) { + return this[name]; + } + return $('.input[data-name],.select[data-name]', this).filter(function() { + return ($(this).attr('data-name') == name); + }).get(0); + } + }); + }; + $.fn.reset = function(val) { + return this.each(function() { + if (this.tagName == 'FORM') { + this.reset(); + $('.input[data-name]', this).each(function() { + $(this).text($(this).attr('data-value')).trigger('input'); + }); + $('.select[data-name]', this).each(function() { + $(this).trigger('reset'); + }); + } + }); + }; + $.fn.scrollHeight = function() { + return this.first().map(function() { + return this.scrollHeight; + }).get(0) || ''; + }; + $.fn.defaultValue = function(val) { + if (typeof val !== 'undefined') { + return this.each(function() { + if (this.tagName == 'TEXTAREA' || this.tagName == 'INPUT') { + this.defaultValue = val; + } else { + $(this).attr('data-value', val); + } + }); + } + return this.first().map(function() { + if (this.tagName == 'TEXTAREA' || this.tagName == 'INPUT') { + return this.defaultValue || ''; + } else { + return $(this).attr('data-value') || ''; + } + }).get(0) || ''; + }; + $.fn.value = function(val) { + if (typeof val !== 'undefined') { + return this.each(function() { + if (this.tagName == 'TEXTAREA' || this.tagName == 'INPUT' || this instanceof RadioNodeList) { + this.value = val; + } else { + $(this).text(val).trigger('input'); + } + }); + } + return this.first().map(function() { + if (this.tagName == 'TEXTAREA' || this.tagName == 'INPUT' || this instanceof RadioNodeList) { + return this.value || ''; + } else { + return $(this).text() || ''; + } + }).get(0) || ''; + }; + $.fn.values = function(val) { + if (typeof val !== 'undefined') { + return this.value(val); + } + return this.map(function() { + if (this.tagName == 'TEXTAREA' || this.tagName == 'INPUT') { + return this.value || ''; + } else { + return $(this).text() || ''; + } + }).get() || []; + }; + + $.fn.initTextarea = function(options) { + options = options || {}; + + function getRangeText(range) { + var div = document.createElement('DIV'); + div.appendChild(range.cloneContents()); + return getText(div, true); + } + function isBlockEl(el) { + var blockTags = {ADDRESS: 1, ARTICLE: 1, ASIDE: 1, AUDIO: 1, BLOCKQUOTE: 1, CANVAS: 1, DD: 1, DIV: 1, DL: 1, FIELDSET: 1, FIGCAPTION: 1, FIGURE: 1, FIGURE: 1, FIGCAPTION: 1, FOOTER: 1, FORM: 1, H1: 1, H2: 1, H3: 1, H4: 1, H5: 1, H6: 1, HEADER: 1, HGROUP: 1, HR: 1, LI: 1, MAIN: 1, NAV: 1, NOSCRIPT: 1, OL: 1, OUTPUT: 1, P: 1, PRE: 1, SECTION: 1, TABLE: 1, TFOOT: 1, UL: 1, VIDEO: 1}; + // return (el.nodeType == el.ELEMENT_NODE && blockTags[el.tagName]); + if (el.nodeType == el.ELEMENT_NODE) { + var display = $(el).css('display'); + if (!display) return blockTags[el.tagName]; + return (display == 'block' || display == 'table' || display == 'table-row'); + } + return false; + } + function isMetadataEl(el) { + var metadataTags = {HEAD: 1, TITLE: 1, BASE: 1, LINK: 1, META: 1, STYLE: 1, SCRIPT: 1}; + return (el.nodeType == el.ELEMENT_NODE && metadataTags[el.tagName]); + } + function getText(el, safe_last_br) { + var child = el.firstChild, blocks = [], block = ''; + while (child) { + if (child.nodeType == child.TEXT_NODE) { + block += child.nodeValue; + } else if (child.nodeType == child.ELEMENT_NODE && !isMetadataEl(child)) { + if (child.tagName == 'BR') { + block += '\n'; + } else if (child.tagName == 'IMG') { + block += child.getAttribute('alt') || ''; + } else if (!isBlockEl(child)) { + block += getText(child); + } else { + if (block.length > 0) { + if (block.substr(-1) == '\n') { + block = block.slice(0, -1); + } + blocks.push(block); + block = ''; + } + blocks.push(getText(child, safe_last_br)); + } + } + child = child.nextSibling; + } + if (block.length > 0) { + if (!safe_last_br && block.substr(-1) == '\n') { + block = block.slice(0, -1); + } + blocks.push(block); + } + return blocks.join('\n'); + } + function getTextNodesIn(node) { + var textNodes = []; + if (node.nodeType == node.TEXT_NODE) { + textNodes.push(node); + } else { + for (var i = 0, len = node.childNodes.length; i < len; ++i) { + textNodes.push.apply(textNodes, getTextNodesIn(node.childNodes[i])); + } + } + return textNodes; + } + function editableClosest(el) { + while (el) { + if (el.nodeType == el.ELEMENT_NODE && + el.getAttribute('contenteditable') == 'true') { + return el; + } + el = el.parentNode; + } + return null; + } + function nonEditableClosest(el) { + while (el) { + if (el.tagName == 'MARK' && + el.getAttribute('contenteditable') == 'false') { + return el; + } + el = el.parentNode; + } + return null; + } + function setSelectionRange(el, start, end) { + var sel = window.getSelection(); + sel.removeAllRanges(); + var textNodes = getTextNodesIn(el); + var charCount = 0, endCharCount, i, textNode, node, offset, nonEditEl; + for (i = 0, charCount = 0; textNode = textNodes[i++]; ) { + endCharCount = charCount + textNode.length; + if (start >= charCount && (start < endCharCount || + (start == endCharCount && i <= textNodes.length))) { + if (nonEditEl = nonEditableClosest(textNode)) { + var range = document.createRange(); + if (start < end) range.setStartBefore(nonEditEl); + else range.setStartAfter(nonEditEl); + node = range.startContainer; + offset = range.startOffset; + } else { + node = textNode; + offset = start - charCount; + } + sel.collapse(node, offset); + break; + } + charCount = endCharCount; + } + if (start != end) { + for (i = 0, charCount = 0; textNode = textNodes[i++]; ) { + endCharCount = charCount + textNode.length; + if (end >= charCount && (end < endCharCount || + (end == endCharCount && i <= textNodes.length))) { + if (nonEditEl = nonEditableClosest(textNode)) { + var range = document.createRange(); + if (start < end) range.setStartAfter(nonEditEl); + else range.setStartBefore(nonEditEl); + node = range.startContainer; + offset = range.startOffset; + } else { + node = textNode; + offset = end - charCount; + } + sel.extend(node, offset); + break; + } + charCount = endCharCount; + } + } + } + function onKeyDown(e) { + if ((e.metaKey || e.ctrlKey) && !e.altKey && + e.which == 90) { // Z + e.preventDefault(); + if (e.shiftKey) { + redo(this); + } else { + undo(this); + } + } + else if ((e.metaKey || e.ctrlKey) && !e.shiftKey && !e.altKey && + e.which == 89) { // Y + e.preventDefault(); + redo(this); + } + else if (!e.shiftKey && !e.altKey && e.which == 13) { // Enter + if ((e.metaKey || e.ctrlKey) || $(this).data('textOptions').singleLine) { + e.preventDefault(); + $(this).parents('form').submit(); + } + } + else if ((e.metaKey || e.ctrlKey) && + !e.shiftKey && !e.altKey && e.which == 73 && + $(this).data('textOptions').allowTokens) { // I + e.preventDefault(); + $(this).data('$tokens').filter(':not(.used)').eq(0).trigger('click'); + } + else if (!e.metaKey && !e.ctrlKey && !e.shiftKey && !e.altKey && + (e.which == Keys.LEFT || e.which == Keys.RIGHT || e.which == Keys.BACKSPACE)) { + var isLeft = e.which == Keys.LEFT || e.which == Keys.BACKSPACE; + var isBackspace = e.which == Keys.BACKSPACE; + var sel = window.getSelection(); + if (sel.isCollapsed && sel.focusNode) { + if (sel.focusNode.nodeType == sel.focusNode.TEXT_NODE) { + var newOffset = sel.focusOffset + (isLeft ? -1 : 1); + if (newOffset < 0) { + var prevNode = sel.focusNode.previousSibling; + if (prevNode && prevNode.nodeType == prevNode.ELEMENT_NODE) { + var range = document.createRange(); + range.setStartBefore(prevNode); + if (isBackspace) { + range.setEnd(sel.focusNode, sel.focusOffset); + range.deleteContents(); + $(sel.focusNode).closest('.input').trigger('input'); + } else { + sel.collapse(range.startContainer, range.startOffset); + } + e.preventDefault(); + } else { + if (isBackspace) { + $(sel.focusNode).closest('.input').trigger('backspaceonleft'); + } + } + } else if (newOffset > sel.focusNode.nodeValue.length) { + var nextNode = sel.focusNode.nextSibling; + if (nextNode.nodeType == nextNode.ELEMENT_NODE && nextNode.tagName != 'BR') { + var range = document.createRange(); + range.setStartAfter(nextNode); + if (!isBackspace) { + sel.collapse(range.startContainer, range.startOffset); + } + e.preventDefault(); + } + } + } + else if (sel.focusNode.nodeType == sel.focusNode.ELEMENT_NODE) { + var curNode = sel.focusNode.childNodes[sel.focusOffset]; + if (isLeft) { + var prevNode = curNode ? curNode.previousSibling : sel.focusNode.lastChild; + while (prevNode && + prevNode.nodeType == prevNode.TEXT_NODE && + !prevNode.nodeValue.length) { + prevNode = prevNode.previousSibling; + } + if (prevNode && prevNode.nodeType == prevNode.ELEMENT_NODE) { + if (isBackspace) { + var range = document.createRange(); + range.selectNode(prevNode); + range.deleteContents(); + $(sel.focusNode).closest('.input').trigger('input'); + } else { + sel.collapse(sel.focusNode, sel.focusOffset - 1); + } + e.preventDefault(); + } else if (prevNode && prevNode.nodeType == prevNode.TEXT_NODE) { + if (isBackspace) { + var range = document.createRange(); + range.setStart(prevNode, prevNode.nodeValue.length - 1); + range.setEnd(prevNode, prevNode.nodeValue.length); + range.deleteContents(); + $(sel.focusNode).closest('.input').trigger('input'); + } else { + sel.collapse(prevNode, prevNode.nodeValue.length - 1); + } + e.preventDefault(); + } else { + if (isBackspace) { + $(sel.focusNode).closest('.input').trigger('backspaceonleft'); + } + } + } else { + if (curNode && curNode.nodeType == curNode.ELEMENT_NODE && curNode.tagName != 'BR') { + sel.collapse(sel.focusNode, sel.focusOffset + 1); + e.preventDefault(); + } else if (curNode && curNode.nodeType == curNode.TEXT_NODE) { + sel.collapse(curNode, 1); + e.preventDefault(); + } + } + } + } + } + } + function getFieldRange(field) { + var sel = window.getSelection(); + if (sel.anchorNode && sel.focusNode) { + var rng = document.createRange(); + rng.setStart(field, 0); + rng.setEnd(sel.anchorNode, sel.anchorOffset); + var startOffset = getRangeText(rng).length; + rng.setEnd(sel.focusNode, sel.focusOffset); + var endOffset = getRangeText(rng).length; + return {startOffset: startOffset, endOffset: endOffset}; + } + var offset = field.childNodes.length; + if (field.lastChild && field.lastChild.tagName == 'BR') { + offset--; + } + return {startOffset: offset, endOffset: offset}; + } + function setFieldRange(field, fieldRange) { + if (fieldRange) { + setSelectionRange(field, fieldRange.startOffset, fieldRange.endOffset); + } + } + function onSetFocus() { + setFieldRange(this, $(this).data('prevSelRange')); + } + function update(field, text, fieldRange) { + var $field = $(field); + var tokens = $field.data('tokens'); + var options = $field.data('textOptions'); + if (options.checkText) { + text = options.checkText(text); + } + var html = cleanHTML(text), fhtml; + if (options.allowTokens) { + var avail_tokens = []; + $.each(tokens, function(i, value) { + avail_tokens[i] = cleanHTML(value); + }); + var avail_count = tokens.length; + var $tokens = $field.data('$tokens'); + if (avail_count > 0) { + html = html.replace(TOKEN_REGEX, function(s) { + var i = avail_tokens.indexOf(s); + if (i >= 0) { + avail_tokens[i] = null; + avail_count--; + var $token = $tokens.eq(i); + if (!$token.hasClass('used')) { + $token.prepareSlideX().addClass('used'); + } + return '' + s + ''; + } else { + return s; + } + }); + $tokens.each(function(i) { + if (avail_tokens[i] !== null) { + var $token = $(this); + if ($token.hasClass('used')) { + $token.prepareSlideX().removeClass('used'); + } + } + }); + } + $tokens.parents('.key-add-tokens-wrap').toggleClass('empty', !avail_count) + } + if (options.allowEmoji && options.emojiRE) { + html = html.replace(options.emojiRE, function(s) { + return '' + EmojiSearch.emojiHtml(s) + ''; + }); + } + html = html.split(getBR()).join('\n'); + if (options.singleLine) { + html = html.replace(/^\n+|\n+$/g, '').replace(/\n+/g, ' '); + } + fhtml = $field.html(); + if (fhtml === html) { + $field.append('
').toggleClass('empty', !$field.text().length); + return; + } + if (fhtml === html + getBR()) { + $field.toggleClass('empty', !$field.text().length); + return; + } + + fieldRange = fieldRange || getFieldRange(field); + $field.html(html + getBR()).toggleClass('empty', !$field.text().length); + setFieldRange(field, fieldRange); + } + function onInput() { + var field = this; + var $field = $(this); + var text = getText(field); + update(field, text); + + var history = $field.data('history'); + var fieldRange = getFieldRange(field); + var prevSelRange = $field.data('prevSelRange'); + var time = +(new Date); + history.list = history.index >= 0 ? history.list.slice(0, history.index + 1) : []; + if (history.index >= 0 && history.list[history.index]) { + var entry = history.list[history.index]; + if (entry.text == text) { + return; + } + if (time - entry.time < 1000 && + entry.redoSel.startOffset == entry.redoSel.endOffset && + (entry.text.length - entry.redoSel.endOffset) == + (text.length - fieldRange.endOffset)) { + entry.text = text; + entry.redoSel = fieldRange; + return; + } + entry.undoSel = prevSelRange; + } + history.list.push({text: text, redoSel: fieldRange, time: time}); + history.index++; + } + function undo(field) { + var $field = $(field); + var history = $field.data('history'); + if (history.index > 0) { + history.index--; + var entry = history.list[history.index]; + update(field, entry.text, entry.undoSel); + } + } + function redo(field) { + var $field = $(field); + var history = $field.data('history'); + if (history.index < history.list.length - 1) { + history.index++; + var entry = history.list[history.index]; + update(field, entry.text, entry.redoSel); + } + } + function onSelectionChange() { + $(this).data('prevSelRange', getFieldRange(this)); + var sel = window.getSelection(); + if (sel.isCollapsed) { + var nonEditEl; + if (nonEditEl = nonEditableClosest(sel.focusNode)) { + var range = document.createRange(); + if (sel.focusOffset < $(nonEditEl).text().length / 2) { + range.setStartBefore(nonEditEl); + } else { + range.setStartAfter(nonEditEl); + } + sel.collapse(range.startContainer, range.startOffset); + } + else if (sel.focusNode === this && sel.focusOffset == this.childNodes.length && this.lastChild && this.lastChild.nodeType == 'BR') { + sel.collapse(this, this.childNodes.length - 1); + } + else if (sel.focusNode.nodeType == sel.focusNode.TEXT_NODE && sel.focusOffset == sel.focusNode.nodeValue.length) { + var range = document.createRange(); + range.setStartAfter(sel.focusNode); + sel.collapse(range.startContainer, range.startOffset); + } + } + } + + if (!$(document).data('selectionchange_inited')) { + $(document).data('selectionchange_inited', true); + document.execCommand('autoUrlDetect', false, false); + $(document).on('selectionchange', function() { + var sel = window.getSelection(); + var anchorField, focusField; + var field, offset; + if (sel.anchorNode && (anchorField = editableClosest(sel.anchorNode))) { + $(anchorField).triggerHandler('selectionchange'); + } + if (sel.focusNode && (focusField = editableClosest(sel.focusNode)) && + anchorField != focusField) { + $(focusField).triggerHandler('selectionchange'); + } + if (!sel.focusNode && + document.activeElement && + document.activeElement.getAttribute('contenteditable') == 'true') { + field = document.activeElement; + offset = field.childNodes.length; + if (field.lastChild.tagName == 'BR') { + offset--; + } + sel.collapse(field, offset); + } + }); + } + + return this.each(function() { + var field = this; + var $field = $(field); + var textOptions = $.extend({}, options); + if ($field.data('inited')) { + return; + } + $field.attr('contenteditable', 'true'); + $field.data('textOptions', textOptions); + + function insertTag(e) { + e.preventDefault(); + document.execCommand('insertText', false, $(this).attr('data-token')); + $field.focus(); + } + + $field.data('history', {list: [], index: -1}); + + if (options.allowTokens) { + var tokens_attr = $field.attr('data-tokens'); + var tokens = tokens_attr ? tokens_attr.split(' ') : []; + + var $tokensBtns = $('
'); + for (var i = 0; i < tokens.length; i++) { + var token = tokens[i] = tokens[i].replace('\xa0', ' '); + var $token = $(''); + $token.attr('data-token', token).appendTo($tokensBtns); + } + var ua = navigator.userAgent || '', + is_mac = ua.indexOf('Mac') >= 0 || + ua.indexOf('AppleWebKit') >= 0 && + /Mobile\/\w+/.test(ua); + var shortcut = is_mac ? '⌘I' : 'Ctrl+I'; + $tokensBtns.attr('data-shortcut', shortcut).wrap('
').parent().wrap('
').parent().toggleClass('empty', !tokens.length).insertAfter($field); + var $tokens = $('.field-ins-btn', $tokensBtns); + $tokens.on('click.tr-textarea', insertTag); + $field.data('$tokens', $tokens); + $field.data('tokens', tokens); + } + if ($field.is('[data-single-line]')) { + textOptions.singleLine = true; + } + if ($field.is('[data-value]')) { + $field.value($field.defaultValue()); + } else { + $field.defaultValue($field.value()); + } + + $field.on('selectionchange.tr-textarea', onSelectionChange); + $field.on('keydown.tr-textarea', onKeyDown); + $field.on('input.tr-textarea', onInput); + $field.on('setfocus.tr-textarea', onSetFocus); + $field.trigger('input'); + $field.data('inited', true); + }); + + }; + $.fn.destroyTextarea = function() { + return this.off('.tr-textarea').each(function() { + $(this).data('inited', false); + var $tokens = $(this).data('$tokens'); + if ($tokens) { + $tokens.off('.tr-textarea'); + } + }); + }; + + $.fn.blockBodyScroll = function() { + function onResultsMouseWheel(e) { + var d = e.originalEvent.wheelDelta; + if((this.scrollTop === (this.scrollHeight - this.clientHeight) && d < 0) || + (this.scrollTop === 0 && d > 0)) { + e.preventDefault(); + } + } + return this.on('mousewheel', onResultsMouseWheel); + }; + + $.fn.initAutosize = function() { + return this.map(function(){ autosize(this); return this; }); + }; + + $.fn.updateAutosize = function() { + return this.map(function(){ autosize.update(this); return this; }); + }; + + $.fn.destroyAutosize = function() { + return this.map(function(){ autosize.destroy(this); return this; }); + }; + +})(jQuery); + +function getBR() { + if (window._brHTML) return window._brHTML; + return window._brHTML = $('

').html(); +} + +function cleanHTML(value) { + return value.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/\n/g, getBR()); +} +function uncleanHTML(value) { + return $('
').html(value).text(); +} +function cleanRE(value) { + return value.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&"); +} +function wrapHighlight(value, highlight, wrap_tag, prefix_only) { + value = cleanHTML(value); + if (highlight) { + var pattern = cleanRE(cleanHTML(highlight)); + if (prefix_only) { + pattern = '^' + pattern; + } + value = value.replace(new RegExp(pattern, 'gi'), '$&<\/strong>'); + } + if (wrap_tag) { + value = value.replace(TOKEN_REGEX, '$&'); + } + return value; +} +function wrapSize(size) { + if (size < 1024) { + return size + ' B'; + } else if (size < 1048576) { + return (Math.round(size * 10 / 1024.0) / 10) + ' KB'; + } else if (size < 1073741824) { + return (Math.round(size * 10 / 1048576.0) / 10) + ' MB'; + } else { + return (Math.round(size * 10 / 1073741824.0) / 10) + ' GB'; + } +} +function dataUrlToBlob(url) { + try { + var match = null; + if (match = url.match(/^data:(image\/gif|image\/jpe?g|image\/png|video\/mp4);base64,(.*)$/)) { + var type = match[1], b64 = match[2]; + var binary = atob(b64); + var array = []; + for(var i = 0; i < binary.length; i++) { + array.push(binary.charCodeAt(i)); + } + return new Blob([new Uint8Array(array)], {type: type}); + } + } catch (e) {} + return false; +} +function copyToClipboard(str) { + var $text = $('",k.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue,c.appendChild(b),b.innerHTML="",k.checkClone=b.cloneNode(!0).cloneNode(!0).lastChild.checked,k.noCloneEvent=!0,b.attachEvent&&(b.attachEvent("onclick",function(){k.noCloneEvent=!1}),b.cloneNode(!0).click()),null==k.deleteExpando){k.deleteExpando=!0;try{delete b.test}catch(d){k.deleteExpando=!1}}}(),function(){var b,c,d=y.createElement("div");for(b in{submit:!0,change:!0,focusin:!0})c="on"+b,(k[b+"Bubbles"]=c in a)||(d.setAttribute(c,"t"),k[b+"Bubbles"]=d.attributes[c].expando===!1);d=null}();var X=/^(?:input|select|textarea)$/i,Y=/^key/,Z=/^(?:mouse|pointer|contextmenu)|click/,$=/^(?:focusinfocus|focusoutblur)$/,_=/^([^.]*)(?:\.(.+)|)$/;function ab(){return!0}function bb(){return!1}function cb(){try{return y.activeElement}catch(a){}}m.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,n,o,p,q,r=m._data(a);if(r){c.handler&&(i=c,c=i.handler,e=i.selector),c.guid||(c.guid=m.guid++),(g=r.events)||(g=r.events={}),(k=r.handle)||(k=r.handle=function(a){return typeof m===K||a&&m.event.triggered===a.type?void 0:m.event.dispatch.apply(k.elem,arguments)},k.elem=a),b=(b||"").match(E)||[""],h=b.length;while(h--)f=_.exec(b[h])||[],o=q=f[1],p=(f[2]||"").split(".").sort(),o&&(j=m.event.special[o]||{},o=(e?j.delegateType:j.bindType)||o,j=m.event.special[o]||{},l=m.extend({type:o,origType:q,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&m.expr.match.needsContext.test(e),namespace:p.join(".")},i),(n=g[o])||(n=g[o]=[],n.delegateCount=0,j.setup&&j.setup.call(a,d,p,k)!==!1||(a.addEventListener?a.addEventListener(o,k,!1):a.attachEvent&&a.attachEvent("on"+o,k))),j.add&&(j.add.call(a,l),l.handler.guid||(l.handler.guid=c.guid)),e?n.splice(n.delegateCount++,0,l):n.push(l),m.event.global[o]=!0);a=null}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,n,o,p,q,r=m.hasData(a)&&m._data(a);if(r&&(k=r.events)){b=(b||"").match(E)||[""],j=b.length;while(j--)if(h=_.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o){l=m.event.special[o]||{},o=(d?l.delegateType:l.bindType)||o,n=k[o]||[],h=h[2]&&new RegExp("(^|\\.)"+p.join("\\.(?:.*\\.|)")+"(\\.|$)"),i=f=n.length;while(f--)g=n[f],!e&&q!==g.origType||c&&c.guid!==g.guid||h&&!h.test(g.namespace)||d&&d!==g.selector&&("**"!==d||!g.selector)||(n.splice(f,1),g.selector&&n.delegateCount--,l.remove&&l.remove.call(a,g));i&&!n.length&&(l.teardown&&l.teardown.call(a,p,r.handle)!==!1||m.removeEvent(a,o,r.handle),delete k[o])}else for(o in k)m.event.remove(a,o+b[j],c,d,!0);m.isEmptyObject(k)&&(delete r.handle,m._removeData(a,"events"))}},trigger:function(b,c,d,e){var f,g,h,i,k,l,n,o=[d||y],p=j.call(b,"type")?b.type:b,q=j.call(b,"namespace")?b.namespace.split("."):[];if(h=l=d=d||y,3!==d.nodeType&&8!==d.nodeType&&!$.test(p+m.event.triggered)&&(p.indexOf(".")>=0&&(q=p.split("."),p=q.shift(),q.sort()),g=p.indexOf(":")<0&&"on"+p,b=b[m.expando]?b:new m.Event(p,"object"==typeof b&&b),b.isTrigger=e?2:3,b.namespace=q.join("."),b.namespace_re=b.namespace?new RegExp("(^|\\.)"+q.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,b.result=void 0,b.target||(b.target=d),c=null==c?[b]:m.makeArray(c,[b]),k=m.event.special[p]||{},e||!k.trigger||k.trigger.apply(d,c)!==!1)){if(!e&&!k.noBubble&&!m.isWindow(d)){for(i=k.delegateType||p,$.test(i+p)||(h=h.parentNode);h;h=h.parentNode)o.push(h),l=h;l===(d.ownerDocument||y)&&o.push(l.defaultView||l.parentWindow||a)}n=0;while((h=o[n++])&&!b.isPropagationStopped())b.type=n>1?i:k.bindType||p,f=(m._data(h,"events")||{})[b.type]&&m._data(h,"handle"),f&&f.apply(h,c),f=g&&h[g],f&&f.apply&&m.acceptData(h)&&(b.result=f.apply(h,c),b.result===!1&&b.preventDefault());if(b.type=p,!e&&!b.isDefaultPrevented()&&(!k._default||k._default.apply(o.pop(),c)===!1)&&m.acceptData(d)&&g&&d[p]&&!m.isWindow(d)){l=d[g],l&&(d[g]=null),m.event.triggered=p;try{d[p]()}catch(r){}m.event.triggered=void 0,l&&(d[g]=l)}return b.result}},dispatch:function(a){a=m.event.fix(a);var b,c,e,f,g,h=[],i=d.call(arguments),j=(m._data(this,"events")||{})[a.type]||[],k=m.event.special[a.type]||{};if(i[0]=a,a.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,a)!==!1){h=m.event.handlers.call(this,a,j),b=0;while((f=h[b++])&&!a.isPropagationStopped()){a.currentTarget=f.elem,g=0;while((e=f.handlers[g++])&&!a.isImmediatePropagationStopped())(!a.namespace_re||a.namespace_re.test(e.namespace))&&(a.handleObj=e,a.data=e.data,c=((m.event.special[e.origType]||{}).handle||e.handler).apply(f.elem,i),void 0!==c&&(a.result=c)===!1&&(a.preventDefault(),a.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,a),a.result}},handlers:function(a,b){var c,d,e,f,g=[],h=b.delegateCount,i=a.target;if(h&&i.nodeType&&(!a.button||"click"!==a.type))for(;i!=this;i=i.parentNode||this)if(1===i.nodeType&&(i.disabled!==!0||"click"!==a.type)){for(e=[],f=0;h>f;f++)d=b[f],c=d.selector+" ",void 0===e[c]&&(e[c]=d.needsContext?m(c,this).index(i)>=0:m.find(c,this,null,[i]).length),e[c]&&e.push(d);e.length&&g.push({elem:i,handlers:e})}return h]","i"),hb=/^\s+/,ib=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,jb=/<([\w:]+)/,kb=/\s*$/g,rb={option:[1,""],legend:[1,"
","
"],area:[1,"",""],param:[1,"",""],thead:[1,"","
"],tr:[2,"","
"],col:[2,"","
"],td:[3,"","
"],_default:k.htmlSerialize?[0,"",""]:[1,"X
","
"]},sb=db(y),tb=sb.appendChild(y.createElement("div"));rb.optgroup=rb.option,rb.tbody=rb.tfoot=rb.colgroup=rb.caption=rb.thead,rb.th=rb.td;function ub(a,b){var c,d,e=0,f=typeof a.getElementsByTagName!==K?a.getElementsByTagName(b||"*"):typeof a.querySelectorAll!==K?a.querySelectorAll(b||"*"):void 0;if(!f)for(f=[],c=a.childNodes||a;null!=(d=c[e]);e++)!b||m.nodeName(d,b)?f.push(d):m.merge(f,ub(d,b));return void 0===b||b&&m.nodeName(a,b)?m.merge([a],f):f}function vb(a){W.test(a.type)&&(a.defaultChecked=a.checked)}function wb(a,b){return m.nodeName(a,"table")&&m.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function xb(a){return a.type=(null!==m.find.attr(a,"type"))+"/"+a.type,a}function yb(a){var b=pb.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function zb(a,b){for(var c,d=0;null!=(c=a[d]);d++)m._data(c,"globalEval",!b||m._data(b[d],"globalEval"))}function Ab(a,b){if(1===b.nodeType&&m.hasData(a)){var c,d,e,f=m._data(a),g=m._data(b,f),h=f.events;if(h){delete g.handle,g.events={};for(c in h)for(d=0,e=h[c].length;e>d;d++)m.event.add(b,c,h[c][d])}g.data&&(g.data=m.extend({},g.data))}}function Bb(a,b){var c,d,e;if(1===b.nodeType){if(c=b.nodeName.toLowerCase(),!k.noCloneEvent&&b[m.expando]){e=m._data(b);for(d in e.events)m.removeEvent(b,d,e.handle);b.removeAttribute(m.expando)}"script"===c&&b.text!==a.text?(xb(b).text=a.text,yb(b)):"object"===c?(b.parentNode&&(b.outerHTML=a.outerHTML),k.html5Clone&&a.innerHTML&&!m.trim(b.innerHTML)&&(b.innerHTML=a.innerHTML)):"input"===c&&W.test(a.type)?(b.defaultChecked=b.checked=a.checked,b.value!==a.value&&(b.value=a.value)):"option"===c?b.defaultSelected=b.selected=a.defaultSelected:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}}m.extend({clone:function(a,b,c){var d,e,f,g,h,i=m.contains(a.ownerDocument,a);if(k.html5Clone||m.isXMLDoc(a)||!gb.test("<"+a.nodeName+">")?f=a.cloneNode(!0):(tb.innerHTML=a.outerHTML,tb.removeChild(f=tb.firstChild)),!(k.noCloneEvent&&k.noCloneChecked||1!==a.nodeType&&11!==a.nodeType||m.isXMLDoc(a)))for(d=ub(f),h=ub(a),g=0;null!=(e=h[g]);++g)d[g]&&Bb(e,d[g]);if(b)if(c)for(h=h||ub(a),d=d||ub(f),g=0;null!=(e=h[g]);g++)Ab(e,d[g]);else Ab(a,f);return d=ub(f,"script"),d.length>0&&zb(d,!i&&ub(a,"script")),d=h=e=null,f},buildFragment:function(a,b,c,d){for(var e,f,g,h,i,j,l,n=a.length,o=db(b),p=[],q=0;n>q;q++)if(f=a[q],f||0===f)if("object"===m.type(f))m.merge(p,f.nodeType?[f]:f);else if(lb.test(f)){h=h||o.appendChild(b.createElement("div")),i=(jb.exec(f)||["",""])[1].toLowerCase(),l=rb[i]||rb._default,h.innerHTML=l[1]+f.replace(ib,"<$1>")+l[2],e=l[0];while(e--)h=h.lastChild;if(!k.leadingWhitespace&&hb.test(f)&&p.push(b.createTextNode(hb.exec(f)[0])),!k.tbody){f="table"!==i||kb.test(f)?""!==l[1]||kb.test(f)?0:h:h.firstChild,e=f&&f.childNodes.length;while(e--)m.nodeName(j=f.childNodes[e],"tbody")&&!j.childNodes.length&&f.removeChild(j)}m.merge(p,h.childNodes),h.textContent="";while(h.firstChild)h.removeChild(h.firstChild);h=o.lastChild}else p.push(b.createTextNode(f));h&&o.removeChild(h),k.appendChecked||m.grep(ub(p,"input"),vb),q=0;while(f=p[q++])if((!d||-1===m.inArray(f,d))&&(g=m.contains(f.ownerDocument,f),h=ub(o.appendChild(f),"script"),g&&zb(h),c)){e=0;while(f=h[e++])ob.test(f.type||"")&&c.push(f)}return h=null,o},cleanData:function(a,b){for(var d,e,f,g,h=0,i=m.expando,j=m.cache,l=k.deleteExpando,n=m.event.special;null!=(d=a[h]);h++)if((b||m.acceptData(d))&&(f=d[i],g=f&&j[f])){if(g.events)for(e in g.events)n[e]?m.event.remove(d,e):m.removeEvent(d,e,g.handle);j[f]&&(delete j[f],l?delete d[i]:typeof d.removeAttribute!==K?d.removeAttribute(i):d[i]=null,c.push(f))}}}),m.fn.extend({text:function(a){return V(this,function(a){return void 0===a?m.text(this):this.empty().append((this[0]&&this[0].ownerDocument||y).createTextNode(a))},null,a,arguments.length)},append:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=wb(this,a);b.appendChild(a)}})},prepend:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=wb(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},remove:function(a,b){for(var c,d=a?m.filter(a,this):this,e=0;null!=(c=d[e]);e++)b||1!==c.nodeType||m.cleanData(ub(c)),c.parentNode&&(b&&m.contains(c.ownerDocument,c)&&zb(ub(c,"script")),c.parentNode.removeChild(c));return this},empty:function(){for(var a,b=0;null!=(a=this[b]);b++){1===a.nodeType&&m.cleanData(ub(a,!1));while(a.firstChild)a.removeChild(a.firstChild);a.options&&m.nodeName(a,"select")&&(a.options.length=0)}return this},clone:function(a,b){return a=null==a?!1:a,b=null==b?a:b,this.map(function(){return m.clone(this,a,b)})},html:function(a){return V(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a)return 1===b.nodeType?b.innerHTML.replace(fb,""):void 0;if(!("string"!=typeof a||mb.test(a)||!k.htmlSerialize&&gb.test(a)||!k.leadingWhitespace&&hb.test(a)||rb[(jb.exec(a)||["",""])[1].toLowerCase()])){a=a.replace(ib,"<$1>");try{for(;d>c;c++)b=this[c]||{},1===b.nodeType&&(m.cleanData(ub(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(){var a=arguments[0];return this.domManip(arguments,function(b){a=this.parentNode,m.cleanData(ub(this)),a&&a.replaceChild(b,this)}),a&&(a.length||a.nodeType)?this:this.remove()},detach:function(a){return this.remove(a,!0)},domManip:function(a,b){a=e.apply([],a);var c,d,f,g,h,i,j=0,l=this.length,n=this,o=l-1,p=a[0],q=m.isFunction(p);if(q||l>1&&"string"==typeof p&&!k.checkClone&&nb.test(p))return this.each(function(c){var d=n.eq(c);q&&(a[0]=p.call(this,c,d.html())),d.domManip(a,b)});if(l&&(i=m.buildFragment(a,this[0].ownerDocument,!1,this),c=i.firstChild,1===i.childNodes.length&&(i=c),c)){for(g=m.map(ub(i,"script"),xb),f=g.length;l>j;j++)d=i,j!==o&&(d=m.clone(d,!0,!0),f&&m.merge(g,ub(d,"script"))),b.call(this[j],d,j);if(f)for(h=g[g.length-1].ownerDocument,m.map(g,yb),j=0;f>j;j++)d=g[j],ob.test(d.type||"")&&!m._data(d,"globalEval")&&m.contains(h,d)&&(d.src?m._evalUrl&&m._evalUrl(d.src):m.globalEval((d.text||d.textContent||d.innerHTML||"").replace(qb,"")));i=c=null}return this}}),m.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){m.fn[a]=function(a){for(var c,d=0,e=[],g=m(a),h=g.length-1;h>=d;d++)c=d===h?this:this.clone(!0),m(g[d])[b](c),f.apply(e,c.get());return this.pushStack(e)}});var Cb,Db={};function Eb(b,c){var d,e=m(c.createElement(b)).appendTo(c.body),f=a.getDefaultComputedStyle&&(d=a.getDefaultComputedStyle(e[0]))?d.display:m.css(e[0],"display");return e.detach(),f}function Fb(a){var b=y,c=Db[a];return c||(c=Eb(a,b),"none"!==c&&c||(Cb=(Cb||m("