Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node/npm package support #268

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dist/sly.node.source.js
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dist/sly.node.source.js
28 changes: 27 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@
module.exports = function (grunt) {
'use strict';

grunt.registerTask('node', 'Prepare node source', function() {
var fs = require('fs');
var done = this.async();
fs.readFile('src/sly.js', function(err, source) {
if (err) {
done(false);
} else {
var lines = source.toString().trim().split("\n");
lines[0] = lines[0].replace(/^;/, ';module.exports = ');
lines[lines.length-1] = lines[lines.length-1].replace('}(jQuery, window)', 'return Sly;}');
source = lines.join("\n");
fs.writeFile('dist/sly.node.source.js', source, function(err) {
done(!err);
});
}
});
});

// Override environment based line endings enforced by Grunt
grunt.util.linefeed = '\n';

Expand Down Expand Up @@ -41,6 +59,13 @@ module.exports = function (grunt) {
},
src: 'src/<%= pkg.name %>.js',
dest: 'dist/<%= pkg.name %>.js'
},
node: {
options: {
banner: '<%= meta.banner %>'
},
src: 'dist/<%= pkg.name %>.node.source.js',
dest: 'dist/<%= pkg.name %>.node.js'
}
},

Expand All @@ -62,7 +87,7 @@ module.exports = function (grunt) {
pkg: 'meta.json',
},
},
files: ['meta.json', '<%= pkg.name %>.jquery.json'],
files: ['meta.json', '<%= pkg.name %>.jquery.json', 'package.json'],
},

// Commit changes and tag the latest commit with a version from JSON file.
Expand All @@ -80,6 +105,7 @@ module.exports = function (grunt) {
// Build task.
grunt.registerTask('build', function () {
grunt.task.run('clean');
grunt.task.run('node');
grunt.task.run('concat');
grunt.task.run('uglify');
});
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ $('#frame').sly(options);

jQuery proxy is good when you want to create an instance and forget about it. For anything more complex, like using methods, events, accessing instance properties, ... use the constructor and work with the instance directly.

In Node:

```js
var jQuery = require('jquery');
var Sly = require('sly-scrolling')(jQuery, window);

// now use Sly as above
var options = {
horizontal: 1,
itemNav: 'basic',
speed: 300,
mouseDragging: 1,
touchDragging: 1
};
var frame = new Sly('#frame', options).init();
```

## Download

Latest stable release:
Expand Down
9 changes: 9 additions & 0 deletions docs/Calling.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Calling

If using Sly in the Node.js environment, require and instantiate it first:

```js
var jQuery = require('jquery');
var Sly = require('sly-scrolling')(jQuery, window);
```

Browser environments do not need this step.

When you want to have a direct access to all methods and complete control over Sly:

```js
Expand Down
16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
{
"name": "sly",
"version": "0.0.0",
"name": "sly-scrolling",
"version": "1.6.1",
"description": "JavaScript library for advanced one-directional scrolling with item based navigation support.",
"keywords": ["jquery", "scrolling"],
"homepage": "http://darsa.in/sly/",
"bugs": "https://github.com/darsain/sly/issues",
"license": "MIT",
"main": "dist/sly.node.js",
"repository": {"type": "git", "url": "https://github.com/darsain/sly"},
"peerDependencies": {
"jquery": ">=1.7"
},
"devDependencies": {
"grunt-contrib-jshint": "~0.7.2",
"grunt-contrib-uglify": "~0.6.0",
Expand All @@ -10,4 +20,4 @@
"grunt-bumpup": "~0.4.2",
"grunt": "~0.4.2"
}
}
}