From 668f03459231f97081dd504cb49961a0d5884d01 Mon Sep 17 00:00:00 2001 From: Alexei Zaviruha Date: Wed, 12 Oct 2016 20:15:03 +0300 Subject: [PATCH 01/17] Add babel, eslint, nvm --- .babelrc | 4 + .eslintrc.json | 13 + .nvmrc | 1 + dist/old/v1.1.0/pager.js | 256 ----------------- dist/old/v1.1.0/pager.min.js | 1 - dist/pager.js | 535 ++++++++++++++++++----------------- dist/pager.js.map | 1 + dist/pager.min.js | 1 - gulpfile.js | 100 ++----- package.json | 33 +-- src/pager.jsx | 392 +++++++++++++------------ 11 files changed, 540 insertions(+), 797 deletions(-) create mode 100644 .babelrc create mode 100644 .eslintrc.json create mode 100644 .nvmrc delete mode 100644 dist/old/v1.1.0/pager.js delete mode 100644 dist/old/v1.1.0/pager.min.js create mode 100644 dist/pager.js.map delete mode 100644 dist/pager.min.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..f1957f1 --- /dev/null +++ b/.babelrc @@ -0,0 +1,4 @@ +{ + "presets": ["latest", "react"], + "plugins": ["transform-es2015-modules-umd"] +} \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..7d29dc1 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,13 @@ +{ + "parser": "babel-eslint", + "extends": "airbnb", + "rules": { + "indent": [1, "tab"], + "no-tabs": "off", + "no-multi-spaces": "off", + "key-spacing": "off", + "no-plusplus": "off", + "react/jsx-indent": [2, "tab"], + "react/jsx-indent-props": [2, "tab"] + } +} \ No newline at end of file diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..7648508 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +6.7.9 diff --git a/dist/old/v1.1.0/pager.js b/dist/old/v1.1.0/pager.js deleted file mode 100644 index f851652..0000000 --- a/dist/old/v1.1.0/pager.js +++ /dev/null @@ -1,256 +0,0 @@ -/** @jsx React.DOM */ - -/** - * # Stateless Pager component - * - * ## Usage - * ``` - * >>", - * next: "Next", - * last: "Last" - * }} /> - * ``` - * - * ## How it looks like - * ``` - * First | Prev | ... | 6 | 7 | 8 | 9 | ... | Next | Last - * ``` - * - */ - -var React = require( 'react' ); - - -/** - * ## Constants - */ -var BASE_SHIFT = 0 - , TITLE_SHIFT = 1 - , TITLES = { - first: 'First', - prev: '\u00AB', - prevSet: '...', - nextSet: '...', - next: '\u00BB', - last: 'Last' - }; - -/** - * ## Constructor - */ -var Pager = React.createClass({displayName: "Pager", - propTypes: { - current: React.PropTypes.number.isRequired, - total: React.PropTypes.number.isRequired, - visiblePages: React.PropTypes.number.isRequired, - titles: React.PropTypes.object, - - onPageChanged: React.PropTypes.func, - onPageSizeChanged: React.PropTypes.func - }, - - - /* ========================= HANDLERS =============================*/ - handleFirstPage: function () { - if ( this.isPrevDisabled() ) return; - this.handlePageChanged( BASE_SHIFT ); - }, - - handlePreviousPage: function () { - if ( this.isPrevDisabled() ) return; - this.handlePageChanged( this.props.current - TITLE_SHIFT ); - }, - - handleNextPage: function () { - if ( this.isNextDisabled() ) return; - this.handlePageChanged( this.props.current + TITLE_SHIFT ); - }, - - handleLastPage: function () { - if ( this.isNextDisabled() ) return; - this.handlePageChanged( this.props.total - TITLE_SHIFT ); - }, - - /** - * Chooses page, that is one before min of currently visible - * pages. - */ - handleMorePrevPages: function () { - var blocks = this.calcBlocks(); - this.handlePageChanged( blocks.current * blocks.size - TITLE_SHIFT ); - }, - - /** - * Chooses page, that is one after max of currently visible - * pages. - */ - handleMoreNextPages: function () { - var blocks = this.calcBlocks(); - this.handlePageChanged( (blocks.current + TITLE_SHIFT) * blocks.size ); - }, - - handlePageChanged: function ( el ) { - var handler = this.props.onPageChanged; - if ( handler ) handler( el ); - }, - - - /* ========================= HELPERS ==============================*/ - /** - * Calculates "blocks" of buttons with page numbers. - */ - calcBlocks: function () { - var props = this.props - , total = props.total - , blockSize = props.visiblePages - , current = props.current + TITLE_SHIFT - - , blocks = Math.ceil( total / blockSize ) - , currBlock = Math.ceil( current / blockSize ) - TITLE_SHIFT; - - return { - total: blocks, - current: currBlock, - size: blockSize - }; - }, - - isPrevDisabled: function () { - return this.props.current <= BASE_SHIFT; - }, - - isNextDisabled: function () { - return this.props.current >= ( this.props.total - TITLE_SHIFT ); - }, - - isPrevMoreHidden: function () { - var blocks = this.calcBlocks(); - return ( blocks.total === TITLE_SHIFT ) - || ( blocks.current === BASE_SHIFT ); - }, - - isNextMoreHidden: function () { - var blocks = this.calcBlocks(); - return ( blocks.total === TITLE_SHIFT ) - || ( blocks.current === (blocks.total - TITLE_SHIFT) ); - }, - - visibleRange: function () { - var blocks = this.calcBlocks() - , start = blocks.current * blocks.size - , delta = this.props.total - start - , end = start + ( (delta > blocks.size) ? blocks.size : delta ); - return [ start + TITLE_SHIFT, end + TITLE_SHIFT ]; - }, - - - getTitles: function ( key ) { - var pTitles = this.props.titles || {}; - return pTitles[ key ] || TITLES[ key ]; - }, - - /* ========================= RENDERS ==============================*/ - render: function () { - var titles = this.getTitles; - - return ( - React.createElement("nav", null, - React.createElement("ul", {className: "pagination"}, - React.createElement(Page, {className: "btn-first-page", - key: "btn-first-page", - isDisabled: this.isPrevDisabled(), - onClick: this.handleFirstPage}, titles('first')), - - React.createElement(Page, {className: "btn-prev-page", - key: "btn-prev-page", - isDisabled: this.isPrevDisabled(), - onClick: this.handlePreviousPage}, titles('prev')), - - React.createElement(Page, {className: "btn-prev-more", - key: "btn-prev-more", - isHidden: this.isPrevMoreHidden(), - onClick: this.handleMorePrevPages}, titles('prevSet')), - - this.renderPages( this.visibleRange()), - - React.createElement(Page, {className: "btn-next-more", - key: "btn-next-more", - isHidden: this.isNextMoreHidden(), - onClick: this.handleMoreNextPages}, titles('nextSet')), - - React.createElement(Page, {className: "btn-next-page", - key: "btn-next-page", - isDisabled: this.isNextDisabled(), - onClick: this.handleNextPage}, titles('next')), - - React.createElement(Page, {className: "btn-last-page", - key: "btn-last-page", - isDisabled: this.isNextDisabled(), - onClick: this.handleLastPage}, titles('last')) - ) - ) - ); - }, - - - /** - * ### renderPages() - * Renders block of pages' buttons with numbers. - * @param {Number[]} range - pair of [start, from], `from` - not inclusive. - * @return {React.Element[]} - array of React nodes. - */ - renderPages: function ( pair ) { - var self = this; - - return range( pair[0], pair[1] ).map(function ( el, idx ) { - var current = el - TITLE_SHIFT - , onClick = self.handlePageChanged.bind(null, current) - , isActive = (self.props.current === current); - - return (React.createElement(Page, {key: idx, isActive: isActive, - className: "btn-numbered-page", - onClick: onClick}, el)); - }); - } -}); - - - -var Page = React.createClass({displayName: "Page", - render: function () { - var props = this.props; - if ( props.isHidden ) return null; - - var baseCss = props.className ? props.className + ' ' : '' - , css = baseCss - + (props.isActive ? 'active' : '') - + (props.isDisabled ? ' disabled' : ''); - - return ( - React.createElement("li", {key: this.props.key, className: css}, - React.createElement("a", {onClick: this.props.onClick}, this.props.children) - ) - ); - } -}); - - - -function range ( start, end ) { - var res = []; - for ( var i = start; i < end; i++ ) { - res.push( i ); - } - - return res; -} - -module.exports = Pager; diff --git a/dist/old/v1.1.0/pager.min.js b/dist/old/v1.1.0/pager.min.js deleted file mode 100644 index ec84dd9..0000000 --- a/dist/old/v1.1.0/pager.min.js +++ /dev/null @@ -1 +0,0 @@ -function range(e,t){for(var a=[],s=e;t>s;s++)a.push(s);return a}var BASE_SHIFT=0,TITLE_SHIFT=1,TITLES={first:"First",prev:"«",prevSet:"...",nextSet:"...",next:"»",last:"Last"},Pager=React.createClass({displayName:"Pager",propTypes:{current:React.PropTypes.number.isRequired,total:React.PropTypes.number.isRequired,visiblePages:React.PropTypes.number.isRequired,titles:React.PropTypes.object,onPageChanged:React.PropTypes.func,onPageSizeChanged:React.PropTypes.func},handleFirstPage:function(){this.isPrevDisabled()||this.handlePageChanged(BASE_SHIFT)},handlePreviousPage:function(){this.isPrevDisabled()||this.handlePageChanged(this.props.current-TITLE_SHIFT)},handleNextPage:function(){this.isNextDisabled()||this.handlePageChanged(this.props.current+TITLE_SHIFT)},handleLastPage:function(){this.isNextDisabled()||this.handlePageChanged(this.props.total-TITLE_SHIFT)},handleMorePrevPages:function(){var e=this.calcBlocks();this.handlePageChanged(e.current*e.size-TITLE_SHIFT)},handleMoreNextPages:function(){var e=this.calcBlocks();this.handlePageChanged((e.current+TITLE_SHIFT)*e.size)},handlePageChanged:function(e){var t=this.props.onPageChanged;t&&t(e)},calcBlocks:function(){var e=this.props,t=e.total,a=e.visiblePages,s=e.current+TITLE_SHIFT,i=Math.ceil(t/a),n=Math.ceil(s/a)-TITLE_SHIFT;return{total:i,current:n,size:a}},isPrevDisabled:function(){return this.props.current<=BASE_SHIFT},isNextDisabled:function(){return this.props.current>=this.props.total-TITLE_SHIFT},isPrevMoreHidden:function(){var e=this.calcBlocks();return e.total===TITLE_SHIFT||e.current===BASE_SHIFT},isNextMoreHidden:function(){var e=this.calcBlocks();return e.total===TITLE_SHIFT||e.current===e.total-TITLE_SHIFT},visibleRange:function(){var e=this.calcBlocks(),t=e.current*e.size,a=this.props.total-t,s=t+(a>e.size?e.size:a);return[t+TITLE_SHIFT,s+TITLE_SHIFT]},getTitles:function(e){var t=this.props.titles||{};return t[e]||TITLES[e]},render:function(){var e=this.getTitles;return React.createElement("nav",null,React.createElement("ul",{className:"pagination"},React.createElement(Page,{className:"btn-first-page",isDisabled:this.isPrevDisabled(),onClick:this.handleFirstPage},e("first")),React.createElement(Page,{className:"btn-prev-page",isDisabled:this.isPrevDisabled(),onClick:this.handlePreviousPage},e("prev")),React.createElement(Page,{className:"btn-prev-more",isHidden:this.isPrevMoreHidden(),onClick:this.handleMorePrevPages},e("prevSet")),this.renderPages(this.visibleRange()),React.createElement(Page,{className:"btn-next-more",isHidden:this.isNextMoreHidden(),onClick:this.handleMoreNextPages},e("nextSet")),React.createElement(Page,{className:"btn-next-page",isDisabled:this.isNextDisabled(),onClick:this.handleNextPage},e("next")),React.createElement(Page,{className:"btn-last-page",isDisabled:this.isNextDisabled(),onClick:this.handleLastPage},e("last"))))},renderPages:function(e){var t=this;return range(e[0],e[1]).map(function(e,a){var s=e-TITLE_SHIFT,i=t.handlePageChanged.bind(null,s),n=t.props.current===s;return React.createElement(Page,{key:a,isActive:n,className:"btn-numbered-page",onClick:i},e)})}}),Page=React.createClass({displayName:"Page",render:function(){var e=this.props;if(e.isHidden)return null;var t=e.className?e.className+" ":"",a=t+(e.isActive?"active":"")+(e.isDisabled?" disabled":"");return React.createElement("li",{key:this.props.key,className:a},React.createElement("a",{onClick:this.props.onClick},this.props.children))}});window.Pager=window.Pager||Pager; \ No newline at end of file diff --git a/dist/pager.js b/dist/pager.js index fd9f8b5..ac462f8 100644 --- a/dist/pager.js +++ b/dist/pager.js @@ -1,254 +1,283 @@ -/** - * # Stateless Pager component - * - * ## Usage - * ``` - * >>", - * next: "Next", - * last: "Last" - * }} /> - * ``` - * - * ## How it looks like - * ``` - * First | Prev | ... | 6 | 7 | 8 | 9 | ... | Next | Last - * ``` - * - */ - -var React = require( 'react' ); - - -/** - * ## Constants - */ -var BASE_SHIFT = 0 - , TITLE_SHIFT = 1 - , TITLES = { - first: 'First', - prev: '\u00AB', - prevSet: '...', - nextSet: '...', - next: '\u00BB', - last: 'Last' - }; - -/** - * ## Constructor - */ -var Pager = React.createClass({displayName: "Pager", - propTypes: { - current: React.PropTypes.number.isRequired, - total: React.PropTypes.number.isRequired, - visiblePages: React.PropTypes.number.isRequired, - titles: React.PropTypes.object, - - onPageChanged: React.PropTypes.func, - onPageSizeChanged: React.PropTypes.func - }, - - - /* ========================= HANDLERS =============================*/ - handleFirstPage: function () { - if ( this.isPrevDisabled() ) return; - this.handlePageChanged( BASE_SHIFT ); - }, - - handlePreviousPage: function () { - if ( this.isPrevDisabled() ) return; - this.handlePageChanged( this.props.current - TITLE_SHIFT ); - }, - - handleNextPage: function () { - if ( this.isNextDisabled() ) return; - this.handlePageChanged( this.props.current + TITLE_SHIFT ); - }, - - handleLastPage: function () { - if ( this.isNextDisabled() ) return; - this.handlePageChanged( this.props.total - TITLE_SHIFT ); - }, - - /** - * Chooses page, that is one before min of currently visible - * pages. - */ - handleMorePrevPages: function () { - var blocks = this.calcBlocks(); - this.handlePageChanged( blocks.current * blocks.size - TITLE_SHIFT ); - }, - - /** - * Chooses page, that is one after max of currently visible - * pages. - */ - handleMoreNextPages: function () { - var blocks = this.calcBlocks(); - this.handlePageChanged( (blocks.current + TITLE_SHIFT) * blocks.size ); - }, - - handlePageChanged: function ( el ) { - var handler = this.props.onPageChanged; - if ( handler ) handler( el ); - }, - - - /* ========================= HELPERS ==============================*/ - /** - * Calculates "blocks" of buttons with page numbers. - */ - calcBlocks: function () { - var props = this.props - , total = props.total - , blockSize = props.visiblePages - , current = props.current + TITLE_SHIFT - - , blocks = Math.ceil( total / blockSize ) - , currBlock = Math.ceil( current / blockSize ) - TITLE_SHIFT; - - return { - total: blocks, - current: currBlock, - size: blockSize - }; - }, - - isPrevDisabled: function () { - return this.props.current <= BASE_SHIFT; - }, - - isNextDisabled: function () { - return this.props.current >= ( this.props.total - TITLE_SHIFT ); - }, - - isPrevMoreHidden: function () { - var blocks = this.calcBlocks(); - return ( blocks.total === TITLE_SHIFT ) - || ( blocks.current === BASE_SHIFT ); - }, - - isNextMoreHidden: function () { - var blocks = this.calcBlocks(); - return ( blocks.total === TITLE_SHIFT ) - || ( blocks.current === (blocks.total - TITLE_SHIFT) ); - }, - - visibleRange: function () { - var blocks = this.calcBlocks() - , start = blocks.current * blocks.size - , delta = this.props.total - start - , end = start + ( (delta > blocks.size) ? blocks.size : delta ); - return [ start + TITLE_SHIFT, end + TITLE_SHIFT ]; - }, - - - getTitles: function ( key ) { - var pTitles = this.props.titles || {}; - return pTitles[ key ] || TITLES[ key ]; - }, - - /* ========================= RENDERS ==============================*/ - render: function () { - var titles = this.getTitles; - - return ( - React.createElement("nav", null, - React.createElement("ul", {className: "pagination"}, - React.createElement(Page, {className: "btn-first-page", - key: "btn-first-page", - isDisabled: this.isPrevDisabled(), - onClick: this.handleFirstPage}, titles('first')), - - React.createElement(Page, {className: "btn-prev-page", - key: "btn-prev-page", - isDisabled: this.isPrevDisabled(), - onClick: this.handlePreviousPage}, titles('prev')), - - React.createElement(Page, {className: "btn-prev-more", - key: "btn-prev-more", - isHidden: this.isPrevMoreHidden(), - onClick: this.handleMorePrevPages}, titles('prevSet')), - - this.renderPages( this.visibleRange()), - - React.createElement(Page, {className: "btn-next-more", - key: "btn-next-more", - isHidden: this.isNextMoreHidden(), - onClick: this.handleMoreNextPages}, titles('nextSet')), - - React.createElement(Page, {className: "btn-next-page", - key: "btn-next-page", - isDisabled: this.isNextDisabled(), - onClick: this.handleNextPage}, titles('next')), - - React.createElement(Page, {className: "btn-last-page", - key: "btn-last-page", - isDisabled: this.isNextDisabled(), - onClick: this.handleLastPage}, titles('last')) - ) - ) - ); - }, - - - /** - * ### renderPages() - * Renders block of pages' buttons with numbers. - * @param {Number[]} range - pair of [start, from], `from` - not inclusive. - * @return {React.Element[]} - array of React nodes. - */ - renderPages: function ( pair ) { - var self = this; - - return range( pair[0], pair[1] ).map(function ( el, idx ) { - var current = el - TITLE_SHIFT - , onClick = self.handlePageChanged.bind(null, current) - , isActive = (self.props.current === current); - - return (React.createElement(Page, {key: idx, index: idx, isActive: isActive, - className: "btn-numbered-page", - onClick: onClick}, el)); - }); - } +(function (global, factory) { + if (typeof define === "function" && define.amd) { + define(['exports', 'react'], factory); + } else if (typeof exports !== "undefined") { + factory(exports, require('react')); + } else { + var mod = { + exports: {} + }; + factory(mod.exports, global.react); + global.pager = mod.exports; + } +})(this, function (exports, _react) { + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + var _react2 = _interopRequireDefault(_react); + + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + + /** + * ## Constants + */ + var BASE_SHIFT = 0; /** + * # Stateless Pager component + * + * ## Usage + * ``` + * >>", + * next: "Next", + * last: "Last" + * }} /> + * ``` + * + * ## How it looks like + * ``` + * First | Prev | ... | 6 | 7 | 8 | 9 | ... | Next | Last + * ``` + * + */ + + var TITLE_SHIFT = 1; + + var TITLES = { + first: 'First', + prev: '\xAB', + prevSet: '...', + nextSet: '...', + next: '\xBB', + last: 'Last' + }; + + /** + * ## Constructor + */ + var Pager = _react2.default.createClass({ + displayName: 'Pager', + + propTypes: { + current: _react2.default.PropTypes.number.isRequired, + total: _react2.default.PropTypes.number.isRequired, + visiblePages: _react2.default.PropTypes.number.isRequired, + titles: _react2.default.PropTypes.object, + + onPageChanged: _react2.default.PropTypes.func, + onPageSizeChanged: _react2.default.PropTypes.func + }, + + getTitles: function getTitles(key) { + return (this.props.titles || TITLES)[key]; + }, + calcBlocks: function calcBlocks() { + var props = this.props; + var total = props.total; + var blockSize = props.visiblePages; + var current = props.current + TITLE_SHIFT; + var blocks = Math.ceil(total / blockSize); + var currBlock = Math.ceil(current / blockSize) - TITLE_SHIFT; + + return { + total: blocks, + current: currBlock, + size: blockSize + }; + }, + isPrevDisabled: function isPrevDisabled() { + return this.props.current <= BASE_SHIFT; + }, + isNextDisabled: function isNextDisabled() { + return this.props.current >= this.props.total - TITLE_SHIFT; + }, + isPrevMoreHidden: function isPrevMoreHidden() { + var blocks = this.calcBlocks(); + return blocks.total === TITLE_SHIFT || blocks.current === BASE_SHIFT; + }, + isNextMoreHidden: function isNextMoreHidden() { + var blocks = this.calcBlocks(); + return blocks.total === TITLE_SHIFT || blocks.current === blocks.total - TITLE_SHIFT; + }, + visibleRange: function visibleRange() { + var blocks = this.calcBlocks(); + var start = blocks.current * blocks.size; + var delta = this.props.total - start; + var end = start + (delta > blocks.size ? blocks.size : delta); + + return [start + TITLE_SHIFT, end + TITLE_SHIFT]; + }, + handleFirstPage: function handleFirstPage() { + if (!this.isPrevDisabled()) { + this.handlePageChanged(BASE_SHIFT); + } + }, + handlePreviousPage: function handlePreviousPage() { + if (!this.isPrevDisabled()) { + this.handlePageChanged(this.props.current - TITLE_SHIFT); + } + }, + handleNextPage: function handleNextPage() { + if (!this.isNextDisabled()) { + this.handlePageChanged(this.props.current + TITLE_SHIFT); + } + }, + handleLastPage: function handleLastPage() { + if (!this.isNextDisabled()) { + this.handlePageChanged(this.props.total - TITLE_SHIFT); + } + }, + handleMorePrevPages: function handleMorePrevPages() { + var blocks = this.calcBlocks(); + this.handlePageChanged(blocks.current * blocks.size - TITLE_SHIFT); + }, + handleMoreNextPages: function handleMoreNextPages() { + var blocks = this.calcBlocks(); + this.handlePageChanged((blocks.current + TITLE_SHIFT) * blocks.size); + }, + handlePageChanged: function handlePageChanged(el) { + var handler = this.props.onPageChanged; + if (handler) handler(el); + }, + renderPages: function renderPages(pair) { + var _this = this; + + return range(pair[0], pair[1]).map(function (el, idx) { + var current = el - TITLE_SHIFT; + var onClick = _this.handlePageChanged.bind(null, current); + var isActive = _this.props.current === current; + + return _react2.default.createElement( + Page, + { + key: idx, + index: idx, isActive: isActive, + className: 'btn-numbered-page', + onClick: onClick + }, + el + ); + }); + }, + render: function render() { + var titles = this.getTitles; + + return _react2.default.createElement( + 'nav', + null, + _react2.default.createElement( + 'ul', + { className: 'pagination' }, + _react2.default.createElement( + Page, + { + className: 'btn-first-page', + key: 'btn-first-page', + isDisabled: this.isPrevDisabled(), + onClick: this.handleFirstPage + }, + titles('first') + ), + _react2.default.createElement( + Page, + { + className: 'btn-prev-page', + key: 'btn-prev-page', + isDisabled: this.isPrevDisabled(), + onClick: this.handlePreviousPage + }, + titles('prev') + ), + _react2.default.createElement( + Page, + { + className: 'btn-prev-more', + key: 'btn-prev-more', + isHidden: this.isPrevMoreHidden(), + onClick: this.handleMorePrevPages + }, + titles('prevSet') + ), + this.renderPages(this.visibleRange()), + _react2.default.createElement( + Page, + { + className: 'btn-next-more', + key: 'btn-next-more', + isHidden: this.isNextMoreHidden(), + onClick: this.handleMoreNextPages + }, + titles('nextSet') + ), + _react2.default.createElement( + Page, + { + className: 'btn-next-page', + key: 'btn-next-page', + isDisabled: this.isNextDisabled(), + onClick: this.handleNextPage + }, + titles('next') + ), + _react2.default.createElement( + Page, + { + className: 'btn-last-page', + key: 'btn-last-page', + isDisabled: this.isNextDisabled(), + onClick: this.handleLastPage + }, + titles('last') + ) + ) + ); + } + }); + + var Page = _react2.default.createClass({ + displayName: 'Page', + render: function render() { + var props = this.props; + + if (props.isHidden) return null; + + var baseCss = props.className ? props.className + ' ' : ''; + var css = baseCss + (props.isActive ? 'active' : '') + (props.isDisabled ? ' disabled' : ''); + + return _react2.default.createElement( + 'li', + { key: this.props.index, className: css }, + _react2.default.createElement( + 'a', + { onClick: this.props.onClick }, + this.props.children + ) + ); + } + }); + + function range(start, end) { + var res = []; + for (var i = start; i < end; i++) { + res.push(i); + } + + return res; + } + + exports.default = Pager; }); - - - -var Page = React.createClass({displayName: "Page", - render: function () { - var props = this.props; - if ( props.isHidden ) return null; - - var baseCss = props.className ? props.className + ' ' : '' - , css = baseCss - + (props.isActive ? 'active' : '') - + (props.isDisabled ? ' disabled' : ''); - - return ( - React.createElement("li", {key: this.props.index, className: css}, - React.createElement("a", {onClick: this.props.onClick}, this.props.children) - ) - ); - } -}); - - - -function range ( start, end ) { - var res = []; - for ( var i = start; i < end; i++ ) { - res.push( i ); - } - - return res; -} - -module.exports = Pager; +//# sourceMappingURL=pager.js.map diff --git a/dist/pager.js.map b/dist/pager.js.map new file mode 100644 index 0000000..abf1ed8 --- /dev/null +++ b/dist/pager.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["pager.jsx"],"names":["BASE_SHIFT","TITLE_SHIFT","TITLES","first","prev","prevSet","nextSet","next","last","Pager","createClass","propTypes","current","PropTypes","number","isRequired","total","visiblePages","titles","object","onPageChanged","func","onPageSizeChanged","getTitles","key","props","calcBlocks","blockSize","blocks","Math","ceil","currBlock","size","isPrevDisabled","isNextDisabled","isPrevMoreHidden","isNextMoreHidden","visibleRange","start","delta","end","handleFirstPage","handlePageChanged","handlePreviousPage","handleNextPage","handleLastPage","handleMorePrevPages","handleMoreNextPages","el","handler","renderPages","pair","range","map","idx","onClick","bind","isActive","render","Page","isHidden","baseCss","className","css","isDisabled","index","children","res","i","push"],"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BAAMjD,WAAN,CAAkB;AAAA;AAC9BgD,QAD8B,oBACrB;AACR,OAAMjC,QAAQ,KAAKA,KAAnB;;AAEA,OAAIA,MAAMmC,QAAV,EAAoB,OAAO,IAAP;;AAEpB,OAAMC,UAAUpC,MAAMqC,SAAN,GAAqBrC,MAAMqC,SAA3B,SAA0C,EAA1D;AACA,OAAMC,MAAMF,WACLpC,MAAMgC,QAAN,GAAiB,QAAjB,GAA4B,EADvB,KAELhC,MAAMuC,UAAN,GAAmB,WAAnB,GAAiC,EAF5B,CAAZ;;AAIA,UACC;AAAA;AAAA,MAAI,KAAK,KAAKvC,KAAL,CAAWwC,KAApB,EAA2B,WAAWF,GAAtC;AACC;AAAA;AAAA,OAAG,SAAS,KAAKtC,KAAL,CAAW8B,OAAvB;AAAiC,UAAK9B,KAAL,CAAWyC;AAA5C;AADD,IADD;AAKA;AAhB6B,EAAlB,CAAb;;AAoBA,UAASd,KAAT,CAAed,KAAf,EAAsBE,GAAtB,EAA2B;AAC1B,MAAM2B,MAAM,EAAZ;AACA,OAAK,IAAIC,IAAI9B,KAAb,EAAoB8B,IAAI5B,GAAxB,EAA6B4B,GAA7B,EAAkC;AACjCD,OAAIE,IAAJ,CAASD,CAAT;AACA;;AAED,SAAOD,GAAP;AACA;;mBAEc1D","file":"pager.js","sourcesContent":["/**\n * # Stateless Pager component\n *\n * ## Usage\n * ```\n * >>\",\n * next: \"Next\",\n * last: \"Last\"\n * }} />\n * ```\n *\n * ## How it looks like\n * ```\n * First | Prev | ... | 6 | 7 | 8 | 9 | ... | Next | Last\n * ```\n *\n */\n\nimport React from 'react';\n\n\n/**\n * ## Constants\n */\nconst BASE_SHIFT = 0;\nconst TITLE_SHIFT = 1;\n\nconst TITLES = {\n\tfirst: 'First',\n\tprev: '\\u00AB',\n\tprevSet: '...',\n\tnextSet: '...',\n\tnext: '\\u00BB',\n\tlast: 'Last',\n};\n\n\n/**\n * ## Constructor\n */\nconst Pager = React.createClass({\n\tpropTypes: {\n\t\tcurrent: React.PropTypes.number.isRequired,\n\t\ttotal: React.PropTypes.number.isRequired,\n\t\tvisiblePages: React.PropTypes.number.isRequired,\n\t\ttitles: React.PropTypes.object,\n\n\t\tonPageChanged: React.PropTypes.func,\n\t\tonPageSizeChanged: React.PropTypes.func,\n\t},\n\n /* ========================= HELPERS ==============================*/\n\tgetTitles(key) {\n\t\treturn (this.props.titles || TITLES)[key];\n\t},\n\n /**\n * Calculates \"blocks\" of buttons with page numbers.\n */\n\tcalcBlocks() {\n\t\tconst props = this.props;\n\t\tconst total = props.total;\n\t\tconst blockSize = props.visiblePages;\n\t\tconst current = props.current + TITLE_SHIFT;\n\t\tconst blocks = Math.ceil(total / blockSize);\n\t\tconst currBlock = Math.ceil(current / blockSize) - TITLE_SHIFT;\n\n\t\treturn {\n\t\t\ttotal: blocks,\n\t\t\tcurrent: currBlock,\n\t\t\tsize: blockSize,\n\t\t};\n\t},\n\n\tisPrevDisabled() {\n\t\treturn this.props.current <= BASE_SHIFT;\n\t},\n\n\tisNextDisabled() {\n\t\treturn this.props.current >= (this.props.total - TITLE_SHIFT);\n\t},\n\n\tisPrevMoreHidden() {\n\t\tconst blocks = this.calcBlocks();\n\t\treturn (blocks.total === TITLE_SHIFT) || (blocks.current === BASE_SHIFT);\n\t},\n\n\tisNextMoreHidden() {\n\t\tconst blocks = this.calcBlocks();\n\t\treturn (blocks.total === TITLE_SHIFT) || (blocks.current === (blocks.total - TITLE_SHIFT));\n\t},\n\n\tvisibleRange() {\n\t\tconst blocks = this.calcBlocks();\n\t\tconst start = blocks.current * blocks.size;\n\t\tconst delta = this.props.total - start;\n\t\tconst end = start + ((delta > blocks.size) ? blocks.size : delta);\n\n\t\treturn [start + TITLE_SHIFT, end + TITLE_SHIFT];\n\t},\n\n\n /* ========================= HANDLERS =============================*/\n\thandleFirstPage() {\n\t\tif (!this.isPrevDisabled()) {\n\t\t\tthis.handlePageChanged(BASE_SHIFT);\n\t\t}\n\t},\n\n\thandlePreviousPage() {\n\t\tif (!this.isPrevDisabled()) {\n\t\t\tthis.handlePageChanged(this.props.current - TITLE_SHIFT);\n\t\t}\n\t},\n\n\thandleNextPage() {\n\t\tif (!this.isNextDisabled()) {\n\t\t\tthis.handlePageChanged(this.props.current + TITLE_SHIFT);\n\t\t}\n\t},\n\n\thandleLastPage() {\n\t\tif (!this.isNextDisabled()) {\n\t\t\tthis.handlePageChanged(this.props.total - TITLE_SHIFT);\n\t\t}\n\t},\n\n /**\n * Chooses page, that is one before min of currently visible\n * pages.\n */\n\thandleMorePrevPages() {\n\t\tconst blocks = this.calcBlocks();\n\t\tthis.handlePageChanged((blocks.current * blocks.size) - TITLE_SHIFT);\n\t},\n\n /**\n * Chooses page, that is one after max of currently visible\n * pages.\n */\n\thandleMoreNextPages() {\n\t\tconst blocks = this.calcBlocks();\n\t\tthis.handlePageChanged((blocks.current + TITLE_SHIFT) * blocks.size);\n\t},\n\n\thandlePageChanged(el) {\n\t\tconst handler = this.props.onPageChanged;\n\t\tif (handler) handler(el);\n\t},\n\n\n /* ========================= RENDERS ==============================*/\n /**\n * ### renderPages()\n * Renders block of pages' buttons with numbers.\n * @param {Number[]} range - pair of [start, from], `from` - not inclusive.\n * @return {React.Element[]} - array of React nodes.\n */\n\trenderPages(pair) {\n\t\treturn range(pair[0], pair[1]).map((el, idx) => {\n\t\t\tconst current = el - TITLE_SHIFT;\n\t\t\tconst onClick = this.handlePageChanged.bind(null, current);\n\t\t\tconst isActive = (this.props.current === current);\n\n\t\t\treturn (\n\t\t\t\t{el}\n\t\t\t);\n\t\t});\n\t},\n\n\n\trender() {\n\t\tconst titles = this.getTitles;\n\n\t\treturn (\n\t\t\t\n\t\t);\n\t},\n});\n\n\nconst Page = React.createClass({\n\trender() {\n\t\tconst props = this.props;\n\n\t\tif (props.isHidden) return null;\n\n\t\tconst baseCss = props.className ? `${props.className} ` : '';\n\t\tconst css = baseCss\n\t\t\t\t\t\t+ (props.isActive ? 'active' : '')\n\t\t\t\t\t\t+ (props.isDisabled ? ' disabled' : '');\n\n\t\treturn (\n\t\t\t
  • \n\t\t\t\t{this.props.children}\n\t\t\t
  • \n\t\t);\n\t},\n});\n\n\nfunction range(start, end) {\n\tconst res = [];\n\tfor (let i = start; i < end; i++) {\n\t\tres.push(i);\n\t}\n\n\treturn res;\n}\n\nexport default Pager;\n"]} \ No newline at end of file diff --git a/dist/pager.min.js b/dist/pager.min.js deleted file mode 100644 index 65da4e4..0000000 --- a/dist/pager.min.js +++ /dev/null @@ -1 +0,0 @@ -function range(e,t){for(var a=[],s=e;t>s;s++)a.push(s);return a}var BASE_SHIFT=0,TITLE_SHIFT=1,TITLES={first:"First",prev:"«",prevSet:"...",nextSet:"...",next:"»",last:"Last"},Pager=React.createClass({displayName:"Pager",propTypes:{current:React.PropTypes.number.isRequired,total:React.PropTypes.number.isRequired,visiblePages:React.PropTypes.number.isRequired,titles:React.PropTypes.object,onPageChanged:React.PropTypes.func,onPageSizeChanged:React.PropTypes.func},handleFirstPage:function(){this.isPrevDisabled()||this.handlePageChanged(BASE_SHIFT)},handlePreviousPage:function(){this.isPrevDisabled()||this.handlePageChanged(this.props.current-TITLE_SHIFT)},handleNextPage:function(){this.isNextDisabled()||this.handlePageChanged(this.props.current+TITLE_SHIFT)},handleLastPage:function(){this.isNextDisabled()||this.handlePageChanged(this.props.total-TITLE_SHIFT)},handleMorePrevPages:function(){var e=this.calcBlocks();this.handlePageChanged(e.current*e.size-TITLE_SHIFT)},handleMoreNextPages:function(){var e=this.calcBlocks();this.handlePageChanged((e.current+TITLE_SHIFT)*e.size)},handlePageChanged:function(e){var t=this.props.onPageChanged;t&&t(e)},calcBlocks:function(){var e=this.props,t=e.total,a=e.visiblePages,s=e.current+TITLE_SHIFT,n=Math.ceil(t/a),i=Math.ceil(s/a)-TITLE_SHIFT;return{total:n,current:i,size:a}},isPrevDisabled:function(){return this.props.current<=BASE_SHIFT},isNextDisabled:function(){return this.props.current>=this.props.total-TITLE_SHIFT},isPrevMoreHidden:function(){var e=this.calcBlocks();return e.total===TITLE_SHIFT||e.current===BASE_SHIFT},isNextMoreHidden:function(){var e=this.calcBlocks();return e.total===TITLE_SHIFT||e.current===e.total-TITLE_SHIFT},visibleRange:function(){var e=this.calcBlocks(),t=e.current*e.size,a=this.props.total-t,s=t+(a>e.size?e.size:a);return[t+TITLE_SHIFT,s+TITLE_SHIFT]},getTitles:function(e){var t=this.props.titles||{};return t[e]||TITLES[e]},render:function(){var e=this.getTitles;return React.createElement("nav",null,React.createElement("ul",{className:"pagination"},React.createElement(Page,{className:"btn-first-page",key:"btn-first-page",isDisabled:this.isPrevDisabled(),onClick:this.handleFirstPage},e("first")),React.createElement(Page,{className:"btn-prev-page",key:"btn-prev-page",isDisabled:this.isPrevDisabled(),onClick:this.handlePreviousPage},e("prev")),React.createElement(Page,{className:"btn-prev-more",key:"btn-prev-more",isHidden:this.isPrevMoreHidden(),onClick:this.handleMorePrevPages},e("prevSet")),this.renderPages(this.visibleRange()),React.createElement(Page,{className:"btn-next-more",key:"btn-next-more",isHidden:this.isNextMoreHidden(),onClick:this.handleMoreNextPages},e("nextSet")),React.createElement(Page,{className:"btn-next-page",key:"btn-next-page",isDisabled:this.isNextDisabled(),onClick:this.handleNextPage},e("next")),React.createElement(Page,{className:"btn-last-page",key:"btn-last-page",isDisabled:this.isNextDisabled(),onClick:this.handleLastPage},e("last"))))},renderPages:function(e){var t=this;return range(e[0],e[1]).map(function(e,a){var s=e-TITLE_SHIFT,n=t.handlePageChanged.bind(null,s),i=t.props.current===s;return React.createElement(Page,{key:a,isActive:i,className:"btn-numbered-page",onClick:n},e)})}}),Page=React.createClass({displayName:"Page",render:function(){var e=this.props;if(e.isHidden)return null;var t=e.className?e.className+" ":"",a=t+(e.isActive?"active":"")+(e.isDisabled?" disabled":"");return React.createElement("li",{key:this.props.key,className:a},React.createElement("a",{onClick:this.props.onClick},this.props.children))}});window.Pager=window.Pager||Pager; \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 6305315..766d5c4 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,87 +1,29 @@ -var gulp = require( 'gulp' ) - , react = require( 'gulp-react' ) - , uglify = require( 'gulp-uglify' ) - , concat = require( 'gulp-concat' ) - , replace = require( 'gulp-replace' ) - , browserify = require( 'gulp-browserify' ) - , karma = require( 'karma' ).server; +const gulp = require('gulp'); +const sourcemaps = require('gulp-sourcemaps'); +const babel = require('gulp-babel'); +const concat = require('gulp-concat'); +const rimraf = require('rimraf'); +const join = require('path').join; +const PATH = { + src : 'src/', + dest : 'dist/', +}; -// Builds version for "require( 'react-pager' );" -gulp.task( 'build', function () { - return gulp.src( 'src/pager.jsx' ) - .pipe( react() ) - .pipe( concat( 'pager.js' ) ) - .pipe( gulp.dest( 'dist/' ) ); -}); - - -// Builds version for " + + - +
    diff --git a/demo/js/bundle.js b/demo/js/bundle.js deleted file mode 100644 index c401e33..0000000 --- a/demo/js/bundle.js +++ /dev/null @@ -1,21279 +0,0 @@ -(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o|' }, - onPageChanged: this.handlePageChanged - }); - } - }]); - - return App; - }(_react2.default.Component); - - exports.default = App; -}); - -},{"../../../src/pager.jsx":174,"react":173}],2:[function(require,module,exports){ -(function (global, factory) { - if (typeof define === "function" && define.amd) { - define(['react', 'react-dom', './components/app.jsx'], factory); - } else if (typeof exports !== "undefined") { - factory(require('react'), require('react-dom'), require('./components/app.jsx')); - } else { - var mod = { - exports: {} - }; - factory(global.react, global.reactDom, global.app); - global.main = mod.exports; - } -})(this, function (_react, _reactDom, _app) { - 'use strict'; - - var _react2 = _interopRequireDefault(_react); - - var _reactDom2 = _interopRequireDefault(_reactDom); - - var _app2 = _interopRequireDefault(_app); - - function _interopRequireDefault(obj) { - return obj && obj.__esModule ? obj : { - default: obj - }; - } - - window.onload = function () { - _reactDom2.default.render(_react2.default.createElement(_app2.default), document.querySelector('#app')); - }; /* global window = true */ - /* global document = true */ -}); - -},{"./components/app.jsx":1,"react":173,"react-dom":30}],3:[function(require,module,exports){ -(function (process){ -'use strict'; - -/** - * Copyright (c) 2013-present, Facebook, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * @typechecks - */ - -var emptyFunction = require('./emptyFunction'); - -/** - * Upstream version of event listener. Does not take into account specific - * nature of platform. - */ -var EventListener = { - /** - * Listen to DOM events during the bubble phase. - * - * @param {DOMEventTarget} target DOM element to register listener on. - * @param {string} eventType Event type, e.g. 'click' or 'mouseover'. - * @param {function} callback Callback function. - * @return {object} Object with a `remove` method. - */ - listen: function listen(target, eventType, callback) { - if (target.addEventListener) { - target.addEventListener(eventType, callback, false); - return { - remove: function remove() { - target.removeEventListener(eventType, callback, false); - } - }; - } else if (target.attachEvent) { - target.attachEvent('on' + eventType, callback); - return { - remove: function remove() { - target.detachEvent('on' + eventType, callback); - } - }; - } - }, - - /** - * Listen to DOM events during the capture phase. - * - * @param {DOMEventTarget} target DOM element to register listener on. - * @param {string} eventType Event type, e.g. 'click' or 'mouseover'. - * @param {function} callback Callback function. - * @return {object} Object with a `remove` method. - */ - capture: function capture(target, eventType, callback) { - if (target.addEventListener) { - target.addEventListener(eventType, callback, true); - return { - remove: function remove() { - target.removeEventListener(eventType, callback, true); - } - }; - } else { - if (process.env.NODE_ENV !== 'production') { - console.error('Attempted to listen to events during the capture phase on a ' + 'browser that does not support the capture phase. Your application ' + 'will not receive some events.'); - } - return { - remove: emptyFunction - }; - } - }, - - registerDefault: function registerDefault() {} -}; - -module.exports = EventListener; -}).call(this,require('_process')) -},{"./emptyFunction":10,"_process":29}],4:[function(require,module,exports){ -/** - * Copyright (c) 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - */ - -'use strict'; - -var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement); - -/** - * Simple, lightweight module assisting with the detection and context of - * Worker. Helps avoid circular dependencies and allows code to reason about - * whether or not they are in a Worker, even if they never include the main - * `ReactWorker` dependency. - */ -var ExecutionEnvironment = { - - canUseDOM: canUseDOM, - - canUseWorkers: typeof Worker !== 'undefined', - - canUseEventListeners: canUseDOM && !!(window.addEventListener || window.attachEvent), - - canUseViewport: canUseDOM && !!window.screen, - - isInWorker: !canUseDOM // For now, this is true - might change in the future. - -}; - -module.exports = ExecutionEnvironment; -},{}],5:[function(require,module,exports){ -"use strict"; - -/** - * Copyright (c) 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @typechecks - */ - -var _hyphenPattern = /-(.)/g; - -/** - * Camelcases a hyphenated string, for example: - * - * > camelize('background-color') - * < "backgroundColor" - * - * @param {string} string - * @return {string} - */ -function camelize(string) { - return string.replace(_hyphenPattern, function (_, character) { - return character.toUpperCase(); - }); -} - -module.exports = camelize; -},{}],6:[function(require,module,exports){ -/** - * Copyright (c) 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @typechecks - */ - -'use strict'; - -var camelize = require('./camelize'); - -var msPattern = /^-ms-/; - -/** - * Camelcases a hyphenated CSS property name, for example: - * - * > camelizeStyleName('background-color') - * < "backgroundColor" - * > camelizeStyleName('-moz-transition') - * < "MozTransition" - * > camelizeStyleName('-ms-transition') - * < "msTransition" - * - * As Andi Smith suggests - * (http://www.andismith.com/blog/2012/02/modernizr-prefixed/), an `-ms` prefix - * is converted to lowercase `ms`. - * - * @param {string} string - * @return {string} - */ -function camelizeStyleName(string) { - return camelize(string.replace(msPattern, 'ms-')); -} - -module.exports = camelizeStyleName; -},{"./camelize":5}],7:[function(require,module,exports){ -'use strict'; - -/** - * Copyright (c) 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * - */ - -var isTextNode = require('./isTextNode'); - -/*eslint-disable no-bitwise */ - -/** - * Checks if a given DOM node contains or is another DOM node. - */ -function containsNode(outerNode, innerNode) { - if (!outerNode || !innerNode) { - return false; - } else if (outerNode === innerNode) { - return true; - } else if (isTextNode(outerNode)) { - return false; - } else if (isTextNode(innerNode)) { - return containsNode(outerNode, innerNode.parentNode); - } else if ('contains' in outerNode) { - return outerNode.contains(innerNode); - } else if (outerNode.compareDocumentPosition) { - return !!(outerNode.compareDocumentPosition(innerNode) & 16); - } else { - return false; - } -} - -module.exports = containsNode; -},{"./isTextNode":20}],8:[function(require,module,exports){ -(function (process){ -'use strict'; - -/** - * Copyright (c) 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @typechecks - */ - -var invariant = require('./invariant'); - -/** - * Convert array-like objects to arrays. - * - * This API assumes the caller knows the contents of the data type. For less - * well defined inputs use createArrayFromMixed. - * - * @param {object|function|filelist} obj - * @return {array} - */ -function toArray(obj) { - var length = obj.length; - - // Some browsers builtin objects can report typeof 'function' (e.g. NodeList - // in old versions of Safari). - !(!Array.isArray(obj) && (typeof obj === 'object' || typeof obj === 'function')) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'toArray: Array-like object expected') : invariant(false) : void 0; - - !(typeof length === 'number') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'toArray: Object needs a length property') : invariant(false) : void 0; - - !(length === 0 || length - 1 in obj) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'toArray: Object should have keys for indices') : invariant(false) : void 0; - - !(typeof obj.callee !== 'function') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'toArray: Object can\'t be `arguments`. Use rest params ' + '(function(...args) {}) or Array.from() instead.') : invariant(false) : void 0; - - // Old IE doesn't give collections access to hasOwnProperty. Assume inputs - // without method will throw during the slice call and skip straight to the - // fallback. - if (obj.hasOwnProperty) { - try { - return Array.prototype.slice.call(obj); - } catch (e) { - // IE < 9 does not support Array#slice on collections objects - } - } - - // Fall back to copying key by key. This assumes all keys have a value, - // so will not preserve sparsely populated inputs. - var ret = Array(length); - for (var ii = 0; ii < length; ii++) { - ret[ii] = obj[ii]; - } - return ret; -} - -/** - * Perform a heuristic test to determine if an object is "array-like". - * - * A monk asked Joshu, a Zen master, "Has a dog Buddha nature?" - * Joshu replied: "Mu." - * - * This function determines if its argument has "array nature": it returns - * true if the argument is an actual array, an `arguments' object, or an - * HTMLCollection (e.g. node.childNodes or node.getElementsByTagName()). - * - * It will return false for other array-like objects like Filelist. - * - * @param {*} obj - * @return {boolean} - */ -function hasArrayNature(obj) { - return ( - // not null/false - !!obj && ( - // arrays are objects, NodeLists are functions in Safari - typeof obj == 'object' || typeof obj == 'function') && - // quacks like an array - 'length' in obj && - // not window - !('setInterval' in obj) && - // no DOM node should be considered an array-like - // a 'select' element has 'length' and 'item' properties on IE8 - typeof obj.nodeType != 'number' && ( - // a real array - Array.isArray(obj) || - // arguments - 'callee' in obj || - // HTMLCollection/NodeList - 'item' in obj) - ); -} - -/** - * Ensure that the argument is an array by wrapping it in an array if it is not. - * Creates a copy of the argument if it is already an array. - * - * This is mostly useful idiomatically: - * - * var createArrayFromMixed = require('createArrayFromMixed'); - * - * function takesOneOrMoreThings(things) { - * things = createArrayFromMixed(things); - * ... - * } - * - * This allows you to treat `things' as an array, but accept scalars in the API. - * - * If you need to convert an array-like object, like `arguments`, into an array - * use toArray instead. - * - * @param {*} obj - * @return {array} - */ -function createArrayFromMixed(obj) { - if (!hasArrayNature(obj)) { - return [obj]; - } else if (Array.isArray(obj)) { - return obj.slice(); - } else { - return toArray(obj); - } -} - -module.exports = createArrayFromMixed; -}).call(this,require('_process')) -},{"./invariant":18,"_process":29}],9:[function(require,module,exports){ -(function (process){ -'use strict'; - -/** - * Copyright (c) 2013-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - * - * @typechecks - */ - -/*eslint-disable fb-www/unsafe-html*/ - -var ExecutionEnvironment = require('./ExecutionEnvironment'); - -var createArrayFromMixed = require('./createArrayFromMixed'); -var getMarkupWrap = require('./getMarkupWrap'); -var invariant = require('./invariant'); - -/** - * Dummy container used to render all markup. - */ -var dummyNode = ExecutionEnvironment.canUseDOM ? document.createElement('div') : null; - -/** - * Pattern used by `getNodeName`. - */ -var nodeNamePattern = /^\s*<(\w+)/; - -/** - * Extracts the `nodeName` of the first element in a string of markup. - * - * @param {string} markup String of markup. - * @return {?string} Node name of the supplied markup. - */ -function getNodeName(markup) { - var nodeNameMatch = markup.match(nodeNamePattern); - return nodeNameMatch && nodeNameMatch[1].toLowerCase(); -} - -/** - * Creates an array containing the nodes rendered from the supplied markup. The - * optionally supplied `handleScript` function will be invoked once for each - * - - + + + - +
    - + From 6c1cff53b696c871d16d11ffa84ef91bf5877052 Mon Sep 17 00:00:00 2001 From: Alexei Zaviruha Date: Mon, 17 Oct 2016 13:00:05 +0300 Subject: [PATCH 15/17] Update demo --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b506a70..28cf937 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,9 @@ window.onload = () => { ## Demo -Just open [demo/index.html](./demo/index.html) in your browser. +Just open `demo/index.html` in your browser. +Or see interactive demo [here](http://azaviruha.github.io/demo/react-pager/). + ## Tests From 157804c473422904b457c70f9a5e697e6e5fa6e2 Mon Sep 17 00:00:00 2001 From: Alexei Zaviruha Date: Mon, 17 Oct 2016 13:29:32 +0300 Subject: [PATCH 16/17] Update karma config --- karma.conf.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index d0326eb..b76a9c8 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,6 +1,6 @@ var path = require('path'); -module.exports = (config) => { +module.exports = function (config) { config.set({ basePath: './', diff --git a/package.json b/package.json index 77ed48a..b02a143 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-pager", - "version": "1.2.0", + "version": "1.1.4", "description": "Stateless Pager component (for Bootstrap).", "main": "dist/pager.js", "scripts": { From 03c4f60441c277aa8077396ed47f156cfc64d2ce Mon Sep 17 00:00:00 2001 From: Alexei Zaviruha Date: Mon, 17 Oct 2016 13:34:17 +0300 Subject: [PATCH 17/17] Update node version for Travis CI --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2083806..b16d7f9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,3 @@ language: node_js node_js: - - "0.11" - - "0.10" \ No newline at end of file + - "6" \ No newline at end of file