How can I integrate fitVids.js into a .load function? - ajax

I'm new to jquery and I need to integrate a bit of code and I'm calling it from an external html file with the .load() function. That part of code it's a .div containing a video and a description. All I need to do is to make fitVids work on the code loaded from the external file.
This is the html loaded in the div.featured-container:
<div class="featured-container">
<div class="container player clearfix">
<div class="span8 video-container">
<iframe width="600" height="338" src="http://www.youtube.com/embed/QkhqI49QeaM?rel=0" frameborder="0" allowfullscreen></iframe>
</div>
<div class="span4 featured-content">
<div class="feat-meta">May 8, 2010 at 16:50 / by Silviu Stefu</div>
<h2>Retiner - Mobile UI Kit</h2>
<p>
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. Duis aute irure dolor in reprehenderit in voluptate velit esse.
</p>
<a class="button-normal" href="">Read More...</a>
</div>
</div>
</div>
And here is the JS:
//load the first list item link
var firstLoad = $('.thumbnails li:nth-child(2) a').attr('href')+' .player';
$('.featured-container').load(firstLoad,'',showTheContent());
function showTheContent() {
$('.player').fitVids().fadeIn('slow');
}
//load the links on click
$('.thumbnails li a').click(function(){
var toLoad = $(this).attr('href')+' .player';
$('.player').fadeOut('slow',loadContent);
$('#load').remove();
$('#load').fadeIn('normal');
function loadContent() {
$('.featured-container').load(toLoad,'',showNewContent());
}
function showNewContent() {
$('.player').fadeIn('slow',hideLoader());
}
function hideLoader() {
$('#load').fadeOut('normal');
}
return false;
});
So, where I should put the .fitVids() function to make the fideo fluid?

I would use the success function for this, so that if its loaded run the code.
$("#success").load("file.html", function(response, status, xhr) {
if (status == "succes") {
// your code
}
});

Related

CoreUI vue.js template in Laravel not working correctly

My problem is, that coreui in laravel does render the components, but none of them are interactive. For example when I use Tabs (CTabs), then it gets displayed correctly, but I cannot switch the tabs.
This is how I load coreui and the components:
import CoreuiVue from '#coreui/vue';
Vue.use(CoreuiVue);
// Registering a single component
import { CSwitch, CButton, CTabs, CTab, CCarousel, CCarouselItem } from '#coreui/vue';
Vue.component('CTabs', CTabs)
Vue.component('CTab', CTab)
Vue.component('CCarousel', CCarousel)
Vue.component('CCarouselItem', CCarouselItem)
// globally
Vue.directive('c-emit-root-event', CEmitRootEvent)
export default {
components: {
CTabs, CTab, CCarousel, CCarouselItem
},
directives: {
'c-tooltip': CTooltip
},
}
Vue.component(
'example-component',
require('./components/ExampleComponent.vue').default
);
const app = new Vue({
el: '#my-app',
data(){
}
});
Then the ExampleComponent.vue
<template>
<div>
<CTabs variant="pills" :active-tab="0">
<CTab title="Home">
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. 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.
</CTab>
<CTab title="Profile">
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. 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.
</CTab>
<CTab title="Disabled" >
Text will not be shown.
</CTab>
</CTabs>
<CCarousel
arrows
indicators
animate
height="450px"
>
<CCarouselItem
captionHeader="First Slide"
image="https://picsum.photos/1024/480/?image=52"
captionText="Nulla vitae elit libero, a pharetra augue mollis interdum."
/>
<CCarouselItem
captionHeader="Blank page"
:image="{ placeholderColor: 'grey' }"
captionText="Nulla vitae elit libero, a pharetra augue mollis interdum."
/>
<CCarouselItem
image="https://picsum.photos/1024/480/?image=54"
/>
</CCarousel>
</div>
</template>
<script>
module.exports = {
data: function () {
return {
message : 'Hello Vue!!'
}
},
name: 'example-component'
}
</script>
and the view file
<div id="my-app">
<example-component></example-component>
</div>
Any ideas?
I simply had to wrap the Vue Object into DOMContentLoaded to make sure that the DOM is ready before attaching vue.js.
document.addEventListener("DOMContentLoaded", function(event) {
const app = new Vue({
el: '#my-app',
data(){
}
});
})

Error message cannot use URL in swift 3 swift file

I created a swift file using a class called Course . Everything works in my code except when I try to input the URL. I get an error Message.
Here's is my sample code
URL(String:"https://www.youtube.com/watch?v=QBULK-w-i90")!
I keep getting error
Argument labels '(String)' do not match any available overloads
I'm not sure what that means and how can I fix this problem .
here is the code written out I follow video but keep getting errors.
import UIKit
class CourseStore
{
class func downloadNewCourses()-> [Course]
{
var courses = [Course]()
let chefCourse = Course(buttonImage: #imageLiteral(resourceName: "cover_chef"),
title: "Become a Pro Chef",
instructor: "Gordon Ramsay",
featuredImage: #imageLiteral(resourceName: "chef"),
introductionVideoUrl: URL(String:"https://www.youtube.com/watch?v=QBULK-w-i90")!,
introductionVideoUrl: ,
description: "Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, 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. Nam liber te conscient to factor tum poen legum odioque civiuda."
)
return courses
}
}
Argument labels '(String)' do not match any available overloads
Means that URL doesn't have constructor which has those parameters. In your case you named parameter String but it should be lowercased string.
Instead use
URL(string: "https://www.youtube.com/watch?v=QBULK-w-i90")!

