@ -10,11 +10,7 @@
// Open window icon (on background 'desktop')
// Close window button (on 'window' itself)
$ ( document ) . ready ( function ( ) {
let corpi = {
let corpi = {
0 : {
id : 'xpub' ,
glyph : '🖨️' ,
@ -35,18 +31,44 @@ $(document).ready(function(){
title : 'let greetings' ,
content : 'We are pleased to invite you to window.open(), a day-long festival, held by students and alumni of the Master of Experimental Publishing (XPUB) at Page Not Found.'
} ,
}
}
$ ( document ) . ready ( function ( ) {
// generate divs
Object . values ( corpi ) . forEach ( corpus => {
$ ( '#boxes' ) . append ( ` <div class="ui-widget-content draggable resizable" id=" ${ corpus [ 'id' ] } "><h1> ${ corpus [ 'title' ] } </h1><p> ${ corpus [ 'content' ] } </p><button class="closable">X</button></div> ` )
$ ( "#icons" ) . append ( ` <button onclick=" $ ( ${ corpus [ 'id' ] } ).fadeIn()" class="icon"> ${ corpus [ "glyph" ] } </button> ` )
$ ( '#boxes' ) . append ( `
< div class = "ui-widget-content draggable resizable" id = "${corpus['id']}" >
< h1 > $ { corpus [ 'title' ] } < / h 1 >
< p > $ { corpus [ 'content' ] } < / p >
< button class = "closable" > X < / b u t t o n >
< / d i v >
` )
$ ( '#icons' ) . append ( ` <button onclick=" $ ( ${ corpus [ 'id' ] } ).fadeIn()" class="icon"> ${ corpus [ "glyph" ] } </button> ` )
} ) ;
const dragResize = new DragResizeClose ( ) ;
} ) ;
class DragResizeClose {
constructor ( ) {
this . zIndex = 3 ;
this . drag ( ) ;
this . setDraggables ( ) ;
this . setZindex ( ) ;
this . handleCursor ( ) ;
this . closeBtn ( ) ;
}
drag ( ) {
$ ( '.draggable' ) . draggable ( { containment : "window" } , { // Setup dragging and containment
start : ( event , ui ) => $ ( this ) . css ( "z-index" , this . zIndex ++ ) // Initialize z-index
} ) ;
}
setDraggables ( ) {
//size window
function getWidth ( ) {
const getWidth = ( ) => {
return Math . max (
document . body . scrollWidth ,
document . documentElement . scrollWidth ,
@ -56,66 +78,57 @@ $(document).ready(function(){
) ;
}
var widthDrag = ( getWidth ( ) ) / 2 ;
function getHeight ( ) {
return Math . max (
document . body . scrollHeight ,
document . documentElement . scrollHeight ,
document . body . offsetHeight ,
document . documentElement . offsetHeight ,
document . documentElement . clientHeight
) ;
}
var heightDrag = ( getHeight ( ) ) / 2 ;
//let widthDrag = (getWidth())/2;
// function getHeight() {
// return Math.max(
// document.body.scrollHeight,
// document.documentElement.scrollHeight,
// document.body.offsetHeight,
// document.documentElement.offsetHeight,
// document.documentElement.clientHeight
// );
// }
// random
function getRndInteger ( min , max ) {
return Math . floor ( Math . random ( ) * ( max - min + 1 ) ) + min ;
}
// let heightDrag = (getHeight())/2;
const getRndInteger = ( min , max ) => Math . floor ( Math . random ( ) * ( max - min + 1 ) ) + min ;
// DRAG and Z-INDEX priorities handler
var a = 3 ;
$ ( '.draggable' ) . draggable ( { containment : "window" } , { // Setup dragging and containment
start : function ( event , ui ) { $ ( this ) . css ( "z-index" , a ++ ) ; } // Initialize z-index for handelr
$ ( ".draggable" ) . each ( function ( ) {
let rw = getRndInteger ( ( getWidth ( ) ) / 2 - 500 , ( getWidth ( ) ) / 2 )
//let rh = getRndInteger(heightDrag-200, heightDrag)
$ ( this ) . css ( "width" , rw ) ;
$ ( this ) . css ( "height" , 'auto' ) ;
} ) ;
}
$ ( '#dragZone div' ) . click ( function ( ) { // Setup z-index handler
setZindex ( ) {
$ ( '#dragZone div' ) . click ( ( ) => { // Setup z-index handler
$ ( this ) . addClass ( 'top' ) . removeClass ( 'bottom' ) ;
$ ( this ) . siblings ( ) . removeClass ( 'top' ) . addClass ( 'bottom' ) ;
$ ( this ) . css ( "z-index" , a ++ ) ;
} ) ;
// CURSOR MOUSE DOWN
$ ( '.draggable' ) . on ( "mousedown" , function ( ) {
$ ( '.draggable' ) . css ( 'cursor' , 'grabbing' ) ;
} ) . on ( "mouseup mouseleave" , function ( ) {
$ ( '.draggable' ) . css ( 'cursor' , 'grab' ) ;
$ ( this ) . css ( "z-index" , this . zIndex ++ ) ;
} ) ;
}
// RESIZE with aspect ratio
$ ( ".resizable" ) . resizable ( { aspectRatio : true , maxHeight : 900 , minHeight : 200 } ) ;
$ ( ".resizableOriz" ) . resizable ( { aspectRatio : true , maxHeight : 500 , minHeight : 200 } ) ;
// settings draggables
$ ( ".draggable" ) . each ( function ( ) {
let rw = getRndInteger ( widthDrag - 500 , widthDrag )
let rh = getRndInteger ( heightDrag - 200 , heightDrag )
$ ( this ) . css ( "width" , rw ) ;
$ ( this ) . css ( "height" , rh )
handleCursor ( ) {
$ ( '.draggable' )
. on ( "mousedown" , ( ) => $ ( '.draggable' ) . css ( 'cursor' , 'grabbing' ) )
. on ( "mouseup mouseleave" , ( ) => $ ( '.draggable' ) . css ( 'cursor' , 'grab' ) ) ;
}
} ) ;
resize ( ) {
$ ( ".resizable" ) . resizable ( { aspectRatio : true , maxHeight : 900 , minHeight : 10 } ) ;
$ ( ".resizableOriz" ) . resizable ( { aspectRatio : true , maxHeight : 500 , minHeight : 10 } ) ;
}
// close window
closeBtn ( ) {
$ ( ".closable" ) . click ( function ( ) {
$ ( this ) . parent ( ) . fadeOut ( ) ;
} ) ;
$ ( this ) . parent ( ) . fadeOut ( ) ;
} )
. hover (
function ( ) { $ ( this ) . addClass ( "hover" ) ; } ,
function ( ) { $ ( this ) . removeClass ( "hover" ) ; }
) ;
}
}
} ) ;