Skip to content

Instantly share code, notes, and snippets.

@4kochi
Last active September 15, 2017 09:43
Show Gist options
  • Save 4kochi/d5c0d93497376a3afe889794ad6d1daa to your computer and use it in GitHub Desktop.
Save 4kochi/d5c0d93497376a3afe889794ad6d1daa to your computer and use it in GitHub Desktop.
Random JS/HTML/CSS stuff
function setContextMenuPostion(event, contextMenu) {
var mousePosition = {};
var menuPostion = {};
var menuDimension = {};
menuDimension.x = contextMenu.outerWidth();
menuDimension.y = contextMenu.outerHeight();
mousePosition.x = event.pageX;
mousePosition.y = event.pageY;
if (mousePosition.x + menuDimension.x > $(window).width() + $(window).scrollLeft()) {
menuPostion.x = mousePosition.x - menuDimension.x;
} else {
menuPostion.x = mousePosition.x;
}
if (mousePosition.y + menuDimension.y > $(window).height() + $(window).scrollTop()) {
menuPostion.y = mousePosition.y - menuDimension.y;
} else {
menuPostion.y = mousePosition.y;
}
return menuPostion;
}
var windowHeight = $(window).height()/2;
var windowWidth = $(window).width()/2;
if(e.clientY > windowHeight && e.clientX <= windowWidth) {
$("#contextMenuContainer").css("left", e.clientX);
$("#contextMenuContainer").css("bottom", $(window).height()-e.clientY);
$("#contextMenuContainer").css("right", "auto");
$("#contextMenuContainer").css("top", "auto");
} else if(e.clientY > windowHeight && e.clientX > windowWidth) {
$("#contextMenuContainer").css("right", $(window).width()-e.clientX);
$("#contextMenuContainer").css("bottom", $(window).height()-e.clientY);
$("#contextMenuContainer").css("left", "auto");
$("#contextMenuContainer").css("top", "auto");
} else if(e.clientY <= windowHeight && e.clientX <= windowWidth) {
$("#contextMenuContainer").css("left", e.clientX);
$("#contextMenuContainer").css("top", e.clientY);
$("#contextMenuContainer").css("right", "auto");
$("#contextMenuContainer").css("bottom", "auto");
} else {
$("#contextMenuContainer").css("right", $(window).width()-e.clientX);
$("#contextMenuContainer").css("top", e.clientY);
$("#contextMenuContainer").css("left", "auto");
$("#contextMenuContainer").css("bottom", "auto");
}
import { Injectable } from '@angular/core';
function getWindow (): any {
return window;
}
@Injectable()
export class WindowRefService {
get nativeWindow (): any {
return getWindow();
}
}
&.right {
.ui-datepicker {
margin-left: -100px;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment