Skip to content

Loading…

Namespaces and menubutton work #1

Merged
merged 5 commits into from

1 participant

Commits on Oct 21, 2012
Commits on Nov 4, 2012
  1. Added bex-spec.md notes

    committed
Commits on Feb 27, 2013
This page is out of date. Refresh to see the latest.
View
2 .gitignore
@@ -0,0 +1,2 @@
+*~
+
View
48 bex-spec.md
@@ -0,0 +1,48 @@
+# BEX - Browser Editor for XML
+
+Node
+- Element
+- Text
+- Attribute
+- Other
+- List
+
+### Core methods
+
+#### Manipulation
+
+new
+insertBefore
+insertAfter
+appendNode
+setData
+setName
+unbind
+destroy
+
+List->
+remove
+
+#### Traversal
+
+children
+parent
+following
+preceding
+attributes
+name
+
+### Derived methods
+
+#### Manipulation
+
+moveBeforePrevious
+moveAfterNext
+moveAfterParent
+moveIntoPreceding
+append
+prepend
+before
+after
+
+$text->bisect ::= insertAfter, substring
View
34 html/test.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<head>
+ <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
+ <title>Test</title>
+<!-- <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/sunny/jquery-ui.css" /> -->
+ <link rel="stylesheet" type="text/css" href="../jquery/smoothness/jquery-ui-1.8.23.custom.css" />
+ <link rel="stylesheet" type="text/css" href="../css/ui.bextextnode.css"/>
+<!-- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
+ <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script> -->
+ <script src="../jquery/jquery-1.8.0.js"></script>
+ <script src="../jquery/jquery-ui-1.8.23.custom.min.js"></script>
+ <script src="../zc/zen_textarea.js"></script>
+ <script src="../js/bex.contents.js"></script>
+ <script src="../js/bex.childnode.js"></script>
+ <script src="../js/bex.parentnode.js"></script>
+ <script src="../js/bex.menubutton.js"></script>
+ <script src="../js/bex.textcontainer.js"></script>
+ <script src="../js/bex.textnode.js"></script>
+ <script src="../js/bex.commentnode.js"></script>
+ <script src="../js/bex.cdatasection.js"></script>
+ <script src="../js/bex.element.js"></script>
+ <script src="../js/bex.document.js"></script>
+ <script src="../js/bex.js"></script>
+</head>
+<body style="font-size: 1em; font-family:sans-serif;">
+ <!--
+ div.document>ul.contents>li>div.element>(ul.menu>li*3>a)+(dl.attributes>dt+dd)+ul.contents>li
+ -->
+
+ <textarea name="" id="bexme" cols="30" rows="10">&lt;root&gt;&lt;element/&gt;text&lt;element/&gt;&lt;comment&gt;<!-- this is a comment </body> -->&lt;/comment&gt;&lt;cdata&gt;<![CDATA[%{ <&$_> }]]>&lt;/cdata&gt;&lt;/root&gt;</textarea>
+
+</body>
+</html>
View
2 js/jquery.ui.bexcdatasection.js → js/bex.cdatasection.js
@@ -1,5 +1,5 @@
(function($) {
- $.widget("ui.bexcdatasection", {
+ $.widget("bex.bexcdatasection", {
options: {
},
View
2 js/jquery.ui.bexchildnode.js → js/bex.childnode.js
@@ -14,7 +14,7 @@ Used by:
*/
(function($) {
- $.widget("ui.bexchildnode", {
+ $.widget("bex.bexchildnode", {
options: {
},
View
2 js/jquery.ui.bexcommentnode.js → js/bex.commentnode.js
@@ -1,5 +1,5 @@
(function($) {
- $.widget("ui.bexcommentnode", {
+ $.widget("bex.bexcommentnode", {
options: {
},
View
0 js/bexcommon.js → js/bex.common.js
File renamed without changes.
View
2 js/jquery.ui.bexcontents.js → js/bex.contents.js
@@ -1,5 +1,5 @@
(function($) {
- $.widget("ui.bexcontents", {
+ $.widget("bex.bexcontents", {
options: {
},
_create: function() {
View
2 js/jquery.ui.bexdocument.js → js/bex.document.js
@@ -1,5 +1,5 @@
(function($) {
- $.widget("ui.bexdocument", {
+ $.widget("bex.bexdocument", {
options: {
},
_create: function() {
View
5 js/jquery.ui.bexelement.js → js/bex.element.js
@@ -1,5 +1,5 @@
(function($) {
- $.widget("ui.bexelement", {
+ $.widget("bex.bexelement", {
options: {
from: $('<element/>')
},
@@ -10,7 +10,8 @@
.addClass("ui-widget ui-widget-contents ui-helper-reset bex-element");
var bexheader = $('<div></div>').addClass("ui-widget-header ui-corner-all bex-element-header").appendTo(el);
el.bexparentnode().bexchildnode();
- var menu = $("<button></button>").bexmenubutton().appendTo(bexheader);
+ var menu = $("<button></button>").appendTo(bexheader);
+ el.bexmenubutton({"button": menu});
var bexnodename = $('<span></span>')
.text(o.from[0].nodeName)
.bextextcontainer({pattern:'[a-zA-Z][\w]*'})
View
64 js/jquery.ui.bexmenubutton.js → js/bex.menubutton.js
@@ -1,12 +1,20 @@
(function($) {
- $.widget("ui.bexmenubutton", {
+ var validName = "[a-zA-Z_][a-zA-Z_0-9\-]*";
+ var validBexName = "bex\.(menubutton|elementnode|childnode|documentnode|parentnode|[a-z]+)\.([a-zA-Z_][a-zA-Z_0-9\-]*)";
+ $.widget("bex.bexmenubutton", {
options: {
+ commands: {}
},
_create: function() {
var self = this;
var o = self.options;
- var el = self.element
- .button({
+ var el = self.element;
+ var button = self.options.button;
+ if (!typeof button){
+ button = $("<button></button>").appendTo(el)
+ }
+ self.button = button;
+ button.button({
text: false,
icons: {
primary: "ui-icon-triangle-1-s"
@@ -23,9 +31,9 @@
{
label: "Before Preceding",
action: function(){
- var controller = self.controller();
+ var controller = self.element;
$(controller).bexchildnode('precedingSibling').bexchildnode("insertPreceding", controller);
- $(self.element).focus();
+ $(self.button).focus();
}
}
]
@@ -33,7 +41,7 @@
{
label: "Delete",
action: function(){
- $(self.controller()).bexchildnode('removeNode');
+ $(self.element).bexchildnode('removeNode');
}
}
];
@@ -53,12 +61,12 @@
for (var i=0; i<menuoptions.length; i++){
add_menuoption(bexcontextmenu, menuoptions[i]);
}
- bexcontextmenu.menu().show().appendTo(self.controller());
+ bexcontextmenu.menu().show().appendTo(self.button);
})
/* Define the keyboard commands */
.keyup(function(e){
/* alert( "Keyup " + e.keyCode + " CtrlKey: "+e.ctrlKey); */
- var controller = self.controller();
+ var controller = self.element;
var keyCode = e.keyCode;
if (e.ctrlKey)
@@ -67,19 +75,19 @@
{
case 37: /*LEFT: Insert after parent*/
$(controller).bexchildnode('parent').bexchildnode("insertFollowing", controller);
- $(self.element).focus();
+ $(self.button).focus();
break;
case 38: /*UP: Insert before previous*/
$(controller).bexchildnode('precedingSibling').bexchildnode("insertPreceding", controller);
- $(self.element).focus();
+ $(self.button).focus();
break;
case 39: /*RIGHT: Append to previous*/
$(controller).bexchildnode('precedingSibling').bexparentnode("append", controller);
- $(self.element).focus();
+ $(self.button).focus();
break;
case 40: /*DOWN: Insert after following */
$(controller).bexchildnode('followingSibling').bexchildnode("insertFollowing", controller);
- $(self.element).focus();
+ $(self.button).focus();
break;
case 46: /*DELETE*/
$( "#bex-dlg-confirm-delete" ).dialog({
@@ -88,8 +96,8 @@
modal: true,
title: 'Confirm node deletion',
close: function(){
- if (self.element){
- self.element.focus();
+ if (self.button){
+ self.button.focus();
}
},
buttons: {
@@ -108,8 +116,8 @@
modal: true,
title: 'Insert Node',
close: function(){
- if (self.element){
- self.element.focus();
+ if (self.button){
+ self.button.focus();
}
},
buttons: {
@@ -164,9 +172,23 @@
});
return self;
},
- controller: function() {
+ addCommand: function(command) {
var self = this;
- return $(self.element).parents('.bex-textnode, .bex-element').first();
+ var commands = self.commands;
+ commands[command.name] = command;
+ /*
+ if (command.name && validName.match(command.name)){
+ self.commands[command.name] = command;
+ }
+ if (command.name && validBexName.match(command.name)){
+ command.action = function () {self.element[ns](method)}
+ self.commands[command.name] = command;
+ }*/
+ return self;
+ },
+ execCommand: function(commandName){
+ var self = this;
+ self.commands[commandName](self);
},
destroy: function() {
@@ -180,10 +202,10 @@
/*
- TODO: Make bexmenubutton apply to the controlling element. It will either find and use an existing button as the button or, if it cannot, it will just append a button.
-
+ DONE: Make bexmenubutton apply to the controlling element. It will either find and use an existing button as the button or, if it cannot, it will just append a button.
+
Commands are always user-facing and if they require parameters, will demand them.
-
+ TODO: Write the following methods
addCommand ( {
name: 'insertBefore',
action: function(){}
View
2 js/jquery.ui.bexparentnode.js → js/bex.parentnode.js
@@ -1,5 +1,5 @@
(function($) {
- $.widget("ui.bexparentnode", {
+ $.widget("bex.bexparentnode", {
options: {
},
_create: function() {
View
2 js/jquery.ui.bextextcontainer.js → js/bex.textcontainer.js
@@ -1,5 +1,5 @@
(function($) {
- $.widget("ui.bextextcontainer", {
+ $.widget("bex.bextextcontainer", {
options: {
pattern: ''
},
View
5 js/jquery.ui.bextextnode.js~ → js/bex.textnode.js
@@ -1,5 +1,5 @@
(function($) {
- $.widget("ui.bextextnode", {
+ $.widget("bex.bextextnode", {
options: {
},
@@ -12,8 +12,9 @@
.addClass("ui-widget bex-textnode ui-helper-reset")
.bexchildnode();
var
- menu = $("<button></button>").bexmenubutton().appendTo(el),
+ menu = $("<button></button>").appendTo(el),
textcontainer = $("<span></span>").text(textcontent).bextextcontainer().appendTo(el);
+ el.bexmenubutton({"button": menu})
self._trigger("added", null);
return self;
},
View
26 js/bexcommon.js~
@@ -1,26 +0,0 @@
-(function( $ ){
-
- var methods = {
- parseXMLText : function( content ) {
- // !!!
- }
- parseXMLElement : function( content ) {
- // !!!
- }
- };
-
- $.fn.bex = function( method ) {
-
- // Method calling logic
- if ( methods[method] ) {
- return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
- } else if ( typeof method === 'object' || ! method ) {
- return methods.init.apply( this, arguments );
- } else {
- $.error( 'Method ' + method + ' does not exist on jQuery.bex' );
- }
-
- };
-
-})( jQuery );
-
View
24 js/jquery.ui.bexcdatasection.js~
@@ -1,24 +0,0 @@
-(function($) {
- $.widget("ui.bexcdatasection", {
- options: {
-
- },
- _create: function() {
- $(this.element).bextextnode().addClass('bex-cdatasection ui-state-highlight');
- return this;
- },
- xml: function(){
- $(this.element).bextextnode('sleep');
- var cdata = $(this.element).find(".bex-textcontainer")[0].textContent;
- cdata.replace(']]>', ']]&gt;');
- return '<![CDATA['+ cdata + ']]>';
- },
- destroy: function(){
- $(this.element).removeClass('bex-cdatasection ui-state-highlight');
- }
- _setOption: function(option, value) {
- $.Widget.prototype._setOption.apply( this, arguments );
-
- }
- });
-})(jQuery);
View
77 js/jquery.ui.bexchildnode.js~
@@ -1,77 +0,0 @@
-/*
-
-Child Node
-
-Provides methods relating to a node's role as a child of an element or of the document root, for instance "parent" and "insertPreceding".
-
-Used by:
-
-* Element Nodes
-* Text Nodes
-* CDATA Sections
-* Comment nodes
-* Processing instructions
-
-*/
-(function($) {
- $.widget("ui.bexchildnode", {
- options: {
-
- },
- _create: function() {
- var self = this;
- return self;
- },
- parent: function(){
- var self = this;
- return $(self.element).parents('.bex-element,.bex-document').first();
- },
- ancestors: function(){ /*todo: add optional selector*/
- var self = this;
- return $(self.element).parents('.bex-element,.bex-document');
- },
- precedingSibling: function(){ /*todo: add optional selector*/
- var self = this;
- return $(self.element).prev();
- },
- precedingSiblings: function(){ /*todo: add optional selector*/
- var self = this;
- return $(self.element).prevAll();
- },
- followingSibling: function(){ /*todo: add optional selector*/
- var self = this;
- return $(self.element).next();
- },
- followingSiblings: function(){ /*todo: add optional selector*/
- var self = this;
- return self.nextAll();
- },
- insertPreceding: function(newNode){
- var self = this;
- /*todo: check if newNode is ok*/
- return $(self.element).before(newNode);
- },
- insertFollowing: function(newNode){
- var self = this;
- /*todo: check if newNode is ok*/
- return $(self.element).after(newNode);
- },
- removeNode: function() {
- var focusfallback = $(this.element).bexchildnode('followingSibling');
- if (!$(focusfallback).is('li')){
- focusfallback = $(this.element).bexchildnode('precedingSibling')
- }
- if (!$(focusfallback).is('li')) {
- focusfallback = $(this.element).bexchildnode('parent');
- }
- this.element.remove();
- $(focusfallback).find('button').first().focus();
- },
- destroy: function() {
-
- },
- _setOption: function(option, value) {
- $.Widget.prototype._setOption.apply( this, arguments );
- }
- });
-})(jQuery);
View
21 js/jquery.ui.bexcommentnode.js~
@@ -1,21 +0,0 @@
-(function($) {
- $.widget("ui.bexcommentnode", {
- options: {
-
- },
- _create: function() {
- $(this.element).bextextnode().addClass('bex-commentnode ui-state-disabled');
- return this;
- },
- xml: function(){
- $(this.element).bextextnode('sleep');
- return '<!--'+$(this.element).find(".bex-textcontainer")[0].textContent + '-->';
- },
- destroy: function(){
- $(this.element).removeClass('bex-commentnode ui-state-highlight');
- }
- _setOption: function(option, value) {
- $.Widget.prototype._setOption.apply( this, arguments );
- }
- });
-})(jQuery);
View
26 js/jquery.ui.bexcontents.js~
@@ -1,26 +0,0 @@
-(function($) {
- $.widget("ui.bextextcontainer", {
- options: {
- },
- _create: function() {
-
- var self = this,
- o = self.options,
- el = self.element
- .addClass("ui-helper-reset bex-contents")
- .sortable({
- connectWith: ".bex-contents",
- placeholder: "ui-state-highlight"
- })
- .disableSelection();
- return self;
- },
- destroy: function() {
- this.sleep();
- },
- _setOption: function(option, value) {
- $.Widget.prototype._setOption.apply( this, arguments );
-
- }
- });
-})(jQuery);
View
104 js/jquery.ui.bexdocument.js~
@@ -1,104 +0,0 @@
-(function($) {
- $.widget("ui.bexdocument", {
- options: {
- },
- _create: function() {
-
- var self = this;
- var o = self.options;
- var el = self.element;
-
-
- self.bexdocument = $('<div></div>')
- .addClass("ui-widget ui-widget-contents ui-helper-reset bex-document")
- .insertAfter(el).append(el);
- self.bexpreview = $('<div></div>')
- .addClass("ui-widget ui-widget-contents ui-helper-reset bex-preview")
- .appendTo(self.bexdocument);
- self.bexheader = $('<div></div>')
- .addClass("ui-widget-header ui-corner-all bex-document-header")
- .prependTo(self.bexdocument)
- .append(
- $('<button class="bex-show-tree">Tree</button>').button().click(function(){
- self.showtree();
- })
- )
- .append(
- $('<button class="bex-show-source">Source</button>').button().click(function(){
- self.showsource();
- })
- )
- .append(
- $('<button class="bex-show-preview">Preview</button>').button().click(function(){
- self.showpreview();
- })
- );
- $(self.bexdocument).bexparentnode();
- self.showtree();
- var bexdialogconfirmdelete = $('<div id="bex-dlg-confirm-delete"></div>').hide().appendTo(self.bexdocument);
- var bexdialoginsertnode = $('<div id="bex-dlg-insert">\
-<form>\
- <div id="bex-insert-location">\
- <input type="radio" id="insertPreceding" value="insertPreceding" name="bex-insert-location" /><label for="insertPreceding">Preceding</label>\
- <input type="radio" id="insertFollowing" value="insertFollowing" name="bex-insert-location"" /><label for="insertFollowing">Following</label>\
- <br/>\
- <input type="radio" id="append" value="append" name="bex-insert-location" checked="checked" /><label for="append">Append</label>\
- <input type="radio" id="prepend" value="prepend" name="bex-insert-location" /><label for="prepend">Prepend</label>\
- <br/>\
- <input type="radio" id="aroundSelf" name="bex-insert-location" /><label for="aroundSelf">Around</label>\
- <input type="radio" id="aroundContents" name="bex-insert-location" /><label for="aroundContents">Wrap Contents</label>\
- <textarea id="bex-xmlforinsertion" type="text"/>\
- </div>\
-</form>\
-</div>').hide().appendTo(self.bexdocument);
- $('#bex-insert-location').buttonset();
- zen_textarea.setup({pretty_break: true, use_tab: false});
- return self;
- },
- showpreview: function(){
- $(this.element).hide();
- $(this.bexdocument).find('>ul').hide();
- $(this.bexpreview).show();
- $(this.bexpreview).html(this.xmlpreview());
- },
- showtree: function(){
- this.tree();
- $(this.element).hide();
- $(this.bexpreview).hide();
- $(this.bexdocument).find('>ul').show();
- },
- showsource: function(){
- $(this.bexpreview).hide();
- $(this.bexdocument).find('>ul').hide();
- $(this.element).show().val(this.xml());
- },
- xml: function(){
- var source = '';
- $(this.bexdocument).bexparentnode("children").each(function(){
- source += $(this).bexelement('xml');
- });
- return source;
- },
- xmlpreview: function(){
- return this.xml(); // TODO: Add a callback so that users can insert their own XSLT.
- },
- tree: function(){
- var xml = $(this.element).val();
- var xmldoc = $.parseXML(xml);
- var root = $(xmldoc.documentElement);
- $(this.bexdocument).find('>ul').empty();
- $(this.bexdocument).bexparentnode(
- "append",
- $("<li></li>")
- .bexelement({"from": root})
- ).find('button').first().focus();
- },
- destroy: function() {
- this.element.after('.bex-document').first.unbindNode();
- },
- _setOption: function(option, value) {
- $.Widget.prototype._setOption.apply( this, arguments );
-
- }
- });
-})(jQuery);
View
116 js/jquery.ui.bexelement.js~
@@ -1,116 +0,0 @@
-(function($) {
- $.widget("ui.bexelement", {
- options: {
- from: $('<element/>')
- },
- _create: function() {
- var self = this;
- var o = self.options;
- var el = self.element
- .addClass("ui-widget ui-widget-contents ui-helper-reset bex-element");
- var bexheader = $('<div></div>').addClass("ui-widget-header ui-corner-all bex-element-header").appendTo(el);
- el.bexparentnode().bexchildnode();
- var menu = $("<button></button>").bexmenubutton().appendTo(bexheader);
- var bexnodename = $('<span></span>')
- .text(o.from[0].nodeName)
- .bextextcontainer({pattern:'[a-zA-Z][\w]*'})
- .addClass("bex-element-name")
- .appendTo(bexheader);
- self.bexnodename = bexnodename;
- $(o.from).contents().each(function(){ /*use contents().each() then determine nodetype*/
- if (this.nodeType == 1)
- {
- $(self.element).bexparentnode(
- "append", $("<li></li>").bexelement({from: $(this)})
- );
- }
- else if (this.nodeType == 3)
- {
- $(self.element).bexparentnode(
- "append", $("<li></li>").text(this.data).bextextnode()
- );
- }
- else if (this.nodeType == 4)
- {
- $(self.element).bexparentnode(
- "append", $("<li></li>").text(this.data).bexcdatasection()
- );
- }
- else if (this.nodeType == 8)
- {
- $(self.element).bexparentnode(
- "append", $("<li></li>").text(this.data).bexcommentnode()
- );
- }
- else
- {
- alert("Don't know how to handle node type " + this.nodeType);
- }
- });
- return self;
- },
- insertPreceding: function(newNode){
- var self = this;
- /*todo: check if newNode is ok*/
- return $(self.element).before(newNode);
- },
- insertFollowing: function(newNode){
- var self = this;
- /*todo: check if newNode is ok*/
- return $(self.element).after(newNode);
- },
- nodeName: function(){ /*todo: add optional selector*/
- var self = this;
- return $(self.bexnodename).bextextcontainer('val');
- },
- /*
- Todo: core methods
- insertBefore
- insertAfter
- appendNode
- setData
- setName
- unbind
- */
- xml: function(){
- var self = this;
- var xml = '<' + self.nodeName();
- /* attributes*/
-
- var children = self.element.bexparentnode('children');
- if (children.length>0) {
- xml += '>';
- children.each(function(){
- if ($(this).is('.bex-element'))
- {
- xml += $(this).bexelement('xml');
- }
- else if ($(this).is('.bex-commentnode'))
- {
- xml += $(this).bexcommentnode('xml');
- }
- else if ($(this).is('.bex-cdatasection'))
- {
- xml += $(this).bexcdatasection('xml');
- }
- else if ($(this).is('.bex-textnode'))
- {
- xml += $(this).bextextnode('xml');
- }
- });
- xml +='</'+self.nodeName()+'>';
- }
- else {
- xml += '/>';
- }
- return xml;
-
- },
- destroy: function() {
-
- },
- _setOption: function(option, value) {
- $.Widget.prototype._setOption.apply( this, arguments );
- }
- });
-})(jQuery);
View
208 js/jquery.ui.bexmenubutton.js~
@@ -1,208 +0,0 @@
-(function($) {
- $.widget("ui.bexmenubutton", {
- options: {
- },
- _create: function() {
- var self = this;
- var o = self.options;
- var el = self.element
- .button({
- text: false,
- icons: {
- primary: "ui-icon-triangle-1-s"
- }
- })
- .addClass("bex-handle ui-corner-left")
- .removeClass("ui-corner-all")
- .click(function(){
- /* todo: menu here */
- var menuoptions = [
- {
- label: "Move...",
- contains: [
- {
- label: "Before Preceding",
- action: function(){
- var controller = self.controller();
- $(controller).bexchildnode('precedingSibling').bexchildnode("insertPreceding", controller);
- $(self.element).focus();
- }
- }
- ]
- },
- {
- label: "Delete",
- action: function(){
- $(self.controller()).bexchildnode('removeNode');
- }
- }
- ];
- $('.bex-contextmenu').remove();
- var bexcontextmenu = $('<ul class="bex-contextmenu"></ul>');
- var add_menuoption = function(menu, menuoption){
- var listitem = $('<li></li>');
- listitem.append($('<a href="#"></a>').text(menuoption.label).click(menuoption.action));
- if (menuoption.contains !== undefined && menuoption.contains.length > 0) {
- var newmenu = $('<ul></ul>').appendTo(listitem);
- for (var i=0; i<menuoption.contains.length; i++) {
- add_menuoption(newmenu, menuoption.contains[i]);
- }
- }
- menu.append(listitem);
- };
- for (var i=0; i<menuoptions.length; i++){
- add_menuoption(bexcontextmenu, menuoptions[i]);
- }
- bexcontextmenu.menu().show().appendTo(self.controller());
- })
- /* Define the keyboard commands */
- .keyup(function(e){
- /* alert( "Keyup " + e.keyCode + " CtrlKey: "+e.ctrlKey); */
- var controller = self.controller();
- var keyCode = e.keyCode;
-
- if (e.ctrlKey)
- {
- switch (keyCode)
- {
- case 37: /*LEFT: Insert after parent*/
- $(controller).bexchildnode('parent').bexchildnode("insertFollowing", controller);
- $(self.element).focus();
- break;
- case 38: /*UP: Insert before previous*/
- $(controller).bexchildnode('precedingSibling').bexchildnode("insertPreceding", controller);
- $(self.element).focus();
- break;
- case 39: /*RIGHT: Append to previous*/
- $(controller).bexchildnode('precedingSibling').bexparentnode("append", controller);
- $(self.element).focus();
- break;
- case 40: /*DOWN: Insert after following */
- $(controller).bexchildnode('followingSibling').bexchildnode("insertFollowing", controller);
- $(self.element).focus();
- break;
- case 46: /*DELETE*/
- $( "#bex-dlg-confirm-delete" ).dialog({
- resizable: false,
- height: 140,
- modal: true,
- title: 'Confirm node deletion',
- close: function(){
- if (self.element){
- self.element.focus();
- }
- },
- buttons: {
- "Delete": function() {
- $(controller).bexchildnode('removeNode');
- $( this ).dialog( "close" );
- },
- "Cancel": function() {
- $( this ).dialog( "close" );
- }
- }
- });
- break;
- case 73: /* CTRL + I */
- $( "#bex-dlg-insert" ).dialog({
- modal: true,
- title: 'Insert Node',
- close: function(){
- if (self.element){
- self.element.focus();
- }
- },
- buttons: {
- "Add Element": function() {
- var xmlforinsertion = '' + $( this ).find('#bex-xmlforinsertion').val();
- if(xmlforinsertion == '' ){xmlforinsertion = '<element/>';}
- var method = $( this ).find(':checked').val();
- /* alert (method+' ' + xmlforinsertion); */
- $(controller).bexparentnode(
- method,
- $('<li/>')
- .bexelement(
- {'from': $($.parseXML(xmlforinsertion).documentElement) }
- )
- );
- $( this ).dialog( "close" );
- },
- "Cancel": function() {
- $( this ).dialog( "close" );
- }
- }
- });
- break;
-
- }
- }
- else{
- switch (keyCode)
- {
- case 37: /*LEFT: focus on parentnode */
- $(controller).bexchildnode('parent').find('button').first().focus();
- break;
- case 38: /*UP: Focus on preceding sibling */
- $(controller).bexchildnode('precedingSibling').find('button').first().focus();
- break;
- case 39: /*RIGHT: Focus on first child OR edit text node*/
- if ($(controller).is('.bex-textnode'))
- {
- $(controller).bextextnode('wake');
- }
- else if ($(controller).is('.bex-element') && $(controller).bexparentnode('children').length > 0)
- {
- $(controller).bexparentnode('children').first().find('button').first().focus();
- }
- break;
- case 40: /*DOWN: Focus on following sibling */
- $(controller).bexchildnode('followingSibling').find('button').first().focus();
- break;
- }
-
- }
- });
- return self;
- },
- controller: function() {
- var self = this;
- return $(self.element).parents('.bex-textnode, .bex-element').first();
- },
- destroy: function() {
-
- },
- _setOption: function(option, value) {
- $.Widget.prototype._setOption.apply( this, arguments );
-
- }
- });
-})(jQuery);
-
-/*
-
- TODO: Make bexmenubutton apply to the controlling element. It will either find and use an existing button as the button or, if it cannot, it will just append a button.
-
- Commands are always user-facing and if they require parameters, will demand them.
-
- addCommand ( {
- name: 'insertBefore',
- action: function(){}
- }); # also overwrites existing commands.
- removeCommand ( {
- name: 'insertBefore',
- }); # also iterates through the menu and keyboard shortcuts and unbinds them.
- replaceCommand # alias for addCommand
- addMenuCommand ({
- name: 'insertBeforePreceding'
- path: []
- action: function(){} | commandName ==> function(){execCommand()}
- });
- addKeyboardShortcut ({
- ctrl: 1,
- keyCode: 39
- action: function(){} | commandName ==> function(){execCommand()}
- });
- execCommand ({
-
- });
-*/
View
40 js/jquery.ui.bexparentnode.js~
@@ -1,40 +0,0 @@
-(function($) {
- $.widget("ui.bexparentnode", {
- options: {
- },
- _create: function() {
- /*self._trigger("added", null);*/
- var self = this;
- var bexcontents = $('<ul></ul>')
- .addClass("ui-helper-reset bex-contents")
- .sortable({
- connectWith: ".bex-contents",
- placeholder: "ui-state-highlight"
- })
- .appendTo(self.element)
- .disableSelection();
- self.bexcontents = bexcontents;
- alert (self.element.html());
- return this;
- },
- append: function(newNode){
- var self = this;
- /*todo: check if newNode is ok*/
- return $(self.bexcontents).append(newNode);
- },
- prepend: function(newNode){
- var self = this;
- /*todo: check if newNode is ok*/
- return $(self.bexcontents).prepend(newNode);
- },
- children: function(){
- var self = this;
- return $(self.bexcontents).children();
- },
- destroy: function() {
- },
- _setOption: function(option, value) {
- $.Widget.prototype._setOption.apply( this, arguments );
- }
- });
-})(jQuery);
View
42 js/jquery.ui.bextextnode.js
@@ -1,42 +0,0 @@
-(function($) {
- $.widget("ui.bextextnode", {
- options: {
-
- },
- _create: function() {
- var self = this,
- o = self.options,
- el = self.element,
- textcontent = el.text();
- el .empty()
- .addClass("ui-widget bex-textnode ui-helper-reset")
- .bexchildnode();
- var
- menu = $("<button></button>").bexmenubutton().appendTo(el),
- textcontainer = $("<span></span>").text(textcontent).bextextcontainer().appendTo(el);
- self._trigger("added", null);
- return self;
- },
- wake: function() {
- var textcontainer = this.element.find(".bex-textcontainer");
- textcontainer.bextextcontainer('wake');
- return this;
- },
- sleep: function() {
- var textcontainer = this.element.find(".bex-textcontainer");
- textcontainer.bextextcontainer('sleep');
- return this;
- },
- destroy: function() {
- var textcontent = this.element.find(".bex-textcontainer").text();
- this.element.empty().text(textcontent);
- },
- xml: function(){
- return this.sleep().element.find(".bex-textcontainer")[0].innerHTML;
- },
- _setOption: function(option, value) {
- $.Widget.prototype._setOption.apply( this, arguments );
-
- }
- });
-})(jQuery);
Something went wrong with that request. Please try again.