├── .gitignore ├── languages ├── editorial-access-manager-it_IT.mo ├── editorial-access-manager-it_IT.po └── editorial-access-manager.pot ├── bower_components └── chosen_v1.1.0 │ ├── chosen-sprite.png │ ├── chosen-sprite@2x.png │ ├── docsupport │ ├── chosen.png │ ├── oss-credit.png │ ├── prism.css │ ├── prism.js │ └── style.css │ ├── .bower.json │ ├── chosen.min.css │ ├── options.html │ ├── chosen.css │ ├── chosen.jquery.min.js │ ├── chosen.proto.min.js │ └── chosen.jquery.js ├── composer.json ├── scss └── post-admin.scss ├── .travis.yml ├── phpunit.xml ├── tests ├── bootstrap.php └── test-core.php ├── package.json ├── Dockunit.json ├── bower.json ├── editorial-access-manager.php ├── js └── post-admin.js ├── Gruntfile.js ├── bin └── install-wp-tests.sh ├── readme.txt ├── README.md └── classes └── class-editorial-access-manager.php /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /node_modules/ 3 | /.sass-cache/ 4 | /.idea/ 5 | *.LCK 6 | _notes/ 7 | dwsync.xml 8 | -------------------------------------------------------------------------------- /languages/editorial-access-manager-it_IT.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/washingtonstateuniversity/editorial-access-manager/master/languages/editorial-access-manager-it_IT.mo -------------------------------------------------------------------------------- /bower_components/chosen_v1.1.0/chosen-sprite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/washingtonstateuniversity/editorial-access-manager/master/bower_components/chosen_v1.1.0/chosen-sprite.png -------------------------------------------------------------------------------- /bower_components/chosen_v1.1.0/chosen-sprite@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/washingtonstateuniversity/editorial-access-manager/master/bower_components/chosen_v1.1.0/chosen-sprite@2x.png -------------------------------------------------------------------------------- /bower_components/chosen_v1.1.0/docsupport/chosen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/washingtonstateuniversity/editorial-access-manager/master/bower_components/chosen_v1.1.0/docsupport/chosen.png -------------------------------------------------------------------------------- /bower_components/chosen_v1.1.0/docsupport/oss-credit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/washingtonstateuniversity/editorial-access-manager/master/bower_components/chosen_v1.1.0/docsupport/oss-credit.png -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "editorial-access-manager-wp", 3 | "type": "wordpress-plugin", 4 | "description": "Granular editorial access control for all post types in WordPress", 5 | "require": { 6 | "composer/installers": "~1.0" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /scss/post-admin.scss: -------------------------------------------------------------------------------- 1 | #eam_access_manager { 2 | label { 3 | display: block; 4 | margin-top: 1em; 5 | } 6 | } 7 | 8 | .column-editorial-access-manager { 9 | width: 20%; 10 | } 11 | 12 | .widefat th, .widefat td { 13 | overflow: visible; /* needed for bulk edit */ 14 | } 15 | 16 | .inline-edit-row fieldset.inline-edit-eam label span.title { 17 | width: 18em; 18 | } -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.3 5 | - 5.4 6 | 7 | env: 8 | - WP_VERSION=latest WP_MULTISITE=0 9 | - WP_VERSION=latest WP_MULTISITE=1 10 | - WP_VERSION=3.6 WP_MULTISITE=0 11 | - WP_VERSION=3.6 WP_MULTISITE=1 12 | 13 | before_script: 14 | - bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION 15 | 16 | script: phpunit 17 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | ./tests/ 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /tests/bootstrap.php: -------------------------------------------------------------------------------- 1 | " 7 | ], 8 | "description": "Allow for granular editorial access control for all post types in WordPress.", 9 | "license": "MIT", 10 | "private": false, 11 | "ignore": [ 12 | "**/.*", 13 | "node_modules", 14 | "bower_components", 15 | "tests" 16 | ], 17 | "dependencies": { 18 | "chosen_v1.1.0": "https://github.com/harvesthq/chosen/releases/download/v1.1.0/chosen_v1.1.0.zip" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /bower_components/chosen_v1.1.0/.bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chosen_v1.1.0", 3 | "_cacheHeaders": { 4 | "ETag": "\"face03d32045f0199c28994d51d2be79\"", 5 | "Last-Modified": "Fri, 07 Feb 2014 04:02:15 GMT", 6 | "Content-Length": "376005", 7 | "Content-Type": "application/octet-stream", 8 | "Content-Disposition": "attachment; filename=chosen_v1.1.0.zip" 9 | }, 10 | "_release": "e-tag:face03d32", 11 | "_source": "https://github.com/harvesthq/chosen/releases/download/v1.1.0/chosen_v1.1.0.zip", 12 | "_target": "*", 13 | "_originalSource": "https://github.com/harvesthq/chosen/releases/download/v1.1.0/chosen_v1.1.0.zip", 14 | "_direct": true 15 | } -------------------------------------------------------------------------------- /editorial-access-manager.php: -------------------------------------------------------------------------------- 1 | code[class*="language-"], 36 | pre[class*="language-"] { 37 | background: #272822; 38 | } 39 | 40 | /* Inline code */ 41 | :not(pre) > code[class*="language-"] { 42 | padding: .1em; 43 | border-radius: .3em; 44 | } 45 | 46 | .token.comment, 47 | .token.prolog, 48 | .token.doctype, 49 | .token.cdata { 50 | color: slategray; 51 | } 52 | 53 | .token.punctuation { 54 | color: #f8f8f2; 55 | } 56 | 57 | .namespace { 58 | opacity: .7; 59 | } 60 | 61 | .token.property, 62 | .token.tag { 63 | color: #f92672; 64 | } 65 | 66 | .token.boolean, 67 | .token.number{ 68 | color: #ae81ff; 69 | } 70 | 71 | .token.selector, 72 | .token.attr-name, 73 | .token.string { 74 | color: #a6e22e; 75 | } 76 | 77 | 78 | .token.operator, 79 | .token.entity, 80 | .token.url, 81 | .language-css .token.string, 82 | .style .token.string { 83 | color: #f8f8f2; 84 | } 85 | 86 | .token.atrule, 87 | .token.attr-value 88 | { 89 | color: #e6db74; 90 | } 91 | 92 | 93 | .token.keyword{ 94 | color: #66d9ef; 95 | } 96 | 97 | .token.regex, 98 | .token.important { 99 | color: #fd971f; 100 | } 101 | 102 | .token.important { 103 | font-weight: bold; 104 | } 105 | 106 | .token.entity { 107 | cursor: help; 108 | } 109 | -------------------------------------------------------------------------------- /languages/editorial-access-manager-it_IT.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Project-Id-Version: Editorial Access Manager v0.1.1\n" 4 | "Report-Msgid-Bugs-To: \n" 5 | "POT-Creation-Date: \n" 6 | "PO-Revision-Date: 2014-10-03 23:12:10+0000\n" 7 | "Last-Translator: marco-chiesi \n" 8 | "Language-Team: \n" 9 | "MIME-Version: 1.0\n" 10 | "Content-Type: text/plain; charset=UTF-8\n" 11 | "Content-Transfer-Encoding: 8bit\n" 12 | "Plural-Forms: nplurals=2; plural=n != 1;\n" 13 | "X-Generator: CSL v1.x\n" 14 | "X-Poedit-Language: Italian\n" 15 | "X-Poedit-Country: ITALY\n" 16 | "X-Poedit-SourceCharset: utf-8\n" 17 | "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;\n" 18 | "X-Poedit-Basepath: ../\n" 19 | "X-Poedit-Bookmarks: \n" 20 | "X-Poedit-SearchPath-0: .\n" 21 | "X-Textdomain-Support: yes" 22 | 23 | #: classes/class-editorial-access-manager.php:141 24 | #@ editorial-access-manager 25 | msgid "Editorial Access Manager" 26 | msgstr "Gestione accesso editoriale" 27 | 28 | #: classes/class-editorial-access-manager.php:253 29 | #@ editorial-access-manager 30 | msgid "Enable custom access management by" 31 | msgstr "Criterio gestione accessi" 32 | 33 | #: classes/class-editorial-access-manager.php:255 34 | #@ editorial-access-manager 35 | msgid "Off" 36 | msgstr "Nessuno" 37 | 38 | #: classes/class-editorial-access-manager.php:256 39 | #: classes/class-editorial-access-manager.php:323 40 | #@ editorial-access-manager 41 | msgid "Roles" 42 | msgstr "Ruoli" 43 | 44 | #: classes/class-editorial-access-manager.php:257 45 | #: classes/class-editorial-access-manager.php:337 46 | #@ editorial-access-manager 47 | msgid "Users" 48 | msgstr "Utenti" 49 | 50 | #: classes/class-editorial-access-manager.php:262 51 | #@ editorial-access-manager 52 | msgid "Manage access for roles:" 53 | msgstr "Gestione accesso ruoli:" 54 | 55 | #: classes/class-editorial-access-manager.php:277 56 | #@ editorial-access-manager 57 | msgid "Manage access for users:" 58 | msgstr "Gestione accesso utenti:" 59 | 60 | #: classes/class-editorial-access-manager.php:302 61 | #@ editorial-access-manager 62 | msgid "Editorial access" 63 | msgstr "Accesso editoriale" 64 | 65 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function ( grunt ) { 2 | grunt.initConfig( { 3 | pkg : grunt.file.readJSON( 'package.json' ), 4 | uglify : { 5 | js : { 6 | files : [{ 7 | expand: true, 8 | cwd: 'js', 9 | src: '**/*.js', 10 | dest: 'build/js/', 11 | ext: '.min.js' 12 | }] 13 | } 14 | }, 15 | jshint : { 16 | options : { 17 | smarttabs : true 18 | }, 19 | all: ['js/*'] 20 | }, 21 | sass : { 22 | dist : { 23 | files : { 24 | 'build/css/post-admin.css' : 'scss/post-admin.scss' 25 | }, 26 | options : { 27 | sourcemap: 'none' 28 | } 29 | } 30 | }, 31 | cssmin : { 32 | backend : { 33 | src : 'build/css/post-admin.css', 34 | dest : 'build/css/post-admin.min.css' 35 | } 36 | }, 37 | watch : { 38 | files : [ 39 | 'js/*', 40 | 'scss/*' 41 | ], 42 | tasks : ['jshint', 'uglify', 'sass', 'cssmin:backend'] 43 | }, 44 | makepot: { 45 | target: { 46 | options: { 47 | domainPath: '/languages', 48 | potFilename: 'editorial-access-manager.pot', 49 | processPot: function( pot ) { 50 | pot.headers['report-msgid-bugs-to'] = 'https://github.com/tlovett1/editorial-access-manager/issues\n'; 51 | pot.headers['plural-forms'] = 'nplurals=2; plural=n != 1;'; 52 | pot.headers['x-poedit-basepath'] = '.\n'; 53 | pot.headers['x-poedit-language'] = 'English\n'; 54 | pot.headers['x-poedit-country'] = 'United States\n'; 55 | pot.headers['x-poedit-sourcecharset'] = 'utf-8\n'; 56 | pot.headers['x-poedit-keywordslist'] = '__;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;\n'; 57 | pot.headers['x-poedit-bookmarks'] = '\n'; 58 | pot.headers['x-poedit-searchpath-0'] = '.\n'; 59 | pot.headers['x-textdomain-support'] = 'yes\n'; 60 | return pot; 61 | }, 62 | type: 'wp-plugin', 63 | updateTimestamp: true 64 | } 65 | } 66 | } 67 | } ); 68 | grunt.loadNpmTasks( 'grunt-contrib-uglify' ); 69 | grunt.loadNpmTasks( 'grunt-contrib-jshint' ); 70 | grunt.loadNpmTasks( 'grunt-contrib-sass' ); 71 | grunt.loadNpmTasks( 'grunt-contrib-cssmin' ); 72 | grunt.loadNpmTasks( 'grunt-contrib-watch' ); 73 | grunt.loadNpmTasks( 'grunt-wp-i18n' ); 74 | grunt.registerTask( 'default', ['jshint', 'uglify:js', 'sass', 'cssmin:backend', 'makepot'] ); 75 | }; -------------------------------------------------------------------------------- /bin/install-wp-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ $# -lt 3 ]; then 4 | echo "usage: $0 [db-host] [wp-version]" 5 | exit 1 6 | fi 7 | 8 | DB_NAME=$1 9 | DB_USER=$2 10 | DB_PASS=$3 11 | DB_HOST=${4-localhost} 12 | WP_VERSION=${5-latest} 13 | 14 | WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib} 15 | WP_CORE_DIR=/tmp/wordpress/ 16 | 17 | set -ex 18 | 19 | install_wp() { 20 | mkdir -p $WP_CORE_DIR 21 | 22 | if [ $WP_VERSION == 'latest' ]; then 23 | local ARCHIVE_NAME='latest' 24 | else 25 | local ARCHIVE_NAME="wordpress-$WP_VERSION" 26 | fi 27 | 28 | wget -nv -O /tmp/wordpress.tar.gz http://wordpress.org/${ARCHIVE_NAME}.tar.gz --no-check-certificate 29 | tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR 30 | 31 | wget -nv -O $WP_CORE_DIR/wp-content/db.php https://raw.github.com/markoheijnen/wp-mysqli/master/db.php --no-check-certificate 32 | } 33 | 34 | install_test_suite() { 35 | # portable in-place argument for both GNU sed and Mac OSX sed 36 | if [[ $(uname -s) == 'Darwin' ]]; then 37 | local ioption='-i .bak' 38 | else 39 | local ioption='-i' 40 | fi 41 | 42 | # set up testing suite 43 | mkdir -p $WP_TESTS_DIR 44 | cd $WP_TESTS_DIR 45 | svn co --quiet http://develop.svn.wordpress.org/trunk/tests/phpunit/includes/ 46 | 47 | wget -nv -O wp-tests-config.php http://develop.svn.wordpress.org/trunk/wp-tests-config-sample.php --no-check-certificate 48 | sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" wp-tests-config.php 49 | sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" wp-tests-config.php 50 | sed $ioption "s/yourusernamehere/$DB_USER/" wp-tests-config.php 51 | sed $ioption "s/yourpasswordhere/$DB_PASS/" wp-tests-config.php 52 | sed $ioption "s|localhost|${DB_HOST}|" wp-tests-config.php 53 | } 54 | 55 | install_db() { 56 | # parse DB_HOST for port or socket references 57 | local PARTS=(${DB_HOST//\:/ }) 58 | local DB_HOSTNAME=${PARTS[0]}; 59 | local DB_SOCK_OR_PORT=${PARTS[1]}; 60 | local EXTRA="" 61 | 62 | if ! [ -z $DB_HOSTNAME ] ; then 63 | if [[ "$DB_SOCK_OR_PORT" =~ ^[0-9]+$ ]] ; then 64 | EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp" 65 | elif ! [ -z $DB_SOCK_OR_PORT ] ; then 66 | EXTRA=" --socket=$DB_SOCK_OR_PORT" 67 | elif ! [ -z $DB_HOSTNAME ] ; then 68 | EXTRA=" --host=$DB_HOSTNAME --protocol=tcp" 69 | fi 70 | fi 71 | 72 | # create database 73 | mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA 74 | } 75 | 76 | install_wp 77 | install_test_suite 78 | install_db 79 | -------------------------------------------------------------------------------- /languages/editorial-access-manager.pot: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2014 Taylor Lovett 2 | # This file is distributed under the same license as the Editorial Access Manager package. 3 | msgid "" 4 | msgstr "" 5 | "Project-Id-Version: Editorial Access Manager 0.3.1\n" 6 | "Report-Msgid-Bugs-To: " 7 | "https://github.com/tlovett1/editorial-access-manager/issues\n" 8 | "POT-Creation-Date: 2014-11-26 15:26:48+00:00\n" 9 | "MIME-Version: 1.0\n" 10 | "Content-Type: text/plain; charset=utf-8\n" 11 | "Content-Transfer-Encoding: 8bit\n" 12 | "PO-Revision-Date: 2014-MO-DA HO:MI+ZONE\n" 13 | "Last-Translator: FULL NAME \n" 14 | "Language-Team: LANGUAGE \n" 15 | "X-Generator: grunt-wp-i18n 0.4.9\n" 16 | "Plural-Forms: nplurals=2; plural=n != 1;\n" 17 | "X-Poedit-Basepath: .\n" 18 | "X-Poedit-Language: English\n" 19 | "X-Poedit-Country: United States\n" 20 | "X-Poedit-SourceCharset: utf-8\n" 21 | "X-Poedit-KeywordsList: " 22 | "__;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_" 23 | "x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;\n" 24 | "X-Poedit-Bookmarks: \n" 25 | "X-Poedit-SearchPath-0: .\n" 26 | "X-Textdomain-Support: yes\n" 27 | 28 | #. Plugin Name of the plugin/theme 29 | msgid "Editorial Access Manager" 30 | msgstr "" 31 | 32 | #: classes/class-editorial-access-manager.php:346 33 | msgid "Enable custom access management by" 34 | msgstr "" 35 | 36 | #: classes/class-editorial-access-manager.php:348 37 | msgid "— No Change —" 38 | msgstr "" 39 | 40 | #: classes/class-editorial-access-manager.php:349 41 | #: classes/class-editorial-access-manager.php:443 42 | msgid "Off" 43 | msgstr "" 44 | 45 | #: classes/class-editorial-access-manager.php:350 46 | #: classes/class-editorial-access-manager.php:418 47 | msgid "Roles" 48 | msgstr "" 49 | 50 | #: classes/class-editorial-access-manager.php:351 51 | #: classes/class-editorial-access-manager.php:431 52 | msgid "Users" 53 | msgstr "" 54 | 55 | #: classes/class-editorial-access-manager.php:356 56 | msgid "Manage access for roles:" 57 | msgstr "" 58 | 59 | #: classes/class-editorial-access-manager.php:371 60 | msgid "Manage access for users:" 61 | msgstr "" 62 | 63 | #: classes/class-editorial-access-manager.php:398 64 | msgid "Editorial access" 65 | msgstr "" 66 | 67 | #. Author URI of the plugin/theme 68 | msgid "http://www.taylorlovett.com" 69 | msgstr "" 70 | 71 | #. Description of the plugin/theme 72 | msgid "Allow for granular editorial access control for all post types" 73 | msgstr "" 74 | 75 | #. Author of the plugin/theme 76 | msgid "Taylor Lovett" 77 | msgstr "" -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === Editorial Access Manager === 2 | Contributors: tlovett1 3 | Donate link: http://www.taylorlovett.com 4 | Tags: editorial access management, user roles, user capabilities, role management, user permissions, administrator permissions 5 | Requires at least: 3.6 6 | Tested up to: 4.1 7 | Stable tag: 0.3.1 8 | License: GPLv2 or later 9 | License URI: http://www.gnu.org/licenses/gpl-2.0.html 10 | 11 | Allow for granular editorial access control for all post types in WordPress 12 | 13 | == Description == 14 | 15 | A simple plugin to let you control who has access to what posts. By default in WordPress, we can create users 16 | and assign them to roles. Roles are automatically assigned certain capabilities. See the codex article for a list of 17 | [Roles and Capabilities](http://codex.wordpress.org/Roles_and_Capabilities). Sometimes default roles are not enough, 18 | and we have one-off situations. Editorial Access Manager lets you set which users or roles have access to specific 19 | posts. Perhaps you have a user who is a Contributor, but you want them to have access to edit one specific page? This 20 | plugin can help you. 21 | 22 | = Configuration Overview = 23 | 24 | There are no overarching settings for this plugin. Simply go to the edit post screen in the WordPress admin and 25 | configure access settings in the "Editorial Access Manager" meta box in the sidebar. 26 | 27 | = Managing Access by Roles = 28 | 29 | In the "Editorial Access Manager" meta box, enable custom access management by "Roles". Once enabled, the post can only be 30 | edited by users that fall into those roles. However, no matter what, the Administrator role can always edit any post. 31 | This if for safety reasons. You can also only use roles that have the "edit_posts" capability; therefore "Subscriber" by 32 | default cannot be used. 33 | 34 | = Managing Access by Users = 35 | 36 | In the "Editorial Access Manager" meta box, enable custom access management by "Users". Once enabled, the post can only be 37 | edited by designated users. However, no matter what, any administrator can edit any post. This if for safety reasons. 38 | You can also only use users that have the "edit_others_posts" capability; therefore "Subscriber" users by default 39 | cannot be used. 40 | 41 | Fork the plugin on [Github](http://github.com/tlovett1/editorial-access-manager) 42 | 43 | == Installation == 44 | 45 | 1. Upload and activate the plugin. 46 | 1. Browse to any post in the WordPress admin and navigate to the "Editorial Access Management" meta box in 47 | the sidebar. 48 | 49 | == Changelog == 50 | 51 | = 0.3.1 = 52 | * Fix bug where logged out user could edit role restricted post [@tripgrass](https://github.com/tripgrass) 53 | 54 | = 0.3.0 = 55 | * Bulk edit access. Props [@marcochiesi](https://github.com/marcochiesi) 56 | * Filterable post types. Props [@marcochiesi](https://github.com/marcochiesi) 57 | * Custom capability to use EAM meta box. Props [@marcochiesi](https://github.com/marcochiesi) 58 | 59 | = 0.2.0 = 60 | * Add Italian language support. Props [@marcochiesi](https://github.com/marcochiesi) 61 | * Add post table column to show editorial access. Props [@marcochiesi](https://github.com/marcochiesi) 62 | * Remove source file for minified CSS. Props [@marcochiesi](https://github.com/marcochiesi) 63 | * Tweak capability handling. Props [@marcochiesi](https://github.com/marcochiesi) 64 | * Add proper bower.json 65 | * Cleanup messy JavaScript 66 | * Remove unit testing of unnecessary WP versions 67 | 68 | = 0.1.1 = 69 | * Properly revoke access, if necessary, for users that have edit_page but not edit_post. 70 | 71 | = 0.1.0 = 72 | * Plugin release 73 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Editorial Access Manager [![Build Status](https://travis-ci.org/tlovett1/editorial-access-manager.svg?branch=master)](https://travis-ci.org/tlovett1/editorial-access-manager) 2 | ============== 3 | 4 | Allow for granular editorial access control for all post types in WordPress 5 | 6 | ## Purpose 7 | 8 | A simple plugin to let you control who has access to what posts. By default in WordPress, we can create users 9 | and assign them to roles. Roles are automatically assigned certain capabilities. See the codex article for a list of 10 | [Roles and Capabilities](http://codex.wordpress.org/Roles_and_Capabilities). Sometimes default roles are not enough, 11 | and we have one-off situations. Editorial Access Manager lets you set which users or roles have access to specific 12 | posts. Perhaps you have a user who is a Contributor, but you want them to have access to edit one specific page? This 13 | plugin can help you. 14 | 15 | ## Installation 16 | 17 | Install the plugin in WordPress, you can download a 18 | [zip via Github](https://github.com/tlovett1/editorial-access-manager/archive/master.zip) and upload it using the WP 19 | plugin uploader. 20 | 21 | ## Configuration 22 | 23 | There are no overarching settings for this plugin. Simply go to the edit post screen in the WordPress admin and 24 | configure access settings in the "Editorial Access Manager" meta box in the sidebar. 25 | 26 | #### Managing Access by Roles 27 | In the "Editorial Access Manager" meta box, enable custom access management by "Roles". Once enabled, the post can only be 28 | edited by users that fall into those roles. However, no matter what, the Administrator role can always edit any post. 29 | This if for safety reasons. You can also only use roles that have the "edit_posts" capability; therefore "Subscriber" by 30 | default cannot be used. 31 | 32 | #### Managing Access by Users 33 | In the "Editorial Access Manager" meta box, enable custom access management by "Users". Once enabled, the post can only be 34 | edited by designated users. However, no matter what, any administrator can edit any post. This if for safety reasons. 35 | You can also only use users that have the "edit_others_posts" capability; therefore "Subscriber" users by default 36 | cannot be used. 37 | 38 | ## Development 39 | 40 | #### Setup 41 | Follow the configuration instructions above to setup the plugin. I recommend developing the plugin locally in an 42 | environment such as [Varying Vagrant Vagrants](https://github.com/Varying-Vagrant-Vagrants/VVV). 43 | 44 | If you want to touch JavaScript or CSS, you will need to fire up [Grunt](http://gruntjs.com). Assuming you have 45 | [npm](https://www.npmjs.org/) installed, you can setup and run Grunt like so: 46 | 47 | First install Grunt: 48 | ``` 49 | npm install -g grunt-cli 50 | ``` 51 | 52 | Next install the node packages required by the plugin: 53 | ``` 54 | npm install 55 | ``` 56 | 57 | Finally, start Grunt watch. Whenever you edit JS or SCSS, the appropriate files will be compiled: 58 | ``` 59 | grunt watch 60 | ``` 61 | 62 | #### Testing 63 | Within the terminal change directories to the plugin folder. Initialize your unit testing environment by running the 64 | following command: 65 | 66 | For VVV users: 67 | ``` 68 | bash bin/install-wp-tests.sh wordpress_test root root localhost latest 69 | ``` 70 | 71 | For VIP Quickstart users: 72 | ``` 73 | bash bin/install-wp-tests.sh wordpress_test root '' localhost latest 74 | ``` 75 | 76 | where: 77 | 78 | * wordpress_test is the name of the test database (all data will be deleted!) 79 | * root is the MySQL user name 80 | * root is the MySQL user password (if you're running VVV). Blank if you're running VIP Quickstart. 81 | * localhost is the MySQL server host 82 | * latest is the WordPress version; could also be 3.7, 3.6.2 etc. 83 | 84 | Run the plugin tests: 85 | ``` 86 | phpunit 87 | ``` 88 | 89 | ##### Dockunit 90 | 91 | This plugin contains a valid [Dockunit](https://www.npmjs.com/package/dockunit) file for running unit tests across a variety of environments locally (PHP 5.2 and 5.5). You can use Dockunit (after installing it via npm) by running: 92 | 93 | ```bash 94 | dockunit 95 | ``` 96 | 97 | #### Issues 98 | If you identify any errors or have an idea for improving the plugin, please 99 | [open an issue](https://github.com/tlovett1/editorial-access-manager/issues?state=open). -------------------------------------------------------------------------------- /bower_components/chosen_v1.1.0/docsupport/prism.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Prism: Lightweight, robust, elegant syntax highlighting 3 | * MIT license http://www.opensource.org/licenses/mit-license.php/ 4 | * @author Lea Verou http://lea.verou.me 5 | */(function(){var e=/\blang(?:uage)?-(?!\*)(\w+)\b/i,t=self.Prism={util:{type:function(e){return Object.prototype.toString.call(e).match(/\[object (\w+)\]/)[1]},clone:function(e){var n=t.util.type(e);switch(n){case"Object":var r={};for(var i in e)e.hasOwnProperty(i)&&(r[i]=t.util.clone(e[i]));return r;case"Array":return e.slice()}return e}},languages:{extend:function(e,n){var r=t.util.clone(t.languages[e]);for(var i in n)r[i]=n[i];return r},insertBefore:function(e,n,r,i){i=i||t.languages;var s=i[e],o={};for(var u in s)if(s.hasOwnProperty(u)){if(u==n)for(var a in r)r.hasOwnProperty(a)&&(o[a]=r[a]);o[u]=s[u]}return i[e]=o},DFS:function(e,n){for(var r in e){n.call(e,r,e[r]);t.util.type(e)==="Object"&&t.languages.DFS(e[r],n)}}},highlightAll:function(e,n){var r=document.querySelectorAll('code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code');for(var i=0,s;s=r[i++];)t.highlightElement(s,e===!0,n)},highlightElement:function(r,i,s){var o,u,a=r;while(a&&!e.test(a.className))a=a.parentNode;if(a){o=(a.className.match(e)||[,""])[1];u=t.languages[o]}if(!u)return;r.className=r.className.replace(e,"").replace(/\s+/g," ")+" language-"+o;a=r.parentNode;/pre/i.test(a.nodeName)&&(a.className=a.className.replace(e,"").replace(/\s+/g," ")+" language-"+o);var f=r.textContent;if(!f)return;f=f.replace(/&/g,"&").replace(/e.length)break e;if(p instanceof i)continue;a.lastIndex=0;var d=a.exec(p);if(d){l&&(c=d[1].length);var v=d.index-1+c,d=d[0].slice(c),m=d.length,g=v+m,y=p.slice(0,v+1),b=p.slice(g+1),w=[h,1];y&&w.push(y);var E=new i(u,f?t.tokenize(d,f):d);w.push(E);b&&w.push(b);Array.prototype.splice.apply(s,w)}}}return s},hooks:{all:{},add:function(e,n){var r=t.hooks.all;r[e]=r[e]||[];r[e].push(n)},run:function(e,n){var r=t.hooks.all[e];if(!r||!r.length)return;for(var i=0,s;s=r[i++];)s(n)}}},n=t.Token=function(e,t){this.type=e;this.content=t};n.stringify=function(e,r,i){if(typeof e=="string")return e;if(Object.prototype.toString.call(e)=="[object Array]")return e.map(function(t){return n.stringify(t,r,e)}).join("");var s={type:e.type,content:n.stringify(e.content,r,i),tag:"span",classes:["token",e.type],attributes:{},language:r,parent:i};s.type=="comment"&&(s.attributes.spellcheck="true");t.hooks.run("wrap",s);var o="";for(var u in s.attributes)o+=u+'="'+(s.attributes[u]||"")+'"';return"<"+s.tag+' class="'+s.classes.join(" ")+'" '+o+">"+s.content+""};if(!self.document){self.addEventListener("message",function(e){var n=JSON.parse(e.data),r=n.language,i=n.code;self.postMessage(JSON.stringify(t.tokenize(i,t.languages[r])));self.close()},!1);return}var r=document.getElementsByTagName("script");r=r[r.length-1];if(r){t.filename=r.src;document.addEventListener&&!r.hasAttribute("data-manual")&&document.addEventListener("DOMContentLoaded",t.highlightAll)}})();; 6 | Prism.languages.markup={comment:/<!--[\w\W]*?-->/g,prolog:/<\?.+?\?>/,doctype:/<!DOCTYPE.+?>/,cdata:/<!\[CDATA\[[\w\W]*?]]>/i,tag:{pattern:/<\/?[\w:-]+\s*(?:\s+[\w:-]+(?:=(?:("|')(\\?[\w\W])*?\1|\w+))?\s*)*\/?>/gi,inside:{tag:{pattern:/^<\/?[\w:-]+/i,inside:{punctuation:/^<\/?/,namespace:/^[\w-]+?:/}},"attr-value":{pattern:/=(?:('|")[\w\W]*?(\1)|[^\s>]+)/gi,inside:{punctuation:/=|>|"/g}},punctuation:/\/?>/g,"attr-name":{pattern:/[\w:-]+/g,inside:{namespace:/^[\w-]+?:/}}}},entity:/&#?[\da-z]{1,8};/gi};Prism.hooks.add("wrap",function(e){e.type==="entity"&&(e.attributes.title=e.content.replace(/&/,"&"))});; 7 | Prism.languages.css={comment:/\/\*[\w\W]*?\*\//g,atrule:{pattern:/@[\w-]+?.*?(;|(?=\s*{))/gi,inside:{punctuation:/[;:]/g}},url:/url\((["']?).*?\1\)/gi,selector:/[^\{\}\s][^\{\};]*(?=\s*\{)/g,property:/(\b|\B)[\w-]+(?=\s*:)/ig,string:/("|')(\\?.)*?\1/g,important:/\B!important\b/gi,ignore:/&(lt|gt|amp);/gi,punctuation:/[\{\};:]/g};Prism.languages.markup&&Prism.languages.insertBefore("markup","tag",{style:{pattern:/(<|<)style[\w\W]*?(>|>)[\w\W]*?(<|<)\/style(>|>)/ig,inside:{tag:{pattern:/(<|<)style[\w\W]*?(>|>)|(<|<)\/style(>|>)/ig,inside:Prism.languages.markup.tag.inside},rest:Prism.languages.css}}});; 8 | Prism.languages.clike={comment:{pattern:/(^|[^\\])(\/\*[\w\W]*?\*\/|(^|[^:])\/\/.*?(\r?\n|$))/g,lookbehind:!0},string:/("|')(\\?.)*?\1/g,"class-name":{pattern:/((?:(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/ig,lookbehind:!0,inside:{punctuation:/(\.|\\)/}},keyword:/\b(if|else|while|do|for|return|in|instanceof|function|new|try|catch|finally|null|break|continue)\b/g,"boolean":/\b(true|false)\b/g,"function":{pattern:/[a-z0-9_]+\(/ig,inside:{punctuation:/\(/}}, number:/\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?)\b/g,operator:/[-+]{1,2}|!|<=?|>=?|={1,3}|(&){1,2}|\|?\||\?|\*|\/|\~|\^|\%/g,ignore:/&(lt|gt|amp);/gi,punctuation:/[{}[\];(),.:]/g};; 9 | Prism.languages.javascript=Prism.languages.extend("clike",{keyword:/\b(var|let|if|else|while|do|for|return|in|instanceof|function|new|with|typeof|try|catch|finally|null|break|continue)\b/g,number:/\b-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?|NaN|-?Infinity)\b/g});Prism.languages.insertBefore("javascript","keyword",{regex:{pattern:/(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/g,lookbehind:!0}});Prism.languages.markup&&Prism.languages.insertBefore("markup","tag",{script:{pattern:/(<|<)script[\w\W]*?(>|>)[\w\W]*?(<|<)\/script(>|>)/ig,inside:{tag:{pattern:/(<|<)script[\w\W]*?(>|>)|(<|<)\/script(>|>)/ig,inside:Prism.languages.markup.tag.inside},rest:Prism.languages.javascript}}});; 10 | -------------------------------------------------------------------------------- /bower_components/chosen_v1.1.0/docsupport/style.css: -------------------------------------------------------------------------------- 1 | /* Reset */ 2 | html, body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp, small, strong, sub, sup, var, b, i, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, figcaption, figure, footer, header, hgroup, menu, nav, section, summary, time, mark, audio, video { margin: 0; padding: 0; border: 0; font-size: 100%; font: inherit; vertical-align: baseline; } 3 | 4 | article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { display: block; } 5 | 6 | blockquote, q { quotes: none; } 7 | blockquote:before, blockquote:after, q:before, q:after { content: ""; content: none; } 8 | ins { background-color: #ff9; color: #000; text-decoration: none; } 9 | mark { background-color: #ff9; color: #000; font-style: italic; font-weight: bold; } 10 | del { text-decoration: line-through; } 11 | abbr[title], dfn[title] { border-bottom: 1px dotted; cursor: help; } 12 | table { border-collapse: collapse; border-spacing: 0; } 13 | hr { display: block; height: 1px; border: 0; border-top: 1px solid #ccc; margin: 1em 0; padding: 0; } 14 | input, select { vertical-align: middle; } 15 | 16 | body { font:13px/1.231 sans-serif; *font-size:small; } /* Hack retained to preserve specificity */ 17 | select, input, textarea, button { font:99% sans-serif; } 18 | pre, code, kbd, samp { font-family: monospace, sans-serif; } 19 | 20 | 21 | body { background: #EEE; color: #444; line-height: 1.4em; } 22 | 23 | header h1 { color: black; font-size: 2em; line-height: 1.1em; display: inline-block; height: 27px; margin: 20px 0 25px; } 24 | header h1 small { font-size: 0.6em; } 25 | 26 | div#content { background: white; border: 1px solid #ccc; border-width: 0 1px 1px; margin: 0 auto; padding: 40px 50px 40px; width: 738px; } 27 | 28 | footer { color: #999; padding-top: 40px; font-size: 0.8em; text-align: center; } 29 | 30 | body { font-family: sans-serif; font-size: 1em; } 31 | 32 | p { margin: 0 0 .7em; max-width: 700px; } 33 | 34 | h2 { border-bottom: 1px solid #ccc; font-size: 1.2em; margin: 3em 0 1em 0; font-weight: bold;} 35 | h3 { font-weight: bold; } 36 | 37 | h2.intro { border-bottom: none; font-size: 1em; font-weight: normal; margin-top:0; } 38 | 39 | ul li { list-style: disc; margin-left: 1em; margin-bottom: 1.25em; } 40 | ol li { margin-left: 1.25em; } 41 | ol ul, ul ul { margin: .25em 0 0; } 42 | ol ul li, ul ul li { list-style-type: circle; margin: 0 0 .25em 1em; } 43 | 44 | li > p { margin-top: .25em; } 45 | 46 | div.side-by-side { width: 100%; margin-bottom: 1em; } 47 | div.side-by-side > div { float: left; width: 49%; } 48 | div.side-by-side > div > em { margin-bottom: 10px; display: block; } 49 | 50 | .faqs em { display: block; } 51 | 52 | .clearfix:after { 53 | content: "\0020"; 54 | display: block; 55 | height: 0; 56 | clear: both; 57 | overflow: hidden; 58 | visibility: hidden; 59 | } 60 | 61 | a { color: #F36C00; outline: none; text-decoration: none; } 62 | a:hover { text-decoration: underline; } 63 | 64 | ul.credits li { margin-bottom: .25em; } 65 | 66 | strong { font-weight: bold; } 67 | i { font-style: italic; } 68 | 69 | .button { 70 | background: #fafafa; 71 | background: -webkit-linear-gradient(top, #ffffff, #eeeeee); 72 | background: -moz-linear-gradient(top, #ffffff, #eeeeee); 73 | background: -o-linear-gradient(top, #ffffff, #eeeeee); 74 | background: linear-gradient(to bottom, #ffffff, #eeeeee); 75 | border: 1px solid #bbbbbb; 76 | border-radius: 4px; 77 | box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.2); 78 | color: #555555; 79 | cursor: pointer; 80 | display: inline-block; 81 | font-family: "Helvetica Neue", Arial, Verdana, "Nimbus Sans L", sans-serif; 82 | font-size: 13px; 83 | font-weight: 500; 84 | height: 31px; 85 | line-height: 28px; 86 | outline: none; 87 | padding: 0 13px; 88 | text-shadow: 0 1px 0 white; 89 | text-decoration: none; 90 | vertical-align: middle; 91 | white-space: nowrap; 92 | -webkit-font-smoothing: antialiased; 93 | -webkit-box-sizing: border-box; 94 | -moz-box-sizing: border-box; 95 | box-sizing: border-box; 96 | } 97 | 98 | .button-blue { 99 | background: #1385e5; 100 | background: -webkit-linear-gradient(top, #53b2fc, #1385e5); 101 | background: -moz-linear-gradient(top, #53b2fc, #1385e5); 102 | background: -o-linear-gradient(top, #53b2fc, #1385e5); 103 | background: linear-gradient(to bottom, #53b2fc, #1385e5); 104 | border-color: #075fa9; 105 | color: white; 106 | font-weight: bold; 107 | text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.4); 108 | } 109 | 110 | 111 | /* Tweak navbar brand link to be super sleek 112 | -------------------------------------------------- */ 113 | .oss-bar { 114 | top: 0; 115 | right: 20px; 116 | position: fixed; 117 | z-index: 1030; 118 | } 119 | .oss-bar ul { 120 | float: right; 121 | margin: 0; 122 | list-style: none; 123 | } 124 | .oss-bar ul li { 125 | list-style: none; 126 | float: left; 127 | line-height: 0; 128 | margin: 0; 129 | } 130 | .oss-bar ul li a { 131 | -moz-box-sizing: border-box; 132 | -webkit-box-sizing: border-box; 133 | -ms-box-sizing: border-box; 134 | box-sizing: border-box; 135 | border: 0; 136 | margin-top: -10px; 137 | display: block; 138 | height: 58px; 139 | background: #F36C00 url(oss-credit.png) no-repeat 20px 22px; 140 | padding: 22px 20px 12px 20px; 141 | text-indent: 120%; /* stupid padding */ 142 | white-space: nowrap; 143 | overflow: hidden; 144 | -webkit-transition: all 0.10s ease-in-out; 145 | -moz-transition: all 0.10s ease-in-out; 146 | transition: all 0.15s ease-in-out; 147 | } 148 | .oss-bar ul li a:hover { 149 | margin-top: 0px; 150 | } 151 | .oss-bar a.harvest { 152 | width: 196px; 153 | background-color: #F36C00; 154 | background-position: -142px 22px; 155 | padding-right: 22px; /* optical illusion */ 156 | } 157 | .oss-bar a.fork { 158 | width: 162px; 159 | background-color: #333333; 160 | } 161 | 162 | .docs-table th, .docs-table td { 163 | border: 1px solid #000; 164 | padding: 4px 6px; 165 | white-space: nowrap; 166 | } 167 | 168 | .docs-table td:last-child { 169 | white-space: normal; 170 | } 171 | 172 | .docs-table th { 173 | font-weight: bold; 174 | text-align: left; 175 | } 176 | 177 | #content pre[class*=language-] { 178 | font-size: 14px; 179 | margin-bottom: 20px; 180 | } 181 | 182 | #content pre[class*=language-] code { 183 | font-size: 14px; 184 | padding: 0; 185 | } 186 | 187 | #content code[class*=language-] { 188 | font-size: 12px; 189 | padding: 2px 4px; 190 | } 191 | 192 | .anchor { 193 | color: inherit; 194 | position: relative; 195 | } 196 | 197 | .anchor:hover { 198 | background: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNiIgaGVpZ2h0PSI3Ij48ZyBmaWxsPSIjNDE0MDQyIj48cGF0aCBkPSJNOS44IDdoLS45bC0uOS0uMWMtLjctLjMtMS40LS43LTEuOC0xLjMtLjItLjEtLjMtLjMtLjMtLjVsLS4zLS40Yy0uMS0uNC0uMi0uOC0uMi0xLjIgMC0uNC4xLS44LjItMS4yaDEuN2MtLjMuNC0uNC44LS40IDEuMiAwIC40LjEuOC4zIDEuMS4xLjIuMi4zLjQuNC4xLjEuMi4yLjQuMy4zLjIuNy4zIDEgLjNoMy40YzEuMiAwIDIuMi0uOSAyLjItMi4xcy0xLTIuMS0yLjItMi4xaC0xLjRjLS4zLS42LS43LTEtMS4yLTEuNGgyLjZjMiAwIDMuNiAxLjYgMy42IDMuNXMtMS42IDMuNS0zLjYgMy41aC0yLjZ6TTguNCAyYy0uMS0uMS0uMi0uMy0uNC0uMy0uMy0uMi0uNy0uMy0xLS4zaC0zLjRjLTEuMiAwLTIuMi45LTIuMiAyLjEgMCAxLjIgMSAyLjEgMi4yIDIuMWgxLjRjLjMuNS43IDEgMS4yIDEuNGgtMi42Yy0yIDAtMy42LTEuNi0zLjYtMy41czEuNi0zLjUgMy42LTMuNWgzLjUwMDAwMDAwMDAwMDAwMDRsLjkuMWMuNy4yIDEuNC43IDEuOCAxLjMuMS4xLjIuMy4zLjUuMS4xLjIuMy4yLjUuMS40LjIuOC4yIDEuMiAwIC40LS4xLjgtLjIgMS4yaC0xLjZjLjMtLjUuNC0uOS40LTEuM3MtLjEtLjgtLjMtMS4xYy0uMS0uMi0uMi0uMy0uNC0uNHoiLz48L2c+PC9zdmc+) 0 50% no-repeat; 199 | background-size: 21px 9px; 200 | margin-left: -27px; 201 | padding-left: 27px; 202 | text-decoration: none; 203 | } 204 | -------------------------------------------------------------------------------- /bower_components/chosen_v1.1.0/chosen.min.css: -------------------------------------------------------------------------------- 1 | /* Chosen v1.1.0 | (c) 2011-2013 by Harvest | MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md */ 2 | 3 | .chosen-container{position:relative;display:inline-block;vertical-align:middle;font-size:13px;zoom:1;*display:inline;-webkit-user-select:none;-moz-user-select:none;user-select:none}.chosen-container .chosen-drop{position:absolute;top:100%;left:-9999px;z-index:1010;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;width:100%;border:1px solid #aaa;border-top:0;background:#fff;box-shadow:0 4px 5px rgba(0,0,0,.15)}.chosen-container.chosen-with-drop .chosen-drop{left:0}.chosen-container a{cursor:pointer}.chosen-container-single .chosen-single{position:relative;display:block;overflow:hidden;padding:0 0 0 8px;height:23px;border:1px solid #aaa;border-radius:5px;background-color:#fff;background:-webkit-gradient(linear,50% 0,50% 100%,color-stop(20%,#fff),color-stop(50%,#f6f6f6),color-stop(52%,#eee),color-stop(100%,#f4f4f4));background:-webkit-linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background:-moz-linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background:-o-linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background:linear-gradient(top,#fff 20%,#f6f6f6 50%,#eee 52%,#f4f4f4 100%);background-clip:padding-box;box-shadow:0 0 3px #fff inset,0 1px 1px rgba(0,0,0,.1);color:#444;text-decoration:none;white-space:nowrap;line-height:24px}.chosen-container-single .chosen-default{color:#999}.chosen-container-single .chosen-single span{display:block;overflow:hidden;margin-right:26px;text-overflow:ellipsis;white-space:nowrap}.chosen-container-single .chosen-single-with-deselect span{margin-right:38px}.chosen-container-single .chosen-single abbr{position:absolute;top:6px;right:26px;display:block;width:12px;height:12px;background:url(chosen-sprite.png) -42px 1px no-repeat;font-size:1px}.chosen-container-single .chosen-single abbr:hover{background-position:-42px -10px}.chosen-container-single.chosen-disabled .chosen-single abbr:hover{background-position:-42px -10px}.chosen-container-single .chosen-single div{position:absolute;top:0;right:0;display:block;width:18px;height:100%}.chosen-container-single .chosen-single div b{display:block;width:100%;height:100%;background:url(chosen-sprite.png) no-repeat 0 2px}.chosen-container-single .chosen-search{position:relative;z-index:1010;margin:0;padding:3px 4px;white-space:nowrap}.chosen-container-single .chosen-search input[type=text]{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;margin:1px 0;padding:4px 20px 4px 5px;width:100%;height:auto;outline:0;border:1px solid #aaa;background:#fff url(chosen-sprite.png) no-repeat 100% -20px;background:url(chosen-sprite.png) no-repeat 100% -20px;font-size:1em;font-family:sans-serif;line-height:normal;border-radius:0}.chosen-container-single .chosen-drop{margin-top:-1px;border-radius:0 0 4px 4px;background-clip:padding-box}.chosen-container-single.chosen-container-single-nosearch .chosen-search{position:absolute;left:-9999px}.chosen-container .chosen-results{position:relative;overflow-x:hidden;overflow-y:auto;margin:0 4px 4px 0;padding:0 0 0 4px;max-height:240px;-webkit-overflow-scrolling:touch}.chosen-container .chosen-results li{display:none;margin:0;padding:5px 6px;list-style:none;line-height:15px;-webkit-touch-callout:none}.chosen-container .chosen-results li.active-result{display:list-item;cursor:pointer}.chosen-container .chosen-results li.disabled-result{display:list-item;color:#ccc;cursor:default}.chosen-container .chosen-results li.highlighted{background-color:#3875d7;background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(20%,#3875d7),color-stop(90%,#2a62bc));background-image:-webkit-linear-gradient(#3875d7 20%,#2a62bc 90%);background-image:-moz-linear-gradient(#3875d7 20%,#2a62bc 90%);background-image:-o-linear-gradient(#3875d7 20%,#2a62bc 90%);background-image:linear-gradient(#3875d7 20%,#2a62bc 90%);color:#fff}.chosen-container .chosen-results li.no-results{display:list-item;background:#f4f4f4}.chosen-container .chosen-results li.group-result{display:list-item;font-weight:700;cursor:default}.chosen-container .chosen-results li.group-option{padding-left:15px}.chosen-container .chosen-results li em{font-style:normal;text-decoration:underline}.chosen-container-multi .chosen-choices{position:relative;overflow:hidden;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;margin:0;padding:0;width:100%;height:auto!important;height:1%;border:1px solid #aaa;background-color:#fff;background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(1%,#eee),color-stop(15%,#fff));background-image:-webkit-linear-gradient(#eee 1%,#fff 15%);background-image:-moz-linear-gradient(#eee 1%,#fff 15%);background-image:-o-linear-gradient(#eee 1%,#fff 15%);background-image:linear-gradient(#eee 1%,#fff 15%);cursor:text}.chosen-container-multi .chosen-choices li{float:left;list-style:none}.chosen-container-multi .chosen-choices li.search-field{margin:0;padding:0;white-space:nowrap}.chosen-container-multi .chosen-choices li.search-field input[type=text]{margin:1px 0;padding:5px;height:15px;outline:0;border:0!important;background:transparent!important;box-shadow:none;color:#666;font-size:100%;font-family:sans-serif;line-height:normal;border-radius:0}.chosen-container-multi .chosen-choices li.search-field .default{color:#999}.chosen-container-multi .chosen-choices li.search-choice{position:relative;margin:3px 0 3px 5px;padding:3px 20px 3px 5px;border:1px solid #aaa;border-radius:3px;background-color:#e4e4e4;background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(20%,#f4f4f4),color-stop(50%,#f0f0f0),color-stop(52%,#e8e8e8),color-stop(100%,#eee));background-image:-webkit-linear-gradient(#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-image:-moz-linear-gradient(#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-image:-o-linear-gradient(#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-image:linear-gradient(#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-clip:padding-box;box-shadow:0 0 2px #fff inset,0 1px 0 rgba(0,0,0,.05);color:#333;line-height:13px;cursor:default}.chosen-container-multi .chosen-choices li.search-choice .search-choice-close{position:absolute;top:4px;right:3px;display:block;width:12px;height:12px;background:url(chosen-sprite.png) -42px 1px no-repeat;font-size:1px}.chosen-container-multi .chosen-choices li.search-choice .search-choice-close:hover{background-position:-42px -10px}.chosen-container-multi .chosen-choices li.search-choice-disabled{padding-right:5px;border:1px solid #ccc;background-color:#e4e4e4;background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(20%,#f4f4f4),color-stop(50%,#f0f0f0),color-stop(52%,#e8e8e8),color-stop(100%,#eee));background-image:-webkit-linear-gradient(top,#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-image:-moz-linear-gradient(top,#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-image:-o-linear-gradient(top,#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);background-image:linear-gradient(top,#f4f4f4 20%,#f0f0f0 50%,#e8e8e8 52%,#eee 100%);color:#666}.chosen-container-multi .chosen-choices li.search-choice-focus{background:#d4d4d4}.chosen-container-multi .chosen-choices li.search-choice-focus .search-choice-close{background-position:-42px -10px}.chosen-container-multi .chosen-results{margin:0;padding:0}.chosen-container-multi .chosen-drop .result-selected{display:list-item;color:#ccc;cursor:default}.chosen-container-active .chosen-single{border:1px solid #5897fb;box-shadow:0 0 5px rgba(0,0,0,.3)}.chosen-container-active.chosen-with-drop .chosen-single{border:1px solid #aaa;-moz-border-radius-bottomright:0;border-bottom-right-radius:0;-moz-border-radius-bottomleft:0;border-bottom-left-radius:0;background-image:-webkit-gradient(linear,50% 0,50% 100%,color-stop(20%,#eee),color-stop(80%,#fff));background-image:-webkit-linear-gradient(#eee 20%,#fff 80%);background-image:-moz-linear-gradient(#eee 20%,#fff 80%);background-image:-o-linear-gradient(#eee 20%,#fff 80%);background-image:linear-gradient(#eee 20%,#fff 80%);box-shadow:0 1px 0 #fff inset}.chosen-container-active.chosen-with-drop .chosen-single div{border-left:0;background:transparent}.chosen-container-active.chosen-with-drop .chosen-single div b{background-position:-18px 2px}.chosen-container-active .chosen-choices{border:1px solid #5897fb;box-shadow:0 0 5px rgba(0,0,0,.3)}.chosen-container-active .chosen-choices li.search-field input[type=text]{color:#111!important}.chosen-disabled{opacity:.5!important;cursor:default}.chosen-disabled .chosen-single{cursor:default}.chosen-disabled .chosen-choices .search-choice .search-choice-close{cursor:default}.chosen-rtl{text-align:right}.chosen-rtl .chosen-single{overflow:visible;padding:0 8px 0 0}.chosen-rtl .chosen-single span{margin-right:0;margin-left:26px;direction:rtl}.chosen-rtl .chosen-single-with-deselect span{margin-left:38px}.chosen-rtl .chosen-single div{right:auto;left:3px}.chosen-rtl .chosen-single abbr{right:auto;left:26px}.chosen-rtl .chosen-choices li{float:right}.chosen-rtl .chosen-choices li.search-field input[type=text]{direction:rtl}.chosen-rtl .chosen-choices li.search-choice{margin:3px 5px 3px 0;padding:3px 5px 3px 19px}.chosen-rtl .chosen-choices li.search-choice .search-choice-close{right:auto;left:4px}.chosen-rtl.chosen-container-single-nosearch .chosen-search,.chosen-rtl .chosen-drop{left:9999px}.chosen-rtl.chosen-container-single .chosen-results{margin:0 0 4px 4px;padding:0 4px 0 0}.chosen-rtl .chosen-results li.group-option{padding-right:15px;padding-left:0}.chosen-rtl.chosen-container-active.chosen-with-drop .chosen-single div{border-right:0}.chosen-rtl .chosen-search input[type=text]{padding:4px 5px 4px 20px;background:#fff url(chosen-sprite.png) no-repeat -30px -20px;background:url(chosen-sprite.png) no-repeat -30px -20px;direction:rtl}.chosen-rtl.chosen-container-single .chosen-single div b{background-position:6px 2px}.chosen-rtl.chosen-container-single.chosen-with-drop .chosen-single div b{background-position:-12px 2px}@media only screen and (-webkit-min-device-pixel-ratio:2),only screen and (min-resolution:144dpi){.chosen-rtl .chosen-search input[type=text],.chosen-container-single .chosen-single abbr,.chosen-container-single .chosen-single div b,.chosen-container-single .chosen-search input[type=text],.chosen-container-multi .chosen-choices .search-choice .search-choice-close,.chosen-container .chosen-results-scroll-down span,.chosen-container .chosen-results-scroll-up span{background-image:url(chosen-sprite@2x.png)!important;background-size:52px 37px!important;background-repeat:no-repeat!important}} -------------------------------------------------------------------------------- /bower_components/chosen_v1.1.0/options.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Chosen: A jQuery Plugin by Harvest to Tame Unwieldy Select Boxes 6 | 7 | 8 | 9 | 13 | 14 | 15 |
16 |
17 |
18 |

Chosen (v1.1.0)

19 |
20 |

Chosen has a number of options and attributes that allow you to have full control of your select boxes.

21 | 22 |

Options

23 |

The following options are available to pass into Chosen on instantiation.

24 | 25 |

Example:

26 |
 27 |   $(".my_select_box").chosen({
 28 |     disable_search_threshold: 10,
 29 |     no_results_text: "Oops, nothing found!",
 30 |     width: "95%"
 31 |   });
 32 | 
33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 111 | 112 |
OptionDefaultDescription
allow_single_deselectfalseWhen set to true on a single select, Chosen adds a UI element which selects the first elment (if it is blank).
disable_searchfalseWhen set to true, Chosen will not display the search field (single selects only).
disable_search_threshold0Hide the search input on single selects if there are fewer than (n) options.
enable_split_word_searchtrueBy default, searching will match on any word within an option tag. Set this option to false if you want to only match on the entire text of an option tag.
inherit_select_classesfalseWhen set to true, Chosen will grab any classes on the original select field and add them to Chosen’s container div.
max_selected_optionsInfinityLimits how many options the user can select. When the limit is reached, the chosen:maxselected event is triggered.
no_results_text"No results match"The text to be displayed when no matching results are found. The current search is shown at the end of the text (e.g., 72 | No results match "Bad Search").
placeholder_text_multiple"Select Some Options"The text to be displayed as a placeholder when no options are selected for a multiple select.
placeholder_text_single"Select an Option"The text to be displayed as a placeholder when no options are selected for a single select.
search_containsfalseBy default, Chosen’s search matches starting at the beginning of a word. Setting this option to true allows matches starting from anywhere within a word. This is especially useful for options that include a lot of special characters or phrases in ()s and []s.
single_backstroke_deletetrueBy default, pressing delete/backspace on multiple selects will remove a selected choice. When false, pressing delete/backspace will highlight the last choice, and a second press deselects it.
widthOriginal select width.The width of the Chosen select box. By default, Chosen attempts to match the width of the select box you are replacing. If your select is hidden when Chosen is instantiated, you must specify a width or the select will show up with a width of 0.
display_disabled_optionstrueBy default, Chosen includes disabled options in search results with a special styling. Setting this option to false will hide disabled results and exclude them from searches.
display_selected_optionstrue 108 |

By default, Chosen includes selected options in search results with a special styling. Setting this option to false will hide selected results and exclude them from searches.

109 |

Note: this is for multiple selects only. In single selects, the selected result will always be displayed.

110 |
113 | 114 |

Attributes

115 |

Certain attributes placed on the select tag or its options can be used to configure Chosen.

116 | 117 |

Example:

118 | 119 |
120 |   <select class="my_select_box" data-placeholder="Select Your Options">
121 |     <option value="1">Option 1</option>
122 |     <option value="2" selected>Option 2</option>
123 |     <option value="3" disabled>Option 3</option>
124 |   </select>
125 | 
126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 |
AttributeDescription
data-placeholder 134 |

The text to be displayed as a placeholder when no options are selected for a select. Defaults to "Select an Option" for single selects or "Select Some Options" for multiple selects.

135 |

Note:This attribute overrides anything set in the placeholder_text_multiple or placeholder_text_single options.

136 |
multipleThe attribute multiple on your select box dictates whether Chosen will render a multiple or single select.
selected, disabledChosen automatically highlights selected options and disables disabled options.
147 | 148 |

Classes

149 |

Classes placed on the select tag can be used to configure Chosen.

150 | 151 |

Example:

152 | 153 |
154 |   <select class="my_select_box chosen-rtl">
155 |     <option value="1">Option 1</option>
156 |     <option value="2">Option 2</option>
157 |     <option value="3">Option 3</option>
158 |   </select>
159 | 
160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 172 | 173 |
ClassnameDescription
chosen-rtl 169 |

Chosen supports right-to-left text in select boxes. Add the class chosen-rtl to your select tag to support right-to-left text options.

170 |

Note: The chosen-rtl class will pass through to the Chosen select even when the inherit_select_classes option is set to false.

171 |
174 | 175 |

Triggered Events

176 |

Chosen triggers a number of standard and custom events on the original select field.

177 | 178 |

Example:

179 | 180 |
181 |   $('.my_select_box').on('change', function(evt, params) {
182 |     do_something(evt, params);
183 |   });
184 | 
185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 |
EventDescription
change 193 |

Chosen triggers the standard DOM event whenever a selection is made (it also sends a selected or deselected parameter that tells you which option was changed).

194 |

Note: in order to use change in the Prototype version, you have to include the Event.simulate class. The selected and deselected parameters are not available for Prototype.

195 |
chosen:readyTriggered after Chosen has been fully instantiated.
chosen:maxselectedTriggered if max_selected_options is set and that total is broken.
chosen:showing_dropdownTriggered when Chosen’s dropdown is opened.
chosen:hiding_dropdownTriggered when Chosen’s dropdown is closed.
chosen:no_resultsTriggered when a search returns no matching results.
218 | 219 |

220 | Note: all custom Chosen events (those that being with chosen:) also include the chosen object as a parameter. 221 |

222 | 223 |

Triggerable Events

224 |

You can trigger several events on the original select field to invoke a behavior in Chosen.

225 | 226 |

Example:

227 | 228 |
229 |   // tell Chosen that a select has changed
230 |     $('.my_select_box').trigger('chosen:updated');
231 | 
232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 |
EventDescription
chosen:updatedThis event should be triggered whenever Chosen’s underlying select element changes (such as a change in selected options).
chosen:activateThis is the equivalant of focusing a standard HTML select field. When activated, Chosen will capure keypress events as if you had clicked the field directly.
chosen:openThis event activates Chosen and also displays the search results.
chosen:closeThis event deactivates Chosen and hides the search results.
254 | 255 | 258 | 259 |
260 |
261 |
262 | 266 |
267 | 268 | 269 | 270 | -------------------------------------------------------------------------------- /tests/test-core.php: -------------------------------------------------------------------------------- 1 | factory->user->create( array( 'user_login' => $username, 'role' => $role, 'user_pass' => '12345' ) ); 30 | 31 | $user = @wp_signon( 32 | array( 33 | 'user_login' => $username, 34 | 'user_password' => '12345', 35 | ) 36 | ); 37 | 38 | wp_set_current_user( $user->ID ); 39 | 40 | return $user; 41 | } 42 | 43 | /** 44 | * Test edit a post whitelisted for contributors by a contributor 45 | * 46 | * @since 0.1.0 47 | */ 48 | public function testEditByWhitelistedContributorPost() { 49 | 50 | $post_id = $this->factory->post->create(); 51 | 52 | $this->_configureAccess( $post_id, 'roles', array( 'contributor' ) ); 53 | 54 | $this->_createAndSignInUser( 'contributor' ); 55 | 56 | $_POST['post_ID'] = $post_id; 57 | $_GET['post'] = $post_id; 58 | 59 | $this->assertTrue( current_user_can( 'edit_post', $post_id ) && current_user_can( 'publish_posts' ) && current_user_can( 'edit_others_posts' ) ); 60 | } 61 | 62 | /** 63 | * Test edit a post not whitelisted for contributors by a contributor 64 | * 65 | * @since 0.1.0 66 | */ 67 | public function testEditByNonWhitelistedContributorPost() { 68 | 69 | $post_id = $this->factory->post->create(); 70 | 71 | $this->_configureAccess( $post_id, 'roles', array( 'editor' ) ); 72 | 73 | $this->_createAndSignInUser( 'contributor' ); 74 | 75 | $_POST['post_ID'] = $post_id; 76 | $_GET['post'] = $post_id; 77 | 78 | $this->assertTrue( ! ( current_user_can( 'edit_post', $post_id ) && current_user_can( 'publish_posts' ) && current_user_can( 'edit_others_posts' ) ) ); 79 | } 80 | 81 | /** 82 | * Test edit a post whitelisted for editors by an editor 83 | * 84 | * @since 0.1.0 85 | */ 86 | public function testEditByWhitelistedEditorPost() { 87 | 88 | $post_id = $this->factory->post->create(); 89 | 90 | $this->_configureAccess( $post_id, 'roles', array( 'editor' ) ); 91 | 92 | $this->_createAndSignInUser( 'editor' ); 93 | 94 | $_POST['post_ID'] = $post_id; 95 | $_GET['post'] = $post_id; 96 | 97 | $this->assertTrue( current_user_can( 'edit_post', $post_id ) && current_user_can( 'publish_posts' ) && current_user_can( 'edit_others_posts' ) ); 98 | } 99 | 100 | /** 101 | * Test edit a post not whitelisted for editors by an editor 102 | * 103 | * @since 0.1.0 104 | */ 105 | public function testEditByNonWhitelistedEditorPost() { 106 | 107 | $post_id = $this->factory->post->create(); 108 | 109 | $this->_configureAccess( $post_id, 'roles', array( 'contributor' ) ); 110 | 111 | $this->_createAndSignInUser( 'editor' ); 112 | 113 | $_POST['post_ID'] = $post_id; 114 | $_GET['post'] = $post_id; 115 | 116 | $this->assertTrue( ! ( current_user_can( 'edit_post', $post_id ) && current_user_can( 'publish_posts' ) && current_user_can( 'edit_others_posts' ) ) ); 117 | } 118 | 119 | /** 120 | * Test edit a post whitelisted for editor by admin 121 | * 122 | * @since 0.1.0 123 | */ 124 | public function testEditByNonWhitelistedAdminPost() { 125 | 126 | $post_id = $this->factory->post->create(); 127 | 128 | $this->_configureAccess( $post_id, 'roles', array( 'editor' ) ); 129 | 130 | $this->_createAndSignInUser( 'administrator' ); 131 | 132 | $_POST['post_ID'] = $post_id; 133 | $_GET['post'] = $post_id; 134 | 135 | $this->assertTrue( current_user_can( 'edit_post', $post_id ) && current_user_can( 'publish_posts' ) && current_user_can( 'edit_others_posts' ) ); 136 | } 137 | 138 | /** 139 | * Test edit a post whitelisted for authors by an author 140 | * 141 | * @since 0.1.0 142 | */ 143 | public function testEditByWhitelistedAuthorPost() { 144 | 145 | $post_id = $this->factory->post->create(); 146 | 147 | $this->_configureAccess( $post_id, 'roles', array( 'author', 'contributor', 'editor' ) ); 148 | 149 | $this->_createAndSignInUser( 'author' ); 150 | 151 | $_POST['post_ID'] = $post_id; 152 | $_GET['post'] = $post_id; 153 | 154 | $this->assertTrue( current_user_can( 'edit_post', $post_id ) && current_user_can( 'publish_posts' ) && current_user_can( 'edit_others_posts' ) ); 155 | } 156 | 157 | /** 158 | * Test edit a post not whitelisted for authors by an author 159 | * 160 | * @since 0.1.0 161 | */ 162 | public function testEditByNonWhitelistedAuthorPost() { 163 | 164 | $post_id = $this->factory->post->create(); 165 | 166 | $this->_configureAccess( $post_id, 'roles', array( 'contributor', 'editor' ) ); 167 | 168 | $this->_createAndSignInUser( 'author' ); 169 | 170 | $_POST['post_ID'] = $post_id; 171 | $_GET['post'] = $post_id; 172 | 173 | $this->assertTrue( ! ( current_user_can( 'edit_post', $post_id ) && current_user_can( 'publish_posts' ) && current_user_can( 'edit_others_posts' ) ) ); 174 | } 175 | 176 | /** 177 | * Test an edit by a whitelisted author user where access is user restricted 178 | * 179 | * @since 0.1.0 180 | */ 181 | public function testEditByWhitelistedAuthorUser() { 182 | 183 | $post_id = $this->factory->post->create(); 184 | 185 | $user = $this->_createAndSignInUser( 'author' ); 186 | 187 | $this->_configureAccess( $post_id, 'users', array(), array( $user->ID ) ); 188 | 189 | $_POST['post_ID'] = $post_id; 190 | $_GET['post'] = $post_id; 191 | 192 | $this->assertTrue( current_user_can( 'edit_post', $post_id ) && current_user_can( 'publish_posts' ) && current_user_can( 'edit_others_posts' ) ); 193 | } 194 | 195 | /** 196 | * Test an edit by a non whitelisted author user where access is user restricted 197 | * 198 | * @since 0.1.0 199 | */ 200 | public function testEditByNonWhitelistedAuthorUser() { 201 | 202 | $post_id = $this->factory->post->create(); 203 | 204 | $user = $this->_createAndSignInUser( 'author' ); 205 | 206 | $this->_configureAccess( $post_id, 'users', array(), array( (int) $user->ID + 1 ) ); 207 | 208 | $_POST['post_ID'] = $post_id; 209 | $_GET['post'] = $post_id; 210 | 211 | $this->assertTrue( ! ( current_user_can( 'edit_post', $post_id ) && current_user_can( 'publish_posts' ) && current_user_can( 'edit_others_posts' ) ) ); 212 | } 213 | 214 | /** 215 | * Test an edit by a whitelisted editor user where access is user restricted 216 | * 217 | * @since 0.1.0 218 | */ 219 | public function testEditByWhitelistedEditorUser() { 220 | 221 | $post_id = $this->factory->post->create(); 222 | 223 | $user = $this->_createAndSignInUser( 'editor' ); 224 | 225 | $this->_configureAccess( $post_id, 'users', array(), array( $user->ID, (int) $user->ID + 1 ) ); 226 | 227 | $_POST['post_ID'] = $post_id; 228 | $_GET['post'] = $post_id; 229 | 230 | $this->assertTrue( current_user_can( 'edit_post', $post_id ) && current_user_can( 'publish_posts' ) && current_user_can( 'edit_others_posts' ) ); 231 | } 232 | 233 | /** 234 | * Test an edit by a non whitelisted editor user where access is user restricted 235 | * 236 | * @since 0.1.0 237 | */ 238 | public function testEditByNonWhitelistedEditorUser() { 239 | 240 | $post_id = $this->factory->post->create(); 241 | 242 | $user = $this->_createAndSignInUser( 'editor' ); 243 | 244 | $this->_configureAccess( $post_id, 'users', array(), array( (int) $user->ID + 1, (int) $user->ID + 2 ) ); 245 | 246 | $_POST['post_ID'] = $post_id; 247 | $_GET['post'] = $post_id; 248 | 249 | $this->assertTrue( ! ( current_user_can( 'edit_post', $post_id ) && current_user_can( 'publish_posts' ) && current_user_can( 'edit_others_posts' ) ) ); 250 | } 251 | 252 | /** 253 | * Test an edit by a whitelisted contributor user where access is user restricted 254 | * 255 | * @since 0.1.0 256 | */ 257 | public function testEditByWhitelistedContributorUser() { 258 | 259 | $post_id = $this->factory->post->create(); 260 | 261 | $user = $this->_createAndSignInUser( 'contributor' ); 262 | 263 | $this->_configureAccess( $post_id, 'users', array(), array( $user->ID, (int) $user->ID + 1, (int) $user->ID + 2 ) ); 264 | 265 | $_POST['post_ID'] = $post_id; 266 | $_GET['post'] = $post_id; 267 | 268 | $this->assertTrue( current_user_can( 'edit_post', $post_id ) && current_user_can( 'publish_posts' ) && current_user_can( 'edit_others_posts' ) ); 269 | } 270 | 271 | /** 272 | * Test an edit by a non whitelisted contributor user where access is user restricted 273 | * 274 | * @since 0.1.0 275 | */ 276 | public function testEditByNonWhitelistedContributorUser() { 277 | 278 | $post_id = $this->factory->post->create(); 279 | 280 | $user = $this->_createAndSignInUser( 'contributor' ); 281 | 282 | $this->_configureAccess( $post_id, 'users', array(), array( (int) $user->ID + 1, (int) $user->ID + 2 ) ); 283 | 284 | $_POST['post_ID'] = $post_id; 285 | $_GET['post'] = $post_id; 286 | 287 | $this->assertTrue( ! ( current_user_can( 'edit_post', $post_id ) && current_user_can( 'publish_posts' ) && current_user_can( 'edit_others_posts' ) ) ); 288 | } 289 | 290 | /** 291 | * Test an edit by a whitelisted editor where access is role restricted 292 | * 293 | * @since 0.1.0 294 | */ 295 | public function testPageEditByWhitelistedEditorRole() { 296 | 297 | $page_id = $this->factory->post->create( array( 'post_type' => 'page' ) ); 298 | 299 | $user = $this->_createAndSignInUser( 'editor' ); 300 | 301 | $this->_configureAccess( $page_id, 'roles', array( 'editor' ) ); 302 | 303 | $_POST['post_ID'] = $page_id; 304 | $_GET['post'] = $page_id; 305 | 306 | $this->assertTrue( current_user_can( 'edit_page', $page_id ) && current_user_can( 'publish_pages' ) && current_user_can( 'edit_others_pages' ) ); 307 | } 308 | 309 | /** 310 | * Test an edit by a non whitelisted editor where access is role restricted 311 | * 312 | * @since 0.1.0 313 | */ 314 | public function testPageEditByNonWhitelistedEditorRole() { 315 | 316 | $page_id = $this->factory->post->create( array( 'post_type' => 'page' ) ); 317 | 318 | $user = $this->_createAndSignInUser( 'editor' ); 319 | 320 | $this->_configureAccess( $page_id, 'roles', array() ); 321 | 322 | $_POST['post_ID'] = $page_id; 323 | $_GET['post'] = $page_id; 324 | 325 | $this->assertTrue( ! ( current_user_can( 'edit_page', $page_id ) && current_user_can( 'publish_posts' ) && current_user_can( 'edit_others_posts' ) ) ); 326 | } 327 | 328 | /** 329 | * Test an edit by a whitelisted editor where access is user restricted 330 | * 331 | * @since 0.1.0 332 | */ 333 | public function testPageEditByWhitelistedEditorUser() { 334 | 335 | $page_id = $this->factory->post->create( array( 'post_type' => 'page' ) ); 336 | 337 | $user = $this->_createAndSignInUser( 'editor' ); 338 | 339 | $this->_configureAccess( $page_id, 'users', array(), array( $user->ID, (int) $user->ID + 1 ) ); 340 | 341 | $_POST['post_ID'] = $page_id; 342 | $_GET['post'] = $page_id; 343 | 344 | $this->assertTrue( current_user_can( 'edit_page', $page_id ) && current_user_can( 'publish_pages' ) && current_user_can( 'edit_others_pages' ) ); 345 | } 346 | 347 | /** 348 | * Test an edit by a non whitelisted editor where access is user restricted 349 | * 350 | * @since 0.1.0 351 | */ 352 | public function testPageEditByNonWhitelistedEditorUser() { 353 | 354 | $page_id = $this->factory->post->create( array( 'post_type' => 'page' ) ); 355 | 356 | $user = $this->_createAndSignInUser( 'editor' ); 357 | 358 | $this->_configureAccess( $page_id, 'users' ); 359 | 360 | $_POST['post_ID'] = $page_id; 361 | $_GET['post'] = $page_id; 362 | 363 | $this->assertTrue( ! ( current_user_can( 'edit_page', $page_id ) && current_user_can( 'publish_posts' ) && current_user_can( 'edit_others_posts' ) ) ); 364 | } 365 | 366 | /** 367 | * Test an edit of a role restricted post by a logged out user 368 | * 369 | * @since 0.3.1 370 | */ 371 | public function testLoggedOutUserRoleAccess() { 372 | wp_set_current_user( 0 ); 373 | 374 | $page_id = $this->factory->post->create( array( 'post_type' => 'page' ) ); 375 | 376 | $this->_configureAccess( $page_id, 'roles', array( 'editor' ) ); 377 | 378 | $_POST['post_ID'] = $page_id; 379 | $_GET['post'] = $page_id; 380 | 381 | $this->assertTrue( ! current_user_can( 'edit_page', $page_id ) ); 382 | } 383 | 384 | /** 385 | * Test an edit of a user restricted post by a logged out user 386 | * 387 | * @since 0.3.1 388 | */ 389 | public function testLoggedOutUserUserAccess() { 390 | $page_id = $this->factory->post->create( array( 'post_type' => 'page' ) ); 391 | 392 | $user = $this->_createAndSignInUser( 'author' ); 393 | 394 | $this->_configureAccess( $page_id, 'users', array(), array( $user->ID ) ); 395 | 396 | wp_set_current_user( 0 ); 397 | 398 | $_POST['post_ID'] = $page_id; 399 | $_GET['post'] = $page_id; 400 | 401 | $this->assertTrue( ! current_user_can( 'edit_page', $page_id ) ); 402 | } 403 | } -------------------------------------------------------------------------------- /bower_components/chosen_v1.1.0/chosen.css: -------------------------------------------------------------------------------- 1 | /*! 2 | Chosen, a Select Box Enhancer for jQuery and Prototype 3 | by Patrick Filler for Harvest, http://getharvest.com 4 | 5 | Version 1.1.0 6 | Full source at https://github.com/harvesthq/chosen 7 | Copyright (c) 2011 Harvest http://getharvest.com 8 | 9 | MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md 10 | This file is generated by `grunt build`, do not edit it by hand. 11 | */ 12 | 13 | /* @group Base */ 14 | .chosen-container { 15 | position: relative; 16 | display: inline-block; 17 | vertical-align: middle; 18 | font-size: 13px; 19 | zoom: 1; 20 | *display: inline; 21 | -webkit-user-select: none; 22 | -moz-user-select: none; 23 | user-select: none; 24 | } 25 | .chosen-container .chosen-drop { 26 | position: absolute; 27 | top: 100%; 28 | left: -9999px; 29 | z-index: 1010; 30 | -webkit-box-sizing: border-box; 31 | -moz-box-sizing: border-box; 32 | box-sizing: border-box; 33 | width: 100%; 34 | border: 1px solid #aaa; 35 | border-top: 0; 36 | background: #fff; 37 | box-shadow: 0 4px 5px rgba(0, 0, 0, 0.15); 38 | } 39 | .chosen-container.chosen-with-drop .chosen-drop { 40 | left: 0; 41 | } 42 | .chosen-container a { 43 | cursor: pointer; 44 | } 45 | 46 | /* @end */ 47 | /* @group Single Chosen */ 48 | .chosen-container-single .chosen-single { 49 | position: relative; 50 | display: block; 51 | overflow: hidden; 52 | padding: 0 0 0 8px; 53 | height: 23px; 54 | border: 1px solid #aaa; 55 | border-radius: 5px; 56 | background-color: #fff; 57 | background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #ffffff), color-stop(50%, #f6f6f6), color-stop(52%, #eeeeee), color-stop(100%, #f4f4f4)); 58 | background: -webkit-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%); 59 | background: -moz-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%); 60 | background: -o-linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%); 61 | background: linear-gradient(top, #ffffff 20%, #f6f6f6 50%, #eeeeee 52%, #f4f4f4 100%); 62 | background-clip: padding-box; 63 | box-shadow: 0 0 3px white inset, 0 1px 1px rgba(0, 0, 0, 0.1); 64 | color: #444; 65 | text-decoration: none; 66 | white-space: nowrap; 67 | line-height: 24px; 68 | } 69 | .chosen-container-single .chosen-default { 70 | color: #999; 71 | } 72 | .chosen-container-single .chosen-single span { 73 | display: block; 74 | overflow: hidden; 75 | margin-right: 26px; 76 | text-overflow: ellipsis; 77 | white-space: nowrap; 78 | } 79 | .chosen-container-single .chosen-single-with-deselect span { 80 | margin-right: 38px; 81 | } 82 | .chosen-container-single .chosen-single abbr { 83 | position: absolute; 84 | top: 6px; 85 | right: 26px; 86 | display: block; 87 | width: 12px; 88 | height: 12px; 89 | background: url('chosen-sprite.png') -42px 1px no-repeat; 90 | font-size: 1px; 91 | } 92 | .chosen-container-single .chosen-single abbr:hover { 93 | background-position: -42px -10px; 94 | } 95 | .chosen-container-single.chosen-disabled .chosen-single abbr:hover { 96 | background-position: -42px -10px; 97 | } 98 | .chosen-container-single .chosen-single div { 99 | position: absolute; 100 | top: 0; 101 | right: 0; 102 | display: block; 103 | width: 18px; 104 | height: 100%; 105 | } 106 | .chosen-container-single .chosen-single div b { 107 | display: block; 108 | width: 100%; 109 | height: 100%; 110 | background: url('chosen-sprite.png') no-repeat 0px 2px; 111 | } 112 | .chosen-container-single .chosen-search { 113 | position: relative; 114 | z-index: 1010; 115 | margin: 0; 116 | padding: 3px 4px; 117 | white-space: nowrap; 118 | } 119 | .chosen-container-single .chosen-search input[type="text"] { 120 | -webkit-box-sizing: border-box; 121 | -moz-box-sizing: border-box; 122 | box-sizing: border-box; 123 | margin: 1px 0; 124 | padding: 4px 20px 4px 5px; 125 | width: 100%; 126 | height: auto; 127 | outline: 0; 128 | border: 1px solid #aaa; 129 | background: white url('chosen-sprite.png') no-repeat 100% -20px; 130 | background: url('chosen-sprite.png') no-repeat 100% -20px; 131 | font-size: 1em; 132 | font-family: sans-serif; 133 | line-height: normal; 134 | border-radius: 0; 135 | } 136 | .chosen-container-single .chosen-drop { 137 | margin-top: -1px; 138 | border-radius: 0 0 4px 4px; 139 | background-clip: padding-box; 140 | } 141 | .chosen-container-single.chosen-container-single-nosearch .chosen-search { 142 | position: absolute; 143 | left: -9999px; 144 | } 145 | 146 | /* @end */ 147 | /* @group Results */ 148 | .chosen-container .chosen-results { 149 | position: relative; 150 | overflow-x: hidden; 151 | overflow-y: auto; 152 | margin: 0 4px 4px 0; 153 | padding: 0 0 0 4px; 154 | max-height: 240px; 155 | -webkit-overflow-scrolling: touch; 156 | } 157 | .chosen-container .chosen-results li { 158 | display: none; 159 | margin: 0; 160 | padding: 5px 6px; 161 | list-style: none; 162 | line-height: 15px; 163 | -webkit-touch-callout: none; 164 | } 165 | .chosen-container .chosen-results li.active-result { 166 | display: list-item; 167 | cursor: pointer; 168 | } 169 | .chosen-container .chosen-results li.disabled-result { 170 | display: list-item; 171 | color: #ccc; 172 | cursor: default; 173 | } 174 | .chosen-container .chosen-results li.highlighted { 175 | background-color: #3875d7; 176 | background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #3875d7), color-stop(90%, #2a62bc)); 177 | background-image: -webkit-linear-gradient(#3875d7 20%, #2a62bc 90%); 178 | background-image: -moz-linear-gradient(#3875d7 20%, #2a62bc 90%); 179 | background-image: -o-linear-gradient(#3875d7 20%, #2a62bc 90%); 180 | background-image: linear-gradient(#3875d7 20%, #2a62bc 90%); 181 | color: #fff; 182 | } 183 | .chosen-container .chosen-results li.no-results { 184 | display: list-item; 185 | background: #f4f4f4; 186 | } 187 | .chosen-container .chosen-results li.group-result { 188 | display: list-item; 189 | font-weight: bold; 190 | cursor: default; 191 | } 192 | .chosen-container .chosen-results li.group-option { 193 | padding-left: 15px; 194 | } 195 | .chosen-container .chosen-results li em { 196 | font-style: normal; 197 | text-decoration: underline; 198 | } 199 | 200 | /* @end */ 201 | /* @group Multi Chosen */ 202 | .chosen-container-multi .chosen-choices { 203 | position: relative; 204 | overflow: hidden; 205 | -webkit-box-sizing: border-box; 206 | -moz-box-sizing: border-box; 207 | box-sizing: border-box; 208 | margin: 0; 209 | padding: 0; 210 | width: 100%; 211 | height: auto !important; 212 | height: 1%; 213 | border: 1px solid #aaa; 214 | background-color: #fff; 215 | background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(1%, #eeeeee), color-stop(15%, #ffffff)); 216 | background-image: -webkit-linear-gradient(#eeeeee 1%, #ffffff 15%); 217 | background-image: -moz-linear-gradient(#eeeeee 1%, #ffffff 15%); 218 | background-image: -o-linear-gradient(#eeeeee 1%, #ffffff 15%); 219 | background-image: linear-gradient(#eeeeee 1%, #ffffff 15%); 220 | cursor: text; 221 | } 222 | .chosen-container-multi .chosen-choices li { 223 | float: left; 224 | list-style: none; 225 | } 226 | .chosen-container-multi .chosen-choices li.search-field { 227 | margin: 0; 228 | padding: 0; 229 | white-space: nowrap; 230 | } 231 | .chosen-container-multi .chosen-choices li.search-field input[type="text"] { 232 | margin: 1px 0; 233 | padding: 5px; 234 | height: 15px; 235 | outline: 0; 236 | border: 0 !important; 237 | background: transparent !important; 238 | box-shadow: none; 239 | color: #666; 240 | font-size: 100%; 241 | font-family: sans-serif; 242 | line-height: normal; 243 | border-radius: 0; 244 | } 245 | .chosen-container-multi .chosen-choices li.search-field .default { 246 | color: #999; 247 | } 248 | .chosen-container-multi .chosen-choices li.search-choice { 249 | position: relative; 250 | margin: 3px 0 3px 5px; 251 | padding: 3px 20px 3px 5px; 252 | border: 1px solid #aaa; 253 | border-radius: 3px; 254 | background-color: #e4e4e4; 255 | background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #f4f4f4), color-stop(50%, #f0f0f0), color-stop(52%, #e8e8e8), color-stop(100%, #eeeeee)); 256 | background-image: -webkit-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); 257 | background-image: -moz-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); 258 | background-image: -o-linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); 259 | background-image: linear-gradient(#f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); 260 | background-clip: padding-box; 261 | box-shadow: 0 0 2px white inset, 0 1px 0 rgba(0, 0, 0, 0.05); 262 | color: #333; 263 | line-height: 13px; 264 | cursor: default; 265 | } 266 | .chosen-container-multi .chosen-choices li.search-choice .search-choice-close { 267 | position: absolute; 268 | top: 4px; 269 | right: 3px; 270 | display: block; 271 | width: 12px; 272 | height: 12px; 273 | background: url('chosen-sprite.png') -42px 1px no-repeat; 274 | font-size: 1px; 275 | } 276 | .chosen-container-multi .chosen-choices li.search-choice .search-choice-close:hover { 277 | background-position: -42px -10px; 278 | } 279 | .chosen-container-multi .chosen-choices li.search-choice-disabled { 280 | padding-right: 5px; 281 | border: 1px solid #ccc; 282 | background-color: #e4e4e4; 283 | background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #f4f4f4), color-stop(50%, #f0f0f0), color-stop(52%, #e8e8e8), color-stop(100%, #eeeeee)); 284 | background-image: -webkit-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); 285 | background-image: -moz-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); 286 | background-image: -o-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); 287 | background-image: linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%); 288 | color: #666; 289 | } 290 | .chosen-container-multi .chosen-choices li.search-choice-focus { 291 | background: #d4d4d4; 292 | } 293 | .chosen-container-multi .chosen-choices li.search-choice-focus .search-choice-close { 294 | background-position: -42px -10px; 295 | } 296 | .chosen-container-multi .chosen-results { 297 | margin: 0; 298 | padding: 0; 299 | } 300 | .chosen-container-multi .chosen-drop .result-selected { 301 | display: list-item; 302 | color: #ccc; 303 | cursor: default; 304 | } 305 | 306 | /* @end */ 307 | /* @group Active */ 308 | .chosen-container-active .chosen-single { 309 | border: 1px solid #5897fb; 310 | box-shadow: 0 0 5px rgba(0, 0, 0, 0.3); 311 | } 312 | .chosen-container-active.chosen-with-drop .chosen-single { 313 | border: 1px solid #aaa; 314 | -moz-border-radius-bottomright: 0; 315 | border-bottom-right-radius: 0; 316 | -moz-border-radius-bottomleft: 0; 317 | border-bottom-left-radius: 0; 318 | background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #eeeeee), color-stop(80%, #ffffff)); 319 | background-image: -webkit-linear-gradient(#eeeeee 20%, #ffffff 80%); 320 | background-image: -moz-linear-gradient(#eeeeee 20%, #ffffff 80%); 321 | background-image: -o-linear-gradient(#eeeeee 20%, #ffffff 80%); 322 | background-image: linear-gradient(#eeeeee 20%, #ffffff 80%); 323 | box-shadow: 0 1px 0 #fff inset; 324 | } 325 | .chosen-container-active.chosen-with-drop .chosen-single div { 326 | border-left: none; 327 | background: transparent; 328 | } 329 | .chosen-container-active.chosen-with-drop .chosen-single div b { 330 | background-position: -18px 2px; 331 | } 332 | .chosen-container-active .chosen-choices { 333 | border: 1px solid #5897fb; 334 | box-shadow: 0 0 5px rgba(0, 0, 0, 0.3); 335 | } 336 | .chosen-container-active .chosen-choices li.search-field input[type="text"] { 337 | color: #111 !important; 338 | } 339 | 340 | /* @end */ 341 | /* @group Disabled Support */ 342 | .chosen-disabled { 343 | opacity: 0.5 !important; 344 | cursor: default; 345 | } 346 | .chosen-disabled .chosen-single { 347 | cursor: default; 348 | } 349 | .chosen-disabled .chosen-choices .search-choice .search-choice-close { 350 | cursor: default; 351 | } 352 | 353 | /* @end */ 354 | /* @group Right to Left */ 355 | .chosen-rtl { 356 | text-align: right; 357 | } 358 | .chosen-rtl .chosen-single { 359 | overflow: visible; 360 | padding: 0 8px 0 0; 361 | } 362 | .chosen-rtl .chosen-single span { 363 | margin-right: 0; 364 | margin-left: 26px; 365 | direction: rtl; 366 | } 367 | .chosen-rtl .chosen-single-with-deselect span { 368 | margin-left: 38px; 369 | } 370 | .chosen-rtl .chosen-single div { 371 | right: auto; 372 | left: 3px; 373 | } 374 | .chosen-rtl .chosen-single abbr { 375 | right: auto; 376 | left: 26px; 377 | } 378 | .chosen-rtl .chosen-choices li { 379 | float: right; 380 | } 381 | .chosen-rtl .chosen-choices li.search-field input[type="text"] { 382 | direction: rtl; 383 | } 384 | .chosen-rtl .chosen-choices li.search-choice { 385 | margin: 3px 5px 3px 0; 386 | padding: 3px 5px 3px 19px; 387 | } 388 | .chosen-rtl .chosen-choices li.search-choice .search-choice-close { 389 | right: auto; 390 | left: 4px; 391 | } 392 | .chosen-rtl.chosen-container-single-nosearch .chosen-search, 393 | .chosen-rtl .chosen-drop { 394 | left: 9999px; 395 | } 396 | .chosen-rtl.chosen-container-single .chosen-results { 397 | margin: 0 0 4px 4px; 398 | padding: 0 4px 0 0; 399 | } 400 | .chosen-rtl .chosen-results li.group-option { 401 | padding-right: 15px; 402 | padding-left: 0; 403 | } 404 | .chosen-rtl.chosen-container-active.chosen-with-drop .chosen-single div { 405 | border-right: none; 406 | } 407 | .chosen-rtl .chosen-search input[type="text"] { 408 | padding: 4px 5px 4px 20px; 409 | background: white url('chosen-sprite.png') no-repeat -30px -20px; 410 | background: url('chosen-sprite.png') no-repeat -30px -20px; 411 | direction: rtl; 412 | } 413 | .chosen-rtl.chosen-container-single .chosen-single div b { 414 | background-position: 6px 2px; 415 | } 416 | .chosen-rtl.chosen-container-single.chosen-with-drop .chosen-single div b { 417 | background-position: -12px 2px; 418 | } 419 | 420 | /* @end */ 421 | /* @group Retina compatibility */ 422 | @media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-resolution: 144dpi) { 423 | .chosen-rtl .chosen-search input[type="text"], 424 | .chosen-container-single .chosen-single abbr, 425 | .chosen-container-single .chosen-single div b, 426 | .chosen-container-single .chosen-search input[type="text"], 427 | .chosen-container-multi .chosen-choices .search-choice .search-choice-close, 428 | .chosen-container .chosen-results-scroll-down span, 429 | .chosen-container .chosen-results-scroll-up span { 430 | background-image: url('chosen-sprite@2x.png') !important; 431 | background-size: 52px 37px !important; 432 | background-repeat: no-repeat !important; 433 | } 434 | } 435 | /* @end */ 436 | -------------------------------------------------------------------------------- /classes/class-editorial-access-manager.php: -------------------------------------------------------------------------------- 1 | $role ) { 24 | $role_object = get_role( $key ); 25 | $role_object->add_cap( EAM_CAPABILITY, $role_object->has_cap( 'manage_options' ) ); 26 | } 27 | } 28 | 29 | /** 30 | * Deactivation 31 | * 32 | * @since 0.3.0 33 | */ 34 | public static function deactivation() { 35 | $roles = get_editable_roles(); 36 | foreach ( $roles as $key => $role ) { 37 | get_role( $key )->remove_cap( EAM_CAPABILITY ); 38 | } 39 | } 40 | 41 | /** 42 | * Register actions and filters 43 | * 44 | * @since 0.1.0 45 | */ 46 | public function setup() { 47 | 48 | // If current user has not the capability to manage access do nothing 49 | if ( ! current_user_can( EAM_CAPABILITY ) ) { 50 | return; 51 | } 52 | 53 | // Register meta boxes and other hooks 54 | add_action( 'add_meta_boxes', array( $this, 'action_add_meta_boxes' ) ); 55 | add_action( 'save_post', array( $this, 'action_save_post' ) ); 56 | add_action( 'admin_enqueue_scripts', array( $this, 'action_admin_enqueue_scripts' ) ); 57 | add_action( 'bulk_edit_custom_box', array( $this, 'action_bulk_edit_custom_box' ), 10, 2 ); 58 | 59 | // Setup admin columns 60 | $post_types = $this->get_post_types(); 61 | foreach( $post_types as $post_type ) { 62 | add_filter( "manage_${post_type}_posts_columns", array( $this, 'manage_columns' ) ); 63 | add_action( "manage_${post_type}_posts_custom_column", array( $this, 'manage_custom_column' ), 10, 2 ); 64 | } 65 | } 66 | 67 | /** 68 | * Return list of post types managed by the plugin 69 | * 70 | * @since 0.3.0 71 | * @return array 72 | */ 73 | public function get_post_types() { 74 | return apply_filters( 'eam_post_types', get_post_types( array( 'public' => true ) ) ); 75 | } 76 | 77 | /** 78 | * Load translation 79 | * 80 | * @since 0.2.0 81 | */ 82 | public function load_textdomain() { 83 | load_plugin_textdomain( 'editorial-access-manager', false, dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' ); 84 | } 85 | 86 | /** 87 | * Map the edit_post meta cap based on whether the users role is whitelisted by the post 88 | * 89 | * @param array $caps 90 | * @param string $cap 91 | * @param int $user_id 92 | * @param array $args 93 | * @since 0.1.0 94 | * @return array 95 | */ 96 | public function filter_map_meta_cap( $caps, $cap, $user_id, $args ) { 97 | $eam_caps = array( 98 | 'edit_page', 99 | 'edit_post', 100 | 'edit_others_pages', 101 | 'edit_others_posts', 102 | 'publish_posts', 103 | 'publish_pages', 104 | 'delete_page', 105 | 'delete_post', 106 | ); 107 | 108 | if ( in_array( $cap, $eam_caps ) ) { 109 | 110 | $post_id = ( isset( $args[0] ) ) ? (int) $args[0] : null; 111 | if ( ! $post_id && ! empty( $_GET['post'] ) ) { 112 | $post_id = (int) $_GET['post']; 113 | } 114 | 115 | if ( ! $post_id && ! empty( $_POST['post_ID'] ) ) { 116 | $post_id = (int) $_POST['post_ID']; 117 | } 118 | 119 | if ( ! $post_id ) { 120 | return $caps; 121 | } 122 | 123 | $enable_custom_access = get_post_meta( $post_id, 'eam_enable_custom_access', true ); 124 | 125 | if ( ! empty( $enable_custom_access ) ) { 126 | $user = new WP_User( $user_id ); 127 | 128 | // If user is admin, we do nothing 129 | if ( ! in_array( 'administrator', $user->roles ) ) { 130 | 131 | if ( 'roles' === $enable_custom_access ) { 132 | // Limit access to whitelisted roles 133 | 134 | $allowed_roles = (array) get_post_meta( $post_id, 'eam_allowed_roles', true ); 135 | 136 | if ( empty( $user->roles ) || count( array_diff( $user->roles, $allowed_roles ) ) >= 1 ) { 137 | $caps[] = 'do_not_allow'; 138 | } else { 139 | $caps = array(); 140 | } 141 | } elseif ( 'users' === $enable_custom_access ) { 142 | // Limit access to whitelisted users 143 | 144 | $allowed_users = (array) get_post_meta( $post_id, 'eam_allowed_users', true ); 145 | 146 | if ( ! in_array( $user_id, $allowed_users ) ) { 147 | $caps[] = 'do_not_allow'; 148 | } else { 149 | $caps = array(); 150 | } 151 | } 152 | } 153 | } 154 | } 155 | 156 | return $caps; 157 | } 158 | 159 | /** 160 | * Enqueue backend JS and CSS for post edit screen 161 | * 162 | * @param string $hook 163 | * @since 0.1.0 164 | */ 165 | public function action_admin_enqueue_scripts( $hook ) { 166 | 167 | /** 168 | * Setup CSS stuff 169 | */ 170 | if ( 'post.php' == $hook || 'post-new.php' == $hook || 'edit.php' == $hook ) { 171 | if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { 172 | $css_path = '/build/css/post-admin.css'; 173 | } else { 174 | $css_path = '/build/css/post-admin.min.css'; 175 | } 176 | wp_enqueue_style( 'eam-post-admin', plugins_url( $css_path, dirname( __FILE__ ) ) ); 177 | } 178 | 179 | /** 180 | * Setup JS stuff 181 | */ 182 | if ( 'post.php' == $hook || 'post-new.php' == $hook || 'edit.php' == $hook ) { // edit.php needed for bulk edit 183 | if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { 184 | $js_path = '/js/post-admin.js'; 185 | } else { 186 | $js_path = '/build/js/post-admin.min.js'; 187 | } 188 | wp_enqueue_style( 'jquery-chosen', plugins_url( '/bower_components/chosen_v1.1.0/chosen.min.css', dirname( __FILE__ ) ) ); 189 | wp_register_script( 'jquery-chosen', plugins_url( '/bower_components/chosen_v1.1.0/chosen.jquery.js', dirname( __FILE__ ) ), array( 'jquery' ), '1.0', true ); 190 | wp_enqueue_script( 'eam-post-admin', plugins_url( $js_path, dirname( __FILE__ ) ), array( 'jquery-chosen' ), '1.0', true ); 191 | } 192 | 193 | } 194 | 195 | /** 196 | * Register meta boxes 197 | * 198 | * @since 0.1.0 199 | */ 200 | public function action_add_meta_boxes() { 201 | $post_types = $this->get_post_types(); 202 | 203 | foreach( $post_types as $post_type ) { 204 | add_meta_box( 'eam_access_manager', __( 'Editorial Access Manager', 'editorial-access-manager' ), array( $this, 'meta_box_access_manager' ), $post_type, 'side', 'core' ); 205 | } 206 | } 207 | 208 | /** 209 | * Save access control information 210 | * 211 | * @param int $post_id 212 | * @since 0.1.0 213 | */ 214 | public function action_save_post( $post_id ) { 215 | if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ! current_user_can( 'edit_post', $post_id ) || 'revision' == get_post_type( $post_id ) ) { 216 | return; 217 | } 218 | 219 | if ( isset( $_REQUEST['bulk_edit'] ) || ( ! empty( $_REQUEST['eam_access_manager'] ) && wp_verify_nonce( $_REQUEST['eam_access_manager'], 'eam_access_manager_action' ) ) ) { 220 | 221 | if ( ! empty( $_REQUEST['eam_enable_custom_access'] ) && in_array( $_REQUEST['eam_enable_custom_access'], array( 'roles', 'users' ) ) ) { 222 | update_post_meta( $post_id, 'eam_enable_custom_access', sanitize_text_field( $_REQUEST['eam_enable_custom_access'] ) ); 223 | 224 | if ( 'roles' == $_REQUEST['eam_enable_custom_access'] ) { 225 | if ( ! empty( $_REQUEST['eam_allowed_roles'] ) ) { 226 | 227 | foreach( $_REQUEST['eam_allowed_roles'] as $role ) { 228 | $allowed_roles[] = sanitize_text_field( $role ); 229 | } 230 | 231 | update_post_meta( $post_id, 'eam_allowed_roles', $allowed_roles ); 232 | 233 | } else { 234 | update_post_meta( $post_id, 'eam_allowed_roles', array() ); 235 | } 236 | } elseif ( 'users' == $_REQUEST['eam_enable_custom_access'] ) { 237 | if ( ! empty( $_REQUEST['eam_allowed_users'] ) ) { 238 | update_post_meta( $post_id, 'eam_allowed_users', array_map( 'absint', $_REQUEST['eam_allowed_users'] ) ); 239 | 240 | } else { 241 | update_post_meta( $post_id, 'eam_allowed_users', array() ); 242 | } 243 | } 244 | } elseif ( '0' == $_REQUEST['eam_enable_custom_access'] ) { 245 | delete_post_meta( $post_id, 'eam_enable_custom_access' ); 246 | } 247 | 248 | } 249 | } 250 | 251 | /** 252 | * Output access manager meta box 253 | * 254 | * @param object $post 255 | * @since 0.1.0 256 | */ 257 | public function meta_box_access_manager( $post ) { 258 | $this->access_form( get_post_type( $post->ID ), $post->ID, false ); 259 | } 260 | 261 | /** 262 | * Output form for bulk editing 263 | * 264 | * @since 0.3.0 265 | * @param string $column_name 266 | * @param string $post_type 267 | * @return object 268 | */ 269 | public function action_bulk_edit_custom_box( $column_name, $post_type ) { 270 | if ( $column_name == 'editorial-access-manager' ) { 271 | $this->access_form( $post_type ); 272 | } 273 | } 274 | 275 | /** 276 | * Output access manager form 277 | * 278 | * @param string $post_type 279 | * @param int $post_id 280 | * @param bool $bulk 281 | * @since 0.3.0 282 | */ 283 | public function access_form( $post_type, $post_id = null, $bulk = true ) { 284 | global $wp_roles; 285 | $post_type_object = get_post_type_object( $post_type ); 286 | 287 | // By default every user and every role with the edit_others_posts cap can edit this post 288 | $edit_others_posts_cap = $post_type_object->cap->edit_others_posts; 289 | 290 | $roles = get_editable_roles(); 291 | 292 | // We only want to allow roles to be whitelisted that already have edit_posts 293 | foreach ( $roles as $role_name => $role_array ) { 294 | $role = get_role( $role_name ); 295 | 296 | if ( ! $role->has_cap( $post_type_object->cap->edit_posts ) ) { 297 | unset( $roles[$role_name] ); 298 | } 299 | } 300 | 301 | $users = get_users(); 302 | 303 | // We only want to allow users to be whitelisted that already have edit_posts 304 | foreach ( $users as $key => $user_object) { 305 | if ( ! user_can( $user_object->ID, $post_type_object->cap->edit_posts ) ) { 306 | unset( $users[$key] ); 307 | } 308 | } 309 | 310 | $allowed_roles = $post_id ? get_post_meta( $post_id, 'eam_allowed_roles', true ) : ''; 311 | if ( $allowed_roles === '' ) { 312 | // get default allowed roles since we have never saved allowed roles for this post 313 | 314 | foreach ( $roles as $role_name => $role_array ) { 315 | $role = get_role( $role_name ); 316 | 317 | if ( $role->has_cap( $edit_others_posts_cap ) ) { 318 | $allowed_roles[] = $role_name; 319 | } 320 | } 321 | } 322 | $allowed_roles = (array) $allowed_roles; 323 | 324 | $allowed_users = $post_id ? get_post_meta( $post_id, 'eam_allowed_users', true ) : ''; 325 | if ( $allowed_users === '' ) { 326 | // get default allowed users since we have never saved allowed users for this post 327 | 328 | foreach ( $users as $user_object ) { 329 | 330 | if ( user_can( $user_object->ID, $edit_others_posts_cap ) ) { 331 | $allowed_users = $user_object->ID; 332 | } 333 | } 334 | 335 | } 336 | $allowed_users = (array) $allowed_users; 337 | 338 | if ( ! $bulk ) { 339 | wp_nonce_field( 'eam_access_manager_action', 'eam_access_manager' ); 340 | } 341 | ?> 342 | 343 |
344 | 345 |
346 | 347 | 353 |
354 | 355 |
356 | 357 | 368 |
369 | 370 |
371 | 372 | 383 |
384 | 385 |
386 | 387 | ' . __( 'Roles', 'editorial-access-manager' ) . ':
'; 419 | foreach ( $roles as $role ) { 420 | if ( ! empty( $wp_roles->roles[ $role ]['name'] ) ) { 421 | $role_names[] = translate_user_role( $wp_roles->roles[ $role ]['name'] ); 422 | } 423 | } 424 | sort( $role_names ); 425 | echo implode( ', ', $role_names ); 426 | } elseif ( 'users' === $eam ) { 427 | $users = get_post_meta( $post_id, 'eam_allowed_users', true ); 428 | $admins = get_users( array( 'role' => 'administrator', 'fields' => 'ID' ) ); 429 | $users = array_merge( $users, $admins ); 430 | $user_names = array(); 431 | echo '' . __( 'Users', 'editorial-access-manager' ) . ':
'; 432 | foreach ( $users as $user ) { 433 | $user_object = get_userdata( $user ); 434 | if ( ! empty( $user_object ) ) { 435 | $user_names[] = $user_object->user_login; 436 | } 437 | } 438 | sort( $user_names ); 439 | echo implode( ', ', $user_names ); 440 | } 441 | } 442 | else { 443 | esc_html_e( 'Off', 'editorial-access-manager' ); 444 | } 445 | } 446 | } 447 | 448 | /** 449 | * Return singleton instance of class 450 | * 451 | * @since 0.1.0 452 | * @return object 453 | */ 454 | public static function factory() { 455 | static $instance; 456 | 457 | if ( ! $instance ) { 458 | $instance = new self(); 459 | } 460 | 461 | return $instance; 462 | } 463 | } -------------------------------------------------------------------------------- /bower_components/chosen_v1.1.0/chosen.jquery.min.js: -------------------------------------------------------------------------------- 1 | /* Chosen v1.1.0 | (c) 2011-2013 by Harvest | MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md */ 2 | !function(){var a,AbstractChosen,Chosen,SelectParser,b,c={}.hasOwnProperty,d=function(a,b){function d(){this.constructor=a}for(var e in b)c.call(b,e)&&(a[e]=b[e]);return d.prototype=b.prototype,a.prototype=new d,a.__super__=b.prototype,a};SelectParser=function(){function SelectParser(){this.options_index=0,this.parsed=[]}return SelectParser.prototype.add_node=function(a){return"OPTGROUP"===a.nodeName.toUpperCase()?this.add_group(a):this.add_option(a)},SelectParser.prototype.add_group=function(a){var b,c,d,e,f,g;for(b=this.parsed.length,this.parsed.push({array_index:b,group:!0,label:this.escapeExpression(a.label),children:0,disabled:a.disabled}),f=a.childNodes,g=[],d=0,e=f.length;e>d;d++)c=f[d],g.push(this.add_option(c,b,a.disabled));return g},SelectParser.prototype.add_option=function(a,b,c){return"OPTION"===a.nodeName.toUpperCase()?(""!==a.text?(null!=b&&(this.parsed[b].children+=1),this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,value:a.value,text:a.text,html:a.innerHTML,selected:a.selected,disabled:c===!0?c:a.disabled,group_array_index:b,classes:a.className,style:a.style.cssText})):this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,empty:!0}),this.options_index+=1):void 0},SelectParser.prototype.escapeExpression=function(a){var b,c;return null==a||a===!1?"":/[\&\<\>\"\'\`]/.test(a)?(b={"<":"<",">":">",'"':""","'":"'","`":"`"},c=/&(?!\w+;)|[\<\>\"\'\`]/g,a.replace(c,function(a){return b[a]||"&"})):a},SelectParser}(),SelectParser.select_to_array=function(a){var b,c,d,e,f;for(c=new SelectParser,f=a.childNodes,d=0,e=f.length;e>d;d++)b=f[d],c.add_node(b);return c.parsed},AbstractChosen=function(){function AbstractChosen(a,b){this.form_field=a,this.options=null!=b?b:{},AbstractChosen.browser_is_supported()&&(this.is_multiple=this.form_field.multiple,this.set_default_text(),this.set_default_values(),this.setup(),this.set_up_html(),this.register_observers())}return AbstractChosen.prototype.set_default_values=function(){var a=this;return this.click_test_action=function(b){return a.test_active_click(b)},this.activate_action=function(b){return a.activate_field(b)},this.active_field=!1,this.mouse_on_container=!1,this.results_showing=!1,this.result_highlighted=null,this.allow_single_deselect=null!=this.options.allow_single_deselect&&null!=this.form_field.options[0]&&""===this.form_field.options[0].text?this.options.allow_single_deselect:!1,this.disable_search_threshold=this.options.disable_search_threshold||0,this.disable_search=this.options.disable_search||!1,this.enable_split_word_search=null!=this.options.enable_split_word_search?this.options.enable_split_word_search:!0,this.group_search=null!=this.options.group_search?this.options.group_search:!0,this.search_contains=this.options.search_contains||!1,this.single_backstroke_delete=null!=this.options.single_backstroke_delete?this.options.single_backstroke_delete:!0,this.max_selected_options=this.options.max_selected_options||1/0,this.inherit_select_classes=this.options.inherit_select_classes||!1,this.display_selected_options=null!=this.options.display_selected_options?this.options.display_selected_options:!0,this.display_disabled_options=null!=this.options.display_disabled_options?this.options.display_disabled_options:!0},AbstractChosen.prototype.set_default_text=function(){return this.default_text=this.form_field.getAttribute("data-placeholder")?this.form_field.getAttribute("data-placeholder"):this.is_multiple?this.options.placeholder_text_multiple||this.options.placeholder_text||AbstractChosen.default_multiple_text:this.options.placeholder_text_single||this.options.placeholder_text||AbstractChosen.default_single_text,this.results_none_found=this.form_field.getAttribute("data-no_results_text")||this.options.no_results_text||AbstractChosen.default_no_result_text},AbstractChosen.prototype.mouse_enter=function(){return this.mouse_on_container=!0},AbstractChosen.prototype.mouse_leave=function(){return this.mouse_on_container=!1},AbstractChosen.prototype.input_focus=function(){var a=this;if(this.is_multiple){if(!this.active_field)return setTimeout(function(){return a.container_mousedown()},50)}else if(!this.active_field)return this.activate_field()},AbstractChosen.prototype.input_blur=function(){var a=this;return this.mouse_on_container?void 0:(this.active_field=!1,setTimeout(function(){return a.blur_test()},100))},AbstractChosen.prototype.results_option_build=function(a){var b,c,d,e,f;for(b="",f=this.results_data,d=0,e=f.length;e>d;d++)c=f[d],b+=c.group?this.result_add_group(c):this.result_add_option(c),(null!=a?a.first:void 0)&&(c.selected&&this.is_multiple?this.choice_build(c):c.selected&&!this.is_multiple&&this.single_set_selected_text(c.text));return b},AbstractChosen.prototype.result_add_option=function(a){var b,c;return a.search_match?this.include_option_in_results(a)?(b=[],a.disabled||a.selected&&this.is_multiple||b.push("active-result"),!a.disabled||a.selected&&this.is_multiple||b.push("disabled-result"),a.selected&&b.push("result-selected"),null!=a.group_array_index&&b.push("group-option"),""!==a.classes&&b.push(a.classes),c=document.createElement("li"),c.className=b.join(" "),c.style.cssText=a.style,c.setAttribute("data-option-array-index",a.array_index),c.innerHTML=a.search_text,this.outerHTML(c)):"":""},AbstractChosen.prototype.result_add_group=function(a){var b;return a.search_match||a.group_match?a.active_options>0?(b=document.createElement("li"),b.className="group-result",b.innerHTML=a.search_text,this.outerHTML(b)):"":""},AbstractChosen.prototype.results_update_field=function(){return this.set_default_text(),this.is_multiple||this.results_reset_cleanup(),this.result_clear_highlight(),this.results_build(),this.results_showing?this.winnow_results():void 0},AbstractChosen.prototype.reset_single_select_options=function(){var a,b,c,d,e;for(d=this.results_data,e=[],b=0,c=d.length;c>b;b++)a=d[b],a.selected?e.push(a.selected=!1):e.push(void 0);return e},AbstractChosen.prototype.results_toggle=function(){return this.results_showing?this.results_hide():this.results_show()},AbstractChosen.prototype.results_search=function(){return this.results_showing?this.winnow_results():this.results_show()},AbstractChosen.prototype.winnow_results=function(){var a,b,c,d,e,f,g,h,i,j,k,l,m;for(this.no_results_clear(),e=0,g=this.get_search_text(),a=g.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),d=this.search_contains?"":"^",c=new RegExp(d+a,"i"),j=new RegExp(a,"i"),m=this.results_data,k=0,l=m.length;l>k;k++)b=m[k],b.search_match=!1,f=null,this.include_option_in_results(b)&&(b.group&&(b.group_match=!1,b.active_options=0),null!=b.group_array_index&&this.results_data[b.group_array_index]&&(f=this.results_data[b.group_array_index],0===f.active_options&&f.search_match&&(e+=1),f.active_options+=1),(!b.group||this.group_search)&&(b.search_text=b.group?b.label:b.html,b.search_match=this.search_string_match(b.search_text,c),b.search_match&&!b.group&&(e+=1),b.search_match?(g.length&&(h=b.search_text.search(j),i=b.search_text.substr(0,h+g.length)+""+b.search_text.substr(h+g.length),b.search_text=i.substr(0,h)+""+i.substr(h)),null!=f&&(f.group_match=!0)):null!=b.group_array_index&&this.results_data[b.group_array_index].search_match&&(b.search_match=!0)));return this.result_clear_highlight(),1>e&&g.length?(this.update_results_content(""),this.no_results(g)):(this.update_results_content(this.results_option_build()),this.winnow_results_set_highlight())},AbstractChosen.prototype.search_string_match=function(a,b){var c,d,e,f;if(b.test(a))return!0;if(this.enable_split_word_search&&(a.indexOf(" ")>=0||0===a.indexOf("["))&&(d=a.replace(/\[|\]/g,"").split(" "),d.length))for(e=0,f=d.length;f>e;e++)if(c=d[e],b.test(c))return!0},AbstractChosen.prototype.choices_count=function(){var a,b,c,d;if(null!=this.selected_option_count)return this.selected_option_count;for(this.selected_option_count=0,d=this.form_field.options,b=0,c=d.length;c>b;b++)a=d[b],a.selected&&(this.selected_option_count+=1);return this.selected_option_count},AbstractChosen.prototype.choices_click=function(a){return a.preventDefault(),this.results_showing||this.is_disabled?void 0:this.results_show()},AbstractChosen.prototype.keyup_checker=function(a){var b,c;switch(b=null!=(c=a.which)?c:a.keyCode,this.search_field_scale(),b){case 8:if(this.is_multiple&&this.backstroke_length<1&&this.choices_count()>0)return this.keydown_backstroke();if(!this.pending_backstroke)return this.result_clear_highlight(),this.results_search();break;case 13:if(a.preventDefault(),this.results_showing)return this.result_select(a);break;case 27:return this.results_showing&&this.results_hide(),!0;case 9:case 38:case 40:case 16:case 91:case 17:break;default:return this.results_search()}},AbstractChosen.prototype.clipboard_event_checker=function(){var a=this;return setTimeout(function(){return a.results_search()},50)},AbstractChosen.prototype.container_width=function(){return null!=this.options.width?this.options.width:""+this.form_field.offsetWidth+"px"},AbstractChosen.prototype.include_option_in_results=function(a){return this.is_multiple&&!this.display_selected_options&&a.selected?!1:!this.display_disabled_options&&a.disabled?!1:a.empty?!1:!0},AbstractChosen.prototype.search_results_touchstart=function(a){return this.touch_started=!0,this.search_results_mouseover(a)},AbstractChosen.prototype.search_results_touchmove=function(a){return this.touch_started=!1,this.search_results_mouseout(a)},AbstractChosen.prototype.search_results_touchend=function(a){return this.touch_started?this.search_results_mouseup(a):void 0},AbstractChosen.prototype.outerHTML=function(a){var b;return a.outerHTML?a.outerHTML:(b=document.createElement("div"),b.appendChild(a),b.innerHTML)},AbstractChosen.browser_is_supported=function(){return"Microsoft Internet Explorer"===window.navigator.appName?document.documentMode>=8:/iP(od|hone)/i.test(window.navigator.userAgent)?!1:/Android/i.test(window.navigator.userAgent)&&/Mobile/i.test(window.navigator.userAgent)?!1:!0},AbstractChosen.default_multiple_text="Select Some Options",AbstractChosen.default_single_text="Select an Option",AbstractChosen.default_no_result_text="No results match",AbstractChosen}(),a=jQuery,a.fn.extend({chosen:function(b){return AbstractChosen.browser_is_supported()?this.each(function(){var c,d;c=a(this),d=c.data("chosen"),"destroy"===b&&d?d.destroy():d||c.data("chosen",new Chosen(this,b))}):this}}),Chosen=function(c){function Chosen(){return b=Chosen.__super__.constructor.apply(this,arguments)}return d(Chosen,c),Chosen.prototype.setup=function(){return this.form_field_jq=a(this.form_field),this.current_selectedIndex=this.form_field.selectedIndex,this.is_rtl=this.form_field_jq.hasClass("chosen-rtl")},Chosen.prototype.set_up_html=function(){var b,c;return b=["chosen-container"],b.push("chosen-container-"+(this.is_multiple?"multi":"single")),this.inherit_select_classes&&this.form_field.className&&b.push(this.form_field.className),this.is_rtl&&b.push("chosen-rtl"),c={"class":b.join(" "),style:"width: "+this.container_width()+";",title:this.form_field.title},this.form_field.id.length&&(c.id=this.form_field.id.replace(/[^\w]/g,"_")+"_chosen"),this.container=a("
",c),this.is_multiple?this.container.html('
    '):this.container.html(''+this.default_text+'
      '),this.form_field_jq.hide().after(this.container),this.dropdown=this.container.find("div.chosen-drop").first(),this.search_field=this.container.find("input").first(),this.search_results=this.container.find("ul.chosen-results").first(),this.search_field_scale(),this.search_no_results=this.container.find("li.no-results").first(),this.is_multiple?(this.search_choices=this.container.find("ul.chosen-choices").first(),this.search_container=this.container.find("li.search-field").first()):(this.search_container=this.container.find("div.chosen-search").first(),this.selected_item=this.container.find(".chosen-single").first()),this.results_build(),this.set_tab_index(),this.set_label_behavior(),this.form_field_jq.trigger("chosen:ready",{chosen:this})},Chosen.prototype.register_observers=function(){var a=this;return this.container.bind("mousedown.chosen",function(b){a.container_mousedown(b)}),this.container.bind("mouseup.chosen",function(b){a.container_mouseup(b)}),this.container.bind("mouseenter.chosen",function(b){a.mouse_enter(b)}),this.container.bind("mouseleave.chosen",function(b){a.mouse_leave(b)}),this.search_results.bind("mouseup.chosen",function(b){a.search_results_mouseup(b)}),this.search_results.bind("mouseover.chosen",function(b){a.search_results_mouseover(b)}),this.search_results.bind("mouseout.chosen",function(b){a.search_results_mouseout(b)}),this.search_results.bind("mousewheel.chosen DOMMouseScroll.chosen",function(b){a.search_results_mousewheel(b)}),this.search_results.bind("touchstart.chosen",function(b){a.search_results_touchstart(b)}),this.search_results.bind("touchmove.chosen",function(b){a.search_results_touchmove(b)}),this.search_results.bind("touchend.chosen",function(b){a.search_results_touchend(b)}),this.form_field_jq.bind("chosen:updated.chosen",function(b){a.results_update_field(b)}),this.form_field_jq.bind("chosen:activate.chosen",function(b){a.activate_field(b)}),this.form_field_jq.bind("chosen:open.chosen",function(b){a.container_mousedown(b)}),this.form_field_jq.bind("chosen:close.chosen",function(b){a.input_blur(b)}),this.search_field.bind("blur.chosen",function(b){a.input_blur(b)}),this.search_field.bind("keyup.chosen",function(b){a.keyup_checker(b)}),this.search_field.bind("keydown.chosen",function(b){a.keydown_checker(b)}),this.search_field.bind("focus.chosen",function(b){a.input_focus(b)}),this.search_field.bind("cut.chosen",function(b){a.clipboard_event_checker(b)}),this.search_field.bind("paste.chosen",function(b){a.clipboard_event_checker(b)}),this.is_multiple?this.search_choices.bind("click.chosen",function(b){a.choices_click(b)}):this.container.bind("click.chosen",function(a){a.preventDefault()})},Chosen.prototype.destroy=function(){return a(this.container[0].ownerDocument).unbind("click.chosen",this.click_test_action),this.search_field[0].tabIndex&&(this.form_field_jq[0].tabIndex=this.search_field[0].tabIndex),this.container.remove(),this.form_field_jq.removeData("chosen"),this.form_field_jq.show()},Chosen.prototype.search_field_disabled=function(){return this.is_disabled=this.form_field_jq[0].disabled,this.is_disabled?(this.container.addClass("chosen-disabled"),this.search_field[0].disabled=!0,this.is_multiple||this.selected_item.unbind("focus.chosen",this.activate_action),this.close_field()):(this.container.removeClass("chosen-disabled"),this.search_field[0].disabled=!1,this.is_multiple?void 0:this.selected_item.bind("focus.chosen",this.activate_action))},Chosen.prototype.container_mousedown=function(b){return this.is_disabled||(b&&"mousedown"===b.type&&!this.results_showing&&b.preventDefault(),null!=b&&a(b.target).hasClass("search-choice-close"))?void 0:(this.active_field?this.is_multiple||!b||a(b.target)[0]!==this.selected_item[0]&&!a(b.target).parents("a.chosen-single").length||(b.preventDefault(),this.results_toggle()):(this.is_multiple&&this.search_field.val(""),a(this.container[0].ownerDocument).bind("click.chosen",this.click_test_action),this.results_show()),this.activate_field())},Chosen.prototype.container_mouseup=function(a){return"ABBR"!==a.target.nodeName||this.is_disabled?void 0:this.results_reset(a)},Chosen.prototype.search_results_mousewheel=function(a){var b;return a.originalEvent&&(b=-a.originalEvent.wheelDelta||a.originalEvent.detail),null!=b?(a.preventDefault(),"DOMMouseScroll"===a.type&&(b=40*b),this.search_results.scrollTop(b+this.search_results.scrollTop())):void 0},Chosen.prototype.blur_test=function(){return!this.active_field&&this.container.hasClass("chosen-container-active")?this.close_field():void 0},Chosen.prototype.close_field=function(){return a(this.container[0].ownerDocument).unbind("click.chosen",this.click_test_action),this.active_field=!1,this.results_hide(),this.container.removeClass("chosen-container-active"),this.clear_backstroke(),this.show_search_field_default(),this.search_field_scale()},Chosen.prototype.activate_field=function(){return this.container.addClass("chosen-container-active"),this.active_field=!0,this.search_field.val(this.search_field.val()),this.search_field.focus()},Chosen.prototype.test_active_click=function(b){var c;return c=a(b.target).closest(".chosen-container"),c.length&&this.container[0]===c[0]?this.active_field=!0:this.close_field()},Chosen.prototype.results_build=function(){return this.parsing=!0,this.selected_option_count=null,this.results_data=SelectParser.select_to_array(this.form_field),this.is_multiple?this.search_choices.find("li.search-choice").remove():this.is_multiple||(this.single_set_selected_text(),this.disable_search||this.form_field.options.length<=this.disable_search_threshold?(this.search_field[0].readOnly=!0,this.container.addClass("chosen-container-single-nosearch")):(this.search_field[0].readOnly=!1,this.container.removeClass("chosen-container-single-nosearch"))),this.update_results_content(this.results_option_build({first:!0})),this.search_field_disabled(),this.show_search_field_default(),this.search_field_scale(),this.parsing=!1},Chosen.prototype.result_do_highlight=function(a){var b,c,d,e,f;if(a.length){if(this.result_clear_highlight(),this.result_highlight=a,this.result_highlight.addClass("highlighted"),d=parseInt(this.search_results.css("maxHeight"),10),f=this.search_results.scrollTop(),e=d+f,c=this.result_highlight.position().top+this.search_results.scrollTop(),b=c+this.result_highlight.outerHeight(),b>=e)return this.search_results.scrollTop(b-d>0?b-d:0);if(f>c)return this.search_results.scrollTop(c)}},Chosen.prototype.result_clear_highlight=function(){return this.result_highlight&&this.result_highlight.removeClass("highlighted"),this.result_highlight=null},Chosen.prototype.results_show=function(){return this.is_multiple&&this.max_selected_options<=this.choices_count()?(this.form_field_jq.trigger("chosen:maxselected",{chosen:this}),!1):(this.container.addClass("chosen-with-drop"),this.results_showing=!0,this.search_field.focus(),this.search_field.val(this.search_field.val()),this.winnow_results(),this.form_field_jq.trigger("chosen:showing_dropdown",{chosen:this}))},Chosen.prototype.update_results_content=function(a){return this.search_results.html(a)},Chosen.prototype.results_hide=function(){return this.results_showing&&(this.result_clear_highlight(),this.container.removeClass("chosen-with-drop"),this.form_field_jq.trigger("chosen:hiding_dropdown",{chosen:this})),this.results_showing=!1},Chosen.prototype.set_tab_index=function(){var a;return this.form_field.tabIndex?(a=this.form_field.tabIndex,this.form_field.tabIndex=-1,this.search_field[0].tabIndex=a):void 0},Chosen.prototype.set_label_behavior=function(){var b=this;return this.form_field_label=this.form_field_jq.parents("label"),!this.form_field_label.length&&this.form_field.id.length&&(this.form_field_label=a("label[for='"+this.form_field.id+"']")),this.form_field_label.length>0?this.form_field_label.bind("click.chosen",function(a){return b.is_multiple?b.container_mousedown(a):b.activate_field()}):void 0},Chosen.prototype.show_search_field_default=function(){return this.is_multiple&&this.choices_count()<1&&!this.active_field?(this.search_field.val(this.default_text),this.search_field.addClass("default")):(this.search_field.val(""),this.search_field.removeClass("default"))},Chosen.prototype.search_results_mouseup=function(b){var c;return c=a(b.target).hasClass("active-result")?a(b.target):a(b.target).parents(".active-result").first(),c.length?(this.result_highlight=c,this.result_select(b),this.search_field.focus()):void 0},Chosen.prototype.search_results_mouseover=function(b){var c;return c=a(b.target).hasClass("active-result")?a(b.target):a(b.target).parents(".active-result").first(),c?this.result_do_highlight(c):void 0},Chosen.prototype.search_results_mouseout=function(b){return a(b.target).hasClass("active-result")?this.result_clear_highlight():void 0},Chosen.prototype.choice_build=function(b){var c,d,e=this;return c=a("
    • ",{"class":"search-choice"}).html(""+b.html+""),b.disabled?c.addClass("search-choice-disabled"):(d=a("",{"class":"search-choice-close","data-option-array-index":b.array_index}),d.bind("click.chosen",function(a){return e.choice_destroy_link_click(a)}),c.append(d)),this.search_container.before(c)},Chosen.prototype.choice_destroy_link_click=function(b){return b.preventDefault(),b.stopPropagation(),this.is_disabled?void 0:this.choice_destroy(a(b.target))},Chosen.prototype.choice_destroy=function(a){return this.result_deselect(a[0].getAttribute("data-option-array-index"))?(this.show_search_field_default(),this.is_multiple&&this.choices_count()>0&&this.search_field.val().length<1&&this.results_hide(),a.parents("li").first().remove(),this.search_field_scale()):void 0},Chosen.prototype.results_reset=function(){return this.reset_single_select_options(),this.form_field.options[0].selected=!0,this.single_set_selected_text(),this.show_search_field_default(),this.results_reset_cleanup(),this.form_field_jq.trigger("change"),this.active_field?this.results_hide():void 0},Chosen.prototype.results_reset_cleanup=function(){return this.current_selectedIndex=this.form_field.selectedIndex,this.selected_item.find("abbr").remove()},Chosen.prototype.result_select=function(a){var b,c;return this.result_highlight?(b=this.result_highlight,this.result_clear_highlight(),this.is_multiple&&this.max_selected_options<=this.choices_count()?(this.form_field_jq.trigger("chosen:maxselected",{chosen:this}),!1):(this.is_multiple?b.removeClass("active-result"):this.reset_single_select_options(),c=this.results_data[b[0].getAttribute("data-option-array-index")],c.selected=!0,this.form_field.options[c.options_index].selected=!0,this.selected_option_count=null,this.is_multiple?this.choice_build(c):this.single_set_selected_text(c.text),(a.metaKey||a.ctrlKey)&&this.is_multiple||this.results_hide(),this.search_field.val(""),(this.is_multiple||this.form_field.selectedIndex!==this.current_selectedIndex)&&this.form_field_jq.trigger("change",{selected:this.form_field.options[c.options_index].value}),this.current_selectedIndex=this.form_field.selectedIndex,this.search_field_scale())):void 0},Chosen.prototype.single_set_selected_text=function(a){return null==a&&(a=this.default_text),a===this.default_text?this.selected_item.addClass("chosen-default"):(this.single_deselect_control_build(),this.selected_item.removeClass("chosen-default")),this.selected_item.find("span").text(a)},Chosen.prototype.result_deselect=function(a){var b;return b=this.results_data[a],this.form_field.options[b.options_index].disabled?!1:(b.selected=!1,this.form_field.options[b.options_index].selected=!1,this.selected_option_count=null,this.result_clear_highlight(),this.results_showing&&this.winnow_results(),this.form_field_jq.trigger("change",{deselected:this.form_field.options[b.options_index].value}),this.search_field_scale(),!0)},Chosen.prototype.single_deselect_control_build=function(){return this.allow_single_deselect?(this.selected_item.find("abbr").length||this.selected_item.find("span").first().after(''),this.selected_item.addClass("chosen-single-with-deselect")):void 0},Chosen.prototype.get_search_text=function(){return this.search_field.val()===this.default_text?"":a("
      ").text(a.trim(this.search_field.val())).html()},Chosen.prototype.winnow_results_set_highlight=function(){var a,b;return b=this.is_multiple?[]:this.search_results.find(".result-selected.active-result"),a=b.length?b.first():this.search_results.find(".active-result").first(),null!=a?this.result_do_highlight(a):void 0},Chosen.prototype.no_results=function(b){var c;return c=a('
    • '+this.results_none_found+' ""
    • '),c.find("span").first().html(b),this.search_results.append(c),this.form_field_jq.trigger("chosen:no_results",{chosen:this})},Chosen.prototype.no_results_clear=function(){return this.search_results.find(".no-results").remove()},Chosen.prototype.keydown_arrow=function(){var a;return this.results_showing&&this.result_highlight?(a=this.result_highlight.nextAll("li.active-result").first())?this.result_do_highlight(a):void 0:this.results_show()},Chosen.prototype.keyup_arrow=function(){var a;return this.results_showing||this.is_multiple?this.result_highlight?(a=this.result_highlight.prevAll("li.active-result"),a.length?this.result_do_highlight(a.first()):(this.choices_count()>0&&this.results_hide(),this.result_clear_highlight())):void 0:this.results_show()},Chosen.prototype.keydown_backstroke=function(){var a;return this.pending_backstroke?(this.choice_destroy(this.pending_backstroke.find("a").first()),this.clear_backstroke()):(a=this.search_container.siblings("li.search-choice").last(),a.length&&!a.hasClass("search-choice-disabled")?(this.pending_backstroke=a,this.single_backstroke_delete?this.keydown_backstroke():this.pending_backstroke.addClass("search-choice-focus")):void 0)},Chosen.prototype.clear_backstroke=function(){return this.pending_backstroke&&this.pending_backstroke.removeClass("search-choice-focus"),this.pending_backstroke=null},Chosen.prototype.keydown_checker=function(a){var b,c;switch(b=null!=(c=a.which)?c:a.keyCode,this.search_field_scale(),8!==b&&this.pending_backstroke&&this.clear_backstroke(),b){case 8:this.backstroke_length=this.search_field.val().length;break;case 9:this.results_showing&&!this.is_multiple&&this.result_select(a),this.mouse_on_container=!1;break;case 13:a.preventDefault();break;case 38:a.preventDefault(),this.keyup_arrow();break;case 40:a.preventDefault(),this.keydown_arrow()}},Chosen.prototype.search_field_scale=function(){var b,c,d,e,f,g,h,i,j;if(this.is_multiple){for(d=0,h=0,f="position:absolute; left: -1000px; top: -1000px; display:none;",g=["font-size","font-style","font-weight","font-family","line-height","text-transform","letter-spacing"],i=0,j=g.length;j>i;i++)e=g[i],f+=e+":"+this.search_field.css(e)+";";return b=a("
      ",{style:f}),b.text(this.search_field.val()),a("body").append(b),h=b.width()+25,b.remove(),c=this.container.outerWidth(),h>c-10&&(h=c-10),this.search_field.css({width:h+"px"})}},Chosen}(AbstractChosen)}.call(this); -------------------------------------------------------------------------------- /bower_components/chosen_v1.1.0/chosen.proto.min.js: -------------------------------------------------------------------------------- 1 | /* Chosen v1.1.0 | (c) 2011-2013 by Harvest | MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md */ 2 | !function(){var AbstractChosen,SelectParser,a,b={}.hasOwnProperty,c=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a};SelectParser=function(){function SelectParser(){this.options_index=0,this.parsed=[]}return SelectParser.prototype.add_node=function(a){return"OPTGROUP"===a.nodeName.toUpperCase()?this.add_group(a):this.add_option(a)},SelectParser.prototype.add_group=function(a){var b,c,d,e,f,g;for(b=this.parsed.length,this.parsed.push({array_index:b,group:!0,label:this.escapeExpression(a.label),children:0,disabled:a.disabled}),f=a.childNodes,g=[],d=0,e=f.length;e>d;d++)c=f[d],g.push(this.add_option(c,b,a.disabled));return g},SelectParser.prototype.add_option=function(a,b,c){return"OPTION"===a.nodeName.toUpperCase()?(""!==a.text?(null!=b&&(this.parsed[b].children+=1),this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,value:a.value,text:a.text,html:a.innerHTML,selected:a.selected,disabled:c===!0?c:a.disabled,group_array_index:b,classes:a.className,style:a.style.cssText})):this.parsed.push({array_index:this.parsed.length,options_index:this.options_index,empty:!0}),this.options_index+=1):void 0},SelectParser.prototype.escapeExpression=function(a){var b,c;return null==a||a===!1?"":/[\&\<\>\"\'\`]/.test(a)?(b={"<":"<",">":">",'"':""","'":"'","`":"`"},c=/&(?!\w+;)|[\<\>\"\'\`]/g,a.replace(c,function(a){return b[a]||"&"})):a},SelectParser}(),SelectParser.select_to_array=function(a){var b,c,d,e,f;for(c=new SelectParser,f=a.childNodes,d=0,e=f.length;e>d;d++)b=f[d],c.add_node(b);return c.parsed},AbstractChosen=function(){function AbstractChosen(a,b){this.form_field=a,this.options=null!=b?b:{},AbstractChosen.browser_is_supported()&&(this.is_multiple=this.form_field.multiple,this.set_default_text(),this.set_default_values(),this.setup(),this.set_up_html(),this.register_observers())}return AbstractChosen.prototype.set_default_values=function(){var a=this;return this.click_test_action=function(b){return a.test_active_click(b)},this.activate_action=function(b){return a.activate_field(b)},this.active_field=!1,this.mouse_on_container=!1,this.results_showing=!1,this.result_highlighted=null,this.allow_single_deselect=null!=this.options.allow_single_deselect&&null!=this.form_field.options[0]&&""===this.form_field.options[0].text?this.options.allow_single_deselect:!1,this.disable_search_threshold=this.options.disable_search_threshold||0,this.disable_search=this.options.disable_search||!1,this.enable_split_word_search=null!=this.options.enable_split_word_search?this.options.enable_split_word_search:!0,this.group_search=null!=this.options.group_search?this.options.group_search:!0,this.search_contains=this.options.search_contains||!1,this.single_backstroke_delete=null!=this.options.single_backstroke_delete?this.options.single_backstroke_delete:!0,this.max_selected_options=this.options.max_selected_options||1/0,this.inherit_select_classes=this.options.inherit_select_classes||!1,this.display_selected_options=null!=this.options.display_selected_options?this.options.display_selected_options:!0,this.display_disabled_options=null!=this.options.display_disabled_options?this.options.display_disabled_options:!0},AbstractChosen.prototype.set_default_text=function(){return this.default_text=this.form_field.getAttribute("data-placeholder")?this.form_field.getAttribute("data-placeholder"):this.is_multiple?this.options.placeholder_text_multiple||this.options.placeholder_text||AbstractChosen.default_multiple_text:this.options.placeholder_text_single||this.options.placeholder_text||AbstractChosen.default_single_text,this.results_none_found=this.form_field.getAttribute("data-no_results_text")||this.options.no_results_text||AbstractChosen.default_no_result_text},AbstractChosen.prototype.mouse_enter=function(){return this.mouse_on_container=!0},AbstractChosen.prototype.mouse_leave=function(){return this.mouse_on_container=!1},AbstractChosen.prototype.input_focus=function(){var a=this;if(this.is_multiple){if(!this.active_field)return setTimeout(function(){return a.container_mousedown()},50)}else if(!this.active_field)return this.activate_field()},AbstractChosen.prototype.input_blur=function(){var a=this;return this.mouse_on_container?void 0:(this.active_field=!1,setTimeout(function(){return a.blur_test()},100))},AbstractChosen.prototype.results_option_build=function(a){var b,c,d,e,f;for(b="",f=this.results_data,d=0,e=f.length;e>d;d++)c=f[d],b+=c.group?this.result_add_group(c):this.result_add_option(c),(null!=a?a.first:void 0)&&(c.selected&&this.is_multiple?this.choice_build(c):c.selected&&!this.is_multiple&&this.single_set_selected_text(c.text));return b},AbstractChosen.prototype.result_add_option=function(a){var b,c;return a.search_match?this.include_option_in_results(a)?(b=[],a.disabled||a.selected&&this.is_multiple||b.push("active-result"),!a.disabled||a.selected&&this.is_multiple||b.push("disabled-result"),a.selected&&b.push("result-selected"),null!=a.group_array_index&&b.push("group-option"),""!==a.classes&&b.push(a.classes),c=document.createElement("li"),c.className=b.join(" "),c.style.cssText=a.style,c.setAttribute("data-option-array-index",a.array_index),c.innerHTML=a.search_text,this.outerHTML(c)):"":""},AbstractChosen.prototype.result_add_group=function(a){var b;return a.search_match||a.group_match?a.active_options>0?(b=document.createElement("li"),b.className="group-result",b.innerHTML=a.search_text,this.outerHTML(b)):"":""},AbstractChosen.prototype.results_update_field=function(){return this.set_default_text(),this.is_multiple||this.results_reset_cleanup(),this.result_clear_highlight(),this.results_build(),this.results_showing?this.winnow_results():void 0},AbstractChosen.prototype.reset_single_select_options=function(){var a,b,c,d,e;for(d=this.results_data,e=[],b=0,c=d.length;c>b;b++)a=d[b],a.selected?e.push(a.selected=!1):e.push(void 0);return e},AbstractChosen.prototype.results_toggle=function(){return this.results_showing?this.results_hide():this.results_show()},AbstractChosen.prototype.results_search=function(){return this.results_showing?this.winnow_results():this.results_show()},AbstractChosen.prototype.winnow_results=function(){var a,b,c,d,e,f,g,h,i,j,k,l,m;for(this.no_results_clear(),e=0,g=this.get_search_text(),a=g.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),d=this.search_contains?"":"^",c=new RegExp(d+a,"i"),j=new RegExp(a,"i"),m=this.results_data,k=0,l=m.length;l>k;k++)b=m[k],b.search_match=!1,f=null,this.include_option_in_results(b)&&(b.group&&(b.group_match=!1,b.active_options=0),null!=b.group_array_index&&this.results_data[b.group_array_index]&&(f=this.results_data[b.group_array_index],0===f.active_options&&f.search_match&&(e+=1),f.active_options+=1),(!b.group||this.group_search)&&(b.search_text=b.group?b.label:b.html,b.search_match=this.search_string_match(b.search_text,c),b.search_match&&!b.group&&(e+=1),b.search_match?(g.length&&(h=b.search_text.search(j),i=b.search_text.substr(0,h+g.length)+""+b.search_text.substr(h+g.length),b.search_text=i.substr(0,h)+""+i.substr(h)),null!=f&&(f.group_match=!0)):null!=b.group_array_index&&this.results_data[b.group_array_index].search_match&&(b.search_match=!0)));return this.result_clear_highlight(),1>e&&g.length?(this.update_results_content(""),this.no_results(g)):(this.update_results_content(this.results_option_build()),this.winnow_results_set_highlight())},AbstractChosen.prototype.search_string_match=function(a,b){var c,d,e,f;if(b.test(a))return!0;if(this.enable_split_word_search&&(a.indexOf(" ")>=0||0===a.indexOf("["))&&(d=a.replace(/\[|\]/g,"").split(" "),d.length))for(e=0,f=d.length;f>e;e++)if(c=d[e],b.test(c))return!0},AbstractChosen.prototype.choices_count=function(){var a,b,c,d;if(null!=this.selected_option_count)return this.selected_option_count;for(this.selected_option_count=0,d=this.form_field.options,b=0,c=d.length;c>b;b++)a=d[b],a.selected&&(this.selected_option_count+=1);return this.selected_option_count},AbstractChosen.prototype.choices_click=function(a){return a.preventDefault(),this.results_showing||this.is_disabled?void 0:this.results_show()},AbstractChosen.prototype.keyup_checker=function(a){var b,c;switch(b=null!=(c=a.which)?c:a.keyCode,this.search_field_scale(),b){case 8:if(this.is_multiple&&this.backstroke_length<1&&this.choices_count()>0)return this.keydown_backstroke();if(!this.pending_backstroke)return this.result_clear_highlight(),this.results_search();break;case 13:if(a.preventDefault(),this.results_showing)return this.result_select(a);break;case 27:return this.results_showing&&this.results_hide(),!0;case 9:case 38:case 40:case 16:case 91:case 17:break;default:return this.results_search()}},AbstractChosen.prototype.clipboard_event_checker=function(){var a=this;return setTimeout(function(){return a.results_search()},50)},AbstractChosen.prototype.container_width=function(){return null!=this.options.width?this.options.width:""+this.form_field.offsetWidth+"px"},AbstractChosen.prototype.include_option_in_results=function(a){return this.is_multiple&&!this.display_selected_options&&a.selected?!1:!this.display_disabled_options&&a.disabled?!1:a.empty?!1:!0},AbstractChosen.prototype.search_results_touchstart=function(a){return this.touch_started=!0,this.search_results_mouseover(a)},AbstractChosen.prototype.search_results_touchmove=function(a){return this.touch_started=!1,this.search_results_mouseout(a)},AbstractChosen.prototype.search_results_touchend=function(a){return this.touch_started?this.search_results_mouseup(a):void 0},AbstractChosen.prototype.outerHTML=function(a){var b;return a.outerHTML?a.outerHTML:(b=document.createElement("div"),b.appendChild(a),b.innerHTML)},AbstractChosen.browser_is_supported=function(){return"Microsoft Internet Explorer"===window.navigator.appName?document.documentMode>=8:/iP(od|hone)/i.test(window.navigator.userAgent)?!1:/Android/i.test(window.navigator.userAgent)&&/Mobile/i.test(window.navigator.userAgent)?!1:!0},AbstractChosen.default_multiple_text="Select Some Options",AbstractChosen.default_single_text="Select an Option",AbstractChosen.default_no_result_text="No results match",AbstractChosen}(),this.Chosen=function(b){function Chosen(){return a=Chosen.__super__.constructor.apply(this,arguments)}return c(Chosen,b),Chosen.prototype.setup=function(){return this.current_selectedIndex=this.form_field.selectedIndex,this.is_rtl=this.form_field.hasClassName("chosen-rtl")},Chosen.prototype.set_default_values=function(){return Chosen.__super__.set_default_values.call(this),this.single_temp=new Template('#{default}
        '),this.multi_temp=new Template('
          '),this.no_results_temp=new Template('
        • '+this.results_none_found+' "#{terms}"
        • ')},Chosen.prototype.set_up_html=function(){var a,b;return a=["chosen-container"],a.push("chosen-container-"+(this.is_multiple?"multi":"single")),this.inherit_select_classes&&this.form_field.className&&a.push(this.form_field.className),this.is_rtl&&a.push("chosen-rtl"),b={"class":a.join(" "),style:"width: "+this.container_width()+";",title:this.form_field.title},this.form_field.id.length&&(b.id=this.form_field.id.replace(/[^\w]/g,"_")+"_chosen"),this.container=this.is_multiple?new Element("div",b).update(this.multi_temp.evaluate({"default":this.default_text})):new Element("div",b).update(this.single_temp.evaluate({"default":this.default_text})),this.form_field.hide().insert({after:this.container}),this.dropdown=this.container.down("div.chosen-drop"),this.search_field=this.container.down("input"),this.search_results=this.container.down("ul.chosen-results"),this.search_field_scale(),this.search_no_results=this.container.down("li.no-results"),this.is_multiple?(this.search_choices=this.container.down("ul.chosen-choices"),this.search_container=this.container.down("li.search-field")):(this.search_container=this.container.down("div.chosen-search"),this.selected_item=this.container.down(".chosen-single")),this.results_build(),this.set_tab_index(),this.set_label_behavior(),this.form_field.fire("chosen:ready",{chosen:this})},Chosen.prototype.register_observers=function(){var a=this;return this.container.observe("mousedown",function(b){return a.container_mousedown(b)}),this.container.observe("mouseup",function(b){return a.container_mouseup(b)}),this.container.observe("mouseenter",function(b){return a.mouse_enter(b)}),this.container.observe("mouseleave",function(b){return a.mouse_leave(b)}),this.search_results.observe("mouseup",function(b){return a.search_results_mouseup(b)}),this.search_results.observe("mouseover",function(b){return a.search_results_mouseover(b)}),this.search_results.observe("mouseout",function(b){return a.search_results_mouseout(b)}),this.search_results.observe("mousewheel",function(b){return a.search_results_mousewheel(b)}),this.search_results.observe("DOMMouseScroll",function(b){return a.search_results_mousewheel(b)}),this.search_results.observe("touchstart",function(b){return a.search_results_touchstart(b)}),this.search_results.observe("touchmove",function(b){return a.search_results_touchmove(b)}),this.search_results.observe("touchend",function(b){return a.search_results_touchend(b)}),this.form_field.observe("chosen:updated",function(b){return a.results_update_field(b)}),this.form_field.observe("chosen:activate",function(b){return a.activate_field(b)}),this.form_field.observe("chosen:open",function(b){return a.container_mousedown(b)}),this.form_field.observe("chosen:close",function(b){return a.input_blur(b)}),this.search_field.observe("blur",function(b){return a.input_blur(b)}),this.search_field.observe("keyup",function(b){return a.keyup_checker(b)}),this.search_field.observe("keydown",function(b){return a.keydown_checker(b)}),this.search_field.observe("focus",function(b){return a.input_focus(b)}),this.search_field.observe("cut",function(b){return a.clipboard_event_checker(b)}),this.search_field.observe("paste",function(b){return a.clipboard_event_checker(b)}),this.is_multiple?this.search_choices.observe("click",function(b){return a.choices_click(b)}):this.container.observe("click",function(a){return a.preventDefault()})},Chosen.prototype.destroy=function(){return this.container.ownerDocument.stopObserving("click",this.click_test_action),this.form_field.stopObserving(),this.container.stopObserving(),this.search_results.stopObserving(),this.search_field.stopObserving(),null!=this.form_field_label&&this.form_field_label.stopObserving(),this.is_multiple?(this.search_choices.stopObserving(),this.container.select(".search-choice-close").each(function(a){return a.stopObserving()})):this.selected_item.stopObserving(),this.search_field.tabIndex&&(this.form_field.tabIndex=this.search_field.tabIndex),this.container.remove(),this.form_field.show()},Chosen.prototype.search_field_disabled=function(){return this.is_disabled=this.form_field.disabled,this.is_disabled?(this.container.addClassName("chosen-disabled"),this.search_field.disabled=!0,this.is_multiple||this.selected_item.stopObserving("focus",this.activate_action),this.close_field()):(this.container.removeClassName("chosen-disabled"),this.search_field.disabled=!1,this.is_multiple?void 0:this.selected_item.observe("focus",this.activate_action))},Chosen.prototype.container_mousedown=function(a){return this.is_disabled||(a&&"mousedown"===a.type&&!this.results_showing&&a.stop(),null!=a&&a.target.hasClassName("search-choice-close"))?void 0:(this.active_field?this.is_multiple||!a||a.target!==this.selected_item&&!a.target.up("a.chosen-single")||this.results_toggle():(this.is_multiple&&this.search_field.clear(),this.container.ownerDocument.observe("click",this.click_test_action),this.results_show()),this.activate_field())},Chosen.prototype.container_mouseup=function(a){return"ABBR"!==a.target.nodeName||this.is_disabled?void 0:this.results_reset(a)},Chosen.prototype.search_results_mousewheel=function(a){var b;return b=-a.wheelDelta||a.detail,null!=b?(a.preventDefault(),"DOMMouseScroll"===a.type&&(b=40*b),this.search_results.scrollTop=b+this.search_results.scrollTop):void 0},Chosen.prototype.blur_test=function(){return!this.active_field&&this.container.hasClassName("chosen-container-active")?this.close_field():void 0},Chosen.prototype.close_field=function(){return this.container.ownerDocument.stopObserving("click",this.click_test_action),this.active_field=!1,this.results_hide(),this.container.removeClassName("chosen-container-active"),this.clear_backstroke(),this.show_search_field_default(),this.search_field_scale()},Chosen.prototype.activate_field=function(){return this.container.addClassName("chosen-container-active"),this.active_field=!0,this.search_field.value=this.search_field.value,this.search_field.focus()},Chosen.prototype.test_active_click=function(a){return a.target.up(".chosen-container")===this.container?this.active_field=!0:this.close_field()},Chosen.prototype.results_build=function(){return this.parsing=!0,this.selected_option_count=null,this.results_data=SelectParser.select_to_array(this.form_field),this.is_multiple?this.search_choices.select("li.search-choice").invoke("remove"):this.is_multiple||(this.single_set_selected_text(),this.disable_search||this.form_field.options.length<=this.disable_search_threshold?(this.search_field.readOnly=!0,this.container.addClassName("chosen-container-single-nosearch")):(this.search_field.readOnly=!1,this.container.removeClassName("chosen-container-single-nosearch"))),this.update_results_content(this.results_option_build({first:!0})),this.search_field_disabled(),this.show_search_field_default(),this.search_field_scale(),this.parsing=!1},Chosen.prototype.result_do_highlight=function(a){var b,c,d,e,f;return this.result_clear_highlight(),this.result_highlight=a,this.result_highlight.addClassName("highlighted"),d=parseInt(this.search_results.getStyle("maxHeight"),10),f=this.search_results.scrollTop,e=d+f,c=this.result_highlight.positionedOffset().top,b=c+this.result_highlight.getHeight(),b>=e?this.search_results.scrollTop=b-d>0?b-d:0:f>c?this.search_results.scrollTop=c:void 0},Chosen.prototype.result_clear_highlight=function(){return this.result_highlight&&this.result_highlight.removeClassName("highlighted"),this.result_highlight=null},Chosen.prototype.results_show=function(){return this.is_multiple&&this.max_selected_options<=this.choices_count()?(this.form_field.fire("chosen:maxselected",{chosen:this}),!1):(this.container.addClassName("chosen-with-drop"),this.results_showing=!0,this.search_field.focus(),this.search_field.value=this.search_field.value,this.winnow_results(),this.form_field.fire("chosen:showing_dropdown",{chosen:this}))},Chosen.prototype.update_results_content=function(a){return this.search_results.update(a)},Chosen.prototype.results_hide=function(){return this.results_showing&&(this.result_clear_highlight(),this.container.removeClassName("chosen-with-drop"),this.form_field.fire("chosen:hiding_dropdown",{chosen:this})),this.results_showing=!1},Chosen.prototype.set_tab_index=function(){var a;return this.form_field.tabIndex?(a=this.form_field.tabIndex,this.form_field.tabIndex=-1,this.search_field.tabIndex=a):void 0},Chosen.prototype.set_label_behavior=function(){var a=this;return this.form_field_label=this.form_field.up("label"),null==this.form_field_label&&(this.form_field_label=$$("label[for='"+this.form_field.id+"']").first()),null!=this.form_field_label?this.form_field_label.observe("click",function(b){return a.is_multiple?a.container_mousedown(b):a.activate_field()}):void 0},Chosen.prototype.show_search_field_default=function(){return this.is_multiple&&this.choices_count()<1&&!this.active_field?(this.search_field.value=this.default_text,this.search_field.addClassName("default")):(this.search_field.value="",this.search_field.removeClassName("default"))},Chosen.prototype.search_results_mouseup=function(a){var b;return b=a.target.hasClassName("active-result")?a.target:a.target.up(".active-result"),b?(this.result_highlight=b,this.result_select(a),this.search_field.focus()):void 0},Chosen.prototype.search_results_mouseover=function(a){var b;return b=a.target.hasClassName("active-result")?a.target:a.target.up(".active-result"),b?this.result_do_highlight(b):void 0},Chosen.prototype.search_results_mouseout=function(a){return a.target.hasClassName("active-result")||a.target.up(".active-result")?this.result_clear_highlight():void 0},Chosen.prototype.choice_build=function(a){var b,c,d=this;return b=new Element("li",{"class":"search-choice"}).update(""+a.html+""),a.disabled?b.addClassName("search-choice-disabled"):(c=new Element("a",{href:"#","class":"search-choice-close",rel:a.array_index}),c.observe("click",function(a){return d.choice_destroy_link_click(a)}),b.insert(c)),this.search_container.insert({before:b})},Chosen.prototype.choice_destroy_link_click=function(a){return a.preventDefault(),a.stopPropagation(),this.is_disabled?void 0:this.choice_destroy(a.target)},Chosen.prototype.choice_destroy=function(a){return this.result_deselect(a.readAttribute("rel"))?(this.show_search_field_default(),this.is_multiple&&this.choices_count()>0&&this.search_field.value.length<1&&this.results_hide(),a.up("li").remove(),this.search_field_scale()):void 0},Chosen.prototype.results_reset=function(){return this.reset_single_select_options(),this.form_field.options[0].selected=!0,this.single_set_selected_text(),this.show_search_field_default(),this.results_reset_cleanup(),"function"==typeof Event.simulate&&this.form_field.simulate("change"),this.active_field?this.results_hide():void 0},Chosen.prototype.results_reset_cleanup=function(){var a;return this.current_selectedIndex=this.form_field.selectedIndex,a=this.selected_item.down("abbr"),a?a.remove():void 0},Chosen.prototype.result_select=function(a){var b,c;return this.result_highlight?(b=this.result_highlight,this.result_clear_highlight(),this.is_multiple&&this.max_selected_options<=this.choices_count()?(this.form_field.fire("chosen:maxselected",{chosen:this}),!1):(this.is_multiple?b.removeClassName("active-result"):this.reset_single_select_options(),b.addClassName("result-selected"),c=this.results_data[b.getAttribute("data-option-array-index")],c.selected=!0,this.form_field.options[c.options_index].selected=!0,this.selected_option_count=null,this.is_multiple?this.choice_build(c):this.single_set_selected_text(c.text),(a.metaKey||a.ctrlKey)&&this.is_multiple||this.results_hide(),this.search_field.value="","function"!=typeof Event.simulate||!this.is_multiple&&this.form_field.selectedIndex===this.current_selectedIndex||this.form_field.simulate("change"),this.current_selectedIndex=this.form_field.selectedIndex,this.search_field_scale())):void 0},Chosen.prototype.single_set_selected_text=function(a){return null==a&&(a=this.default_text),a===this.default_text?this.selected_item.addClassName("chosen-default"):(this.single_deselect_control_build(),this.selected_item.removeClassName("chosen-default")),this.selected_item.down("span").update(a)},Chosen.prototype.result_deselect=function(a){var b;return b=this.results_data[a],this.form_field.options[b.options_index].disabled?!1:(b.selected=!1,this.form_field.options[b.options_index].selected=!1,this.selected_option_count=null,this.result_clear_highlight(),this.results_showing&&this.winnow_results(),"function"==typeof Event.simulate&&this.form_field.simulate("change"),this.search_field_scale(),!0)},Chosen.prototype.single_deselect_control_build=function(){return this.allow_single_deselect?(this.selected_item.down("abbr")||this.selected_item.down("span").insert({after:''}),this.selected_item.addClassName("chosen-single-with-deselect")):void 0},Chosen.prototype.get_search_text=function(){return this.search_field.value===this.default_text?"":this.search_field.value.strip().escapeHTML()},Chosen.prototype.winnow_results_set_highlight=function(){var a;return this.is_multiple||(a=this.search_results.down(".result-selected.active-result")),null==a&&(a=this.search_results.down(".active-result")),null!=a?this.result_do_highlight(a):void 0},Chosen.prototype.no_results=function(a){return this.search_results.insert(this.no_results_temp.evaluate({terms:a})),this.form_field.fire("chosen:no_results",{chosen:this})},Chosen.prototype.no_results_clear=function(){var a,b;for(a=null,b=[];a=this.search_results.down(".no-results");)b.push(a.remove());return b},Chosen.prototype.keydown_arrow=function(){var a;return this.results_showing&&this.result_highlight?(a=this.result_highlight.next(".active-result"))?this.result_do_highlight(a):void 0:this.results_show()},Chosen.prototype.keyup_arrow=function(){var a,b,c;return this.results_showing||this.is_multiple?this.result_highlight?(c=this.result_highlight.previousSiblings(),a=this.search_results.select("li.active-result"),b=c.intersect(a),b.length?this.result_do_highlight(b.first()):(this.choices_count()>0&&this.results_hide(),this.result_clear_highlight())):void 0:this.results_show()},Chosen.prototype.keydown_backstroke=function(){var a;return this.pending_backstroke?(this.choice_destroy(this.pending_backstroke.down("a")),this.clear_backstroke()):(a=this.search_container.siblings().last(),a&&a.hasClassName("search-choice")&&!a.hasClassName("search-choice-disabled")?(this.pending_backstroke=a,this.pending_backstroke&&this.pending_backstroke.addClassName("search-choice-focus"),this.single_backstroke_delete?this.keydown_backstroke():this.pending_backstroke.addClassName("search-choice-focus")):void 0)},Chosen.prototype.clear_backstroke=function(){return this.pending_backstroke&&this.pending_backstroke.removeClassName("search-choice-focus"),this.pending_backstroke=null},Chosen.prototype.keydown_checker=function(a){var b,c;switch(b=null!=(c=a.which)?c:a.keyCode,this.search_field_scale(),8!==b&&this.pending_backstroke&&this.clear_backstroke(),b){case 8:this.backstroke_length=this.search_field.value.length;break;case 9:this.results_showing&&!this.is_multiple&&this.result_select(a),this.mouse_on_container=!1;break;case 13:a.preventDefault();break;case 38:a.preventDefault(),this.keyup_arrow();break;case 40:a.preventDefault(),this.keydown_arrow()}},Chosen.prototype.search_field_scale=function(){var a,b,c,d,e,f,g,h,i;if(this.is_multiple){for(c=0,g=0,e="position:absolute; left: -1000px; top: -1000px; display:none;",f=["font-size","font-style","font-weight","font-family","line-height","text-transform","letter-spacing"],h=0,i=f.length;i>h;h++)d=f[h],e+=d+":"+this.search_field.getStyle(d)+";";return a=new Element("div",{style:e}).update(this.search_field.value.escapeHTML()),document.body.appendChild(a),g=Element.measure(a,"width")+25,a.remove(),b=this.container.getWidth(),g>b-10&&(g=b-10),this.search_field.setStyle({width:g+"px"})}},Chosen}(AbstractChosen)}.call(this); -------------------------------------------------------------------------------- /bower_components/chosen_v1.1.0/chosen.jquery.js: -------------------------------------------------------------------------------- 1 | /*! 2 | Chosen, a Select Box Enhancer for jQuery and Prototype 3 | by Patrick Filler for Harvest, http://getharvest.com 4 | 5 | Version 1.1.0 6 | Full source at https://github.com/harvesthq/chosen 7 | Copyright (c) 2011 Harvest http://getharvest.com 8 | 9 | MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md 10 | This file is generated by `grunt build`, do not edit it by hand. 11 | */ 12 | 13 | (function() { 14 | var $, AbstractChosen, Chosen, SelectParser, _ref, 15 | __hasProp = {}.hasOwnProperty, 16 | __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; 17 | 18 | SelectParser = (function() { 19 | function SelectParser() { 20 | this.options_index = 0; 21 | this.parsed = []; 22 | } 23 | 24 | SelectParser.prototype.add_node = function(child) { 25 | if (child.nodeName.toUpperCase() === "OPTGROUP") { 26 | return this.add_group(child); 27 | } else { 28 | return this.add_option(child); 29 | } 30 | }; 31 | 32 | SelectParser.prototype.add_group = function(group) { 33 | var group_position, option, _i, _len, _ref, _results; 34 | group_position = this.parsed.length; 35 | this.parsed.push({ 36 | array_index: group_position, 37 | group: true, 38 | label: this.escapeExpression(group.label), 39 | children: 0, 40 | disabled: group.disabled 41 | }); 42 | _ref = group.childNodes; 43 | _results = []; 44 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { 45 | option = _ref[_i]; 46 | _results.push(this.add_option(option, group_position, group.disabled)); 47 | } 48 | return _results; 49 | }; 50 | 51 | SelectParser.prototype.add_option = function(option, group_position, group_disabled) { 52 | if (option.nodeName.toUpperCase() === "OPTION") { 53 | if (option.text !== "") { 54 | if (group_position != null) { 55 | this.parsed[group_position].children += 1; 56 | } 57 | this.parsed.push({ 58 | array_index: this.parsed.length, 59 | options_index: this.options_index, 60 | value: option.value, 61 | text: option.text, 62 | html: option.innerHTML, 63 | selected: option.selected, 64 | disabled: group_disabled === true ? group_disabled : option.disabled, 65 | group_array_index: group_position, 66 | classes: option.className, 67 | style: option.style.cssText 68 | }); 69 | } else { 70 | this.parsed.push({ 71 | array_index: this.parsed.length, 72 | options_index: this.options_index, 73 | empty: true 74 | }); 75 | } 76 | return this.options_index += 1; 77 | } 78 | }; 79 | 80 | SelectParser.prototype.escapeExpression = function(text) { 81 | var map, unsafe_chars; 82 | if ((text == null) || text === false) { 83 | return ""; 84 | } 85 | if (!/[\&\<\>\"\'\`]/.test(text)) { 86 | return text; 87 | } 88 | map = { 89 | "<": "<", 90 | ">": ">", 91 | '"': """, 92 | "'": "'", 93 | "`": "`" 94 | }; 95 | unsafe_chars = /&(?!\w+;)|[\<\>\"\'\`]/g; 96 | return text.replace(unsafe_chars, function(chr) { 97 | return map[chr] || "&"; 98 | }); 99 | }; 100 | 101 | return SelectParser; 102 | 103 | })(); 104 | 105 | SelectParser.select_to_array = function(select) { 106 | var child, parser, _i, _len, _ref; 107 | parser = new SelectParser(); 108 | _ref = select.childNodes; 109 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { 110 | child = _ref[_i]; 111 | parser.add_node(child); 112 | } 113 | return parser.parsed; 114 | }; 115 | 116 | AbstractChosen = (function() { 117 | function AbstractChosen(form_field, options) { 118 | this.form_field = form_field; 119 | this.options = options != null ? options : {}; 120 | if (!AbstractChosen.browser_is_supported()) { 121 | return; 122 | } 123 | this.is_multiple = this.form_field.multiple; 124 | this.set_default_text(); 125 | this.set_default_values(); 126 | this.setup(); 127 | this.set_up_html(); 128 | this.register_observers(); 129 | } 130 | 131 | AbstractChosen.prototype.set_default_values = function() { 132 | var _this = this; 133 | this.click_test_action = function(evt) { 134 | return _this.test_active_click(evt); 135 | }; 136 | this.activate_action = function(evt) { 137 | return _this.activate_field(evt); 138 | }; 139 | this.active_field = false; 140 | this.mouse_on_container = false; 141 | this.results_showing = false; 142 | this.result_highlighted = null; 143 | this.allow_single_deselect = (this.options.allow_single_deselect != null) && (this.form_field.options[0] != null) && this.form_field.options[0].text === "" ? this.options.allow_single_deselect : false; 144 | this.disable_search_threshold = this.options.disable_search_threshold || 0; 145 | this.disable_search = this.options.disable_search || false; 146 | this.enable_split_word_search = this.options.enable_split_word_search != null ? this.options.enable_split_word_search : true; 147 | this.group_search = this.options.group_search != null ? this.options.group_search : true; 148 | this.search_contains = this.options.search_contains || false; 149 | this.single_backstroke_delete = this.options.single_backstroke_delete != null ? this.options.single_backstroke_delete : true; 150 | this.max_selected_options = this.options.max_selected_options || Infinity; 151 | this.inherit_select_classes = this.options.inherit_select_classes || false; 152 | this.display_selected_options = this.options.display_selected_options != null ? this.options.display_selected_options : true; 153 | return this.display_disabled_options = this.options.display_disabled_options != null ? this.options.display_disabled_options : true; 154 | }; 155 | 156 | AbstractChosen.prototype.set_default_text = function() { 157 | if (this.form_field.getAttribute("data-placeholder")) { 158 | this.default_text = this.form_field.getAttribute("data-placeholder"); 159 | } else if (this.is_multiple) { 160 | this.default_text = this.options.placeholder_text_multiple || this.options.placeholder_text || AbstractChosen.default_multiple_text; 161 | } else { 162 | this.default_text = this.options.placeholder_text_single || this.options.placeholder_text || AbstractChosen.default_single_text; 163 | } 164 | return this.results_none_found = this.form_field.getAttribute("data-no_results_text") || this.options.no_results_text || AbstractChosen.default_no_result_text; 165 | }; 166 | 167 | AbstractChosen.prototype.mouse_enter = function() { 168 | return this.mouse_on_container = true; 169 | }; 170 | 171 | AbstractChosen.prototype.mouse_leave = function() { 172 | return this.mouse_on_container = false; 173 | }; 174 | 175 | AbstractChosen.prototype.input_focus = function(evt) { 176 | var _this = this; 177 | if (this.is_multiple) { 178 | if (!this.active_field) { 179 | return setTimeout((function() { 180 | return _this.container_mousedown(); 181 | }), 50); 182 | } 183 | } else { 184 | if (!this.active_field) { 185 | return this.activate_field(); 186 | } 187 | } 188 | }; 189 | 190 | AbstractChosen.prototype.input_blur = function(evt) { 191 | var _this = this; 192 | if (!this.mouse_on_container) { 193 | this.active_field = false; 194 | return setTimeout((function() { 195 | return _this.blur_test(); 196 | }), 100); 197 | } 198 | }; 199 | 200 | AbstractChosen.prototype.results_option_build = function(options) { 201 | var content, data, _i, _len, _ref; 202 | content = ''; 203 | _ref = this.results_data; 204 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { 205 | data = _ref[_i]; 206 | if (data.group) { 207 | content += this.result_add_group(data); 208 | } else { 209 | content += this.result_add_option(data); 210 | } 211 | if (options != null ? options.first : void 0) { 212 | if (data.selected && this.is_multiple) { 213 | this.choice_build(data); 214 | } else if (data.selected && !this.is_multiple) { 215 | this.single_set_selected_text(data.text); 216 | } 217 | } 218 | } 219 | return content; 220 | }; 221 | 222 | AbstractChosen.prototype.result_add_option = function(option) { 223 | var classes, option_el; 224 | if (!option.search_match) { 225 | return ''; 226 | } 227 | if (!this.include_option_in_results(option)) { 228 | return ''; 229 | } 230 | classes = []; 231 | if (!option.disabled && !(option.selected && this.is_multiple)) { 232 | classes.push("active-result"); 233 | } 234 | if (option.disabled && !(option.selected && this.is_multiple)) { 235 | classes.push("disabled-result"); 236 | } 237 | if (option.selected) { 238 | classes.push("result-selected"); 239 | } 240 | if (option.group_array_index != null) { 241 | classes.push("group-option"); 242 | } 243 | if (option.classes !== "") { 244 | classes.push(option.classes); 245 | } 246 | option_el = document.createElement("li"); 247 | option_el.className = classes.join(" "); 248 | option_el.style.cssText = option.style; 249 | option_el.setAttribute("data-option-array-index", option.array_index); 250 | option_el.innerHTML = option.search_text; 251 | return this.outerHTML(option_el); 252 | }; 253 | 254 | AbstractChosen.prototype.result_add_group = function(group) { 255 | var group_el; 256 | if (!(group.search_match || group.group_match)) { 257 | return ''; 258 | } 259 | if (!(group.active_options > 0)) { 260 | return ''; 261 | } 262 | group_el = document.createElement("li"); 263 | group_el.className = "group-result"; 264 | group_el.innerHTML = group.search_text; 265 | return this.outerHTML(group_el); 266 | }; 267 | 268 | AbstractChosen.prototype.results_update_field = function() { 269 | this.set_default_text(); 270 | if (!this.is_multiple) { 271 | this.results_reset_cleanup(); 272 | } 273 | this.result_clear_highlight(); 274 | this.results_build(); 275 | if (this.results_showing) { 276 | return this.winnow_results(); 277 | } 278 | }; 279 | 280 | AbstractChosen.prototype.reset_single_select_options = function() { 281 | var result, _i, _len, _ref, _results; 282 | _ref = this.results_data; 283 | _results = []; 284 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { 285 | result = _ref[_i]; 286 | if (result.selected) { 287 | _results.push(result.selected = false); 288 | } else { 289 | _results.push(void 0); 290 | } 291 | } 292 | return _results; 293 | }; 294 | 295 | AbstractChosen.prototype.results_toggle = function() { 296 | if (this.results_showing) { 297 | return this.results_hide(); 298 | } else { 299 | return this.results_show(); 300 | } 301 | }; 302 | 303 | AbstractChosen.prototype.results_search = function(evt) { 304 | if (this.results_showing) { 305 | return this.winnow_results(); 306 | } else { 307 | return this.results_show(); 308 | } 309 | }; 310 | 311 | AbstractChosen.prototype.winnow_results = function() { 312 | var escapedSearchText, option, regex, regexAnchor, results, results_group, searchText, startpos, text, zregex, _i, _len, _ref; 313 | this.no_results_clear(); 314 | results = 0; 315 | searchText = this.get_search_text(); 316 | escapedSearchText = searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); 317 | regexAnchor = this.search_contains ? "" : "^"; 318 | regex = new RegExp(regexAnchor + escapedSearchText, 'i'); 319 | zregex = new RegExp(escapedSearchText, 'i'); 320 | _ref = this.results_data; 321 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { 322 | option = _ref[_i]; 323 | option.search_match = false; 324 | results_group = null; 325 | if (this.include_option_in_results(option)) { 326 | if (option.group) { 327 | option.group_match = false; 328 | option.active_options = 0; 329 | } 330 | if ((option.group_array_index != null) && this.results_data[option.group_array_index]) { 331 | results_group = this.results_data[option.group_array_index]; 332 | if (results_group.active_options === 0 && results_group.search_match) { 333 | results += 1; 334 | } 335 | results_group.active_options += 1; 336 | } 337 | if (!(option.group && !this.group_search)) { 338 | option.search_text = option.group ? option.label : option.html; 339 | option.search_match = this.search_string_match(option.search_text, regex); 340 | if (option.search_match && !option.group) { 341 | results += 1; 342 | } 343 | if (option.search_match) { 344 | if (searchText.length) { 345 | startpos = option.search_text.search(zregex); 346 | text = option.search_text.substr(0, startpos + searchText.length) + '
          ' + option.search_text.substr(startpos + searchText.length); 347 | option.search_text = text.substr(0, startpos) + '' + text.substr(startpos); 348 | } 349 | if (results_group != null) { 350 | results_group.group_match = true; 351 | } 352 | } else if ((option.group_array_index != null) && this.results_data[option.group_array_index].search_match) { 353 | option.search_match = true; 354 | } 355 | } 356 | } 357 | } 358 | this.result_clear_highlight(); 359 | if (results < 1 && searchText.length) { 360 | this.update_results_content(""); 361 | return this.no_results(searchText); 362 | } else { 363 | this.update_results_content(this.results_option_build()); 364 | return this.winnow_results_set_highlight(); 365 | } 366 | }; 367 | 368 | AbstractChosen.prototype.search_string_match = function(search_string, regex) { 369 | var part, parts, _i, _len; 370 | if (regex.test(search_string)) { 371 | return true; 372 | } else if (this.enable_split_word_search && (search_string.indexOf(" ") >= 0 || search_string.indexOf("[") === 0)) { 373 | parts = search_string.replace(/\[|\]/g, "").split(" "); 374 | if (parts.length) { 375 | for (_i = 0, _len = parts.length; _i < _len; _i++) { 376 | part = parts[_i]; 377 | if (regex.test(part)) { 378 | return true; 379 | } 380 | } 381 | } 382 | } 383 | }; 384 | 385 | AbstractChosen.prototype.choices_count = function() { 386 | var option, _i, _len, _ref; 387 | if (this.selected_option_count != null) { 388 | return this.selected_option_count; 389 | } 390 | this.selected_option_count = 0; 391 | _ref = this.form_field.options; 392 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { 393 | option = _ref[_i]; 394 | if (option.selected) { 395 | this.selected_option_count += 1; 396 | } 397 | } 398 | return this.selected_option_count; 399 | }; 400 | 401 | AbstractChosen.prototype.choices_click = function(evt) { 402 | evt.preventDefault(); 403 | if (!(this.results_showing || this.is_disabled)) { 404 | return this.results_show(); 405 | } 406 | }; 407 | 408 | AbstractChosen.prototype.keyup_checker = function(evt) { 409 | var stroke, _ref; 410 | stroke = (_ref = evt.which) != null ? _ref : evt.keyCode; 411 | this.search_field_scale(); 412 | switch (stroke) { 413 | case 8: 414 | if (this.is_multiple && this.backstroke_length < 1 && this.choices_count() > 0) { 415 | return this.keydown_backstroke(); 416 | } else if (!this.pending_backstroke) { 417 | this.result_clear_highlight(); 418 | return this.results_search(); 419 | } 420 | break; 421 | case 13: 422 | evt.preventDefault(); 423 | if (this.results_showing) { 424 | return this.result_select(evt); 425 | } 426 | break; 427 | case 27: 428 | if (this.results_showing) { 429 | this.results_hide(); 430 | } 431 | return true; 432 | case 9: 433 | case 38: 434 | case 40: 435 | case 16: 436 | case 91: 437 | case 17: 438 | break; 439 | default: 440 | return this.results_search(); 441 | } 442 | }; 443 | 444 | AbstractChosen.prototype.clipboard_event_checker = function(evt) { 445 | var _this = this; 446 | return setTimeout((function() { 447 | return _this.results_search(); 448 | }), 50); 449 | }; 450 | 451 | AbstractChosen.prototype.container_width = function() { 452 | if (this.options.width != null) { 453 | return this.options.width; 454 | } else { 455 | return "" + this.form_field.offsetWidth + "px"; 456 | } 457 | }; 458 | 459 | AbstractChosen.prototype.include_option_in_results = function(option) { 460 | if (this.is_multiple && (!this.display_selected_options && option.selected)) { 461 | return false; 462 | } 463 | if (!this.display_disabled_options && option.disabled) { 464 | return false; 465 | } 466 | if (option.empty) { 467 | return false; 468 | } 469 | return true; 470 | }; 471 | 472 | AbstractChosen.prototype.search_results_touchstart = function(evt) { 473 | this.touch_started = true; 474 | return this.search_results_mouseover(evt); 475 | }; 476 | 477 | AbstractChosen.prototype.search_results_touchmove = function(evt) { 478 | this.touch_started = false; 479 | return this.search_results_mouseout(evt); 480 | }; 481 | 482 | AbstractChosen.prototype.search_results_touchend = function(evt) { 483 | if (this.touch_started) { 484 | return this.search_results_mouseup(evt); 485 | } 486 | }; 487 | 488 | AbstractChosen.prototype.outerHTML = function(element) { 489 | var tmp; 490 | if (element.outerHTML) { 491 | return element.outerHTML; 492 | } 493 | tmp = document.createElement("div"); 494 | tmp.appendChild(element); 495 | return tmp.innerHTML; 496 | }; 497 | 498 | AbstractChosen.browser_is_supported = function() { 499 | if (window.navigator.appName === "Microsoft Internet Explorer") { 500 | return document.documentMode >= 8; 501 | } 502 | if (/iP(od|hone)/i.test(window.navigator.userAgent)) { 503 | return false; 504 | } 505 | if (/Android/i.test(window.navigator.userAgent)) { 506 | if (/Mobile/i.test(window.navigator.userAgent)) { 507 | return false; 508 | } 509 | } 510 | return true; 511 | }; 512 | 513 | AbstractChosen.default_multiple_text = "Select Some Options"; 514 | 515 | AbstractChosen.default_single_text = "Select an Option"; 516 | 517 | AbstractChosen.default_no_result_text = "No results match"; 518 | 519 | return AbstractChosen; 520 | 521 | })(); 522 | 523 | $ = jQuery; 524 | 525 | $.fn.extend({ 526 | chosen: function(options) { 527 | if (!AbstractChosen.browser_is_supported()) { 528 | return this; 529 | } 530 | return this.each(function(input_field) { 531 | var $this, chosen; 532 | $this = $(this); 533 | chosen = $this.data('chosen'); 534 | if (options === 'destroy' && chosen) { 535 | chosen.destroy(); 536 | } else if (!chosen) { 537 | $this.data('chosen', new Chosen(this, options)); 538 | } 539 | }); 540 | } 541 | }); 542 | 543 | Chosen = (function(_super) { 544 | __extends(Chosen, _super); 545 | 546 | function Chosen() { 547 | _ref = Chosen.__super__.constructor.apply(this, arguments); 548 | return _ref; 549 | } 550 | 551 | Chosen.prototype.setup = function() { 552 | this.form_field_jq = $(this.form_field); 553 | this.current_selectedIndex = this.form_field.selectedIndex; 554 | return this.is_rtl = this.form_field_jq.hasClass("chosen-rtl"); 555 | }; 556 | 557 | Chosen.prototype.set_up_html = function() { 558 | var container_classes, container_props; 559 | container_classes = ["chosen-container"]; 560 | container_classes.push("chosen-container-" + (this.is_multiple ? "multi" : "single")); 561 | if (this.inherit_select_classes && this.form_field.className) { 562 | container_classes.push(this.form_field.className); 563 | } 564 | if (this.is_rtl) { 565 | container_classes.push("chosen-rtl"); 566 | } 567 | container_props = { 568 | 'class': container_classes.join(' '), 569 | 'style': "width: " + (this.container_width()) + ";", 570 | 'title': this.form_field.title 571 | }; 572 | if (this.form_field.id.length) { 573 | container_props.id = this.form_field.id.replace(/[^\w]/g, '_') + "_chosen"; 574 | } 575 | this.container = $("
          ", container_props); 576 | if (this.is_multiple) { 577 | this.container.html('
            '); 578 | } else { 579 | this.container.html('' + this.default_text + '
              '); 580 | } 581 | this.form_field_jq.hide().after(this.container); 582 | this.dropdown = this.container.find('div.chosen-drop').first(); 583 | this.search_field = this.container.find('input').first(); 584 | this.search_results = this.container.find('ul.chosen-results').first(); 585 | this.search_field_scale(); 586 | this.search_no_results = this.container.find('li.no-results').first(); 587 | if (this.is_multiple) { 588 | this.search_choices = this.container.find('ul.chosen-choices').first(); 589 | this.search_container = this.container.find('li.search-field').first(); 590 | } else { 591 | this.search_container = this.container.find('div.chosen-search').first(); 592 | this.selected_item = this.container.find('.chosen-single').first(); 593 | } 594 | this.results_build(); 595 | this.set_tab_index(); 596 | this.set_label_behavior(); 597 | return this.form_field_jq.trigger("chosen:ready", { 598 | chosen: this 599 | }); 600 | }; 601 | 602 | Chosen.prototype.register_observers = function() { 603 | var _this = this; 604 | this.container.bind('mousedown.chosen', function(evt) { 605 | _this.container_mousedown(evt); 606 | }); 607 | this.container.bind('mouseup.chosen', function(evt) { 608 | _this.container_mouseup(evt); 609 | }); 610 | this.container.bind('mouseenter.chosen', function(evt) { 611 | _this.mouse_enter(evt); 612 | }); 613 | this.container.bind('mouseleave.chosen', function(evt) { 614 | _this.mouse_leave(evt); 615 | }); 616 | this.search_results.bind('mouseup.chosen', function(evt) { 617 | _this.search_results_mouseup(evt); 618 | }); 619 | this.search_results.bind('mouseover.chosen', function(evt) { 620 | _this.search_results_mouseover(evt); 621 | }); 622 | this.search_results.bind('mouseout.chosen', function(evt) { 623 | _this.search_results_mouseout(evt); 624 | }); 625 | this.search_results.bind('mousewheel.chosen DOMMouseScroll.chosen', function(evt) { 626 | _this.search_results_mousewheel(evt); 627 | }); 628 | this.search_results.bind('touchstart.chosen', function(evt) { 629 | _this.search_results_touchstart(evt); 630 | }); 631 | this.search_results.bind('touchmove.chosen', function(evt) { 632 | _this.search_results_touchmove(evt); 633 | }); 634 | this.search_results.bind('touchend.chosen', function(evt) { 635 | _this.search_results_touchend(evt); 636 | }); 637 | this.form_field_jq.bind("chosen:updated.chosen", function(evt) { 638 | _this.results_update_field(evt); 639 | }); 640 | this.form_field_jq.bind("chosen:activate.chosen", function(evt) { 641 | _this.activate_field(evt); 642 | }); 643 | this.form_field_jq.bind("chosen:open.chosen", function(evt) { 644 | _this.container_mousedown(evt); 645 | }); 646 | this.form_field_jq.bind("chosen:close.chosen", function(evt) { 647 | _this.input_blur(evt); 648 | }); 649 | this.search_field.bind('blur.chosen', function(evt) { 650 | _this.input_blur(evt); 651 | }); 652 | this.search_field.bind('keyup.chosen', function(evt) { 653 | _this.keyup_checker(evt); 654 | }); 655 | this.search_field.bind('keydown.chosen', function(evt) { 656 | _this.keydown_checker(evt); 657 | }); 658 | this.search_field.bind('focus.chosen', function(evt) { 659 | _this.input_focus(evt); 660 | }); 661 | this.search_field.bind('cut.chosen', function(evt) { 662 | _this.clipboard_event_checker(evt); 663 | }); 664 | this.search_field.bind('paste.chosen', function(evt) { 665 | _this.clipboard_event_checker(evt); 666 | }); 667 | if (this.is_multiple) { 668 | return this.search_choices.bind('click.chosen', function(evt) { 669 | _this.choices_click(evt); 670 | }); 671 | } else { 672 | return this.container.bind('click.chosen', function(evt) { 673 | evt.preventDefault(); 674 | }); 675 | } 676 | }; 677 | 678 | Chosen.prototype.destroy = function() { 679 | $(this.container[0].ownerDocument).unbind("click.chosen", this.click_test_action); 680 | if (this.search_field[0].tabIndex) { 681 | this.form_field_jq[0].tabIndex = this.search_field[0].tabIndex; 682 | } 683 | this.container.remove(); 684 | this.form_field_jq.removeData('chosen'); 685 | return this.form_field_jq.show(); 686 | }; 687 | 688 | Chosen.prototype.search_field_disabled = function() { 689 | this.is_disabled = this.form_field_jq[0].disabled; 690 | if (this.is_disabled) { 691 | this.container.addClass('chosen-disabled'); 692 | this.search_field[0].disabled = true; 693 | if (!this.is_multiple) { 694 | this.selected_item.unbind("focus.chosen", this.activate_action); 695 | } 696 | return this.close_field(); 697 | } else { 698 | this.container.removeClass('chosen-disabled'); 699 | this.search_field[0].disabled = false; 700 | if (!this.is_multiple) { 701 | return this.selected_item.bind("focus.chosen", this.activate_action); 702 | } 703 | } 704 | }; 705 | 706 | Chosen.prototype.container_mousedown = function(evt) { 707 | if (!this.is_disabled) { 708 | if (evt && evt.type === "mousedown" && !this.results_showing) { 709 | evt.preventDefault(); 710 | } 711 | if (!((evt != null) && ($(evt.target)).hasClass("search-choice-close"))) { 712 | if (!this.active_field) { 713 | if (this.is_multiple) { 714 | this.search_field.val(""); 715 | } 716 | $(this.container[0].ownerDocument).bind('click.chosen', this.click_test_action); 717 | this.results_show(); 718 | } else if (!this.is_multiple && evt && (($(evt.target)[0] === this.selected_item[0]) || $(evt.target).parents("a.chosen-single").length)) { 719 | evt.preventDefault(); 720 | this.results_toggle(); 721 | } 722 | return this.activate_field(); 723 | } 724 | } 725 | }; 726 | 727 | Chosen.prototype.container_mouseup = function(evt) { 728 | if (evt.target.nodeName === "ABBR" && !this.is_disabled) { 729 | return this.results_reset(evt); 730 | } 731 | }; 732 | 733 | Chosen.prototype.search_results_mousewheel = function(evt) { 734 | var delta; 735 | if (evt.originalEvent) { 736 | delta = -evt.originalEvent.wheelDelta || evt.originalEvent.detail; 737 | } 738 | if (delta != null) { 739 | evt.preventDefault(); 740 | if (evt.type === 'DOMMouseScroll') { 741 | delta = delta * 40; 742 | } 743 | return this.search_results.scrollTop(delta + this.search_results.scrollTop()); 744 | } 745 | }; 746 | 747 | Chosen.prototype.blur_test = function(evt) { 748 | if (!this.active_field && this.container.hasClass("chosen-container-active")) { 749 | return this.close_field(); 750 | } 751 | }; 752 | 753 | Chosen.prototype.close_field = function() { 754 | $(this.container[0].ownerDocument).unbind("click.chosen", this.click_test_action); 755 | this.active_field = false; 756 | this.results_hide(); 757 | this.container.removeClass("chosen-container-active"); 758 | this.clear_backstroke(); 759 | this.show_search_field_default(); 760 | return this.search_field_scale(); 761 | }; 762 | 763 | Chosen.prototype.activate_field = function() { 764 | this.container.addClass("chosen-container-active"); 765 | this.active_field = true; 766 | this.search_field.val(this.search_field.val()); 767 | return this.search_field.focus(); 768 | }; 769 | 770 | Chosen.prototype.test_active_click = function(evt) { 771 | var active_container; 772 | active_container = $(evt.target).closest('.chosen-container'); 773 | if (active_container.length && this.container[0] === active_container[0]) { 774 | return this.active_field = true; 775 | } else { 776 | return this.close_field(); 777 | } 778 | }; 779 | 780 | Chosen.prototype.results_build = function() { 781 | this.parsing = true; 782 | this.selected_option_count = null; 783 | this.results_data = SelectParser.select_to_array(this.form_field); 784 | if (this.is_multiple) { 785 | this.search_choices.find("li.search-choice").remove(); 786 | } else if (!this.is_multiple) { 787 | this.single_set_selected_text(); 788 | if (this.disable_search || this.form_field.options.length <= this.disable_search_threshold) { 789 | this.search_field[0].readOnly = true; 790 | this.container.addClass("chosen-container-single-nosearch"); 791 | } else { 792 | this.search_field[0].readOnly = false; 793 | this.container.removeClass("chosen-container-single-nosearch"); 794 | } 795 | } 796 | this.update_results_content(this.results_option_build({ 797 | first: true 798 | })); 799 | this.search_field_disabled(); 800 | this.show_search_field_default(); 801 | this.search_field_scale(); 802 | return this.parsing = false; 803 | }; 804 | 805 | Chosen.prototype.result_do_highlight = function(el) { 806 | var high_bottom, high_top, maxHeight, visible_bottom, visible_top; 807 | if (el.length) { 808 | this.result_clear_highlight(); 809 | this.result_highlight = el; 810 | this.result_highlight.addClass("highlighted"); 811 | maxHeight = parseInt(this.search_results.css("maxHeight"), 10); 812 | visible_top = this.search_results.scrollTop(); 813 | visible_bottom = maxHeight + visible_top; 814 | high_top = this.result_highlight.position().top + this.search_results.scrollTop(); 815 | high_bottom = high_top + this.result_highlight.outerHeight(); 816 | if (high_bottom >= visible_bottom) { 817 | return this.search_results.scrollTop((high_bottom - maxHeight) > 0 ? high_bottom - maxHeight : 0); 818 | } else if (high_top < visible_top) { 819 | return this.search_results.scrollTop(high_top); 820 | } 821 | } 822 | }; 823 | 824 | Chosen.prototype.result_clear_highlight = function() { 825 | if (this.result_highlight) { 826 | this.result_highlight.removeClass("highlighted"); 827 | } 828 | return this.result_highlight = null; 829 | }; 830 | 831 | Chosen.prototype.results_show = function() { 832 | if (this.is_multiple && this.max_selected_options <= this.choices_count()) { 833 | this.form_field_jq.trigger("chosen:maxselected", { 834 | chosen: this 835 | }); 836 | return false; 837 | } 838 | this.container.addClass("chosen-with-drop"); 839 | this.results_showing = true; 840 | this.search_field.focus(); 841 | this.search_field.val(this.search_field.val()); 842 | this.winnow_results(); 843 | return this.form_field_jq.trigger("chosen:showing_dropdown", { 844 | chosen: this 845 | }); 846 | }; 847 | 848 | Chosen.prototype.update_results_content = function(content) { 849 | return this.search_results.html(content); 850 | }; 851 | 852 | Chosen.prototype.results_hide = function() { 853 | if (this.results_showing) { 854 | this.result_clear_highlight(); 855 | this.container.removeClass("chosen-with-drop"); 856 | this.form_field_jq.trigger("chosen:hiding_dropdown", { 857 | chosen: this 858 | }); 859 | } 860 | return this.results_showing = false; 861 | }; 862 | 863 | Chosen.prototype.set_tab_index = function(el) { 864 | var ti; 865 | if (this.form_field.tabIndex) { 866 | ti = this.form_field.tabIndex; 867 | this.form_field.tabIndex = -1; 868 | return this.search_field[0].tabIndex = ti; 869 | } 870 | }; 871 | 872 | Chosen.prototype.set_label_behavior = function() { 873 | var _this = this; 874 | this.form_field_label = this.form_field_jq.parents("label"); 875 | if (!this.form_field_label.length && this.form_field.id.length) { 876 | this.form_field_label = $("label[for='" + this.form_field.id + "']"); 877 | } 878 | if (this.form_field_label.length > 0) { 879 | return this.form_field_label.bind('click.chosen', function(evt) { 880 | if (_this.is_multiple) { 881 | return _this.container_mousedown(evt); 882 | } else { 883 | return _this.activate_field(); 884 | } 885 | }); 886 | } 887 | }; 888 | 889 | Chosen.prototype.show_search_field_default = function() { 890 | if (this.is_multiple && this.choices_count() < 1 && !this.active_field) { 891 | this.search_field.val(this.default_text); 892 | return this.search_field.addClass("default"); 893 | } else { 894 | this.search_field.val(""); 895 | return this.search_field.removeClass("default"); 896 | } 897 | }; 898 | 899 | Chosen.prototype.search_results_mouseup = function(evt) { 900 | var target; 901 | target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first(); 902 | if (target.length) { 903 | this.result_highlight = target; 904 | this.result_select(evt); 905 | return this.search_field.focus(); 906 | } 907 | }; 908 | 909 | Chosen.prototype.search_results_mouseover = function(evt) { 910 | var target; 911 | target = $(evt.target).hasClass("active-result") ? $(evt.target) : $(evt.target).parents(".active-result").first(); 912 | if (target) { 913 | return this.result_do_highlight(target); 914 | } 915 | }; 916 | 917 | Chosen.prototype.search_results_mouseout = function(evt) { 918 | if ($(evt.target).hasClass("active-result" || $(evt.target).parents('.active-result').first())) { 919 | return this.result_clear_highlight(); 920 | } 921 | }; 922 | 923 | Chosen.prototype.choice_build = function(item) { 924 | var choice, close_link, 925 | _this = this; 926 | choice = $('
            • ', { 927 | "class": "search-choice" 928 | }).html("" + item.html + ""); 929 | if (item.disabled) { 930 | choice.addClass('search-choice-disabled'); 931 | } else { 932 | close_link = $('', { 933 | "class": 'search-choice-close', 934 | 'data-option-array-index': item.array_index 935 | }); 936 | close_link.bind('click.chosen', function(evt) { 937 | return _this.choice_destroy_link_click(evt); 938 | }); 939 | choice.append(close_link); 940 | } 941 | return this.search_container.before(choice); 942 | }; 943 | 944 | Chosen.prototype.choice_destroy_link_click = function(evt) { 945 | evt.preventDefault(); 946 | evt.stopPropagation(); 947 | if (!this.is_disabled) { 948 | return this.choice_destroy($(evt.target)); 949 | } 950 | }; 951 | 952 | Chosen.prototype.choice_destroy = function(link) { 953 | if (this.result_deselect(link[0].getAttribute("data-option-array-index"))) { 954 | this.show_search_field_default(); 955 | if (this.is_multiple && this.choices_count() > 0 && this.search_field.val().length < 1) { 956 | this.results_hide(); 957 | } 958 | link.parents('li').first().remove(); 959 | return this.search_field_scale(); 960 | } 961 | }; 962 | 963 | Chosen.prototype.results_reset = function() { 964 | this.reset_single_select_options(); 965 | this.form_field.options[0].selected = true; 966 | this.single_set_selected_text(); 967 | this.show_search_field_default(); 968 | this.results_reset_cleanup(); 969 | this.form_field_jq.trigger("change"); 970 | if (this.active_field) { 971 | return this.results_hide(); 972 | } 973 | }; 974 | 975 | Chosen.prototype.results_reset_cleanup = function() { 976 | this.current_selectedIndex = this.form_field.selectedIndex; 977 | return this.selected_item.find("abbr").remove(); 978 | }; 979 | 980 | Chosen.prototype.result_select = function(evt) { 981 | var high, item; 982 | if (this.result_highlight) { 983 | high = this.result_highlight; 984 | this.result_clear_highlight(); 985 | if (this.is_multiple && this.max_selected_options <= this.choices_count()) { 986 | this.form_field_jq.trigger("chosen:maxselected", { 987 | chosen: this 988 | }); 989 | return false; 990 | } 991 | if (this.is_multiple) { 992 | high.removeClass("active-result"); 993 | } else { 994 | this.reset_single_select_options(); 995 | } 996 | item = this.results_data[high[0].getAttribute("data-option-array-index")]; 997 | item.selected = true; 998 | this.form_field.options[item.options_index].selected = true; 999 | this.selected_option_count = null; 1000 | if (this.is_multiple) { 1001 | this.choice_build(item); 1002 | } else { 1003 | this.single_set_selected_text(item.text); 1004 | } 1005 | if (!((evt.metaKey || evt.ctrlKey) && this.is_multiple)) { 1006 | this.results_hide(); 1007 | } 1008 | this.search_field.val(""); 1009 | if (this.is_multiple || this.form_field.selectedIndex !== this.current_selectedIndex) { 1010 | this.form_field_jq.trigger("change", { 1011 | 'selected': this.form_field.options[item.options_index].value 1012 | }); 1013 | } 1014 | this.current_selectedIndex = this.form_field.selectedIndex; 1015 | return this.search_field_scale(); 1016 | } 1017 | }; 1018 | 1019 | Chosen.prototype.single_set_selected_text = function(text) { 1020 | if (text == null) { 1021 | text = this.default_text; 1022 | } 1023 | if (text === this.default_text) { 1024 | this.selected_item.addClass("chosen-default"); 1025 | } else { 1026 | this.single_deselect_control_build(); 1027 | this.selected_item.removeClass("chosen-default"); 1028 | } 1029 | return this.selected_item.find("span").text(text); 1030 | }; 1031 | 1032 | Chosen.prototype.result_deselect = function(pos) { 1033 | var result_data; 1034 | result_data = this.results_data[pos]; 1035 | if (!this.form_field.options[result_data.options_index].disabled) { 1036 | result_data.selected = false; 1037 | this.form_field.options[result_data.options_index].selected = false; 1038 | this.selected_option_count = null; 1039 | this.result_clear_highlight(); 1040 | if (this.results_showing) { 1041 | this.winnow_results(); 1042 | } 1043 | this.form_field_jq.trigger("change", { 1044 | deselected: this.form_field.options[result_data.options_index].value 1045 | }); 1046 | this.search_field_scale(); 1047 | return true; 1048 | } else { 1049 | return false; 1050 | } 1051 | }; 1052 | 1053 | Chosen.prototype.single_deselect_control_build = function() { 1054 | if (!this.allow_single_deselect) { 1055 | return; 1056 | } 1057 | if (!this.selected_item.find("abbr").length) { 1058 | this.selected_item.find("span").first().after(""); 1059 | } 1060 | return this.selected_item.addClass("chosen-single-with-deselect"); 1061 | }; 1062 | 1063 | Chosen.prototype.get_search_text = function() { 1064 | if (this.search_field.val() === this.default_text) { 1065 | return ""; 1066 | } else { 1067 | return $('
              ').text($.trim(this.search_field.val())).html(); 1068 | } 1069 | }; 1070 | 1071 | Chosen.prototype.winnow_results_set_highlight = function() { 1072 | var do_high, selected_results; 1073 | selected_results = !this.is_multiple ? this.search_results.find(".result-selected.active-result") : []; 1074 | do_high = selected_results.length ? selected_results.first() : this.search_results.find(".active-result").first(); 1075 | if (do_high != null) { 1076 | return this.result_do_highlight(do_high); 1077 | } 1078 | }; 1079 | 1080 | Chosen.prototype.no_results = function(terms) { 1081 | var no_results_html; 1082 | no_results_html = $('
            • ' + this.results_none_found + ' ""
            • '); 1083 | no_results_html.find("span").first().html(terms); 1084 | this.search_results.append(no_results_html); 1085 | return this.form_field_jq.trigger("chosen:no_results", { 1086 | chosen: this 1087 | }); 1088 | }; 1089 | 1090 | Chosen.prototype.no_results_clear = function() { 1091 | return this.search_results.find(".no-results").remove(); 1092 | }; 1093 | 1094 | Chosen.prototype.keydown_arrow = function() { 1095 | var next_sib; 1096 | if (this.results_showing && this.result_highlight) { 1097 | next_sib = this.result_highlight.nextAll("li.active-result").first(); 1098 | if (next_sib) { 1099 | return this.result_do_highlight(next_sib); 1100 | } 1101 | } else { 1102 | return this.results_show(); 1103 | } 1104 | }; 1105 | 1106 | Chosen.prototype.keyup_arrow = function() { 1107 | var prev_sibs; 1108 | if (!this.results_showing && !this.is_multiple) { 1109 | return this.results_show(); 1110 | } else if (this.result_highlight) { 1111 | prev_sibs = this.result_highlight.prevAll("li.active-result"); 1112 | if (prev_sibs.length) { 1113 | return this.result_do_highlight(prev_sibs.first()); 1114 | } else { 1115 | if (this.choices_count() > 0) { 1116 | this.results_hide(); 1117 | } 1118 | return this.result_clear_highlight(); 1119 | } 1120 | } 1121 | }; 1122 | 1123 | Chosen.prototype.keydown_backstroke = function() { 1124 | var next_available_destroy; 1125 | if (this.pending_backstroke) { 1126 | this.choice_destroy(this.pending_backstroke.find("a").first()); 1127 | return this.clear_backstroke(); 1128 | } else { 1129 | next_available_destroy = this.search_container.siblings("li.search-choice").last(); 1130 | if (next_available_destroy.length && !next_available_destroy.hasClass("search-choice-disabled")) { 1131 | this.pending_backstroke = next_available_destroy; 1132 | if (this.single_backstroke_delete) { 1133 | return this.keydown_backstroke(); 1134 | } else { 1135 | return this.pending_backstroke.addClass("search-choice-focus"); 1136 | } 1137 | } 1138 | } 1139 | }; 1140 | 1141 | Chosen.prototype.clear_backstroke = function() { 1142 | if (this.pending_backstroke) { 1143 | this.pending_backstroke.removeClass("search-choice-focus"); 1144 | } 1145 | return this.pending_backstroke = null; 1146 | }; 1147 | 1148 | Chosen.prototype.keydown_checker = function(evt) { 1149 | var stroke, _ref1; 1150 | stroke = (_ref1 = evt.which) != null ? _ref1 : evt.keyCode; 1151 | this.search_field_scale(); 1152 | if (stroke !== 8 && this.pending_backstroke) { 1153 | this.clear_backstroke(); 1154 | } 1155 | switch (stroke) { 1156 | case 8: 1157 | this.backstroke_length = this.search_field.val().length; 1158 | break; 1159 | case 9: 1160 | if (this.results_showing && !this.is_multiple) { 1161 | this.result_select(evt); 1162 | } 1163 | this.mouse_on_container = false; 1164 | break; 1165 | case 13: 1166 | evt.preventDefault(); 1167 | break; 1168 | case 38: 1169 | evt.preventDefault(); 1170 | this.keyup_arrow(); 1171 | break; 1172 | case 40: 1173 | evt.preventDefault(); 1174 | this.keydown_arrow(); 1175 | break; 1176 | } 1177 | }; 1178 | 1179 | Chosen.prototype.search_field_scale = function() { 1180 | var div, f_width, h, style, style_block, styles, w, _i, _len; 1181 | if (this.is_multiple) { 1182 | h = 0; 1183 | w = 0; 1184 | style_block = "position:absolute; left: -1000px; top: -1000px; display:none;"; 1185 | styles = ['font-size', 'font-style', 'font-weight', 'font-family', 'line-height', 'text-transform', 'letter-spacing']; 1186 | for (_i = 0, _len = styles.length; _i < _len; _i++) { 1187 | style = styles[_i]; 1188 | style_block += style + ":" + this.search_field.css(style) + ";"; 1189 | } 1190 | div = $('
              ', { 1191 | 'style': style_block 1192 | }); 1193 | div.text(this.search_field.val()); 1194 | $('body').append(div); 1195 | w = div.width() + 25; 1196 | div.remove(); 1197 | f_width = this.container.outerWidth(); 1198 | if (w > f_width - 10) { 1199 | w = f_width - 10; 1200 | } 1201 | return this.search_field.css({ 1202 | 'width': w + 'px' 1203 | }); 1204 | } 1205 | }; 1206 | 1207 | return Chosen; 1208 | 1209 | })(AbstractChosen); 1210 | 1211 | }).call(this); 1212 | --------------------------------------------------------------------------------