Skip to content

Commit

Permalink
Merge branch 'release/v1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
wpmark committed Dec 18, 2017
2 parents cd245fa + 8464cf2 commit 16d17d6
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 154 deletions.
81 changes: 81 additions & 0 deletions assets/js/wp-limit-tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
( function( $ ) {

/* set the maximum number of tags allowed - pulled from options */
var maxtags = wplt.max_tags;

/**
* function disabletags()
* this hides the tags button and disables the input when max tags is reached
*/
function disbaletags() {
$( "input.newtag" ).prop('disabled', true );
$( ".tagadd" ).css( 'visibility', 'hidden' );
$( ".tagcloud-link" ).css( 'visibility', 'hidden' );
$( ".the-tagcloud" ).css( 'visibility', 'hidden' );
}

/**
* function disabletagsbutton()
* this hides the tags button when max tags is reached
*/
function disabletagsbutton() {
$( ".tagadd" ).css( 'visibility', 'hidden' );
}

/**
* function showaddtagsbutton()
* this shows the tags button and enables the input when below max tags
*/
function showaddtagsbutton() {
$( "input.newtag" ).prop('disabled', false );
$( ".tagadd" ).css( 'visibility', 'visible' );
$( ".tagcloud-link" ).css( 'visibility', 'visible' );
$( ".the-tagcloud" ).css( 'visibility', 'visible' );
}

function disableenter() {

}

/**
* here we are checking for DOM changes within the tagchecklist element
* we a change is detected we run either hide or show
* depending on whether the change is adding or removing an element
* we also count number of tags added to the input and disable if more than max tags
*/
$(document).ready( function() {

$( '.tagchecklist' ).bind( "DOMSubtreeModified", function() {
var count = $(".tagchecklist > span").length;
if( count >= maxtags ) {
disbaletags();
} else {
showaddtagsbutton();
}
});

/* count tags as tying in input */
$( "input.newtag" ).bind("keyup keypress", function(e) {

/* get teh number of tags the user has entered into the input box */
var tags = $( "input.newtag" ).val();
var inputtedtags = tags.split( ',' ).length;

/* get the number of tags already added */
var addedtags = $(".tagchecklist > span").length;

/* work how many tags can be added now - based on the maxtags and the number already added */
var tagsleft = maxtags - addedtags;

/* if the tags inputted are greater than maxtags or greater than tagsleft to add */
if( inputtedtags > maxtags || inputtedtags > tagsleft ) {
disabletagsbutton();
e.preventDefault();
} else {
showaddtagsbutton();
}
});

});

} )( jQuery );
15 changes: 11 additions & 4 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
=== Plugin Name ===
Contributors: wpmarkuk, keithdevon
Donate Link: http://markwilkinson.me/saythanks
Contributors: wpmarkuk, keithdevon, highrisedigital
Tags: tags
Requires at least: 4.2
Tested up to: 4.4
Stable tag: 0.3.2
Tested up to: 4.9.1
Stable tag: 1.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -36,6 +35,14 @@ None so far!

== Changelog ==

= 1.0 =
* Improvements to code to better meet the WP.org coding standards.
* Introduce new filter `wplt_max_tags` for filtering the max tags.
* Better prepare the plugin for translation, making sure strings are translation ready and the plugin text domain is loaded.
* Load JS as an external file rather than with admin print scripts.
* Add the newly added built in post types to the ignore array e.g. Custom CSS and Customize changesets.
* Fix some php warning notices.

= 0.3.2 =
* Prevent users from choosing tags from the tag cloud of most popular tags once the tag limit is reached. Thanks to [ezkay](https://wordpress.org/support/profile/ezkay) for reporting this issue.

Expand Down
Loading

0 comments on commit 16d17d6

Please sign in to comment.