-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
72045c1
commit 90fc173
Showing
6 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
lib | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
src/ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,24 @@ | ||
# stylerjs | ||
This is a simple JavaScript function which allows you to get and set CSS styles on DOM elements with ease. | ||
This is a simple JavaScript function which allows you to get and set CSS styles on DOM elements with ease. | ||
|
||
# Step 1 # | ||
|
||
### Install ### | ||
`npm install --save-dev stylerjs` | ||
|
||
# Step 2 # | ||
|
||
### Import to your project (ES5) ### | ||
|
||
`var styler = require('stylerjs');` | ||
|
||
### Import to your project (ES6) ### | ||
|
||
`import styler from 'stylerjs'` | ||
|
||
# Step 3 # | ||
|
||
### Get Styles ### | ||
`var styles = styler('.class-name').get(['height', 'width']);` | ||
|
||
### Set Styles ### | ||
`styler('.class-name').set({ 'height': '50px', 'width': '50px' });` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "spinner", | ||
"version": "1.0.0", | ||
"description": "A simple class allowing you to implement and use your own loading and percentage spinners/loaders.", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"compile": "babel --presets es2015,stage-0 -d lib/ src/", | ||
"prepublish": "npm run compile" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/tjcafferkey/stylerjs.git" | ||
}, | ||
"author": "Tom Cafferkey", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/tjcafferkey/stylerjs/issues" | ||
}, | ||
"homepage": "https://github.com/tjcafferkey/stylerjs#readme", | ||
"devDependencies": { | ||
"babel-cli": "^6.24.1", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babel-preset-stage-0": "^6.24.1", | ||
"chai": "^4.0.2", | ||
"jsdom": "^11.0.0", | ||
"jsdom-global": "^3.0.2", | ||
"mocha": "^3.4.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
export function styler(element) { | ||
function getElement() { | ||
return element instanceof HTMLElement ? element : document.querySelector(element); | ||
} | ||
|
||
return { | ||
get(styles) { | ||
if (!Array.isArray(styles)) { | ||
throw new Error('Second parameter of this function should be an array'); | ||
} | ||
|
||
let elem = getElement(); | ||
let obj = {}; | ||
|
||
if (elem instanceof HTMLElement && styles) { | ||
styles.map((style) => obj[style] = window.getComputedStyle(elem, null).getPropertyValue(style)); | ||
return obj; | ||
} | ||
}, | ||
|
||
set(styles) { | ||
if (typeof styles !== 'object') { | ||
throw new Error('Second parameter of this function should be an object'); | ||
} | ||
|
||
let elem = getElement(); | ||
|
||
if (elem instanceof HTMLElement && styles) { | ||
for (let i in styles) { | ||
elem.style[i] = styles[i]; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import "jsdom-global/register"; | ||
var expect = require("chai").expect; | ||
var assert = require("chai").assert; | ||
|
||
import styler from "../src/index"; | ||
|
||
describe("Styler", function() { | ||
|
||
}); |