jquery-asOffset

0.1.1 • Public • Published

jQuery asOffset bower NPM version Dependency Status prs-welcome

A jquery plugin that for pick a image.

Table of contents

Main files

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

Quick start

Several quick start options are available:

Download the latest build

Install From Bower

bower install jquery-asOffset --save

Install From Npm

npm install jquery-asOffset --save

Install From Yarn

yarn add jquery-asOffset

Build From Source

If you want build from source:

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

Done!

Requirements

jquery-asOffset requires the latest version of jQuery and asSpinner.

Usage

Including files:

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

Required HTML structure

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

Initialization

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

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

Examples

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

Options

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

{
  namespace: 'asOffset',

  tpl: function() {
    return '<div class="{{namespace}}-wrap">' +
          '<div class="{{namespace}}-inner">' +
            '<div class="{{namespace}}-marginTop">' +
              '<label for="marginTop"></label>' +
              '<input id="marginTop" type="text" value="0">' +
            '</div>' +
            '<div class="{{namespace}}-marginRight">' +
              '<label for="marginRight"></label>' +
              '<input id="marginRight" type="text" value="0">' +
            '</div>' +
            '<div class="{{namespace}}-marginBottom">' +
              '<label for="marginBottom"></label>' +
              '<input id="marginBottom" type="text" value="0">' +
            '</div>' +
            '<div class="{{namespace}}-marginLeft">' +
              '<label for="marginLeft"></label>' +
              '<input id="marginLeft" type="text" value="0">' +
            '</div>' +
          '</div>' +
        '</div>';
  },

  process: function(value) {
    if (value) {
      return JSON.stringify(value);
    }
    return '';
  },

  parse: function(value) {
    if (value) {
      return $.parseJSON(value);
    }
    return {};
  },

  format: function(value) {
    return `${value}px`;
  },

  unformat: function(value) {
    return parseInt(value, 10);
  }
}

Methods

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

// call directly
$().asOffset('destroy');
 
// or
var api = $().data('asOffset');
api.destroy();

val(value)

Get or set the value.

// get the value
$().asOffset('val');
 
// set the value
$().asOffset('val', {"margin-top": "20px","margin-right": "20px","margin-bottom": "20px","margin-left": "20px"});

set(value)

Set the value.

$().asOffset('set', {"margin-top": "20px","margin-right": "20px","margin-bottom": "20px","margin-left": "20px"});

get()

Get the value.

$().asOffset('get');

enable()

Enable the offset setter functions.

$().asOffset('enable');

disable()

Disable the offset setter functions.

$().asOffset('disable');

destroy()

Destroy the offset setter instance.

$().asOffset('destroy');

Events

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

$('.the-element').on('asOffset::ready', function (e) {
  // on instance ready
});
 
Event Description
init Fires when the instance is setup for the first time.
ready Fires when the instance is ready for API use.
enable Fired when the enable instance method has been called.
disable Fired when the disable instance method has been called.
destroy Fires when an instance is destroyed.

No conflict

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

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

Browser support

Tested on all major browsers.

Safari Chrome Firefox Edge IE Opera
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-asOffset before submitting an issue. There are several ways to help out:

Development

jquery-asOffset 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

Package Sidebar

Install

npm i jquery-asOffset

Weekly Downloads

2

Version

0.1.1

License

LGPL-3.0

Last publish

Collaborators

  • amazingsurge