Git Product home page Git Product logo

micc83 / fonticonpicker Goto Github PK

View Code? Open in Web Editor NEW
266.0 22.0 86.0 2.39 MB

🌈 jQuery fontIconPicker v2 is a small (3.22kb gzipped) jQuery plugin which allows you to include a simple icon picker with search and pagination inside your administration forms.

Home Page: http://micc83.github.io/fontIconPicker/

License: MIT License

CSS 10.96% JavaScript 12.47% HTML 76.57%
jquery-fonticonpicker icon-picker jquery-plugin font-icons fontello

fonticonpicker's Introduction

jQuery fontIconPicker v3.0 is out

Version 2.0 of jQuery fontIconPicker will no more receive updates nor support. You can find Version 3.0 right here:

Click here to get jQuery fontIconPicker v3.0

jQuery fontIconPicker v2.0

jQuery fontIconPicker is a small (3.22KB gzipped) jQuery plugin which allows you to include an elegant icon picker with categories, search and pagination inside your administration forms. The list of icons can be loaded manually using a SELECT field, an Array or Object of icons or directly from a Fontello config.json or IcoMoon selection.json file. Go to the official plugin page for examples and documentation.

Notice : Many of the features introduced with release 2.0.0 were the result of a collaboration. Unfortunately the developer of those features is not actively following the project anymore so you're more than welcome to step in. The problem is that since version 1.0.0 jQuery fontIconPicker has grown much and it's not mantainable anymore without writing first a carefully drafted test suite. So the first stage of any collaboration would be about writing unit and integration testing for everything implemented up to now (I know it's a pain in the ...). Until then unfortunately It won't be possible to me to address any bug or add new features. Thx for the understanding.

fontIconPickers

How it works

Just include a copy of jQuery, the fontIconPickers script, the fontIconPickers theme and your Font Icons. Now you can trigger it on a SELECT or INPUT[type="text"] element.

Include the JavaScript

<!-- jQuery -->
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>

<!-- fontIconPicker JS -->
<script type="text/javascript" src="jquery.fonticonpicker.min.js"></script>

Include the CSS

<!-- fontIconPicker core CSS -->
<link rel="stylesheet" type="text/css" href="jquery.fonticonpicker.min.css" />

<!-- required default theme -->
<link rel="stylesheet" type="text/css" href="themes/grey-theme/jquery.fonticonpicker.grey.min.css" />

<!-- optional themes -->
<link rel="stylesheet" type="text/css" href="themes/dark-grey-theme/jquery.fonticonpicker.darkgrey.min.css" />
<link rel="stylesheet" type="text/css" href="themes/bootstrap-theme/jquery.fonticonpicker.bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="themes/inverted-theme/jquery.fonticonpicker.inverted.min.css" />

Include Font Icons

<!-- Font -->
<link rel="stylesheet" type="text/css" href="fontello-7275ca86/css/fontello.css" />
<link rel="stylesheet" type="text/css" href="icomoon/icomoon.css" />

Initialize with jQuery

Finally call the fontIconPicker on a SELECT or INPUT[type="text"] element.

<!-- SELECT element -->
<select id="myselect" name="myselect" class="myselect">
	<option value="">No icon</option>
	<option>icon-user</option>
	<option>icon-search</option>
	<option>icon-right-dir</option>
	<option>icon-star</option>
	<option>icon-cancel</option>
	<option>icon-help-circled</option>
	<option>icon-info-circled</option>
	<option>icon-eye</option>
	<option>icon-tag</option>
	<option>icon-bookmark</option>
	<option>icon-heart</option>
	<option>icon-thumbs-down-alt</option>
	<option>icon-upload-cloud</option>
	<option>icon-phone-squared</option>
	<option>icon-cog</option>
	<option>icon-wrench</option>
	<option>icon-volume-down</option>
	<option>icon-down-dir</option>
	<option>icon-up-dir</option>
	<option>icon-left-dir</option>
	<option>icon-thumbs-up-alt</option>
</select>
<!-- JavaScript -->
<script type="text/javascript">
	// Make sure to fire only when the DOM is ready
	jQuery(document).ready(function($) {
		$('#myselect').fontIconPicker(); // Load with default options
	});
</script>
<!-- INPUT element -->
<input type="text" name="mytext" id="mytext" />
<script type="text/javascript">
	jQuery(document).ready(function($) {
		$('#mytext').fontIconPicker({
			source:    ['icon-heart', 'icon-search', 'icon-user', 'icon-tag', 'icon-help'],
			emptyIcon: false,
			hasSearch: false
		});
	});
</script>

Plugin Options

Here's fontIconPicker options:

var $picker = $('.picker').fontIconPicker({
	theme             : 'fip-grey',              // The CSS theme to use with this fontIconPicker. You can set different themes on multiple elements on the same page
	source            : false,                   // Icons source (array|false|object)
	emptyIcon         : true,                    // Empty icon should be shown?
	emptyIconValue    : '',                      // The value of the empty icon, change if you select has something else, say "none"
	iconsPerPage      : 20,                      // Number of icons per page
	hasSearch         : true,                    // Is search enabled?
	searchSource      : false,                   // Give a manual search values. If using attributes then for proper search feature we also need to pass icon names under the same order of source
	useAttribute      : false,                   // Whether to use attribute selector for printing icons
	attributeName     : 'data-icon',             // HTML Attribute name
	convertToHex      : true,                    // Whether or not to convert to hexadecimal for attribute value. If true then please pass decimal integer value to the source (or as value="" attribute of the select field)
	allCategoryText   : 'From all categories',   // The text for the select all category option
	unCategorizedText : 'Uncategorized'          // The text for the select uncategorized option
});

Plugin APIs

fontIconPicker provides three public APIs to manipulating the icon picker.

setIcons( Array|Object newIcons, Array|Object iconSearch )

Use this method to dynamically change icons on the fly. newIcons and iconSearch (optional) have same datatypes as source and searchSource options.

$picker.setIcons(['icon-one', 'icon-two']);
$picker.setIcons(['icon-one', 'icon-two'], ['Icon one will be searched by this', 'Icon two will be searched by this']);

destroyPicker()

Use this to remove the icon picker and restore the original element.

$picker.destroyPicker();

refreshPicker( Object|Boolean newOptions )

Refresh the icon picker from DOM or passed options. Useful when DOM has been changed or reinitializing after calling the destroy method or changing the options values.

$picker.refreshPicker({
	theme: 'fip-bootstrap',
	hasSearch: false
});

Options and APIs are discussed in details with live examples at the project page.

Important notes for local demo

Only when loading demo locally: In firefox fontIconPicker icons won't be shown correctly because of CORS. For the same reason "Load icons from Fontello JSON config file" won't work on Chrome or IE 10. If you need to do some local testing you can disable strict_origin_policy at your risk.

Browser Compatibility

jQuery iconPicker has been successfully tested on: Firefox (edge), Safari (edge), Chrome (edge), IE8+ and Opera (edge).

Credits

jQuery fontIconPicker has been made by me & swashata. You can contact me at [email protected] or twitter for any issue or feauture request.

I really have to thank miniMAC for the idea, Zeno Rocha for jQuery plugin boilerplate, Dave Gandy & KeyaMoon for the beautiful sets of icons and Elliot Condon for the amazing Advanced Custom Field WordPress plugin.

fonticonpicker's People

Contributors

micc83 avatar swashata avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fonticonpicker's Issues

Things to do for v3.0.0

After completion of #44 we need to do a few more things before release.

  • Document #16 - better repositioning.
  • Document #39 - Render function.
  • Add searchPlaceholder and extraClass support #21
  • Fix issue #10

custom svg icon does not align in the middle of the selector box

Maybe someone could help with this issue. I am using the bootstrap theme with custom svg icon. It's working, but the icon is not aligned in the middle of the selector box. I have tried with v2.0.0 and master and both are not aligned correctly.

<style>
    .icon-airfield:before {  
        content: url("/media/airfield.svg"); 
        vertical-align:"middle" !important;
    }
</style>

<select id="id_form-0-marker" class="fontIconPicker select form-control" name="form-0-marker">
    <option selected="selected" value="">Please Choose</option>
    <option value="1">icon-airfield</option>
</select>

  $(".fontIconPicker").fontIconPicker({
          source: ['icon-airfield']
  });

Result:
iconpicker

See this jsFiddle: https://jsfiddle.net/5m9wco4b/6/

Add possibility to customize search texte

Would be great to add the ability to customize the search text placeholder like we do for the categories. Would make it possible to translate this hardcoded string.

Question related other iconpacks

First things first: the script is fantastic, love it!
I was wondering tho if I could make it work together with another icon library such as Fontawesome. I'm planning on building a "select icon" panel in a wordpress template admin area.

  • I enqueued FA icons and they show.
  • I did the same for fontIconPicker and the select shows up correctly.

But the icon is corrupted/missing (on firefox shows up as a strange glyph, on chrome is just a white bordered box). In firebug i see that the HTML code being generated is correct.

So I was wondering am I missing something or is this a feature to be implemented maybe someday?

Themes not working? Not default theme either?

I have this very weird problem as the picker won't show up with any styles.
It's just all white.
I've checked that all the css files are loaded properly in the browser, and they are.

The css i include are theese:
jquery.fonticonpicker.min.css
jquery.fonticonpicker.grey.min.css
jquery.fonticonpicker.bootstrap.min.css

And it still looks like this:
bilde

Here is the code i use to instantiate the icon picker:
var fontIconPickerInput = $('#fontIconPicker'); fontIconPickerInput.fontIconPicker({ emptyIcon: false, source: ['fas fa-heart', 'fas fa-search', ' fas fa-user', 'fas fa-tag', 'fas fa-help'], theme : 'grey' });

Am I missing something here?
I also tried adding some style to the .selector class, but it doesn't show either.
I don't know what I am doing wrong here.

Can't see the dropdown icon

My dropdown looks like this:
image
Empty icon shows a chinese character, and no dropdown icon. Icons are showned fine. What could be wrong? Thanks

Setup Testing, CI and some automation

So I have been long absent on this and finally have enough time and experience to come back at it. But before we proceed with the issues and MRs, I think it would be better if we put up some sort of testing along with continuous integration and some grunt/gulp tasks to create dist files and set things up in package managers like yarn/npm etc.

I have very limited experience with javascript unit testing, but I am good with browser automation tests (acceptance tests) with http://codecept.io/

So @micc83 please suggest.

LICENSE

I see there's no license attached. Does this have a reason?

'.selector-button' click event issue

Hi,

First of all, thanks for this library, it's really useful.

I do have a problem with my WordPress ACF field that I .fontIconPicker(). So far so good, it's working fine, as below :
capture d ecran 2015-09-11 a 11 52 24

But I do have repeating field, so I can add various icon field on my screen. I have no problem initializing the plugin on newly added fields, because ACF offers a JS event when new fields are created.

But because of this event in the library :

this.iconPicker.find('.selector-button').click($.proxy(function () {

There is no way to display the selection dropdown or browse through it via the small arrows. The event does not work on newly added elements into the DOM after creation.

I tried to use refreshPicker(), hoping that the event will be taken into account, but that's not the case

function initAndRefreshIconInputs() {
    var $icon_fields = $('.volticon-field input').not('.fonticoned');

    setTimeout(function(){
        $icon_fields.each(function(){
            $(this).addClass('fonticoned');
            fonticonpick_instance = $(this).fontIconPicker({
                source: icomoon_json_icons,
                hasSearch: false
            });

            fonticonpick_els.push(fonticonpick_instance);
        });

        for (var i = 0; i < fonticonpick_els.length; i++) {
            fonticonpick_els[i].refreshPicker({
                source: icomoon_json_icons,
                hasSearch: false
            });
        }
    }, 50);
}

What can I do ?

Thanks for your help

Load JSON Icomoon (example 9)

Hi,

I try to reproduce Example 9 of the website.
In my code I link to the JSON file on your website to test it.

This is the part of the code where I link to the JSON file:

// Get the JSON file
        $.ajax({
            url: "http://codeb.it/fonticonpicker/icomoon/selection.json",
            type: 'GET',
            dataType: 'json'
        })
        .done(function(response) {

Everything else in the code of example 9 is the same.
jQuery is loaded off course. The button also changes to the error text.

Do you know why the icons are not loaded on the click of the button?

Regards

stupid question - only using fontawesome

Hi..

Thanks foe this amazing plugin, I am going to use it in one of my wordpress theme. However, I am a bit confused, I only want to use FontAwesome, is there any example which displays categorized fontawesome icons only ?

regards

Problem with hidden input field

As i told you for now i could find only a few bugs. I don't understand why you have added this code:

// Hide source element
// Instead of doing a display:none, we would rather
// make the element invisible
// and adjust the margin
this.element.css({
    visibility: 'hidden',
    top: '-' + this.element.outerHeight(true) + 'px',
    position: 'relative',
    zIndex: '-1',
    left: '-100px'
});

Cause now the inline-block element is not actually put inline with the next block as you can see in the following figure:
schermata_05-2456790_alle_12_17_29-4

Add option for SELECT OPTION

Hello,

When your icon list is constructed in the following way, where 'id' is the database id:

<option value="id">fa fa-search</option>

fontIconPicker is going to use the 'id' for the class, as below:

<i data-fip-value"..." class="id"></i>

Would that be possible to add an option to specify for SELECT tag to use the OPTION tag's value attributes or the text between OPTION and /OPTION

It would mean using 'flipBoxTitle' instead of 'item' in line https://github.com/micc83/fontIconPicker/blob/master/jquery.fonticonpicker.js#L640

What do you think?

Pagination buttons doesn't work properly

Steps to reproduce:

  1. Select a certain category where pagination > 1.
  2. Navigate to last page, this will hide the next arrow.
  3. Now select another category where pagination > 1.
  4. Icons will be rendered from first page but the next and previous button will not reset.

Already working on a fix. Will upload on the 2.1.0 branch.

Suggestion for moving into org repository

Hello @micc83

I have a small suggestion to make. Would it be okay if we move fontIconPicker to a separate organization account? The reason why I am asking this

  1. It will be synced with npm organization
  2. I am learning react right now. Once done, I will create a better doc with react and material ui (will also make fip react compatible and have material themes). We can seamlessly publish it as github pages and get a custom domain from js.org.

Let me know what you think.

Use the number (html entity, css before, etc..) instead of the <i> tag with a class name.

I'm used to working with font icons using the number, not the class name thing. I even would like to be able to search using the number. I think the name system these guys use is pretty bogus and the need for the list of thousands of lines of CSS when I'm using only a few of those icons is pretty over the top.
It would be good if there was a mode where you could search using the number (or the existing keywords), the values displayed in the picker would not use the i tag - perhaps just display the html entity, the value that would be saved in the text input is the number. Then I can use that value however I like.
Really to me the 'value' of a font icon is that number. Not the word.

Discussion and updates for 2.0.0

I am working on a new documentation template (please check index-new.html), let me know what you think of it. Also I've added two new public methods (already in the docs), please do a review.

New option autoClose

By default fip closes when clicked outside. We should introduce an option to disable that.

This is useful in cases like WordPress navigation area, when a click on the menu builder is triggered and it would cause fip to close.

loading in wordpress thickbox..

hi micc again, sorry for posting another question.. please bear with me as I love your plugin and want to use it in one of my theme that I have been working over 8 months now..

I have successfully created a working example with field on the localhost.. which works perfectly except it does not show the pagination and dropdown icon... but it shows the Fontawesome icons perfectly...

however when loading it in Thickbox (using Zilla Shortcode plugin) it converts the inputbox to a working iconPicker but it doesnt show any icons, I checked the code, its perfectly added everything, but simply doesnt show the fontawesome icons, I put the2 icons before the inputbox to see if there is something wrong with Fontawesome, but those icons how perfectly... what could possible be wrong ? am still digging..

regards

font_picker

The select triggers change event on load.

Hi,
I have been working on implementing the icon selector to a CMS form (WordPress). When a user leaves the form-page, the system checks to see if any changes has happened to the form, and if it finds that changes has happened, it prompts the user with a "are you sure you want to leave the page..." message.

For some reason, the script changes the value from whatever is selected to the same value again, which is considered a ".change" event in Javascript, even though the value is the same. In my case this results in the warning every time someone tries to leave the form-page, even if nothing has changed at all.

Note that this is not the case in version 1.0.0, but is the case in 2.0.0.

Is there a way to get around this? Does the script have to trigger the change-event on load?

For now I have to use version 1.0.0 to get around this, but this doesn't trigger the change-warning, even if it is changed, which I don't quite understand.

Thank you for all your time building this.

Adding support for data-icon attribute

Hello,

I am forking your repository to support for data-icon attribute (or any other custom attribute) and naming icons (for searching). If you think this features are good, then I can send you a pull request.

Version 2.1.0 is good to go

Hello,

I have committed all necessary patches for version 2.1.0. I think it is ready to go live now. Please update the readme.md file while on the process.

Modernize & Modularize Development Environment

The first thing we need to focus on is modernize the environment for development. Currently, the build process is manual and code is intermingled.

Phase 1: Modernize environment

  • Initialize an npm package.json with devDependencies gulp, jest, babel, eslint, stylelint and needed plugins/config.
  • Create editorconfig for consistency with coding.
  • Setup linter for JS eslint
  • Setup linter for CSS stylelint.

Phase 2: Modularize code

  • Separate Plugin from jQuery wrapper and use UMD within the build process. We can concat.
  • Further breakdown the Plugin class into separate smaller methods so that we can unit test.
  • Refactor CSS with SCSS and separate layout and theming.
  • Create JS build process with Rollup, Babel and UglifyJS.
  • Create CSS build process with node-sass.

All built code should go under ./dist which should be in .gitignore. All source code will go under ./src which will be under .npmignore.

Phase 3: Setup Testing

  • Fix all eslint errors on our own scripts. Mostly is due to spacing and can be fixed automatically.
  • Setup test using jest or qunit or karma. Assess what options can be easily used in CI like travis.
  • Lint all files in the CI. Use gulp to lint .js and .scss files.

Phase 4: Setup CI

  • Use travis-ci for continuous integration. Steps are

General Testing

  1. Lint all files.
  2. Run jest tests.

Tagged Releases

  1. Build distribution.
  2. Publish on NPM.
  3. Upload artifacts to github release as .zip.

Phase 5: Document procedure

  1. Document npm and setup.
  2. Document available gulp tasks.
  3. Document lint and test process approval for PRs.

References:

Saving some references which I might need in future.

  1. https://babeljs.io/docs/plugins/transform-es2015-modules-umd/
  2. https://stackoverflow.com/questions/48818400/how-to-transpile-ecma6-import-of-jquery-to-a-umd-wrapper-with-babel
  3. https://stackoverflow.com/questions/35061900/converting-a-jquery-plugin-to-an-es6-module
  4. https://stackoverflow.com/questions/35136874/extend-es6-plugin-to-jquery-prototype
  5. https://medium.com/@tarkus/how-to-build-and-publish-es6-modules-today-with-babel-and-rollup-4426d9c7ca71

Needed feature: appendTo for selectorPopup

As I started using the picker on my project, I noticed a much needed feature is missing, ie to append the iconpicker where ever we want. I am already on a commit where I did this, but I need to confirm where to push the commit. I think we can push to master and release it as 2.1.0. Suggestions?

Option Trigger

Hi,

How can i trigger change option?

This codes not working.

$("select#ozellikSimgeD").val(array.simge).trigger("change");
$("select#ozellikSimgeD option[value='"+array.simge+"']").attr("selected", "selected");

Thanks,
Metin.

Ideas for future

Since we are good to go with version 2.0.0, here are my ideas for future release:

  • Make the plugin APIs more like widgets. Instead of having to save the reference in a variable, I think something like this would be a better approach: $('.mypicker').fontIconPicker('setIcons', newSource, newSearch) This will require major structure rewrite.
  • Support for HTML data-attr for having inline options. Like <input source="['icon-1', 'icon-2']" />
  • Custom events triggered when the picker opens, closes, user chooses an icon, makes search etc. So that others can hook in.
  • A new API to set & get individual options. Something like: $('.mypicker').fontIconPicker('options', 'theme', 'fip-grey'); // Setter & $('.mypicker').fontIconPicker('options', 'theme'); // Getter
  • Ability to categorize icons on the fly from config or selection json files based on user provided tags. I can adapt to the logic used in IconIndexer script.

This is all I can think of now.

Icon picker

Dear Micc83, Can you help me to select different icons than what i have.

Can i upload other icons than the icons i have. I use your iconpicker in the administration system from wordpress.
iconpicker screenshot

SVG Icon Support & FontAwesome Example

Hi,

Thanks for this great work. Just a very very minor change request to accept svg icons for icomoon, font awesome and others: I had to edit the selector to get the selected icon in jquery.fonticonpicker.js L.428:

$(e.currentTarget)
.find('i, svg') // instead of .find('i')
.attr('data-fip-value')

I thought it may be useful for other users.

2nd thing: I built a JSON list with all the Font Awesome Icons categorized, feel free to use it and maybe add an example https://codeb.it/fonticonpicker/:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.