Scroll to Accordion Item Top Once Open (Foundation Framework) - zurb-foundation

I'm using ZURB Foundation (v6) Accordions.
When an accordion opens, I want to scroll the page to be at the top of that accordion item. I can run this code:
$("#arf").on("down.zf.accordion", function() {
$('html,body').animate({scrollTop: $(this).offset().top}, 'slow');
});
Of course, this scrolls the page to the top of the accordion, not the accordion item. How would I modify this code to scroll to the accordion's item when it opens?

Here is the solution that I found that works. This works for version 6 of Foundation for Sites.
$("#form-selector").on("up.zf.accordion", function(event) {
setTimeout(function(){
$('html,body').animate({scrollTop: $('.is-active').offset().top}, 'slow');
}, 250); //Adjust to match slideSpeed
});
The setTimeout is used because of the slideSpeed of the accordion. If you do not use setTimeout it scrolls the moment down.zf.accordion fires thus scrolling to the wrong position.
You can also us down.zf.accordion in place of up.zf.accordion, however, if you use down.zf.accordion, it will fire once the page loads (as the accordion is initialized and opens) and scrolls to the accordion item. This is unwanted in my case but may be desired in certain case.

You could attach your own click listeners to each accordion <a> tag and scroll to the top of that tag on click. Eg.
JS
$('.accordionBtn').on('click', function(event) {
$('html,body').animate({scrollTop: $(event.target).offset().top}, 'slow');
});)
CSS
<ul class="accordion" data-accordion>
<li class="accordion-navigation">
<a class="accordionBtn" href="#panel1a">Accordion 1</a>
<div id="panel1a" class="content active">
Panel 1. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</div>
</li>
<li class="accordion-navigation">
<a class="accordionBtn" href="#panel2a">Accordion 2</a>
<div id="panel2a" class="content">
Panel 2. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</div>
</li>
<li class="accordion-navigation">
<a class="accordionBtn" href="#panel3a">Accordion 3</a>
<div id="panel3a" class="content">
Panel 3. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</div>
</li>
</ul>

I first used the solution posted by #L84 then I thought of this one.
In the code below, $active references the currently active accordion item (Note: the reference is stored each time an accordion is opened rather than when the accordion title is clicked). When a new title is clicked, $active is the item that will be closed. We need to know its height in advance.
For the newly active accordion item to be properly positioned, the height of that previously active item has to be subtracted from the viewport's scrolling position -- note that this in necessary only if the newly active item is located further down.
$(function () {
var $active;
$(".accordion").on("click", ".accordion-title", function () {
var itemIndexNew = $(".accordion-item").index($(this).parent());
var itemIndexOld = ($active ? $(".accordion-item").index($active) : null);
if (itemIndexOld !== null && itemIndexOld < itemIndexNew) {
$("html, body").scrollTop($(window).scrollTop() - $active.height());
}
});
$(".accordion").on("down.zf.accordion", function(e) {
$active = $(".accordion").find(".accordion-item.is-active");
});
$(document).foundation();
});

You could use the below script, im also using foundation 6 accordion, this will work also if you have multiple accordions on single page. Thanks
jQuery(".accordion-title").click(function() {
var $this = this;
setTimeout(function(){
jQuery('html,body').animate({scrollTop: jQuery($this).closest('.accordion').find('.is-active').offset().top}, 'slow');
}, 250);
});

Related

How to render Django TextField within VueJs Template

