diff --git a/.editorconfig b/.editorconfig index 47c5438..219985c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,22 +13,8 @@ insert_final_newline = true indent_style = space indent_size = 2 -[*.js] -indent_style = space -indent_size = 2 - [*.hbs] insert_final_newline = false -indent_style = space -indent_size = 2 - -[*.css] -indent_style = space -indent_size = 2 - -[*.html] -indent_style = space -indent_size = 2 [*.{diff,md}] trim_trailing_whitespace = false diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..fbfc364 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,13 @@ +module.exports = { + root: true, + parserOptions: { + ecmaVersion: 6, + sourceType: 'module' + }, + extends: 'eslint:recommended', + env: { + browser: true + }, + rules: { + } +}; diff --git a/.gitignore b/.gitignore index 86fceae..5ad14dd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -# See http://help.github.com/ignore-files/ for more about ignoring files. +# See https://help.github.com/ignore-files/ for more about ignoring files. # compiled output /dist @@ -13,5 +13,5 @@ /connect.lock /coverage/* /libpeerconnection.log -npm-debug.log +npm-debug.log* testem.log diff --git a/.npmignore b/.npmignore index 49996f5..889b2bf 100644 --- a/.npmignore +++ b/.npmignore @@ -1,14 +1,16 @@ -bower_components/ -tests/ -tmp/ -dist/ - +/bower_components +/config/ember-try.js +/dist +/tests +/tmp +**/.gitkeep .bowerrc .editorconfig .ember-cli +.gitignore +.eslintrc.js +.watchmanconfig .travis.yml -.npmignore -**/.gitkeep bower.json -Brocfile.js -testem.json +ember-cli-build.js +testem.js diff --git a/.travis.yml b/.travis.yml index 621f310..5235bf5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,22 +1,23 @@ --- language: node_js node_js: - - "0.12" + - "6" sudo: false cache: directories: - - node_modules + - $HOME/.npm + - $HOME/.cache # includes bowers cache env: - - EMBER_TRY_SCENARIO=ember-1.10 - - EMBER_TRY_SCENARIO=ember-1.11 - - EMBER_TRY_SCENARIO=ember-1.12 - - EMBER_TRY_SCENARIO=default + # we recommend testing LTS's and latest stable release (bonus points to beta/canary) + - EMBER_TRY_SCENARIO=ember-lts-2.4 + - EMBER_TRY_SCENARIO=ember-lts-2.8 - EMBER_TRY_SCENARIO=ember-release - EMBER_TRY_SCENARIO=ember-beta - EMBER_TRY_SCENARIO=ember-canary + - EMBER_TRY_SCENARIO=ember-default matrix: fast_finish: true @@ -24,14 +25,16 @@ matrix: - env: EMBER_TRY_SCENARIO=ember-canary before_install: - - export PATH=/usr/local/phantomjs-2.0.0/bin:$PATH - - "npm config set spin false" - - "npm install -g npm@^2" + - npm config set spin false + - npm install -g bower phantomjs-prebuilt + - bower --version + - phantomjs --version install: - - npm install -g bower - npm install - bower install script: - - ember try $EMBER_TRY_SCENARIO test + # Usually, it's ok to finish the test scenario without reverting + # to the addon's original dependency state, skipping "cleanup". + - node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO test --skip-cleanup diff --git a/.watchmanconfig b/.watchmanconfig index 5e9462c..e7834e3 100644 --- a/.watchmanconfig +++ b/.watchmanconfig @@ -1,3 +1,3 @@ { - "ignore_dirs": ["tmp"] + "ignore_dirs": ["tmp", "dist"] } diff --git a/Brocfile.js b/Brocfile.js deleted file mode 100644 index 2a682c0..0000000 --- a/Brocfile.js +++ /dev/null @@ -1,16 +0,0 @@ -/* jshint node: true */ -/* global require, module */ - -var EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); - -/* - This Brocfile specifes the options for the dummy test app of this - addon, located in `/tests/dummy` - - This Brocfile does *not* influence how the addon or the app using it - behave. You most likely want to be modifying `./index.js` or app's Brocfile -*/ - -var app = new EmberAddon(); - -module.exports = app.toTree(); diff --git a/README.md b/README.md index 89646c1..4033b2b 100644 --- a/README.md +++ b/README.md @@ -79,5 +79,10 @@ Example }} ``` +##TODO + +1. Create a demo of the addon. +2. Write test cases supporting the addon. + ## Contribution Fork this repository, make a feature branch and send in a pull request. diff --git a/addon/components/sortable-items.js b/addon/components/sortable-items.js index 1737c1b..197a186 100644 --- a/addon/components/sortable-items.js +++ b/addon/components/sortable-items.js @@ -1,14 +1,22 @@ import Ember from 'ember'; import layout from '../templates/components/sortable-items'; + /* global Sortable */ +const { + Component, + computed, + observer, + run +} = Ember; + var pid, frozen, frozenObjects, positions; -var SortableItems = Ember.Component.extend({ - target: Ember.computed.alias('targetObject'), // Bubble up all actions +export default Component.extend({ + target: computed.alias('targetObject'), layout: layout, tagName: "ul", classNames: ['sortable-items'], @@ -37,9 +45,11 @@ var SortableItems = Ember.Component.extend({ Initializes Sortable with given properties and binds callbacks to private methods */ - setup: function() { - var options = { + didInsertElement() { + this._super(...arguments); + + let options = { group: this.get('group'), sort: this.get('sort'), disabled: this.get('disabled'), @@ -51,14 +61,14 @@ var SortableItems = Ember.Component.extend({ scroll: this.get('scroll'), scrollSensitivity: this.get('scrollSensitivity'), scrollSpeed: this.get('scrollSpeed'), - onStart: Ember.run.bind(this, this._onStart), - onEnd: Ember.run.bind(this, this._onEnd), - onAdd: Ember.run.bind(this, this._onAdd), - onUpdate: Ember.run.bind(this, this._onUpdate), - onSort: Ember.run.bind(this, this._onSort), - onRemove: Ember.run.bind(this, this._onRemove), - onFilter: Ember.run.bind(this, this._onFilter), - onMove: Ember.run.bind(this, this._onMove) + onStart: run.bind(this, this._onStart), + onEnd: run.bind(this, this._onEnd), + onAdd: run.bind(this, this._onAdd), + onUpdate: run.bind(this, this._onUpdate), + onSort: run.bind(this, this._onSort), + onRemove: run.bind(this, this._onRemove), + onFilter: run.bind(this, this._onFilter), + onMove: run.bind(this, this._onMove) }; if (this.get('draggable')) { @@ -67,22 +77,21 @@ var SortableItems = Ember.Component.extend({ this.set('_sortableInstance', new Sortable(this.$()[0], options)); - }.on('didInsertElement'), - + }, /** @method _onStart @private The user has started to drag an item */ - _onStart: function(evt) { + _onStart(evt) { - Ember.run(this, function() { - var freezeSelector = this.get('freeze'); + run(this, function() { + let freezeSelector = this.get('freeze'); if (freezeSelector) { - var _sortableInstance = this.get('_sortableInstance'); - var itemCollection = this.get('itemCollection'); + let _sortableInstance = this.get('_sortableInstance'); + let itemCollection = this.get('itemCollection'); frozenObjects = []; frozen = [].slice.call(_sortableInstance.el.querySelectorAll(freezeSelector)); @@ -104,7 +113,7 @@ var SortableItems = Ember.Component.extend({ @private The user has stopped draggging an item */ - _onEnd: function(evt) { + _onEnd(evt) { this._sendOutAction('onEndAction', evt); }, @@ -113,7 +122,7 @@ var SortableItems = Ember.Component.extend({ @private An item is dropped into the list from another list */ - _onAdd: function(evt) { + _onAdd(evt) { this._sendOutAction('onAddAction', evt); }, @@ -122,29 +131,27 @@ var SortableItems = Ember.Component.extend({ @private Changed sorting within list */ - _onUpdate: function(evt) { + _onUpdate(evt) { this._sendOutAction('onUpdateAction', evt); - Ember.run(this, function() { - var collection = this.get('itemCollection'); - var item = collection.objectAt(evt.oldIndex); - var list = evt.to; - var freezeSelector = this.get('freeze'); - collection.removeAt(evt.oldIndex); - collection.insertAt(evt.newIndex, item); + run(this, function() { + let collection = this.get('itemCollection'); + let item = collection[evt.oldIndex]; + let freezeSelector = this.get('freeze'); + delete collection[evt.oldIndex]; + collection.splice(evt.newIndex, 0, item); if (freezeSelector) { frozenObjects.forEach(function(obj, i) { - var pos = positions[i]; - if (collection.objectAt(pos) !== obj) { - var realPos = collection.indexOf(obj); - collection.removeAt(realPos); - collection.insertAt(pos, obj); + let pos = positions[i]; + if (collection[pos] !== obj) { + let realPos = collection.indexOf(obj); + delete collection[realPos]; + collection.splice(pos, 0, obj); } }); } - this.sendAction('onItemMoveAction', item, evt.oldIndex, evt.newIndex); }); @@ -155,7 +162,7 @@ var SortableItems = Ember.Component.extend({ @private Called when any change occurs within the list (add, update, remove) */ - _onSort: function(evt) { + _onSort(evt) { this._sendOutAction('onSortAction', evt); }, @@ -165,7 +172,7 @@ var SortableItems = Ember.Component.extend({ @private An item is removed from the list and added into another */ - _onRemove: function(evt) { + _onRemove(evt) { this._sendOutAction('onRemoveAction', evt); }, @@ -174,7 +181,7 @@ var SortableItems = Ember.Component.extend({ @private Called when an attempt is made to drag a filtered item */ - _onFilter: function(evt) { + _onFilter(evt) { this._sendOutAction('onFilterAction', evt); }, @@ -183,23 +190,23 @@ var SortableItems = Ember.Component.extend({ @private Called when re-ordering the list during drag */ - _onMove: function(evt) { + _onMove(evt) { this._sendOutAction('onMoveAction', evt); - var vector; - var freeze = false; - var freezeSelector = this.get('freeze'); + let vector; + let freeze = false; + let freezeSelector = this.get('freeze'); if (freezeSelector) { clearTimeout(pid); pid = setTimeout(function () { - var list = evt.to; + let list = evt.to; frozen.forEach(function (el, i) { - var idx = positions[i]; + let idx = positions[i]; if (list.children[idx] !== el) { - var realIdx = Sortable.utils.index(el); + let realIdx = Sortable.utils.index(el); list.insertBefore(el, list.children[idx + (realIdx < idx)]); } }); @@ -224,10 +231,10 @@ var SortableItems = Ember.Component.extend({ @private Used to update sortable properties */ - _updateOptionDisabled: function() { - var _sortableInstance = this.get('_sortableInstance'); + _updateOptionDisabled: observer('disabled', function() { + let _sortableInstance = this.get('_sortableInstance'); _sortableInstance.option('disabled', this.get('disabled')); - }.observes('disabled'), + }), /** @method _sendOutAction @@ -235,19 +242,18 @@ var SortableItems = Ember.Component.extend({ Used as an interface for the sendAction method, checks if consumer defined an action before sending one out */ - _sendOutAction: function(action, evt) { + _sendOutAction(action, evt) { if (this.get(action)) { this.sendAction(action, evt); } }, - teardown: function() { - var _sortableInstance = this.get('_sortableInstance'); + + willDestroyElement() { + this._super(...arguments); + let _sortableInstance = this.get('_sortableInstance'); if (_sortableInstance) { _sortableInstance.destroy(); } - }.on('willDestroyElement') - -}); - -export default SortableItems; + } +}); \ No newline at end of file diff --git a/addon/templates/sortable-items-partial.hbs b/addon/templates/sortable-items-partial.hbs new file mode 100644 index 0000000..c3d401d --- /dev/null +++ b/addon/templates/sortable-items-partial.hbs @@ -0,0 +1,4 @@ +