Git Product home page Git Product logo

nialloc9 / inputbordercolorchange Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 120 KB

This is a prototypal inheritance(object composition) project that changes the input border color green or blue depending on the boolean value passed. This was made with re-usability at it's core and can be used as a stand alone object or if the developer wants other objects can 'inherit' from it.

CSS 2.63% HTML 23.49% JavaScript 73.88%

inputbordercolorchange's Introduction

inputBorderColorChange

This is a prototypal inheritance(object composition) project that changes the input border color green or blue depending on the boolean value passed. This was made with re-usability at it's core and can be used as a stand alone object or if the developer wants other objects can 'inherit' from it.

Getting Started

  1. add jQuery to your project.

  2. Add the file public/src/js/addColorInputBox.js to your project

  3. Add css that has 2 classes. One for positive. One for the negative. (Default styling found at public/src/css/styles.css

  4. When you need to add a info message create new instance of the infoMessage object by using the create method.

     var addColorInputBox = addInputBoxColor.create();
    
  5. Call the add method to change the color of your input.

     addColorInputBox.add(boxId, tOrF, positiveClass, negativeClass);
    
  6. If the developer wants to change the styling to the other class then change the value of tOrF.

  7. If you want to remove any colors call the remove method.

     addColorInputBox.remove();
    

create() Arguements

We can pass an optional object of methods and properties that we want to add to our new object here. This is how we use prototypal inheritance(object composition) to create new objects that have the parent addInputBoxColor objects methods and properties but also have new ones.

    //parent 
    var parent = addInputBoxColor.create();

    //child
    var child = parent.create({}
            newMethod: function(){},
            newProperty: 'new property'
    );
    
    //alert newProperty
    alert(child.newProperty); //alerts 'new property'
    
    //alert(parent.newProperty); --> This will fail because newProperty is a property of child not parent

add() Arguements

boxId: The id of the input we want to change. e.g 'myInput'

tOrF: true or false is do you want it to appear with a class of positiveClass or negativeClass

positiveClass: The name of the class you want to style with positive styling . e.g 'myPositiveClass'

negativeClass: The name of the class you want to style with negative styling. e.g 'myNegativeClass'

remove() Arguements

boxId: The id of the input we want to remove. e.g 'myInput'

positiveClass: The name of the positive styling class . e.g 'myPositiveClass'

negativeClass: The name of the negative styling class. e.g 'myNegativeClass'

Dependencies

jQuery

Example

//cache DOM
var $wrapper = $('#wrapper'),
    $green = $wrapper.find('#green'),
    $red = $wrapper.find('#red'),
    $remove = $wrapper.find('#remove');

//events
$green.on('click', greenClick);
$red.on('click', redClick);
$remove.on('click', removeClick);

//create object
var addColorInputBox = addInputBoxColor.create();

//greenClick
function greenClick() {
    addColorInputBox.add('box', true, 'input-success', 'input-error');
}

//redClick
function redClick() {
    addColorInputBox.add('box', false, 'input-success', 'input-error');
}

function removeClick() {
    addColorInputBox.remove('box', 'input-success', 'input-error')
}

Authors

inputbordercolorchange's People

Contributors

nialloc9 avatar

Watchers

James Cloos avatar

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.