angularjs - How to modify Angular slide.and.push directive to close when clicking off menu -



angularjs - How to modify Angular slide.and.push directive to close when clicking off menu -

i'm trying modify nice angular slide.and.push directive (https://github.com/thram/slide.and.push) after slide menu shown if user clicks off of onto somewhere on page go ahead , slide menu shut. currently, have click same button used open in order close it. help appreciated!

angular.module("slidepushmenu", []).factory('slidepush',function () { var spmenuhorizontalheight, spmenuverticalwidth; spmenuverticalwidth = 320; spmenuhorizontalheight = 150; homecoming { slide: function (menu, btn) { btn.toggleclass("active"); if (menu.hasclass("spmenu-left")) { if (menu.hasclass("spmenu-open")) { menu.css("left", parseint(menu.css("left")) - spmenuverticalwidth); } else { menu.css("left", parseint(menu.css("left")) + spmenuverticalwidth); } } if (menu.hasclass("spmenu-right")) { if (menu.hasclass("spmenu-open")) { menu.css("right", parseint(menu.css("right")) - spmenuverticalwidth); } else { menu.css("right", parseint(menu.css("right")) + spmenuverticalwidth); } } if (menu.hasclass("spmenu-top")) { if (menu.hasclass("spmenu-open")) { menu.css("top", parseint(menu.css("top")) - spmenuhorizontalheight); } else { menu.css("top", parseint(menu.css("top")) + spmenuhorizontalheight); } } if (menu.hasclass("spmenu-bottom")) { if (menu.hasclass("spmenu-open")) { menu.css("bottom", parseint(menu.css("bottom")) - spmenuhorizontalheight); } else { menu.css("bottom", parseint(menu.css("bottom")) + spmenuhorizontalheight); } } homecoming menu.toggleclass("spmenu-open"); }, slideforceclose: function (menu, btn) { if (menu.hasclass("spmenu-open")) { btn.removeclass("active"); if (menu.hasclass("spmenu-left")) { menu.css("left", parseint(menu.css("left")) - spmenuverticalwidth); } if (menu.hasclass("spmenu-right")) { menu.css("right", parseint(menu.css("right")) - spmenuverticalwidth); } if (menu.hasclass("spmenu-top")) { menu.css("top", parseint(menu.css("top")) - spmenuhorizontalheight); } if (menu.hasclass("spmenu-bottom")) { menu.css("bottom", parseint(menu.css("bottom")) - spmenuhorizontalheight); } homecoming menu.removeclass("spmenu-open"); } }, push: function (menu, btn) { var body, bodyleft, bodytop; body = angular.element("body"); btn.toggleclass("active"); if (menu.hasclass("spmenu-left")) { bodyleft = parseint(body.css("left")); bodyleft = (bodyleft ? bodyleft : 0); if (menu.hasclass("spmenu-open")) { body.css("left", bodyleft - spmenuverticalwidth); } else { body.css("left", bodyleft + spmenuverticalwidth); } if (menu.hasclass("spmenu-open")) { menu.css("left", parseint(menu.css("left")) - spmenuverticalwidth); } else { menu.css("left", parseint(menu.css("left")) + spmenuverticalwidth); } } if (menu.hasclass("spmenu-right")) { bodyleft = parseint(body.css("left")); bodyleft = (bodyleft ? bodyleft : 0); if (menu.hasclass("spmenu-open")) { body.css("left", bodyleft + spmenuverticalwidth); } else { body.css("left", bodyleft - spmenuverticalwidth); } if (menu.hasclass("spmenu-open")) { menu.css("right", parseint(menu.css("right")) - spmenuverticalwidth); } else { menu.css("right", parseint(menu.css("right")) + spmenuverticalwidth); } } if (menu.hasclass("spmenu-top")) { bodytop = parseint(body.css("top")); bodytop = (bodytop ? bodytop : 0); if (menu.hasclass("spmenu-open")) { body.css("top", "auto"); } else { body.css("top", bodytop + spmenuhorizontalheight); } if (menu.hasclass("spmenu-open")) { menu.css("top", parseint(menu.css("top")) - spmenuhorizontalheight); } else { menu.css("top", parseint(menu.css("top")) + spmenuhorizontalheight); } } if (menu.hasclass("spmenu-bottom")) { bodytop = parseint(body.css("top")); bodytop = (bodytop ? bodytop : 0); if (menu.hasclass("spmenu-open")) { body.css("top", "auto"); } else { body.css("top", bodytop - spmenuhorizontalheight); } if (menu.hasclass("spmenu-open")) { menu.css("bottom", parseint(menu.css("bottom")) - spmenuhorizontalheight); } else { menu.css("bottom", parseint(menu.css("bottom")) + spmenuhorizontalheight); } } homecoming menu.toggleclass("spmenu-open"); }, pushforceclose: function (menu, btn) { var body, bodyleft; if (menu.hasclass("spmenu-open")) { btn.removeclass("active"); body = angular.element("body"); if (menu.hasclass("spmenu-left")) { bodyleft = parseint(body.css("left")); bodyleft = (bodyleft ? bodyleft : 0); body.css("left", bodyleft - spmenuverticalwidth); menu.css("left", parseint(menu.css("left")) - spmenuverticalwidth); } if (menu.hasclass("spmenu-right")) { bodyleft = parseint(body.css("left")); bodyleft = (bodyleft ? bodyleft : 0); body.css("left", bodyleft + spmenuverticalwidth); menu.css("right", parseint(menu.css("right")) - spmenuverticalwidth); } if (menu.hasclass("spmenu-top")) { body.css("top", "auto"); menu.css("top", parseint(menu.css("top")) - spmenuhorizontalheight); } if (menu.hasclass("spmenu-bottom")) { body.css("top", "auto"); menu.css("bottom", parseint(menu.css("bottom")) - spmenuhorizontalheight); } homecoming menu.removeclass("spmenu-open"); } } }; }).directive("ngslidemenu", [ 'slidepush', function (slidepush) { homecoming { restrict: "a", link: function (scope, elem, attrs) { homecoming elem.click(function () { var menu; menu = angular.element("#" + attrs.ngslidemenu); homecoming slidepush.slide(menu, elem); }); } }; } ]).directive("ngpushmenu", [ 'slidepush', function (slidepush) { homecoming { restrict: "a", link: function (scope, elem, attrs) { var body, menu; menu = angular.element("#" + attrs.ngpushmenu); body = angular.element("body"); body.addclass("spmenu-push"); homecoming elem.click(function () { homecoming slidepush.push(menu, elem); }); } }; } ]).directive("ngslidepushmenu", [ "$document", 'slidepush', function ($document, slidepush) { var compile, link; compile = function (elem, attrs, transclude) { link.transclude = transclude; homecoming link; }; link = function (scope, elem, attrs) { homecoming link.transclude(scope, function (clone) { var body, btn, buttonclass, buttontext, classes, positionfix; classes = (attrs.spmclass ? attrs.spmclass : ""); classes += " spmenu spmenu-" + (attrs.position === "right" || attrs.position === "left" ? "vertical" : "horizontal") + " spmenu-" + attrs.position; elem.addclass(classes); body = angular.element("body"); if (attrs.button) { btn = elem.find(".spmenu-button").addclass("show"); buttontext = attrs.buttontext ? attrs.buttontext : ""; buttonclass = attrs.buttonclass ? attrs.buttonclass : ""; btn.addclass(buttonclass); btn.append("<span class=\"" + buttonclass + "\">" + buttontext + "</span>"); positionfix = (attrs.fixtop ? "top: " + (parseint(attrs.fixtop) + elem.position().top) + "px; " : ""); positionfix += (attrs.fixleft ? "left: " + (parseint(attrs.fixleft) + elem.position().left) + "px; " : ""); btn.attr("style", positionfix); if (attrs.button === "slide") { $document.mouseup(function (e) { if (!elem.is(e.target) && elem.has(e.target).length === 0 && !body.hasclass('modal-open')) { homecoming slidepush.slideforceclose(elem, btn); } }); btn.click(function () { homecoming slidepush.slide(elem, btn); }); } if (attrs.button === "push") { angular.element("body").addclass("spmenu-push"); $document.mouseup(function (e) { if (!elem.is(e.target) && elem.has(e.target).length === 0 && !body.hasclass('modal-open')) { homecoming slidepush.pushforceclose(elem, btn); } }); btn.click(function () { homecoming slidepush.push(elem, btn); }); } } elem.append(clone); if (attrs.open) { homecoming btn.click(); } }); }; homecoming { compile: compile, restrict: "e", replace: true, template: "<nav><a class=\"spmenu-button\"><i class=\"caret\"></i></a></nav>", transclude: "element" }; } ]);

okay, figured out answer. created directive within slide.and.push module. instead of beingness set body element. set main content element id of #content.

.directive('ngclosemenu', [ 'slidepush', function (slidepush) { homecoming { restrict: "a", link: function (scope, elem, attrs) { var content, menu; menu = angular.element("#" + attrs.ngclosemenu); content = angular.element("#content"); content.addclass("spmenu-push"); homecoming elem.click(function () { if (menu.hasclass('spmenu-open')) homecoming slidepush.push(menu, elem); }); } }; }

and utilize so:

<div ui-view id="content" class="spmenu-push" ng-close-menu="menu"></div>

here passing in "menu" id of slide.and.push menu element

angularjs angularjs-directive

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -