Fullcalendar Scheduler Grab and drag horizontal - fullcalendar

I'm trying to grab and drag the scroller canvas horizontally. I can scroll left & right with my mouse (Apple Magic Mouse), but have not been able to figure out how to implement the grab and drag left & right.
I tried to follow the instructions on the link below, but the pageX & clientX seems to cancel out bringing me straight to the beginning.
$('.fc-scroller-canvas').on('mousedown', function(e) {
console.log('pageX:::', e.pageX)
$('.fc-scroller-canvas').on('mousemove', function(evt) {
console.log('clientX:::', evt.clientX)
$('.fc-scroller').stop(false, true).animate({
scrollLeft: e.pageX - evt.clientX
});
});
});
$('.fc-scroller-canvas').on('mouseup', function() {
$('.fc-scroller-canvas').off('mousemove');
});
jQuery Grab Content and Scroll page horizontally
Any clue? Can someone help?

Thanks #hman! Code worked like a charm!
I've made some modifications to mine so the scrolling activated when clicking and dragging on the .fc-time
let pageX_Drag, pageY_Drag;
let disableDragSelector = '.fc-event,.some-other-class-here-maybe';
$('.fc-time-area').on('mousedown', '.fc-scroller', function (e) {
// prevent drag from happening if we click on certain things
let dragDisabledElms = $(e.target).parents(disableDragSelector).addBack(disableDragSelector);
if (dragDisabledElms.length) return;
pageX_Drag = e.pageX;
pageY_Drag = e.pageY;
$(window).off("mousemove", __mouseMove_Drag);
$(window).on("mousemove", __mouseMove_Drag);
});
$(window).on('mouseup', __mouseUp_Drag);
function __mouseUp_Drag() {
$(window).off("mousemove", __mouseMove_Drag);
}
function __mouseMove_Drag(evt) {
let offsetX = pageX_Drag - evt.pageX;
let offsetY = pageY_Drag - evt.pageY;
$('.fc-scroller', '.fc-time-area').each(function () {
let scroller = $(this);
let newX = scroller.scrollLeft() + offsetX;
let newY = scroller.scrollTop() + offsetY;
scroller.scrollLeft(newX);
scroller.scrollTop(newY);
});
pageX_Drag = evt.pageX;
pageY_Drag = evt.pageY;
}

Here is what I did to allow panning around the calendar both vertically and horizontally. You should be able to easily modify it to only work horizontally if that's what you want. I've only tested this with timeline view but it should work with all of the views.
var pageX_Drag, pageY_Drag;
var disableDragSelector = '.fc-event,.some-other-class-here-maybe';
calendarElement.on('mousedown', '.fc-scroller', function (e)
{
// prevent drag from happening if we click on certain things
var dragDisabledElms = $(e.target).parents(disableDragSelector).addBack(disableDragSelector);
if (dragDisabledElms.length) return;
pageX_Drag = e.pageX;
pageY_Drag = e.pageY;
$(window).off("mousemove", __mouseMove_Drag);
$(window).on("mousemove", __mouseMove_Drag);
});
$(window).on('mouseup', __mouseUp_Drag);
function __mouseUp_Drag()
{
$(window).off("mousemove", __mouseMove_Drag);
}
function __mouseMove_Drag(evt)
{
var offsetX = pageX_Drag - evt.pageX;
var offsetY = pageY_Drag - evt.pageY;
$('.fc-scroller', calendarElement).each(function ()
{
var scroller = $(this);
var newX = scroller.scrollLeft() + offsetX;
var newY = scroller.scrollTop() + offsetY;
scroller.scrollLeft(newX);
scroller.scrollTop(newY);
});
pageX_Drag = evt.pageX;
pageY_Drag = evt.pageY;
}

Related

Google Maps draggable overlay on touch screen

I have added a custom draggable overlay onto a google map, which works well using a mouse, but doesn't work on touch screens.
The code I am using is from this question : Can we make custom overlays draggable on google maps V3
The code is from #Dr.Molle and shown below.
Is there anything I can do to make it work on a touch screen? The marker shows, but I cannot move it.
DraggableOverlay.prototype = new google.maps.OverlayView();
DraggableOverlay.prototype.onAdd = function () {
var container = document.createElement('div'),
that = this;
if (typeof this.get('content').nodeName !== 'undefined') {
container.appendChild(this.get('content'));
} else {
if (typeof this.get('content') === 'string') {
container.innerHTML = this.get('content');
} else {
return;
}
}
container.style.position = 'absolute';
container.draggable = true;
google.maps.event.addDomListener(this.get('map').getDiv(),
'mouseleave',
function () {
google.maps.event.trigger(container, 'mouseup');
}
);
google.maps.event.addDomListener(container,
'mousedown',
function (e) {
this.style.cursor = 'move';
that.map.set('draggable', false);
that.set('origin', e);
that.moveHandler =
google.maps.event.addDomListener(that.get('map').getDiv(),
'mousemove',
function (e) {
var origin = that.get('origin'),
left = origin.clientX - e.clientX,
top = origin.clientY - e.clientY,
pos = that.getProjection()
.fromLatLngToDivPixel(that.get('position')),
latLng = that.getProjection()
.fromDivPixelToLatLng(new google.maps.Point(pos.x - left,
pos.y - top));
that.set('origin', e);
that.set('position', latLng);
that.draw();
});
}
);
google.maps.event.addDomListener(container, 'mouseup', function () {
that.map.set('draggable', true);
this.style.cursor = 'default';
google.maps.event.removeListener(that.moveHandler);
});
this.set('container', container)
this.getPanes().floatPane.appendChild(container);
};
function DraggableOverlay(map, position, content) {
if (typeof draw === 'function') {
this.draw = draw;
}
this.setValues({
position: position,
container: null,
content: content,
map: map
});
}
DraggableOverlay.prototype.draw = function () {
var pos = this.getProjection().fromLatLngToDivPixel(this.get('position'));
this.get('container').style.left = pos.x + 'px';
this.get('container').style.top = pos.y + 'px';
};
DraggableOverlay.prototype.onRemove = function () {
this.get('container').parentNode.removeChild(this.get('container'));
this.set('container', null)
};
new DraggableOverlay(
map,//maps-instance
latLng,//google.maps.LatLng
'content',//HTML-String or DOMNode
function(){}//optional, function that ovverrides the draw-method
);

how to trigger the google map event from inside the overlayview

In a application, I am using google map to display stations with google marker, because the google marker is static with icon not animated, so I decided to inherit OverlayView and use canvas to draw a station dynamically. And this works, however, I want this overlay to receive the google events like the marker, such as click, mouse over, mouse out...
For example,
function StationCanvas(map, position, name) {
this.map_ = map;
this.position_ = position;
this.name_ = name;
this.canvas_ = null;
this.labelDiv_ = null;
this.canvasWidth_ = 12;
this.canvasHeight_ = 50;
this.setMap(map);
console.log('canvas '+this.position_);
}
StationCanvas.prototype = new google.maps.OverlayView();
StationCanvas.prototype.onAdd = function() {
var canvas = document.createElement("canvas");
canvas.setAttribute("width", this.canvasWidth_);
canvas.setAttribute("height", this.canvasHeight_);
canvas.style.position = "absolute";
this.canvas_ = canvas;
var panes = this.getPanes();
panes.floatPane.appendChild(canvas);
this.labelDiv_ = document.createElement("div");
this.labelDiv_ .setAttribute("width", this.canvasWidth_);
this.labelDiv_ .setAttribute("height", this.canvasHeight_);
this.labelDiv_ .style.position = "absolute";
this.labelDiv_ .innerHTML = this.name_;
panes.floatPane.appendChild(this.labelDiv_ );
/////////////////////////////////////////////////////////////
this.listeners_ = [
google.maps.event.addListener(this.canvas_, "mouseover", function (e) {
//this.style.cursor = "pointer";
//google.maps.event.trigger(this, "mouseover", e);
console.log('mouse mover');
}),
google.maps.event.addListener(this.canvas_, "mouseout", function (e) {
//this.style.cursor = this.getCursor();
//google.maps.event.trigger(this, "mouseout", e);
console.log('mouse out');
}),
google.maps.event.addListener(this.canvas_, "click", function (e) {
google.maps.event.trigger(this, "click", e);
console.log('click');
}),
google.maps.event.addListener(this.canvas_, "dblclick", function (e) {
//google.maps.event.trigger(this, "dblclick", e);
}),
];
}
Intially, I use google.maps.event.addListener as showed above to listen the event, nothing happens, so it seems canvas doesn't work with google.maps.eventListener.
Then I found google has provided a addDomListener(instance:Object, eventName:string, handler:Function), but since it only support dom rather then canvas, so when I used that listener, the browser breaks down.
At last, I have tried to use
canvas.onmouseout = function() {
console.log("on mouse out");
}
}
It is supposed to work, but still no, I guess something wrong within the code. even this works, the next question is how can I trigger the event to outside, so that I can work this overlayview like the google marker
var test1 = new StationCanvas(map, new google.maps.LatLng(53.3234,-2.9178), "abc",13);
google.maps.event.addListener(test1, 'click', function(event){
console.log('test 1 click');
});
addDomListener works for me, even with <canvas/>
What would break your code is e.g. this:
google.maps.event.addListener(this.canvas_, "click", function (e) {
google.maps.event.trigger(this, "click", e);
console.log('click');
})
this , when used in a event-callback, refers to the object that triggers the event(here: the canvas-node), your code produces a recursion. When you want to trigger the click-event for the StationCanvas-instance, you may store the instance as a property of the canvas-element, so it will be easy accessible inside the click-callback
StationCanvas.prototype.onAdd = function() {
var canvas = document.createElement("canvas");
canvas.overlay=this;
//more code
}
this.listeners_ = [
google.maps.event.addDomListener(this.canvas_, "click", function (e) {
google.maps.event.trigger(this.overlay,'click')
}),
google.maps.event.addListener(this, "click", function (e) {
alert('click on the StationCanvas-instance');
})
];

