Skip to content
Browse files

Postbox is now draggable.

  • Loading branch information...
1 parent 225bac8 commit 9bb5ac4ae672aac1f3ed571621436cf3142639c8 @jaw-sh jaw-sh committed Nov 23, 2015
View
9 public/static/css/app/responsive.css
@@ -248,6 +248,15 @@
color: white;
text-indent: 4px;
}
+ html.js form.form-post .ui-draggable-handle {
+ cursor: drag;
+ cursor: -webkit-grab;
+ cursor: grab;
+ }
+ html.js form.form-post.ui-draggable-dragging .ui-draggable-handle {
+ cursor: -webkit-grabbing;
+ cursor: grabbing;
+ }
html.js body.responsive form.form-post .field {
margin: 0;
View
3 public/static/js/app/main.js
@@ -6,6 +6,9 @@
ib.widgets = {};
+ ib.rtl = $("body").hasClass("rtl");
+ ib.ltr = !ib.rtl;
+
ib.bindAll = function(eventOrScope) {
var $scope;
View
63 public/static/js/app/widgets/postbox.widget.js
@@ -8,8 +8,9 @@ ib.widget("postbox", function(window, $, undefined) {
// Dropzone instance.
dropzone : null,
- // Resizing bound
+ // jQuery UI bind indicators
resizable : false,
+ draggable : false,
// Widgets instance.
notices : null,
@@ -306,7 +307,8 @@ ib.widget("postbox", function(window, $, undefined) {
// Tweak classes.
widget.$widget.removeClass("postbox-minimized postbox-closed postbox-maximized");
- // Rebind jQuery UI Resize.
+ // Rebind jQuery UI widgets.
+ widget.bind.draggable();
widget.bind.resize();
}
},
@@ -422,7 +424,8 @@ ib.widget("postbox", function(window, $, undefined) {
.removeClass("postbox-minimized postbox-closed")
.addClass("postbox-maximized");
- // Remove jQuery UI Resize.
+ // Remove jQuery UI widgets.
+ widget.unbind.draggable();
widget.unbind.resize();
},
@@ -449,6 +452,7 @@ ib.widget("postbox", function(window, $, undefined) {
.addClass("postbox-minimized");
// Rebind jQuery UI Resize.
+ widget.bind.draggable();
widget.bind.resize();
},
@@ -458,6 +462,30 @@ ib.widget("postbox", function(window, $, undefined) {
widget.dropzone.options.maxFilesize = window.app.settings.attachmentFilesize / 1024;
},
+ postDragStop : function(event, ui) {
+ if (ib.ltr)
+ {
+ // Okay, so:
+ // Our styling using top,right.
+ // Draggable sets the position using top,left.
+ // This causes the box to expand to the right when dragging with the resize handles.
+ // Because you cannot drag to expand and drag to move at the same time, it's safe
+ // to fix the right/left assignent after the drag has stopped.
+ // This uses little jQuery as well which is just gravy.
+ var rect = this.getBoundingClientRect();
+ var right = (document.body.clientWidth - rect.right);
+
+ if (rect.top <= 80 && right <= 40)
+ {
+ right = 10;
+ this.style.top = 45 + "px";
+ }
+
+ this.style.left = "auto";
+ this.style.right = right + "px";
+ }
+ },
+
postResize : function(event, ui) {
var $post = $(this);
var $form = $post.resizable( "option", "alsoResize" );
@@ -469,7 +497,10 @@ ib.widget("postbox", function(window, $, undefined) {
ui.size.width = Math.min(ui.size.width, $form.width());
ui.size.height += Math.min(0, formHangY);
- $form.css('height', formHangY > 0 ? "auto" : window.innerHeight - $form.position().top);
+ $form.css({
+ 'height' : formHangY > 0 ? "auto" : window.innerHeight - $form.position().top
+ });
+
$post.css('width', ui.size.width);
$post.children().first().css('width', "100%");
@@ -493,6 +524,7 @@ ib.widget("postbox", function(window, $, undefined) {
{
if (window.innerHeight < 480 || window.innerWidth < 1028)
{
+ widget.unbind.draggable();
widget.unbind.resize();
}
else
@@ -523,6 +555,19 @@ ib.widget("postbox", function(window, $, undefined) {
// Event bindings
bind : {
+ draggable : function() {
+ if (window.innerHeight >= 480 && window.innerWidth >= 1028)
+ {
+ widget.$widget.draggable({
+ containment : "window",
+ handle : "legend.form-legend",
+ stop : widget.events.postDragStop
+ });
+
+ widget.draggable = true;
+ }
+ },
+
resize : function() {
if (window.innerHeight >= 480 && window.innerWidth >= 1028)
{
@@ -593,11 +638,21 @@ ib.widget("postbox", function(window, $, undefined) {
.on('fileUploading.ib-postbox', widget.events.fileUploading)
;
+ widget.bind.draggable();
widget.bind.resize();
}
},
unbind : {
+ draggable : function() {
+ if (widget.draggable && typeof widget.$widget.draggable === "function")
+ {
+ widget.$widget.draggable( "destroy" ).attr('style', "");
+
+ widget.draggable = false;
+ }
+ },
+
resize : function() {
// Bind resizability onto the post area.
var $body = $(widget.options.selector['form-body'], widget.$widget);
View
2 resources/views/layouts/static.blade.php
@@ -23,7 +23,7 @@
@yield('head')
</head>
-<body class="infinity-next responsive @yield('body-class')">
+<body class="infinity-next responsive ltr @yield('body-class')">
<div id="page-container">
@section('header')
<header class="board-header header-height-1">

0 comments on commit 9bb5ac4

Please sign in to comment.
Something went wrong with that request. Please try again.