diff options
author | Kandrashin Denis <mail@lintest.ru> | 2012-09-20 14:49:01 +0400 |
---|---|---|
committer | Kandrashin Denis <mail@lintest.ru> | 2012-09-20 14:49:01 +0400 |
commit | 3f1648290b694f3641d7879021b8df4a3163708a (patch) | |
tree | 7bfe7b4983f683e49b1d78051f647fea6e149f5e /source/js | |
parent | def2b74da504624aede4bea1d174152d7c7fc394 (diff) |
Create section: undo, redo action
Diffstat (limited to 'source/js')
-rw-r--r-- | source/js/get_location.js | 9 | ||||
-rw-r--r-- | source/js/get_status.js | 2 | ||||
-rw-r--r-- | source/js/javascript.qrc | 5 | ||||
-rw-r--r-- | source/js/location.js | 11 | ||||
-rw-r--r-- | source/js/section_get.js (renamed from source/js/new_section.js) | 20 | ||||
-rw-r--r-- | source/js/section_new.js | 14 |
6 files changed, 35 insertions, 26 deletions
diff --git a/source/js/get_location.js b/source/js/get_location.js deleted file mode 100644 index d0ef097..0000000 --- a/source/js/get_location.js +++ /dev/null @@ -1,9 +0,0 @@ -// create a reverse function for jQuery
-$.fn.reverse = [].reverse;
-var hierarchy = $(element).parents().reverse().add($(element));
-hierarchy.map(function () {
- var parent = $(this).parent();
- if (undefined !== parent.get( 0 ).tagName) {
- return parent.get(0).tagName + "=" + parent.children().index(this);
- }
-}).get().join(",");
diff --git a/source/js/get_status.js b/source/js/get_status.js index 30e7779..63b9a71 100644 --- a/source/js/get_status.js +++ b/source/js/get_status.js @@ -6,4 +6,4 @@ if (baseNode === null) ''; else { if (tag === 'DIV') tag = node.getAttribute('CLASS'); return f(node.parentNode) + '/' + tag; })(baseNode.parentNode); -}
\ No newline at end of file +} diff --git a/source/js/javascript.qrc b/source/js/javascript.qrc index 8590381..d9c5a3f 100644 --- a/source/js/javascript.qrc +++ b/source/js/javascript.qrc @@ -3,9 +3,10 @@ <file alias="jquery.js">../../3rdparty/jQuery/jquery.js</file> <file>export.js</file> <file>get_status.js</file> - <file>get_location.js</file> <file>set_cursor.js</file> <file>insert_title.js</file> - <file>new_section.js</file> + <file>location.js</file> + <file>section_get.js</file> + <file>section_new.js</file> </qresource> </RCC> diff --git a/source/js/location.js b/source/js/location.js new file mode 100644 index 0000000..73c2823 --- /dev/null +++ b/source/js/location.js @@ -0,0 +1,11 @@ +function location(e){ +$.fn.reverse = [].reverse; +var h=$(e).parents().reverse().add($(e)); +var f=function(){ + var p=$(this).parent(); + var t=p.get(0).tagName; + if(t===undefined)return; + return t+"="+p.children().index(this); +}; +return h.map(f).get().join(","); +}; diff --git a/source/js/new_section.js b/source/js/section_get.js index 0583d23..ac1b34a 100644 --- a/source/js/new_section.js +++ b/source/js/section_get.js @@ -1,15 +1,15 @@ -(function(){ -if(window.getSelection().rangeCount===0)return; +(f=function(){ var selection=window.getSelection(); +if(selection.rangeCount===0)return; var range=selection.getRangeAt(0); var root=range.commonAncestorContainer; var start=range.startContainer; var end=range.endContainer; while (true) { if(root===null)return; - tag=root.nodeName.toLowerCase(); - if(tag==="body")return; - if(tag==="div"){ + tag=root.tagName; + if(tag==="BODY")return; + if(tag==="DIV"){ type=root.className.toLowerCase(); if(type==="body"||type==="section")break; } @@ -23,13 +23,5 @@ while(end.parentNode!==root) { if(end===null)return; end=end.parentNode; } -range=document.createRange(); -range.setStartBefore(start); -range.setEndAfter(end); -var newNode=document.createElement("div"); -newNode.className="section"; -range.surroundContents(newNode); -range.setEndBefore(start); -selection.removeAllRanges(); -selection.addRange(range); +return location(root) + "|" + $(root).children().index(start) + "," + $(root).children().index(end); })() diff --git a/source/js/section_new.js b/source/js/section_new.js new file mode 100644 index 0000000..70bc430 --- /dev/null +++ b/source/js/section_new.js @@ -0,0 +1,14 @@ +f=function(elem,start, end){ +start=$(elem).children().get(start); +end=$(elem).children().get(end); +var range=document.createRange(); +range.setStartBefore(start); +range.setEndAfter(end); +var newNode=document.createElement("div"); +newNode.className="section"; +range.surroundContents(newNode); +range.setEndBefore(start); +var selection=window.getSelection(); +selection.removeAllRanges(); +selection.addRange(range); +}; |