æšå¹ŽçºçããããŒã¿ã«ã¬ã€ãã©ã€ã³ã®ã¡ãžã£ãŒã¢ããããŒãã®çµæãããŒã¿ã«ã¡ãã¥ãŒã®æ°ããããŒãžã§ã³ãå¿ èŠã«ãªããŸããã å€æŽç¹ãšãã®çç±ã®è©³çŽ°ã¯ã Behanceã§ç¢ºèªã§ããŸãã æŽæ°ã®äžç°ãšããŠãMail.RuããŒã¿ã«ã®ããŸããŸãªãããžã§ã¯ãã®ã¹ã¿ã€ã«äžã®çµ±äžæ§ãšãèŠèŠçããã³æ©èœçã«çµ±äžãããããã²ãŒã·ã§ã³ã¹ã¿ã€ã«ã確ä¿ããå¿ èŠããããŸããã ãŠãŒã¶ãŒãã©ã®ãããžã§ã¯ãã«åå ããŠããå Žåã§ãããŠãŒã¶ãŒã¯ãããããã²ãŒãããæ¹æ³ãç解ããå¿ èŠããããŸãã ãããã£ãŠãã¡ãã¥ãŒãšæè¡çã«ã¯ãåäžã®ã¯ãã¹ãã¶ã€ã³ã§ããå¿ èŠããããŸãã
ç§ãã¡ã®ä»äºã®çµæã¯ãå®éã«ã¯åçãªèŠçŽ ãå«ãèŠçŽ ã®å€§ããªã»ãããæã€ã³ã³ã¹ãã©ã¯ã¿ãŒã§ãããœãªã¥ãŒã·ã§ã³ã§ããã ãã®ã¢ãããŒãã«ãããç¹å®ã®ãããžã§ã¯ãã®èŠä»¶ãæºããããŒã¿ã«ã¡ãã¥ãŒããããã®èŠçŽ ãããåéããããŠãŒã¶ãŒãæãå¿ èŠãšããæ©èœãæ£ç¢ºã«åé¢ã«è¡šç€ºããããšãå¯èœã«ãªããŸããã èŠçŽ ã®åœ¢åŒãããŠãŒã¶ãŒãããŒãžãéããç»é¢ã®è§£å床ã«å¿ããŠèª¿æŽãããŸãã
ãããŠä»ãç§ãã¡ããããã©ããã£ãŠãã£ããã«ã€ããŠã®è©³çŽ°ã
çœé³¥ãã¬ã³ããã€ã¯
åãããžã§ã¯ãã«ã¯ç¬èªã®ããŒãºããããŸãã 1ã€ã«ã¯5ã€ã®ãã¿ã³ãå¿ èŠã§ãä»ã®2ã€ã«ã¯ããããããŠã³ãããã3ã€ç®ã®ãã¿ã³ã«ã¯å·ŠåŽã«2ã€ãå³åŽã«1ã€ã®ãã¿ã³ãå¿ èŠã§ãã ããŒã¿ã«ã¡ãã¥ãŒã®èŠçŽ ã®ããã€ããè€æ°ã®ãããžã§ã¯ãã§èŠã€ãã£ãå Žåã§ããã©ãã§ãç°ãªã圹å²ãæãããŸãã ããšãã°ãæ€çŽ¢æååãèããŸãã åœç¶ãMail.Ru Searchã®äžå¿çãªå Žæãå ããŸãã Mailã§ã¯ãããã¯ã°ã©ãŠã³ãã«åŸéããŸããå€ãã®å Žåãã¡ãŒã«ããã¯ã¹ã§ãã¡ã€ã«ãæçŽãèŠã€ããå¿ èŠããããŸãããããã§ãäž»èŠãªæ©èœã§ã¯ãããŸããã ãŸããããšãã°ãMail.Ru Newsã§æ€çŽ¢ã䜿çšããããšã¯ã»ãšãã©ãªãããããã®èŠçŽ ãã³ã³ãã¯ãã«ããããšã¯çã«ããªã£ãŠããŸãã ãããŠæè¡çã«ã¯ããµãŒããŒïŒç°ãªããã©ãããã©ãŒã ãèšèªããã³ãã¬ãŒããšã³ãžã³ïŒãšã¯ã©ã€ã¢ã³ãïŒç°ãªãã©ã€ãã©ãªãDoctypeãã¹ã¿ã€ã«ããã¯ãããžãŒïŒã®äž¡æ¹ã§ãããžã§ã¯ãã¯åçã«ç°ãªããŸãã ãŸããSPAã®ã¯ã©ã€ã¢ã³ãã§ã®åçåæ§ç¯ãå¿ããŠã¯ãªããŸããã
ã¯ãã¹ãšã¯ã¹ããŒãèŠçŽ ãæäœãããšãã«ééããå¯èœæ§ãããæ倧ã®èœãšãç©Žã®1ã€ã¯ãæŽæ°ã®è€éãã§ãã ã¡ãã¥ãŒã®æŽæ°ãç°¡åã ã£ãããšãäºåã«ç¢ºèªããŠããªãå Žåããã®åŸã®ãµããŒãã¯ãããžã§ã¯ãããŒã ã«ãšã£ãŠèŠçã«ãªããŸãã ããŒã¿ã«ã¡ãã¥ãŒãéçã«ããããšãã§ããŸãããããžã§ã¯ãã¯ãããŒã¿ã«ãœãªã¥ãŒã·ã§ã³ã®éçºè ãããã¹ãŠã®ã³ã³ãããŒã«ãåããæ¢è£œã®ã³ãŒããåãåããæŽæ°ãå®å šãªåœ¢åŒã®ã³ãŒãã®åœ¢ã§æäŸãããŸãã ãã®å Žåããããžã§ã¯ãããŒã ãã¡ãã¥ãŒãå€æŽãããšã次ã®ããŒãžã§ã³ãšã®äºææ§ã倱ãããŸãã ããã«ãããããŒã¿ã«ã«äžè¬çãªå€æŽãå ããããšãããã«é£ãããªããŸãã ããã«ãããŒã¿ã«ã¡ãã¥ãŒã®æ°ããããŒãžã§ã³ã§ã¯ãããŸããŸãªç¶æ ã®åçãªèŠçŽ ãå«ãããããŸã§ãããå€ãã®èŠçŽ ãèšç»ãããŸããã ãµãŒããŒåŽã®ãããžã§ã¯ãã®å€çš®å€æ§ãªæšæºåæè¡ãšææ¡ãããæ°ãããœãªã¥ãŒã·ã§ã³ã®æãããªæè¡çè€éãã®ããã«ãã¯ã©ã€ã¢ã³ãäžã«ããŒã¿ã«ã¡ãã¥ãŒãæ§ç¯ããããšãéžæããŸããã
äžèšã®åé¡ãåé¿ããæŽæ°ã容æã«ããã«ã¯ã2ã€ã®æ¡ä»¶ãæºãããŠããå¿ èŠããããŸãã ãŸããç°å¢ããå¯èœãªéãåé¢ããã³ã³ããŒãã³ããéçºããå¿ èŠããããŸããããã¯ããããžã§ã¯ãã«ç°¡åã«çµ±åã§ããå¿ èŠã«å¿ããŠæŽæ°ããã®ãç°¡åã§ããããšãã°ããããžã§ã¯ãã®æå°éã®åŽåã§ããŒã¿ã«å šäœã®ã¡ãã¥ãŒã®è²ãå€æŽã§ããŸãã 第äºã«ãå éšãããã³ãé ãããšã«ãããèšèšã³ãŒããå¯èœãªéãç°¡çŽ åããå¿ èŠããããŸãã ãããžã§ã¯ãã¯ããã¿ã³ã欲ããã-ããªãã«ã¯ãã¿ã³ããå³ã«æ¬²ããããšèšã£ãŠããŸãã-ããã§ããªãã¯å³ã«è¡ããŸãã 宣èšçãªãã®ãçæ³çã§ãã
æ¥ç¶
<script src="hat.js"></script> <script> hat.draw({}); </script>
çµ±åãœãªã¥ãŒã·ã§ã³ã䜿çšããçæ³çãªã±ãŒã¹ã¯æ¬¡ã®ãšããã§ããã©ã€ãã©ãªãæ¥ç¶ããå¿ èŠãªã³ã³ããŒãã³ããåæåããŸããã ããã«ãããããŒãžã§ã³ãç°¡åã«æŽæ°ããŠããããžã§ã¯ãã³ãŒãã«æå°éã®å€æŽãå ãããããŸã£ãã觊ããªãããã«ããããšãã§ããŸãã ãã ããããŒã¿ã«ã¡ãã¥ãŒã¯ããŒãžã®æäžéšã«ããéèŠãªèŠçŽ ã§ããããããšã«ããæ¥ç¶ããŠæç»ããããšã¯ã§ããŸããã ããŒãžè¡šç€ºã®éå§æã«ããããã¯ããã®å Žæãåããä»ã®ãããã¯ã®äœçœ®ã«åœ±é¿ãäžããªãããšãå¿ èŠã§ãã ã€ãŸããããŒã¿ã«ã¡ãã¥ãŒã¯ãã¹ã¿ã€ã«ãã¹ã¯ãªãããããã³åºæ¬çãªHTMLã®å°ãªããšã3ã€ã®éšåã«åå²ããå¿ èŠããããŸãã HTMLã¯ãããŒãæã«æç»ãããããŒãžäžã®é©åãªå Žæã«æ¿å ¥ããå¿ èŠããããŸãã ããã«ãã¹ã¯ãªããã¯ããŸããŸãªèŠçŽ ãããã«çµ±åããŸãã
<link href="hat.css"/> <div class="hat">...</div> <script src="hat.js"></script> <script> hat.draw({}); </script>
æ°ããã¡ãã¥ãŒã«ã¯å€ãã®æ©èœãèšç»ãããŠãããããããªãã®ééããããŸãã ãã¹ãŠã®ã³ãŒããåæçã«ããŒãããããšã¯ã§ããŸãã-ãããžã§ã¯ãã®ããŒãæéã«å€§ããªåœ±é¿ãäžããŸãã çæ³çã«ã¯ãã³ãŒãã2ã€ã®éšåã«åå²ããŸãããã¬ãŒã¹ãã«ããŒïŒã«ãŒãã¡ãã¥ãŒé ç®ïŒã®ã¬ã³ããªã³ã°ã«å¿ èŠãªã³ãŒããšãéåæã«ããŒããããæ®ãã®ã³ãŒãã§ãã
<style>/* base styles */</style> <div class="hat">...</div> <script> loadExternalScript(); </script> <script> hat.init(); </script>
ãã®å Žåããã¹ãŠã®å€éšããŒã¿ãããŒããããŠããå Žåã«ã®ã¿ããŒã¿ã«ã¡ãã¥ãŒã䜿çšã§ããããšãããããŸãã ãã ããå¿ èŠãªãã®ããã¹ãŠããŒããããã¿ã€ãã³ã°ã決å®ããããã«ãããžã§ã¯ãã«æããããšã¯çµ¶å¯Ÿã«ããããããŸããã å¥ã®ãã¹ãæ¢ãå¿ èŠããããŸãã ãã®ç¥èãããããžã§ã¯ããåé¢ããããã«ããããã·APIãäœæãããã€ã³ã©ã€ã³éšåã«é 眮ãããŸããã
hat.draw = new DeferredQuery.getQuery(); hat.draw({}); // put in queue hat.draw({}); // put in queue hat.draw.replace(realDrawFn); // run two times hat.draw({}); // run immediately
ãã®å Žåããããã·ã¯åŒæ°ä»ãã®ãã¹ãŠã®åŒã³åºããèšæ¶ããé¢æ°ã§ãããåŒã³åºãã®æºåãã§ããæç¹ã§ãæ¢åã®åŒæ°ã§å¿ èŠãªåæ°ã ãå®è¡ãããå®éã®é¢æ°ã«çœ®ãæããããŸãã ã¹ã¿ãã«ã¯ãããŒã¿ã«ã¡ãã¥ãŒã®æäœã«å¿ èŠãªãã¹ãŠã®æ©èœïŒæç»/åæç»ãªã©ïŒãå«ãŸããŠããŸãã
1ã€ã®èŠæ±ã§å€éšãªãœãŒã¹ãããŒãããããã«ãã¹ã¿ã€ã«ãã¹ã¯ãªããã«å«ãŸããåçã«æ¥ç¶ãããŸãã ããŒã¿ã«ã¡ãã¥ãŒã³ãŒããæ§ç¯ãããšããåéãããã¹ã¿ã€ã«ã³ãŒãã¯ã¹ã¯ãªããã®è¡ãšããŠé 眮ãããAPIãã¹ããŒãã£ã³ã°ãããåã«å®¶ã«æ¿å ¥ãããŸãã
var styles = ".body{background:url(\"http://...\")}", style = document.createElement('style'); style.appendChild(document.createTextNode(styles)); body.appendChild(style); init();
æªç¥ã®ç¶æ³ã§æã人æ°ã®ãããã©ãŠã¶ã®ããã€ãã¯ãããã«ã¹ã¿ã€ã«ãé©çšããªãããšã«æ³šæããŠãã ããã ã€ãŸããã¹ã¿ã€ã«ã·ãŒãæ¥ç¶ã«åŸãã¹ã¯ãªããã¯ãå€ãããŒã¿ã§æ©èœããŸãã èãçŽãããšãªããå€éšã¹ã¿ã€ã«ã§äžé£ã®ã«ãŒã«ãé©çšããã空ã®èŠçŽ ãã€ã³ã©ã€ã³HTMLã«è¿œå ããŸããã ãã®å€èŠ³ã«ãã£ãŠãã¹ã¿ã€ã«ãé©çšããç¬éã決å®ãããåæåãéå§ãããŸãã ã¹ã¿ã€ã«é¡ã®é©çšããã§ãã¯ããŸã-ã¿ã€ã ã¢ãŠãããŸãã
appendStyles(); whenStylesLoaded(init);
ããŒã¿ã«ã¡ãã¥ãŒãäœæãã
ã¢ã»ã³ããªã«ã¯3ã€ã®ãªãã·ã§ã³ããããŸãïŒãã¹ãŠã®å ŽåïŒã
- éåæ-ããŒã¿ã«ã¡ãã¥ãŒããã€ã©ã®ããã«èªã¿èŸŒãŸããããéèŠã§ãªããããžã§ã¯ãã®ã¢ã»ã³ããªãäž»ãªããšã¯ããããæ©èœããããšã§ãã
- åéåæ-ã¹ã¿ã€ã«ãæ¥ç¶ããç¬éãéèŠãªãããžã§ã¯ãåãã
- åæ-Webã®é人åãã
éåæã¢ã»ã³ããª
<style>/* base styles */</style> <div class="hat">...</div> <script> createAPI(); loadExternalScript(); </script> <script>hat.draw({});</script>
ãããã£ãŠã次ã®ã¢ã»ã³ããªãå€æããŸãããã€ã³ã©ã€ã³ããŒããé©åãªå Žæã«è²Œãä»ããããã«ããŒã¿ã«ã¡ãã¥ãŒã®åæåãéå§ãããšããã€ãã©ã®ããã«æç»ããããããããŸãã ãã®ã¢ã»ã³ããªã䜿çšããå Žåãæ°ããããŒãžã§ã³ã«æ¥ç¶ããŠæŽæ°ãããšãå°ããªã€ã³ã©ã€ã³ããŒããã³ãŒãã®é©åãªå Žæã«ã³ããŒãããŸãã
æºéåæã¢ã»ã³ããª
ã¹ã¿ã€ã«ãæ¥ç¶ãããšãã«éèŠãªãããžã§ã¯ãã®å Žåãåå¥ã®ãã¡ã€ã«ã®ã¹ã¿ã€ã«ãšåæ§ã®å€éšã¹ã¯ãªããã䜿çšããŠãããããã¹ã¿ã€ã«ãæããªãã¢ã»ã³ããªãäœæããå¿ èŠããããŸããã ãã®ãããªãããžã§ã¯ãã®äŸã¯ã¡ãŒã«ã§ãã åéåæã¢ã»ã³ããªã®å¿ èŠæ§ã¯ããããžã§ã¯ãã«ããŸããŸãªèšèšããŒããååšããããã§ãã 2ã€ã®CSSãã¡ã€ã«ãMailã§æ¥ç¶ãããŠããŸã-1ã€ã¯ããã©ã«ãããŒãã®ãžãªã¡ããªãšè²ã§ããã1ã€ã¯éžæããããŒãã®è²ã§ãã ããã«ã€ããŠã¯ãå¥ã®èšäºã§ãã§ã«è©³ãã説æããŸããã ããŒã¿ã«ã¡ãã¥ãŒã®éåžžã®ã¢ã»ã³ããªã§ã¯ãã¹ã¿ã€ã«ã¯å¶åŸ¡ãããŠããªãå Žæã§æªå®çŸ©ã®ç¬éã«æ¥ç¶ãããŸããã¡ãã¥ãŒãŸãã¯ãããžã§ã¯ãåŽã§ã®ç¹å®ã®å€æŽã«ãããã¡ãã¥ãŒã¹ã¿ã€ã«ãããŒãã¹ã¿ã€ã«ã®åŸã«æ¥ç¶ãããããšãç°¡åã«ããããŸãïŒã³ãŒãã«ã€ããŠã¯ä»¥äžãåç §ïŒã æºéåæã¢ã»ã³ããªã䜿çšãããšãã¹ã¿ã€ã«ãå¶åŸ¡ã§ããæ®ãã¯ãåç¬ã§ãå®è¡ãããŸãã
<link href="full.css"> <div class="hat">...</div> <script> createAPI(); loadExternalScriptWithoutCSS(); </script> <script>hat.draw({});</script>
åæã¢ã»ã³ããª
èªã¿èŸŒã¿ããã»ã¹ã®å¶åŸ¡ãéèŠãªãããžã§ã¯ãã§ã¯ãããŒããŒã䜿çšããã«ã¹ã¿ã€ã«ãšã¹ã¯ãªãããåããã€ã³ã©ã€ã³HTMLãã¡ã€ã«ãšå€éšãã¡ã€ã«ãå«ãåå¥ã®ã¢ã»ã³ããªãäœæãããŠããŸãã ãããžã§ã¯ãã¯ãã¢ã»ã³ããªã«ãã¡ã€ã«ãå«ããŠãå¿ èŠã«å¿ããŠããŒãã§ããŸãã
<link href="full.css"> <script src="full.js"></script> <div class="hat">...</div> <script>hat.draw({});</script>
åæå
ããŒã¿ã«ã¡ãã¥ãŒãæ¥ç¶ããããã¬ã³ããªã³ã°é¢æ°ãåŒã³åºããŠãå¿ èŠãªèŠçŽ ã®æ§æãšãäœæãããèŠçŽ ã®APIã»ãããæž¡ãããã³ãŒã«ããã¯é¢æ°ãæž¡ãå¿ èŠããããŸãã
hat.draw({ logo: {}, toolbar: {}, submenu: {} }, function(menuItems){ menuItems.toolbar // menuItems.submenu // });
ããŒã¿ã«ã¡ãã¥ãŒã«ã¯ãã¡ãã¥ãŒã®2ã€ã®ã¬ãã«ããããŸããã¡ã€ã³ã¬ãã«ïŒããŒã«ããŒã®èšå®ïŒãšã°ã¬ãŒã®ãµãã¡ãã¥ãŒïŒãµãã¡ãã¥ãŒã®èšå®ïŒã§ãã
ã¡ã€ã³ã³ãŒãã¯ããã¬ãŒã¹ãã«ããŒãã¬ã³ããªã³ã°ããåŸã«ããŒã«ããŒãæç»ããè¿œå ã®è¡ãè¿œå ããŠé«ããå¢ããå¿ èŠãããããšãç¥ã£ãŠããŸãã ããŒã¿ã«ã¡ãã¥ãŒã«å¿ èŠãªã¹ããŒã¹ã確ä¿ããã«ã¯ããã¬ãŒã¹ãã«ããŒãå¿ èŠã§ããããšãæãåºãããŠãã ããã ãã®ãããæåã®ã¬ã³ããªã³ã°ã§ãµãã¡ãã¥ãŒã®èšç»ãææ¡ããããã«é«ãã¡ãã¥ãŒãæç»ããå¿ èŠããããŸãã
hatConfig = { submenu: true }
ãããè¡ãããã«ãã€ã³ã©ã€ã³ã¡ãã¥ãŒã³ãŒãã¯ãäžèšã®æ§æã§çºè¡šããããªãã·ã§ã³ããã第2ã¬ãã«ã®ãã¬ãŒã¹ãã«ããŒãããã«è¡šç€ºããå¿ èŠããããã©ãããç解ããããšãåŠã³ãŸããã
次ã«ãã¡ãã¥ãŒã®å 容ã«ã€ããŠè©³ãã説æããŸãã
ã¢ã€ãã
ããŒã¿ã«ã¡ãã¥ãŒã§äœ¿çšã§ããèŠçŽ ã¯å€æ°ãããŸãã ããã¯ãæ€çŽ¢ããŒããã¿ã³ãåºåãæåãæ«å°Ÿã®åºåãæåãªã©ã§ãã ã»ãšãã©ã®èŠçŽ ã«ã¯ãå€èŠ³ãã«ã¹ã¿ãã€ãºããããã®å€ãã®ãªãã·ã§ã³ããããŸãã ããšãã°ãçŽNçš®é¡ã®æ€çŽ¢æååããããŸãã ã¬ã€ãã©ã€ã³å ã®å€æ§æ§ã«ããããããžã§ã¯ãã¯ã¡ãã¥ãŒé ç®ã®åäœãšå€èŠ³ãæè»ã«ã«ã¹ã¿ãã€ãºã§ããŸãã ããã¯ãã¹ãŠãå€ãã®ãªãã·ã§ã³ã§æ§æå¯èœã§ãã ãããã«ã€ããŠè©³ããã¯è¿°ã¹ãŸããã ç¹ã«èå³ããã人ã¯ãMail.Ruãããžã§ã¯ããèŠãŠåããã¡ãã¥ãŒã®éããç解ããŠãã ããã
ã¢ã€ã³ã³ããã¯
æ°ããããŒã¿ã«ã¡ãã¥ãŒãšãšãã«ãçµ±åãããããŒã¿ã«ã¢ã€ã³ã³ãéçºããã³å®è£ ããŸããã ã¢ã€ã³ã³ã®åäžæ§ã¯ããã¹ãŠã®ããŒã¿ã«ãããžã§ã¯ãã§åäžãªãŠãŒã¶ãŒãšã¯ã¹ããªãšã³ã¹ã確ä¿ããã®ã«åœ¹ç«ã¡ãŸãã ããšãã°ãæ°ããéç¥ã®ã¢ã€ã³ã³ã¯ãã²ãŒã ã§ããã€ã¯ãŒã«ãã§ãåãããã«èŠããŸãã
ããŒã¿ã«ã¡ãã¥ãŒã§ããã¿ã³ã®ã¢ã€ã³ã³ã¯ã©ã¹ãèšå®ãããŸãã èšå®ãããŠããå Žåããã®ã¯ã©ã¹ãæã€ã¢ã€ã³ã³èŠçŽ ãäœæãããŸãã é©åãªã¹ã¿ã€ã«ã§ç¬èªã®ã¢ã€ã³ã³ã¯ã©ã¹ãèšå®ããããäºåå®çŸ©ãããã»ããã䜿çšã§ããŸãã å®çŸ©æžã¿ã®ã»ããã¯ãç¹å®ã®ãã©ã«ããŒå ã®ã¢ã€ã³ã³ã®ã»ããããã¹ãã©ã€ãã«èªåçã«åéãããŸãã åçã¯ååãšçš®é¡ã§ãœãŒããããŸãã çŸæç¹ã§ã¯ãname.pngããã³name@2x.pngãšããååã®ãretinãããã³ãneretinãpngãšãããããããŠã³ãéãããšãã«è¡šç€ºããã2ã€ã®å転ã¢ã€ã³ã³ããããŸãã ãµã€ãºã2åã«ãªã£ãretinovã¢ã€ã³ã³ãåŒã³åºããŸãããããã¯2以äžã®å¯åºŠã§ç»é¢ã«è¡šç€ºãããŸããäž¡æ¹ã®ãã¡ã€ã«ãããå Žåãã¢ã€ã³ã³ã¯ã»ããã«è¿œå ãããŸãã https://github.com/aheckmann/gmã䜿çšããŠ2ã€ã®ã¹ãã©ã€ããã»ããããåéããããã®åŸã®ã¢ã»ã³ããªã«å«ããããã«ã¹ã¿ã€ã«ãçæãããŸãã
.icon { background: url(icons.png) no-repeat -3427px 0; background-size: 3458px 21px; } @media only screen and (min-device-pixel-ratio: 1.5){ .icon { background-image: url(icons@2x.png); }}
ããŒã¿ã«ã¡ãã¥ãŒé ç®ã¯ãAPIãä»ããŠç®¡çãããŸãã
APIèŠçŽ
drawé¢æ°ãåŒã³åºããããšãäœæãããèŠçŽ ã®APIã»ãããã³ãŒã«ããã¯é¢æ°ã«æž¡ãããŸãã ãã®ã»ããã¯ãhat.getItemsïŒfunctionïŒitemsïŒ{}ïŒé¢æ°ãåŒã³åºãããšã§ãã€ã§ãååŸã§ããŸãã
hat.draw({}, function(menuItems){ menuItems.toolbar // menuItems.submenu // }); hat.getItems(function(menuItems){});
APIã䜿çšãããšãDOMèŠçŽ ã«ã¢ã¯ã»ã¹ããããããŸããŸãªã€ãã³ãã®ãã³ãã©ãŒããã³ã°ããããããã®èŠçŽ ããã®èŠçŽ ãé衚瀺/衚瀺ããããšãã§ããŸãã
ç¹å®ã®ã¿ã€ãã®èŠçŽ ã«ã¯ãè¿œå ã®æ©èœããããŸãã ãã®ããããã¿ã³ã§ãçŸåšã®ã»ã¯ã·ã§ã³ãã®ã¹ããŒã¿ã¹ãå€æŽãïŒ2ã€ã®ãçŸåšã®ããã¿ã³ãäœæããããšã¯ã§ããŸããïŒãããã¹ããšã¢ã€ã³ã³ãå€æŽãããã¿ã³ã®éç¥ã®çªå·ãæŽæ°ã§ããŸãã ããããããŠã³ã«ã¯åã«ãŠã³ãããã³åæç»æ©èœããããHTMLããããããŠã³ã®ã³ã³ãã³ããæŽæ°ãããšãã«å¿ èŠã§ãã æ€çŽ¢ã«ã¯ãsagestasãšã³ã³ããã¹ãã»ã¬ã¯ã¿ãŒãæäœããããã®é¢æ°ããããŸãã
åçèŠçŽ
厩å£ã°ã«ãŒã
ãã®ãããªã°ã«ãŒãã®åæãããã¿èŠçŽ ã¯ãååãªã¹ããŒã¹ããªãå Žåãããã®ä»ãããããããŠã³ã¡ãã¥ãŒã«è»¢éã§ããŸãã
ã¢ãããã£ããšã¬ã¡ã³ã
ããšãã°ãããã¯ååãªã¹ããŒã¹ããããšãã«ã¢ã€ã³ã³ããããã¹ãä»ãã®ãã¿ã³ã«é£ã³åºãããšãã§ããã¢ã€ã³ã³ä»ãã®ãã¿ã³ã§ãã
æ«å°Ÿã®èŠçŽ
çŸæç¹ã§ã¯ãæ«å°Ÿã®èŠçŽ ã¯ãwidthãæå®ããªãã¹ããŒãµãŒã§ãããflexibleïŒtrueãã©ã¡ãŒã¿ãŒãšæ€çŽ¢ã«ããæ€çŽ¢ã§ãã
ããã©ã«ãã§ã¯ãåãŸããªããã¿ã³ãšã¢ãããã£ãèŠçŽ ã®èšç®ãé衚瀺ã«ããåŸã®æ®ãã®ç©ºãé åã¯ããã¹ãŠã®äŒžçž®èŠçŽ éã§åçã«åå²ãããŸããã€ãŸããflex =1ãä»»æã®äŒžçž®èŠçŽ ã«å¯ŸããŠãflexãã©ã¡ãŒã¿ã1以å€ã«èšå®ãããšã空ãé åãåå²ãããŸããã®å€ã§ã ããšãã°ãflex = 1ã®2ã€ã®äŒžçž®èŠçŽ ãšflex = 2ã®1ã€ã®èŠçŽ ãããå Žåã空ãé åã100ãã¯ã»ã«ã®å ŽåãæåŸã®èŠçŽ ã«ã¯50ãã¯ã»ã«ãå²ãåœãŠãããæ®ãã®èŠçŽ ã«ã¯25ãã¯ã»ã«ãå²ãåœãŠãããŸãã
<èŠçŽ ã®è¿œå ã¹ããŒã¹> = <空ãã¹ããŒã¹> / <ãã¹ãŠã®ãã¬ãã¯ã¹ã®â> * <èŠçŽ ã®ãã¬ãã¯ã¹>
èŠçŽ ãåŒã䌞ã°ãããã«å¿ èŠãªå¥ã®æŠå¿µã¯ãããŒã¹å¹ ã§ãã ããã¯ã空ãé åãèšç®ãããçžå¯Ÿçãªå¹ ã§ãã æ§æã®å¹ ããååŸãããŸãïŒæ«å°Ÿã®ã¹ããŒãµãŒ= 0ã®å ŽåïŒã
空ãé åã決å®ããããã«ããã¹ãŠã®èŠçŽ ãããŒã¹ãšçããå¹ ã§ã¬ã³ããªã³ã°ãããŸãã æ®ãã®ã¹ããŒã¹ã¯ããã¬ãã¯ã¹ãã©ã¡ãŒã¿ã«åŸã£ãŠã¹ãã¬ããèŠçŽ éã§åå²ãããããŒã¹å¹ ã«è¿œå ãããŸãã
<æåŸã®èŠçŽ ã®å¹ > =
<èŠçŽ ã®äœåãªã¹ããŒã¹> + <ããŒã¹å¹ >
ã¬ã³ããªã³ã°
hat.drawïŒ{}ïŒ;
äžè¬ã«ãããŒã¿ã«ã¡ãã¥ãŒã®ã¬ã³ããªã³ã°ã¯ããã次ã®ããã«è¡ãããŸãã ã€ã³ã©ã€ã³éšåã®åŸïŒã€ãŸããAPIããŒãžã«è¡šç€ºãããïŒããããžã§ã¯ãã¯å¿ èŠãªèŠçŽ ã®ã¬ã³ããªã³ã°ãèŠæ±ããŸãã ã¹ã¿ã€ã«ãæ¥ç¶ããã䜿çšå¯èœãªãã¹ãŠã®èŠçŽ ã®ãã¯ã©ã¹ããäœæãããèŠæ±ãããã¬ã³ããªã³ã°ãèµ·åãããå€éšã¹ã¯ãªãããããŒããããŸãã
configãæåã«åŠçãããtoolbar.itemsãã°ã«ãŒãã®ã»ããã«çž®å°ãããŸãã ãã£ãã
[ {type: 'button'}, {type: 'button'}, {type: 'group', items: [{type: 'button'},{type: 'button'}]}, {type: 'button'} ]
åºåã¯3ã€ã®ã°ã«ãŒãã«ãªããŸãïŒæåã®2ã€ã®ãã¿ã³ãå ã®ã°ã«ãŒãã1ã€ã®ãã¿ã³ãæã€ã°ã«ãŒãã
[ {type: 'group', items: ... } {type: 'group', items: ... } {type: 'group', items: ... } ]
次ã«ãåèŠçŽ ã®æ§æãæ£èŠåãããŸãã åèŠçŽ ãåå¥ã«æ€èšããŸããã ããã§ã¯ãããã©ã«ãã®æ§æå€ãèšå®ãããä»ã®ãªãã·ã§ã³ãšçµã¿åãããŠæå³ããªããªãèšå®ãå€æŽãããŸãã ããšãã°ããã¿ã³ãããã¹ãã®å Žåããã¿ã³ã®ã¢ã€ã³ã³ãžã®æãããã¿ãç¡å¹ã«ããŸãã
item = classes[item.type].getConfig(item);
æ§æã¯ãã³ãã¬ãŒããšã³ãžã³ïŒFestïŒã«æž¡ãããå¿ èŠãªããŒã¯ã¢ãããçæãããŸãã èŠçŽ ãé©åãªå Žæã«æ¿å ¥ãããJSã³ã³ããŒãã³ããåæåãããŸãã ããèªäœã®åèŠçŽ ã¯ãå¿ èŠãªæ¥ç¶ãåæåããã€ãã³ããã³ãã©ãŒããã³ã°ã¢ããããŸãã
html = fest(config); block.innerHTML = html; $(block).find('.elements').bem()
ã°ã«ãŒãã®æãããã¿ãã¢ãããã£ããã¿ã³ãèŠçŽ ã®ã¹ãã¬ãããªã©ãåçãªèŠçŽ ã®æ¹ãé¢çœãã£ãã§ãã
ã¢ã€ãã ãã°ã«ãŒãã«è§£æãã
getEls(); getCollapsibleGroups(); getMoreButtons(); getAdaptive(); getFlexible();
ããã«èšç®ããã«ã¯ããã¹ãŠã®èŠçŽ ã解æããŠã³ã¬ã¯ã·ã§ã³ã«ãŸãšããå¿ èŠããããŸããæãããã¿ã°ã«ãŒãã®èŠçŽ ãæãããã¿ã°ã«ãŒãã®ããã®ä»ããã¿ã³ãã¢ãããã£ãèŠçŽ ãã¹ãã¬ããèŠçŽ ãããã³åèšãã¬ãã¯ã¹ä¿æ°ã§ãã èŠçŽ ã®ã»ãããå€æŽãããšãåãããšãèµ·ãããŸãã
ããã©ã«ãç¶æ
elements.show(); adaptive.collapse(); flexible.width(baseWidth); els.each(funcion(el){ el._width = el.width(); }); fullWidth = sum(el._width);
åæååŸã衚瀺ãããå¯èœæ§ã®ãããã¹ãŠã®èŠçŽ ã衚瀺ãããŸãã ã¹ãã¬ããèŠçŽ ã®å Žåãå¹ ã¯ããŒã¹ã«çããèšå®ãããé©å¿å¯èœãªèŠçŽ ã¯æããããŸãããã¹ãŠã®èŠçŽ ã®å¹ ãã°ã«ãŒãã®ãã¹ãŠã®æãããã¿èŠçŽ ã®å¹ ãããŒã«ããŒã®å šå¹ ããã£ãã·ã¥ãããŸãã
ã»ããïŒæ§æïŒå ã®èŠçŽ ãå€æŽãé衚瀺/衚瀺ãã€ãŸããèšç®å ã®èŠçŽ ã®åœ¹å²ãå€æŽããŸãã¯ã»ãããå€æŽãããšãåæ§ã®ã¢ã¯ã·ã§ã³ãçºçããŸãã
ããŒã¿ã«ã¡ãã¥ãŒã¯ã衚瀺ä»ãã®2ã€ã®ã»ã«ãtable-cellã«åãããŠããŸãã ããŽã¯å·ŠåŽã«ãããå³åŽã«ã¯ããŒã«ããŒããããæ®ãã®ãã¹ãŠã®ã¹ããŒã¹ãå ããŠããŸãã ãã¥ãŒãã©ãŒã¯å³ã®ã»ã«å ã«ãããã¡ãã¥ãŒå šäœã®å¹ ã«åœ±é¿ãäžããªãããã«çµ¶å¯Ÿçã«é 眮ãããŠããŸãã
ãããã£ãŠãèŠçŽ ãããã©ã«ãã®ç¶æ ïŒå¯èŠïŒã«ãããšãã»ã«ãšããŒã«ããŒã®å¹ ããããã®ã§ãåãŸããªããã¯ã»ã«ã®æ°ããŸãã¯éã«ç©ºãã¹ããŒã¹ã®éãããããŸãã
å¯èŠèŠçŽ ã®èšç®
ããŒã«ããŒã®å šå¹ ãæ¢åã®å¹ ãããå°ããå Žåã¯ããã¹ãŠã®èŠçŽ ã衚瀺ããããã®ä»ããã¿ã³ãé衚瀺ã«ããŸãã
if (fullWidth <= currentWidth) moreButtonsHide(); collapsibleEls.show(); }
ãã以å€ã®å Žåã¯ãããã®ä»ããã¿ã³ã衚瀺ãããã¹ãŠã®ã°ã«ãŒãã調ã¹ãŠãå¿ èŠãªæ°ã®èŠçŽ ãé衚瀺ã«ããŸãã
if (fullWidth > currentWidth) moreButtonsShow(); groups.each(function(group){ ... }) }
ã°ã«ãŒãèšç®
è€æ°ã®ã°ã«ãŒããååšããå Žåãé¡ã®å³ããå·Šã«èŠçŽ ãé衚瀺ã«ããããšãããšã1ã€ã®ã°ã«ãŒãïŒå³ã®ã°ã«ãŒãïŒãããã¹ãŠãé衚瀺ã«ãªãããšããããŸãã ããã¯è¯ããããŸããã å¥ã®ãªãã·ã§ã³ãæ¢ããŠããŸãã åã°ã«ãŒãã®åæ°ã®èŠçŽ ã§é衚瀺ã«ã§ããŸãã ãŸãããããããŸããïŒãããããå¿ èŠä»¥äžã®èŠçŽ ãé衚瀺ã«ããããšãããããŸãã ãããã£ãŠãã°ã«ãŒãã®è¡šç€ºå¹ ã®åèšã«æ¯äŸããŠé衚瀺ã¹ããŒã¹ãåæ£ããå¿ èŠããããŸãã ã°ã«ãŒãå ã®èŠçŽ ãå€ãã»ã©ãããå€ãã®èŠçŽ ãé衚瀺ã«ããå¿ èŠããããŸãã
ã»ãšãã©ã®å Žåãé衚瀺ã«ã§ãããã¯ã»ã«æ°ãã°ã«ãŒãã«èŠæ±ããå¿ èŠãããããšãããããŸãã çµå±ã®ãšãããèŠçŽ ãéšåçã«é衚瀺ã«ããããšã¯ã§ããŸãããã€ãŸããããã«é衚瀺ã«ããŸãã ããã¯åçã«ç€ºãããŠããŸãïŒå³ã®è¡-質åãããæ°ãå·Š-çµå±ã¯ã©ããããã§ãããã
ãã®ç¶æ³ã§ã¯ããµã€ãºå€æŽæã«èŠçŽ ããžã£ã³ãããããšãããããŸãã ããã°ã«ãŒãã§ã¯è¡šç€ºãããå¥ã®ã°ã«ãŒãã§ã¯é衚瀺ã«ãªããéã®å Žåãåæ§ã§ãã ãã®åé¡ã解決ããã«ã¯ãèŠæ±ããããã¯ã»ã«ãšå®éã«é ããããã¯ã»ã«ã®éããèæ ®ãããã®éãã«åãããŠæ¬¡ã®ã°ã«ãŒãã®ãã¯ã»ã«ã調æŽããå¿ èŠããããŸãã
var groupToHide = Math.round(pixelsToHide * group.collapsibleWidth /collapsibleFullWidth); var hiddenFromGroup = group.expand(groupToHide + notHidden); notHidden = groupToHide - hiddenFromGroup;
ã¢ãããã£ããšã¬ã¡ã³ã
ã°ã«ãŒããå®æããããæ®ãã®ãã¯ã»ã«ãåé ã§ããŸãã
æåã«ãã¢ãããã£ããã¿ã³ãéããã©ããã確èªããå¿ èŠããããŸãã
ããžãã¯ã¯åçŽã§ãã åæå段éã§ãæããããŸããã¢ãããã£ããšã¬ã¡ã³ããšæããããŸããã¢ãããã£ããšã¬ã¡ã³ãã®ãµã€ãºããã£ãã·ã¥ãããŸãã
this.expand(); this._expandedWidth = this.el.clientWidth; this.collapse(); this._width = this.el.clientWidth;
ã€ãŸããå転ããèŠçŽ ãæ®ãã®ã¹ããŒã¹ã«åãŸããã©ãããç°¡åã«èŠã€ããããšãã§ããŸãã ã¯ãã®å Žåããã¿ã³ã«å¯ŸããŠããã¹ããæç»ããæ€çŽ¢ãå®å šãªãã¥ãŒã«åãæ¿ããŸãã ããã§ãªãå Žåããã¿ã³ã¯ã¢ã€ã³ã³ã®ç¶æ ã®ãŸãŸã«ãªããæ€çŽ¢ã¯ãã¿ã³ã®åœ¢ã«ãªããŸããã¯ãªãã¯ãããšãä»ã®èŠçŽ ã®äžã«ãã©ãŒã ã衚瀺ãããŸãã
if (currentWidth + adaptiveFullWidth <= avaibleWidth){ adaptive.expand(); }
æ«å°Ÿã®èŠçŽ
åŸç¶ã®èŠçŽ ã¯æ®ããŸããã ååãªã¹ããŒã¹ããªãå Žåã¯ããµã€ãºãããŒã¹å¹ ã«åãããŸãã
if (avaibleWidth <= 0){ flexible.width(baseWidth); }
ãã以å€ã®å Žåã¯ãã¹ãã¬ããèŠçŽ éã®ç©ºãã¹ããŒã¹ãåçã«åé ããŸãã
if (avaibleWidth > 0){ flexible.width(baseWidth + + avaibleWidth / flexible.length); }
ããããèŠããŠããããã«ãèæ ®ãã¹ããã¬ãã¯ã¹ä¿æ°ããããŸãã åèšãããšãç¹å®ã®äŒžçž®èŠçŽ ã®å¹ ã¯ãã®ããŒã¹å¹ ã«çãããªãããã¬ãã¯ã¹ä¿æ°ã«æ¯äŸããŠèšç®ãããè¿œå ã®å¹ ã§æãç³ãŸããŸãã
var pix = (flexEl.flex) * (avaibleWidth) / (flexSum); flexEl.width(baseWidth + pix);
ãã¥ã¢ã³ã¹ããããŸãã 100ãã¯ã»ã«ã®ç©ºãã¹ããŒã¹ãšflex 1ã®3ã€ã®äŒžçž®èŠçŽ ããããšããŸããããããã«33ãã¯ã»ã«ãå²ãåœãŠã1ã¯æªå²ãåœãŠã®ãŸãŸã§ããããšãããããŸãã ããŒãžã®ãµã€ãºãå€æŽãããšãããšãã°99ãã¯ã»ã«ã«ãªãããã¹ãŠãåæ£ãããŸãã
ã€ãŸããæåŸã®æåŸã®èŠçŽ ã®å³åŽã«ããèŠçŽ ã¯ãå®æçã«å³ã®å¢çã«å¯ŸããŠãã®ãã¯ã»ã«ã«ãžã£ã³ãããŸãã
ãã®åé¡ã解決ããã«ã¯ãæãããã¿å¯èœãªã°ã«ãŒãã«äœ¿çšããããã®ãšåæ§ã®ã¹ããŒã ã䜿çšã§ããŸãã èŠçŽ ã«ãã£ãŠèšå®ãããèšç®å€ãšå®éã«é©çšãããèšç®å€ãšã®å·®ãèŠããŠããå¿ èŠããããŸããã€ãŸãããã®å€ã§æ¬¡ã®èŠçŽ ãäžžããŠèª¿æŽããŸãã
var pix = (flexEl.flex) * (avaibleWidth) / / (flexSum) + delta; var roundedPix = Math.round(pix); flexEl.width(baseWidth + roundedPix); delta += (pix - roundedPix);
çµè«ãšããŠ
ãã®ãããäž¡æ¹ã®åæèŠä»¶ãæºããé©å¿åããŒã¿ã«ã¡ãã¥ãŒãäœæããããšãã§ããŸããã ãŸããæè¡çã«ç¬ç«ããŠããããšãå€æããŸãããåäžã®æè¡ãœãªã¥ãŒã·ã§ã³ã䜿çšããããšã§ããã¹ãŠã®ãããžã§ã¯ãã®ããŒã¿ã«ã¬ã€ãã©ã€ã³ããµããŒãã§ããæ°ããããŒã¿ã«ã¹ã¿ã€ã«ã¯ã©ãã§ãéåžžã«åäžã«èŠããŸãã 次ã«ããããžã§ã¯ãããŒã ã«ããŒã¿ã«ã¡ãã¥ãŒã®èŠçŽ ã»ãããæè»ã«å¶åŸ¡ã§ããããã«ããŸããã ããã§ãåããŒã ã¯ã¬ã€ãã©ã€ã³å ã«ãšã©ãŸããªãããè¿ éã«ã調æŽãã§ããŸãã
ç§ãã¡ã¯äœãèµ·ãã£ããã奜ãã§ãããã®åé¡ã¯è§£æ±ºããããšèããããšãã§ããŸãã ããããç§ãã¡ã«ã¯ãŸã èšå€§ãªéã®è€éãªã¿ã¹ã¯ããããããããŸãã é¢çœãïŒ ç§ãã¡ã«æ¥ãŠãã ããïŒ