Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
Features
~~~~~~~~

- Navigation:
- Do not set the ``.navigation-in-path`` class for elenents already marked with ``.current``.
- Allow configuration of "in path" and "current" classes via ``in-path-class`` and ``current-class`` configuration options.
- Add ``utils.getCSSValue`` for retrieving CSS property values for DOM nodes.
- Add configurable scrolling behavior to pat-inject.
- Add ``webpack-visualizer-plugin`` for analyzation of generated bundles.
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ all_css:: css
@$(SASS) -I . -I _sass src/pat/markdown/_markdown.scss src/pat/markdown/markdown.css
@$(SASS) -I . -I _sass src/pat/masonry/_masonry.scss src/pat/masonry/masonry.css
@$(SASS) -I . -I _sass src/pat/modal/_modal.scss src/pat/modal/modal.css
@$(SASS) -I . -I _sass src/pat/navigation/_navigation.scss src/pat/navigation/navigation.css
@$(SASS) -I . -I _sass src/pat/notification/_notification.scss src/pat/notification/notification.css
@$(SASS) -I . -I _sass src/pat/slideshow-builder/_slideshow-builder.scss src/pat/slideshow-builder/slideshow-builder.css
@$(SASS) -I . -I _sass src/pat/sortable/_sortable.scss src/pat/sortable/sortable.css
Expand Down
10 changes: 4 additions & 6 deletions _sass/_settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// with Fontello.com Make sure the fontello folder is placed in your
// style folder

@import "/patternslib/style/fontello/css/fontello.css";
@import "/style/fontello/css/fontello.css";

// Assets
//@import url(http://fonts.googleapis.com/css?family=Sorts+Mill+Goudy:400,400italic);
Expand All @@ -14,11 +14,11 @@
// $felt: #89AA74;
$felt: #565656;

$colour-accent: #0198E1 !default;
$colour-accent: #0198e1 !default;
$colour-base: #efefef !default;
$colour-alert: red !default;
$colour-success: green !default;
$colour-notice: #FFFFD6 !default;
$colour-notice: #ffffd6 !default;
$colour-warning: orange !default;
$colour-error: red !default;
$colour-info: $colour-notice !default;
Expand All @@ -37,7 +37,7 @@ $glyph-radio-button-active: "\e2001";
$glyph-close: "\e2005";

// We use these to control various global styles
$body-font-family: 'Source Sans Pro', sans-serif;
$body-font-family: "Source Sans Pro", sans-serif;
$body-font-weight: $font-weight-normal;
$body-font-style: normal;

Expand All @@ -51,5 +51,3 @@ $cat-layout: #a1ced2;

$break-small: 768px !default;
$break-large: 769px !default;


6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
138 changes: 97 additions & 41 deletions src/pat/navigation/index.html
Original file line number Diff line number Diff line change
@@ -1,46 +1,102 @@
<!DOCTYPE html>
<html>
<head>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Navigation demo</title>
<link rel="stylesheet" href="/style/common.css" type="text/css" />
<script src="/bundle.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css" media="screen">
a.current {
color: white;
background: green;
}
.navigation-in-path > a {
color: white;
background: blue;
}
#content-tab {
font-weight: bold;
font-size: 2em;
}
</style>
</head>
<body>
<header>
<h2>Navigation demos</h2>
</header>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>pat-navigation demo page</title>
<link rel="stylesheet" href="/style/common.css" type="text/css">
<script src="/bundle.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<section class="description">
<a href="description.md" class="pat-inject" data-pat-inject="source: ::element; target: self::element; trigger: autoload">Description</a>
</section>
<h2>Demo</h2>
<div id="demo">
<section class="demo">
<p>Testing tab .current behaviour</p>
<ul class="pat-navigation">
<li>
<a href="pattern-test-response.html#inject-tab-1" class="pat-inject"
data-pat-inject="target: #content-tab">Tab 1</a>
<section>
<header>
<h3>Example 1</h3>
</header>
<ul class="pat-navigation">
<li>
<a
href="pattern-test-response.html#inject-tab-1"
class="pat-inject"
data-pat-inject="target: #content-tab"
>Tab 1</a
>

<ul class="navigation">
<li>
<a href="pattern-test-response.html#inject-tab-1-1" class="pat-inject"
data-pat-inject="target: #content-tab">Link 1.1</a>
</li>
<li>
<a href="pattern-test-response.html#inject-tab-1-2" class="pat-inject"
data-pat-inject="target: #content-tab">Link 1.2</a>
</li>
</ul>
</li>
<li>
<a href="pattern-test-response.html#inject-tab-2" class="pat-inject"
data-pat-inject="target: #content-tab">Tab 2</a>
</li>
</ul>
<div id="content-tab">Content will appear here</div>
</section>
</div>
<section class="documentation">
<a href="documentation.md" class="pat-inject" data-pat-inject="source: ## Documentation::element; target: self::element; trigger: autoload">Documentation</a>
</section>
</body>
<ul>
<li>
<a
href="pattern-test-response.html#inject-tab-1-1"
class="pat-inject"
data-pat-inject="target: #content-tab"
>Link 1.1</a
>
</li>
<li>
<a
href="pattern-test-response.html#inject-tab-1-2"
class="pat-inject"
data-pat-inject="target: #content-tab"
>Link 1.2</a
>
</li>
</ul>
</li>
<li>
<a
href="pattern-test-response.html#inject-tab-2"
class="pat-inject"
data-pat-inject="target: #content-tab"
>Tab 2</a
>
</li>
</ul>
</section>

