]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
closes #7882, adds examples of passing options for plugins through js, as well as...
authorChris Oyler <chris@zurb.com>
Thu, 14 Jan 2016 23:50:07 +0000 (15:50 -0800)
committerChris Oyler <chris@zurb.com>
Thu, 14 Jan 2016 23:50:07 +0000 (15:50 -0800)
docs/pages/javascript.md

index c9408af886d9bb1963b3c49726f22bbef1bd31d3..5478c905e9d5c9883f9ad64b74e1bb042362ece2 100644 (file)
@@ -82,12 +82,25 @@ In the HTML, each setting can be defined as an individual data attribute. Note t
 <div data-accordion data-slide-speed="500" data-multi-expand="true"></div>
 ```
 
-Data options can also be set in bulk on one attribute, `data-options`. Options are written with the format `key: value`, with a semicolon separating each option. The above example can be written using `data-options` like so:
+Data options can also be set in bulk on one attribute, `data-options`. Options are written with the format `key: value;`, with a semicolon separating each option. The above example can be written using `data-options` like so:
 
 ```html
-<div data-accordion data-options="slideSpeed: 500; multiExpand: true"></div>
+<div data-accordion data-options="slideSpeed: 500; multiExpand: true;"></div>
 ```
 
+Setting options with JavaScript involves passing an object into the constructor function, like this:
+
+```js
+var options = {multiExpand: true, allowAllClosed: false};
+var accordion = new Foundation.Accordion($('#some-accordion'), options);
+```
+
+It's worth noting that options passed to plugins via JavaScript take the highest precedence, and will overwrite any default values or options applied via the `data-some-option` tag. This is also how the `data-options="someOption:true; someOtherOption:false"` options are passed into constructor functions. So, if you were to say:
+```html
+<div data-accordion data-slide-speed="500" data-options="slideSpeed:250;">...</div>
+```
+your accordion element would have a slide speed of 250 milliseconds.
+
 ---
 
 ## Adding Plugins After Page Load