FullCalendar's dayClick not firing when a date is tapped - angularjs

What I'm trying to do. Tap a day in the calendar and have show the details of that day's events in the area below it.
How I'm doing it. With Angular and the ui-calendar directive. In FullCalendar's dayClick event, I'm creating a new set of events that are happening on that day. In the template, I'm doing a typical ng-repeat="event in daysEvents" div. This works perfectly fine when I'm testing it in ionic serve.
The problem. The dayClick event doesn't work in the iOS emulator, when I send the app to my device (with ionic run ios) or Chrome Developer Tools "Toggle device mode".
The code. Here's my controller:
angular.module('starter.controllers', ['ui.calendar'])
.controller('CalendarCtrl', function($scope) {
$scope.eventSources = [
{
title: "Spring Awards Night",
start: moment("2015-5-19 18:30"),
description: "The Spring Awards are awesome and you should come."
}
]
$scope.uiConfig = {
calendar:{
height: 'auto',
editable: false,
header:{
left: 'prev',
center: 'title',
right: 'next'
},
dayClick: function(date, jsEvent, view) {
$scope.daysEvents = $scope.eventSources.filter(function(event){
return event.start.isBetween(date, moment(date).add(1, 'days'));
});
$(".fc-day").removeClass("fc-selected");
$(this).addClass("fc-selected");
}
}
};
And part of my template:
<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>
If you need anything else, let me know. Thanks in advance.

1st solution:
This happens only when using UI-Calendar (FullCalendar) with Ionic, because Ionic catches all tap events. That's why it works fine for you in a desktop browser, but not in a mobile browser.
To solve this issue, add data-tap-disabled="true" to UI-Calendar directive, like this:
<div data-tap-disabled="true" ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>
UPD - 2nd solution:
By disabling the Ionic tap listeners, you'll face the default browser's 300ms delays after each tap is made, which leads to an extremely poor user experience.
So, another solution for your question would be to select dates programmatically.
function onViewRender( view, element ){
// 1. Add tap listeners for each day (in my case - the date number element)
var matches = document.querySelectorAll(".fc-day-number");
_.forEach(matches, function(element){
$ionicGesture.on('tap', function (event) {
// 2. On tap - parse data-date attribute from the element
var selectedDateStr = $(event.target).attr('data-date');
// 3. And select an according day with uiCalendarConfig select method
uiCalendarConfig.calendars.mobileCal.fullCalendar('select', moment(selectedDateStr), moment(selectedDateStr).add(24,'h'));
}, angular.element(element));
});
}

In FullCalendar, if you drag on the day then the dayclick event is fired.
Other devices fire the dragstart and dragend events when you tap on the day, but iOS devices don't.
I had no choice but to modify fullcalendar.js. You can see my modified version here:
angularui-calendar-fullcalendar-dayclick-not-work-expectedly-on-ios

Related

Don't show side menu on drag ionic

I have a calendar element on my ionic app. When user swipe left or right on it, it goes to a different month. One problem/challenge is that when I swipe to the right the side bar is showing.
I did use drag-content="false" and that disabled the swipe menu function everywhere but I want it only on that calendar element.
I found this Stackoverflow post with a answer but I did not understand how it worked because I can't find any difference between the content elements. In that post they also included a codepen link to an answer CODEPEN
UPDATE:
Here a link to the calendar plugin
Maybe you could bind drag-content directive to a scope variable (boolean) and then change its value when mouse is over the calendar component:
<ion-side-menu-content drag-content="drag">
So register the listeners for mouseover/mouseleave events on calendar:
<flex-calendar on-touch="mouseoverCalendar()" on-release="mouseleaveCalendar()" drag-content="toggledrag" options="options" events="events"></flex-calendar>
and insert in your controller:
$scope.drag = true;
$scope.mouseoverCalendar = function() {
$scope.drag = false;
};
$scope.mouseleaveCalendar = function() {
$scope.drag = true;
};
Here is an example using Flex Calendar: http://codepen.io/beaver71/pen/bEmaJZ
Put this into the controller of your calendar-view and it will the menu as you enter the calendar and re-enable it as you leave the view:
$scope.$on('$ionicView.enter', function(){
$ionicSideMenuDelegate.canDragContent(false);
});
$scope.$on('$ionicView.leave', function(){
$ionicSideMenuDelegate.canDragContent(true);
});
Answer from this post

ng-click on firing on mobile or tablet devices

On page load i have a controller that calls a service and then binds the returned data to some $scope.objects:
app.controller("MainController", function($scope, $http, serviceGetData) {
serviceGetData.getData(function(data) {
$scope.LoginCount = data.LoginCount;
$scope.ProductInfo = data.ProductInfo;
$scope.ProfileInfo = data.ProfileInfo;
// Delayed binding
$scope.OrderHistory = { History: [] };
}
$scope.populateModel = function(model, values) {
var isArray = $.isArray(values);
$.each(values, function(key, value) {
if (isArray) {
key = this.key;
value = this.value;
}
if (model[key] !== value) {
model[key] = value;
}
});
};
}
And in my HTML, i try to bind $scope.OrderHistory by:
<h1><a href="#" ng-click="populateModel(OrderHistory , { History: OrderEntries })" >View order details</a></h1>
This is fine when viewing on laptops/desktops, but not working in tablet and mobile devices e.g. iphone/ipad
Try to add the ngTouch. From documentation:
A more powerful replacement for the default ngClick designed to be used on touchscreen devices. Most mobile browsers wait about 300ms after a tap-and-release before sending the click event. This version handles them immediately, and then prevents the following click event from propagating.
Requires the ngTouch module to be installed.
I had the same problem.
I tried adding the ngTouch library and dependency, but was still having a problem.
My static <div> elements which contained an ng-click worked fine, but the div's which were created dynamically (in an ng-repeat on the same webpage) which contained an ng-click didn't work. Tapping on them just didn't do anything.
This happened on my iPhone 6, my iPad and in Google Chrome when I asked to view my webpage on any of the device types. When I viewed the same webpage in IE or regular Chrome, all of the ng-clicks worked fine.
The solution was to use the ngMobileClick directive described here and changing my ng-click's to ng-mobile-click.
After doing that, my dynamically created click events did get triggered normally when I tapped on them on a device.
Very odd.
Had a similar issue where the ng-click inside of a ng-repeat would not trigger.
I fixed this by adding $event.stopPropagation()
Ex:
<li ng-repeat="option in $scope.options">
<span><a ng-click="trigger(); $event.stopPropagation()"></a></span>
</li>

BackboneJS - Magnific popup not firing youtube video

I want to show youtube videos in the Magnific popup http://dimsemenov.com/plugins/magnific-popup/. The URl for the youtube video I get from a JSON file which I insert in my HTML with HandlebarsJS. So far so good, when I check the <a href> with the webinspector, the correct link is available.
Somehow though, when I click on it, the Magnific popup opens, but the youtube video is not firing, instead I get an error message. It seems like as soon the popup opens, or rather, when Magnific popup gets triggered, it completely disattaches itself from my BackboneJS App. Can this be true?
In my HTML (video.html) I have:
<a class="vidPopup" href="youtubelink here">
and in the Backbone View i created event:
template: 'video', //referring to the video.html
events: {
'click .vidPopup': 'seeVid'
},
seeVid: function(e) {
e.preventDefault();
$('.vidPopup').magnificPopup({
disableOn: 700,
type: 'iframe',
mainClass: 'mfp-fade',
removalDelay: 160,
preloader: false,
fixedContentPos: false
});
}
What could be the issue here?
I solved it myself! Since the Youtube API returns the ID of the youtube video I just had to do this:
<a class="vidPopup" href="https://www.youtube.com/watch?v={{id}}">
I didnt have to change the popup settings

Bootstrap 3 Popover in Angular-UI Calendar

I'm using Angular-UI Calendar directive and Bootstrap 3 popover to attempt to create a popover on click. I tried using the day click event:
$scope.dayClick = function(event, allDay, jsEvent, view){
jsEvent.stopPropagation();
jsEvent.preventDefault();
var eventID = event.getDate();
eventID = jsEvent.target;
$(eventID).popover({
html: true,
title: 'Hello',
placement: 'bottom',
content: '<button id="close-me">Close Me!</button>'
}).parent().delegate('button#close-me', 'click', function() {
jsEvent.stopPropagation();
$(eventID).popover('hide');
return false;
});
$(eventID).popover('show');
};
The problem with this way is that it causes the calendar cells to push to the right at times or duplicate. Is there a better way I could attach the popover to the existing calendar?
Are you trying to create pop-over when any day is clicked?
If yes, then dayClick is the correct way for a popover.
Can you create a Plunk to provide more details.
I think the problem may be due to CSS.

BackboneJS Magnific Popup URL's

Is there a way to display a thumbnail of a youtube video in a BackboneJS view, then after clicking the thumbnail a lightbox opens and plays the video and at the same time the URL changes, so that you actually can send the URL-link?
I have a Backbone App where I list multiple Artists and when you click on one of those you get to an artist specific page where the user among other things can watch videos. So lets say you are on Lady Gaga's page and i click on a video, the Magnific Popup-opens with the video. But what I want to achieve i that the URL changes as well. something like ladygaga/videos/titleofvideo(or youtubelink):
Right now, in my Backbone View I have:
events: {
'click .video' : 'popUp'
},
popUp: function (e) {
e.preventDefault();
$('.video').magnificPopup({
disableOn: 700,
type: 'iframe',
mainClass: 'mfp-fade',
removalDelay: 160,
preloader: false,
fixedContentPos: false
});
}
The popup works fine, I just need the URL to change... Does anyone have an idea how to add this here if it is possible?
Thanks in advance...

Resources