Div which appears, dissapears after a while and apears when hovering...

i'm trying to code a div which appears, dissapears after a while and apears when hovering..
you can see the live example at www.aedas.com - the left pane slides in, then it dissapears, and when you hover that area it will reappear.
thank you very much!
You could try something simple as this :
I am using setInterval and clearInterval for setting an interval for hiding the bar.
Important Note
id returned by the setInterval should be used by the clearInterval or the loop won't break!!
Working jsfiddle : http://jsfiddle.net/frictionless/QmLAv/
$(function() {
var showTime = 5000;
var transition = 'slow';
var target = $('.headerbar');
var flag = false;
target.slideDown(transition);
var id = setInterval(function(){hide(target);}, showTime);
var hide = function(item) {
debugger;
if(flag){
return;
}
clearInterval(id);
item.slideUp(transition);
};
target.hover(function() {
flag = true;
clearInterval(id);
$(this).show();
}, function() {
flag = false;
id = setInterval(function(){hide(target);}, showTime);
});
});​

Google Places API autocomplete not working

Right now, the autocomplete box works just fine when I click on the location, but when I press down, highlight the location that I want to go to, and press enter, it simply goes back to the home location of the map. Any insights on this? I call this function in initialize(). I'm lost as to what I possibly did wrong. Is this just a google api bug? If so, any insights as to how to work around it?
function setupAutoComplete() {
var defaultBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(-90, -180),
new google.maps.LatLng(90, 180));
var input = document.getElementById('placeSearch');
var options = {
bounds: defaultBounds,
types: ['(regions)']
};
autocomplete = new google.maps.places.Autocomplete(input, options);
google.maps.event.addListener(autocomplete, 'place_changed', function() {
alert('hi');
removeAllOverlays();
var place = autocomplete.getPlace();
var mapCenter = place.geometry.location;
var colLat = mapCenter.lat() - (halfPoints)*latSeparation;
var colLng = mapCenter.lng() - (halfPoints)*lngSeparation;
var tempStart = new google.maps.LatLng(colLat, colLng);
map.setCenter(mapCenter);
pointArray[0][0] = tempStart;
reService();
mapSearch();
drawBounds();
});
}
Thanks so much!
I guess the input#placeSearch is placed inside a <form>.
You submit the form when you press [ENTER].
You may either remove the surrounding form or cancel the submission by adding:
onsubmit="return false"
...to the form-element.
I just hit this issue and went with the following, as I do want to submit the form at a later stage. This code is from google groups.
var input = document.getElementById('create-location');
var options = {
//types: ['(cities)'],
};
autocomplete = new google.maps.places.Autocomplete(input, options);
google.maps.event.addDomListener(input, 'keydown', function(e) {
if (e.keyCode == 13)
{
if (e.preventDefault)
{
e.preventDefault();
}
else
{
// Since the google event handler framework does not handle early IE versions, we have to do it by our self. :-(
e.cancelBubble = true;
e.returnValue = false;
}
}
});

Google Map Tooltip

