From: Hypolite Petovan Date: Thu, 28 Nov 2019 17:42:12 +0000 (-0500) Subject: Use visibility tags input for the default ACL selector X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ae3d4f63a31c5a9f35c55e6507263a600867b55a;p=friendica.git Use visibility tags input for the default ACL selector - Move friendica-tagsinput to default view folder - Update all references to ACL::getFullSelectorHTML - Fix theme-specific issues with the new ACL --- diff --git a/mod/community.php b/mod/community.php index 81857c6d3a..4d98f0c4fa 100644 --- a/mod/community.php +++ b/mod/community.php @@ -125,7 +125,7 @@ function community_content(App $a, $update = 0) 'default_location' => $a->user['default-location'], 'nickname' => $a->user['nickname'], 'lockstate' => (is_array($a->user) && (strlen($a->user['allow_cid']) || strlen($a->user['allow_gid']) || strlen($a->user['deny_cid']) || strlen($a->user['deny_gid'])) ? 'lock' : 'unlock'), - 'acl' => ACL::getFullSelectorHTML($a->user, true), + 'acl' => ACL::getFullSelectorHTML($a->page, $a->user, true), 'bang' => '', 'visitor' => 'block', 'profile_uid' => local_user(), diff --git a/mod/display.php b/mod/display.php index 12fa8d7ece..175616f98d 100644 --- a/mod/display.php +++ b/mod/display.php @@ -304,7 +304,7 @@ function display_content(App $a, $update = false, $update_uid = 0) 'default_location' => $a->user['default-location'], 'nickname' => $a->user['nickname'], 'lockstate' => (is_array($a->user) && (strlen($a->user['allow_cid']) || strlen($a->user['allow_gid']) || strlen($a->user['deny_cid']) || strlen($a->user['deny_gid'])) ? 'lock' : 'unlock'), - 'acl' => ACL::getFullSelectorHTML($a->user, true), + 'acl' => ACL::getFullSelectorHTML($a->page, $a->user, true), 'bang' => '', 'visitor' => 'block', 'profile_uid' => local_user(), diff --git a/mod/events.php b/mod/events.php index 11bb25f51b..a642f16651 100644 --- a/mod/events.php +++ b/mod/events.php @@ -13,6 +13,7 @@ use Friendica\Core\L10n; use Friendica\Core\Logger; use Friendica\Core\Renderer; use Friendica\Core\System; +use Friendica\Core\Theme; use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\Model\Event; @@ -384,6 +385,12 @@ function events_content(App $a) $events[$key]['item'] = $event_item; } + // ACL blocks are loaded in modals in frio + $a->page->registerFooterScript(Theme::getPathForFile('asset/typeahead.js/dist/typeahead.bundle.js')); + $a->page->registerFooterScript(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.js')); + $a->page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.css')); + $a->page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput-typeahead.css')); + $o = Renderer::replaceMacros($tpl, [ '$tabs' => $tabs, '$title' => L10n::t('Events'), @@ -486,7 +493,7 @@ function events_content(App $a) $perms = ACL::getDefaultUserPermissions($orig_event); if (!$cid && in_array($mode, ['new', 'copy'])) { - $acl = ACL::getFullSelectorHTML($a->user, false, $orig_event); + $acl = ACL::getFullSelectorHTML($a->page, $a->user, false, $perms); } else { $acl = ''; } @@ -506,11 +513,6 @@ function events_content(App $a) '$cid' => $cid, '$uri' => $uri, - '$allow_cid' => json_encode($perms['allow_cid']), - '$allow_gid' => json_encode($perms['allow_gid']), - '$deny_cid' => json_encode($perms['deny_cid']), - '$deny_gid' => json_encode($perms['deny_gid']), - '$title' => L10n::t('Event details'), '$desc' => L10n::t('Starting date and Title are required.'), '$s_text' => L10n::t('Event Starts:') . ' *', diff --git a/mod/network.php b/mod/network.php index 5fbfa9a5d8..44c7c8b44f 100644 --- a/mod/network.php +++ b/mod/network.php @@ -377,7 +377,7 @@ function networkFlatView(App $a, $update = 0) (strlen($a->user['allow_cid']) || strlen($a->user['allow_gid']) || strlen($a->user['deny_cid']) || strlen($a->user['deny_gid'])) ? 'lock' : 'unlock'), 'default_perms' => ACL::getDefaultUserPermissions($a->user), - 'acl' => ACL::getFullSelectorHTML($a->user, true), + 'acl' => ACL::getFullSelectorHTML($a->page, $a->user, true), 'bang' => '', 'visitor' => 'block', 'profile_uid' => local_user(), @@ -554,7 +554,7 @@ function networkThreadedView(App $a, $update, $parent) (strlen($a->user['allow_cid']) || strlen($a->user['allow_gid']) || strlen($a->user['deny_cid']) || strlen($a->user['deny_gid']))) ? 'lock' : 'unlock'), 'default_perms' => ACL::getDefaultUserPermissions($a->user), - 'acl' => ACL::getFullSelectorHTML($a->user, true, $default_permissions), + 'acl' => ACL::getFullSelectorHTML($a->page, $a->user, true, $default_permissions), 'bang' => (($gid || $cid || $nets) ? '!' : ''), 'visitor' => 'block', 'profile_uid' => local_user(), diff --git a/mod/photos.php b/mod/photos.php index e0630e7dc9..684e525d43 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -960,7 +960,7 @@ function photos_content(App $a) $tpl = Renderer::getMarkupTemplate('photos_upload.tpl'); - $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML($a->user)); + $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML($a->page, $a->user)); $o .= Renderer::replaceMacros($tpl,[ '$pagename' => L10n::t('Upload Photos'), @@ -1332,7 +1332,7 @@ function photos_content(App $a) $album_e = $ph[0]['album']; $caption_e = $ph[0]['desc']; - $aclselect_e = ACL::getFullSelectorHTML($a->user, false, $ph[0]); + $aclselect_e = ACL::getFullSelectorHTML($a->page, $a->user, false, $ph[0]); $edit = Renderer::replaceMacros($edit_tpl, [ '$id' => $ph[0]['id'], diff --git a/mod/settings.php b/mod/settings.php index 5ae4086b61..2ab4cc8f3c 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -1197,7 +1197,7 @@ function settings_content(App $a) '$permissions' => L10n::t('Default Post Permissions'), '$permdesc' => L10n::t("\x28click to open/close\x29"), '$visibility' => $profile['net-publish'], - '$aclselect' => ACL::getFullSelectorHTML($a->user), + '$aclselect' => ACL::getFullSelectorHTML($a->page, $a->user), '$suggestme' => $suggestme, '$blockwall'=> $blockwall, // array('blockwall', L10n::t('Allow friends to post to your profile page:'), !$blockwall, ''), '$blocktags'=> $blocktags, // array('blocktags', L10n::t('Allow friends to tag your posts:'), !$blocktags, ''), diff --git a/src/Core/ACL.php b/src/Core/ACL.php index ccc2b34d5d..880a1e47ff 100644 --- a/src/Core/ACL.php +++ b/src/Core/ACL.php @@ -6,13 +6,10 @@ namespace Friendica\Core; +use Friendica\App\Page; use Friendica\BaseObject; -use Friendica\Content\Feature; use Friendica\Database\DBA; use Friendica\Model\Contact; -use Friendica\Model\GContact; -use Friendica\Core\Session; -use Friendica\Util\Network; use Friendica\Model\Group; /** @@ -312,26 +309,50 @@ class ACL extends BaseObject /** * Return the full jot ACL selector HTML * + * @param Page $page * @param array $user User array - * @param bool $show_jotnets - * @param array $default_permissions Static defaults permission array: ['allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => ''] + * @param bool $for_federation + * @param array $default_permissions Static defaults permission array: + * [ + * 'allow_cid' => [], + * 'allow_gid' => [], + * 'deny_cid' => [], + * 'deny_gid' => [], + * 'hidewall' => true/false + * ] * @return string * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function getFullSelectorHTML(array $user = null, $show_jotnets = false, array $default_permissions = []) + public static function getFullSelectorHTML(Page $page, array $user = null, bool $for_federation = false, array $default_permissions = []) { + $page->registerFooterScript(Theme::getPathForFile('asset/typeahead.js/dist/typeahead.bundle.js')); + $page->registerFooterScript(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.js')); + $page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.css')); + $page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput-typeahead.css')); + // Defaults user permissions if (empty($default_permissions)) { $default_permissions = self::getDefaultUserPermissions($user); } + if (count($default_permissions['allow_cid']) + + count($default_permissions['allow_gid']) + + count($default_permissions['deny_cid']) + + count($default_permissions['deny_gid'])) { + $visibility = 'custom'; + } else { + $visibility = 'public'; + // Default permission display for custom panel + $default_permissions['allow_gid'] = [Group::FOLLOWERS]; + } + $jotnets_fields = []; - if ($show_jotnets) { + if ($for_federation) { $mail_enabled = false; $pubmail_enabled = false; if (function_exists('imap_open') && !Config::get('system', 'imap_disabled')) { - $mailacct = DBA::selectFirst('mailacct', ['pubmail'], ['`uid` = ? AND `server` != ""', local_user()]); + $mailacct = DBA::selectFirst('mailacct', ['pubmail'], ['`uid` = ? AND `server` != ""', $user['úid']]); if (DBA::isResult($mailacct)) { $mail_enabled = true; $pubmail_enabled = !empty($mailacct['pubmail']); @@ -354,27 +375,35 @@ class ACL extends BaseObject } } + $acl_contacts = self::getContactListByUserId($user['uid']); + + $acl_groups = self::getGroupListByUserId($user['uid']); + + $acl_list = array_merge($acl_groups, $acl_contacts); + $tpl = Renderer::getMarkupTemplate('acl_selector.tpl'); $o = Renderer::replaceMacros($tpl, [ - '$showall' => L10n::t('Visible to everybody'), - '$show' => L10n::t('show'), - '$hide' => L10n::t('don\'t show'), - '$allowcid' => json_encode(($default_permissions['allow_cid'] ?? '') ?: []), // We need arrays for - '$allowgid' => json_encode(($default_permissions['allow_gid'] ?? '') ?: []), // Javascript since we - '$denycid' => json_encode(($default_permissions['deny_cid'] ?? '') ?: []), // call .remove() and - '$denygid' => json_encode(($default_permissions['deny_gid'] ?? '') ?: []), // .push() on these values - '$networks' => $show_jotnets, - '$emailcc' => L10n::t('CC: email addresses'), - '$emtitle' => L10n::t('Example: bob@example.com, mary@example.com'), - '$jotnets_enabled' => empty($default_permissions['hidewall']), + '$public_title' => L10n::t('Public'), + '$public_desc' => L10n::t('This content will be shown to all your followers and can be seen in the community pages and by anyone with its link.'), + '$custom_title' => L10n::t('Limited/Private'), + '$custom_desc' => L10n::t('This content will be shown only to the people in the first box, to the exception of the people mentioned in the second box. It won\'t appear anywhere public.'), + '$allow_label' => L10n::t('Show to:'), + '$deny_label' => L10n::t('Except to:'), + '$emailcc' => L10n::t('CC: email addresses'), + '$emtitle' => L10n::t('Example: bob@example.com, mary@example.com'), '$jotnets_summary' => L10n::t('Connectors'), - '$jotnets_fields' => $jotnets_fields, '$jotnets_disabled_label' => L10n::t('Connectors disabled, since "%s" is enabled.', L10n::t('Hide your profile details from unknown viewers?')), - '$aclModalTitle' => L10n::t('Permissions'), - '$aclModalDismiss' => L10n::t('Close'), - '$features' => [ - 'aclautomention' => !empty($user['uid']) && Feature::isEnabled($user['uid'], 'aclautomention') ? 'true' : 'false' - ], + '$visibility' => $visibility, + '$acl_contacts' => $acl_contacts, + '$acl_groups' => $acl_groups, + '$acl_list' => $acl_list, + '$contact_allow' => implode(',', $default_permissions['allow_cid']), + '$group_allow' => implode(',', $default_permissions['allow_gid']), + '$contact_deny' => implode(',', $default_permissions['deny_cid']), + '$group_deny' => implode(',', $default_permissions['deny_gid']), + '$for_federation' => $for_federation, + '$jotnets_fields' => $jotnets_fields, + '$user_hidewall' => $default_permissions['hidewall'], ]); return $o; diff --git a/src/Module/Bookmarklet.php b/src/Module/Bookmarklet.php index a50f23c256..08bac2c1d0 100644 --- a/src/Module/Bookmarklet.php +++ b/src/Module/Bookmarklet.php @@ -44,7 +44,7 @@ class Bookmarklet extends BaseModule 'nickname' => $app->user['nickname'], 'lockstate' => ((is_array($app->user) && ((strlen($app->user['allow_cid'])) || (strlen($app->user['allow_gid'])) || (strlen($app->user['deny_cid'])) || (strlen($app->user['deny_gid'])))) ? 'lock' : 'unlock'), 'default_perms' => ACL::getDefaultUserPermissions($app->user), - 'acl' => ACL::getFullSelectorHTML($app->user, true), + 'acl' => ACL::getFullSelectorHTML($app->page, $app->user, true), 'bang' => '', 'visitor' => 'block', 'profile_uid' => local_user(), diff --git a/src/Module/Contact.php b/src/Module/Contact.php index ded5ffbe23..5ef06b72a1 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -926,7 +926,7 @@ class Contact extends BaseModule 'default_location' => $a->user['default-location'], 'nickname' => $a->user['nickname'], 'lockstate' => (is_array($a->user) && (strlen($a->user['allow_cid']) || strlen($a->user['allow_gid']) || strlen($a->user['deny_cid']) || strlen($a->user['deny_gid'])) ? 'lock' : 'unlock'), - 'acl' => ACL::getFullSelectorHTML($a->user, true), + 'acl' => ACL::getFullSelectorHTML($a->page, $a->user, true), 'bang' => '', 'visitor' => 'block', 'profile_uid' => local_user(), diff --git a/src/Module/Profile.php b/src/Module/Profile.php index aab5918567..db1a6f86b3 100644 --- a/src/Module/Profile.php +++ b/src/Module/Profile.php @@ -208,7 +208,7 @@ class Profile extends BaseModule || strlen($a->user['deny_cid']) || strlen($a->user['deny_gid']) ) ? 'lock' : 'unlock', - 'acl' => $is_owner ? ACL::getFullSelectorHTML($a->user, true) : '', + 'acl' => $is_owner ? ACL::getFullSelectorHTML($a->page, $a->user, true) : '', 'bang' => '', 'visitor' => $is_owner || $commvisitor ? 'block' : 'none', 'profile_uid' => $a->profile['profile_uid'], diff --git a/view/js/friendica-tagsinput/LICENSE b/view/js/friendica-tagsinput/LICENSE new file mode 100644 index 0000000000..58bc985baf --- /dev/null +++ b/view/js/friendica-tagsinput/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2013 Tim Schlechter + +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/view/js/friendica-tagsinput/friendica-tagsinput-typeahead.css b/view/js/friendica-tagsinput/friendica-tagsinput-typeahead.css new file mode 100644 index 0000000000..8cec654c47 --- /dev/null +++ b/view/js/friendica-tagsinput/friendica-tagsinput-typeahead.css @@ -0,0 +1,54 @@ +/* + * friendica-tagsinput v0.8.0 + * + */ + +.twitter-typeahead .tt-query, +.twitter-typeahead .tt-hint { + margin-bottom: 0; +} + +.twitter-typeahead .tt-hint +{ + display: none; +} + +.tt-menu { + position: absolute; + top: 100%; + left: 0; + z-index: 1000; + display: none; + float: left; + min-width: 160px; + padding: 5px 0; + margin: 2px 0 0; + list-style: none; + font-size: 14px; + background-color: #ffffff; + border: 1px solid #cccccc; + border: 1px solid rgba(0, 0, 0, 0.15); + border-radius: 4px; + -webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175); + box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175); + background-clip: padding-box; + cursor: pointer; +} + +.tt-suggestion { + display: block; + padding: 3px 20px; + clear: both; + font-weight: normal; + line-height: 1.428571429; + color: #333333; + white-space: nowrap; +} + +.tt-suggestion:hover, +.tt-suggestion:focus { + color: #ffffff; + text-decoration: none; + outline: 0; + background-color: #428bca; +} diff --git a/view/js/friendica-tagsinput/friendica-tagsinput.css b/view/js/friendica-tagsinput/friendica-tagsinput.css new file mode 100644 index 0000000000..6ad1d0015a --- /dev/null +++ b/view/js/friendica-tagsinput/friendica-tagsinput.css @@ -0,0 +1,155 @@ +/* + * friendica-tagsinput v0.8.0 + * + * Non-Bootstrap edition + */ + +.label { + display: inline; + padding: .2em .6em .3em; + font-size: 75%; + font-weight: 700; + line-height: 1; + color: #fff; + text-align: center; + white-space: nowrap; + vertical-align: baseline; + border-radius: .25em; +} + +.label-default { + background-color: #777777; +} +.label-default[href]:hover, +.label-default[href]:focus { + background-color: #5e5e5e; +} +.label-primary { + background-color: #337ab7; +} +.label-primary[href]:hover, +.label-primary[href]:focus { + background-color: #286090; +} +.label-success { + background-color: #5cb85c; +} +.label-success[href]:hover, +.label-success[href]:focus { + background-color: #449d44; +} +.label-info { + background-color: #5bc0de; +} +.label-info[href]:hover, +.label-info[href]:focus { + background-color: #31b0d5; +} +.label-warning { + background-color: #f0ad4e; +} +.label-warning[href]:hover, +.label-warning[href]:focus { + background-color: #ec971f; +} +.label-danger { + background-color: #d9534f; +} +.label-danger[href]:hover, +.label-danger[href]:focus { + background-color: #c9302c; +} + +.form-control[disabled], +.form-control[readonly], +fieldset[disabled] .form-control { + background-color: #eeeeee; + opacity: 1; +} +.form-control[disabled], +fieldset[disabled] .form-control { + cursor: not-allowed; +} + + + + +.friendica-tagsinput { + background-color: #fff; + border: 1px solid #ccc; + box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); + display: inline-block; + padding: 4px 6px; + color: #555; + vertical-align: middle; + border-radius: 4px; + max-width: 100%; + line-height: 22px; + cursor: text; + height: auto; +} + +.friendica-tagsinput.input-lg { + line-height: 27px; +} + +.friendica-tagsinput input { + border: none; + box-shadow: none; + outline: none; + background-color: transparent; + padding: 0 6px; + margin: 0; + width: auto; + max-width: inherit; +} + +.friendica-tagsinput.form-control input::-moz-placeholder { + color: #777; + opacity: 1; +} + +.friendica-tagsinput.form-control input:-ms-input-placeholder { + color: #777; +} + +.friendica-tagsinput.form-control input::-webkit-input-placeholder { + color: #777; +} + +.friendica-tagsinput input:focus { + border: none; + box-shadow: none; +} + +.friendica-tagsinput .tag { + margin: 0 2px 2px 0; + color: white; + font-weight: normal; +} + +.friendica-tagsinput .tag img { + width: auto; + height: 1.5em; + vertical-align: text-top; + margin-right: 8px; +} + +.friendica-tagsinput .tag [data-role="remove"] { + margin-left: 8px; + cursor: pointer; +} + +.friendica-tagsinput .tag [data-role="remove"]:after { + content: "x"; + padding: 0px 2px; + font-weight: bold; +} + +.friendica-tagsinput .tag [data-role="remove"]:hover { + box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05); +} + +.friendica-tagsinput .tag [data-role="remove"]:hover:active { + box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125); +} diff --git a/view/js/friendica-tagsinput/friendica-tagsinput.js b/view/js/friendica-tagsinput/friendica-tagsinput.js new file mode 100644 index 0000000000..af722d789e --- /dev/null +++ b/view/js/friendica-tagsinput/friendica-tagsinput.js @@ -0,0 +1,695 @@ +/* + * friendica-tagsinput v0.8.0 + * Based on bootstrap-tagsinput v0.8.0 + * + * Adds: + * - optional thumbnail + * - copying source input element class to the pseudo-input element + * + */ + +(function ($) { + "use strict"; + + var defaultOptions = { + tagClass: function(item) { + return 'label label-info'; + }, + focusClass: 'focus', + itemValue: function(item) { + return item ? item.toString() : item; + }, + itemText: function(item) { + return this.itemValue(item); + }, + itemTitle: function(item) { + return null; + }, + itemThumb: function(item) { + return null; + }, + freeInput: true, + addOnBlur: true, + maxTags: undefined, + maxChars: undefined, + confirmKeys: [13, 44], + delimiter: ',', + delimiterRegex: null, + cancelConfirmKeysOnEmpty: false, + onTagExists: function(item, $tag) { + $tag.hide().fadeIn(); + }, + trimValue: false, + allowDuplicates: false, + triggerChange: true + }; + + /** + * Constructor function + */ + function TagsInput(element, options) { + this.isInit = true; + this.itemsArray = []; + + this.$element = $(element); + this.$element.hide(); + + this.isSelect = (element.tagName === 'SELECT'); + this.multiple = (this.isSelect && element.hasAttribute('multiple')); + this.objectItems = options && options.itemValue; + this.placeholderText = element.hasAttribute('placeholder') ? this.$element.attr('placeholder') : ''; + this.inputSize = Math.max(1, this.placeholderText.length); + + this.$container = $('
'); + this.$container.addClass(this.$element.attr('class')); + this.$input = $('').appendTo(this.$container); + + this.$element.before(this.$container); + + this.build(options); + this.isInit = false; + } + + TagsInput.prototype = { + constructor: TagsInput, + + /** + * Adds the given item as a new tag. Pass true to dontPushVal to prevent + * updating the elements val() + */ + add: function(item, dontPushVal, options) { + let self = this; + + if (self.options.maxTags && self.itemsArray.length >= self.options.maxTags) + return; + + // Ignore falsey values, except false + if (item !== false && !item) + return; + + // Trim value + if (typeof item === "string" && self.options.trimValue) { + item = $.trim(item); + } + + // Throw an error when trying to add an object while the itemValue option was not set + if (typeof item === "object" && !self.objectItems) + throw("Can't add objects when itemValue option is not set"); + + // Ignore strings only containg whitespace + if (item.toString().match(/^\s*$/)) + return; + + // If SELECT but not multiple, remove current tag + if (self.isSelect && !self.multiple && self.itemsArray.length > 0) + self.remove(self.itemsArray[0]); + + if (typeof item === "string" && this.$element[0].tagName === 'INPUT') { + var delimiter = (self.options.delimiterRegex) ? self.options.delimiterRegex : self.options.delimiter; + var items = item.split(delimiter); + if (items.length > 1) { + for (var i = 0; i < items.length; i++) { + this.add(items[i], true); + } + + if (!dontPushVal) + self.pushVal(self.options.triggerChange); + return; + } + } + + var itemValue = self.options.itemValue(item), + itemText = self.options.itemText(item), + tagClass = self.options.tagClass(item), + itemTitle = self.options.itemTitle(item), + itemThumb = self.options.itemThumb(item); + + // Ignore items allready added + var existing = $.grep(self.itemsArray, function(item) { return self.options.itemValue(item) === itemValue; } )[0]; + if (existing && !self.options.allowDuplicates) { + // Invoke onTagExists + if (self.options.onTagExists) { + var $existingTag = $(".tag", self.$container).filter(function() { return $(this).data("item") === existing; }); + self.options.onTagExists(item, $existingTag); + } + return; + } + + // if length greater than limit + if (self.items().toString().length + item.length + 1 > self.options.maxInputLength) + return; + + // raise beforeItemAdd arg + var beforeItemAddEvent = $.Event('beforeItemAdd', { item: item, cancel: false, options: options}); + self.$element.trigger(beforeItemAddEvent); + if (beforeItemAddEvent.cancel) + return; + + // register item in internal array and map + self.itemsArray.push(item); + + // add a tag element + var $tag = $('' + + (itemThumb !== null ? '' : '') + + htmlEncode(itemText) + '' + + ''); + $tag.data('item', item); + self.findInputWrapper().before($tag); + $tag.after(' '); + + // Check to see if the tag exists in its raw or uri-encoded form + var optionExists = ( + $('option[value="' + encodeURIComponent(itemValue) + '"]', self.$element).length || + $('option[value="' + htmlEncode(itemValue) + '"]', self.$element).length + ); + + // add