When my page loads the active accordion item slides open which causes the other elements on the page to also move for a second.
I'd like the active accordion item to render "already opened", but still retain the animation for when a user clicks on another accordion item, or even the originally opened item in cases where the user selects another item and then the original.
I cant find any css being used to do this, so maybe its something in the javascript? If so, how would I go about overriding this.
Any suggestions on how to accomplish this would be greatly appreciated!
Foundation Accordion: http://foundation.zurb.com/sites/docs/accordion.html
There's no simple solution from what I know, but you can override some attributes on load so that the active item is displayed by default. You'd have to begin with an accordion none of the items are active i.e. none of the accordion items have a class of .is-active:
Html:
<ul class="accordion" data-accordion data-allow-all-closed='true'>
<li class="accordion-item" data-accordion-item>
Accordion 1
<div class="accordion-content" data-tab-content>
Panel 1. Lorem ipsum dolor
</div>
</li>
<li class="accordion-item" data-accordion-item>
Accordion 2
<div class="accordion-content" data-tab-content>
Panel 2. Lorem ipsum dolor
</div>
</li>
<li class="accordion-item" data-accordion-item>
Accordion 3
<div class="accordion-content" data-tab-content>
Panel 3. Lorem ipsum dolor
</div>
</li>
</ul>
jQuery:
//Initialise the Foundation plugins
$(document).foundation();
function activateWithoutAnimation(itemIndex) {
//Get the accordion item according to its index (0 based)
var $accordionItem = $('.accordion-title:eq(' + itemIndex + ')');
//Set the aria attributes of the accordion item you want to appear
$accordionItem.attr('aria-expanded', 'true');
$accordionItem.attr('aria-selected', 'true');
//Set the attributes of the content.
$accordionItem.next().attr('aria-hidden', 'false');
$accordionItem.next().css('display', 'block');
//This is essential as it lets foundation know that the item is active (to re-allow toggling)
$accordionItem.trigger('click');
}
//Call the function.
activateWithoutAnimation(0);
There might be a better way to do the above, but from what I've read, there's no option that allows the animation to be disabled. I've tried overriding the defaults that Foundation provides to no avail.
Fiddle Demo
CSS Solution
If using the default helper class .is-active on initial load then some plain css can eliminate the slide open animation.
.is-active .accordion-content {
display: block;
}
https://jsfiddle.net/r6jvbohu/
CSS only (without losing the animation)
To always open the first item immediately while still keeping the animation, you can use the following code.
.accordion-item:first-of-type .accordion-content {
display: block;
}
The first item should still have the .is-active class to be consistent, but this removes the initial animation because we overwrite the display value from none to block. The JS still overwrites this state when another accordion item is clicked, resulting in the animation we want to keep.
Related
In a template I have two connected lists, one of which is initially empty. The user has to choose up to three options from the left list, add them to the right list, order them (according to his/her priorities) and then send it back.
it looks like:
<ul id="sortable1" class="connectedSortable">
<li value="1">Item A</li>
<li value="2">Item B</li>
<li value="3">Item C</li>
<li value="4">Item D</li>
<li value="5">Item E</li>
<li value="6">Item F</li>
<li value="7">Item G</li>
</ul>
</div>
<ul id="sortable2" class="connectedSortable">
<!--here goes the initially empty list-->
</ul>
and in {% scripts %} block:
<script>
$( function() {
$( "#sortable1, #sortable2" ).sortable({
connectWith: ".connectedSortable"
}).disableSelection();
} );
</script>
in models.py I have a field to store the selected info:
preferences = CommaSeparatedIntegerField()
The problem is how to POST info from the updated ul (sortable2) back to the database? I can add a hidden field preferences to the page and then fill it using jQuery, but it seems like an ugly solution. What is the right one?
If you want to POST the updated ul (sortable2) back to the database, then one of the possible solution is that the ul (sortable2) should be inside a form whose data you can submit using POST method.
Now when any of the li element is moved from the ul (sortable1) to ul(sortable2), then an input type element is also inserted in the ul (sortable2) along with the list element, where "value" attribute of the input will have to be the same as the li element in the ul (sortable1) was. Also the type of this input element will be hidden.
So now when you'll submit this form using a submit button, you'll get all the data back in your views and hence can make changes to your database accordingly.
I am currently working within SharePoint 2013 and was wondering if there was a way to create a button on a home page that when pressed, opens a list form in a modal window? (or in a non modal window).
I understand the method of using "Embed code" to code a button; however, it doesn't seem to allow me to link it to a list form, or edit what the button actually does.
Example:
1. An employee lands on the home page and wants to initiate a Purchase Request through the company.
2. The employee clicks on a button labeled "Click here to submit a Purchase Request".
3. After clicking, the Purchase Request form opens from the Purchase Request list (pre-created).
Thank you for your assistance!
You can use something like this in a CEWP to redirect to the new item form:
<button onclick="formRedirect(); return false;">New Form</button>
<script>
function formRedirect() {
window.location = "/test/Lists/LinkList/NewForm.aspx"
}
</script>
To display it in Modal form you will need to use the NewItem2 JS function:
<button onclick="NewItem2(event, "https://Your.SP.Site/_layouts/15/listform.aspx?PageType=8&ListId=%7B59E6FE0C%2D02C6%2D4B00%2D9B6A%2D87116A2DF594%7D&RootFolder="); return false;">New Form</button>
To get this to work you will need the list web part on the page where the button is located, though it can be hidden from view by setting th chrome to none and minimizing it. You can copy the function from the new item button in the list you wish to display, it is stored as an 'OnClick' property.
I know I am late to this but I just figured how to do this for the "Upload Document" for a document library. It took me a while but I stumbled upon it through trial and error using F12. I will provide both script for a "LIST and LIBRARY" form.
FOR A LIST:
<a href="#" onclick="openDialog('YourSiteURL/Lists/YourListName/NewForm.aspx');">
<img src="YourSiteImageURL" alt="NameofYourImage">
</a>
<script>
function openDialog(pageUrl) {
var options = {
url: pageUrl,
title: 'NameofYourForm', /* Enter the name you want for your form */
allowMaximize: false,
showClose: true,
width: 1225, /* Modify for your needs */
height: 800 /* Modify for your needs */
};
SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
}
</script>
FOR A LIBRARY:
This is for use with a button:
<a class="ms-addnew" id="idHomePageNewDocument" onclick='NewItem2(event, "YourSiteURL/_layouts/15/Upload.aspx?List={YourListID}&RootFolder="); return false;' href="YourSiteURL/_layouts/15/Upload.aspx?List={SameListID}&RootFolder=" target="_self" data-viewctr="702">
<img src="URLforYourButtonImage" alt="NameofYourButton">
</a>
This is for use with text:
<a class="ms-addnew" id="idHomePageNewDocument" onclick='NewItem2(event, "YourSiteURL/_layouts/15/Upload.aspx?List={YourListID}&RootFolder="); return false;' href="YourSiteURL/_layouts/15/Upload.aspx?List={SameListID}&RootFolder=" target="_self" data-viewctr="702">Add document
</a>
When I add new list items to an existing dropdown button they do not show up on the front end. The dropdown just continues to show the original list items. All my caching systems are off and I cleared the cache locally, but I'm still getting the same issue. Anyone know what could be causing this?
<div class="sidebar-dropdown">
<button data-dropdown="drop" aria-controls="drop", aria-expanded="false" class="large alert round button dropdown">Select Type</button>
<br>
<ul id="drop" data-dropdown-content class="f-dropdown" role="menu" aria-hidden="false" tabindex="-1">
<li>All-Purpose (USA)</li>
<li>Mobile</li>
<li>E-Commerce</li>
<li>All-Purpose (CAN)</li>
<li>Tablet POS</li>
<li>High Risk</li>
</ul>
</div>
The Foundation-generated dropdown needs to be refreshed when new content is added to it. This can be done by adding this to your javascript, which adds a listener to the dropdown element(s):
$(document).foundation('dropdown', 'reflow');
See the docs for more info
Is it possible to have two joyrides on one page? For example: run one joyride, then, once the user selects something, start a second joyride?
I believe what your looking for has its roots in the answer to this question. You can use the Callback to then initialize a 2nd Joyride by doing something such as triggering a button click on a hidden button.
I haven't been able to test this code yet, but it should work something along these lines:
// set up the config for a Callback
var config = {
nubPosition : 'auto',
postRideCallback : function() {
// Joyride has ended, simulate a click on a hidden button
$(#hidden_button).click();
}
// When the Hidden button is clicked, call the 2nd Joyride
$( "#hidden_button" ).click(function() {
$(document).foundation('joyride2', 'start');
});
You just have to wrap your joyride in a div and then start that joyride when you want to.
For example:
<div id="Joyryde1">
<ol class="joyride-list" data-joyride >
<li data-id="message1" data-text="Next" data-options="tip_location: top">
<p>Joyride 01</p>
</li>
</ol>
</div>
<div id="Joyryde2">
<ol class="joyride-list" data-joyride >
<li data-id="message1" data-text="Next" data-options="tip_location: top">
<p>Joyride 02</p>
</li>
</ol>
</div>
<script>
$("#joyride1").foundation('joyride', 'start'); //Start when the page loads
// Add this to your trigger(button or another page load)
$("#joyride2").foundation('joyride', 'start');
</script>
Is there a simple way to accomplish this using dojo (jQuery would be easier for me but I have to use dojo): I have a simple unordered list. I don't want dojo to style the list (as it might if I used some widget). When I click a link on the list I want to show a div associated with the link. Then if I click another link in the list the first div hides and that one shows.
<div id="content">
<h2>Header</h2>
<ul>
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
</ul>
<div id="sub_content1" style="display:none;">
<h3>Sub Content Header 1</h3>
<p>Lorem ipsum veritas britas conflictum civa</p>
</div>
<div id="sub_content2" style="display:none;">
<h3>Sub Content Header 2</h3>
<p>Lorem ipsum mobius ceti</p>
</div>
<div id="sub_content3" style="display:none;">
<h3>Sub Content Header 3</h3>
<p>Lorem ipsum citrus pecto</p>
<ul>
<li>Lemons</li>
<li>Limes</li>
</ul>
</div>
</div><!-- end of #content -->
So in fact you're creating your own tabcontainer? If you really want to do it yourself you should probably need something like this:
require(["dojo/ready", "dojo/on", "dojo/dom-attr", "dojo/dom-style", "dojo/query", "dojo/NodeList-dom"], function(ready, on, domAttr, domStyle, query) {
ready(function() {
query("ul li a").forEach(function(node) {
query(domAttr.get(node, "href")).forEach(function(node) {
domStyle.set(node, "display", "none");
});
on(node, "click", function(e) {
query("ul li a").forEach(function(node) {
if (node == e.target) {
query(domAttr.get(node, "href")).forEach(function(node) {
domStyle.set(node, "display", "block");
});
} else {
query(domAttr.get(node, "href")).forEach(function(node) {
domStyle.set(node, "display", "none");
});
}
});
});
});
});
});
I'm not sure how familiar you are with Dojo, but it uses a query that will loop all links in lists (with the dojo/query and dojo/NodeList-dom modules) (you should provide a classname or something like that to make it easier). Then it will, for each link, retrieve the div corresponding to it and hide it, it will also connect a click event handler to it (with the dojo/on module).
When someone clicks the link, it will (again) loop all the links, but this time it's doing that to determine which node is the target one and which isn't (so it can hide/show the corresponding div).
I made a JSFiddle to show you this. If something is still not clear you should first try to look at the reference guide of Dojo since it really demonstrates the most common uses of most modules.
But since this behavior is quite similar to a TabContainer, I would recommend you to look at the TabContainer reference guide.