I am writing my backend using DRF and using VueJS frontend templates. In the admin panel I use Ckeditor to edit textfield.
class ArticleModelForm(forms.ModelForm):
content = forms.CharField(widget=CKEditorUploadingWidget)
class Meta:
model=Article
fields = [ "title", "slug" "published_at"]
While rendering a post TextField I can not use template filters to render correctly, so text seems ruined. I have tried lots of things but no success yet.
<template>
<div>
<div class="container negative-margin-top150">
<div class="col col-xl-8 m-auto col-lg-12 col-md-12 col-sm-12 col-12">
<div class="ui-block">
<!-- Single Post -->
<article class="hentry blog-post single-post single-post-v1">
<div class="post-content-wrap">
<div class="post-content" >
<p class="post-paragraph">
{{article.content}}
</p>
<p>{{content}}</p>
</div>
</div>
</article>
<!-- ... end Single Post -->
</div>
</div>
</div>
</div>
</template>
and my script is below
<script>
import axios from 'axios';
export default {
name: "Article",
props: {
slug: {
type: String,
required: true
}
},
data() {
return {
article: {},
content: `${content}`,
}
},
methods: {
setPageTitle(title) {
document.title = title;
},
setRequestUser() {
this.requestUser = window.localStorage.getItem("username");
},
getArticle(slug) {
axios.get(`http://localhost:8000/api/articles/${this.slug}`)
.then(response => {
this.article = response.data;
this.setPageTitle(response.data.title);
this.content = window.content;
});
}
},
created() {
this.getArticle();
this.setRequestUser();
},
};
</script>
Now in the browser my text is rendered with template tags
<h3>The standard Lorem Ipsum passage, used since the 1500s</h3>
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
Anybody here who can point me in the right direction?
You need to use v-html attribute to render raw conent.
https://v2.vuejs.org/v2/guide/syntax.html

More than one time Tabbed Content with jQuery and CSS not working

Below the HTML and Jquery code that is not working. I want two tabbing section on a single page.
So, how can I modify it to make it work ?..
<div class="container">
<ul class="tabs">
<li class="tab-link current" data-tab="tab-1">Tab One</li>
<li class="tab-link" data-tab="tab-2">Tab Two</li>
<li class="tab-link" data-tab="tab-3">Tab Three</li>
<li class="tab-link" data-tab="tab-4">Tab Four</li>
</ul>
<div id="tab-1" class="tab-content current">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</div>
<div id="tab-2" class="tab-content">
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<div id="tab-3" class="tab-content">
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
</div>
<div id="tab-4" class="tab-content">
Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</div>
$(document).ready(function(){
$('ul.tabs li').click(function(){
var tab_id = $(this).attr('data-tab');
$('ul.tabs li').removeClass('current');
$('.tab-content').removeClass('current');
$(this).addClass('current');
$("#"+tab_id).addClass('current');
})
})

Apply Equalizer on Orbit slider in Foundation 6

I am trying to get all of the slides in my orbit slider to be the height of the largest slide.
Here is my markup:
$(document).ready(function(){
$('.orbit-container').equalize('outerHeight');
});
<div class="orbit" data-orbit="" role="region" data-auto-play="false" data-resize="7sdsk0-orbit" id="7sdsk0-orbit" data-t="3k1v70-t"><button class="orbit-previous" tabindex="0"><span class="show-for-sr">Previous Slide</span>◀︎</button><button class="orbit-next" tabindex="0"><span class="show-for-sr">Next Slide</span>▶︎</button><div class="orbit-wrapper">
<ul class="orbit-container" data-options="bullets: true; autoPlay:false;" data-auto-play="false" data-equalizer="" data-equalize-on-stack="true" data-equalize-by-row="true" data-resize="lo2q16-eq" data-mutate="k2tsn5-eq" data-t="fgxh6n-t" tabindex="0" style="height: 0px;" data-events="mutate">
<li data-equalizer-watch class="orbit-slide" data-slide="0">
<div>
<div class="text-container">
<h1>Arthritis. Give Before it takes.</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisi elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, nostrud</p>
Learn More
</div>
<div class="inner-overlay"> </div>
<img alt="" class="orbit-image desktop" src="/AS/media/AS/Homepage%20Billboards/billboard-tweaked.jpg?ext=.jpg">
<img alt="" class="orbit-image mobile" src="/AS/media/AS/Homepage%20Billboards/mobile-cropped.jpg?ext=.jpg">
</div>
</li>
<li data-equalizer-watch class="orbit-slide is-active" data-slide="1" aria-live="polite">
<div>
<div class="text-container">
<h1>Lorem ipsum dolor sit amet</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisi elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, nostrud</p>
Learn More
</div>
<div class="inner-overlay"> </div>
<img alt="" class="orbit-image desktop" src="/AS/media/AS/Homepage%20Billboards/billboard-tweaked.jpg?ext=.jpg">
<img alt="" class="orbit-image mobile" src="/AS/media/AS/Test%20Images/rough-mobile.jpg?ext=.jpg">
</div>
</li>
</ul>
</div>
On each li, an inline style is being applied of height="auto", so the slides are different heights. Even if I call that function after the window has loaded, it has the same effect.
Am I missing something?

Regular expression to select group of text/bunch of lines based on specific line of text

