0.2.4 • Published 7 years ago

jquery-asFontEditor v0.2.4

Weekly downloads
3
License
LGPL-3.0
Repository
github
Last release
7 years ago

jQuery asFontEditor bower NPM version Dependency Status prs-welcome

A jquery plugin that give typegraphy selection.

Table of contents

Main files

dist/
├── jquery-asFontEditor.js
├── jquery-asFontEditor.es.js
├── jquery-asFontEditor.min.js
└── css/
    ├── asFontEditor.css
    └── asFontEditor.min.css

Quick start

Several quick start options are available:

Download the latest build

Install From Bower

bower install jquery-asFontEditor --save

Install From Npm

npm install jquery-asFontEditor --save

Install From Yarn

yarn add jquery-asFontEditor

Build From Source

If you want build from source:

git clone git@github.com:amazingSurge/jquery-asFontEditor.git
cd jquery-asFontEditor
npm install
npm install -g gulp-cli babel-cli
gulp build

Done!

Requirements

jquery-asFontEditor requires the latest version of jQuery, asDropdown and asRange.

Usage

Including files:

<link rel="stylesheet" href="/path/to/asFontEditor.css">
<script src="/path/to/jquery.js"></script>
<script src="/path/to/jquery-asFontEditor.js"></script>

Required HTML structure

<input type="text" class="typography" value='' />

Initialization

All you need to do is call the plugin on the element:

jQuery(function($) {
  $('.example').asFontEditor(); 
});

Examples

There are some example usages that you can look at to get started. They can be found in the examples folder.

Options

jquery-asFontEditor can accept an options object to alter the way it behaves. You can see the default options by call $.asFontEditor.setDefaults(). The structure of an options object is as follows:

{
  namespace: 'asFontEditor',
  skin: null,
  lang: 'en',
  fontFamily: {
    namespace: 'asDropdown',
    defaultValue: 'inherit',
    values: {
      Arial: 'Arial',
      Bpreplay: 'Bpreplay',
      Cambira: 'Cambira',
      Gabriola: 'Gabriola'
    },
    tpl: function() {
      return '<div class="{{namespace}}-fontFamily">' +
        '<span class="{{namespace}}-fontFamily-title">{{strings.typeface}}</span>' +
        '<div class="{{namespace}}-fontFamily-content">' +
        '<div class="{{fontFamilyNamespace}} {{namespace}}-fontFamily-dropdown"><i class="asIcon-caret-down"></i></div>' +
        '<ul>' +
        '</ul>' +
        '</div>' +
        '</div>';
    }
  },
  fontWeight: {
    namespace: 'asDropdown',
    defaultValue: 'inherit',
    values: ['inherit', 'bold', '400', '500', '600', '700'],
    tpl: function() {
      return '<div class="{{namespace}}-fontWeight">' +
        '<span class="{{namespace}}-fontWeight-title">{{strings.weight}}</span>' +
        '<div class="{{namespace}}-fontWeight-content">' +
        '<div class="{{fontWeightNamespace}} {{namespace}}-fontWeight-dropdown"><i class="asIcon-caret-down"></i></div>' +
        '<ul>' +
        '<li>inherit</li>' +
        '<li>bold</li>' +
        '<li>400</li>' +
        '<li>500</li>' +
        '<li>600</li>' +
        '<li>700</li>' +
        '</ul>' +
        '</div>' +
        '</div>';
    }
  },
  fontSize: {
    namespace: 'asRange',
    defaultValue: 'inherit',
    value: 0,
    unit: 'px',
    min: 0,
    max: 100,
    step: 2,
    tpl: function() {
      return '<div class="{{namespace}}-fontSize">' +
        '<span class="{{namespace}}-fontSize-title">{{strings.fontSize}}</span>' +
        '<div class="{{namespace}}-fontSize-content">' +
        '<div class="{{fontSizeNamespace}} {{namespace}}-fontSize-range"></div>' +
        '<div class="{{namespace}}-fontSize-value">0</div>' +
        '</div>' +
        '</div>';
    }
  },
  lineHeight: {
    namespace: 'asRange',
    defaultValue: 'inherit',
    value: 'inherit',
    unit: 'px',
    min: 1,
    max: 10,
    step: 0.5,
    tpl: function() {
      return '<div class="{{namespace}}-lineHeight">' +
        '<span class="{{namespace}}-lineHeight-title">{{strings.lineHeight}}</span>' +
        '<div class="{{namespace}}-lineHeight-content">' +
        '<div class="{{lineHeightNamespace}} {{namespace}}-lineHeight-range"></div>' +
        '<div class="{{namespace}}-lineHeight-value">1</div>' +
        '</div>' +
        '</div>';
    }
  },
  textAlign: {
    defaultValue: '',
    values: ['left', 'center', 'right'],
    tpl: function() {
      return '<ul class="{{namespace}}-decorations">' +
        '<li class="{{namespace}}-textAlign text-left"></li>' +
        '<li class="{{namespace}}-textAlign text-center"></li>' +
        '<li class="{{namespace}}-textAlign text-right"></li>' +
        '</ul>';
    }
  },
  fontStyle: {
    defaultValue: '',
    value: 'italy',
    tpl: function() {
      return '<li class="{{namespace}}-fontStyle text-italy"></li>';
    }
  },
  textTransform: {
    defaultValue: '',
    values: ['uppercase', 'lowercase', 'capitalize'],
    tpl: function() {
      return '<li class="{{namespace}}-textTransform text-uppercase"></li>' +
        '<li class="{{namespace}}-textTransform text-lowercase"></li>' +
        '<li class="{{namespace}}-textTransform text-capitalize"></li>';
    }
  },
  textDecoration: {
    defaultValue: '',
    values: ['underline', 'line-through'],
    tpl: function() {
      return '<li class="{{namespace}}-textDecoration text-underline"></li>' +
        '<li class="{{namespace}}-textDecoration text-linethrough"></li>';
    }
  },
  tpl: function() {
    return '<div class="{{namespace}}">' +
      '<div class="{{namespace}}-initial">' +
      '<i></i>{{strings.addTypography}}' +
      '</div>' +
      '<div class="{{namespace}}-info">' +
      '<div class="{{namespace}}-info-font"><i>Aa</i><span class="{{namespace}}-info-font-name">{{strings.fontFamily}}</span></div>' +
      '<div class="{{namespace}}-info-change">{{strings.change}}</div>' +
      '<a class="{{namespace}}-info-remove" href="#">x</a>' +
      '</div>' +
      '<div class="{{namespace}}-expand">' +
      '<a class="{{namespace}}-expand-close" href="#">-</a>' +
      '</div>' +
      '</div>';
  },
  process: function(value) {
    if (value) {
      for (const prop in value) {
        if (value[prop] === this.options[prop].defaultValue) {
          delete value[prop];
        }
      }
      const json = JSON.stringify(value);
      if (json !== '{}') {
        return json;
      }
    }
    return '';
  },
  parse: function(value) {
    if (value) {
      return $.parseJSON(value);
    }
    return {};
  },
  onChange: function() {},
  onClick: function() {},
  strings: {}
}

