Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jameelmoses committed Oct 24, 2017
0 parents commit 0ab2053
Show file tree
Hide file tree
Showing 85 changed files with 9,757 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015"]
}
57 changes: 57 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# folders and files to be ignored by git

############
## IDEs
############

*.pydevproject
.project
.metadata
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
.externalToolBuilders/
*.launch
.cproject
.buildpath
nbproject/
node_modules/*
premium/node_modules/*

############
## OSes
############

[Tt]humbs.db
[Dd]esktop.ini
*.DS_store
.DS_store?

############
## Misc
############

bin/
tmp/
*.tmp
*.bak
*.log
*.[Cc]ache
*.cpr
*.orig
*.php.in
.idea/
temp/
._*
.Trashes

.svn

############
## Composer
############
vendor/
composer.phar
110 changes: 110 additions & 0 deletions acf-icomoon.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
/*
Plugin Name: Advanced Custom Fields: IcoMoon
Version: 1.0
Plugin URI: http://www.jameelmoses.com
Description: ACF IcoMoon select field
Author: Jameel Moses
Author URI: http://www.jameelmoses.com
Domain Path: languages
Text Domain: acf-icomoon
----
Copyright 2017 Jameel Moses ([email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

if ( ! defined( 'ABSPATH' ) ) {
die();
}

define( 'ACF_ICOMOON_VER', '1.0' );
define( 'ACF_ICOMOON_URL', plugin_dir_url( __FILE__ ) );
define( 'ACF_ICOMOON_DIR', plugin_dir_path( __FILE__ ) );

class acf_field_icomoon_plugin {

/**
* Constructor.
*
* Load plugin's translation and register icomoon fields.
*
* @since 1.0.0
*/
function __construct() {

add_action( 'init', array( __CLASS__, 'load_translation' ), 1 );

// Register ACF fields
add_action( 'acf/register_fields', array( __CLASS__, 'register_field_v4' ) );
add_action( 'acf/include_field_types', array( __CLASS__, 'register_field_v5' ) );
}

/**
* Load plugin translation.
*
* @since 1.0.0
*/
public static function load_translation() {
load_plugin_textdomain(
'acf-icomoon',
false,
dirname( plugin_basename( __FILE__ ) ) . '/languages'
);
}

/**
* Register Icomoon field for ACF v4.
*
* @since 1.0.0
*/
public static function register_field_v4() {
include_once( ACF_ICOMOON_DIR . 'fields/icomoon-base-field.php' );
include_once( ACF_ICOMOON_DIR . 'fields/icomoon-v4.php' );
}

/**
* Register Icomoon field for ACF v5.
*
* @since 1.0.0
*/
public static function register_field_v5() {

$enqueue_select2 = acf_get_setting( 'enqueue_select2' );
if ( is_null( $enqueue_select2 ) ) {
acf_update_setting( 'enqueue_select2', true );
}

$select2_version = acf_get_setting( 'select2_version' );
if ( is_null( $select2_version ) ) {
acf_update_setting( 'select2_version', 3 );
}

include_once( ACF_ICOMOON_DIR . 'fields/icomoon-base-field.php' );
include_once( ACF_ICOMOON_DIR . 'fields/icomoon-v5.php' );
}
}

/**
* Init plugin.
*
* @since 1.0.0
*/
function acf_field_icomoon_load() {
new acf_field_icomoon_plugin();
}
add_action( 'plugins_loaded', 'acf_field_icomoon_load' );
29 changes: 29 additions & 0 deletions assets/css/fonts/icomoon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/css/fonts/icomoon.ttf
Binary file not shown.
Binary file added assets/css/fonts/icomoon.woff
Binary file not shown.
Binary file added assets/css/fonts/icomoon.woff2
Binary file not shown.
53 changes: 53 additions & 0 deletions assets/css/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/css/style.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

120 changes: 120 additions & 0 deletions assets/js/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
(function ($, undefined) {

var select2_format = {
'3': {
data: {
results: acf_icomoon
},
formatResult: function (css) {
return "<span style='display: inline-block; font-size:18px; margin-right: 5px;' class='icon-" + css.id + "'></span> " + css.text;
},
formatSelection: function (css) {
return "<span class='icon-" + css.id + "'></span> " + css.text;
}
},
'4': {
data: acf_icomoon,
templateResult: function (css) {
return $("<span style='display: inline-block; font-size:18px; margin-right: 5px;' class='icon-" + css.id + "'></span><span>" + css.text + "</span>");
},
templateSelection: function (css) {
return $("<span class='icon-" + css.id + "'></span><span>" + css.text + "</span>");
}
}
};

/**
* Get config properties matching current Select2 version.
*
* @param {String} version
* @return {Object}
*/
function select2FormatProvider(version) {
if(undefined !== version && undefined !== select2_format[version]) {
return select2_format[version];
}

return select2_format['4'];
}

/**
* Detect which version of Select2 is loaded.
*
* @return {String|Boolean}
*/
function detectSelect2Version() {
if(undefined === $.fn.select2) {
return false;
}

return ('formatResult' in $.fn.select2.defaults) ? '3' : '4';
}

/**
* Initialize ACF field.
*
* @param $field
*/
function initialize_field($field) {

var select2Version = detectSelect2Version();
if(!select2Version) {
return;
}
var formatProvider = select2FormatProvider( select2Version );
var input = $field.find('input.acf-icomoon');
var allowClear = $(input).attr('data-allow-clear') || 0;
var opts = $.extend({
dropdownCssClass: "bigdrop widefat",
dropdownAutoWidth: true,
allowClear: 1 == allowClear
}, formatProvider);

input.select2(opts);
}

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 jQuery(document).ready()
* append = on new DOM elements appended via repeater field
*
* @type event
* @date 20/07/13
*
* @param jQueryel (jQuery selection) the jQuery element which contains the ACF fields
* @return n/a
*/

acf.add_action('ready append', function (jQueryel) {
// search jQueryel for fields of type 'FIELD_NAME'
acf.get_fields({type: 'icomoon'}, jQueryel).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="icomoon"]').each(function () {
console.log($(this));
initialize_field($(this));
});
});
}
})(jQuery);
Loading

0 comments on commit 0ab2053

Please sign in to comment.