Git Product home page Git Product logo

mickey.js's Introduction

THIS IS MY FIRST TRY ON MAKING SOMETHING, REALLY, IGNORE IT. ๐Ÿ’ฉ

Mickey.js

Mouses are smarter these days! A handy tool that makes it easy to play with mouses. Mickey is still a work in progress, so it might have many issues, we'll be glad if you report them. View examples here: Mickey.js

Download minified version for production: Mickey-0.1.min.js

Clone Mickey's repo:

$ git clone https://github.com/Mahdi-/Mickey.js.git

Why Mickey?

  • No dependecy
  • jQuery-like API
  • Event-based
  • Easy to use

API

Mickey.js has a jQuery-like chained API. Mickey uses document.querySelectorAll() to parse selectors, so you have to separate selectors with commas, take a look:

Mickey('button, .s').blink(200);

Here is a list of Mickey's functions:

Mickey( selector )

Needs an argument selector which is one or more CSS Selector(s) or an HTML Element Object.

.blink( delay, cursor )

Has two optional arguments delay and cursor. The cursor blinks with a delay, if you want to specify the cursor to be blinked, add cursor.

Defaults values:

delay = 300
cursor = 'default'

.timeout( cursor, delay, revert )

Has three optional arguments cursor, delay and revert. The current cursor changes to cursor after a delay, if revert is not null or undefined, the cursor changes back to what it was.

Default values:

cursor = 'pointer'
delay = 300
revert = undefined

.interval( from, to, delay )

Has one optional argument delay and two must-be-specified arguments from and to. The cursor changes from from to to with a delay and repeats.

Default values:

delay = 300

.shadow( x, y, color, delay, effect, className )

Has 6 optional arguments x, y, color, delay, effect and id. Adds a shadow to cursor, placed at right-bottom of the cursor, x and y are relative positions to shadow's place and cannot be less than 0, color specifies shadow's color and delay specifies the delay that shadow has to answer to mouse's move, effect is an object containing effect's info[effects], and className specifies the class attribute gave to the shadow.

Default values:

x = 0
y = 0
color = 'black'
delay = 0
className = undefined

Effects

.text( text, styles, x, y, effect, className )

Has 5 optional arguments styles, x, y, effect and className and a must-be-specified argument text. Adds a text that follows the cursor at it's right-bottom corner by default, relative position of text can be changed using x and y, CSS styles of the text can be specified using an object of styles as styles argument, can have different effects[effects] and the text's class attribute is specified using className argument.

Defaullt values:

styles = undefined
x = 0
y = 0
effect = undefined
className = undefined

Built-in effects available:

heartbeat

Effects

.image( src, styles, x, y, effect, className )

Same as .text( .. ), with a difference of src instead of text.

Default values:

styles = undefined
x = 0
y = 0
effect = undefined
className = undefined

Built-in effects available:

spin

Effects

.chase()

Has no arguments. Calling this function forces scrolls to chase the mouse.

.absolute()

Has no argument, returns an object of mouse's current position with two properties top and left.

.relative()

Has no argument, returns an object of mouse's current position, relative to selector defined in Mickey( .. ) with two properties top and left.

.hover( function )

Needs a function as first argument to be called on mouseover event.

.click( function )

Needs a function as first argument to be called on click event.

.remove( object )

Needs an object as first argument, this is used to remove EventListeners, take a look at example:

var x = Mickey().chase();
Mickey().stop( x );

When you .stop an object, for example, let's say, .blink, the .blink is not stopped in the elements it started from, it stops in the elements specified in Mickey():

var b = Mickey('.foo, #test').blink();

.blink was called on .foo and #test. But when you do this:

Mickey('.foo').stop( b );

The #test still blinks!

NOTE: This feature works on .blink, .interval, .timeout, .image, .text, .shadow, .hover and .click

Effects

We made it easy to make effects for Mickey. All you have to do is to make a function and assign it to Mickey.effects object that has 3 properties text,shadow and image, your function takes an array of elements as argument, for example, text effects, take the span elements as their first argument, and other properties as second argument. Use Mickey.forEach( elementsArray, function( element ) ) to loop over elements, it's safe and easy.

Mickey(selector).text(..,..,..,.., { name : 'effectName', option1 : 'foo' })

Effects should be in an external file and placed in /effects folder.

Example:

Mickey.effects.text.youreffectname = function( els, opts ) {
  Mickey.forEach( els, function( el ) {
    //Your code
  });
};

That's all, Mickey loops over effects and tries to find the effect that user has called.

Effects available:

text:
     heartbeat

image:
      spin

Third-party effects:

none yet :(

TODO

Mickey has a long way to go, but these spotted bugs are in priority:

Issue #1

Issue #2

Issue #3

License

Mickey is published under MIT LICENSE.

The MIT License (MIT)

Copyright 2013 Mahdi Dibaiee

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

mickey.js's People

Stargazers

Mohammad Kermani avatar Mohammad Sadegh Khoeini avatar Mohamad Mohebifar avatar charalampos papaloizou avatar Reiha Hosseini avatar Dmitry Iv. avatar Nikos M. avatar Josh Miller avatar Rashaad Essop avatar ็Ž‹ๆตท่‹ฑ avatar Alexander Salas Bastidas avatar  avatar  avatar

Watchers

James Cloos avatar Mahdi Dibaiee avatar  avatar

Forkers

pighy

mickey.js's Issues

Detect user's cursor automatically

User's cursor can be ANYTHING, so we cannot depend on drawing shadow's manually, what about cursor themes? without this, our shadow will be limited and pretty useless.

Remove Elements

We need a function ( or just an update for .stop ) to remove Elements created using .shadow, .image and .text.

GitHub Page down?

Not sure if it is just a temporary problem, but I can't seem to access http://mahdi-.github.io/Mickey.js/; it seems to be 404'ing.

edit: Never mind, must have just been temporary.

Shadow's blur

If we want to add blur to shadow, that's not hard in theory,

shadow.shadowBlur = blur,
shadow.shadowColor = color;

But, as long as #1 is there, we can't do that, if we want to add blur, we have to increase canvas' size, and by that, #1 comes in the way.

Remove EventListeners

It could be awesome if Mickey function could be assigned to a variable, and so deleted aftewards, something like this:

var x = Mickey().chase();

Mickey().stop( x )

object in another object

Imagine when someone writes something like this:

click = Mickey().click(function() {
    chase = Mickey().chase();
});

This way, if he wants to stop the .click event, the .chase still remains, because that's assigned to an object that doesn't die! Need an update to remove all objects declared in the function.

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.