some refactoring

This commit is contained in:
Curtis SerVaas
2014-09-20 16:55:20 -04:00
parent 63af9b9b21
commit 0cc6c6f16c
25 changed files with 97 additions and 28624 deletions
-104
View File
@@ -2,95 +2,6 @@ $(function(){
//alert("jquery works");
INPUT_PROCESSED = true;
$("#COMMIT").click(function(){
socket.emit("COMMIT");
});
$(".getRevHistory").click(function(e){
var rootId = $(".root").attr("data-id")
socket.emit("revHistoryRequest", rootId);
$(e.target).attr("data-id", rootId);
});
$("body").on("click", ".snapLI", function(e){
$(e.target).addClass("selectedSnap");
});
$(".toggleSidebar").click(function(){
$("#mainPanel").toggleClass("floatRight centering");
$("#metaSidebar").toggleClass("hideBar");
});
$("#markdownButton").click(function(){
vo.thisView.createMarkDownBullet();
});
//grab the rendered div.
//(remove the content of everything else)
//remove the classes.
$("body").on("blur", "#marked-mathjax-input", function(){
var editor = $("#marked-mathjax-input"); //(this is the text-area)
var wrapper = editor.closest(".hoverWrap");
var text = editor.siblings(".Current").html();
var html = "<div>" + text + "</div>";
wrapper.html(html).addClass('markdown');
//editor.remove() is redundant.
});
$("body").on("mouseover", "a.expandCollapse", function(event){
$(event.target).find("a.expandCollapse").css("opacity", "1");
$(event.target).closest("a.expandCollapse").css("opacity", "1");
// $(event.target).siblings("a.expandCollapse").css("opacity", "1")
});
$("body").on("mouseleave", "a.expandCollapse", function(event){
$(event.target).find("a.expandCollapse").css("opacity", ".001");
$(event.target).closest("a.expandCollapse").css("opacity", ".001");
// $(event.target).siblings("a.expandCollapse").css("opacity", ".001")
});
$("body").on("click", ".expandCollapse", function(event){
var LI = $(event.target).parent();
LI.children("ul").slideToggle(110);
LI.children(".zoomButton").toggleClass("collapsed");
});
$("body").on("click", ".splitScreen", function(){
$(".main2").remove();
})
$("body").on("keydown", "textarea", keydownHandler);
$("body").on("focus", "textarea", function(event){
var that = this;
voInitializer(that, event);
var id = $(event.target).closest("li").attr("data-id");
keydownHandler(event);
socket.emit("editing", [id, CurrentUser.google.name]);
});
$("body").on("blur", "textarea", function(event){
var thisLI = $(event.target).closest("li");
var id = thisLI.attr("data-id");
var text = thisLI.children().children("textarea").val();
$("textarea").textareaAutoExpand();
socket.emit("blurred", [id, text, CurrentUser]);
});
$("body").on("click", ".transclude", function(event){
alert("Transclusion syncing with the server has not been implemented. KnownBugs:\n0.Don't make infinite loops.\n1.");
transclude();
});
myRouter = new AppRouter;
Backbone.history.start();
//this calls initialize twice.
@@ -119,8 +30,6 @@ function createPathMenu(event){
}
Array.prototype.insert = function (index, item) {
this.splice(index, 0, item);
};
@@ -149,13 +58,6 @@ Array.prototype.removeOne = function(parId){
this.remove(parIndex);
}
voInitializer = function(that, event){
//var that = this;
vo = {};
@@ -220,12 +122,6 @@ voInitializer = function(that, event){
keydownHandler = function(event){ //the entire body is wrapped in this.
var that = this;
console.log("keyDownHandler");
+61
View File
@@ -0,0 +1,61 @@
$(function(){
$("#markdownButton").click(function(){
vo.thisView.createMarkDownBullet();
});
//grab the rendered div.
//(remove the content of everything else)
//remove the classes.
$("body").on("blur", "#marked-mathjax-input", function(){
var editor = $("#marked-mathjax-input"); //(this is the text-area)
var wrapper = editor.closest(".hoverWrap");
var text = editor.siblings(".Current").html();
var html = "<div>" + text + "</div>";
wrapper.html(html).addClass('markdown');
//editor.remove() is redundant.
});
$("body").on("mouseover", "a.expandCollapse", function(event){
$(event.target).find("a.expandCollapse").css("opacity", "1");
$(event.target).closest("a.expandCollapse").css("opacity", "1");
// $(event.target).siblings("a.expandCollapse").css("opacity", "1")
});
$("body").on("mouseleave", "a.expandCollapse", function(event){
$(event.target).find("a.expandCollapse").css("opacity", ".001");
$(event.target).closest("a.expandCollapse").css("opacity", ".001");
// $(event.target).siblings("a.expandCollapse").css("opacity", ".001")
});
$("body").on("click", ".expandCollapse", function(event){
var LI = $(event.target).parent();
LI.children("ul").slideToggle(110);
LI.children(".zoomButton").toggleClass("collapsed");
});
$("body").on("click", ".splitScreen", function(){
$(".main2").remove();
})
$("body").on("keydown", "textarea", keydownHandler);
$("body").on("focus", "textarea", function(event){
var that = this;
voInitializer(that, event);
var id = $(event.target).closest("li").attr("data-id");
keydownHandler(event);
socket.emit("editing", [id, CurrentUser.google.name]);
});
$("body").on("blur", "textarea", function(event){
var thisLI = $(event.target).closest("li");
var id = thisLI.attr("data-id");
var text = thisLI.children().children("textarea").val();
$("textarea").textareaAutoExpand();
socket.emit("blurred", [id, text, CurrentUser]);
});
$("body").on("click", ".transclude", function(event){
alert("Transclusion syncing with the server has not been implemented. KnownBugs:\n0.Don't make infinite loops.\n1.");
transclude();
});
})
+20
View File
@@ -0,0 +1,20 @@
$(function(){
$("#COMMIT").click(function(){
socket.emit("COMMIT");
});
$(".getRevHistory").click(function(e){
var rootId = $(".root").attr("data-id")
socket.emit("revHistoryRequest", rootId);
$(e.target).attr("data-id", rootId);
});
$("body").on("click", ".snapLI", function(e){
$(e.target).addClass("selectedSnap");
});
$(".toggleSidebar").click(function(){
$("#mainPanel").toggleClass("floatRight centering");
$("#metaSidebar").toggleClass("hideBar");
});
})
-2006
View File
File diff suppressed because it is too large Load Diff
-14972
View File
File diff suppressed because it is too large Load Diff
-8829
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
-554
View File
@@ -1,554 +0,0 @@
/*!
* Nestable jQuery Plugin - Copyright (c) 2012 David Bushell - http://dbushell.com/
* Dual-licensed under the BSD or MIT licenses
*/
;(function($, window, document, undefined)
{
var hasTouch = 'ontouchstart' in window;
/**
* Detect CSS pointer-events property
* events are normally disabled on the dragging element to avoid conflicts
* https://github.com/ausi/Feature-detection-technique-for-pointer-events/blob/master/modernizr-pointerevents.js
*/
var hasPointerEvents = (function()
{
var el = document.createElement('div'),
docEl = document.documentElement;
if (!('pointerEvents' in el.style)) {
return false;
}
el.style.pointerEvents = 'auto';
el.style.pointerEvents = 'x';
docEl.appendChild(el);
var supports = window.getComputedStyle && window.getComputedStyle(el, '').pointerEvents === 'auto';
docEl.removeChild(el);
return !!supports;
})();
var eStart = hasTouch ? 'touchstart' : 'mousedown',
eMove = hasTouch ? 'touchmove' : 'mousemove',
eEnd = hasTouch ? 'touchend' : 'mouseup';
eCancel = hasTouch ? 'touchcancel' : 'mouseup';
var defaults = {
listNodeName : 'ol',
itemNodeName : 'li',
rootClass : 'dd',
listClass : 'dd-list',
itemClass : 'dd-item',
dragClass : 'dd-dragel',
handleClass : 'dd-handle',
collapsedClass : 'dd-collapsed',
placeClass : 'dd-placeholder',
noDragClass : 'dd-nodrag',
emptyClass : 'dd-empty',
expandBtnHTML : '<button data-action="expand" type="button">Expand</button>',
collapseBtnHTML : '<button data-action="collapse" type="button">Collapse</button>',
group : 0,
maxDepth : 5,
threshold : 20
};
defaults = {
listNodeName : 'ul',
itemNodeName : 'li',
rootClass : 'main',
listClass : 'dd-list',
itemClass : 'node',
dragClass : 'dd-dragel',
handleClass : 'handle',
collapsedClass : 'dd-collapsed',
placeClass : 'placeholder',
noDragClass : 'dd-nodrag',
emptyClass : 'dd-empty',
expandBtnHTML : '<a data-action="expand" class="expand expandCollapse">+</a>',
collapseBtnHTML : '<a data-action="collapse" class="expand expandCollapse">-</a>',
dragHeight : '24',
group : 0,
maxDepth : 99999,
threshold : 15
};
function Plugin(element, options)
{
this.w = $(window);
this.el = $(element);
this.options = $.extend({}, defaults, options);
this.init();
}
Plugin.prototype = {
init: function()
{
var list = this;
list.reset();
list.el.data('nestable-group', this.options.group);
list.placeEl = $('<div class="' + list.options.placeClass + '"/>');
// $.each(this.el.find(list.options.itemNodeName), function(k, el) {
// list.setParent($(el));
// });
// list.el.on('click', 'button', function(e) {
// if (list.dragEl || (!hasTouch && e.button !== 0)) {
// return;
// }
// var target = $(e.currentTarget),
// action = target.data('action'),
// item = target.parent(list.options.itemNodeName);
// if (action === 'collapse') {
// list.collapseItem(item);
// }
// if (action === 'expand') {
// list.expandItem(item);
// }
// });
var onStartEvent = function(e)
{
var handle = $(e.target);
if (!handle.hasClass(list.options.handleClass)) {
if (handle.closest('.' + list.options.noDragClass).length) {
return;
}
handle = handle.closest('.' + list.options.handleClass);
}
if (!handle.length || list.dragEl || (!hasTouch && e.button !== 0) || (hasTouch && e.touches.length !== 1)) {
return;
}
var myVar = setInterval(function() {
clearInterval(myVar);
e.preventDefault();
list.dragStart(hasTouch ? e.touches[0] : e);
}, 100);
};
var onMoveEvent = function(e)
{
if (list.dragEl) {
e.preventDefault();
list.dragMove(hasTouch ? e.touches[0] : e);
}
};
var onEndEvent = function(e)
{
if (list.dragEl) {
e.preventDefault();
list.dragStop(hasTouch ? e.touches[0] : e);
}
};
if (hasTouch) {
list.el[0].addEventListener(eStart, onStartEvent, false);
window.addEventListener(eMove, onMoveEvent, false);
window.addEventListener(eEnd, onEndEvent, false);
window.addEventListener(eCancel, onEndEvent, false);
} else {
list.el.on(eStart, onStartEvent);
list.w.on(eMove, onMoveEvent);
list.w.on(eEnd, onEndEvent);
}
},
serialize: function()
{
var data,
depth = 0,
list = this;
step = function(level, depth)
{
var array = [ ],
items = level.children(list.options.itemNodeName);
items.each(function()
{
var li = $(this),
item = $.extend({}, li.data()),
sub = li.children(list.options.listNodeName);
if (sub.length) {
item.children = step(sub, depth + 1);
}
array.push(item);
});
return array;
};
data = step(list.el.find(list.options.listNodeName).first(), depth);
return data;
},
serialise: function()
{
return this.serialize();
},
reset: function()
{
this.mouse = {
offsetX : 0,
offsetY : 0,
startX : 0,
startY : 0,
lastX : 0,
lastY : 0,
nowX : 0,
nowY : 0,
distX : 0,
distY : 0,
dirAx : 0,
dirX : 0,
dirY : 0,
lastDirX : 0,
lastDirY : 0,
distAxX : 0,
distAxY : 0
};
this.moving = false;
this.dragEl = null;
this.dragRootEl = null;
this.dragDepth = 0;
this.hasNewRoot = false;
this.pointEl = null;
},
// expandItem: function(li)
// {
// li.removeClass(this.options.collapsedClass);
// li.children('[data-action="expand"]').hide();
// li.children('[data-action="collapse"]').show();
// li.children(this.options.listNodeName).show();
// },
// collapseItem: function(li)
// {
// var lists = li.children(this.options.listNodeName);
// if (lists.length) {
// li.addClass(this.options.collapsedClass);
// li.children('[data-action="collapse"]').hide();
// li.children('[data-action="expand"]').show();
// li.children(this.options.listNodeName).hide();
// }
// },
// expandAll: function()
// {
// var list = this;
// list.el.find(list.options.itemNodeName).each(function() {
// list.expandItem($(this));
// });
// },
// collapseAll: function()
// {
// var list = this;
// list.el.find(list.options.itemNodeName).each(function() {
// list.collapseItem($(this));
// });
// },
// setParent: function(li)
// {
// // if this node's children's subLists have any children
// if (li.children(this.options.listNodeName).children().length) {
// li.prepend($(this.options.expandBtnHTML));
// li.prepend($(this.options.collapseBtnHTML));
// }
// li.children('[data-action="expand"]').hide();
// },
// unsetParent: function(li)
// {
// li.removeClass(this.options.collapsedClass);
// li.children('[data-action]').remove();
// li.children(this.options.listNodeName).remove();
// },
dragStart: function(e)
{
var mouse = this.mouse,
target = $(e.target),
dragItem = target.closest(this.options.itemNodeName);
console.log("mouse");
console.log(mouse);
// this.placeEl.css('height', dragItem.height());
mouse.offsetX = e.offsetX !== undefined ? e.offsetX : e.pageX - target.offset().left;
mouse.offsetY = e.offsetY !== undefined ? e.offsetY : e.pageY - target.offset().top;
mouse.startX = mouse.lastX = e.pageX;
mouse.startY = mouse.lastY = e.pageY;
console.log("offsetXY");
console.log(mouse.offsetX + ", " + mouse.offsetY);
console.log(e.offsetX + ", " + e.offsetY);
this.dragRootEl = this.el;
this.dragEl = $(document.createElement(this.options.listNodeName)).addClass(this.options.listClass + ' ' + this.options.dragClass);
this.dragEl.css('width', dragItem.width());
// fix for zepto.js
// dragItem.after(this.placeEl).detach().appendTo(this.dragEl);
dragItem.after(this.placeEl);
dragItem[0].parentNode.removeChild(dragItem[0]);
dragItem.appendTo(this.dragEl);
$(document.body).append(this.dragEl);
this.dragEl.css({
'left' : e.pageX - mouse.offsetX,
'top' : e.pageY - mouse.offsetY
});
// total depth of dragging item
// var i, depth,
// items = this.dragEl.find(this.options.itemNodeName);
// for (i = 0; i < items.length; i++) {
// depth = $(items[i]).parents(this.options.listNodeName).length;
// if (depth > this.dragDepth) {
// this.dragDepth = depth;
// }
// }
},
dragStop: function(e)
{
// fix for zepto.js
// this.placeEl.replaceWith(this.dragEl.children(this.options.itemNodeName + ':first').detach());
var el = this.dragEl.children(this.options.itemNodeName).first();
el[0].parentNode.removeChild(el[0]);
this.placeEl.replaceWith(el);
this.dragEl.remove();
this.el.trigger('change');
if (this.hasNewRoot) {
this.dragRootEl.trigger('change');
}
this.reset();
$('.handle').find('img').attr('src', 'img/bullet-8.png');
},
dragMove: function(e)
{
// $closestNode = $('.node').closestEL({left: e.pageX, top: e.pageY});
// var offset = $closestNode.children('.content').offset();
// console.log("node");
// console.log($closestNode);
// console.log("rectangle");
// console.log(offset);
var list, parent, prev, next, depth,
opt = this.options,
mouse = this.mouse;
// this.dragEl.css({
// 'left' : e.pageX - mouse.offsetX,
// 'top' : e.pageY - mouse.offsetY
// });
// mouse position last events
mouse.lastX = mouse.nowX;
mouse.lastY = mouse.nowY;
// mouse position this events
mouse.nowX = e.pageX;
mouse.nowY = e.pageY;
// distance mouse moved between events
mouse.distX = mouse.nowX - mouse.lastX;
mouse.distY = mouse.nowY - mouse.lastY;
// direction mouse was moving
mouse.lastDirX = mouse.dirX;
mouse.lastDirY = mouse.dirY;
// direction mouse is now moving (on both axis)
mouse.dirX = mouse.distX === 0 ? 0 : mouse.distX > 0 ? 1 : -1;
mouse.dirY = mouse.distY === 0 ? 0 : mouse.distY > 0 ? 1 : -1;
// axis mouse is now moving on
var newAx = Math.abs(mouse.distX) > Math.abs(mouse.distY) ? 1 : 0;
// do nothing on first move
if (!mouse.moving) {
mouse.dirAx = newAx;
mouse.moving = true;
return;
}
// calc distance moved on this axis (and direction)
if (mouse.dirAx !== newAx) {
mouse.distAxX = 0;
mouse.distAxY = 0;
} else {
mouse.distAxX += Math.abs(mouse.distX);
if (mouse.dirX !== 0 && mouse.dirX !== mouse.lastDirX) {
mouse.distAxX = 0;
}
mouse.distAxY += Math.abs(mouse.distY);
if (mouse.dirY !== 0 && mouse.dirY !== mouse.lastDirY) {
mouse.distAxY = 0;
}
}
mouse.dirAx = newAx;
/**
* move horizontal
*/
if (mouse.dirAx && mouse.distAxX >= opt.threshold) {
// reset move distance on x-axis for new phase
mouse.distAxX = 0;
prev = this.placeEl.prev(opt.itemNodeName);
// increase horizontal level if previous sibling exists and is not collapsed
if (mouse.distX > 0 && prev.length && !prev.hasClass(opt.collapsedClass)) {
// cannot increase level when item above is collapsed
list = prev.find(opt.listNodeName).last();
// check if depth limit has reached
depth = this.placeEl.parents(opt.listNodeName).length;
if (depth + this.dragDepth <= opt.maxDepth) {
// create new sub-level if one doesn't exist
if (!list.length) {
list = $('<' + opt.listNodeName + '/>').addClass(opt.listClass);
list.append(this.placeEl);
prev.append(list);
// this.setParent(prev);
} else {
// else append to next level up
list = prev.children(opt.listNodeName).last();
list.append(this.placeEl);
}
}
}
// decrease horizontal level
if (mouse.distX < 0) {
// we can't decrease a level if an item preceeds the current one
next = this.placeEl.next(opt.itemNodeName);
if (!next.length) {
parent = this.placeEl.parent();
this.placeEl.closest(opt.itemNodeName).after(this.placeEl);
// if (!parent.children().length) {
// this.unsetParent(parent.parent());
// }
}
}
}
var isEmpty = false;
// find list item under cursor
if (!hasPointerEvents) {
this.dragEl[0].style.visibility = 'hidden';
}
this.pointEl = $(document.elementFromPoint(e.pageX - document.body.scrollLeft, e.pageY - (window.pageYOffset || document.documentElement.scrollTop)));
if (!hasPointerEvents) {
this.dragEl[0].style.visibility = 'visible';
}
if (this.pointEl.hasClass(opt.handleClass)) {
this.pointEl = this.pointEl.parent(opt.itemNodeName);
}
if (this.pointEl.hasClass(opt.emptyClass)) {
isEmpty = true;
}
else if (!this.pointEl.length || !this.pointEl.hasClass(opt.itemClass)) {
return;
}
// find parent list of item under cursor
var pointElRoot = this.pointEl.closest('.' + opt.rootClass),
isNewRoot = this.dragRootEl.data('nestable-id') !== pointElRoot.data('nestable-id');
/**
* move vertical
*/
if (!mouse.dirAx || isNewRoot || isEmpty) {
// check if groups match if dragging over new root
if (isNewRoot && opt.group !== pointElRoot.data('nestable-group')) {
return;
}
// check depth limit
depth = this.dragDepth - 1 + this.pointEl.parents(opt.listNodeName).length;
if (depth > opt.maxDepth) {
return;
}
var before = e.pageY < (this.pointEl.offset().top + this.pointEl.height() / 2);
parent = this.placeEl.parent();
// if empty create new list to replace empty placeholder
if (isEmpty) {
list = $(document.createElement(opt.listNodeName)).addClass(opt.listClass);
list.append(this.placeEl);
this.pointEl.replaceWith(list);
}
else if (before) {
this.pointEl.before(this.placeEl);
}
else {
this.pointEl.after(this.placeEl);
}
// if (!parent.children().length) {
// this.unsetParent(parent.parent());
// }
if (!this.dragRootEl.find(opt.itemNodeName).length) {
this.dragRootEl.append('<div class="' + opt.emptyClass + '"/>');
}
// parent root list has changed
if (isNewRoot) {
this.dragRootEl = pointElRoot;
this.hasNewRoot = this.el[0] !== this.dragRootEl[0];
}
}
}
};
$.fn.nestable = function(params)
{
var lists = this,
retval = this;
lists.each(function()
{
var plugin = $(this).data("nestable");
if (!plugin) {
$(this).data("nestable", new Plugin(this, params));
$(this).data("nestable-id", new Date().getTime());
} else {
if (typeof params === 'string' && typeof plugin[params] === 'function') {
retval = plugin[params]();
}
}
});
return retval || lists;
};
// Helpers
// $('.myselector').closestEL({left: mouse.x, top: mouse.y});
$.fn.closestEL = function(offset) {
var el = null, elOffset, x = offset.left, y = offset.top, distance, dx, dy, minDistance;
this.each(function() {
elOffset = $(this).offset();
if (
(x >= elOffset.left) && (x <= elOffset.right) &&
(y >= elOffset.top) && (y <= elOffset.bottom)
) {
el = $(this);
return false;
}
var offsets = [[elOffset.left, elOffset.top], [elOffset.right, elOffset.top], [elOffset.left, elOffset.bottom], [elOffset.right, elOffset.bottom]];
for (off in offsets) {
dx = offsets[off][0] - x;
dy = offsets[off][1] - y;
distance = Math.sqrt((dx*dx) + (dy*dy));
if (minDistance === undefined || distance < minDistance) {
minDistance = distance;
el = $(this);
}
}
});
return el;
}
})(window.jQuery || window.Zepto, window, document);
-13
View File
@@ -1,13 +0,0 @@
$(function(){
// to hide
hideSidebar = function(){
$('#sidebar').attr('hidden', 'true');
$('#panel-col').toggleClass('col-md-offset-2');
}
// to show
showSidebar = function(){
$('#sidebar').attr('hidden', 'false');
$('#panel-col').toggleClass('col-md-offset-2');
}
})
-609
View File
@@ -1,609 +0,0 @@
/* ===================================================
* jquery-sortable.js v0.9.11
* http://johnny.github.com/jquery-sortable/
* ===================================================
* Copyright (c) 2012 Jonas von Andrian
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ========================================================== */
!function ( $, window, undefined){
var eventNames,
pluginName = 'sortable',
containerDefaults = {
// If true, items can be dragged from this container
drag: true,
// If true, items can be droped onto this container
drop: true,
// Exclude items from being draggable, if the
// selector matches the item
exclude: "",
// If true, search for nested containers within an item
nested: true,
// If true, the items are assumed to be arranged vertically
vertical: true
}, // end container defaults
groupDefaults = {
// This is executed after the placeholder has been moved.
afterMove: function ($placeholder, container) {
},
// The exact css path between the container and its items, e.g. "> tbody"
containerPath: "",
// The css selector of the containers
containerSelector: "ol, ul",
// Distance the mouse has to travel to start dragging
distance: 10, // #Jeremy: Edited from "distance: 0,"
// The css selector of the drag handle
handle: ".handle",
// The exact css path between the item and its subcontainers
itemPath: "",
// The css selector of the items
itemSelector: "li",
// Check if the dragged item may be inside the container.
// Use with care, since the search for a valid container entails a depth first search
// and may be quite expensive.
isValidTarget: function ($item, container) {
return true
},
// Executed before onDrop if placeholder is detached.
// This happens if pullPlaceholder is set to false and the drop occurs outside a container.
onCancel: function ($item, container, _super) {
},
// Executed at the beginning of a mouse move event.
// The Placeholder has not been moved yet.
onDrag: function ($item, position, _super) {
$item.css(position);
$item.closest("ul").addClass("selectedUL");
//console.log("stuff");
},
// Called after the drag has been started,
// that is the mouse button is beeing held down and
// the mouse is moving.
// The container is the closest initialized container.
// Therefore it might not be the container, that actually contains the item.
onDragStart: function ($item, container, _super) {
$item.css({
height: $item.height(),
width: $item.width()
})
$item.addClass("dragged")
$("body").addClass("dragging")
},
// Called when the mouse button is beeing released
onDrop: function ($item, container, _super) {
$item.closest("ul").removeClass("selectedUL");
$item.removeClass("dragged").removeAttr("style")
$("body").removeClass("dragging")
},
// Called on mousedown.
onMousedown: function($item, event, _super) {
event.preventDefault()
},
// Template for the placeholder. Can be any valid jQuery input
// e.g. a string, a DOM element.
// The placeholder must have the class "placeholder"
placeholder: '<li class="placeholder" />', // #Jeremy: Edited from <li class="placeholder" />
// If true, the position of the placeholder is calculated on every mousemove.
// If false, it is only calculated when the mouse is above a container.
pullPlaceholder: true,
// Specifies serialization of the container group.
// The pair $parent/$children is either container/items or item/subcontainers.
// Note that this default method only works, if every item only has one subcontainer
serialize: function ($parent, $children, parentIsContainer) {
var result = $.extend({}, $parent.data())
if(parentIsContainer)
return $children
else if ($children[0]){
result.children = $children
delete result.subContainer
}
delete result.sortable
return result
},
// Set tolerance while dragging. Positive values decrease sensitivity,
// negative values increase it.
tolerance: 0
}, // end group defaults
containerGroups = {},
groupCounter = 0,
emptyBox = {
left: 0,
top: 0,
bottom: 0,
right:0
}
eventNames = {
start: "touchstart.sortable mousedown.sortable",
drop: "touchend.sortable touchcancel.sortable mouseup.sortable",
drag: "touchmove.sortable mousemove.sortable",
scroll: "scroll.sortable"
}
/*
* a is Array [left, right, top, bottom]
* b is array [left, top]
*/
function d(a,b) {
var x = Math.max(0, a[0] - b[0], b[0] - a[1]),
y = Math.max(0, a[2] - b[1], b[1] - a[3])
return x+y;
}
function setDimensions(array, dimensions, tolerance, useOffset) {
var i = array.length,
offsetMethod = useOffset ? "offset" : "position"
tolerance = tolerance || 0
while(i--){
var el = array[i].el ? array[i].el : $(array[i]),
// use fitting method
pos = el[offsetMethod]()
pos.left += parseInt(el.css('margin-left'), 10)
pos.top += parseInt(el.css('margin-top'),10)
dimensions[i] = [
pos.left - tolerance,
pos.left + el.outerWidth() + tolerance,
pos.top - tolerance,
pos.top + el.outerHeight() + tolerance
]
}
}
function getRelativePosition(pointer, element) {
var offset = element.offset()
return {
left: pointer.left - offset.left,
top: pointer.top - offset.top
}
}
function sortByDistanceDesc(dimensions, pointer, lastPointer) {
pointer = [pointer.left, pointer.top]
lastPointer = lastPointer && [lastPointer.left, lastPointer.top]
var dim,
i = dimensions.length,
distances = []
while(i--){
dim = dimensions[i]
distances[i] = [i,d(dim,pointer), lastPointer && d(dim, lastPointer)]
}
distances = distances.sort(function (a,b) {
return b[1] - a[1] || b[2] - a[2] || b[0] - a[0]
})
// last entry is the closest
return distances
}
function ContainerGroup(options) {
this.options = $.extend({}, groupDefaults, options)
this.containers = []
this.scrollProxy = $.proxy(this.scroll, this)
this.dragProxy = $.proxy(this.drag, this)
this.dropProxy = $.proxy(this.drop, this)
if(!this.options.parentContainer){
this.placeholder = $(this.options.placeholder)
if(!options.isValidTarget)
this.options.isValidTarget = undefined
}
}
ContainerGroup.get = function (options) {
if( !containerGroups[options.group]) {
if(!options.group)
options.group = groupCounter ++
containerGroups[options.group] = new ContainerGroup(options)
}
return containerGroups[options.group]
}
ContainerGroup.prototype = {
dragInit: function (e, itemContainer) {
this.$document = $(itemContainer.el[0].ownerDocument)
if(itemContainer.enabled()){
this.toggleListeners('on')
// get item to drag
this.item = $(e.target).closest(this.options.itemSelector)
this.itemContainer = itemContainer
this.setPointer(e)
this.options.onMousedown(this.item, e, groupDefaults.onMousedown)
} else {
this.toggleListeners('on', ['drop'])
}
this.dragInitDone = true
},
drag: function (e) {
if(!this.dragging){
if(!this.distanceMet(e))
return
this.options.onDragStart(this.item, this.itemContainer, groupDefaults.onDragStart)
this.item.before(this.placeholder)
this.dragging = true
}
this.setPointer(e)
// place item under the cursor
this.options.onDrag(this.item,
getRelativePosition(this.pointer, this.item.offsetParent()),
groupDefaults.onDrag)
var x = e.pageX,
y = e.pageY,
box = this.sameResultBox,
t = this.options.tolerance
if(!box || box.top - t > y || box.bottom + t < y || box.left - t > x || box.right + t < x)
if(!this.searchValidTarget())
this.placeholder.detach()
},
drop: function (e) {
this.toggleListeners('off')
this.dragInitDone = false
if(this.dragging){
// processing Drop, check if placeholder is detached
if(this.placeholder.closest("html")[0])
this.placeholder.before(this.item).detach()
else
this.options.onCancel(this.item, this.itemContainer, groupDefaults.onCancel)
this.options.onDrop(this.item, this.getContainer(this.item), groupDefaults.onDrop)
// cleanup
this.clearDimensions()
this.clearOffsetParent()
this.lastAppendedItem = this.sameResultBox = undefined
this.dragging = false
}
},
searchValidTarget: function (pointer, lastPointer) {
if(!pointer){
pointer = this.relativePointer || this.pointer
lastPointer = this.lastRelativePointer || this.lastPointer
}
var distances = sortByDistanceDesc(this.getContainerDimensions(),
pointer,
lastPointer),
i = distances.length
while(i--){
var index = distances[i][0],
distance = distances[i][1]
if(!distance || this.options.pullPlaceholder){
var container = this.containers[index]
if(!container.disabled){
if(!this.$getOffsetParent()){
var offsetParent = container.getItemOffsetParent()
pointer = getRelativePosition(pointer, offsetParent)
lastPointer = getRelativePosition(lastPointer, offsetParent)
}
if(container.searchValidTarget(pointer, lastPointer))
return true
}
}
}
if(this.sameResultBox)
this.sameResultBox = undefined
},
movePlaceholder: function (container, item, method, sameResultBox) {
var lastAppendedItem = this.lastAppendedItem
if(!sameResultBox && lastAppendedItem && lastAppendedItem[0] === item[0])
return;
item[method](this.placeholder)
this.lastAppendedItem = item
this.sameResultBox = sameResultBox
this.options.afterMove(this.placeholder, container)
},
getContainerDimensions: function () {
if(!this.containerDimensions)
setDimensions(this.containers, this.containerDimensions = [], this.options.tolerance, !this.$getOffsetParent())
return this.containerDimensions
},
getContainer: function (element) {
return element.closest(this.options.containerSelector).data(pluginName)
},
$getOffsetParent: function () {
if(this.offsetParent === undefined){
var i = this.containers.length - 1,
offsetParent = this.containers[i].getItemOffsetParent()
if(!this.options.parentContainer){
while(i--){
if(offsetParent[0] != this.containers[i].getItemOffsetParent()[0]){
// If every container has the same offset parent,
// use position() which is relative to this parent,
// otherwise use offset()
// compare #setDimensions
offsetParent = false
break;
}
}
}
this.offsetParent = offsetParent
}
return this.offsetParent
},
setPointer: function (e) {
console.log("setPointer")
var pointer = {
left: e.pageX,
top: e.pageY
}
if(this.$getOffsetParent()){
var relativePointer = getRelativePosition(pointer, this.$getOffsetParent())
this.lastRelativePointer = this.relativePointer
this.relativePointer = relativePointer
}
this.lastPointer = this.pointer
this.pointer = pointer
},
distanceMet: function (e) {
return (Math.max(
Math.abs(this.pointer.left - e.pageX),
Math.abs(this.pointer.top - e.pageY)
) >= this.options.distance)
},
scroll: function (e) {
this.clearDimensions()
this.clearOffsetParent()
},
toggleListeners: function (method, events) {
var that = this
events = events || ['drag','drop','scroll']
$.each(events,function (i,event) {
that.$document[method](eventNames[event], that[event + 'Proxy'])
})
},
clearOffsetParent: function () {
this.offsetParent = undefined
},
// Recursively clear container and item dimensions
clearDimensions: function () {
this.containerDimensions = undefined
var i = this.containers.length
while(i--){
this.containers[i].clearDimensions()
}
}
}
function Container(element, options) {
this.el = element
this.options = $.extend( {}, containerDefaults, options)
this.group = ContainerGroup.get(this.options)
this.rootGroup = this.options.rootGroup = this.options.rootGroup || this.group
this.parentContainer = this.options.parentContainer
this.handle = this.rootGroup.options.handle || this.rootGroup.options.itemSelector
this.el.on(eventNames.start, this.handle, $.proxy(this.dragInit, this))
if(this.options.drop)
this.group.containers.push(this)
}
Container.prototype = {
dragInit: function (e) {
var rootGroup = this.rootGroup
if( !rootGroup.dragInitDone &&
e.which === 1 &&
this.options.drag &&
!$(e.target).is(this.options.exclude))
rootGroup.dragInit(e, this)
},
searchValidTarget: function (pointer, lastPointer) {
var distances = sortByDistanceDesc(this.getItemDimensions(),
pointer,
lastPointer),
i = distances.length,
rootGroup = this.rootGroup,
validTarget = !rootGroup.options.isValidTarget ||
rootGroup.options.isValidTarget(rootGroup.item, this)
if(!i && validTarget){
rootGroup.movePlaceholder(this, this.el, "append")
return true
} else
while(i--){
var index = distances[i][0],
distance = distances[i][1]
if(!distance && this.hasChildGroup(index)){
var found = this.getContainerGroup(index).searchValidTarget(pointer, lastPointer)
if(found)
return true
}
else if(validTarget){
this.movePlaceholder(index, pointer)
return true
}
}
},
movePlaceholder: function (index, pointer) {
var item = $(this.items[index]),
dim = this.itemDimensions[index],
method = "after",
width = item.outerWidth(),
height = item.outerHeight(),
offset = item.offset(),
sameResultBox = {
left: offset.left,
right: offset.left + width,
top: offset.top,
bottom: offset.top + height
}
if(this.options.vertical){
var yCenter = (dim[2] + dim[3]) / 2,
inUpperHalf = pointer.top <= yCenter
if(inUpperHalf){
method = "before"
sameResultBox.bottom -= height / 2
} else
sameResultBox.top += height / 2
} else {
var xCenter = (dim[0] + dim[1]) / 2,
inLeftHalf = pointer.left <= xCenter
if(inLeftHalf){
method = "before"
sameResultBox.right -= width / 2
} else
sameResultBox.left += width / 2
}
if(this.hasChildGroup(index))
sameResultBox = emptyBox
this.rootGroup.movePlaceholder(this, item, method, sameResultBox)
},
getItemDimensions: function () {
if(!this.itemDimensions){
this.items = this.$getChildren(this.el, "item").filter(":not(.placeholder, .dragged)").get()
setDimensions(this.items, this.itemDimensions = [], this.options.tolerance)
}
return this.itemDimensions
},
getItemOffsetParent: function () {
var offsetParent,
el = this.el
// Since el might be empty we have to check el itself and
// can not do something like el.children().first().offsetParent()
if(el.css("position") === "relative" || el.css("position") === "absolute" || el.css("position") === "fixed")
offsetParent = el
else
offsetParent = el.offsetParent()
return offsetParent
},
hasChildGroup: function (index) {
return this.options.nested && this.getContainerGroup(index)
},
getContainerGroup: function (index) {
var childGroup = $.data(this.items[index], "subContainer")
if( childGroup === undefined){
var childContainers = this.$getChildren(this.items[index], "container")
childGroup = false
if(childContainers[0]){
var options = $.extend({}, this.options, {
parentContainer: this,
group: groupCounter ++
})
childGroup = childContainers[pluginName](options).data(pluginName).group
}
$.data(this.items[index], "subContainer", childGroup)
}
return childGroup
},
enabled: function () {
return !this.disabled && (!this.parentContainer || this.parentContainer.enabled())
},
$getChildren: function (parent, type) {
var options = this.rootGroup.options,
path = options[type + "Path"],
selector = options[type + "Selector"]
parent = $(parent)
if(path)
parent = parent.find(path)
return parent.children(selector)
},
_serialize: function (parent, isContainer) {
var that = this,
childType = isContainer ? "item" : "container",
children = this.$getChildren(parent, childType).not(this.options.exclude).map(function () {
return that._serialize($(this), !isContainer)
}).get()
return this.rootGroup.options.serialize(parent, children, isContainer)
},
clearDimensions: function () {
this.itemDimensions = undefined
if(this.items && this.items[0]){
var i = this.items.length
while(i--){
var group = $.data(this.items[i], "subContainer")
if(group)
group.clearDimensions()
}
}
}
}
var API = {
enable: function (ignoreChildren) {
this.disabled = false
},
disable: function (ignoreChildren) {
this.disabled = true
},
serialize: function () {
return this._serialize(this.el, true)
}
}
$.extend(Container.prototype, API)
/**
* jQuery API
*
* Parameters are
* either options on init
* or a method name followed by arguments to pass to the method
*/
$.fn[pluginName] = function(methodOrOptions) {
var args = Array.prototype.slice.call(arguments, 1)
return this.map(function(){
var $t = $(this),
object = $t.data(pluginName)
if(object && API[methodOrOptions])
return API[methodOrOptions].apply(object, args) || this
else if(!object && (methodOrOptions === undefined ||
typeof methodOrOptions === "object"))
$t.data(pluginName, new Container($t, methodOrOptions))
return this
});
};
}(jQuery, window)
-40
View File
@@ -1,40 +0,0 @@
$(function(){
$('.js-auto-expand').textareaAutoExpand();
// $('.main').nestable();
$('.handle').toolbar({
content: '#toolbar',
position: 'left',
hideOnClick: true
}).on('toolbarItemClick', function(e){
console.log('toolbar item clicked: ' + e.class);
});
// MathJax typesetter
typeset = function(nodeID){
MathJax.Hub.Queue(["Typeset", MathJax.Hub], nodeID);
};
// Bullet outline on hover
$('.handle a').hover(function(){
// mouse enter
$(this).children('img').attr('src', 'img/bullet-combined.png');
},
function(){
// mouse leave
$(this).children('img').attr('src', 'img/bullet-8.png');
});
// Fix for tab border-radius
// $('.ui-tabs .ui-tabs-nav li a').click(function(){
// var idx = $("ul li.ui-state-active").index();
// console.log(idx);
// if( idx !== 0){
// $('tabs-' + (idx+1)).css('border-radius', '5px 5px 5px 5px');
// }
// else{
// $('tabs-' + (idx+1)).css('border-radius', '0px 5px 5px 5px');
// }
// });
});
-60
View File
@@ -1,60 +0,0 @@
var bulletHash = [];
var rootBullets = [];
$(function() {
// Bullet class declaration
function Bullet (parentID, text) {
// If root bullet
if(parentID === -1){
this.ID = bulletHash.length;
this.text = text;
this.children = [];
bulletHash.push(this);
rootBullets.push(this.ID);
return;
}
this.ID = bulletHash.length;
this.text = text;
this.children = [];
bulletHash[parentID].children.push(this.ID);
bulletHash.push(this);
// load(this.ID)
return;
}
$(document).ready(function() {
new Bullet(-1, '')
// loadRoot(0);
console.log(bulletHash);
// bulletHash[0].children = new Array(); //So it doesn't have itself as a child.
// bulletHash[0].parents = [];
//I could replace this with an object literal...
for(var i = 0; i< 5; i++){
new Bullet(0, "bullet" + i);
// bulletHash[i].push(new Bullet(0,'bullet' + i));
console.log(bulletHash);
}
loadAll();
$("textarea").textareaAutoExpand();
});
//Load root nodes and all their children
function loadAll() {
for(var i = 0; i < rootBullets.length; i++){
var rootNodeID = rootBullets[i];
$(".root").append(JSONtoUI(bulletHash[rootNodeID]));
$("#"+rootNodeID).children(".subList").slideToggle(0); //This makes it so that you can hitTab with luke Skywalker and it will work.
loadChildren(rootNodeID);
}
}
function loadChildren(bulletID){
var childrenBullets = bulletHash[bulletID].children;
for(var i = 0; i < childrenBullets.length; i++){
var childID = childrenBullets[i];
$("#"+bulletID).children().filter(".subList").append( JSONtoUI( bulletHash[childID] ) );
$("#"+childID).parent().slideToggle(0); //this refers to the UL in which it's contained...(which, in the base case would hide the entire thing)
$("#"+childID).children(".subList").slideToggle(0); //This makes it so that you can hitTab with luke Skywalker and it will work.
loadChildren(childID);
}
}
});
-20
View File
@@ -1,20 +0,0 @@
/*
Rangy Text Inputs, a cross-browser textarea and text input library plug-in for jQuery.
Part of Rangy, a cross-browser JavaScript range and selection library
http://code.google.com/p/rangy/
Depends on jQuery 1.0 or later.
Copyright 2010, Tim Down
Licensed under the MIT license.
Version: 0.1.205
Build date: 5 November 2010
*/
(function(n){function o(e,g){var a=typeof e[g];return a==="function"||!!(a=="object"&&e[g])||a=="unknown"}function p(e,g,a){if(g<0)g+=e.value.length;if(typeof a=="undefined")a=g;if(a<0)a+=e.value.length;return{start:g,end:a}}function k(){return typeof document.body=="object"&&document.body?document.body:document.getElementsByTagName("body")[0]}var i,h,q,l,r,s,t,u,m;n(document).ready(function(){function e(a,b){return function(){var c=this.jquery?this[0]:this,d=c.nodeName.toLowerCase();if(c.nodeType==
1&&(d=="textarea"||d=="input"&&c.type=="text")){c=[c].concat(Array.prototype.slice.call(arguments));c=a.apply(this,c);if(!b)return c}if(b)return this}}var g=document.createElement("textarea");k().appendChild(g);if(typeof g.selectionStart!="undefined"&&typeof g.selectionEnd!="undefined"){i=function(a){return{start:a.selectionStart,end:a.selectionEnd,length:a.selectionEnd-a.selectionStart,text:a.value.slice(a.selectionStart,a.selectionEnd)}};h=function(a,b,c){b=p(a,b,c);a.selectionStart=b.start;a.selectionEnd=
b.end};m=function(a,b){if(b)a.selectionEnd=a.selectionStart;else a.selectionStart=a.selectionEnd}}else if(o(g,"createTextRange")&&typeof document.selection=="object"&&document.selection&&o(document.selection,"createRange")){i=function(a){var b=0,c=0,d,f,j;if((j=document.selection.createRange())&&j.parentElement()==a){f=a.value.length;d=a.value.replace(/\r\n/g,"\n");c=a.createTextRange();c.moveToBookmark(j.getBookmark());j=a.createTextRange();j.collapse(false);if(c.compareEndPoints("StartToEnd",j)>
-1)b=c=f;else{b=-c.moveStart("character",-f);b+=d.slice(0,b).split("\n").length-1;if(c.compareEndPoints("EndToEnd",j)>-1)c=f;else{c=-c.moveEnd("character",-f);c+=d.slice(0,c).split("\n").length-1}}}return{start:b,end:c,length:c-b,text:a.value.slice(b,c)}};h=function(a,b,c){b=p(a,b,c);c=a.createTextRange();var d=b.start-(a.value.slice(0,b.start).split("\r\n").length-1);c.collapse(true);if(b.start==b.end)c.move("character",d);else{c.moveEnd("character",b.end-(a.value.slice(0,b.end).split("\r\n").length-
1));c.moveStart("character",d)}c.select()};m=function(a,b){var c=document.selection.createRange();c.collapse(b);c.select()}}else{k().removeChild(g);window.console&&window.console.log&&window.console.log("TextInputs module for Rangy not supported in your browser. Reason: No means of finding text input caret position");return}k().removeChild(g);l=function(a,b,c,d){var f;if(b!=c){f=a.value;a.value=f.slice(0,b)+f.slice(c)}d&&h(a,b,b)};q=function(a){var b=i(a);l(a,b.start,b.end,true)};u=function(a){var b=
i(a),c;if(b.start!=b.end){c=a.value;a.value=c.slice(0,b.start)+c.slice(b.end)}h(a,b.start,b.start);return b.text};r=function(a,b,c,d){var f=a.value;a.value=f.slice(0,c)+b+f.slice(c);if(d){b=c+b.length;h(a,b,b)}};s=function(a,b){var c=i(a),d=a.value;a.value=d.slice(0,c.start)+b+d.slice(c.end);c=c.start+b.length;h(a,c,c)};t=function(a,b,c){var d=i(a),f=a.value;a.value=f.slice(0,d.start)+b+d.text+c+f.slice(d.end);b=d.start+b.length;h(a,b,b+d.length)};n.fn.extend({getSelection:e(i,false),setSelection:e(h,
true),collapseSelection:e(m,true),deleteSelectedText:e(q,true),deleteText:e(l,true),extractSelectedText:e(u,false),insertText:e(r,true),replaceSelectedText:e(s,true),surroundSelectedText:e(t,true)})})})(jQuery);
-243
View File
@@ -1,243 +0,0 @@
/**
* Toolbar.js
*
* @fileoverview jQuery plugin that creates tooltip style toolbars.
* @link http://paulkinzett.github.com/toolbar/
* @author Paul Kinzett (http://kinzett.co.nz/)
* @version 1.0.4
* @requires jQuery 1.7+
*
* @license jQuery Toolbar Plugin v1.0.4
* http://paulkinzett.github.com/toolbar/
* Copyright 2013 Paul Kinzett (http://kinzett.co.nz/)
* Released under the MIT license.
* <https://raw.github.com/paulkinzett/toolbar/master/LICENSE.txt>
*/
if ( typeof Object.create !== 'function' ) {
Object.create = function( obj ) {
function F() {}
F.prototype = obj;
return new F();
};
}
(function( $, window, document, undefined ) {
document.oncontextmenu = function() {return false;};
var ToolBar = {
init: function( options, elem ) {
var self = this;
self.elem = elem;
self.$elem = $( elem );
self.options = $.extend( {}, $.fn.toolbar.options, options );
self.toolbar = $('<div class="tool-container gradient" />')
.addClass('tool-'+self.options.position)
.addClass('tool-rounded')
.append('<div class="tool-items" />')
.append('<div class="arrow" />')
.appendTo('body')
.css('opacity', 0)
.hide();
self.toolbar_arrow = self.toolbar.find('.arrow');
self.initializeToolbar();
},
initializeToolbar: function() {
var self = this;
self.populateContent();
self.setTrigger();
self.toolbarWidth = self.toolbar.width();
},
setTrigger: function() {
var self = this;
self.$elem.on('mousedown', function(event) {
if(event.button == 2 && !self.toolbar.is(":visible")) {
self.show();
}
else {
self.hide();
}
});
if (self.options.hideOnClick) {
$('html').on("mousedown.toolbar", function ( event ) {
if (event.target != self.elem &&
self.$elem.has(event.target).length === 0 &&
self.toolbar.has(event.target).length === 0 &&
self.toolbar.is(":visible")) {
self.hide();
}
});
}
$(window).resize(function( event ) {
event.stopPropagation();
if ( self.toolbar.is(":visible") ) {
self.toolbarCss = self.getCoordinates(self.options.position, 20);
self.collisionDetection();
self.toolbar.css( self.toolbarCss );
self.toolbar_arrow.css( self.arrowCss );
}
});
},
populateContent: function() {
var self = this;
var location = self.toolbar.find('.tool-items');
var content = $(self.options.content).clone( true ).find('a').addClass('tool-item gradient');
location.html(content);
location.find('.tool-item').on('click', function(event) {
event.preventDefault();
self.$elem.trigger('toolbarItemClick', this);
});
},
calculatePosition: function() {
var self = this;
self.arrowCss = {};
self.toolbarCss = self.getCoordinates(self.options.position, 0);
self.toolbarCss.position = 'absolute';
self.toolbarCss.zIndex = self.options.zIndex;
self.collisionDetection();
self.toolbar.css(self.toolbarCss);
self.toolbar_arrow.css(self.arrowCss);
},
getCoordinates: function( position, adjustment ) {
var self = this;
self.coordinates = self.$elem.offset();
if (self.options.adjustment && self.options.adjustment[self.options.position]) {
adjustment = self.options.adjustment[self.options.position];
}
switch(self.options.position) {
case 'top':
return {
left: self.coordinates.left-(self.toolbar.width()/2)+(self.$elem.outerWidth()/2),
top: self.coordinates.top-self.$elem.height()-adjustment,
right: 'auto'
};
case 'left':
return {
left: self.coordinates.left-(self.toolbar.width()/2)-(self.$elem.width()/2)-adjustment,
top: self.coordinates.top-(self.toolbar.height()/2)+(self.$elem.outerHeight()/2),
right: 'auto'
};
case 'right':
return {
left: self.coordinates.left+(self.toolbar.width()/2)+(self.$elem.width()/3)+adjustment,
top: self.coordinates.top-(self.toolbar.height()/2)+(self.$elem.outerHeight()/2),
right: 'auto'
};
case 'bottom':
return {
left: self.coordinates.left-(self.toolbar.width()/2)+(self.$elem.outerWidth()/2),
top: self.coordinates.top+self.$elem.height()+adjustment,
right: 'auto'
};
}
},
collisionDetection: function() {
var self = this;
var edgeOffset = 20;
if(self.options.position == 'top' || self.options.position == 'bottom') {
self.arrowCss = {left: '50%', right: '50%'};
if( self.toolbarCss.left < edgeOffset ) {
self.toolbarCss.left = edgeOffset;
self.arrowCss.left = self.$elem.offset().left + self.$elem.width()/2-(edgeOffset);
}
else if(($(window).width() - (self.toolbarCss.left + self.toolbarWidth)) < edgeOffset) {
self.toolbarCss.right = edgeOffset;
self.toolbarCss.left = 'auto';
self.arrowCss.left = 'auto';
self.arrowCss.right = ($(window).width()-self.$elem.offset().left)-(self.$elem.width()/2)-(edgeOffset)-5;
}
}
},
show: function() {
var self = this;
var animation = {'opacity': 1};
self.$elem.addClass('pressed');
self.calculatePosition();
switch(self.options.position) {
case 'top':
animation.top = '-=20';
break;
case 'left':
animation.left = '-=20';
break;
case 'right':
animation.left = '+=20';
break;
case 'bottom':
animation.top = '+=20';
break;
}
self.toolbar.show().animate(animation, 200 );
self.$elem.trigger('toolbarShown');
},
hide: function() {
var self = this;
var animation = {'opacity': 0};
self.$elem.removeClass('pressed');
switch(self.options.position) {
case 'top':
animation.top = '+=20';
break;
case 'left':
animation.left = '+=20';
break;
case 'right':
animation.left = '-=20';
break;
case 'bottom':
animation.top = '-=20';
break;
}
self.toolbar.animate(animation, 200, function() {
self.toolbar.hide();
});
self.$elem.trigger('toolbarHidden');
},
getToolbarElement: function () {
return this.toolbar.find('.tool-items');
}
};
$.fn.toolbar = function( options ) {
if ($.isPlainObject( options )) {
return this.each(function() {
var toolbarObj = Object.create( ToolBar );
toolbarObj.init( options, this );
$(this).data('toolbarObj', toolbarObj);
});
} else if ( typeof options === 'string' && options.indexOf('_') !== 0 ) {
var toolbarObj = $(this).data('toolbarObj');
var method = toolbarObj[options];
return method.apply(toolbarObj, $.makeArray(arguments).slice(1));
}
};
$.fn.toolbar.options = {
content: '#myContent',
position: 'top',
hideOnClick: false,
zIndex: 120
};
}) ( jQuery, window, document );
+16 -12
View File
@@ -11,13 +11,18 @@
<script src="js/libs/externalLibs/jquery-2.0.3.js"></script>
<script src="socket.io/socket.io.js"></script>
<script src="js/libs/myLib/addNode.js"></script>
<script src="js/libs/myLib/removeNode.js"></script>
<script src="js/libs/myLib/KeyBoardLogic.js"></script>
<script src="js/libs/myLib/moveNode.js"></script>
<script src="js/libs/myLib/revControl.js"></script>
<script src="js/libs/myLogic/addNode.js"></script>
<script src="js/libs/myLogic/removeNode.js"></script>
<script src="js/libs/myLogic/KeyBoardLogic.js"></script>
<script src="js/libs/myLogic/moveNode.js"></script>
<script src="js/libs/myLogic/revControl.js"></script>
<script src="js/app.js"></script>
<script src="js/listeners/revListeners.js"></script>
<script src="js/listeners/editorListeners.js"></script>
@@ -42,11 +47,11 @@
<script src="js/libs/externalLibs/markdowneditor.js"></script>
<script src="js/models/node.js"></script>
<script src="js/collections/nodesCollection.js"></script>
<script src="js/views/listView.js"></script>
<script src="js/views/showView.js"></script>
<script src="js/router.js"></script>
<script src="js/backbone/models/node.js"></script>
<script src="js/backbone/collections/nodesCollection.js"></script>
<script src="js/backbone/views/listView.js"></script>
<script src="js/backbone/views/showView.js"></script>
<script src="js/backbone/router.js"></script>
@@ -95,8 +100,7 @@
</div>
</div>
<script src="js/tempFolder/bootstrap.js"></script>
<!-- <script src="js/tempFolder/startup.js"></script> -->
</body>
<script>
$(function(){