I am using swiper.js and fancybox v3 to create a popup gallery. One of the slide contain a video, however after I have click and open popup, the video will load and start playing whatever which slide I landed. I have tried to use any events to stop pause the video but it still can't work. Anyone got a solutions?
Here is a codepen example:
$(document).ready(function () {
var mySwiper = new Swiper('.swiper-container', {
init: false,
pagination: {
el: '.swiper-pagination',
observer: true,
observeParents: true,
on: {
slideChangeTransitionStart: function () {
$('.swiper-slide').find('video').each(function () {
console.log(this);
this.pause();
});
},
slideChangeTransitionEnd: function () {
$('.swiper-slide').find('video').each(function () {
this.pause();
});
}
}
},
})
$('.fancybox-trigger').click(function (e) {
e.preventDefault();
var thisTarget = $(this).data('index');
$.fancybox.open({
src: "#lightbox",
type: 'inline',
opts: {
toolbar: false,
defaultType: 'inline',
autoFocus: true,
touch: false,
afterLoad: function () {
mySwiper.init();
mySwiper.slideTo(thisTarget - 1)
$('swiper-slide').find('video').each(function () {
this.pause();
})
}
}
})
})
});
https://codepen.io/anon/pen/mKOwag?editors=0010
I am not swiper expert, therefore I can not explain why, but I found that callbacks work if you add them like this:
mySwiper.on('slideChange', function() {
$('.swiper-slide').find('video').each(function() {
this.pause();
});
});
Demo - https://codepen.io/anon/pen/ERNogR
Related
Can we show adMob ads for particular DIV in Android application?
If possible, Can you tell me how to implement?
install this plugin cordova plugin add https://github.com/floatinghotpot/cordova-plugin-admob.git
and past bellow code inside your controller
$(function () {
// alert('1');
if ((/(ipad|iphone|ipod|android|windows phone)/i.test(navigator.userAgent))) {
document.addEventListener('deviceready', initApp, false);
} else {
initApp()
// alert('2');
}
})
function initApp() {
// alert('3');
initAd()
// display the banner at startup
window.plugins.AdMob.createBannerView();
}
function initAd() {
// alert('4');
if (window.plugins && window.plugins.AdMob) {
var ad_units = {
ios: {
banner: 'ca-app-pub-6869992474017983/4806197152',
interstitial: 'ca-app-pub-6869992474017983/7563979554'
},
android: {
banner: 'ca-app-pub-6869992474017983/9375997553',
interstitial: 'ca-app-pub-6869992474017983/1657046752'
},
wp8: {
banner: 'ca-app-pub-6869992474017983/8878394753',
interstitial: 'ca-app-pub-6869992474017983/1355127956'
}
};
var admobid = "";
if (/(android)/i.test(navigator.userAgent)) {
admobid = ad_units.android;
} else if (/(iphone|ipad)/i.test(navigator.userAgent)) {
admobid = ad_units.ios;
} else {
admobid = ad_units.wp8;
}
window.plugins.AdMob.setOptions({
publisherId: admobid.banner,
interstitialAdId: admobid.interstitial,
bannerAtTop: false, // set to true, to put banner at top
overlap: false, // set to true, to allow banner overlap webview
offsetTopBar: false, // set to true to avoid ios7 status bar overlap
isTesting: true, // receiving test ad
autoShow: true // auto show interstitial ad when loaded
});
// alert('5');
registerAdEvents()
} else {
// alert( 'admob plugin not ready' );
}
}
// optional, in case respond to events
function registerAdEvents() {
document.addEventListener('onReceiveAd', function() {});
document.addEventListener('onFailedToReceiveAd', function(data) {});
document.addEventListener('onPresentAd', function() {});
document.addEventListener('onDismissAd', function() {});
document.addEventListener('onLeaveToAd', function() {});
document.addEventListener('onReceiveInterstitialAd', function() {});
document.addEventListener('onPresentInterstitialAd', function() {});
document.addEventListener('onDismissInterstitialAd', function() {});
// alert('6');
}
function onResize() {
// alert('7');
var msg = 'web view: ' + window.innerWidth + ' x ' + window.innerHeight;
document.getElementById('sizeinfo').innerHTML = msg;
}
// ADMob
})
I have used Alloy UI Modal window. The code is:
YUI().use(
'aui-modal',
function(Y) {
var modal = new Y.Modal(
{
bodyContent:'test',
centered: true,
headerContent:headerContent,
modal: true,
render: '#testModal',
width: 631,
id:'modalSource',
destroyOnHide:true
}
).render();
modal.addToolbar(
[{
label: 'Add',
on: {
click: function() {
addData();
//modal.hide() works here but i need to close it inside addData..
}
}
},
{
label: 'Cancel',
on: {
click: function() {
modal.hide();
}
}
}
]
);
}
);
The function addData is in a different js file and makes an Ajax call, so I need to pass id of modal window and close it after success callback . Do you have any idea on how to get id of modal window and use modal.hide over there. Thank you
function addData()
{
$('#modalSource').hide();
}
After going through some AUI tutorials, managed to solve it..Just pass an instance of modal window into addData function and then call hide() method.
modal.addToolbar(
[{
label: 'Add',
on: {
click: function() {
addData(modal);
}
}
},
function addData(modalInstance)
{
//do needed stuff
modalInstance.hide();
}
I have a slide-box described in one of my protractor tests; I can find the box and can get properties (i.e. 'how many') but how do I cycle through the boxes so I can test verify the display, e.g.
profilepage.slides.next()
expect(profilepage.slide.slideTitle = 'Credentials'
profilepage.slides.next()
expect(profilepage.slide.slideTitle = "Info"
etc.
Controller:
.controller('ProfileCtrl', function ($scope, ProfileService) {
$scope.data = {
numViewableSlides: 0,
slideIndex: 0,
initialInstruction: true,
secondInstruction: false, slides: [
{
'template': 'templates/slidebox/credentials.html',
'viewable': true
},
{
'template': 'templates/slidebox/contactinfo.html',
'viewable': true
},
{
'template': 'templates/slidebox/employeeinfo.html',
'viewable': true
},
{
'template': 'templates/slidebox/assignmentinfo.html',
'viewable': true
}
]
}
. . .
Template:
<ion-slide-box on-slide-changed="slideChanged(index)" show-pager="true">
<ion-slide ng-repeat="slide in data.slides | filter:{viewable : true}">
<div ng-include src="slide.template"></div>
</ion-slide>
</ion-slide-box>
Page Object:
profilepage.prototype = Object.create({}, {
backButton: {
get: function () {
return element(by.css('ion-ios7-arrow-back'));
}
},
slides: {
get: function () {
return element.all(by.repeater('slide in data.slides'));
}
},
slideTitle: {
get: function (id) {
element.all(by.repeater('slide in data.slides')).then(function (slidelist) {
var titleElement = slidelist[id].element(by.css('#slideName'));
return titleElement.getText();
});
}
},
. . .
Spec:
describe('Profile', function () {
var ppage = new profilepage();
beforeEach(function () {
browser.ignoreSynchronization = false;
});
it('should have correct lastname and have four slides on profile page', function () {
expect(browser.getCurrentUrl()).toEqual('http://localhost:8100/#/profile');
expect(ppage.lastname).toBe('Smith,');
expect(ppage.slides.count()).toEqual(4);
browser.sleep(1000);
});
it('should slide all the pages', function(){
expect(browser.getCurrentUrl()).toEqual('http://localhost:8100/#/profile');
// SLIDE EACH PAGE ABOUT HERE <------------
browser.sleep(1000);
})
The idea is to use ionic's $ionicSlideBoxDelegate from within the spec file. For that we'll need to make it accessible globally:
var addProtractorSlideBox, nextSlide;
addProtractorSlideBox = function() {
return browser.addMockModule("services", function() {
return angular.module("services").run(function($ionicSlideBoxDelegate) {
return window._$ionicSlideBoxDelegate = $ionicSlideBoxDelegate;
});
});
};
nextSlide = function() {
return browser.executeScript('_$ionicSlideBoxDelegate.next()');
};
...
beforeEach(function() {
...
addProtractorSlideBox();
...
});
it('...', function() {
...
nextSlide();
...
})
This pattern is very useful for other ionic/angular services.
I'm a newbie of javascript, trying to build an interactive map online, where some events should be triggered by clicking on markers and some just by hovering them.
Managed to have the click part working, but, because of Markercluster plugin, I'm not sure where to use onEachFeature function for having the tooltip opened by hover a single marker.
Anyone please can tell me what I'm doing wrong?
var geoJsonFeature = {
type: 'FeatureCollection',
features:
[
{
type: 'Feature',
properties: {
title: 'Title',
page: 'some.html',
'marker-color': '#000000',
zoom: 7
},
geometry: {
type: 'Point',
coordinates: [12.583745,55.6750803]
}
},
...
};
// access to mapbox api
L.mapbox.accessToken ='...';
var map = L.mapbox.map('map', 'example1234').setView([34, -37], 3);
function getTitle(marker) {
return marker.feature.properties.title;
};
function getPage(marker) {
return marker.feature.properties.page;
};
var markerGroup = new L.MarkerClusterGroup({showCoverageOnHover:false});
var geoJsonLayer = L.geoJson(geoJsonFeature, {
onEachFeature: function (feature, layer) {
var popupContent = getTitle(marker);
layer.bindPopup(popupContent);
}
});
markerGroup.addLayer(geoJsonLayer);
map.addLayer(markerGroup);
markerGroup.on('click', function(ev) {
var marker = ev.layer;
marker.on('click', function(ev) {
if(map.getZoom() > marker.feature.properties.zoom) {
map.setView(ev.latlng, map.getZoom());
}
else {
map.setView(ev.latlng, marker.feature.properties.zoom);
}
});
});
});
geoJsonLayer.on('mouseover', function(e) {
e.layer.openPopup();
});
geoJsonLayer.on('mouseout', function(e) {
e.layer.closePopup();
});
You need to use the onEachFeature option to get the individual markers and bind handlers to the mouseover and mouseout events:
onEachFeature: function (feature, layer) {
layer.bindPopup(feature.properties.title);
layer.on("mouseover", function () {
layer.openPopup();
});
layer.on("mouseout", function () {
layer.closePopup();
});
}
Here's a working example on Plunker: http://plnkr.co/edit/hfjOWv3uCBFawDGqR3Ue?p=preview
Note: i'm not using ClusterMarker in this example but it should work just fine when using ClusterMarker
I am currently having problem in using the jQuery API for
TextboxList
what i want is that to access the selected value in the Json array form, now the documentation suggest to use:
$('#form_tags_input').textboxlist();
but when i use it in the jQuery function on button click to get values using [getValues]
method it said undefined.
here is the javascript:
<script type="text/javascript">
$(function () {
// Standard initialization
var t = new $.TextboxList('#SentTo', { unique: true, plugins: { autocomplete: { minlength: 2, onlyFromValues: true}} });
//t.addEvent('bitBoxAdd', ContactAdded);
//t.addEvent('bitBoxRemove', ContactRemoved);
t.getContainer().addClass('textboxlist-loading');
$.ajax({
url: '/Home/GetContacts',
dataType: 'json',
success: function (r) {
t.plugins['autocomplete'].setValues(r);
t.getContainer().removeClass('textboxlist-loading');
}
});
});
function GetValues() {
var tblist = $('#SentTo').textboxlist();
alert(tblist.getValues());
return false;
}
function ContactAdded(e) {
//alert(e);
//GetValues();
return false;
}
function ContactRemoved(e) {
//alert(e);
}
i am using GetValues() function on button click to getvalues.
A help would be much appreciated.
Thanks.
Try to made TextboxLists "t" variable global
The changed code is:
$(function () {
// Standard initialization
t = new $.TextboxList('#SentTo', { unique: true, plugins: { autocomplete: { minlength: 2, onlyFromValues: true}} });
//t.addEvent('bitBoxAdd', ContactAdded);
//t.addEvent('bitBoxRemove', ContactRemoved);
t.getContainer().addClass('textboxlist-loading');
$.ajax({
url: '/Home/GetContacts',
dataType: 'json',
success: function (r) {
t.plugins['autocomplete'].setValues(r);
t.getContainer().removeClass('textboxlist-loading');
}
});
});
function GetValues() {
alert(t.getValues());
return false;
}