Skip to content

Commit

Permalink
Merge pull request #8 from AtomicSmash/release/1.3.0
Browse files Browse the repository at this point in the history
Release/1.3.0
  • Loading branch information
steve-brett authored Nov 27, 2020
2 parents 597da74 + 4398b57 commit 04c763b
Show file tree
Hide file tree
Showing 14 changed files with 705 additions and 1,990 deletions.
88 changes: 78 additions & 10 deletions acf-limiter.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,30 +1,98 @@
<?php

/*
Plugin Name: Advanced Custom Fields: Limiter
Plugin URI: http://wordpress.org/extend/plugins/advanced-custom-fields-limiter-field/
Description: This field provides a textarea that limits the number of characters the a user can add. The limit is cleanly represented by a jQuery Ui progress bar. You can define the number of characters on a per field basis.
Version: 1.2.1
Version: 1.3.0
Author: Atomic Smash - David Darke
Author URI: atomicsmash.co.uk
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/

load_plugin_textdomain('acf-limiter', false, dirname(plugin_basename(__FILE__)) . '/lang/');
// exit if accessed directly
if (! defined('ABSPATH')) {
exit;
}


// check if class already exists
if (!class_exists('atomic_smash_acf_plugin_limiter')) :

function include_field_types_limiter($version)
class atomic_smash_acf_plugin_limiter
{

include_once('limiter-v5.php');
}
// vars
public $settings;

add_action('acf/include_field_types', 'include_field_types_limiter');

/**
* __construct
*
* This function will setup the class functionality
*
* @type function
* @date 17/02/2016
* @since 1.0.0
*
* @param void
* @return void
*/

function register_fields_limiter()
{
include_once('limiter-v4.php');
public function __construct()
{

// settings
// - these will be passed into the field class.
$this->settings = array(
'version' => '1.3.0',
'url' => plugin_dir_url(__FILE__),
'path' => plugin_dir_path(__FILE__)
);


// include field
add_action('acf/include_field_types', array($this, 'include_field')); // v5
add_action('acf/register_fields', array($this, 'include_field')); // v4
}


/**
* include_field
*
* This function will include the field type class
*
* @type function
* @date 17/02/2016
* @since 1.0.0
*
* @param $version (int) major ACF version. Defaults to false
* @return void
*/

public function include_field($version = false)
{

// support empty $version
if (!$version) {
$version = 4;
}


// load acf-limiter-field
load_plugin_textdomain('acf-limiter-field', false, plugin_basename(dirname(__FILE__)) . '/lang');


// include
include_once('fields/class-atomic-smash-acf-field-limiter-v' . $version . '.php');
}
}

add_action('acf/register_fields', 'register_fields_limiter');

// initialize
new atomic_smash_acf_plugin_limiter();


// class_exists check
endif;
File renamed without changes.
10 changes: 10 additions & 0 deletions assets/css/limiter.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.counterWrapper {
height: 0px;
top: -23px;
position: relative;
left: 8px;
color: #333;
margin-bottom: 10px;
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier,
monospace;
}
93 changes: 93 additions & 0 deletions assets/js/limiter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
(function ($) {
function characterLimit(currentField) {
progressBar = $(currentField).next(".progressBar");

chars = $(currentField)[0].value.length;

limit = $(currentField).data("characterlimit");

if (chars > limit) {
currentField.value = currentField.value.substr(0, limit);
chars = limit;
}

charactersRemaining = limit - chars;

$(currentField)
.next()
.next(".counterWrapper")
.children(".limiterCount")
.html(chars);

percentage = Math.floor((chars / limit) * 100);

$(progressBar).progressbar({
value: percentage,
});
}

function initialize_field($el) {
//$el.doStuff();

//Setup progress bars of all limiter fields

$($el)
.find(".limiterField")
.each(function () {
characterLimit(this);
});

//Run characterLimit() when the field is being used
$($el)
.find(".limiterField")
.on("keyup focus", function () {
characterLimit(this);
});
}

if (typeof acf.add_action !== "undefined") {
/**
* ready append (ACF5)
*
* These are 2 events which are fired during the page load
* ready = on page load similar to $(document).ready()
* append = on new DOM elements appended via repeater field
*
* @type event
* @date 20/07/13
*
* @param $el (jQuery selection) the jQuery element which contains the ACF fields
* @return n/a
*/

acf.add_action("ready append", function ($el) {
// search $el for fields of type 'limiter'
acf.get_fields({ type: "limiter" }, $el).each(function () {
initialize_field($(this));
});
});
} else {
/**
* acf/setup_fields (ACF4)
*
* This event is triggered when ACF adds any new elements to the DOM.
*
* @type function
* @since 1.0.0
* @date 01/01/12
*
* @param event e: an event object. This can be ignored
* @param Element postbox: An element which contains the new HTML
*
* @return n/a
*/

$(document).on("acf/setup_fields", function (e, postbox) {
$(postbox)
.find('.field[data-field_type="limiter"]')
.each(function () {
initialize_field($(this));
});
});
}
})(jQuery);
8 changes: 0 additions & 8 deletions css/limiter.css

This file was deleted.

Loading

0 comments on commit 04c763b

Please sign in to comment.