touch enabled editor
- jqueryUI touch punch - using jqueryui sortable instead of previous plugin
This commit is contained in:
parent
b4c76677b7
commit
2b26f6f7d1
8 changed files with 41 additions and 273 deletions
File diff suppressed because one or more lines are too long
|
|
@ -15,8 +15,7 @@ MISC = {
|
|||
///////////////////////
|
||||
|
||||
$ = jQuery = require('./jquery/jquery.min')
|
||||
require('./jquery/jquery.resizable-draggable')
|
||||
require('./jquery/jquery.sortable')
|
||||
require('./jquery/jquery.ui')
|
||||
require('./jquery/jquery.drag')
|
||||
require('./jquery/jquery.resize')
|
||||
require('./jquery/jquery.fake-input')
|
||||
|
|
|
|||
|
|
@ -40,8 +40,7 @@ module.exports.enable = function(){
|
|||
module.exports.disable()
|
||||
$('.editor').append('<div class="editor-container"></div>')
|
||||
var enableEditor = module.exports.enable
|
||||
$('.widget').on('click.editor',function(e){
|
||||
e.preventDefault()
|
||||
$('.widget').on('mousedown.editor touchstart.editor',function(e){
|
||||
e.stopPropagation()
|
||||
|
||||
|
||||
|
|
@ -51,6 +50,7 @@ module.exports.enable = function(){
|
|||
data = getdata(container),
|
||||
form = $('<div class="form"></div>')
|
||||
|
||||
if (container.hasClass('editing')) return
|
||||
|
||||
$('.editing').removeClass('editing')
|
||||
container.addClass('editing')
|
||||
|
|
@ -68,10 +68,10 @@ module.exports.enable = function(){
|
|||
|
||||
enableEditor()
|
||||
sync()
|
||||
newContainer.children().first().click()
|
||||
newContainer.children().first().trigger('mousedown.editor')
|
||||
$('#sidepanel').scrollTop(scroll)
|
||||
|
||||
if (data.tabs && data.tabs.length) ui()
|
||||
if (data.tabs && data.tabs.length) ui.init()
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -92,8 +92,8 @@ module.exports.enable = function(){
|
|||
snapTolerance:5
|
||||
})
|
||||
|
||||
$('.widget.ui-draggable').draggable('destroy').find('.ui-draggable-handle').remove()
|
||||
if (data.hasOwnProperty('top')) {
|
||||
$('.widget.ui-draggable').draggable('destroy').find('.ui-draggable-handle').remove()
|
||||
$(this).draggable({
|
||||
stop: function( event, ui ) {
|
||||
event.preventDefault()
|
||||
|
|
@ -170,7 +170,7 @@ module.exports.enable = function(){
|
|||
var item = $(`<li data-index="${i}" class="sortables" data-id="${data.widgets[i].id}"><a class="btn small">${label}</a></li>`)
|
||||
.appendTo(list)
|
||||
.click(function(){
|
||||
container.find('.widget').first().parent().children('.widget').eq($(this).attr('data-index')).click()
|
||||
container.find('.widget').first().parent().children('.widget').eq($(this).attr('data-index')).trigger('mousedown.editor')
|
||||
})
|
||||
var remove = $('<span><i class="fa fa-remove"></i></span>')
|
||||
.appendTo(item)
|
||||
|
|
@ -211,7 +211,7 @@ module.exports.enable = function(){
|
|||
.appendTo(list)
|
||||
.click(function(){
|
||||
var id = container.find('.tab').first().parent().children('.tab').eq($(this).attr('data-index')).attr('id')
|
||||
$(`a[data-tab="#${id}"]`).click()
|
||||
$(`a[data-tab="#${id}"]`).trigger('mousedown.editor')
|
||||
})
|
||||
var remove = $('<span><i class="fa fa-remove"></i></span>')
|
||||
.appendTo(item)
|
||||
|
|
@ -244,8 +244,7 @@ module.exports.enable = function(){
|
|||
})
|
||||
|
||||
|
||||
$('a[data-tab]').on('click.editor',function(e){
|
||||
e.preventDefault()
|
||||
$('a[data-tab]').on('mousedown.editor touchstart.editor',function(e){
|
||||
e.stopPropagation()
|
||||
|
||||
var link = $(this),
|
||||
|
|
@ -281,7 +280,7 @@ module.exports.enable = function(){
|
|||
enableEditor()
|
||||
sync()
|
||||
|
||||
link.click()
|
||||
link.trigger('mousedown.editor')
|
||||
|
||||
$('#sidepanel').scrollTop(scroll)
|
||||
}
|
||||
|
|
@ -329,7 +328,7 @@ module.exports.enable = function(){
|
|||
var item = $(`<li data-index="${i}" class="sortables"><a class="btn small">${label}</a></li>`)
|
||||
.appendTo(list)
|
||||
.click(function(){
|
||||
container.find('.widget').first().parent().children('.widget').eq($(this).attr('data-index')).click()
|
||||
container.find('.widget').first().parent().children('.widget').eq($(this).attr('data-index')).trigger('mousedown.editor')
|
||||
})
|
||||
var remove = $('<span><i class="fa fa-remove"></i></span>')
|
||||
.appendTo(item)
|
||||
|
|
@ -370,7 +369,7 @@ module.exports.enable = function(){
|
|||
.appendTo(list)
|
||||
.click(function(){
|
||||
var id = container.find('.tab').first().parent().children('.tab').eq($(this).attr('data-index')).attr('id')
|
||||
$(`a[data-tab="#${id}"]`).click()
|
||||
$(`a[data-tab="#${id}"]`).trigger('mousedown.editor')
|
||||
})
|
||||
var remove = $('<span><i class="fa fa-remove"></i></span>')
|
||||
.appendTo(item)
|
||||
|
|
@ -433,7 +432,7 @@ module.exports.enable = function(){
|
|||
stateSet(state,false)
|
||||
enableEditor()
|
||||
for (i in ontab) {
|
||||
$(`a[data-tab="#${ontab[i]}"]`).click()
|
||||
$(`a[data-tab="#${ontab[i]}"]`).trigger('mousedown.editor')
|
||||
}
|
||||
$('.editor-root').click()
|
||||
$('#sidepanel').scrollTop(scroll)
|
||||
|
|
@ -494,11 +493,13 @@ module.exports.enable = function(){
|
|||
module.exports.disable = function(){
|
||||
$('.widget.ui-resizable').resizable('destroy')
|
||||
$('.widget.ui-draggable').draggable('destroy').find('.ui-draggable-handle').remove()
|
||||
$('.widget').off('click.editor')
|
||||
$('a[data-tab]').off('click.editor')
|
||||
$('.editor-root').off('click.editor').addClass('disabled')
|
||||
|
||||
$('a[data-tab], .widget, .editor-root').off('.editor')
|
||||
|
||||
$('.editor-root').addClass('disabled')
|
||||
$('.enable-editor').removeClass('on')
|
||||
$('.disable-editor').addClass('on')
|
||||
$('.editing').removeClass('editing')
|
||||
|
||||
$('.editor .editor-container').remove()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
var parsetabs = require('./parser').tabs,
|
||||
ui = require('./ui'),
|
||||
sync = require('./widgets').sync
|
||||
sync = require('./widgets').sync,
|
||||
disableEditor = require('./editor').disable
|
||||
|
||||
module.exports = function(session,callback) {
|
||||
|
||||
|
|
@ -10,6 +11,8 @@ module.exports = function(session,callback) {
|
|||
|
||||
ui.init()
|
||||
|
||||
disableEditor()
|
||||
|
||||
sync()
|
||||
|
||||
if (callback) callback()
|
||||
|
|
|
|||
|
|
@ -124,8 +124,6 @@ module.exports = function() {
|
|||
|
||||
$('#sidepanel').append(sidepanel)
|
||||
|
||||
actions.editorDisable()
|
||||
|
||||
$(`<a id="open-toggle">${icon('navicon')}</a>`).appendTo('#container').click(function(){
|
||||
$('#open-toggle, #sidepanel, #container').toggleClass('sidepanel-open')
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,85 +0,0 @@
|
|||
/*
|
||||
* HTML5 Sortable jQuery Plugin
|
||||
* http://farhadi.ir/projects/html5sortable
|
||||
*
|
||||
* Copyright 2012, Ali Farhadi
|
||||
* Released under the MIT license.
|
||||
*/
|
||||
(function($) {
|
||||
var dragging, placeholders = $();
|
||||
$.fn.sortable = function(options) {
|
||||
var method = String(options);
|
||||
options = $.extend({
|
||||
connectWith: false
|
||||
}, options);
|
||||
return this.each(function() {
|
||||
if (/^(enable|disable|destroy)$/.test(method)) {
|
||||
var items = $(this).children($(this).data('items')).attr('draggable', method == 'enable');
|
||||
if (method == 'destroy') {
|
||||
items.add(this).removeData('connectWith items')
|
||||
.off('dragstart.h5s dragend.h5s selectstart.h5s dragover.h5s dragenter.h5s drop.h5s');
|
||||
}
|
||||
return;
|
||||
}
|
||||
var isHandle, index, items = $(this).children(options.items);
|
||||
var placeholder = $('<' + (/^(ul|ol)$/i.test(this.tagName) ? 'li' : 'div') + ' class="sortable-placeholder">');
|
||||
items.find(options.handle).mousedown(function() {
|
||||
isHandle = true;
|
||||
}).mouseup(function() {
|
||||
isHandle = false;
|
||||
});
|
||||
$(this).data('items', options.items)
|
||||
placeholders = placeholders.add(placeholder);
|
||||
if (options.connectWith) {
|
||||
$(options.connectWith).add(this).data('connectWith', options.connectWith);
|
||||
}
|
||||
items.attr('draggable', 'true').on('dragstart.h5s', function(e) {
|
||||
if (options.handle && !isHandle) {
|
||||
return false;
|
||||
}
|
||||
isHandle = false;
|
||||
var dt = e.originalEvent.dataTransfer;
|
||||
dt.effectAllowed = 'move';
|
||||
dt.setData('Text', 'dummy');
|
||||
index = (dragging = $(this)).addClass('sortable-dragging').index();
|
||||
}).on('dragend.h5s', function() {
|
||||
if (!dragging) {
|
||||
return;
|
||||
}
|
||||
dragging.removeClass('sortable-dragging').show();
|
||||
placeholders.detach();
|
||||
if (index != dragging.index()) {
|
||||
dragging.parent().trigger('sortupdate', {item: dragging});
|
||||
}
|
||||
dragging = null;
|
||||
}).not('a[href], img').on('selectstart.h5s', function() {
|
||||
this.dragDrop && this.dragDrop();
|
||||
return false;
|
||||
}).end().add([this, placeholder]).on('dragover.h5s dragenter.h5s drop.h5s', function(e) {
|
||||
if (!items.is(dragging) && options.connectWith !== $(dragging).parent().data('connectWith')) {
|
||||
return true;
|
||||
}
|
||||
if (e.type == 'drop') {
|
||||
e.stopPropagation();
|
||||
placeholders.filter(':visible').after(dragging);
|
||||
dragging.trigger('dragend.h5s');
|
||||
return false;
|
||||
}
|
||||
e.preventDefault();
|
||||
e.originalEvent.dataTransfer.dropEffect = 'move';
|
||||
if (items.is(this)) {
|
||||
if (options.forcePlaceholderSize) {
|
||||
placeholder.height(dragging.outerHeight());
|
||||
}
|
||||
dragging.hide();
|
||||
$(this)[placeholder.index() < $(this).index() ? 'after' : 'before'](placeholder);
|
||||
placeholders.not(placeholder).detach();
|
||||
} else if (!placeholders.is(this) && !$(this).children(options.items).length) {
|
||||
placeholders.detach();
|
||||
$(this).append(placeholder);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
});
|
||||
};
|
||||
})(jQuery);
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -245,7 +245,8 @@ body {
|
|||
right:0;
|
||||
top:2rem;
|
||||
width:60rem;
|
||||
height:$nav-height;
|
||||
background: $color-bg;
|
||||
height:$nav-height - 2;
|
||||
padding:0 10rem;
|
||||
line-height: $nav-height;
|
||||
font-size: 24rem;
|
||||
|
|
@ -346,7 +347,7 @@ body {
|
|||
}
|
||||
|
||||
.editing {
|
||||
z-index: 99999999!important;
|
||||
z-index: 10!important;
|
||||
}
|
||||
.widget.editing:after, a.editing:before {
|
||||
content:"";
|
||||
|
|
@ -819,7 +820,8 @@ a {
|
|||
background: rgba($color-accent,.25);
|
||||
min-width:30rem!important;
|
||||
min-height:30rem!important;
|
||||
z-index: 99999999999!important;
|
||||
z-index: 10!important;
|
||||
opacity: 1!important;
|
||||
}
|
||||
.ui-draggable-handle {
|
||||
position: absolute;
|
||||
|
|
@ -837,7 +839,6 @@ a {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/* STRIP (contains any widgets) */
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue