aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2014-12-20 15:42:44 -0800
committerfriendica <info@friendica.com>2014-12-20 15:42:44 -0800
commit148f0eb4aed6fdbec62f50d87e6db0c8df35fe28 (patch)
tree16cbf075a0f3be7eb100ad9c44c70ebd9d44f3f5
parentce032531dc63e2be232477bca11bac3aa3dfe314 (diff)
parent9684d682aef5a3fb869498522a6740bb4d721839 (diff)
downloadvolse-hubzilla-148f0eb4aed6fdbec62f50d87e6db0c8df35fe28.tar.gz
volse-hubzilla-148f0eb4aed6fdbec62f50d87e6db0c8df35fe28.tar.bz2
volse-hubzilla-148f0eb4aed6fdbec62f50d87e6db0c8df35fe28.zip
Merge https://github.com/friendica/red into pending_merge
-rw-r--r--doc/accounts_profiles_channels_basics.bb2
-rw-r--r--doc/api_posting.bb6
-rw-r--r--doc/channels.bb2
-rw-r--r--doc/checking_account_quota_usage.bb9
-rw-r--r--doc/de/channels.bb2
-rw-r--r--doc/faq_admins.bb10
-rw-r--r--doc/hidden_configs.bb2
-rw-r--r--include/text.php69
-rw-r--r--library/jquery-textcomplete/LICENSE21
-rw-r--r--library/jquery-textcomplete/jquery.textcomplete.js1088
-rw-r--r--mod/smilies.php14
-rw-r--r--view/js/autocomplete.js201
-rw-r--r--view/php/theme_init.php2
13 files changed, 1210 insertions, 218 deletions
diff --git a/doc/accounts_profiles_channels_basics.bb b/doc/accounts_profiles_channels_basics.bb
index c064e99f1..f8abd3c3b 100644
--- a/doc/accounts_profiles_channels_basics.bb
+++ b/doc/accounts_profiles_channels_basics.bb
@@ -7,7 +7,7 @@ You have [i]one[/i] account. This consists of your email account and your passwo
[i]Think of your account as the way you authenticate at one Red Matrix site. It lets you do things, such as creating profiles and channels with which you can connect to other people.[/i]
[b]Profile[/b]
-You have surely registered with some other internet services, such as forums or online communities. For all of them you provided some information about yourself, such as date of birth, country, age and the likes. If you like you can see your profile here: [baseurl]/profile/[observer.webname] and edit it by clicking on the pencil icon next to your avatar image.
+You have surely registered with some other internet services, such as forums or online communities. For all of them you provided some information about yourself, such as date of birth, country, age and the likes. [observer=1]If you like you can see your profile here: [baseurl]/profile/[observer.webname] and edit it by clicking on the pencil icon next to your avatar image. [/observer]
Unlike other services Red Matrix offers you the advantage of creating [i]many more profiles[/i]. That way you are able to distinguish between profiles targeted specially at everyone (your public profile), your work mates, your family and your partner.
[i]Think of your profile as the basic information about yourself you tell other people.[/i]
diff --git a/doc/api_posting.bb b/doc/api_posting.bb
index eeb7127fd..fa9558268 100644
--- a/doc/api_posting.bb
+++ b/doc/api_posting.bb
@@ -2,7 +2,7 @@
The API allows you to post to the red# by HTTP POST request. Below you see an example using the command line tool cURL:
-[code]curl -ssl -u [color=blue]$E-Mail[/color]:[color=blue]$Password[/color] -d "[color=blue]$Parameters[/color]" [url][observer.baseurl]/api/statuses/update
+[code]curl -ssl -u [color=blue]$E-Mail[/color]:[color=blue]$Password[/color] -d "[color=blue]$Parameters[/color]" [url][observer=1][observer.baseurl][/observer][observer=0]example.com[/observer]/api/statuses/update
[/url][/code]
[table][tr][td]$E-Mail:[/td][td]The E-Mail Adress you use to login[/td][/tr]
[tr][td]$Password:[/td][td]The Password you use to login[/td][/tr]
@@ -18,6 +18,6 @@ The API allows you to post to the red# by HTTP POST request. Below you see an ex
[/ul]
-Instead of calling [observer.baseurl]/api/statuses/update which returns a json (you could also add .json on the end to clarify) output, you can use [observer.baseurl]/api/statuses/update.xml to get an xml formatted return.
+Instead of calling [observer=1][observer.baseurl][/observer][observer=0]example.com[/observer]/api/statuses/update which returns a json (you could also add .json on the end to clarify) output, you can use [observer.baseurl]/api/statuses/update.xml to get an xml formatted return.
-Instead of Basic HTTP Authentification you could also use oAuth. \ No newline at end of file
+Instead of Basic HTTP Authentification you could also use oAuth.
diff --git a/doc/channels.bb b/doc/channels.bb
index 82b70630c..ff0446541 100644
--- a/doc/channels.bb
+++ b/doc/channels.bb
@@ -20,7 +20,7 @@ You will be asked to provide a channel name, and a short nick name. For a channe
Once you have created your channel, you will be taken to the settings page, where you can configure your channel, and set your default permissions.
-Once you have done this, your channel is ready to use. At [observer.url] you will find your channel &quot;stream&quot;. This is where your recent activity will appear, in reverse chronological order. If you post in the box marked &quot;share&quot;, the entry will appear at the top of your stream. You will also find links to all the other communication areas for this channel here. The &quot;About&quot; tab contains your &quot;profile&quot;, the photos page contain photo albums, and the events page contains events share by both yourself and your contacts.
+Once you have done this, your channel is ready to use. At [observer=1][observer.url][/observer][observer=0]example.com/channel/username[/observer] you will find your channel &quot;stream&quot;. This is where your recent activity will appear, in reverse chronological order. If you post in the box marked &quot;share&quot;, the entry will appear at the top of your stream. You will also find links to all the other communication areas for this channel here. The &quot;About&quot; tab contains your &quot;profile&quot;, the photos page contain photo albums, and the events page contains events share by both yourself and your contacts.
The &quot;Matrix&quot; page contains all recent posts from across the matrix, again in reverse chronologial order. The exact posts that appear here depend largely on your permissions. At their most permissive, you will receive posts from complete strangers. At the other end of the scale, you may see posts from only your friends - or if you're feeling really anti-social, only your own posts.
diff --git a/doc/checking_account_quota_usage.bb b/doc/checking_account_quota_usage.bb
index 60d84005e..ca7e070ad 100644
--- a/doc/checking_account_quota_usage.bb
+++ b/doc/checking_account_quota_usage.bb
@@ -6,12 +6,15 @@ Here's how you can quickly check how much of your assigned quota you're currentl
[b]Check file storage quota levels[/b]
Visit the following URL in your browser:
-[observer.baseurl]/filestorage/[observer.webname]
+[observer=1][observer.baseurl]/filestorage/[observer.webname][/observer]
+[observer=0]example.com/filestorage/username[/observer]
[b]Check uploaded photos storage quota levels[/b]
-[observer.baseurl]/photos/[observer.webname]
+[observer=1][observer.baseurl]/photos/[observer.webname][/observer]
+[observer=0]example.com/photos/username[/observer]
Example:
-[observer.baseurl]/filestorage/[observer.webname]
+[observer=1][observer.baseurl]/filestorage/[observer.webname][/observer]
+[observer=0]example.com/filestorage/username[/observer]
#include doc/macros/main_footer.bb;
diff --git a/doc/de/channels.bb b/doc/de/channels.bb
index 41ea68404..19146cf9b 100644
--- a/doc/de/channels.bb
+++ b/doc/de/channels.bb
@@ -17,7 +17,7 @@ Du wirst nach einem Kanalnamen und einem kurzen Spitznamen gefragt. Für einen K
Nachdem Du Deinen Kanal erstellt hast, wirst Du zu den Einstellungen weitergeleitet. Hier kannst Du Deinen Kanal einrichten und die Standard-Berechtigungen setzen.
-Nachdem Du auch das getan hast, kannst Du Deinen Kanal verwenden. Unter der Addresse https://example.com/channel/spitzname ( [observer.url] ) findest Du Deinen Kanal. Hier werden Deine letzten Aktivitäten gezeigt, die neuesten oben. Wenn Du etwas in die Textbox schreibst, in der „Teilen“ steht, wird der neue Eintrag ganz oben in Deinem Kanal auftauchen. Du findest hier auch Links zu den anderen Kommunikationsbereichen Deines Kanals. Der „Über“-Reiter enthält Dein Profil, der „Fotos“-Reiter Deine Fotoalben, und der Veranstaltungskalender enthält Termine und Veranstaltungen, die Du und Deine Kontakte geteilt haben.
+Nachdem Du auch das getan hast, kannst Du Deinen Kanal verwenden. Unter der Addresse https://example.com/channel/spitzname [observer=1]( [observer.url] )[/observer] findest Du Deinen Kanal. Hier werden Deine letzten Aktivitäten gezeigt, die neuesten oben. Wenn Du etwas in die Textbox schreibst, in der „Teilen“ steht, wird der neue Eintrag ganz oben in Deinem Kanal auftauchen. Du findest hier auch Links zu den anderen Kommunikationsbereichen Deines Kanals. Der „Über“-Reiter enthält Dein Profil, der „Fotos“-Reiter Deine Fotoalben, und der Veranstaltungskalender enthält Termine und Veranstaltungen, die Du und Deine Kontakte geteilt haben.
Die „Matrix“-Seite enthält alle neuen Beiträge aus der gesamten Red Matrix, wieder die neuesten oben. Was genau zu sehen ist ist abhängig von den Zugriffsrechten. Falls die Zugriffsrechte Deines Kanals so eingestellt sind, dass jeder Beiträge in Deinen Stream stellen kann, wirst du auch Beiträge von Dir völlig unbekannten Personen hier sehen. Am anderen Ende der Skala kannst Du die Berechtigungen aber auch so einstellen, dass du nur die Beiträge deiner Freunde oder gar nur Deine eigenen siehst.
diff --git a/doc/faq_admins.bb b/doc/faq_admins.bb
index ec4f8d969..953563230 100644
--- a/doc/faq_admins.bb
+++ b/doc/faq_admins.bb
@@ -35,6 +35,16 @@ Don't listen on port 443 if you cannot use it. It is strongly recommended to so
valid SSL certificate rather than disabling port 443.
[*]
+[b]How do I update a non-Git install?[/b]
+1) Backup .htconfig.php
+2) Backup everything in store/
+3) Backup any custom changes in mod/site/ and view/site
+3) Delete your existing installation
+4) Upload the new version.
+5) Upload the new version of themes and addons.
+6) Restore everything backed up earlier.
+
+[*]
[b]What do I need to do when moving my hub to a different server[/b]
1) Git clone on the new server. Repeat the process for any custom themes, and addons.
diff --git a/doc/hidden_configs.bb b/doc/hidden_configs.bb
index afbac5e0d..727428176 100644
--- a/doc/hidden_configs.bb
+++ b/doc/hidden_configs.bb
@@ -25,7 +25,7 @@ This document assumes you're an administrator.
1 - check 3 octets
2 - check 2 octets
3 - check for any difference at all
- [b]system > protect_tag_hijacking[/b]
+ [b]system > prevent_tag_hijacking[/b]
Prevent foreign networks hijacking hashtags in your posts and directing them at its own resources.
[b]system > blocked[/b]
An array of xchans blocked by this channel. Technically, this is a
diff --git a/include/text.php b/include/text.php
index ee0fef262..6516d734d 100644
--- a/include/text.php
+++ b/include/text.php
@@ -958,37 +958,10 @@ function get_mood_verbs() {
return $arr;
}
-
-/**
- *
- * Function: smilies
- *
- * Description:
- * Replaces text emoticons with graphical images
- *
- * @Parameter: string $s
- *
- * Returns string
- *
- * It is expected that this function will be called using HTML text.
- * We will escape text between HTML pre and code blocks, and HTML attributes
- * (such as urls) from being processed.
- *
- * At a higher level, the bbcode [nosmile] tag can be used to prevent this
- * function from being executed by the prepare_text() routine when preparing
- * bbcode source for HTML display
- *
- */
-function smilies($s, $sample = false) {
+// Function to list all smilies, both internal and from addons
+// Returns array with keys 'texts' and 'icons'
+function list_smilies() {
$a = get_app();
-
- if(intval(get_config('system','no_smilies'))
- || (local_user() && intval(get_pconfig(local_user(),'system','no_smilies'))))
- return $s;
-
- $s = preg_replace_callback('{<(pre|code)>.*?</\1>}ism','smile_shield',$s);
- $s = preg_replace_callback('/<[a-z]+ .*?>/ism','smile_shield',$s);
-
$texts = array(
'&lt;3',
'&lt;/3',
@@ -1066,8 +1039,42 @@ function smilies($s, $sample = false) {
);
- $params = array('texts' => $texts, 'icons' => $icons, 'string' => $s);
+ $params = array('texts' => $texts, 'icons' => $icons);
call_hooks('smilie', $params);
+ return $params;
+}
+/**
+ *
+ * Function: smilies
+ *
+ * Description:
+ * Replaces text emoticons with graphical images
+ *
+ * @Parameter: string $s
+ *
+ * Returns string
+ *
+ * It is expected that this function will be called using HTML text.
+ * We will escape text between HTML pre and code blocks, and HTML attributes
+ * (such as urls) from being processed.
+ *
+ * At a higher level, the bbcode [nosmile] tag can be used to prevent this
+ * function from being executed by the prepare_text() routine when preparing
+ * bbcode source for HTML display
+ *
+ */
+function smilies($s, $sample = false) {
+ $a = get_app();
+
+ if(intval(get_config('system','no_smilies'))
+ || (local_user() && intval(get_pconfig(local_user(),'system','no_smilies'))))
+ return $s;
+
+ $s = preg_replace_callback('{<(pre|code)>.*?</\1>}ism','smile_shield',$s);
+ $s = preg_replace_callback('/<[a-z]+ .*?>/ism','smile_shield',$s);
+
+ $params = list_smilies();
+ $params['string'] = $s;
if($sample) {
$s = '<div class="smiley-sample">';
diff --git a/library/jquery-textcomplete/LICENSE b/library/jquery-textcomplete/LICENSE
new file mode 100644
index 000000000..4848bd637
--- /dev/null
+++ b/library/jquery-textcomplete/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2013-2014 Yuku Takahashi
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/library/jquery-textcomplete/jquery.textcomplete.js b/library/jquery-textcomplete/jquery.textcomplete.js
new file mode 100644
index 000000000..1e61683ea
--- /dev/null
+++ b/library/jquery-textcomplete/jquery.textcomplete.js
@@ -0,0 +1,1088 @@
+/*!
+ * jQuery.textcomplete
+ *
+ * Repository: https://github.com/yuku-t/jquery-textcomplete
+ * License: MIT (https://github.com/yuku-t/jquery-textcomplete/blob/master/LICENSE)
+ * Author: Yuku Takahashi
+ */
+
+if (typeof jQuery === 'undefined') {
+ throw new Error('jQuery.textcomplete requires jQuery');
+}
+
++function ($) {
+ 'use strict';
+
+ var warn = function (message) {
+ if (console.warn) { console.warn(message); }
+ };
+
+ $.fn.textcomplete = function (strategies, option) {
+ var args = Array.prototype.slice.call(arguments);
+ return this.each(function () {
+ var $this = $(this);
+ var completer = $this.data('textComplete');
+ if (!completer) {
+ completer = new $.fn.textcomplete.Completer(this, option || {});
+ $this.data('textComplete', completer);
+ }
+ if (typeof strategies === 'string') {
+ if (!completer) return;
+ args.shift()
+ completer[strategies].apply(completer, args);
+ if (strategies === 'destroy') {
+ $this.removeData('textComplete');
+ }
+ } else {
+ // For backward compatibility.
+ // TODO: Remove at v0.4
+ $.each(strategies, function (obj) {
+ $.each(['header', 'footer', 'placement', 'maxCount'], function (name) {
+ if (obj[name]) {
+ completer.option[name] = obj[name];
+ warn(name + 'as a strategy param is deprecated. Use option.');
+ delete obj[name];
+ }
+ });
+ });
+ completer.register($.fn.textcomplete.Strategy.parse(strategies));
+ }
+ });
+ };
+
+}(jQuery);
+
++function ($) {
+ 'use strict';
+
+ // Exclusive execution control utility.
+ //
+ // func - The function to be locked. It is executed with a function named
+ // `free` as the first argument. Once it is called, additional
+ // execution are ignored until the free is invoked. Then the last
+ // ignored execution will be replayed immediately.
+ //
+ // Examples
+ //
+ // var lockedFunc = lock(function (free) {
+ // setTimeout(function { free(); }, 1000); // It will be free in 1 sec.
+ // console.log('Hello, world');
+ // });
+ // lockedFunc(); // => 'Hello, world'
+ // lockedFunc(); // none
+ // lockedFunc(); // none
+ // // 1 sec past then
+ // // => 'Hello, world'
+ // lockedFunc(); // => 'Hello, world'
+ // lockedFunc(); // none
+ //
+ // Returns a wrapped function.
+ var lock = function (func) {
+ var locked, queuedArgsToReplay;
+
+ return function () {
+ // Convert arguments into a real array.
+ var args = Array.prototype.slice.call(arguments);
+ if (locked) {
+ // Keep a copy of this argument list to replay later.
+ // OK to overwrite a previous value because we only replay
+ // the last one.
+ queuedArgsToReplay = args;
+ return;
+ }
+ locked = true;
+ var self = this;
+ args.unshift(function replayOrFree() {
+ if (queuedArgsToReplay) {
+ // Other request(s) arrived while we were locked.
+ // Now that the lock is becoming available, replay
+ // the latest such request, then call back here to
+ // unlock (or replay another request that arrived
+ // while this one was in flight).
+ var replayArgs = queuedArgsToReplay;
+ queuedArgsToReplay = undefined;
+ replayArgs.unshift(replayOrFree);
+ func.apply(self, replayArgs);
+ } else {
+ locked = false;
+ }
+ });
+ func.apply(this, args);
+ };
+ };
+
+ var isString = function (obj) {
+ return Object.prototype.toString.call(obj) === '[object String]';
+ };
+
+ var uniqueId = 0;
+
+ function Completer(element, option) {
+ this.$el = $(element);
+ this.id = 'textcomplete' + uniqueId++;
+ this.strategies = [];
+ this.views = [];
+ this.option = $.extend({}, Completer._getDefaults(), option);
+
+ if (!this.$el.is('textarea') && !element.isContentEditable && element.contentEditable != 'true') {
+ throw new Error('textcomplete must be called on a Textarea or a ContentEditable.');
+ }
+
+ if (element === document.activeElement) {
+ // element has already been focused. Initialize view objects immediately.
+ this.initialize()
+ } else {
+ // Initialize view objects lazily.
+ var self = this;
+ this.$el.one('focus.' + this.id, function () { self.initialize(); });
+ }
+ }
+
+ Completer._getDefaults = function () {
+ if (!Completer.DEFAULTS) {
+ Completer.DEFAULTS = {
+ appendTo: $('body'),
+ zIndex: '100'
+ };
+ }
+
+ return Completer.DEFAULTS;
+ }
+
+ $.extend(Completer.prototype, {
+ // Public properties
+ // -----------------
+
+ id: null,
+ option: null,
+ strategies: null,
+ adapter: null,
+ dropdown: null,
+ $el: null,
+
+ // Public methods
+ // --------------
+
+ initialize: function () {
+ var element = this.$el.get(0);
+ // Initialize view objects.
+ this.dropdown = new $.fn.textcomplete.Dropdown(element, this, this.option);
+ var Adapter, viewName;
+ if (this.option.adapter) {
+ Adapter = this.option.adapter;
+ } else {
+ if (this.$el.is('textarea')) {
+ viewName = typeof element.selectionEnd === 'number' ? 'Textarea' : 'IETextarea';
+ } else {
+ viewName = 'ContentEditable';
+ }
+ Adapter = $.fn.textcomplete[viewName];
+ }
+ this.adapter = new Adapter(element, this, this.option);
+ },
+
+ destroy: function () {
+ this.$el.off('.' + this.id);
+ if (this.adapter) {
+ this.adapter.destroy();
+ }
+ if (this.dropdown) {
+ this.dropdown.destroy();
+ }
+ this.$el = this.adapter = this.dropdown = null;
+ },
+
+ // Invoke textcomplete.
+ trigger: function (text, skipUnchangedTerm) {
+ if (!this.dropdown) { this.initialize(); }
+ text != null || (text = this.adapter.getTextFromHeadToCaret());
+ var searchQuery = this._extractSearchQuery(text);
+ if (searchQuery.length) {
+ var term = searchQuery[1];
+ // Ignore shift-key, ctrl-key and so on.
+ if (skipUnchangedTerm && this._term === term) { return; }
+ this._term = term;
+ this._search.apply(this, searchQuery);
+ } else {
+ this._term = null;
+ this.dropdown.deactivate();
+ }
+ },
+
+ fire: function (eventName) {
+ var args = Array.prototype.slice.call(arguments, 1);
+ this.$el.trigger(eventName, args);
+ return this;
+ },
+
+ register: function (strategies) {
+ Array.prototype.push.apply(this.strategies, strategies);
+ },
+
+ // Insert the value into adapter view. It is called when the dropdown is clicked
+ // or selected.
+ //
+ // value - The selected element of the array callbacked from search func.
+ // strategy - The Strategy object.
+ select: function (value, strategy) {
+ this.adapter.select(value, strategy);
+ this.fire('change').fire('textComplete:select', value, strategy);
+ this.adapter.focus();
+ },
+
+ // Private properties
+ // ------------------
+
+ _clearAtNext: true,
+ _term: null,
+
+ // Private methods
+ // ---------------
+
+ // Parse the given text and extract the first matching strategy.
+ //
+ // Returns an array including the strategy, the query term and the match
+ // object if the text matches an strategy; otherwise returns an empty array.
+ _extractSearchQuery: function (text) {
+ for (var i = 0; i < this.strategies.length; i++) {
+ var strategy = this.strategies[i];
+ var context = strategy.context(text);
+ if (context || context === '') {
+ if (isString(context)) { text = context; }
+ var match = text.match(strategy.match);
+ if (match) { return [strategy, match[strategy.index], match]; }
+ }
+ }
+ return []
+ },
+
+ // Call the search method of selected strategy..
+ _search: lock(function (free, strategy, term, match) {
+ var self = this;
+ strategy.search(term, function (data, stillSearching) {
+ if (!self.dropdown.shown) {
+ self.dropdown.activate();
+ self.dropdown.setPosition(self.adapter.getCaretPosition());
+ }
+ if (self._clearAtNext) {
+ // The first callback in the current lock.
+ self.dropdown.clear();
+ self._clearAtNext = false;
+ }
+ self.dropdown.render(self._zip(data, strategy));
+ if (!stillSearching) {
+ // The last callback in the current lock.
+ free();
+ self._clearAtNext = true; // Call dropdown.clear at the next time.
+ }
+ }, match);
+ }),
+
+ // Build a parameter for Dropdown#render.
+ //
+ // Examples
+ //
+ // this._zip(['a', 'b'], 's');
+ // //=> [{ value: 'a', strategy: 's' }, { value: 'b', strategy: 's' }]
+ _zip: function (data, strategy) {
+ return $.map(data, function (value) {
+ return { value: value, strategy: strategy };
+ });
+ }
+ });
+
+ $.fn.textcomplete.Completer = Completer;
+}(jQuery);
+
++function ($) {
+ 'use strict';
+
+ var include = function (zippedData, datum) {
+ var i, elem;
+ var idProperty = datum.strategy.idProperty
+ for (i = 0; i < zippedData.length; i++) {
+ elem = zippedData[i];
+ if (elem.strategy !== datum.strategy) continue;
+ if (idProperty) {
+ if (elem.value[idProperty] === datum.value[idProperty]) return true;
+ } else {
+ if (elem.value === datum.value) return true;
+ }
+ }
+ return false;
+ };
+
+ var dropdownViews = {};
+ $(document).on('click', function (e) {
+ var id = e.originalEvent && e.originalEvent.keepTextCompleteDropdown;
+ $.each(dropdownViews, function (key, view) {
+ if (key !== id) { view.deactivate(); }
+ });
+ });
+
+ // Dropdown view
+ // =============
+
+ // Construct Dropdown object.
+ //
+ // element - Textarea or contenteditable element.
+ function Dropdown(element, completer, option) {
+ this.$el = Dropdown.findOrCreateElement(option);
+ this.completer = completer;
+ this.id = completer.id + 'dropdown';
+ this._data = []; // zipped data.
+ this.$inputEl = $(element);
+ this.option = option;
+
+ // Override setPosition method.
+ if (option.listPosition) { this.setPosition = option.listPosition; }
+ if (option.height) { this.$el.height(option.height); }
+ var self = this;
+ $.each(['maxCount', 'placement', 'footer', 'header', 'className'], function (_i, name) {
+ if (option[name] != null) { self[name] = option[name]; }
+ });
+ this._bindEvents(element);
+ dropdownViews[this.id] = this;
+ }
+
+ $.extend(Dropdown, {
+ // Class methods
+ // -------------
+
+ findOrCreateElement: function (option) {
+ var $parent = option.appendTo;
+ if (!($parent instanceof $)) { $parent = $($parent); }
+ var $el = $parent.children('.dropdown-menu')
+ if (!$el.length) {
+ $el = $('<ul class="dropdown-menu"></ul>').css({
+ display: 'none',
+ left: 0,
+ position: 'absolute',
+ zIndex: option.zIndex
+ }).appendTo($parent);
+ }
+ return $el;
+ }
+ });
+
+ $.extend(Dropdown.prototype, {
+ // Public properties
+ // -----------------
+
+ $el: null, // jQuery object of ul.dropdown-menu element.
+ $inputEl: null, // jQuery object of target textarea.
+ completer: null,
+ footer: null,
+ header: null,
+ id: null,
+ maxCount: 10,
+ placement: '',
+ shown: false,
+ data: [], // Shown zipped data.
+ className: '',
+
+ // Public methods
+ // --------------
+
+ destroy: function () {
+ // Don't remove $el because it may be shared by several textcompletes.
+ this.deactivate();
+
+ this.$el.off('.' + this.id);
+ this.$inputEl.off('.' + this.id);
+ this.clear();
+ this.$el = this.$inputEl = this.completer = null;
+ delete dropdownViews[this.id]
+ },
+
+ render: function (zippedData) {
+ var contentsHtml = this._buildContents(zippedData);
+ var unzippedData = $.map(this.data, function (d) { return d.value; });
+ if (this.data.length) {
+ this._renderHeader(unzippedData);
+ this._renderFooter(unzippedData);
+ if (contentsHtml) {
+ this._renderContents(contentsHtml);
+ this._activateIndexedItem();
+ }
+ this._setScroll();
+ } else if (this.shown) {
+ this.deactivate();
+ }
+ },
+
+ setPosition: function (position) {
+ this.$el.css(this._applyPlacement(position));
+ return this;
+ },
+
+ clear: function () {
+ this.$el.html('');
+ this.data = [];
+ this._index = 0;
+ this._$header = this._$footer = null;
+ },
+
+ activate: function () {
+ if (!this.shown) {
+ this.clear();
+ this.$el.show();
+ if (this.className) { this.$el.addClass(this.className); }
+ this.completer.fire('textComplete:show');
+ this.shown = true;
+ }
+ return this;
+ },
+
+ deactivate: function () {
+ if (this.shown) {
+ this.$el.hide();
+ if (this.className) { this.$el.removeClass(this.className); }
+ this.completer.fire('textComplete:hide');
+ this.shown = false;
+ }
+ return this;
+ },
+
+ isUp: function (e) {
+ return e.keyCode === 38 || (e.ctrlKey && e.keyCode === 80); // UP, Ctrl-P
+ },
+
+ isDown: function (e) {
+ return e.keyCode === 40 || (e.ctrlKey && e.keyCode === 78); // DOWN, Ctrl-N
+ },
+
+ isEnter: function (e) {
+ var modifiers = e.ctrlKey || e.altKey || e.metaKey || e.shiftKey;
+ return !modifiers && (e.keyCode === 13 || e.keyCode === 9 || (this.option.completeOnSpace === true && e.keyCode === 32)) // ENTER, TAB
+ },
+
+ isPageup: function (e) {
+ return e.keyCode === 33; // PAGEUP
+ },
+
+ isPagedown: function (e) {
+ return e.keyCode === 34; // PAGEDOWN
+ },
+
+ // Private properties
+ // ------------------
+
+ _data: null, // Currently shown zipped data.
+ _index: null,
+ _$header: null,
+ _$footer: null,
+
+ // Private methods
+ // ---------------
+
+ _bindEvents: function () {
+ this.$el.on('mousedown.' + this.id, '.textcomplete-item', $.proxy(this._onClick, this))
+ this.$el.on('mouseover.' + this.id, '.textcomplete-item', $.proxy(this._onMouseover, this));
+ this.$inputEl.on('keydown.' + this.id, $.proxy(this._onKeydown, this));
+ },
+
+ _onClick: function (e) {
+ var $el = $(e.target);
+ e.preventDefault();
+ e.originalEvent.keepTextCompleteDropdown = this.id;
+ if (!$el.hasClass('textcomplete-item')) {
+ $el = $el.closest('.textcomplete-item');
+ }
+ var datum = this.data[parseInt($el.data('index'), 10)];
+ this.completer.select(datum.value, datum.strategy);
+ var self = this;
+ // Deactive at next tick to allow other event handlers to know whether
+ // the dropdown has been shown or not.
+ setTimeout(function () { self.deactivate(); }, 0);
+ },
+
+ // Activate hovered item.
+ _onMouseover: function (e) {
+ var $el = $(e.target);
+ e.preventDefault();
+ if (!$el.hasClass('textcomplete-item')) {
+ $el = $el.closest('.textcomplete-item');
+ }
+ this._index = parseInt($el.data('index'), 10);
+ this._activateIndexedItem();
+ },
+
+ _onKeydown: function (e) {
+ if (!this.shown) { return; }
+ if (this.isUp(e)) {
+ e.preventDefault();
+ this._up();
+ } else if (this.isDown(e)) {
+ e.preventDefault();
+ this._down();
+ } else if (this.isEnter(e)) {
+ e.preventDefault();
+ this._enter();
+ } else if (this.isPageup(e)) {
+ e.preventDefault();
+ this._pageup();
+ } else if (this.isPagedown(e)) {
+ e.preventDefault();
+ this._pagedown();
+ }
+ },
+
+ _up: function () {
+ if (this._index === 0) {
+ this._index = this.data.length - 1;
+ } else {
+ this._index -= 1;
+ }
+ this._activateIndexedItem();
+ this._setScroll();
+ },
+
+ _down: function () {
+ if (this._index === this.data.length - 1) {
+ this._index = 0;
+ } else {
+ this._index += 1;
+ }
+ this._activateIndexedItem();
+ this._setScroll();
+ },
+
+ _enter: function () {
+ var datum = this.data[parseInt(this._getActiveElement().data('index'), 10)];
+ this.completer.select(datum.value, datum.strategy);
+ this._setScroll();
+ },
+
+ _pageup: function () {
+ var target = 0;
+ var threshold = this._getActiveElement().position().top - this.$el.innerHeight();
+ this.$el.children().each(function (i) {
+ if ($(this).position().top + $(this).outerHeight() > threshold) {
+ target = i;
+ return false;
+ }
+ });
+ this._index = target;
+ this._activateIndexedItem();
+ this._setScroll();
+ },
+
+ _pagedown: function () {
+ var target = this.data.length - 1;
+ var threshold = this._getActiveElement().position().top + this.$el.innerHeight();
+ this.$el.children().each(function (i) {
+ if ($(this).position().top > threshold) {
+ target = i;
+ return false
+ }
+ });
+ this._index = target;
+ this._activateIndexedItem();
+ this._setScroll();
+ },
+
+ _activateIndexedItem: function () {
+ this.$el.find('.textcomplete-item.active').removeClass('active');
+ this._getActiveElement().addClass('active');
+ },
+
+ _getActiveElement: function () {
+ return this.$el.children('.textcomplete-item:nth(' + this._index + ')');
+ },
+
+ _setScroll: function () {
+ var $activeEl = this._getActiveElement();
+ var itemTop = $activeEl.position().top;
+ var itemHeight = $activeEl.outerHeight();
+ var visibleHeight = this.$el.innerHeight();
+ var visibleTop = this.$el.scrollTop();
+ if (this._index === 0 || this._index == this.data.length - 1 || itemTop < 0) {
+ this.$el.scrollTop(itemTop + visibleTop);
+ } else if (itemTop + itemHeight > visibleHeight) {
+ this.$el.scrollTop(itemTop + itemHeight + visibleTop - visibleHeight);
+ }
+ },
+
+ _buildContents: function (zippedData) {
+ var datum, i, index;
+ var html = '';
+ for (i = 0; i < zippedData.length; i++) {
+ if (this.data.length === this.maxCount) break;
+ datum = zippedData[i];
+ if (include(this.data, datum)) { continue; }
+ index = this.data.length;
+ this.data.push(datum);
+ html += '<li class="textcomplete-item" data-index="' + index + '"><a>';
+ html += datum.strategy.template(datum.value);
+ html += '</a></li>';
+ }
+ return html;
+ },
+
+ _renderHeader: function (unzippedData) {
+ if (this.header) {
+ if (!this._$header) {
+ this._$header = $('<li class="textcomplete-header"></li>').prependTo(this.$el);
+ }
+ var html = $.isFunction(this.header) ? this.header(unzippedData) : this.header;
+ this._$header.html(html);
+ }
+ },
+
+ _renderFooter: function (unzippedData) {
+ if (this.footer) {
+ if (!this._$footer) {
+ this._$footer = $('<li class="textcomplete-footer"></li>').appendTo(this.$el);
+ }
+ var html = $.isFunction(this.footer) ? this.footer(unzippedData) : this.footer;
+ this._$footer.html(html);
+ }
+ },
+
+ _renderContents: function (html) {
+ if (this._$footer) {
+ this._$footer.before(html);
+ } else {
+ this.$el.append(html);
+ }
+ },
+
+ _applyPlacement: function (position) {
+ // If the 'placement' option set to 'top', move the position above the element.
+ if (this.placement.indexOf('top') !== -1) {
+ // Overwrite the position object to set the 'bottom' property instead of the top.
+ position = {
+ top: 'auto',
+ bottom: this.$el.parent().height() - position.top + position.lineHeight,
+ left: position.left
+ };
+ } else {
+ position.bottom = 'auto';
+ delete position.lineHeight;
+ }
+ if (this.placement.indexOf('absleft') !== -1) {
+ position.left = 0;
+ } else if (this.placement.indexOf('absright') !== -1) {
+ position.right = 0;
+ position.left = 'auto';
+ }
+ return position;
+ }
+ });
+
+ $.fn.textcomplete.Dropdown = Dropdown;
+}(jQuery);
+
++function ($) {
+ 'use strict';
+
+ // Memoize a search function.
+ var memoize = function (func) {
+ var memo = {};
+ return function (term, callback) {
+ if (memo[term]) {
+ callback(memo[term]);
+ } else {
+ func.call(this, term, function (data) {
+ memo[term] = (memo[term] || []).concat(data);
+ callback.apply(null, arguments);
+ });
+ }
+ };
+ };
+
+ function Strategy(options) {
+ $.extend(this, options);
+ if (this.cache) { this.search = memoize(this.search); }
+ }
+
+ Strategy.parse = function (optionsArray) {
+ return $.map(optionsArray, function (options) {
+ return new Strategy(options);
+ });
+ };
+
+ $.extend(Strategy.prototype, {
+ // Public properties
+ // -----------------
+
+ // Required
+ match: null,
+ replace: null,
+ search: null,
+
+ // Optional
+ cache: false,
+ context: function () { return true; },
+ index: 2,
+ template: function (obj) { return obj; },
+ idProperty: null
+ });
+
+ $.fn.textcomplete.Strategy = Strategy;
+
+}(jQuery);
+
++function ($) {
+ 'use strict';
+
+ var now = Date.now || function () { return new Date().getTime(); };
+
+ // Returns a function, that, as long as it continues to be invoked, will not
+ // be triggered. The function will be called after it stops being called for
+ // `wait` msec.
+ //
+ // This utility function was originally implemented at Underscore.js.
+ var debounce = function (func, wait) {
+ var timeout, args, context, timestamp, result;
+ var later = function () {
+ var last = now() - timestamp;
+ if (last < wait) {
+ timeout = setTimeout(later, wait - last);
+ } else {
+ timeout = null;
+ result = func.apply(context, args);
+ context = args = null;
+ }
+ };
+
+ return function () {
+ context = this;
+ args = arguments;
+ timestamp = now();
+ if (!timeout) {
+ timeout = setTimeout(later, wait);
+ }
+ return result;
+ };
+ };
+
+ function Adapter () {}
+
+ $.extend(Adapter.prototype, {
+ // Public properties
+ // -----------------
+
+ id: null, // Identity.
+ completer: null, // Completer object which creates it.
+ el: null, // Textarea element.
+ $el: null, // jQuery object of the textarea.
+ option: null,
+
+ // Public methods
+ // --------------
+
+ initialize: function (element, completer, option) {
+ this.el = element;
+ this.$el = $(element);
+ this.id = completer.id + this.constructor.name;
+ this.completer = completer;
+ this.option = option;
+
+ if (this.option.debounce) {
+ this._onKeyup = debounce(this._onKeyup, this.option.debounce);
+ }
+
+ this._bindEvents();
+ },
+
+ destroy: function () {
+ this.$el.off('.' + this.id); // Remove all event handlers.
+ this.$el = this.el = this.completer = null;
+ },
+
+ // Update the element with the given value and strategy.
+ //
+ // value - The selected object. It is one of the item of the array
+ // which was callbacked from the search function.
+ // strategy - The Strategy associated with the selected value.
+ select: function (/* value, strategy */) {
+ throw new Error('Not implemented');
+ },
+
+ // Returns the caret's relative coordinates from body's left top corner.
+ //
+ // FIXME: Calculate the left top corner of `this.option.appendTo` element.
+ getCaretPosition: function () {
+ var position = this._getCaretRelativePosition();
+ var offset = this.$el.offset();
+ position.top += offset.top;
+ position.left += offset.left;
+ return position;
+ },
+
+ // Focus on the element.
+ focus: function () {
+ this.$el.focus();
+ },
+
+ // Private methods
+ // ---------------
+
+ _bindEvents: function () {
+ this.$el.on('keyup.' + this.id, $.proxy(this._onKeyup, this));
+ },
+
+ _onKeyup: function (e) {
+ if (this._skipSearch(e)) { return; }
+ this.completer.trigger(this.getTextFromHeadToCaret(), true);
+ },
+
+ // Suppress searching if it returns true.
+ _skipSearch: function (clickEvent) {
+ switch (clickEvent.keyCode) {
+ case 40: // DOWN
+ case 38: // UP
+ return true;
+ }
+ if (clickEvent.ctrlKey) switch (clickEvent.keyCode) {
+ case 78: // Ctrl-N
+ case 80: // Ctrl-P
+ return true;
+ }
+ }
+ });
+
+ $.fn.textcomplete.Adapter = Adapter;
+}(jQuery);
+
++function ($) {
+ 'use strict';
+
+ // Textarea adapter
+ // ================
+ //
+ // Managing a textarea. It doesn't know a Dropdown.
+ function Textarea(element, completer, option) {
+ this.initialize(element, completer, option);
+ }
+
+ Textarea.DIV_PROPERTIES = {
+ left: -9999,
+ position: 'absolute',
+ top: 0,
+ whiteSpace: 'pre-wrap'
+ }
+
+ Textarea.COPY_PROPERTIES = [
+ 'border-width', 'font-family', 'font-size', 'font-style', 'font-variant',
+ 'font-weight', 'height', 'letter-spacing', 'word-spacing', 'line-height',
+ 'text-decoration', 'text-align', 'width', 'padding-top', 'padding-right',
+ 'padding-bottom', 'padding-left', 'margin-top', 'margin-right',
+ 'margin-bottom', 'margin-left', 'border-style', 'box-sizing', 'tab-size'
+ ];
+
+ $.extend(Textarea.prototype, $.fn.textcomplete.Adapter.prototype, {
+ // Public methods
+ // --------------
+
+ // Update the textarea with the given value and strategy.
+ select: function (value, strategy) {
+ var pre = this.getTextFromHeadToCaret();
+ var post = this.el.value.substring(this.el.selectionEnd);
+ var newSubstr = strategy.replace(value);
+ if ($.isArray(newSubstr)) {
+ post = newSubstr[1] + post;
+ newSubstr = newSubstr[0];
+ }
+ pre = pre.replace(strategy.match, newSubstr);
+ this.$el.val(pre + post);
+ this.el.selectionStart = this.el.selectionEnd = pre.length;
+ },
+
+ // Private methods
+ // ---------------
+
+ // Returns the caret's relative coordinates from textarea's left top corner.
+ //
+ // Browser native API does not provide the way to know the position of
+ // caret in pixels, so that here we use a kind of hack to accomplish
+ // the aim. First of all it puts a dummy div element and completely copies
+ // the textarea's style to the element, then it inserts the text and a
+ // span element into the textarea.
+ // Consequently, the span element's position is the thing what we want.
+ _getCaretRelativePosition: function () {
+ var dummyDiv = $('<div></div>').css(this._copyCss())
+ .text(this.getTextFromHeadToCaret());
+ var span = $('<span></span>').text('.').appendTo(dummyDiv);
+ this.$el.before(dummyDiv);
+ var position = span.position();
+ position.top += span.height() - this.$el.scrollTop();
+ position.lineHeight = span.height();
+ dummyDiv.remove();
+ return position;
+ },
+
+ _copyCss: function () {
+ return $.extend({
+ // Set 'scroll' if a scrollbar is being shown; otherwise 'auto'.
+ overflow: this.el.scrollHeight > this.el.offsetHeight ? 'scroll' : 'auto'
+ }, Textarea.DIV_PROPERTIES, this._getStyles());
+ },
+
+ _getStyles: (function ($) {
+ var color = $('<div></div>').css(['color']).color;
+ if (typeof color !== 'undefined') {
+ return function () {
+ return this.$el.css(Textarea.COPY_PROPERTIES);
+ };
+ } else { // jQuery < 1.8
+ return function () {
+ var $el = this.$el;
+ var styles = {};
+ $.each(Textarea.COPY_PROPERTIES, function (i, property) {
+ styles[property] = $el.css(property);
+ });
+ return styles;
+ };
+ }
+ })($),
+
+ getTextFromHeadToCaret: function () {
+ return this.el.value.substring(0, this.el.selectionEnd);
+ }
+ });
+
+ $.fn.textcomplete.Textarea = Textarea;
+}(jQuery);
+
++function ($) {
+ 'use strict';
+
+ var sentinelChar = '吶';
+
+ function IETextarea(element, completer, option) {
+ this.initialize(element, completer, option);
+ $('<span>' + sentinelChar + '</span>').css({
+ position: 'absolute',
+ top: -9999,
+ left: -9999
+ }).insertBefore(element);
+ }
+
+ $.extend(IETextarea.prototype, $.fn.textcomplete.Textarea.prototype, {
+ // Public methods
+ // --------------
+
+ select: function (value, strategy) {
+ var pre = this.getTextFromHeadToCaret();
+ var post = this.el.value.substring(pre.length);
+ var newSubstr = strategy.replace(value);
+ if ($.isArray(newSubstr)) {
+ post = newSubstr[1] + post;
+ newSubstr = newSubstr[0];
+ }
+ pre = pre.replace(strategy.match, newSubstr);
+ this.$el.val(pre + post);
+ this.el.focus();
+ var range = this.el.createTextRange();
+ range.collapse(true);
+ range.moveEnd('character', pre.length);
+ range.moveStart('character', pre.length);
+ range.select();
+ },
+
+ getTextFromHeadToCaret: function () {
+ this.el.focus();
+ var range = document.selection.createRange();
+ range.moveStart('character', -this.el.value.length);
+ var arr = range.text.split(sentinelChar)
+ return arr.length === 1 ? arr[0] : arr[1];
+ }
+ });
+
+ $.fn.textcomplete.IETextarea = IETextarea;
+}(jQuery);
+
+// NOTE: TextComplete plugin has contenteditable support but it does not work
+// fine especially on old IEs.
+// Any pull requests are REALLY welcome.
+
++function ($) {
+ 'use strict';
+
+ // ContentEditable adapter
+ // =======================
+ //
+ // Adapter for contenteditable elements.
+ function ContentEditable (element, completer, option) {
+ this.initialize(element, completer, option);
+ }
+
+ $.extend(ContentEditable.prototype, $.fn.textcomplete.Adapter.prototype, {
+ // Public methods
+ // --------------
+
+ // Update the content with the given value and strategy.
+ // When an dropdown item is selected, it is executed.
+ select: function (value, strategy) {
+ var pre = this.getTextFromHeadToCaret();
+ var sel = window.getSelection()
+ var range = sel.getRangeAt(0);
+ var selection = range.cloneRange();
+ selection.selectNodeContents(range.startContainer);
+ var content = selection.toString();
+ var post = content.substring(range.startOffset);
+ var newSubstr = strategy.replace(value);
+ if ($.isArray(newSubstr)) {
+ post = newSubstr[1] + post;
+ newSubstr = newSubstr[0];
+ }
+ pre = pre.replace(strategy.match, newSubstr);
+ range.selectNodeContents(range.startContainer);
+ range.deleteContents();
+ var node = document.createTextNode(pre + post);
+ range.insertNode(node);
+ range.setStart(node, pre.length);
+ range.collapse(true);
+ sel.removeAllRanges();
+ sel.addRange(range);
+ },
+
+ // Private methods
+ // ---------------
+
+ // Returns the caret's relative position from the contenteditable's
+ // left top corner.
+ //
+ // Examples
+ //
+ // this._getCaretRelativePosition()
+ // //=> { top: 18, left: 200, lineHeight: 16 }
+ //
+ // Dropdown's position will be decided using the result.
+ _getCaretRelativePosition: function () {
+ var range = window.getSelection().getRangeAt(0).cloneRange();
+ var node = document.createElement('span');
+ range.insertNode(node);
+ range.selectNodeContents(node);
+ range.deleteContents();
+ var $node = $(node);
+ var position = $node.offset();
+ position.left -= this.$el.offset().left;
+ position.top += $node.height() - this.$el.offset().top;
+ position.lineHeight = $node.height();
+ var dir = this.$el.attr('dir') || this.$el.css('direction');
+ if (dir === 'rtl') { position.left -= this.listView.$el.width(); }
+ return position;
+ },
+
+ // Returns the string between the first character and the caret.
+ // Completer will be triggered with the result for start autocompleting.
+ //
+ // Example
+ //
+ // // Suppose the html is '<b>hello</b> wor|ld' and | is the caret.
+ // this.getTextFromHeadToCaret()
+ // // => ' wor' // not '<b>hello</b> wor'
+ getTextFromHeadToCaret: function () {
+ var range = window.getSelection().getRangeAt(0);
+ var selection = range.cloneRange();
+ selection.selectNodeContents(range.startContainer);
+ return selection.toString().substring(0, range.startOffset);
+ }
+ });
+
+ $.fn.textcomplete.ContentEditable = ContentEditable;
+}(jQuery);
diff --git a/mod/smilies.php b/mod/smilies.php
index c47f95da7..b22d0c6d2 100644
--- a/mod/smilies.php
+++ b/mod/smilies.php
@@ -1,3 +1,15 @@
<?php
-function smilies_content(&$a) { return smilies('',true); }
+function smilies_content(&$a) {
+ if ($a->argv[1]==="json"){
+ $tmp = list_smilies();
+ $results = array();
+ for($i = 0; $i < count($tmp['texts']); $i++) {
+ $results[] = array('text' => $tmp['texts'][$i], 'icon' => $tmp['icons'][$i]);
+ }
+ json_return_and_die($results);
+ }
+ else {
+ return smilies('',true);
+ }
+}
diff --git a/view/js/autocomplete.js b/view/js/autocomplete.js
index c01ba6990..31d693c7b 100644
--- a/view/js/autocomplete.js
+++ b/view/js/autocomplete.js
@@ -1,200 +1,51 @@
/**
- * Friendica people autocomplete
+ * Red people autocomplete
*
- * require jQuery, jquery.textareas
+ * require jQuery, jquery.textcomplete
*/
-
-
-
-function ACPopup(elm,backend_url){
- this.idsel=-1;
- this.element = elm;
- this.searchText="";
- this.ready=true;
- this.kp_timer = false;
- this.url = backend_url;
-
- var w = 530;
- var h = 130;
-
-
- if(typeof elm.editorId == "undefined") {
- style = $(elm).offset();
- w = $(elm).width();
- h = $(elm).height();
- }
- else {
- var container = elm.getContainer();
- if(typeof container != "undefined") {
- style = $(container).offset();
- w = $(container).width();
- h = $(container).height();
- }
- }
-
- if(! w)
- w = 530;
-
- if(! h)
- h = 130;
-
- style.top=style.top+h;
- style.width = w;
- style.position = 'absolute';
- /* style['max-height'] = '150px';
- style.border = '1px solid red';
- style.background = '#cccccc';
-
- style.overflow = 'auto';
- style['z-index'] = '100000';
- */
- style.display = 'none';
-
- this.cont = $("<div class='acpopup'></div>");
- this.cont.css(style);
-
- $("body").append(this.cont);
-}
-ACPopup.prototype.close = function(){
- $(this.cont).remove();
- this.ready=false;
-}
-ACPopup.prototype.search = function(text){
- var that = this;
- this.searchText=text;
- if (this.kp_timer) clearTimeout(this.kp_timer);
- this.kp_timer = setTimeout( function(){that._search();}, 500);
-}
-ACPopup.prototype._search = function(){
- console.log("_search");
- var that = this;
+function mysearch(term, callback, backend_url) {
var postdata = {
start:0,
count:100,
- search:this.searchText,
+ //search:term.substring(1),
+ search:term,
type:'c',
}
$.ajax({
type:'POST',
- url: this.url,
+ url: backend_url,
data: postdata,
dataType: 'json',
success:function(data){
- that.cont.html("");
- if (data.tot>0){
- that.cont.show();
- $(data.items).each(function(){
- html = "<img src='{0}' height='16px' width='16px'>{1} ({2})".format(this.photo, this.name, ((this.label) ? this.nick + ' ' + this.label : this.nick) )
- that.add(this.taggable, html, this.nick.replace(' ','') + '+' + this.id + ' - ' + this.link);
- });
- } else {
- that.cont.hide();
- }
- }
- });
-
-}
-ACPopup.prototype.add = function(taggable, label, value){
- var that=this;
- var elm = $("<div class='acpopupitem " + taggable +"' title='"+value+"'>"+label+"</div>");
- elm.click(function(e){
- t = $(this).attr('title').replace(new RegExp(' \- .*'),'');
- if(typeof(that.element.container) === "undefined") {
- el=$(that.element);
- sel = el.getSelection();
- sel.start = sel.start- that.searchText.length;
- el.setSelection(sel.start,sel.end).replaceSelectedText(t+' ').collapseSelection(false);
- that.close();
- }
- else {
- txt = tinyMCE.activeEditor.getContent();
- // alert(that.searchText + ':' + t);
- newtxt = txt.replace('@' + that.searchText, '@' + t + ' ');
- tinyMCE.activeEditor.setContent(newtxt);
- tinyMCE.activeEditor.focus();
- that.close();
- }
- });
- $(this.cont).append(elm);
-}
-ACPopup.prototype.onkey = function(event){
- if (event.keyCode == '13') {
- if(this.idsel>-1) {
- this.cont.children()[this.idsel].click();
- event.preventDefault();
- }
- else
- this.close();
- }
- if (event.keyCode == '38') { //cursor up
- cmax = this.cont.children().size()-1;
- this.idsel--;
- if (this.idsel<0) this.idsel=cmax;
- event.preventDefault();
- }
- if (event.keyCode == '40' || event.keyCode == '9') { //cursor down
- cmax = this.cont.children().size()-1;
- this.idsel++;
- if (this.idsel>cmax) this.idsel=0;
- event.preventDefault();
- }
-
- if (event.keyCode == '38' || event.keyCode == '40' || event.keyCode == '9') {
- this.cont.children().removeClass('selected');
- $(this.cont.children()[this.idsel]).addClass('selected');
- }
-
- if (event.keyCode == '27') { //ESC
- this.close();
- }
+ callback(data.items);
+ },
+ }).fail(function () {callback([]); }); // Callback must be invoked even if something went wrong.
}
-function ContactAutocomplete(element,backend_url){
- this.pattern=/@(\!*)([^ \n]+)$/;
- this.popup=null;
- var that = this;
-
- $(element).unbind('keydown');
- $(element).unbind('keyup');
-
- $(element).keydown(function(event){
- if (that.popup!==null) that.popup.onkey(event);
- });
-
- $(element).keyup(function(event){
- cpos = $(this).getSelection();
- if (cpos.start==cpos.end){
- match = $(this).val().substring(0,cpos.start).match(that.pattern);
- if (match!==null){
- if (that.popup===null){
- that.popup = new ACPopup(this, backend_url);
- }
- if (that.popup.ready && match[2]!==that.popup.searchText) that.popup.search(match[2]);
- if (!that.popup.ready) that.popup=null;
-
- } else {
- if (that.popup!==null) {that.popup.close(); that.popup=null;}
- }
-
-
- }
- });
-
+function format(item) {
+ return "<img src='{0}' height='16px' width='16px'>{1} ({2})".format(item.photo, item.name, ((item.label) ? item.nick + ' ' + item.label : item.nick) )
}
+function replace(item) {
+ // $2 ensures that prefix (@,@!) is preserved
+ return '$1$2'+item.nick.replace(' ','') + '+' + item.id;
+}
/**
* jQuery plugin 'contact_autocomplete'
*/
(function( $ ){
- $.fn.contact_autocomplete = function(backend_url) {
- this.each(function(){
- new ContactAutocomplete(this, backend_url);
- });
+ $.fn.contact_autocomplete = function(backend_url) {
+
+ // Autocomplete contacts
+ contacts = {
+ match: /(^|\s)(@!?)(\w{2,})$/,
+ index: 3,
+ search: function(term, callback) { mysearch(term, callback, backend_url); },
+ replace: replace,
+ template: format,
+ }
+ this.textcomplete([contacts],{});
};
})( jQuery );
-
-
-
-
diff --git a/view/php/theme_init.php b/view/php/theme_init.php
index f1eaded6a..ff8b54c55 100644
--- a/view/php/theme_init.php
+++ b/view/php/theme_init.php
@@ -12,7 +12,6 @@ head_add_css('view/css/conversation.css');
head_add_css('view/css/widgets.css');
head_add_css('library/justifiedGallery/dist/css/justifiedGallery.css');
-
head_add_js('jquery.js');
head_add_js('jquery-migrate-1.1.1.js');
head_add_js('library/justifiedGallery/dist/js/jquery.justifiedGallery.js');
@@ -22,6 +21,7 @@ head_add_js('spin.js');
head_add_js('jquery.spin.js');
head_add_js('jquery.textinputs.js');
head_add_js('autocomplete.js');
+head_add_js('library/jquery-textcomplete/jquery.textcomplete.js');
head_add_js('library/fancybox/jquery.fancybox-1.3.4.js');
head_add_js('library/jquery.timeago.js');
head_add_js('library/jquery.divgrow/jquery.divgrow-1.3.1.js');