ãã®èšäºã§å®è£ ãããŠããã¡ãã¥ãŒæ©èœïŒ
- ã¡ãã¥ãŒã®ãã¹ãŠã®å 容ã¯ããã£ã¬ã¯ãã£ãã®å éšã«é ãããŠããŸãã htmlããŒãžã¬ã€ã¢ãŠãã§ã¯ããã£ã¬ã¯ãã£ããæã€DOMèŠçŽ ã®ã¿ãæå®ããããããã³ãŒããèªã¿ããããªããŸãã
- ãã®ã¡ãã¥ãŒã«ã¯ãç¡éã¬ãã«ã®ãã¹ããæã€ã¢ã€ãã ãäœæããæ©èœããããŸãã
- ã¡ãã¥ãŒå ã®ã¢ã¯ãã£ããªããŒãžã®åŒ·èª¿è¡šç€ºã¯ãæåã®ã¬ãã«ã ãã§ãªãããã¹ãã®ã©ã®ã¬ãã«ã§ãå®è¡ãããŸãã
- ã¢ããªã±ãŒã·ã§ã³æ§æ段éã§ã¡ãã¥ãŒé ç®ãç»é²ããæ©èœã
- çŸåšã®ãŠãŒã¶ãŒã®ã¢ã¯ã»ã¹æš©ã«å¿ããŠç¹å®ã®ã¡ãã¥ãŒé ç®ã衚瀺/é衚瀺ããæ©èœã
ãã£ã¬ã¯ãã£ãã®ãœãŒã¹ã³ãŒãã¯ããã«ãããŸã ã
åœç¶ãç§ã¯ãã¹ãŠããŒãããæžããããã§ã¯ãªãã®ã§ãåããè³æã®ãªã¹ãã¯æ¬¡ã®ãšããã§ã ã
ãªã¹ããèŠã
PS ïŒãã€ã³ã5ã8ã¯ãªãã·ã§ã³ã§ãããææ°ã®ããã³ããšã³ãéçºè ã®ç掻ãå€§å¹ ã«ç°¡çŽ åããŸãã
- AngularJSã¯ã MVVMã¢ããªã±ãŒã·ã§ã³ã¢ãŒããã¯ãã£ãã¶ã€ã³ãã¿ãŒã³ãå®è£ ããGoogleã®ã¹ãŒããŒããŒããŒãã¬ãŒã ã¯ãŒã¯ã§ãã
- UIã«ãŒã¿ãŒã¯Angularã¢ãžã¥ãŒã«ã§ãããããããªããšã ç¶æ ããŒã¹ã®ã¢ããªã±ãŒã·ã§ã³ãèšèšããããšã¯èããããŸããã
- è§åºŠèš±å¯ -è§åºŠã¢ãžã¥ãŒã«ïŒui-routerãšé£æºããŠã®ã¿åäœããŸãïŒãã¯ã©ã€ã¢ã³ãåŽã§ã®ã¢ã¯ã»ã¹å¶åŸ¡ãšæ¿èªãç°¡çŽ åããŸãã
- ããŒãã¹ãã©ãã3-ã¬ã¹ãã³ã·ãããŒãžã®ã¬ã€ã¢ãŠããé«éåããCSSãã¬ãŒã ã¯ãŒã¯ã
- Yeoman Generatorã¯ããããžã§ã¯ãæ§é ãèªåçã«æ§ç¯ããããã®ã³ã³ãœãŒã«ãŠãŒãã£ãªãã£ã§ãã
- Bowerã¯ããããžã§ã¯ãã®äŸåé¢ä¿ã®ã€ã³ã¹ããŒã«ãšæŽæ°ãç°¡çŽ åããããã±ãŒãžãããŒãžã£ãŒã§ãã
- Gulpã¯ã¹ããªãŒãã³ã°JSãããžã§ã¯ããã«ããŒã§ãã
- NodeJSã¯ãµãŒããŒåŽã®éçºç°å¢ã§ãã
PS ïŒãã€ã³ã5ã8ã¯ãªãã·ã§ã³ã§ãããææ°ã®ããã³ããšã³ãéçºè ã®ç掻ãå€§å¹ ã«ç°¡çŽ åããŸãã
ç§ã«ãšã£ãŠæåã®äžå¿«ãªé©ãã¯ããããžã§ã¯ãã®åçŸæ§ã§ããã äžèšã®è£œåã®æ°ããããŒãžã§ã³ãæ¯æ¥ãªãªãŒã¹ãããæ°ãæåã«æšªããã£ãŠãããããžã§ã¯ãã§æ æ ¢ã«æžãããã¡ãã¥ãŒã¯ãæè¿éçºããããããžã§ã¯ãã§ã®äœæ¥ãå®å šã«æåŠããŸããã 以äžã¯ãç§ãééããåé¡ã®ãªã¹ãã§ãã
åé¡ã衚瀺ãã
- è«çåŠå®ïŒfalseã0ãundefinedãnullããŸãã¯ç©ºã®æååïŒã«çããå€ãæã€paramsãªããžã§ã¯ãã®ãã£ãŒã«ããããå ŽåãUI-routerã®ææ°ããŒãžã§ã³ã¯å€±æããŸãã åé¡ã®è§£æ±ºçãèŠã€ãããªãã£ããããã0.2.13ãã®ææ°ã®äœæ¥ããŒãžã§ã³ã«ããŒã«ããã¯ããŸããã
- Yeomanãžã§ãã¬ãŒã¿ãŒã¯ãå°æ¥ã®ã¢ããªã±ãŒã·ã§ã³ã«éåžžã«äŸ¿å©ãªæ§é ãæäŸããŸãã ãµãŒãã¹ãã£ã¬ã¯ããªã«å ããŠããããžã§ã¯ãèªäœã®srcãã£ã¬ã¯ããªãã«ãŒããã£ã¬ã¯ããªã«äœæãããŸãã ã¡ã€ã³ã®htmlããŒãžãš3ã€ã®ãã£ã¬ã¯ããªãå«ãŸããŠããŸãã
app-ã¢ããªã±ãŒã·ã§ã³ã®ç¶æ ãå«ãŸãããã£ã¬ã¯ããªïŒç¶æ ããšã«ãã©ã«ããå²ãåœãŠãããšããå§ãããŸãïŒã
ã¢ã»ãã -éçã³ã³ãã³ããå«ããã©ã«ããŒã
components-ç¹°ãè¿ã䜿çšã§ããã¢ããªã±ãŒã·ã§ã³èŠçŽ ã®ãã©ã«ããŒïŒãã®å Žåããããã¯ãã£ã¬ã¯ãã£ãããµãŒãã¹ããã¡ã¯ããªãŒããããã€ããŒãªã©ã§ãïŒã
ãã®æ§é ã«åŸã£ãŠãYeomanãžã§ãã¬ãŒã¿ãŒã¯å€æŽãç£èŠããå®è¡äžã®ã¢ããªã±ãŒã·ã§ã³ã«ãã¡ã€ã«ãæ·»ä»ããããã«gulpãæ§æããŸãïŒãã¹ãŠãèªåçã«è¡ããããããäŸåé¢ä¿ãHTMLããŒãžã«æåã§æ¥ç¶ããå¿ èŠã¯ãããŸããïŒã
ãžã§ãã¬ãŒã¿ãŒã®ææ°ããŒãžã§ã³ã§ã¯ãcomponentsãã©ã«ããŒãappãã£ã¬ã¯ããªãŒã«ç§»åãããããã«å¿ããŠgulpèšå®ãå€æŽãããŸããã ãããžã§ã¯ããã³ã³ããŒãã³ããã©ã«ããŒã衚瀺ããnavbarã¢ãžã¥ãŒã«ãååšããªãããšã«ã€ããŠéçºè ã³ã³ãœãŒã«ã«ãšã©ãŒã衚瀺ããªãããã«ãgulpãã©ã«ããŒå ã®æ¬¡ã®ãã¡ã€ã«ãç·šéããŸãã
- inject.jsã¹ã¯ãªãã
injectScriptsé åã«èŠçŽ ãè¿œå ããŸã
options.src + '/components/**/*.js'
injectStylesé åã«èŠçŽ ãè¿œå ããŸã
options.src + '/components/**/*.css'
- watch.jsã¹ã¯ãªãã-次ã®ã«ãŒã«ãè¿œå ããŸãã
gulp.watch(options.src + '/components/**/*.css', function(event) { if(isOnlyChange(event)) { browserSync.reload(event.path); } else { gulp.start('inject'); } }); gulp.watch(options.src + '/components/**/*.js', function(event) { if(isOnlyChange(event)) { gulp.start('scripts'); } else { gulp.start('inject'); } }); gulp.watch(options.src + '/components/**/*.html', function(event) { browserSync.reload(event.path); });
- inject.jsã¹ã¯ãªãã
- ãã£ã¬ã¯ãã£ãã¯ããŒãã¹ãã©ããã§èšè¿°ãããŠãããããåœç¶ããã®ã³ã³ããŒãã³ããç¹ã«jQueryã©ã€ãã©ãªãå¿
èŠã§ãã ãããžã§ã¯ããäœæãããšããYeomanã¯jqueryãbootstrapãæ¥ç¶ããå¿
èŠæ§ãšããããæäœããæ¹æ³ïŒangular ui-bootstrapãŸãã¯AngularStrapãã£ã¬ã¯ãã£ããjQueryãŸãã¯pure CSSã§ã®bootstrapã®å
¬åŒäœ¿çšïŒãå°ããŸãã å°ããªãã£ããããããŸãã ã€ã³ã¹ããŒã«æã«ãäžèšã®ãªãã·ã§ã³ãéžæããåã§ããjQueryããããžã§ã¯ãã«è¿œå ããããã«æ±ããããŸãã å¿
ããã®ãªãã·ã§ã³ãéžæããŠãã ãããããããªããšãéèŠãªäŸåé¢ä¿ããªããªãããã¹ãŠãå£ããŸãã
PS ïŒå®éãç¬éãä¿®æ£ããããšã¯é£ãããããŸããã å¿ èŠãªã®ã¯ããã£ã¬ã¯ãã£ãèªäœã®ã³ãŒããã·ã£ãŒããã€ãºããããšã ãã§ãjQueryãªãã§ãå®è¡ã§ããŸããã圌ããèšãããã«ããåäœããŸã-觊ããªãã§ãã ãããã
- Yeomanããããžã§ã¯ãã«å«ããããšãææ¡ããŠããGoogleã®è§æã§ãããžã§ã¯ãã楜ãã¿ããå Žåã¯ããã®å Žåãå€ãããŒãžã§ã³ã®ã©ã€ãã©ãªãæ¥ç¶ãããããšãç¥ã£ãŠããå¿ èŠããããŸããå ¬åŒãµã€ãã®ããã¥ã¡ã³ãã¯é©åã§ã¯ãããŸããã ãããã£ãŠãæ£ãããªãã·ã§ã³ã¯ãbowerã«--saveãªãã·ã§ã³ã䜿çšããŠã©ã€ãã©ãªãæ¥ç¶ããããšã§ãã
çµç¹çãªåŽé¢ãå®æããããæ什èªäœã®èšè¿°ã«é²ã¿ãŸãã
䟿å®äžããã£ã¬ã¯ãã£ãã®htmlãã³ãã¬ãŒããå¥ã®ãã¡ã€ã«ããåé€ããŸãã
ãã³ãã¬ãŒãã衚瀺
<div class="container" ng-mouseleave="closeMenu($event)"> <div class="navbar-header"> <button type="button" class="navbar-toggle" ng-click="collapseMenu($event)"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="link-kukuri" href="#" ui-sref="{{::sref}}" data-letters="{{::name}}">{{::name}}</a> </div> <div id="navbar" class="collapse navbar-collapse" aria-expanded="false" ng-class="navCollapsed"> <ul class="nav navbar-nav navbar-right"> <li ng-repeat="items in navbar" class="{{::menuClass(items.name, 'firstLevel')}} list-status"> <a href="#" ng-if="!items.name.pop" ui-sref="{{items.state}}" ng-mouseenter="closeOnMoveMenu()">{{items.name}}</a> <a href="#" ng-if="items.name.pop" class="dropdown-toggle dropdown-toggle-firstLevel" dropdown-toggle aria-expanded="false" ng-click="expandMenu($event)" ng-mouseenter="expandMenu($event)" ng-mouseleave="closeSubMenu($event)"> {{::items.name[0]}}<b class="caret"></b> </a> <ul ng-if="items.name.pop" class="dropdown-menu" ng-include="'submenu.template'"></ul> </li> </ul> </div> </div> <script type="text/ng-template" id="submenu.template"> <li ng-repeat="items in items.name" ng-if="$index !== 0" class="{{::menuClass(items.name)}} sub-menu"> <a href="#" class="sub-link" ng-if="!items.name.pop" ui-sref="{{::items.state}}" ng-mouseenter="closeOnMoveSubMenu($event)"> {{::items.name}}</a> <a href="#" ng-if="items.name.pop" class="dropdown-toggle" data-toggle="dropdown" ng-click="expandSubMenu($event)" ng-mouseenter="expandSubMenu($event)"> {{::items.name[0]}} </a> <ul ng-if="items.name.pop" class="dropdown-menu" ng-include="'submenu.template'"> </ul> </li> </script>
å®éãããã¯ããããªãã¥ã¢ã³ã¹ãæã€ããŒãã¹ãã©ããããã¥ã¡ã³ãã®æšæºã¡ãã¥ãŒã®ä¿®æ£ã§ãã
æ©èœã衚瀺
- ã¡ãã¥ãŒé
ç®ã®ãªã¹ãã¯ã ng-repeatãã£ã¬ã¯ãã£ãã䜿çšããŠçæãããŸããng-repeatãã£ã¬ã¯ãã£ãã¯ãæºåãããhtmlãã³ãã¬ãŒããè€è£œããçŸåšã®ãã£ã¬ã¯ãã£ãã¹ã³ãŒãã§å®çŸ©ãããã¡ãã¥ãŒé
ç®ã®é
åããããŒã¿ã眮ãæããŸãã ãã®ãã³ãã¬ãŒãã§ã¯ãå€æ°ã®è¿ãã«2ã€ã®ãã€ã³ããããæ§æïŒããšãã°{{:: name}} ïŒãã1åéãã®å²ãåœãŠãšåŒã°ããããšã«æ³šæããŠãã ããã å®éã«ã¯ãè§åºŠããšã«åå¥ã®ãªã¹ããŒïŒãŠã©ããã£ãŒïŒãäœæãããåãã€ãžã§ã¹ãã§ãã®å€æŽã確èªãããŸãïŒå€ãå€æŽãããéããçŸåšã®ã¹ã³ãŒãå
ã®ãã¹ãŠã®å€æ°ã®å€æŽã確èªããæåŸã«DOMã¯æ°ããå€ã§æç»ãããŸãïŒ ã ã¡ãã¥ãŒã®é
ç®ã¯å®æ°å€ã§ããããããªã¹ããŒã®æ°ãæžãããŠçç£æ§ãé«ããªãããäžåºŠã ãæç»ããã®ãçã«ããªã£ãŠããŸãã
- ãã¹ãããããµãã¢ã€ãã ã¯ã ng-includeã䜿çšããŠååž°çã«åéãããŸã ã ãã³ãã¬ãŒãã®ååž°éšåã¯ãå±æ§type = "text / ng-template"㧠scriptã¿ã°ã«ä¿åãããŸã ã ãã©ãŠã¶ã¯ãã®ã¿ã€ãã®ã¹ã¯ãªãããèªèãããDOMã®ãã®éšåãåŠçããŸããããng-includeãã£ã¬ã¯ãã£ãã¯ã¹ã¯ãªããã®ã³ã³ãã³ãã®ã¿ãé©åãªå Žæã«æ¿å
¥ããŸããããã«ããããã©ãŠã¶ã¯éåžžDOMèŠçŽ ãåŠçã§ããŸãã
ãã¹ãèªäœã¯ng-ifãã£ã¬ã¯ãã£ãã«ãã£ãŠå¶åŸ¡ãããŸããng-ifãã£ã¬ã¯ãã£ãã¯ãçŸåšã®èŠçŽ ãã¢ã€ãã ã®é åã§ããããã¢ã€ãã ã®ååãæã€æååã§ãããããã§ãã¯ããŸãã ãã§ãã¯ã¯ãããããã ã¢ãã«ã¿ã€ãã³ã° ãã䜿çšããŠå®è¡ãããŸã ãé åãããå Žåãé åã¡ãœããïŒããã·ã¥ãããããªã©ïŒããããããã«ã¢ã¯ã»ã¹ããããšã§ïŒïŒãè«çtrueã«çããé¢æ°ãè¿ããŸãã æååãããå Žåãé åã¡ãœãããžã®ãã®ãããªã¢ããŒã«ã¯æªå®çŸ©ãè¿ããŸãã
- è§åºŠãã£ã¬ã¯ãã£ããæäœããããã®æé»ã®ã«ãŒã«ããããããã£ã¬ã¯ãã£ãã¯DOMããªãŒã®èŠçŽ ããã®èŠçŽ ã®å€åŽã§å€æŽããŠã¯ãªããªãããšè¿°ã¹ãŠããŸãã ãããã¢ããã¡ãã¥ãŒé ç®ãæ©èœãããã«ã¯ãã«ãŒãœã«ã§èŠçŽ ãã¯ãªãã¯ããã€ã³ããããã³é¢ããã€ãã³ãã远跡ãããªã¹ããŒãå¿ èŠã§ãã DOMããªãŒèŠçŽ ã®ã»ã¬ã¯ã¿ãŒã«ããéåžžã®èŠçŽ æ€çŽ¢ã䜿çšãããªã¹ããŒããããã«ãã³ã°ãããããšãã§ããŸãã ãããã倧èŠæš¡ãªãããžã§ã¯ãã§ã¯ãä»ã®èª°ããåãã»ã¬ã¯ã¿ãŒåã䜿çšããå¯èœæ§ããããŸãã ãã®ãããªã€ãã³ãã®çµæã¯äºæž¬äžèœã§ã:)ãã®ãããªå Žåããã£ã¬ã¯ãã£ãng-clickãng-mouseenterããã³ng-mouseleaveãæäŸããã察å¿ããèŠçŽ ã«æããããŸããã
以äžã¯ã cssãã¡ã€ã«ã®æŠèŠã§ã ã
CSSã衚瀺
@import urlïŒhttp://fonts.googleapis.com/css?family=Gloria+HallelujahïŒ;
.navbar-brand {
ãã©ã³ããã¡ããªïŒãã°ããªã¢ãã¬ã«ã€ãããã«ãããã¿ããã
ãã©ã³ããµã€ãºïŒ23px;
}
.sub-menu {
èæ¯è²ïŒïŒ333;
}
.sub-menu> a {
è²ïŒïŒ9d9d9dïŒéèŠ;
padding-leftïŒ10pxïŒéèŠ;
}
.dropdown-menu {
ããã£ã³ã°ïŒ0px;
ããŒãžã³å·ŠïŒ-1px;
ããŒãžã³å³ïŒ-1px;
min-widthïŒ90pxïŒéèŠ;
}
.dropdown-submenu {
äœçœ®ïŒçžå¯Ÿ;
}
.dropdown-submenu> .dropdown-menu {
topïŒ0;
å³ïŒ100ïŒ ;
ããŒãžã³äžéšïŒ6px;
ããŒãžã³å·ŠïŒ-1px;
-webkit-border-radiusïŒ0 6px 6px 6px;
-moz-border-radiusïŒ0 6px 6px 6px;
ããŒããŒååŸïŒ0 6px 6px 6px;
}
.dropdown-submenuïŒhover> aïŒ{ã®åŸ
border-left-colorïŒ#ffffff;
}
.dropdown-submenu.pull-left {
floatïŒãªã;
}
.dropdown-submenu.pull-left> .dropdown-menu {
å·ŠïŒ-100ïŒ ;
ããŒãžã³å·ŠïŒ10px;
-webkit-border-radiusïŒ6px 0 6px 6px;
-moz-border-radiusïŒ6px 0 6px 6px;
ããŒããŒååŸïŒ6px 0 6px 6px;
}
.dropdown-submenu> aïŒbefore {
ãã£ã¹ãã¬ã€ïŒãããã¯;
å å®¹ïŒ "";
floatïŒå·Š;
å¹ ïŒ0;
é«ãïŒ0;
ããŒããŒã¹ã¿ã€ã«ïŒãœãªãã;
border-colorïŒtransparent #cccccc transparent transparent;
ããŒãžã³äžéšïŒ7px;
ããŒãžã³å·ŠïŒ-5px;
ããŒãžã³å³ïŒ10px;
}
.dropdown-submenu-big> aïŒ{
ããŒããŒå¹ ïŒ4.5px 7.8px 4.5px 0;
}
.dropdown-submenu-small> aïŒbefore {
ããŒãžã³å³ïŒ7px;
ããŒããŒå·ŠïŒ5pxã®éæãªãœãªãã;
ããŒããŒå³ïŒ5pxã®éæãªéæ;
border-topïŒ5px solid #cccccc;
}
.dropdown-menuïŒãããŒã
.dropdown-toggleïŒãã©ãŒã«ã¹ã
li> [aria-expanded = "true"]ã
.navbar-brandïŒãããŒã
.sub-menu> aïŒãããŒã
.list-statusïŒãããŒã
.nav .open> a {
è²ïŒ#fffïŒéèŠ;
èæ¯è²ïŒïŒ004444ïŒéèŠ;
}
.menu-activeã
.menu-active> a {
ãã©ã³ãã®å€ªãïŒå€ªåïŒéèŠ;
ããã¹ãè£ é£ŸïŒäžç·ã
}
.navbar-cheat {
å¹ ïŒ100ïŒ ;
é«ãïŒ45px;
}
.sub-linkïŒbefore {
ãã£ã¹ãã¬ã€ïŒãããã¯;
å å®¹ïŒ "";
floatïŒå·Š;
å¹ ïŒ12px;
é«ãïŒ5px;
}
/ *ããã* /
.link-kukuri {
ãã©ã³ããã¡ããªãŒïŒãã°ããªã¢ã»ãã¬ã«ã€ãã
ã¢ãŠãã©ã€ã³ïŒãªã;
ããã¹ãè£ é£ŸïŒãªãïŒéèŠ;
äœçœ®ïŒçžå¯Ÿ;
ãã©ã³ããµã€ãºïŒ23px;
è¡ã®é«ãïŒ2;
è²ïŒïŒc5c2b8;
衚瀺ïŒã€ã³ã©ã€ã³ãããã¯ã
}
.link-kukuriïŒãããŒ{
è²ïŒïŒc5c2b8;
}
.link-kukuriïŒãããŒ::åŸ{
-webkit-transformïŒtranslate3dïŒ100ïŒ ã0,0ïŒ;
transformïŒtranslate3dïŒ100ïŒ ã0,0ïŒ;
}
.link-kukuri :: before {
å 容ïŒattrïŒããŒã¿æåïŒ;
äœçœ®ïŒçµ¶å¯Ÿ;
z-indexïŒ2;
ãªãŒããŒãããŒïŒé衚瀺ã
è²ïŒïŒ424242;
空çœïŒnowrap;
å¹ ïŒ0ïŒ ;
-webkit-transitionïŒå¹ 0.4s 0.0s;
é·ç§»ïŒå¹ 0.4s 0.0s;
}
.link-kukuriïŒãããŒ::ã®å{
å¹ ïŒ100ïŒ ;
}
.link-kukuriïŒãã©ãŒã«ã¹{
è²ïŒïŒ9e9ba4;
}
.navbar-brand {
ãã©ã³ããã¡ããªïŒãã°ããªã¢ãã¬ã«ã€ãããã«ãããã¿ããã
ãã©ã³ããµã€ãºïŒ23px;
}
.sub-menu {
èæ¯è²ïŒïŒ333;
}
.sub-menu> a {
è²ïŒïŒ9d9d9dïŒéèŠ;
padding-leftïŒ10pxïŒéèŠ;
}
.dropdown-menu {
ããã£ã³ã°ïŒ0px;
ããŒãžã³å·ŠïŒ-1px;
ããŒãžã³å³ïŒ-1px;
min-widthïŒ90pxïŒéèŠ;
}
.dropdown-submenu {
äœçœ®ïŒçžå¯Ÿ;
}
.dropdown-submenu> .dropdown-menu {
topïŒ0;
å³ïŒ100ïŒ ;
ããŒãžã³äžéšïŒ6px;
ããŒãžã³å·ŠïŒ-1px;
-webkit-border-radiusïŒ0 6px 6px 6px;
-moz-border-radiusïŒ0 6px 6px 6px;
ããŒããŒååŸïŒ0 6px 6px 6px;
}
.dropdown-submenuïŒhover> aïŒ{ã®åŸ
border-left-colorïŒ#ffffff;
}
.dropdown-submenu.pull-left {
floatïŒãªã;
}
.dropdown-submenu.pull-left> .dropdown-menu {
å·ŠïŒ-100ïŒ ;
ããŒãžã³å·ŠïŒ10px;
-webkit-border-radiusïŒ6px 0 6px 6px;
-moz-border-radiusïŒ6px 0 6px 6px;
ããŒããŒååŸïŒ6px 0 6px 6px;
}
.dropdown-submenu> aïŒbefore {
ãã£ã¹ãã¬ã€ïŒãããã¯;
å å®¹ïŒ "";
floatïŒå·Š;
å¹ ïŒ0;
é«ãïŒ0;
ããŒããŒã¹ã¿ã€ã«ïŒãœãªãã;
border-colorïŒtransparent #cccccc transparent transparent;
ããŒãžã³äžéšïŒ7px;
ããŒãžã³å·ŠïŒ-5px;
ããŒãžã³å³ïŒ10px;
}
.dropdown-submenu-big> aïŒ{
ããŒããŒå¹ ïŒ4.5px 7.8px 4.5px 0;
}
.dropdown-submenu-small> aïŒbefore {
ããŒãžã³å³ïŒ7px;
ããŒããŒå·ŠïŒ5pxã®éæãªãœãªãã;
ããŒããŒå³ïŒ5pxã®éæãªéæ;
border-topïŒ5px solid #cccccc;
}
.dropdown-menuïŒãããŒã
.dropdown-toggleïŒãã©ãŒã«ã¹ã
li> [aria-expanded = "true"]ã
.navbar-brandïŒãããŒã
.sub-menu> aïŒãããŒã
.list-statusïŒãããŒã
.nav .open> a {
è²ïŒ#fffïŒéèŠ;
èæ¯è²ïŒïŒ004444ïŒéèŠ;
}
.menu-activeã
.menu-active> a {
ãã©ã³ãã®å€ªãïŒå€ªåïŒéèŠ;
ããã¹ãè£ é£ŸïŒäžç·ã
}
.navbar-cheat {
å¹ ïŒ100ïŒ ;
é«ãïŒ45px;
}
.sub-linkïŒbefore {
ãã£ã¹ãã¬ã€ïŒãããã¯;
å å®¹ïŒ "";
floatïŒå·Š;
å¹ ïŒ12px;
é«ãïŒ5px;
}
/ *ããã* /
.link-kukuri {
ãã©ã³ããã¡ããªãŒïŒãã°ããªã¢ã»ãã¬ã«ã€ãã
ã¢ãŠãã©ã€ã³ïŒãªã;
ããã¹ãè£ é£ŸïŒãªãïŒéèŠ;
äœçœ®ïŒçžå¯Ÿ;
ãã©ã³ããµã€ãºïŒ23px;
è¡ã®é«ãïŒ2;
è²ïŒïŒc5c2b8;
衚瀺ïŒã€ã³ã©ã€ã³ãããã¯ã
}
.link-kukuriïŒãããŒ{
è²ïŒïŒc5c2b8;
}
.link-kukuriïŒãããŒ::åŸ{
-webkit-transformïŒtranslate3dïŒ100ïŒ ã0,0ïŒ;
transformïŒtranslate3dïŒ100ïŒ ã0,0ïŒ;
}
.link-kukuri :: before {
å 容ïŒattrïŒããŒã¿æåïŒ;
äœçœ®ïŒçµ¶å¯Ÿ;
z-indexïŒ2;
ãªãŒããŒãããŒïŒé衚瀺ã
è²ïŒïŒ424242;
空çœïŒnowrap;
å¹ ïŒ0ïŒ ;
-webkit-transitionïŒå¹ 0.4s 0.0s;
é·ç§»ïŒå¹ 0.4s 0.0s;
}
.link-kukuriïŒãããŒ::ã®å{
å¹ ïŒ100ïŒ ;
}
.link-kukuriïŒãã©ãŒã«ã¹{
è²ïŒïŒ9e9ba4;
}
ç¹å¥ãªããšã¯äœããããŸãããã¡ãã¥ãŒã®ã³ãŒãã¯ããã§ã貞ãããããŽã¢ãã¡ãŒã·ã§ã³ã¯ãã¡ãã§ãã
ãšãŠããã£ãããšãç§ãã¡ã¯ãã®èšäºãèæ¡ãããæãèå³æ·±ãéšåã«å°éããŸãã-è§ã®ã¡ãã¥ãŒæ瀺ã³ãŒãã§ãã
navbar.module.jsãã¡ã€ã«
'use strict'; (function () { angular.module('navbar', ['ui.router']); })();
ããã°ã©ãã³ã°æåããå§ããŸãããã è§åºŠèªäœã¯ãå€ãã®æ··ä¹±ãèš±ããªãããã«èšèšãããŠããŸãããå³å¯ãª ' use strict 'ã¢ãŒãã䜿çšã ãã¢ãžã¥ãŒã«ã³ãŒããå¿åé¢æ°ã§ã©ããããã®ãé©åãªåœ¢åŒãšèŠãªãããŸãã
ãã®ãããªå€§éã®æ©èœãå¥ã®ãã¡ã€ã«ã«ãŸãšããããŠããã®ã¯ãªãã§ããããïŒ ãã¹ãŠãéåžžã«ç°¡åã§ãã ã¢ã³ã®ã¥ã©ãŒã®å©ç¹ã®1ã€ã¯ãã®ã¢ãžã¥ãŒã«æ§ã§ããããã«ããããããããžã§ã¯ãããå¥ã®ãããžã§ã¯ãã«æ©èœãç°¡åã«ç§»è¡ã§ããŸãã ãã®å Žåãå¥ã®ã¢ãžã¥ãŒã« ' navbar 'ã宣èšããŸããããã¯ãåŸã§ãã£ã¬ã¯ãã£ããã³ã³ãããŒã©ãŒãå·¥å Žããã®ä»ã®åã³ãæããããšãã§ããŸãã
åæã«ãæ©èœãå¥ã®ãããžã§ã¯ãã«è»¢éãããšããããã«å¿ã㊠' navbar 'ã¢ãžã¥ãŒã«ãæ¥ç¶ããã ãã§ååã§ãã ããã«ããã£ãŠããä»ã®ãã¹ãŠã®äŸåé¢ä¿ã¯ã¢ããŠã³ã¹ãå¿ èŠãšãããèªåçã«åŒ·åãããŸãã
ãããšã¯å¥ã«ãã¢ãžã¥ãŒã«ã宣èšãããšãã®2çªç®ã®åŒæ°ã¯ããã®æäœã«å¿ èŠãªäŸåé¢ä¿ã®é åã§ããããšã«æ³šæããŠãã ããã ãã®å Žåãã ui-router ãã§ãã äŸåé¢ä¿ããªãå Žåã¯ã空ã®é åãæå®ããå¿ èŠããããŸããæå®ããªããšãã¢ãžã¥ãŒã«ãå¥ã®ã¢ããªã±ãŒã·ã§ã³ã«ãšã¯ã¹ããŒãã§ããŸããã
å€ãã®å Žåãäºåèµ·åã¢ããªã±ãŒã·ã§ã³ã®èšå®ãå®è¡ããå¿ èŠããããŸããããã¯ããã£ã¬ã¯ãã£ããã³ã³ãããŒã©ãŒãããã³ãµãŒãã¹ã®èµ·ååã«å®è¡ãããŸãã ãã®ãããªæäœã¯ã configã»ã¯ã·ã§ã³ïŒã¢ããªã±ãŒã·ã§ã³ã®åæåäžã«1åå®è¡ãããïŒããã³runã»ã¯ã·ã§ã³ïŒèšè¿°ãããŠããç¶æ ã«ç§»è¡ãããã³ã«å®è¡ãããïŒã§å®è¡ãããŸãã ãããã®èšå®ã®ã³ãŒããäžèšã®ãã¡ã€ã«ã«ä¿åããŠãããšéåžžã«äŸ¿å©ã§ãã
navbar.directive.jsãã¡ã€ã« ïŒ
navbar.directive.jsã衚瀺
'use strict'; (function () { angular.module('navbar') .directive('navbar', function ($document, $state, navbarList, navPermission) { return { restrict: 'A', scope: { name: '@', sref: '@' }, templateUrl: '/components/navbar.directive/navbar.template.html', link: function (scope, elem) { var openedMenu = null, openedSubMenu = null, username = navPermission.getUser($state.params); // DOM bootstrap elem.addClass('navbar navbar-inverse navbar-fixed-top'); elem.attr('role', 'navigation'); // scope if(username) { navPermission.acceptPermission(navbarList.list, username); } scope.navbar = navbarList.list; // / scope.collapseMenu = function ($event) { var navbar = elem.find('#navbar'), expanded = navbar.hasClass('in'); navbar.attr('aria-expanded', !expanded); scope.navCollapsed = (expanded) ? '' : 'in'; closeAllMenu(); stopBubleAndPropagation($event); }; // , scope.menuClass = function (item, level) { var status = false, activePage = getActivePage($state.current.name), currentPage = (item.pop) ? item[0] : item, classList = (level === 'firstLevel') ? 'dropdown dropdown-firstLevel ' : 'menu-item dropdown dropdown-submenu ', activeClass = (currentPage === activePage || isActive(item, activePage, status) ) ? 'menu-active' : ''; if(item.pop) { return classList + activeClass; } else { return activeClass; } }; // () function getActivePage(state, currentList) { var name; if(!currentList) { currentList = scope.navbar; } for(var i = (currentList[0].name) ? 0 : 1; i < currentList.length; i++) { if(currentList[i].state === state) { return currentList[i].name; } else if(currentList[i].name.pop) { name = getActivePage(state, currentList[i].name); } } return name; } // , function isActive (item, activePage, status) { if(item.pop) { for(var i = 1; i < item.length; i++) { if(item[i].name.pop) { status = isActive(item[i].name, activePage, status); } else if(item[i].name === activePage) { return true; } } } else if(item === activePage) { return true; } return status; } // ( , .. ) scope.expandMenu = function ($event) { var clickedElem = $($event.currentTarget), parentClicked = $($event.currentTarget.parentElement), expanded = clickedElem.attr('aria-expanded'), isOpened = parentClicked.hasClass('open'), attrExpanded = (expanded === 'false'), allOpenedMenu = parentClicked.parent().find('.open'), smallWindow = window.innerWidth < 768, eventMouseEnter = $event.type === 'mouseenter', subMenuAll = elem.find('.dropdown-submenu'); if(!smallWindow || !eventMouseEnter) { allOpenedMenu.removeClass('open'); clickedElem.attr('aria-expanded', attrExpanded); if(isOpened && !eventMouseEnter) { parentClicked.removeClass('open'); } else { parentClicked.addClass('open'); openedMenu = clickedElem; //** } } subMenuAll.removeClass('dropdown-submenu-small dropdown-submenu-big'); if(smallWindow) { subMenuAll.addClass('dropdown-submenu-small'); } else { subMenuAll.addClass('dropdown-submenu-big'); } stopBubleAndPropagation($event); }; // scope.closeOnMoveMenu = function () { var smallWindow = window.innerWidth < 768; if(openedMenu && !smallWindow) { var clickedLink = openedMenu, clickedElement = clickedLink.parent(); clickedElement.removeClass('open'); clickedLink.attr('aria-expanded', false); openedMenu = null; } }; // ( 92 ) scope.expandSubMenu = function ($event) { var elemClicked = $($event.currentTarget.parentElement), smallWindow = window.innerWidth < 768, eMouseEnter = $event.type === 'mouseenter', sameElement = elemClicked.hasClass('open'); if(!smallWindow || !eMouseEnter) { // if(!sameElement && !eMouseEnter || !eMouseEnter || !sameElement) { elemClicked.parent().find('.open').removeClass('open'); } if(!sameElement) { elemClicked.addClass('open'); openedSubMenu = elemClicked; } } stopBubleAndPropagation($event); }; // ( :)) scope.closeOnMoveSubMenu = function ($event) { var smallWindow = window.innerWidth < 768; if(openedSubMenu && !smallWindow) { var clickedElement = openedSubMenu, savedList = clickedElement.parent(), currentList = $($event.target).parent().parent(); if(savedList[0] === currentList[0]) { clickedElement.removeClass('open'); openedSubMenu = null; } } }; scope.closeMenu = closeMenu; // var $body = $document.find('html'); elem.bind('$destroy', function() { $body.unbind(); // }); // - $body.bind('click', closeMenu); function closeMenu ($event) { var elemClicked = $event.relatedTarget || $event.target; if(isClickOutNavbar(elemClicked)) { closeAllMenu(); } } // , , function isClickOutNavbar(elem) { if($(elem).hasClass('dropdown-firstLevel')) { return false; } if(elem.parentElement !== null) { return isClickOutNavbar(elem.parentElement); } else { return true; } } // function closeAllMenu() { elem.find('.open').removeClass('open'); elem.find('[aria-expanded=true]').attr('aria-expanded', false); } // function stopBubleAndPropagation($event) { $event.stopPropagation(); $event.preventDefault(); } } }; }); })();
ç§ã¯ãæ什ã«èšèŒãããŠããã³ãŒããèªãã«æã£ãŠããªãããšã«ããã«æ³šæããŸãã ããŸãèå³ããªã ããŸããŸãªç»é¢è§£å床ã®ã¡ãã¥ãŒãéãããéããããã¢ã€ãã ã®ã¿ã€ãã«å¿ããŠå¿ èŠãªã¯ã©ã¹ãå²ãåœãŠãæ©èœã説æããã ãã§ãã 2ã€ã®ååž°é¢æ°ã¯ãå€ããå°ãªããæçšãªæ å ±ãäŒéããŸãããŠãŒã¶ãŒãã¡ãã¥ãŒã®å€åŽãã¯ãªãã¯ããããšã確èªããïŒ181è¡ç®ïŒããã³ã¡ãã¥ãŒé ç®ãã¢ã¯ãã£ããã©ããã確èªããïŒ70è¡ç®ïŒã
ç§ã®èŠ³ç¹ããæ£ããè¡ãããããšã«æ³šæããŠãã ããïŒ
- ãã£ã¬ã¯ãã£ãã«ã¯ã nameããã³srefãã©ã¡ãŒã¿ãŒãèŠçŽ ã®å±æ§ãä»ããŠã¹ããŒãããéé¢ãããã¹ã³ãŒãããããŸãã ã€ãŸã 倧èŠæš¡ãªãããžã§ã¯ãã§ã¯ãåé¡ãçºçããå¯èœæ§ãäœããªããŸãã
- è€éãªæ§é ïŒèŠçŽ ã®æ€çŽ¢ãå±æ§ã®ãã§ãã¯ïŒã¯å€æ°ã«ãªããŸãã å€æ°ãšé¢æ°ã®ååã¯ããããã®ç®çã瀺ããŠããŸãã
ã©ã¯ãè¡šèšã®åœ¢åŒã§ã®åœåã¯é©åãªåœ¢åŒãšèŠãªãããŸãã ãŸããè€æ°ã®å€æ°ãé£ç¶ããŠã³ãŒãå ã§å®£èšãããŠããå Žåãåžžã«varãèšè¿°ããããšã¯æå³ããããŸãããå€æ°ãã³ã³ãã§åºåã£ãŠåçŽã«ãªã¹ãã§ããããã«è¯ãããšã«ãåè¡ãæ°ããè¡ããæå®ã§ããŸãã ããã«ãããã³ãŒããèªã¿ããããªããŸãã
äœãééã£ãŠããïŒ
- ã³ãŒããè€éããããããäžéšã®æ©èœãããåçŽãªæ©èœã«åå²ã§ããŸãã äž»ãªã«ãŒã«ïŒé¢æ°ãäœããããã粟ç¥çã«çºé³ãããAndãã®æåããã¬ãŒãºãã¹ãããããå Žåãé¢æ°ãããåçŽãªãã®ã«åå²ããå¿ èŠããããŸãã
- ããŸãã«ãäºçŽ°ãªã³ã¡ã³ãã è¯ãã³ãŒãã¯ããããäœãããã®ããèªãã¹ãã§ãã ã³ã¡ã³ãã«ã¯ãç解ããã®ãé£ããç¬éããŸãã¯åçŽãªãã®ã§ã¯ãªããããè€éãªãœãªã¥ãŒã·ã§ã³ãéžæããã³ãŒãã®ã»ã¯ã·ã§ã³ãå¿
èŠã§ãã ã·ã³ãã«ãªãã®ãããªãã«åããªãã£ãã
ãã®å Žåãã³ã¡ã³ãã¯ãèªè ãåé¡ã®æ¬è³ªãç解ããããããããã«æžãããŠããŸãã
navbar.provider.jsãã¡ã€ã«
ããã§ãç§ãã¡ã®ãã£ã¬ã¯ãã£ãã¯å®è£ ãããŠåäœããŠããŸãããã¡ãã¥ãŒé ç®ã®ãªã¹ããã©ãã§å ¥æã§ããŸããïŒ ãã£ã¬ã¯ãã£ãèªäœã«ãã€ã³ãã®é åãèšè¿°ããããšã¯å¯èœã§ãããããã¯ã¢ããªã±ãŒã·ã§ã³ç¶æ ã®ãã®åŸã®è¿œå /åé€ã«ã¯äžäŸ¿ã§ãã ãã£ã¬ã¯ãã£ãã®ãã€ã³ãã®é åã«ç»ãå¿ èŠããããã³ã«ãé©åãªå Žæãæ¢ããŠæ°ããå Žæãè¿œå ããŸãã ãŸããç¶æ ãåé€ãããšããéåžžãã¡ãã¥ãŒå ã®ã¢ã€ãã ã®ååšãå¿ããããšãã§ããŸããããã¯ããŠãŒã¶ãŒãããŒãžã«ã¢ã¯ã»ã¹ããããšãããšãã«ãšã©ãŒã«ã€ãªããå¯èœæ§ããããŸãã
ç¶æ³ããæãåºãæ¹æ³ã¯æããã§ã-ç¹å®ã®ç¶æ ã®èª¬æã®ããé£ã«åã¡ãã¥ãŒé ç®ãç»é²ããå¿ èŠããããŸãã ããããªãã¥ã¢ã³ã¹ããããŸãã Angularã¢ããªã±ãŒã·ã§ã³ã®åæåé åºã¯æ¬¡ã®ãšããã§ãã
- ç»é²æžã¿ã®è§åºŠã¢ãžã¥ãŒã«ïŒã¢ãžã¥ãŒã«ïŒã®æ¥ç¶ã
- ãããã€ããŒïŒãããã€ããŒïŒã®ç»é²ã
- æ§æã»ã¯ã·ã§ã³ã®åŠçïŒã¢ããªã±ãŒã·ã§ã³ã®åæåäžã«1åå®è¡ïŒã
- ç»é²ãã¡ã¯ããªããµãŒãã¹ãå€ãå®æ°ã
- å®è¡ã»ã¯ã·ã§ã³ã®åŠçïŒç¶æ ãå€ãããã³ã«å®è¡ãããŸãïŒã
- ã³ã³ãããŒã©ãŒããã³ãã£ã¬ã¯ãã£ãã®ç»é²ã
ãã¥ãŒã«åºã¥ããŠãæ§æã»ã¯ã·ã§ã³ã¯ã ãããã€ããŒã®ã¿ãå©çšå¯èœãªç§ãã¡ã«é©ããŠããŸãã å¿ èŠã«å¿ããŠååãæ¥ç¶ããã ãã§ãã¢ããªã±ãŒã·ã§ã³ã®ä»»æã®éšåãããããã€ããŒã«ã¢ã¯ã»ã¹ã§ããŸãã æ§æ段éã§ã¯ããããã€ããŒã«ã Provider ããè¿œå ããŠååã«ã¢ã¯ã»ã¹ã§ããŸããããšãã°ããããã€ããŒã®ååãnavbarListã®å Žåãæ§æã»ã¯ã·ã§ã³ã§ã¯navbarListProviderãšããååã§äœ¿çšã§ããŸãã
ãããã€ããŒã®ã³ãŒãã¯æ¬¡ã®ãšããã§ãã
navbar.provider.jsã衚瀺
'use strict'; (function () { angular.module('navbar') .provider('navbarList', function () { var list = []; // this.add = function (obj) { // if(obj.location) { if(obj.location.place.length !== obj.location.priority.length || !obj.location.place.pop || !obj.location.priority.pop) { console.log('Warning! Bad location params for menu "' + obj.name + '". Skip item'); return; } } // if(!obj.location) { var name = obj.name; for(var i = 0; i < list.length; i++) { // var currentName = (list[i].name.pop) ? list[i].name[0] : list[i].name; if(currentName === name) { console.log('Warning! Duplicate menu "' + name + '". Skip item'); return; } } list.push(obj); list.sort(sortByPriority); return; } // , var place = obj.location.place.shift(), priority = obj.location.priority.shift(); for(i = 0; i < list.length; i++) { // , i JS var currentSubName = (list[i].name.pop) ? list[i].name[0] : null; if(place === currentSubName) { list[i].name = changeExistPart(obj, list[i].name); if(priority !== list[i].priority) { console.log('Warning! Priority of menu "' + list[i].name + '" has been changed from "' + list[i].priority + '" to "' + priority + '"'); list[i].priority = priority; list.sort(sortByPriority); } return; } currentName = list[i].name; if(place === currentName) { console.log('Warning! Duplicate submenu "' + place + '". Skip item'); return; } } // , list.push( { name: [place, makeOriginalPart(obj)], priority: priority } ); list.sort(sortByPriority); }; // function changeExistPart(obj, list) { var place = obj.location.place.shift(), priority = obj.location.priority.shift(), // searchName = (place) ? place : obj.name; for(var i = 1; i < list.length; i++) { var currentName = (list[i].name.pop) ? list[i].name[0] : list[i].name; if(searchName === currentName) { if(!list[i].name.pop || (!place && list[i].name.pop) ) { console.log('Warning! Duplicate menu "' + searchName + '". Skip item'); return list; } else { list[i].name = changeExistPart(obj, list[i].name); if(priority !== list[i].priority) { console.log('Warning! Priority of menu "' + list[i].name + '" has been changed from "' + list[i].priority + '" to "' + priority + '"'); list[i].priority = priority; list.sort(sortByPriority); } return list; } } } if(!place) { delete obj.location; list.push(obj); } else { list.push({ name: [place, makeOriginalPart(obj)], priority: priority }); } list.sort(sortByPriority); return list; } // , function makeOriginalPart (obj) { var place = obj.location.place.shift(), priority = obj.location.priority.shift(); if(place) { var menu = { priority: priority, name: [place, makeOriginalPart(obj)] }; } else { delete obj.location; menu = obj; } return menu; } // function sortByPriority(a, b) { return a.priority - b.priority; } // angularJS this.$get = function () { return { list: list, add: this.add }; }; }); })();
$ getã¯ãŠãŒãã£ãªãã£é¢æ°ã§ããããã®å Žåã è¿œå ã¡ãã¥ãŒã«ã¢ã€ãã ãè¿œå ããã¡ãœãããšã ã¯ããŒãžã£ãŒã«ä¿åãããŠãããªã¹ãã¡ãã¥ãŒèªäœã®ãªã¹ããè¿ããŸãã
addé¢æ°ã¯ã次ã®ãã£ãŒã«ããæã€å ¥åãªããžã§ã¯ããåãåããŸãã
- priority-ãªã¹ãããœãŒããããåªå 床ã®æ°å€ã
- permission â , :
- except â ,
- only â ,
- location â , :
- place â , ,
- priority â , ,
- name â .
è¿œå æ©èœã®åçã¯ç°¡åã§ããæåã«ãå ¥åã§åä¿¡ãããªããžã§ã¯ããæ€èšŒããã次ã«çŸåšã®ã¢ã€ãã ãæ¿å ¥ããå Žæãæ€çŽ¢ãããŸããäžèŽãããã®ãèŠã€ãããªãå Žåãååž°é¢æ°makeOriginalPartïŒïŒãåŒã³åºãããã¡ãã¥ãŒã®æ°ããäœæãããéšåãè¿ãããŸããäžèŽãèŠã€ãã£ãå ŽåãchangeExistPartïŒïŒãåŒã³åºãããŸããããã¯ãå Žæé åã®ã¢ã€ãã ã®ååã«äžèŽãããéããååž°çã«æ¬¡ã®ã¬ãã«ã®ãã¹ãã«é²ã¿ãŸãã
åé ç®ãè¿œå ããããšãã¡ãã¥ãŒã¯åªå 床ãã£ãŒã«ãã§ãœãŒããããŸãã
ãããã€ããŒã³ãŒããèšè¿°ããå Žåãelse ifæ§é ãç¹ã«äœ¿çšãããŠããŸããã代ããã«ãæ¡ä»¶ã®æåŸã«returnãè¿œå ãããŸãããç§ã¯ãã®ã¹ããããæ£åœåããããšæãããªããªã ã³ãŒãã®å¯èªæ§ãåäžããŸããäžè¬ã«ããããã€ããŒã³ãŒãã¯ç¹°ãè¿ãæé©åãããŠããŸããé¢çœã人ã«ã¯ãæåã®ããŒãžã§ã³ã以äžã«æ·»ä»ããŸãã
ãããã€ããŒã®æåã®ããŒãžã§ã³ãèŠã
泚æïŒ .
'use strict'; (function () { angular.module('navbar') .provider('navbarList', function () { var list = []; this.add = addMenu; function addMenu(obj, nestedMenu, currentList) { if(currentList) { list = currentList; } else if(list.length < 1) { list.push(makeOriginalPart(obj)); return; } if(!obj.location || !obj.location.place) { // . place==priority isDuplicate(obj.name, list); list.push(obj); list.sort(sortByPriority); return; } else if(obj.location.place.length > 0){ var searchName = obj.location.place.shift(), priority = (obj.location.priority) ? obj.location.priority.shift() : null; for(var i = (nestedMenu) ? 1 : 0; i < list.length; i++) { var currentName = (list[i].name.pop) ? list[i].name[0] :list[i].name; if(currentName === searchName) { if(list[i].name.pop) { // if(!nestedMenu) { nestedMenu = [list]; } var sublistName = list[i].name.shift(); list[i].name.sort(sortByPriority); list[i].name.unshift(sublistName); list[i].name.priority = priority; // nestedMenu.push(list[i].name); addMenu(obj, nestedMenu, list[i].name); return; } else { console.log('Warning! Duplicate menu', currentName); } } } if(nestedMenu) { var last = nestedMenu.length - 1; nestedMenu[last].push({ name: [searchName, makeOriginalPart(obj, null, nestedMenu[last]) ], priority: priority }); } } else { last = nestedMenu.length - 1; nestedMenu[last].push(makeOriginalPart(obj, null, nestedMenu[last])); } if(nestedMenu) { // changeExistPart nestedMenu[nestedMenu.length - 1].sort(sortByPriority); list = changeExistPart(nestedMenu); } else { if(priority) { // . place==priority obj.location.priority.unshift(priority); } obj.location.place.unshift(searchName); list.push(makeOriginalPart(obj, null, list)); list.sort(sortByPriority); } } function changeExistPart(nestedMenu) { if(nestedMenu.length > 1) { var subList = nestedMenu.pop(), priority = subList.priority, searchName = subList[0], last = nestedMenu.length - 1; for(var i = 1; i < nestedMenu[last].length; i++) { var currentName = (nestedMenu[last][i].name.pop) ? nestedMenu[last][i].name[0] : ''; if(searchName === currentName){ nestedMenu[last][i].name = subList; nestedMenu[last][i].priority = priority; return changeExistPart(nestedMenu); } } return changeExistPart(nestedMenu); // . } else { return nestedMenu[0]; } } function makeOriginalPart(obj, menu, currentList){ if(!menu) { isDuplicate(obj.name, currentList); menu = { name: obj.name, priority: obj.priority, state: obj.state, permissions: obj.permissions }; } if(obj.location.place.length > 0) { var currentLocation = obj.location.place.pop(), priority = (obj.location.priority) ? obj.location.priority.pop() : null, currentMenu = { priority: priority, name: [currentLocation, menu] }; return makeOriginalPart(obj, currentMenu); } else { return menu; } } function isDuplicate(name, list) { if(!list || list.length < 1) { return; } for(var i = (list[0].name) ? 0 : 1; i < list.length; i++) { var currentName = (list[i].name.pop) ? list[i].name[0] : list[i].name; if(currentName === name) { console.log('Warning! Duplicate menu', currentName); } } } function sortByPriority(a, b) { return a.priority - b.priority; } this.$get = function () { return { list: list, add: this.add }; }; }); })();
ãã¡ã€ã«navbar.permission.js
navbar.permission.jsãåç
§ããŠãã ãã
'use strict'; (function () { angular.module('navbar') .factory('navPermission', function (Permission, $q) { // function getUser(params) { var users = Permission.roleValidations, names = Object.keys(users), promisesArr = []; for(var i = 0; i < names.length; i++) { var current = names[i], validUser = $q.when( users[current](params) ); promisesArr.push(validUser); } return $q.all(promisesArr).then(function (users) { for(var i = 0; i < users.length; i++) { if(users[i]) { return names[i]; } } return null; }); } // , , - function acceptPermission (list, username) { if(!username.then) { return changeList(list, username); } else { return username.then(function (username) { return changeList(list, username); }); } } // , function changeList(list, username) { for(var i = (list[0].name) ? 0 : 1; i < list.length; i++) { if(list[i].permissions) { if(list[i].permissions.except) { var except = list[i].permissions.except; for(var j = 0; j < except.length; j++) { if(except[j] === username) { list.splice(i--, 1); } } } else if(list[i].permissions.only) { var only = list[i].permissions.only, accessDenided = true; for(j = 0; j < only.length; j++) { if(only[j] === username) { accessDenided = false; } } if(accessDenided) { list.splice(i--, 1); } } } else if(list[i].name.pop) { list[i].name = changeList( list[i].name, username); if(list[i].name.length === 1 ) { list.splice(i--, 1); } } } return list; } // return { getUser: getUser, acceptPermission: acceptPermission }; }); })();
è§åºŠèš±å¯ã¢ãžã¥ãŒã«ã«ãã£ãŠå®çŸ©ãããã¢ã¯ã»ã¹ã¬ãã«ã«å¿ããŠã¡ãã¥ãŒããã£ã«ã¿ãªã³ã°ããããã®ã¹ã¯ãªãããã³ãŒãã¯ãèªã¿ããããšã¢ãžã¥ãŒã«æ§ãé«ããããã«å¥ã®ãã¡ã¯ããªãŒã«ç§»åãããŸããïŒèª°ãããã®æ©èœãå¿ èŠãšããããã§ã¯ãããŸããïŒ
ãã¡ã¯ããªã¯2ã€ã®ã¡ãœããã§æ§æãããŠããŸãã
- acceptPermission-ã¡ãã¥ãŒé ç®ã®é åãååž°çã«èª¿ã¹ãçŠæ¢ãããŠãããã®ãåé€ããŸãã
- getUserã¯ãçŸåšã®ãŠãŒã¶ãŒããŒã«ã決å®ããããã®ã¡ãœããã§ããæããã«ãå®éã®ãããžã§ã¯ãã§ã¯ããŠãŒã¶ãŒããŒã«ã¯ããŒã«ã«ã ãã§ãªããµãŒããŒäžã§ã決å®ã§ããŸãããããã£ãŠããŠãŒã¶ãŒã®ããŒã«ã¯promiseã䜿çšããŠéåæçã«æ±ºå®ãããŸãã
navbar.decorator.jsãã¡ã€ã«
å®éãç§ãèãããã¹ãŠãå®è£ ãããŠããŸããã©ã®ããã«æ©èœããããèŠãŠã¿ãŸãããã以äžã¯ããã®ãµãã¡ãã¥ãŒé ç®ããµãã¬ãã«ã®ãã§ãŒã³ãçãç©ã=>ãåºä¹³é¡ã=>ãç«ãã«ç»é²ããŠãããã«ã·ã£ç«ãã¹ããŒã¿ã¹ã宣èšããã³ãŒãã®äŸã§ãããå¿åããšãçŠæ¢ããé€ããã¹ãŠã®ãŠãŒã¶ãŒãã¢ã€ãã ãå©çšã§ããŸãã
.config(function ($stateProvider, navbarListProvider) { // $stateProvider .state('persianCat', { url: '/ ', templateUrl: 'app/cats/persianCat.html', controller: 'persianCatCtrl', permissions: { except: ['anonymous', 'banned'], redirectTo: 'login' } }); // navbarListProvider.add({ state: 'persianCat', name: ' ', permissions: { except: ['anonymous', 'banned'] }, priority: 20, location: { place: [' ', '', ''], priority: [10, 10, 10] } }); });
ãã¹ãŠãåäœããŠããããã«èŠããŸãããããªãã¯ããã§ããïŒã¹ããŒã¿ã¹ã宣èšããããšãã¡ãã¥ãŒé ç®ã®å®£èšã«å¿ èŠãªã»ãŒãã¹ãŠã®æ å ±ãè€è£œãããŸãããã¹ãŠãçµåããããã«ãUIã«ãŒã¿ãŒã¢ãžã¥ãŒã«ã®éçºè ã芪åã«æäŸããŠããããã³ã¬ãŒã¿é¢æ°ã䜿çšããŸããå®éããã³ã¬ãŒã¿ãŒã¯æ¢åã®é¢æ°ã®ã©ãããŒãäœæãããã®æ©èœãå€æŽã§ããããã«ããŸãã以äžã¯.stateã¡ãœããã®è£ 食ã³ãŒãã§ãstateã«æž¡ããããªããžã§ã¯ãããã¡ãã¥ãŒãã£ãŒã«ããåŠçã§ããŸãã
navbar.decorator.jsãåç
§ããŠãã ãã
'use strict'; (function() { angular.module('navbar') .config(function ($stateProvider, navbarListProvider) { // state $stateProvider.decorator('state', function (obj) { var menu = obj.menu, permissions = (obj.data) ? obj.data.permissions : null; // - if(!menu) { return; } menu.state = obj.name; // if(permissions) { menu.permissions = {}; if(permissions.except) { menu.permissions.except = permissions.except; } else if(permissions.only) { menu.permissions.only = permissions.only; } else { delete menu.permissions; } } // menu navbarListProvider.add(menu); }); }); })();
ããã§ãã¡ãã¥ãŒã«ç»é²ãããç¶æ ã®å®£èšã¯æ¬¡ã®ããã«ãªããŸãã
.config(function ($stateProvider) { $stateProvider .state('persianCat', { url: '/ ', templateUrl: 'app/cats/persianCat.html', controller: 'persianCatCtrl', permissions: { except: ['anonymous', 'banned'], redirectTo: 'login' }, menu: { name: ' ', priority: 20, location: { place: [' ', '', ''], priority: [10, 10, 10] } } }); });
åæãã-ãããšã¬ã¬ã³ãã«ã
æåŸã«ãå°ããªã©ã€ãããã¯ïŒåç¶æ ã®ãããžã§ã¯ãã§ãåå¥ã®ãã©ã«ããŒã ãã§ãªããåå¥ã®Angularã¢ãžã¥ãŒã«ãäœæããäŸåé¢ä¿ã®ãªã¹ãã«æ¥ç¶ããŸããããã«ããããããžã§ã¯ãããç¶æ ãåé€/転éããæéãå€§å¹ ã«ççž®ã§ããŸããã¢ãžã¥ãŒã«ãäŸåé¢ä¿ã®ãªã¹ããšç¶æ ãã©ã«ããŒããåé€ããã ãã§ååã§ãã
ãæž èŽããããšãããããŸãããçããã«å¹žéãã