Methods

Methods are called on asFontEditor instances through the asFontEditor method itself. You can also save the instances to variable for further use.

// call directly
$().asFontEditor('destroy');

// or
var api = $().data('asFontEditor');
api.destroy();

val(value)

Get or set the value.

// get the value
$().asFontEditor('val');

// set the value
$().asFontEditor('val', {"font_family": "Arial"});

set(value)

Set the value.

$().asFontEditor('set', {"font_family": "Arial"});

get()

Get the value.

$().asFontEditor('get');

enable()

Enable the font editor functions.

$().asFontEditor('enable');

disable()

Disable the font editor functions.

$().asFontEditor('disable');

destroy()

Destroy the font editor instance.

$().asFontEditor('destroy');

Events

jquery-asFontEditor provides custom events for the plugin’s unique actions.

$('.the-element').on('asFontEditor::ready', function (e) {
  // on instance ready
});
EventDescription
initFires when the instance is setup for the first time.
readyFires when the instance is ready for API use.
enableFired when the enable instance method has been called.
disableFired when the disable instance method has been called.
destroyFires when an instance is destroyed.

No conflict

If you have to use other plugin with the same namespace, just call the $.asFontEditor.noConflict method to revert to it.

<script src="other-plugin.js"></script>
<script src="jquery-asFontEditor.js"></script>
<script>
  $.asFontEditor.noConflict();
  // Code that uses other plugin's "$().asFontEditor" can follow here.
</script>

Browser support

Tested on all major browsers.

Latest ✓Latest ✓Latest ✓Latest ✓9-11 ✓Latest ✓

As a jQuery plugin, you also need to see the jQuery Browser Support.

Contributing

Anyone and everyone is welcome to contribute. Please take a moment to review the guidelines for contributing. Make sure you're using the latest version of jquery-asFontEditor before submitting an issue. There are several ways to help out:

Development

jquery-asFontEditor is built modularly and uses Gulp as a build system to build its distributable files. To install the necessary dependencies for the build system, please run:

npm install -g gulp
npm install -g babel-cli
npm install

Then you can generate new distributable files from the sources, using:

gulp build

More gulp tasks can be found here.

Changelog

To see the list of recent changes, see Releases section.

Copyright and license

Copyright (C) 2016 amazingSurge.

Licensed under the LGPL license.

⬆ back to top