This repository has been archived by the owner on Jan 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
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
0 parents
commit a900279
Showing
15 changed files
with
360 additions
and
0 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,12 @@ | ||
# This file is for unifying the coding style for different editors and IDEs | ||
# See editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
indent_style = tab | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
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,4 @@ | ||
bower_components | ||
build | ||
coverage | ||
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,31 @@ | ||
{ | ||
"asi": false, | ||
"bitwise": false, | ||
"browser": true, | ||
"curly": true, | ||
"eqeqeq": true, | ||
"esnext": true, | ||
"evil": false, | ||
"forin": false, | ||
"globals": { | ||
"soy": true, | ||
"soydata": true | ||
}, | ||
"immed": true, | ||
"indent": 2, | ||
"lastsemic": false, | ||
"maxdepth": false, | ||
"multistr": false, | ||
"newcap": true, | ||
"noarg": true, | ||
"node": true, | ||
"onevar": false, | ||
"quotmark": "single", | ||
"proto": true, | ||
"regexp": true, | ||
"smarttabs": true, | ||
"strict": true, | ||
"trailing": true, | ||
"undef": true, | ||
"unused": true | ||
} |
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 @@ | ||
# Software License Agreement (BSD License) | ||
|
||
Copyright (c) 2014, Liferay Inc. | ||
All rights reserved. | ||
|
||
Redistribution and use of this software in source and binary forms, with or without modification, are | ||
permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above | ||
copyright notice, this list of conditions and the | ||
following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the | ||
following disclaimer in the documentation and/or other | ||
materials provided with the distribution. | ||
|
||
* The name of Liferay Inc. may not be used to endorse or promote products | ||
derived from this software without specific prior | ||
written permission of Liferay Inc. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED | ||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | ||
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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,28 @@ | ||
# crystal-toggler | ||
|
||
Crystal's toggler component | ||
|
||
## Setup | ||
|
||
1. Install NodeJS >= [v0.12.0](http://nodejs.org/dist/v0.12.0/), if you don't have it yet. | ||
|
||
2. Install global dependencies: | ||
|
||
``` | ||
[sudo] npm install -g gulp | ||
``` | ||
|
||
3. Install local dependencies: | ||
|
||
``` | ||
npm install | ||
bower install | ||
``` | ||
|
||
4. Build the code: | ||
|
||
``` | ||
gulp build | ||
``` | ||
|
||
|
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,23 @@ | ||
{ | ||
"name": "crystal-toggler", | ||
"version": "0.0.0", | ||
"description": "Crystal's toggler component", | ||
"main": "src/Toggler.js", | ||
"moduleType": [ | ||
"es6" | ||
], | ||
"keywords": [ | ||
"metal", | ||
"crystal" | ||
], | ||
"ignore": [ | ||
"*", | ||
"!src/**/*", | ||
"!test/**/*" | ||
], | ||
"dependencies": { | ||
"bootstrap": "~3.3.4", | ||
"metal": "metal/metal.js#master", | ||
"metal-jquery-adapter": "metal/metal-jquery-adapter#master" | ||
} | ||
} |
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,26 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Demo: Toggler</title> | ||
|
||
<link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.css"> | ||
<link rel="stylesheet" href="../build/toggler.css"> | ||
|
||
<script src="../bower_components/soyutils/soyutils.js"></script> | ||
<script src="../build/globals/toggler.js"></script> | ||
</head> | ||
<body> | ||
<h1>Toggler</h1> | ||
<button class="btn btn-primary">Read more »</button> | ||
<div class="content toggler-collapsed"> | ||
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ea qui sint distinctio recusandae quo ut eaque provident eius eos commodi natus labore culpa modi soluta quia repudiandae nulla ex. Reiciendis cupiditate quis voluptatum atque veniam assumenda itaque perferendis eos voluptatem dolores aut eum. Ut voluptatum amet earum delectus totam unde! | ||
</div> | ||
<script type="text/javascript"> | ||
window.toggler = new crystal.Toggler({ | ||
content: '.content', | ||
header: '.btn-primary' | ||
}); | ||
</script> | ||
</body> | ||
</html> |
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,11 @@ | ||
'use strict'; | ||
|
||
var metal = require('gulp-metal'); | ||
|
||
metal.registerTasks({ | ||
bundleCssFileName: 'toggler.css', | ||
bundleFileName: 'toggler.js', | ||
globalName: 'crystal', | ||
mainBuildJsTasks: ['build:globals'], | ||
moduleName: 'crystal-toggler' | ||
}); |
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,42 @@ | ||
var isparta = require('isparta'); | ||
|
||
var babelOptions = { | ||
presets: ['metal'], | ||
sourceMap: 'both' | ||
}; | ||
|
||
module.exports = function (config) { | ||
config.set({ | ||
frameworks: ['mocha', 'chai', 'source-map-support', 'commonjs'], | ||
|
||
files: [ | ||
'bower_components/soyutils/soyutils.js', | ||
'bower_components/metal/src/**/*.js', | ||
'src/**/*.js', | ||
'test/**/*.js' | ||
], | ||
|
||
preprocessors: { | ||
'src/**/!(*.soy).js': ['coverage', 'commonjs'], | ||
'src/**/*.soy.js': ['babel', 'commonjs'], | ||
'bower_components/metal/**/*.js': ['babel', 'commonjs'], | ||
'test/**/*.js': ['babel', 'commonjs'] | ||
}, | ||
|
||
browsers: ['Chrome'], | ||
|
||
reporters: ['coverage', 'progress'], | ||
|
||
babelPreprocessor: {options: babelOptions}, | ||
|
||
coverageReporter: { | ||
instrumenters: {isparta : isparta}, | ||
instrumenter: {'**/*.js': 'isparta'}, | ||
instrumenterOptions: {isparta: {babel: babelOptions}}, | ||
reporters: [ | ||
{type: 'lcov', subdir: 'lcov'}, | ||
{type: 'text-summary'} | ||
] | ||
} | ||
}); | ||
} |
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,27 @@ | ||
var babelOptions = { | ||
presets: ['metal'], | ||
sourceMap: 'both' | ||
}; | ||
|
||
module.exports = function (config) { | ||
config.set({ | ||
frameworks: ['mocha', 'chai', 'source-map-support', 'commonjs'], | ||
|
||
files: [ | ||
'bower_components/soyutils/soyutils.js', | ||
'bower_components/metal/src/**/*.js', | ||
'src/**/*.js', | ||
'test/**/*.js' | ||
], | ||
|
||
preprocessors: { | ||
'src/**/*.js': ['babel', 'commonjs'], | ||
'bower_components/metal/**/*.js': ['babel', 'commonjs'], | ||
'test/**/*.js': ['babel', 'commonjs'] | ||
}, | ||
|
||
browsers: ['Chrome'], | ||
|
||
babelPreprocessor: {options: babelOptions} | ||
}); | ||
} |
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,33 @@ | ||
{ | ||
"name": "crystal-toggler", | ||
"version": "0.0.0", | ||
"description": "Crystal's toggler component", | ||
"license": "SEE LICENSE IN LICENSE.md", | ||
"repository": "metal/crystal-toggler", | ||
"engines": { | ||
"node": ">=0.12.0" | ||
}, | ||
"scripts": { | ||
"test": "gulp test" | ||
}, | ||
"keywords": [ | ||
"metal", | ||
"crystal" | ||
], | ||
"devDependencies": { | ||
"babel-preset-metal": "^1.0.3", | ||
"chai": "^2.3.0", | ||
"gulp": "^3.8.11", | ||
"gulp-metal": "^0.6.0", | ||
"isparta": "^4.0.0", | ||
"karma": "^0.13.9", | ||
"karma-babel-preprocessor": "^6.0.1", | ||
"karma-chai": "^0.1.0", | ||
"karma-chrome-launcher": "^0.2.0", | ||
"karma-commonjs": "0.0.13", | ||
"karma-coverage": "^0.5.1", | ||
"karma-mocha": "^0.2.0", | ||
"karma-source-map-support": "1.0.0", | ||
"mocha": "^2.2.5" | ||
} | ||
} |
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,72 @@ | ||
'use strict'; | ||
|
||
import core from 'bower:metal/src/core'; | ||
import dom from 'bower:metal/src/dom/dom'; | ||
import Attribute from 'bower:metal/src/attribute/Attribute'; | ||
import EventHandler from 'bower:metal/src/events/EventHandler'; | ||
|
||
class Toggler extends Attribute { | ||
constructor(opt_config) { | ||
super(opt_config); | ||
|
||
this.headerEventHandler_ = new EventHandler(); | ||
|
||
this.on('expandedChanged', this.syncExpanded); | ||
this.on('headerChanged', this.syncHeader); | ||
|
||
this.syncExpanded(); | ||
this.syncHeader(); | ||
} | ||
|
||
handleKeydown(event) { | ||
if (event.keyCode === 13 || event.keyCode === 32) { | ||
this.toggle(); | ||
event.preventDefault(); | ||
} | ||
} | ||
|
||
syncExpanded() { | ||
if (this.expanded) { | ||
dom.addClasses(this.content, Toggler.CSS_EXPANDED); | ||
dom.removeClasses(this.content, Toggler.CSS_COLLAPSED); | ||
} else { | ||
dom.removeClasses(this.content, Toggler.CSS_EXPANDED); | ||
dom.addClasses(this.content, Toggler.CSS_COLLAPSED); | ||
} | ||
} | ||
|
||
syncHeader() { | ||
this.headerEventHandler_.removeAllListeners(); | ||
if (this.header) { | ||
this.headerEventHandler_.add( | ||
dom.on(this.header, 'click', this.toggle.bind(this)), | ||
dom.on(this.header, 'keydown', this.handleKeydown.bind(this)) | ||
); | ||
} | ||
} | ||
|
||
toggle() { | ||
this.expanded = !this.expanded; | ||
} | ||
} | ||
|
||
Toggler.ATTRS = { | ||
content: { | ||
setter: dom.toElement, | ||
validator: value => core.isString(value) || core.isElement(value) | ||
}, | ||
|
||
expanded: { | ||
value: false | ||
}, | ||
|
||
header: { | ||
setter: dom.toElement, | ||
validator: value => core.isString(value) || core.isElement(value) | ||
} | ||
}; | ||
|
||
Toggler.CSS_EXPANDED = 'toggler-expanded'; | ||
Toggler.CSS_COLLAPSED = 'toggler-collapsed'; | ||
|
||
export default Toggler; |
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,6 @@ | ||
/* Toggler | ||
========================================================================== */ | ||
|
||
.toggler-collapsed { | ||
display: none; | ||
} |
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,7 @@ | ||
{ | ||
"mocha": true, | ||
"globals": { | ||
"assert": true | ||
}, | ||
"extends": "../.jshintrc" | ||
} |
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 @@ | ||
'use strict'; | ||
|
||
import Toggler from '../src/Toggler'; | ||
|
||
describe('Toggler', function() { | ||
it('should be tested', function() { | ||
assert.fail('No tests for this module yet.'); | ||
}); | ||
}); |