Skip to content

Commit

Permalink
Use Browserify instead of RequireJS
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhooper committed Feb 2, 2015
1 parent 171b205 commit a1e4006
Show file tree
Hide file tree
Showing 87 changed files with 6,847 additions and 6,655 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
bower_components/
node_modules/
demo/js
demo/css
test/js
.DS_Store
135 changes: 0 additions & 135 deletions Gruntfile.coffee

This file was deleted.

17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ First, include the library. (It depends on [Backbone](http://backbonejs.org).) Y
require([ 'path/to/mass-upload' ], function(MassUpload) { ... });
```

Or you can use [Browserify](http://browserify.org/) or plain Node `require`:

```javascript
var MassUpload = require('js-mass-upload');
```

Or, you can go the old-fashioned route in your HTML:

```html
Expand Down Expand Up @@ -232,13 +238,10 @@ To build and contribute:
1. Install [NodeJS](http://nodejs.org/)
2. Clone this repository: `git clone https://github.com/overview/js-mass-upload.git`
3. `npm install` in this directory
4. `bower install` in this directory
5. `grunt develop` to start developing.
6. Write tests in `test/coffee`. In the terminal that's running `grunt develop`, you'll see new failures.
7. Once you've created a test failure, edit code in `src/coffee`, until the terminal that's running `grunt develop` comes up green.
8. Browse to http://localhost:8080/demo/ to see your code in action.
9. Run `grunt` to populate the `dist/` directory.
10. commit and create a pull request.
4. `gulp` to build
5. `gulp test` to unit-test
6. Add a test; return to step 4; make test pass; return to step 4
7. git commit and create a pull request

License
-------
Expand Down
21 changes: 0 additions & 21 deletions bower.json

This file was deleted.

27 changes: 17 additions & 10 deletions demo/coffee/app.coffee
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
define [ 'jquery', 'mass-upload', 'upload-logic', 'MassUpload/views/MassUpload' ], ($, MassUpload, uploadLogic, MassUploadView) ->
options = $.extend({
}, uploadLogic)
$ = require('jquery')
Backbone = require('backbone')

massUpload = new MassUpload(options)
Backbone.$ = $

new MassUploadView(model: massUpload, el: $('.mass-upload'))
MassUpload = require('../../js-mass-upload')
uploadLogic = require('./upload-logic')
MassUploadView = require('../../src/MassUpload/views/MassUpload')

$networkIsWorking = $('#network-is-working')
$networkIsWorking.change ->
value = $networkIsWorking.prop('checked')
uploadLogic.toggleWorking(value)
options = $.extend({}, uploadLogic)

massUpload.fetchFileInfosFromServer()
massUpload = new MassUpload(options)

new MassUploadView(model: massUpload, el: $('.mass-upload'))

$networkIsWorking = $('#network-is-working')
$networkIsWorking.change ->
value = $networkIsWorking.prop('checked')
uploadLogic.toggleWorking(value)

massUpload.fetchFileInfosFromServer()
20 changes: 0 additions & 20 deletions demo/coffee/main.coffee

This file was deleted.

82 changes: 41 additions & 41 deletions demo/coffee/upload-logic.coffee
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
define ->
date1 = new Date('Mon, 13 Aug 2013 09:29:16 -0400')
date2 = new Date('Mon, 14 Aug 2013 09:29:16 -0400')
date3 = new Date('Mon, 15 Aug 2013 09:29:16 -0400')
serverFiles = [
{ name: 'file1.txt', loaded: 2000, total: 10000, lastModifiedDate: date1 }
{ name: 'file2.txt', loaded: 3000, total: 20000, lastModifiedDate: date2 }
{ name: 'file3.txt', loaded: 4000, total: 30000, lastModifiedDate: date3 }
]

networkIsWorking = true # when false, all ticks fail

sendAsyncError = (error, message) ->
window.setTimeout((-> error(message)), 50)

tickListFilesAtBytes = (bytes, progress, success, error) ->
if !networkIsWorking
sendAsyncError(error, 'network is broken')
date1 = new Date('Mon, 13 Aug 2013 09:29:16 -0400')
date2 = new Date('Mon, 14 Aug 2013 09:29:16 -0400')
date3 = new Date('Mon, 15 Aug 2013 09:29:16 -0400')
serverFiles = [
{ name: 'file1.txt', loaded: 2000, total: 10000, lastModifiedDate: date1 }
{ name: 'file2.txt', loaded: 3000, total: 20000, lastModifiedDate: date2 }
{ name: 'file3.txt', loaded: 4000, total: 30000, lastModifiedDate: date3 }
]

networkIsWorking = true # when false, all ticks fail

sendAsyncError = (error, message) ->
window.setTimeout((-> error(message)), 50)

tickListFilesAtBytes = (bytes, progress, success, error) ->
if !networkIsWorking
sendAsyncError(error, 'network is broken')
else
total = 1000
increment = 100
timeout = 100

if bytes >= total
progress({ loaded: total, total: total })
success(serverFiles)
else
total = 1000
increment = 100
timeout = 100

if bytes >= total
progress({ loaded: total, total: total })
success(serverFiles)
else
progress({ loaded: bytes, total: total })
window.setTimeout((-> tickListFilesAtBytes(bytes + increment, progress, success, error)), timeout)

tickUploadFileAtByte = (file, bytes, progress, success, error) ->
if !networkIsWorking
sendAsyncError(error, 'network is broken')
progress({ loaded: bytes, total: total })
window.setTimeout((-> tickListFilesAtBytes(bytes + increment, progress, success, error)), timeout)

tickUploadFileAtByte = (file, bytes, progress, success, error) ->
if !networkIsWorking
sendAsyncError(error, 'network is broken')
else
increment = 50000
timeout = 500

if bytes >= file.size
progress({ loaded: file.size, total: file.size })
success()
else
increment = 50000
timeout = 500

if bytes >= file.size
progress({ loaded: file.size, total: file.size })
success()
else
progress({ loaded: bytes, total: file.size })
window.setTimeout((-> tickUploadFileAtByte(file, bytes + increment, progress, success, error)), timeout)
progress({ loaded: bytes, total: file.size })
window.setTimeout((-> tickUploadFileAtByte(file, bytes + increment, progress, success, error)), timeout)

module.exports =
# Returns three dummy files, taking about a second
doListFiles: (progress, success, error) -> tickListFilesAtBytes(0, progress, success, error)

Expand Down
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ <h1>MassUpload demo</h1>
<p><label><input type="checkbox" checked="checked" id="network-is-working" /> Network is online (when unchecked, all operations will be errors)</label></p>
<div class="mass-upload"></div>
</body>
<script src="../node_modules/grunt-requirejs/node_modules/requirejs/require.js" data-main="./js/main.js"></script>
<script src="./js/app.js"></script>
</html>
Loading

0 comments on commit a1e4006

Please sign in to comment.