Skip to content

Commit

Permalink
Start testing and doing examples
Browse files Browse the repository at this point in the history
  • Loading branch information
artberri committed Feb 14, 2013
1 parent 56333a4 commit c9ccb1e
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 37 deletions.
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
sidr
====
# Sidr

jQuery plugin which creates side menus
The best jQuery plugin ever.

## Getting Started
Download the [production version][min] or the [development version][max].

[min]: https://raw.github.com/artberri/sidr/master/dist/sidr.min.js
[max]: https://raw.github.com/artberri/sidr/master/dist/sidr.js

In your web page:

```html
<script src="jquery.js"></script>
<script src="dist/sidr.min.js"></script>
<script>
jQuery(function($) {
$.sidr(); // "awesome"
});
</script>
```

## Documentation
_(Coming soon)_

## Examples
_(Coming soon)_

## Release History
_(Nothing yet)_
6 changes: 3 additions & 3 deletions grunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module.exports = function(grunt) {
meta: {
banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
'<%= pkg.homepage ? "* " + pkg.homepage + "\n" : "" %>' +
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
'<%= pkg.homepage ? " * " + pkg.homepage + "\n" : "" %>' +
' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */'
},
concat: {
Expand All @@ -20,7 +20,7 @@ module.exports = function(grunt) {
min: {
dist: {
src: ['<banner:meta.banner>', '<config:concat.dist.dest>'],
dest: 'dist/<%= pkg.name %>.min.js'
dest: 'dist/jquery.<%= pkg.name %>.min.js'
}
},
lint: {
Expand Down
71 changes: 42 additions & 29 deletions src/jquery.sidr.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@

(function($) {

// Opening variable
$.sidr.moving = false;

// Default settings
$.sidr.defaults = {
speed : 200, // Accepts standard jQuery effects speeds (i.e. fast, normal or milliseconds)
side : 'left', // Accepts 'left' or 'right'
source: null // Override the source of the content.
};

$.sidr.settings = [];

var exceptions = {
source: {
name: "Invalid Sidr Source",
Expand Down Expand Up @@ -55,39 +43,50 @@
loadContent: function($menu, content) {
$menu.html(content);
},
open: function(name) {
open: function(name, options) {
name = sidr.ensureName(name);
var $menu = $(name),
settings = $.sidr.settings[name],
var $menu = $('#' + name),
$body = $('body'),
settings = options,
menuWidth = $menu.outerWidth(true);

console.log($.sidr.settings);

// Check if we can open it
if( $menu.is(':visible') || $.sidr.moving )
if( $menu.is(':visible') || $.sidr.moving ) {
return;
}

// Lock sidr
$.sidr.moving = true;

console.log(settings);
// Open menu
if(settings.side === 'left') {

$body.animate({marginLeft: menuWidth + 'px'}, settings.duration);
$menu.css('display', 'block').animate({left: '0px'}, settings.duration, function() {
$.sidr.moving = false;
});
}
else {

$body.animate({marginRight: menuWidth + 'px'}, settings.duration);
$menu.css('display', 'block').animate({right: '0px'}, settings.duration, function() {
$.sidr.moving = false;
});
}
},
close: function(name) {

},
toogle: function(name) {
toogle: function(name, options) {
name = sidr.ensureName(name);
var $menu = $(name);

// If the slide is open or opening, just ignore the call
if($menu.is(':visible')) {
sidr.close(name);
sidr.close(name, options);
}
else {
sidr.open(name);
sidr.open(name, options);
}
},
// Main method
Expand All @@ -99,12 +98,11 @@
}
else if(typeof name === 'undefined') {
name = 'sidr';
options = {};
}

// Override defaults
$.sidr.settings[name] = $.extend($.sidr.defaults, options);
// Variables
var settings = $.sidr.settings[name],
var settings = $.extend($.sidr.defaults, options);
$sideMenu = $('#' + name);

// If the side menu do not exist create it
Expand All @@ -129,23 +127,38 @@
});
}
else if(typeof settings.source === 'string') {
var htmlContent = '';
$existingContents = $(settings.source);
var htmlContent = '',
$existingContents = $(settings.source);
$existingContents.each(function() {
htmlContent += $(this).html();
});
sidr.loadContent($sideMenu, htmlContent);
}
else if(typeof settings.source !== null) {
else if(settings.source !== null) {
throw exceptions.source;
}

// Mostramos sidebar
// @TODO Hay que decidir que elementos disparan abrir y cerrar
$('a[href="#' + name + '"]').click(function(e) {
e.preventDefault();
console.log(name);
console.log(settings);
sidr.toogle(name, settings);
});
}
};

// Static method
$.sidr = sidr.init;

// Opening variable
$.sidr.moving = false;

// Default settings
$.sidr.defaults = {
speed : 200, // Accepts standard jQuery effects speeds (i.e. fast, normal or milliseconds)
side : 'left', // Accepts 'left' or 'right'
source: null // Override the source of the content.
};

}(jQuery));
4 changes: 2 additions & 2 deletions src/stylesheets/jquery.sidr.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
box-shadow: inset 0 0 5px 5px #222;
}

.sidr.left {
.sidr.right {
left: auto;
right: -300px;
}

.sidr.right {
.sidr.left {
left: -300px;
right: auto;
}

0 comments on commit c9ccb1e

Please sign in to comment.