Skip to content

Commit

Permalink
Fixed defaults #4
Browse files Browse the repository at this point in the history
  • Loading branch information
makotokw committed Mar 25, 2016
1 parent dcadf83 commit 1f3438d
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 107 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
_site
.DS_Store
.idea/
node_modules/
dist/
tmp/
5 changes: 3 additions & 2 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jquery.ui.potato.menu</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="../src/jquery.ui.potato.menu.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<!--<script type="text/javascript" src="../src/jquery.ui.potato.menu.js"></script>-->
<script type="text/javascript" src="../dist/jquery.ui.potato.menu.min.js"></script>
<link rel=stylesheet href="../src/jquery.ui.potato.menu.css">
<style>
#menu1 {}
Expand Down
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "jquery.ui.potato.menu",
"version": "1.2.1",
"description": "Simple Drop Down Menu for jQuery",
"main": "src/jquery.ui.potato.menu.js",
"repository": {
"type": "git",
"url": "[email protected]:makotokw/jquery.ui.potato.menu.git"
},
"scripts": {
"prebuild": "npm run clean",
"clean": "node -e \"var s=require('shelljs'),d=['dist'];s.rm('-rf',d);s.mkdir('-p',d);\"",
"build": "uglifyjs src/jquery.ui.potato.menu.js --comments --mangle --compress -o dist/jquery.ui.potato.menu.min.js --source-map dist/jquery.ui.potato.menu.min.js.map"
},
"keywords": [],
"author": "Makoto Kawasaki",
"license": "MIT",
"bugs": {
"url": "https://github.com/makotokw/jquery.ui.potato.menu/issues"
},
"homepage": "https://github.com/makotokw/jquery.ui.potato.menu#readme",
"devDependencies": {
"shelljs": "^0.6.0",
"uglify-js": "^2.6.2"
}
}
12 changes: 6 additions & 6 deletions src/jquery.ui.potato.menu.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*!
/**
* jquery.ui.potato.menu
*
* Copyright (c) 2009-2011 makoto_kw, http://www.makotokw.com
* Licensed under the MIT license.
*
*
* Copyright (c) 2009-2016 makoto_kw, http://makotokw.com
*
* @author makoto_kw
* @version 1.2
* @version 1.2.1
* @license MIT
*/
.potato-menu {
margin:0;
Expand Down
173 changes: 88 additions & 85 deletions src/jquery.ui.potato.menu.js
Original file line number Diff line number Diff line change
@@ -1,90 +1,93 @@
/*!
* jquery.ui.potato.menu
/**
* jquery.ui.potato.menu
*
* Copyright (c) 2009-2012 makoto_kw, http://www.makotokw.com
* Licensed under the MIT license.
* Copyright (c) 2009-2016 makoto_kw, http://makotokw.com
*
* @author makoto_kw
* @version 1.2
* @author makoto_kw
* @version 1.2.1
* @license MIT
*/
(function($) {
var defaults = {
vertical:false,
menuItemSelector: 'li',
menuGroupSelector: 'ul',
rootClass:'potato-menu',
menuItemClass:'potato-menu-item',
menuGroupClass:'potato-menu-group',
verticalClass:'potato-menu-vertical',
horizontalClass:'potato-menu-horizontal',
hasVerticalClass:'potato-menu-has-vertical',
hasHorizontalClass:'potato-menu-has-horizontal',
hoverClass:'potato-menu-hover',
showDuration: 350,
hideDuration: 100,
hideDelayDuration: 0
};
function menu() {
var option = (typeof(arguments[0])!='string') ? $.extend(defaults,arguments[0]) : $.extend(defaults,{});
(function ($) {

// Horizontal:
// ul.potato-menu-group,potato-menu-horizontal
// > li.potato-menu-item,potato-menu-has-vertical
// > ul.potato-menu-group,potato-menu-vertical
// > li.potato-menu-item,potato-menu-has-horizontal
// > ....
//
// Vertical
// ul.potato-menu-group,potato-menu-vertical
// > li.potato-menu-item,potato-menu-has-horizontal
// > ul.potato-menu-group,potato-menu-horizontal
// > li.potato-menu-item,potato-menu-has-vertical
// > ....
var topMenuGroupClass = (option.vertical) ? option.verticalClass : option.horizontalClass,
$menu = $(this).addClass(option.rootClass+' '+option.menuGroupClass+' '+topMenuGroupClass),
$menuItems = $menu.find(option.menuItemSelector).addClass(option.menuItemClass),
$menuGroups = $menu.find(option.menuGroupSelector).addClass(option.menuGroupClass);

$menuItems.hover(
function(e) {
$(this).addClass(option.hoverClass);
},
function(e) {
$(this).removeClass(option.hoverClass);
}
);
$menuGroups.parent().each(function(index){
var $parentMenuItem = $(this); // menu item that has menu group
var displayDirection = ($parentMenuItem.parent().hasClass(option.horizontalClass)) ? 'bottom' : 'right';
$parentMenuItem.addClass((displayDirection == 'bottom') ? option.hasVerticalClass : option.hasHorizontalClass);
var $menuGroup = $parentMenuItem.find(option.menuGroupSelector+':first').addClass(option.verticalClass);
$parentMenuItem.hover(
function(e) {
var offset = {left:'', top:''};
if (displayDirection == 'bottom') {
offset.left = 0;
} else {
offset.left = $(this).width() + 'px';
offset.top = '0px';
}
$menuGroup.css(offset).fadeIn(option.showDuration);
},
function(e) {
if (option.hideDelayDuration > 0) {
$menuGroup.delay(option.hideDelayDuration).fadeOut(option.hideDuration);
} else {
$menuGroup.fadeOut(option.hideDuration);
}
}
);
});
$menu.find('a[href^="#"]').click(function() {
$menuGroups.fadeOut(option.hideDuration);
return ($(this).attr('href') != '#');
});
return this;
}
$.fn.extend({
ptMenu:menu
});
var defaults = {
vertical: false,
menuItemSelector: 'li',
menuGroupSelector: 'ul',
rootClass: 'potato-menu',
menuItemClass: 'potato-menu-item',
menuGroupClass: 'potato-menu-group',
verticalClass: 'potato-menu-vertical',
horizontalClass: 'potato-menu-horizontal',
hasVerticalClass: 'potato-menu-has-vertical',
hasHorizontalClass: 'potato-menu-has-horizontal',
hoverClass: 'potato-menu-hover',
showDuration: 350,
hideDuration: 100,
hideDelayDuration: 0
};

function menu() {
var option = (typeof(arguments[0]) != 'string') ? $.extend({}, defaults, arguments[0]) : $.extend({}, defaults);

// Horizontal:
// ul.potato-menu-group,potato-menu-horizontal
// > li.potato-menu-item,potato-menu-has-vertical
// > ul.potato-menu-group,potato-menu-vertical
// > li.potato-menu-item,potato-menu-has-horizontal
// > ....
//
// Vertical
// ul.potato-menu-group,potato-menu-vertical
// > li.potato-menu-item,potato-menu-has-horizontal
// > ul.potato-menu-group,potato-menu-horizontal
// > li.potato-menu-item,potato-menu-has-vertical
// > ....
var topMenuGroupClass = (option.vertical) ? option.verticalClass : option.horizontalClass,
$menu = $(this).addClass(option.rootClass + ' ' + option.menuGroupClass + ' ' + topMenuGroupClass),
$menuItems = $menu.find(option.menuItemSelector).addClass(option.menuItemClass),
$menuGroups = $menu.find(option.menuGroupSelector).addClass(option.menuGroupClass);

$menuItems.hover(
function (/*e*/) {
$(this).addClass(option.hoverClass);
},
function (/*e*/) {
$(this).removeClass(option.hoverClass);
}
);
$menuGroups.parent().each(function (/*index*/) {
var $parentMenuItem = $(this); // menu item that has menu group
var displayDirection = ($parentMenuItem.parent().hasClass(option.horizontalClass)) ? 'bottom' : 'right';
$parentMenuItem.addClass((displayDirection == 'bottom') ? option.hasVerticalClass : option.hasHorizontalClass);
var $menuGroup = $parentMenuItem.find(option.menuGroupSelector + ':first').addClass(option.verticalClass);
$parentMenuItem.hover(
function (/*e*/) {
var offset = {left: '', top: ''};
if (displayDirection == 'bottom') {
offset.left = 0;
} else {
offset.left = $(this).width() + 'px';
offset.top = '0px';
}
$menuGroup.css(offset).fadeIn(option.showDuration);
},
function (/*e*/) {
if (option.hideDelayDuration > 0) {
$menuGroup.delay(option.hideDelayDuration).fadeOut(option.hideDuration);
} else {
$menuGroup.fadeOut(option.hideDuration);
}
}
);
});
$menu.find('a[href^="#"]').click(function () {
$menuGroups.fadeOut(option.hideDuration);
return ($(this).attr('href') != '#');
});
return this;
}

$.fn.extend({
ptMenu: menu
});
})(jQuery);
13 changes: 0 additions & 13 deletions src/jquery.ui.potato.menu.min.js

This file was deleted.

0 comments on commit 1f3438d

Please sign in to comment.