diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..e717f5e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# http://editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a088b6f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +bower_components diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..fa51fc3 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,21 @@ +{ + "node": true, + "esnext": true, + "bitwise": true, + "camelcase": true, + "curly": true, + "eqeqeq": true, + "immed": true, + "indent": 4, + "latedef": true, + "newcap": true, + "noarg": true, + "quotmark": "single", + "regexp": true, + "undef": true, + "unused": true, + "strict": true, + "trailing": true, + "smarttabs": true, + "white": true +} diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b9207e5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +node_js: + - '0.8' + - '0.10' diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..1fe6214 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,27 @@ +# Contributing + +## Important notes +Please don't edit files in the `dist` subdirectory as they are generated via [Grunt](http://gruntjs.com/). You'll find source code in the `src` subdirectory! + +### Code style +Regarding code style like indentation and whitespace, **follow the conventions you see used in the source already.** + +## Modifying the code +First, ensure that you have the latest [Node.js](http://nodejs.org/) and [npm](http://npmjs.org/) installed. + +Test that Grunt's CLI is installed by running `grunt --version`. If the command isn't found, run `npm install -g grunt-cli`. For more information about installing Grunt, see the [getting started with Grunt guide](http://gruntjs.com/getting-started). + +1. Fork and clone the repo. +1. Run `npm install` to install all build dependencies (including Grunt). +1. Run `grunt` to grunt this project. + +Assuming that you don't see any red, you're ready to go. Just be sure to run `grunt` after making any changes, to ensure that nothing is broken. + +## Submitting pull requests + +1. Create a new branch, please don't work in your `master` branch directly. +1. Add failing tests for the change you want to make. Run `grunt` to see the tests fail. +1. Fix stuff. +1. Run `grunt` to see if the tests pass. Repeat steps 2-4 until done. +1. Update the documentation to reflect any changes. +1. Push to your fork and submit a pull request. diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..6e250af --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,85 @@ +// Generated on 2013-11-11 using generator-bespokeplugin v0.1.3 + +module.exports = function(grunt) { + + grunt.initConfig({ + pkg: grunt.file.readJSON('package.json'), + meta: { + banner: '/*!\n' + + ' * <%= pkg.title || pkg.name %> v<%= pkg.version %>\n' + + ' * <%= pkg.homepage %>\n' + + ' *\n' + + ' * Copyright <%= grunt.template.today("yyyy") %>, <%= pkg.author.name %>\n' + + ' * This content is released under the' + + ' <%= _.pluck(pkg.licenses, "type").join(", ") %> license<%= pkg.licenses.length === 1 ? "" : "s" %>\n' + + '' + + ' */\n\n', + microbanner: '/*! <%= pkg.title || pkg.name %> v<%= pkg.version %> ' + + '© <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>, ' + + 'Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n' + }, + clean: { + files: ['dist'] + }, + concat: { + options: { + banner: '<%= meta.banner %>', + stripBanners: true + }, + dist: { + src: ['src/<%= pkg.name %>.js'], + dest: 'dist/<%= pkg.name %>.js' + } + }, + uglify: { + options: { + banner: '<%= meta.microbanner %>' + }, + dist: { + src: ['<%= concat.dist.dest %>'], + dest: 'dist/<%= pkg.name %>.min.js' + } + }, + jasmine: { + src: ['src/**/*.js'], + options: { + vendor: ['node_modules/bespoke/dist/bespoke.js'], + specs: 'spec/*Spec.js', + helpers: 'spec/*Helper.js' + } + }, + jshint: { + src: [ + 'Gruntfile.js', + 'src/**/*.js', + 'spec/**/*.js', + 'demo/**/*.js' + ], + options: { + jshintrc: '.jshintrc' + } + }, + micro: { + src: '<%= uglify.dist.dest %>', + options: { + limit: 1024, + gzip: true + } + }, + watch: { + files: '<%= jshint.src %>', + tasks: ['default'] + } + }); + + grunt.loadNpmTasks('grunt-contrib-clean'); + grunt.loadNpmTasks('grunt-contrib-concat'); + grunt.loadNpmTasks('grunt-contrib-uglify'); + grunt.loadNpmTasks('grunt-contrib-jasmine'); + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-contrib-watch'); + grunt.loadNpmTasks('grunt-micro'); + + grunt.registerTask('default', ['clean', 'jasmine', 'concat', 'uglify', 'micro']); + +}; diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c3c53cc --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Copyright 2013 Joel Purra + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8bc7919 --- /dev/null +++ b/README.md @@ -0,0 +1,53 @@ +[![Build Status](https://secure.travis-ci.org/joelpurra/bespoke-active.png?branch=master)](https://travis-ci.org/joelpurra/bespoke-active) + +# bespoke-active + +Keep track of the active slide in [Bespoke.js](http://markdalgleish.com/projects/bespoke.js) + +## Download + +Download the [production version][min] or the [development version][max], or use a [package manager](#package-managers). + +[min]: https://raw.github.com/joelpurra/bespoke-active/master/dist/bespoke-active.min.js +[max]: https://raw.github.com/joelpurra/bespoke-active/master/dist/bespoke-active.js + +## Usage + +First, include both `bespoke.js` and `bespoke-active.js` in your page. + +Then, simply include the plugin when instantiating your presentation. + +```js +bespoke.horizontal.from('article', { + active: true +}); +``` + +## Package managers + +### Bower + +```bash +$ bower install bespoke-active +``` + +### npm + +```bash +$ npm install bespoke-active +``` + +The bespoke-active npm package is designed for use with [browserify](http://browserify.org/), e.g. + +```js +require('bespoke'); +require('bespoke-active'); +``` + +## Credits + +This plugin was built with [generator-bespokeplugin](https://github.com/markdalgleish/generator-bespokeplugin). + +## License + +[MIT License](http://en.wikipedia.org/wiki/MIT_License) diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..1c25529 --- /dev/null +++ b/bower.json @@ -0,0 +1,7 @@ +{ + "name": "bespoke-active", + "version": "0.0.0", + "dependencies": { + "bespoke.js": ">=0.3.0" + } +} \ No newline at end of file diff --git a/demo/demo.js b/demo/demo.js new file mode 100644 index 0000000..d271ed5 --- /dev/null +++ b/demo/demo.js @@ -0,0 +1,3 @@ +bespoke.horizontal.from('article', { + active: true +}); diff --git a/demo/index.html b/demo/index.html new file mode 100644 index 0000000..858946a --- /dev/null +++ b/demo/index.html @@ -0,0 +1,34 @@ + + + + + bespoke-active demo + + + + +