Java 8 stream emitting a stream

I have the following file format:
Text1
+ continuation of Text1
+ more continuation of Text1
Text2
+ continuation of Text2
+ more continuation of Text2
+ even more continuation of Text2
Continuations are marked by \n+. (Newline, plus character, space as a three character string.) Continuations can be any number of lines, including 0.
I want the following output (each is a line printed with .forEach):
Text1 continuation of Text1 more continuation of Text1
Text2 continuation of Text2 more continuation of Text2 even more continuation of Text2
I would like to use only Java streams to do the conversion, preferably with Collect. Is there a way to do this elegantly?
EDIT:
Another, more realistic example:
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.
Expected result is two lines:
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.
In Java 9, you could use
static final Pattern LINE_WITH_CONTINUATION = Pattern.compile("(\\V|\\R\\+)+");
…
try(Scanner s = new Scanner(file)) {
s.findAll(LINE_WITH_CONTINUATION)
.map(m -> m.group().replaceAll("\\R\\+", ""))
.forEach(System.out::println);
}
Since Java 8 lacks the Scanner.findAll(Pattern) method, you may add a custom implementation of the operation as a work-around
public static Stream<MatchResult> findAll(Scanner s, Pattern pattern) {
return StreamSupport.stream(new Spliterators.AbstractSpliterator<MatchResult>(
1000, Spliterator.ORDERED|Spliterator.NONNULL) {
public boolean tryAdvance(Consumer<? super MatchResult> action) {
if(s.findWithinHorizon(pattern, 0)!=null) {
action.accept(s.match());
return true;
}
else return false;
}
}, false);
}
which can be used like
try(Scanner s = new Scanner(file)) {
findAll(s, LINE_WITH_CONTINUATION)
.map(m -> m.group().replaceAll("\\R\\+", ""))
.forEach(System.out::println);
}
which will make the future migration easy.
Assuming that you run this sequentially only and really want to use streams:
List<String> result = Files.lines(Paths.get("YourPath"))
.collect(() -> new ArrayList<>(), (list, line) -> {
int listSize = list.size();
if (line.startsWith("+ ")) {
list.set(listSize - 1, list.get(listSize - 1) + line.substring(2));
} else {
list.add(line);
}
}, (left, right) -> {
throw new RuntimeException("Not for parallel processing");
});

Linq search - Display small part of searched text

I'm trying to implement text search with linq. I have a Messages table which is populated with emails data. I want to be able to search in Messages body. However emails bodies are very long and I will like to display only small part of the searched text for example if I search for:
aute
in the following text:
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. 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.
the result should be:
...aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur....
Thanks
Something like this should do the job:
var query = from str in messages
let index = str.IndexOf(search)
where index > -1
select str.Substring(Math.Max(0, index - radius), radius + Math.Min(radius, str.Length - index));
Where messages is your email string list, and radius is an int describing how many characters you want to take before and after the string you are looking for. Note that this code will only return the first match in every email, ignoring the other ones.
Everything would be easier if you could use an helper function to calculate the proper substring tho.
Here you can find an extension method that implements a safe version of string.substring, making hte above linq code look something like:
var query = from str in lst
let index = str.IndexOf(search)
where index > -1
select str.SafeSubstring(index - radius, 2*radius);
that in my opinion is much simnpler to read
EDIT
Extending string with the two following methods :
public static List<int> IndexOfAll(this String str, string search)
{
List<int> lst = new List<int>();
foreach (Match match in Regex.Matches(str,search))
{
lst.Add(match.Index);
}
return lst;
}
public static string SafeSubstring(this String str, int start, int n)
{
return str.Substring(Math.Max(start, 0), Math.Min(n, str.Length - start));
}
you can get all the results in a nice form, using
var query = from str in lst
let index = str.IndexOfAll(search)
where index.Count>0
select index.Select(x => str.SafeSubstring(x-radius, 2*radius));
with query as an IEnumerable

Prototype selection of elements

I am trying to update the text inside a div. But when I use the below types of selections I get null.
my.class = Class.create(
{
initialize:function(container){
this._popup = new Element("div",{"id":"tm-popup"});
var innerEl = "<div class='content'><div></div></div>";
this._popup.insert(innerEl);
container.insert({bottom:this._popup});
},
show:function(){
var tempText = "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.";
console.log("div = ", this._popup.select('content') );
console.log("div = ", $('#tm-popup').select('.content') );
$('#tm-popup').select('.content').update( tempText );
}
});
I have tried 3 ways to try and get the div to update its text but all 3 fail.
I want to stay away from $$ as a selector as I have a huge DOM tree and don't want to run through everything with the $$
If I do a log on this._popup in the show method it does trace out the object so I know its there.
For anyone who might run into this issue here is an answer.
$(this._popup).down('.content').update(tempText);

Resources