<section>
<header>
<h3>
Example 2, same as above. Shows that multiple navigation patterns can
be used on same site.
</h3>
</header>
<ul class="pat-navigation">
<li>
<a
href="pattern-test-response.html#inject-tab-1"
class="pat-inject"
data-pat-inject="target: #content-tab"
>Tab 1</a
>
</li>

<li>
<a
href="pattern-test-response.html#inject-tab-2"
class="pat-inject"
data-pat-inject="target: #content-tab"
>Tab 2</a
>
</li>
</ul>
</section>

<div id="content-tab">Content will appear here</div>

</body>
</html>
111 changes: 60 additions & 51 deletions src/pat/navigation/navigation.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,78 @@
define([
"jquery",
"pat-registry",
"pat-parser",
"pat-logger",
"pat-registry"
], function($, logger, registry) {
var log = logger.getLogger("pat.navigation");
], function($, registry, Parser, logger) {
var log = logger.getLogger("navigation");
var parser = new Parser("navigation");

parser.addArgument("in-path-class", "navigation-in-path");
parser.addArgument("current-class", "current");

var _ = {
name: "navigation",
trigger: "nav, .navigation, .pat-navigation",
init: function($el) {
return $el.each(function() {
var $el = $(this);
var curpath = window.location.pathname;
log.debug("current path:", curpath);
current: null,
in_path: null,
init: function($el, opts) {
this.options = parser.parse($el, opts);
this.current = this.options.currentClass;
this.in_path = this.options.inPathClass;

// check whether to load
if ($el.hasClass("navigation-load-current")) {
$el.find("a.current, .current a").click();
// check for current elements injected here
$el.on("patterns-injected-scanned", function(ev) {
var $target = $(ev.target);
if ($target.is("a.current"))
$target.click();
if ($target.is(".current"))
$target.find("a").click();
_._updatenavpath($el);
});
}
var curpath = window.location.pathname;
log.debug("current path:", curpath);

// An anchor within this navigation triggered injection
$el.on("patterns-inject-triggered", "a", function(ev) {
// check whether to load
if ($el.hasClass("navigation-load-current")) {
$el.find("a." + this.current, "." + this.current + " a").click();
// check for current elements injected here
$el.on("patterns-injected-scanned", function(ev) {
var $target = $(ev.target);
// remove all set current classes
$el.find(".current").removeClass("current");
// set .current on target
$target.addClass("current");
// If target's parent is an LI, also set current there
$target.parent("li").addClass("current");
if ($target.is("a." + this.current))
$target.click();
if ($target.is("." + this.current))
$target.find("a").click();
_._updatenavpath($el);
});
}.bind(this));
}

// set current class if it is not set
if ($el.find(".current").length === 0) {
$el.find("li a").each(function() {
var $a = $(this),
$li = $a.parents("li:first"),
url = $a.attr("href"),
path;
if (typeof url === "undefined") {
return;
}
path = _._pathfromurl(url);
log.debug("checking url:", url, "extracted path:", path);
if (_._match(curpath, path)) {
log.debug("found match", $li);
$li.addClass("current");
}
});
}
// An anchor within this navigation triggered injection
$el.on("patterns-inject-triggered", "a", function(ev) {
var $target = $(ev.target);
// remove all set current classes
$el.find("." + this.current).removeClass(this.current);
// set current class on target
$target.addClass(this.current);
// If target's parent is an LI, also set current class there
$target.parent("li").addClass(this.current);
_._updatenavpath($el);
});
}.bind(this));

// Set current class if it is not set
if ($el.find(this.current).length === 0) {
document.querySelectorAll("li a").forEach(function (it) {
var $a = $(it),
$li = $a.parents("li:first"),
url = $a.attr("href"),
path;
if (typeof url === "undefined") {
return;
}
path = _._pathfromurl(url);
log.debug("checking url:", url, "extracted path:", path);
if (_._match(curpath, path)) {
log.debug("found match", $li);
$li.addClass(this.current);
}
}.bind(this));
}
_._updatenavpath($el);
},
_updatenavpath: function($el) {
$el.find(".navigation-in-path").removeClass("navigation-in-path");
$el.find("li:has(.current)").addClass("navigation-in-path");
if (this.in_path === null) { return; }
$el.find(this.in_path).removeClass(this.in_path);
$el.find("li:not(." + this.current + "):has(." + this.current + ")").addClass(this.in_path);
},
_match: function(curpath, path) {
if (!path) {
Expand Down
18 changes: 9 additions & 9 deletions src/pat/navigation/pattern-test-response.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div id="inject-tab-1">
Content for tab 1
Content for tab 1
</div>

<div id="inject-tab-2">
Content for tab 2
Content for tab 2
</div>

<div id="inject-tab-1-1">
Content for tab 1.1
Content for tab 1.1
</div>

<div id="inject-tab-1-2">
Content for tab 1.2
Content for tab 1.2
</div>
</body>
</body>
</html>
Loading