I wonder whether someone may be able to help me please.
I've been working on a tooltip for markers that I place on a google map. I can get this to work showing the information that I would like the user to see, in this case the fields name and address, so the code line is title: name+address.
Could someone please tell me how I could put a space between these so the tooltip would read 'name address' rather than 'nameaddress'.
I've tried all sorts of things using e.g.title: name'_'+ address, title: name' '+address and I can't get it to work.
Any help would be greatly appreciated.
Many thanks
Chris
You can try this
name + ' ' + address
NB: you need a space in the quotes and a + on either side.
I use this function to initialize started values:
//Inicialize map values
function initialize() {
latCenterMap=41.50347;
lonCenterMap=-5.74638;
zommCeneterMap=14;
latPoint=41.50347;
lonPoint=-5.74638;
//Values default initialize
var latlng = new google.maps.LatLng(latCenterMap, lonCenterMap);
var mapOptions = {
zoom: zommCeneterMap,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map-canvas_'), mapOptions);
codePoint(map, lat, lon);
}
I used this function to set values point position into map
//Get position by Latitude and Longitude
function codePoint(map, lat, lon) {
var latlng = new google.maps.LatLng(parseFloat(lat), parseFloat(lon));
var title = "Your text";
var iconPoint = new google.maps.MarkerImage('images/pointBlue.png',
//Measure image
new google.maps.Size(25,25),
new google.maps.Point(0,0),
//Half measure image
new google.maps.Point(12.5,12.5)
);
marker = new google.maps.Marker({
position: latlng,
map: map,
icon: iconPoint,
tooltip: title
});
customTooltip(marker);
}
I use this function to create a tooltip to point position
//TOOLTIP
function customTooltip(marker){
// Constructor function
function Tooltip(opts, marker) {
// Initialization
this.setValues(opts);
this.map_ = opts.map;
this.marker_ = marker;
var div = this.div_ = document.createElement("div");
// Class name of div element to style it via CSS
div.className = "tooltip";
this.markerDragging = false;
}
Tooltip.prototype = {
// Define draw method to keep OverlayView happy
draw: function() {},
visible_changed: function() {
var vis = this.get("visible");
this.div_.style.visibility = vis ? "visible" : "hidden";
},
getPos: function(e) {
var projection = this.getProjection();
// Position of mouse cursor
var pixel = projection.fromLatLngToDivPixel(e.latLng);
var div = this.div_;
// Adjust the tooltip's position
var gap = 15;
var posX = pixel.x + gap;
var posY = pixel.y + gap;
var menuwidth = div.offsetWidth;
// Right boundary of the map
var boundsNE = this.map_.getBounds().getNorthEast();
boundsNE.pixel = projection.fromLatLngToDivPixel(boundsNE);
if (menuwidth + posX > boundsNE.pixel.x) {
posX -= menuwidth + gap;
}
div.style.left = posX + "px";
div.style.top = posY + "px";
if (!this.markerDragging) {
this.set("visible", true);
}
},
// This is added to avoid using listener (Listener is not working when Map is quickly loaded with icons)
getPos2: function(latLng) {
var projection = this.getProjection();
// Position of mouse cursor
var pixel = projection.fromLatLngToDivPixel(latLng);
var div = this.div_;
// Adjust the tooltip's position
var gap = 5;
var posX = pixel.x + gap;
var posY = pixel.y + gap;
var menuwidth = div.offsetWidth;
// Right boundary of the map
var boundsNE = this.map_.getBounds().getNorthEast();
boundsNE.pixel = projection.fromLatLngToDivPixel(boundsNE);
if (menuwidth + posX > boundsNE.pixel.x) {
posX -= menuwidth + gap;
}
div.style.left = posX + "px";
div.style.top = posY + "px";
if (!this.markerDragging) {
this.set("visible", true);
}
},
addTip: function() {
var me = this;
var g = google.maps.event;
var div = me.div_;
div.innerHTML = me.get("text").toString();
// Tooltip is initially hidden
me.set("visible", false);
// Append the tooltip's div to the floatPane
me.getPanes().floatPane.appendChild(this.div_);
// In IE this listener gets randomly lost after it's been cleared once.
// So keep it out of the listeners array.
g.addListener(me.marker_, "dragend", function() {
me.markerDragging = false; });
// Register listeners
me.listeners = [
// g.addListener(me.marker_, "dragend", function() {
// me.markerDragging = false; }),
g.addListener(me.marker_, "position_changed", function() {
me.markerDragging = true;
me.set("visible", false); }),
g.addListener(me.map_, "mousemove", function(e) {
me.getPos(e); })
];
},
removeTip: function() {
// Clear the listeners to stop events when not needed.
if (this.listeners) {
for (var i = 0, listener; listener = this.listeners[i]; i++) {
google.maps.event.removeListener(listener);
}
delete this.listeners;
}
// Remove the tooltip from the map pane.
var parent = this.div_.parentNode;
if (parent) parent.removeChild(this.div_);
}
};
function inherit(addTo, getFrom) {
var from = getFrom.prototype; // prototype object to get methods from
var to = addTo.prototype; // prototype object to add methods to
for (var prop in from) {
if (typeof to[prop] == "undefined") to[prop] = from[prop];
}
}
// Inherits from OverlayView from the Google Maps API
inherit(Tooltip, google.maps.OverlayView);
var tooltip = new Tooltip({map: map}, marker);
tooltip.bindTo("text", marker, "tooltip");
google.maps.event.addListener(marker, 'mouseover', function() {
tooltip.addTip();
tooltip.getPos2(marker.getPosition());
});
google.maps.event.addListener(marker, 'mouseout', function() {
tooltip.removeTip();
});
}
I use this style to css file
//CSS
.tooltip {
position:absolute;
top:0;
left:0;
z-index: 300;
width: 11.5em;
padding: 5px;
font-size: 12pt;
font-family: klavika;
color: #fff;
background-color: #04A2CA;
border-radius: 10px;
box-shadow: 2px 2px 5px 0 rgba(50, 50, 50, 0.75);
}

Resources