I have the text in below format
Scenario: Lorem ipsum dolor sit amet, consectetur adipiscing elit
Given sed do eiusmod tempor
When Ut enim ad minim veniam, quis nostrud exercitation
Then In voluptate velit esse cillum dolore eu fugiat nulla
#Sprint4 #543fsdf
Scenario: Lorem ipsum dolor sit amet, consectetur adipiscing elit
Given sed do eiusmod tempor incididunt ut labore et dolore magna aliqua
When Ut enim ad minim veniam, quis nostrud exercitation
Then In voluptate velit esse cillum dolore eu fugiat nulla
#Sprint1 #345277
Scenario: Sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt returned correct singular message
Given sed do eiusmod tempor incididunt ut labore et dolore magna aliqua
And Duis aute irure dolor in reprehenderit
When Ut enim ad minim veniam, quis nostrud
Then quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur
#Sprint1 #xyz1234
Scenario: At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis
Given sed do eiusmod tempor incididunt ut labore et dolore magna aliqua
And Duis aute irure dolor in reprehenderit
When Ut enim ad minim veniam, quis nostrud
Then quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur
I want to select whole scenario based on a line of text in it.
For eg.
based on the line 'Given sed do eiusmod tempor incididunt ut labore et dolore magna aliqua'
I want the second scenario
Scenario: Lorem ipsum dolor sit amet, consectetur adipiscing elit
Given sed do eiusmod tempor incididunt ut labore et dolore magna aliqua
When Ut enim ad minim veniam, quis nostrud exercitation
Then In voluptate velit esse cillum dolore eu fugiat nulla
, also the third and fourth scenario - but not the first one
I am trying
Scenario[\s\S]*?Given sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua[\s\S]*?(?=(#|Scenario))
But that gives me first and second scenarios together and third but no fourth scenario. I tried other patterns as well but not a lot of success. Help?
Given that your Scenario always begin on a new line, you can use look-behind to search for that, and you can use look-aheat to search for whitespace followed by # or end of the string to capture the end of a matched block. So, for your example:
(?<=\s)Scenario.*?[\r\n]+Given sed do eiusmod tempor incididunt ut labore et dolore magna aliqua[\r\n]+.*?(?=\s+#|\s*$)
You didn't specify what language are you using so you'll have to do the set up, but from options (if not default) you need to choose that dot matches line breaks, and that ^ and $ don't match line breaks but rather the whole string.
I don't know if will help, but what I did was to match all lines with # until the end of line. So you could replace that by null, if this is the case.
(#\V+)
https://regex101.com/r/iCt1j2/1

match line break except line begin with spcific word or blank line

If I have text that the line breaks is broken:
Chapter 1
Lorem ipsum dolor sit amet, consectetur adipisci
ng elit, sed do eiusmod tempor incididunt ut la
bore et dolore magna aliqua. Ut enim ad minim ve
niam, quis nostrud exercitation ullamco labo ris
nisi ut aliquip ex ea commodo consequat.
Chapter 2
Lorem ipsum dolor sit amet, consectetur adipisci
ng elit, sed do eiusmod tempor incididunt ut la
bore et dolore magna aliqua. Ut enim ad minim ve
niam, quis nostrud exercitation ullamco labo ris
nisi ut aliquip ex ea commodo consequat.
Lorem ipsum dolor sit amet, consectetur adipisci
ng elit, sed do eiusmod tempor incididunt ut la
bore et dolore magna aliqua. Ut enim ad minim ve
niam, quis nostrud exercitation ullamco labo ris
nisi ut aliquip ex ea commodo consequat.
...
I want to restore the text by remove non necessary line breaks except the chapter line like this:
Chapter 1
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco labo risnisi ut aliquip ex ea commodo consequat.
Chapter 2
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco labo risnisi ut aliquip ex ea commodo consequat.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco labo risnisi ut aliquip ex ea commodo consequat.
...
I have try to match (?<!Chapter\s\d)\n and replace it with '' in notepad++, but it matches the Chapter lines (Why?). (?<!Chapter\s\d)\n\r or (?<!Chapter\s\d)\r\n also not working. So what regex can remove redundant line breaks?
Try this regex:
(?<=[a-zA-Z])(\n)
I used parentheses to capture the newline character.
https://regex101.com/r/zS9pB4/3