Skip to content

Commit fdd82df

Browse files
committed
Merge branch 'master' into release
2 parents 2e5a5c8 + 3990702 commit fdd82df

File tree

15 files changed

+108
-27
lines changed

15 files changed

+108
-27
lines changed

VERSION.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
// Patternslib 2.0.13
1+
// Patternslib 2.0.14
22

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "patternslib",
3-
"version": "2.0.13",
3+
"version": "2.0.14",
44
"main": "bundle.js",
55
"devDependencies": {
66
"jasmine": "https://github.com/jcbrand/jasmine.git#1_3_x"

changes.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 2.0.14 - Aug. 15, 2016
4+
5+
- A fix for pat-scroll to scroll up to current scroll container instead of body.
6+
- A fix for pat-scroll to await loading of all images before determining the amount to scroll up.
7+
- A fix for IE10/11 where the modal wouldn`t close anymore due to activeElement being undefined
8+
- Allow to configure different data-pat-inject per formaction, so that different targets can be configured per formaction
9+
310
## 2.0.13 - Apr. 27, 2016
411

512
- New property for sortable pattern, `drag-class`, the CSS class to apply to item being dragged. Is `"dragged"` by default.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "patternslib",
3-
"version": "2.0.13",
3+
"version": "2.0.14",
44
"title": "Markup patterns to drive behaviour.",
55
"description": "Patternslib is a JavaScript library that enables designers to build rich interactive prototypes without the need for writing any Javascript. All events are triggered by classes and other attributes in the HTML, without abusing the HTML as a programming language. Accessibility, SEO and well structured HTML are core values of Patterns.",
66
"author": {

src/core/parser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ define([
237237
if (!part) { return; }
238238
var matches = part.match(this.named_param_pattern);
239239
if (!matches) {
240-
this.log.warn("Invalid parameter: " + part);
240+
this.log.warn("Invalid parameter: " + part + ": " + argstring);
241241
return;
242242
}
243243
var name = matches[1],

src/core/store.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ define(function() {
108108
}
109109
}
110110
return options;
111-
},
112-
111+
}
113112
};
114113

115114
// Perform the test separately since this may throw a SecurityError as

src/core/utils.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
define([
22
"jquery",
3-
"jquery.browser",
4-
"underscore"
5-
], function($) {
3+
"underscore",
4+
"jquery.browser" // adds itself to the jquery object, no need to pass to the define callback.
5+
], function($, _) {
66

77
$.fn.safeClone = function () {
88
var $clone = this.clone();

src/pat/clone/documentation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ The markup below would have exactly the same effect as the first example, but us
9191
|------|------|-----|------|
9292
| template |Selects the element that will be cloned each time. You might often want to refer to a piece of template markup for this that is hidden with though the CSS. |:first | | CSS Selector |
9393
| max |Maximum number of clones that is allowed | | | Integer |
94-
| trigger-element |Selector of the element that will remove the clone when clicked upon. | .add-clone | | CSS Selector |
94+
| trigger-element |Selector of the element that will add the clone when clicked upon. | .add-clone | | CSS Selector |
9595
| remove-element |Selector of the element that will remove the clone when clicked upon. | .remove-clone | | CSS Selector|
9696
| remove-behaviour or remove-behavior | What should happen when the user clicks on the element to remove a clone? Two choices exist currently. Show a confirmation dialog, or simply remove the clone immediately. | "confirm" | "confirm", "none" | One of the allowed string values. |
9797
| clone-element |Selector of the individual clone element(s). | .clone | | CSS Selector|

src/pat/gallery/gallery.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ define("pat-gallery", [
6464
});
6565
gallery.init();
6666
});
67-
},
67+
}
6868
});
6969
});

src/pat/inject/inject.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ define([
108108
formaction = $button.attr("formaction"),
109109
$form = $button.parents(".pat-inject").first(),
110110
opts = {url: formaction},
111-
cfgs = inject.extractConfig($form, opts);
111+
$cfg_node = $button.closest("[data-pat-inject]"),
112+
cfgs = inject.extractConfig($cfg_node, opts);
112113

113114
ev.preventDefault();
114115
$form.trigger("patterns-inject-triggered");

src/pat/inject/tests.js

+24
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,30 @@ define(["pat-inject", "pat-utils"], function(pattern, utils) {
660660
$form.append($submit1).append($submit2);
661661
$div.append($target1).append($target2);
662662

663+
pattern.init($form);
664+
$submit2.trigger("click");
665+
answer("<html><body>" +
666+
"<div id=\"someid\">some</div>" +
667+
"<div id=\"otherid\">other</div>" +
668+
"</body></html>");
669+
670+
expect($.ajax).toHaveBeenCalled();
671+
expect($.ajax.mostRecentCall.args[0].url).toContain("submit=special");
672+
expect($.ajax.mostRecentCall.args[0].url).toBe("other.html?submit=special");
673+
expect($target1.html()).toBe("some");
674+
expect($target2.html()).toBe("other");
675+
});
676+
it("formaction works source and target on the button", function() {
677+
var $submit1 = $("<input type=\"submit\" name=\"submit\" value=\"default\" />"),
678+
$submit2 = $("<input type=\"submit\" name=\"submit\" value=\"special\" />"),
679+
$target1 = $("<div id=\"target1\" />"),
680+
$target2 = $("<div id=\"target2\" />");
681+
682+
$submit2.attr("data-pat-inject", "#someid #target1 && #otherid #target2");
683+
$submit2.attr("formaction", "other.html#otherid");
684+
$form.append($submit1).append($submit2);
685+
$div.append($target1).append($target2);
686+
663687
pattern.init($form);
664688
$submit2.trigger("click");
665689
answer("<html><body>" +

src/pat/modal/modal.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ define([
6262

6363
// Restore focus in case the active element was a child of $el and
6464
// the focus was lost during the wrapping.
65-
document.activeElement.focus();
65+
// Only if we have an activeElement, as IE10/11 can have undefined as activeElement
66+
if (document.activeElement) {
67+
document.activeElement.focus();
68+
}
6669
this._init_handlers();
6770
this.resize();
6871
this.setPosition();

src/pat/scroll/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ <h3>3</h3>
7777
</p>
7878
</section>
7979
<p>
80-
<a href="#demo-main-nav" class="pat-scroll">Back to top</a>
80+
<a href="#demo-main-nav" class="pat-scroll" data-pat-scroll="trigger:auto">Back to top</a>
8181
</p>
8282
</article>
8383
</body>

src/pat/scroll/scroll.js

+41-11
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ define([
88
"pat-utils",
99
"pat-logger",
1010
"pat-parser",
11-
"underscore"
12-
], function($, patterns, Base, utils, logging, Parser, _) {
11+
"underscore",
12+
"imagesloaded"
13+
], function($, patterns, Base, utils, logging, Parser, _, imagesLoaded) {
1314
var log = logging.getLogger("scroll"),
1415
parser = new Parser("scroll");
1516
parser.addArgument("trigger", "click", ["click", "auto"]);
@@ -25,7 +26,11 @@ define([
2526
init: function($el, opts) {
2627
this.options = parser.parse(this.$el, opts);
2728
if (this.options.trigger == "auto") {
28-
this.smoothScroll();
29+
// Only calculate the offset when all images are loaded
30+
var that = this;
31+
$('body').imagesLoaded( function() {
32+
that.smoothScroll();
33+
});
2934
} else if (this.options.trigger == "click") {
3035
this.$el.click(this.onClick.bind(this));
3136
}
@@ -121,15 +126,40 @@ define([
121126
$el = this.options.selector ? $(this.options.selector) : this.$el;
122127
options[scroll] = this.options.offset;
123128
} else {
124-
$el = $('body, html');
125-
options[scroll] = $(this.$el.attr('href')).offset().top;
126-
}
127-
$el.animate(options, {
128-
duration: 500,
129-
start: function() {
130-
$('.pat-scroll').addClass('pat-scroll-animated');
129+
// Get the first element with overflow auto starting from the trigger
130+
// (the scroll container)
131+
// Then calculate the offset relatively to that container
132+
$el = $(this.$el.parents()
133+
.filter(function() {
134+
return $(this).css('overflow') === 'auto'; })
135+
.first())
136+
if (typeof $el[0] === 'undefined') {
137+
$el = $('html, body');
131138
}
132-
});
139+
140+
var scroll_container = Math.floor( $el.offset().top );
141+
var target = Math.floor( $(this.$el.attr('href')).offset().top );
142+
143+
if (target == scroll_container) {
144+
options[scroll] = scroll_container;
145+
} else if (target >= scroll_container) {
146+
options[scroll] = target - scroll_container;
147+
$el.animate(options, {
148+
duration: 500,
149+
start: function() {
150+
$('.pat-scroll').addClass('pat-scroll-animated');
151+
}
152+
});
153+
} else {
154+
options[scroll] = target + scroll_container ;
155+
$el.animate(options, {
156+
duration: 500,
157+
start: function() {
158+
$('.pat-scroll').addClass('pat-scroll-animated');
159+
}
160+
});
161+
}
162+
}
133163
}
134164
});
135165
});

src/pat/scroll/tests.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@ define(["pat-scroll"], function(Pattern) {
1717
].join("\n"));
1818
spyOn($.fn, 'animate');
1919
Pattern.init($(".pat-scroll"));
20-
expect($.fn.animate).toHaveBeenCalled();
20+
var flag;
21+
this.waitsFor(function() {
22+
$("body").imagesLoaded(function() {flag = true;});
23+
return flag;
24+
}, "The images should be loaded", 750);
25+
26+
this.runs(function() {
27+
expect($.fn.animate).toHaveBeenCalled();
28+
});
29+
// expect($.fn.animate).toHaveBeenCalled();
2130
});
2231
});
2332

@@ -37,8 +46,16 @@ define(["pat-scroll"], function(Pattern) {
3746
var $el = $(".pat-scroll");
3847
spyOn($.fn, 'animate');
3948
Pattern.init($el);
49+
var flag;
50+
this.waitsFor(function() {
51+
$("body").imagesLoaded(function() {flag = true;});
52+
return flag;
53+
}, "The images should be loaded", 750);
4054
$el.click();
41-
expect($.fn.animate).toHaveBeenCalled();
55+
56+
this.runs(function() {
57+
expect($.fn.animate).toHaveBeenCalled();
58+
});
4259
});
4360

4461
it("will scroll to an anchor on pat-update with originalEvent of click", function() {

0 commit comments

Comments
 (0)