bespoke-active

+ +
+
+

Slide 1

+
+
+

Slide 2

+
+
+

Slide 3

+
+
+

Slide 4

+
+
+

Slide 5

+
+
+ + + + + + diff --git a/demo/style.css b/demo/style.css new file mode 100644 index 0000000..f776515 --- /dev/null +++ b/demo/style.css @@ -0,0 +1,64 @@ +body { + font-family: helvetica, arial, sans-serif; + font-size: 16px; + line-height: 28px; +} + +* { + box-sizing: border-box; + -moz-box-sizing: border-box; + margin: 0; + padding: 0; + color: #303030; +} + +h1 { + height: 25px; + width: 640px; + position: absolute; + top: 50%; + left: 50%; + margin-left: -322px; + margin-top: -290px; + font-size: 32px; + letter-spacing: -1px; +} + +section { + display: none; +} + +.bespoke-parent { + position: absolute; + top: 0; + bottom: 0; + left: 0; + right: 0; +} + +.bespoke-slide { + width: 640px; + height: 480px; + position: absolute; + top: 50%; + margin-top: -240px; + left: 50%; + margin-left: -320px; +} + +section.bespoke-slide { + -webkit-transition: all .3s ease; + -moz-transition: all .3s ease; + -ms-transition: all .3s ease; + -o-transition: all .3s ease; + transition: all .3s ease; + display: block; +} + +.bespoke-inactive { + opacity: 0; +} + +.bespoke-active { + opacity: 1; +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..027132b --- /dev/null +++ b/package.json @@ -0,0 +1,45 @@ +{ + "name": "bespoke-active", + "version": "0.0.0", + "description": "Keep track of the active slide in Bespoke.js", + "homepage": "https://github.com/joelpurra/bespoke-active", + "bugs": "https://github.com/joelpurra/bespoke-active/issues", + "author": { + "name": "Joel Purra", + "url": "https://github.com/joelpurra" + }, + "main": "./dist/bespoke-active.js", + "repository": { + "type": "git", + "url": "git://github.com/joelpurra/bespoke-active.git" + }, + "scripts": { + "test": "grunt" + }, + "peerDependencies": { + "bespoke": ">=0.3.0" + }, + "devDependencies": { + "grunt-cli": "~0.1.9", + "grunt": "~0.4.1", + "grunt-contrib-jshint": "~0.6.4", + "grunt-contrib-jasmine": "~0.5.2", + "grunt-contrib-concat": "~0.3.0", + "grunt-contrib-uglify": "~0.2.4", + "grunt-contrib-clean": "~0.5.0", + "grunt-contrib-watch": "~0.5.3", + "grunt-micro": "~0.1.0", + "bespoke": ">=0.3.0" + }, + "engines": { + "node": ">=0.8.0" + }, + "licenses": [ + { + "type": "MIT" + } + ], + "keywords": [ + "bespoke.js-plugin" + ] +} \ No newline at end of file diff --git a/spec/bespoke-activeSpec.js b/spec/bespoke-activeSpec.js new file mode 100644 index 0000000..baf8df4 --- /dev/null +++ b/spec/bespoke-activeSpec.js @@ -0,0 +1,35 @@ +(function() { + 'use strict'; + + describe("bespoke-active", function() { + + var deck, + + createDeck = function() { + var parent = document.createElement('article'); + for (var i = 0; i < 10; i++) { + parent.appendChild(document.createElement('section')); + } + + deck = bespoke.from(parent, { + active: true + }); + }; + + beforeEach(createDeck); + + describe("deck.slide", function() { + + beforeEach(function() { + deck.slide(0); + }); + + it("should not add a useless 'foobar' class to the slide", function() { + expect(deck.slides[0].classList.contains('foobar')).toBe(false); + }); + + }); + + }); + +}()); diff --git a/src/bespoke-active.js b/src/bespoke-active.js new file mode 100644 index 0000000..ed260ab --- /dev/null +++ b/src/bespoke-active.js @@ -0,0 +1,41 @@ +(function(bespoke) { + + bespoke.plugins.active = function(deck) { + + /* + Interact with the deck + https://github.com/markdalgleish/bespoke.js#deck-instances + */ + deck.next(); + deck.prev(); + deck.slide(0); + + /* + Handle events + https://github.com/markdalgleish/bespoke.js#events + */ + deck.on('activate', function(e) { + console.log('Slide #' + e.index + ' was activated!', e.slide); + }); + + deck.on('deactivate', function(e) { + console.log('Slide #' + e.index + ' was deactivated!', e.slide); + }); + + deck.on('next', function(e) { + console.log('The next slide is #' + (e.index + 1), deck.slides[e.index + 1]); + // return false to cancel user interaction + }); + + deck.on('prev', function(e) { + console.log('The previous slide is #' + (e.index - 1), deck.slides[e.index - 1]); + // return false to cancel user interaction + }); + + deck.on('slide', function(e) { + console.log('The requested slide is #' + e.index, e.slide); + // return false to cancel user interaction + }); + }; + +}(bespoke));