23 |
24 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Tim Down
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/test/highlightertests.js:
--------------------------------------------------------------------------------
1 | xn.test.suite("Highlighter module tests", function(s) {
2 | s.tearDown = function() {
3 | document.getElementById("test").innerHTML = "";
4 | };
5 |
6 | s.test("highlightSelection test", function(t) {
7 | var applier = rangy.createClassApplier("c1");
8 | var highlighter = rangy.createHighlighter();
9 | highlighter.addClassApplier(applier);
10 |
11 | var testEl = document.getElementById("test");
12 | var range = rangyTestUtils.createRangeInHtml(testEl, 'one [two] three four');
13 | range.select();
14 |
15 | var highlights = highlighter.highlightSelection("c1");
16 |
17 | t.assertEquals(highlights.length, 1);
18 |
19 |
20 | //t.assertEquals(highlights.length, 1);
21 |
22 |
23 | });
24 |
25 | s.test("Options test (issue 249)", function(t) {
26 | var applier = rangy.createClassApplier("c1");
27 | var highlighter = rangy.createHighlighter();
28 | highlighter.addClassApplier(applier);
29 |
30 | highlighter.highlightSelection("c1", { selection: rangy.getSelection() });
31 | });
32 |
33 | }, false);
34 |
--------------------------------------------------------------------------------
/test/textareatests.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Rangy - Tests
6 |
7 |
8 |
15 |
16 |
17 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/fiddlings/218.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
42 | Pictures of Steve Claridge:
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/roadmap.txt:
--------------------------------------------------------------------------------
1 | 1.3
2 | ---
3 |
4 | - [X] TextRange module
5 | (http://groups.google.com/group/rangy/browse_frm/thread/bd7a351e63a16474)
6 | - [X] Allow Window, Document, iframe and DOM node as params to range/selection creation methods
7 | - [X] Add rangy.features.implementsWinGetSelection and rangy.features.implementsDocSelection
8 | - [X] Check Range and Selection against WHATWG Range spec algorithms
9 | - [X] Highlighter module. Review and rewrite existing.
10 | - [X] Added select() method to range
11 | - [X] Rename CSS class applier module to "class applier module"
12 | - [X] Add handling for img and similar elements in class applier module
13 | - [X] AMD support
14 | - [X] Add getNativeTextRange() to selection for IE 11
15 | - [X] Add Range setStartAndEnd(). Overloaded? eg. two args collapsed, three args (node, startOffset, endOffset),
16 | four args (startNode, startOffset, endNode, endOffset) (consider this)
17 |
18 | 1.4
19 | ---
20 |
21 | - [?] Consider range.restrict(node)
22 | - [?] Consider filter option in createClassApplier() options object
23 | - [ ] Either a utils module or an FAQ page with code snippets for common use cases, including:
24 | - [X] Simple selection save/restore (bookmark?) (is this necessary?)
25 | - [ ] Insert HTML
26 | (http://stackoverflow.com/questions/2213376/how-to-find-cursor-position-in-a-contenteditable-div/2213514#2213514)
27 | - [?] Some kind of jQuery integration module?
28 | - [ ] Move IE <= 8 support into a separate optional module
29 | - [ ] Add withinRange and withinNode options to move(), moveStart() and moveEnd() methods
30 | - [?] Positions module
31 | (http://stackoverflow.com/questions/4122315/how-to-find-xy-position-in-javascript-with-offset/4123495#4123495)
32 | - [ ] Config module or something so that config can work with AMD. See PR #285
33 | (https://github.com/timdown/rangy/pull/285)
34 | - [ ] Move to one of the common testing libraries
35 | - [ ] Update build not to use a fresh Git checkout
36 | - [ ] Investigate shadow DOM (issue #307)
37 |
38 | Possible features for some version
39 | ----------------------------------
40 |
41 | - [?] Commands module with basic inline commands (bold, italic, colour, font face, font size, background colour, etc.)
42 | (http://stackoverflow.com/questions/2887101/apply-style-to-range-of-text-with-javascript-in-uiwebview/2888969#2888969)
43 | - [?] More commands (block? Insert line break? Think about this, don't want to build a WYSIWYG editor)
44 | - [ ] Add selection extend()? Don't think this is possible.
45 | - [ ] Option in TextRange module for alternative ways to extract text for an element (see email from Bruce Augustine)
46 |
--------------------------------------------------------------------------------
/demos/content.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Rangy Bold Demo
5 |
18 |
26 |
27 |
28 |
Test
29 |
Test
30 |
Test
31 |
32 |
2
33 |
One
34 | Two
35 |
Three
36 |
37 |
38 | Association football is a sport played between two teams. It is usually called football, but in
39 | some countries, such as the United States, it is called soccer. In
40 | Japan, New Zealand, South Africa, Australia, Canada and
41 | Republic of Ireland, both words are commonly used.
42 |
43 |
44 | Each team has 11 players on the field. One of these players is the goalkeeper, and the other ten are
45 | known as "outfield players." The game is played by kicking a ball into the opponent's goal. A
46 | match has 90 minutes of play, with a break of 15 minutes in the middle. The break in the middle is called
47 | half-time.
48 |
49 |
Competitions
50 |
51 | There are many competitions for football, for both football clubs and countries. Football clubs usually play
52 | other teams in their own country, with a few exceptions. Cardiff City F.C. from Wales for example, play
53 | in the English leagues and in the English FA Cup.
54 |
55 |
Who plays football
56 |
57 | Football is the world's most popular sport. It is played in more
58 | countries than any other game. In fact, FIFA (the Federation
59 | Internationale de Football Association) has more members than the
60 | United Nations.
61 |
62 | It is played by both males and females.
63 |
64 |
65 |
62 | 29 min: After that let-off, Portugal tear down the other end and sow panic in the Brazilian defence.
63 |
64 |
66 |
67 |
68 |
69 |
70 |
71 |
Zero
72 |
One two
73 |
Four five
74 |
29 min: After that let-off, Portugal tear down the other end and sow panic in the Brazilian defence, Juan forced into a clusmy-looking tackle on Tiago, who tumbles theatrically. Portugal players howl for a penalty, the ref books Tiago for diving.
75 |
28 min: Portugal switch off defensively, allowing Nilmar to collect a through-ball and shoot from eight yards. The keeper pushes it on to the psot and out! Great save. "Klose ..." blurts David Roberts. "... but no cigar."
76 |
77 | Some preformatted text.
78 |
79 | Wonder how it'll do
80 |
81 | with this, plus some line breaks
82 |
83 |
84 |
32 | The cabbage is a popular cultivar of a the species
33 | Brassica oleracea Linne (Capitata Group)
34 | of the Family Brassicaceae (or Cruciferae), and is used as
35 | a leafy green vegetable. It is a
36 | herbaceous,
37 | biennial,
38 | dicotyledonous
39 |
40 | flowering plant distinguished by a short stem upon
41 | which is crowded a mass of leaves, usually green but in some varieties red or purplish, which while immature
42 | form a characteristic compact, globular cluster (cabbagehead).
43 |
44 |
45 | The cabbage is a popular cultivar of a the species
46 | Brassica oleracea Linne (Capitata Group)
47 | of the Family Brassicaceae (or Cruciferae), and is used as
48 | a leafy green vegetable. It is a
49 | herbaceous,
50 | biennial,
51 | dicotyledonous
52 |
53 | flowering plant distinguished by a short stem upon
54 | which is crowded a mass of leaves, usually green but in some varieties red or purplish, which while immature
55 | form a characteristic compact, globular cluster (cabbagehead).
56 |
57 |
58 | Press the button to refresh this page and restore the current selection from the cookie:
59 |
60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/external/jshashtable.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2010 Tim Down.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | var Hashtable=(function(){var p="function";var n=(typeof Array.prototype.splice==p)?function(s,r){s.splice(r,1)}:function(u,t){var s,v,r;if(t===u.length-1){u.length=t}else{s=u.slice(t+1);u.length=t;for(v=0,r=s.length;v
3 |
4 |
5 | Selection save/restore test
6 |
7 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
49 |
50 |
51 |
Selection save/restore test
52 |
53 |
Below is some editable content:
54 |
55 | The cabbage is a popular cultivar of a the species
56 | Brassica oleracea Linne (Capitata Group)
57 | of the Family Brassicaceae (or Cruciferae), and is used as
58 | a leafy green vegetable. It is a
59 | herbaceous,
60 | biennial,
61 | dicotyledonous
62 |
63 | flowering plant distinguished by a short stem upon
64 | which is crowded a mass of leaves, usually green but in some varieties red or purplish, which while immature
65 | form a characteristic compact, globular cluster (cabbagehead). This is some area to type.
66 |
67 |
68 |
69 |
70 | Select something in the editable area above. Click on the "Save selection" button. Now click somewhere on the
71 | page to destroy the selection, and then press "Restore selection".
72 |
68 | Please use the simple editor below to create a link, demonstrating the getBoookmark() and
69 | moveToBoookmark() methods of Rangy's selection object.
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | Association football is a sport played between two teams. It is usually called football, but in
81 | some countries, such as the United States, it is called soccer. In
82 | Japan, New Zealand, South Africa, Australia, Canada and
83 | Republic of Ireland, both words are commonly used.
84 |
Make a selection in the document and use the buttons below to highlight and unhighlight.
81 |
82 |
83 |
84 |
Preserving highlights between page requests
85 |
92 |
93 |
94 |
95 |
Highlighter module scoped highlights demo
96 |
97 | Please use your mouse and/or keyboard to make selections from the sample quotes below and use the buttons
98 | on the left hand size to create and remove highlights.
99 |
100 |
101 |
"Hello. My name is Inigo Montoya. You killed my father. Prepare to die."
102 |
"You keep using that word. I do not think it means what you think it means."
103 |
"I do not mean to pry, but you don't by any chance happen to have six fingers on your right hand?"
104 |
"Oh, there's something I ought to tell you. I'm not left-handed either."
105 |
106 |
107 |
108 |
--------------------------------------------------------------------------------
/fiddlings/spec/innerText_files/dfn.js:
--------------------------------------------------------------------------------
1 | // dfn.js
2 | // makes elements link back to all uses of the term
3 | // no copyright is asserted on this file
4 |
5 | var dfnTimer = new Date();
6 |
7 | var dfnMapTarget = -1;
8 | var dfnMapDone = false;
9 | var dfnMap = {};
10 | function initDfn() {
11 | var links = [];
12 | dfnMapTarget = document.links.length;
13 | for (var i = 0; i < dfnMapTarget; i += 1)
14 | links[i] = document.links[i];
15 | var k = 0;
16 | var n = 0;
17 | var initDfnInternal = function () {
18 | n += 1;
19 | var start = new Date();
20 | while (k < dfnMapTarget) {
21 | if (links[k].hash.length > 1) {
22 | if (links[k].className != "no-backref" && links[k].parentNode.className != "no-backref") {
23 | var s = links[k].hash.substr(1);
24 | if (!(s in dfnMap))
25 | dfnMap[s] = [];
26 | dfnMap[s].push(links[k]);
27 | }
28 | }
29 | k += 1;
30 | if (new Date() - start > 1000) {
31 | setTimeout(initDfnInternal, 10000);
32 | return;
33 | }
34 | }
35 | dfnMapDone = true;
36 | document.body.className += " dfnEnabled";
37 | if (getCookie('profile') == '1')
38 | document.getElementsByTagName('h2')[0].textContent += '; dfn.js: ' + (new Date() - dfnTimer) + 'ms to do ' + dfnMapTarget + ' links in ' + n + ' loops';
39 | }
40 | initDfnInternal();
41 | }
42 |
43 | var dfnPanel;
44 | var dfnUniqueId = 0;
45 | var dfnTimeout;
46 | document.addEventListener('click', dfnShow, false);
47 | function dfnShow(event) {
48 | if (dfnTimeout) {
49 | clearTimeout(dfnTimeout);
50 | dfnTimeout = null;
51 | }
52 | if (dfnPanel) {
53 | dfnPanel.parentNode.removeChild(dfnPanel);
54 | dfnPanel = null;
55 | }
56 | if (dfnMapDone) {
57 | var node = event.target;
58 | while (node && (node.nodeType != event.target.ELEMENT_NODE || node.tagName != "DFN"))
59 | node = node.parentNode;
60 | if (node) {
61 | var panel = document.createElement('div');
62 | panel.className = 'dfnPanel';
63 | if (node.id) {
64 | var permalinkP = document.createElement('p');
65 | var permalinkA = document.createElement('a');
66 | permalinkA.href = '#' + node.id;
67 | permalinkA.textContent = '#' + node.id;
68 | permalinkP.appendChild(permalinkA);
69 | panel.appendChild(permalinkP);
70 | }
71 | var p = document.createElement('p');
72 | panel.appendChild(p);
73 | if (node.id in dfnMap || node.parentNode.id in dfnMap) {
74 | p.textContent = 'Referenced in:';
75 | var ul = document.createElement('ul');
76 | var lastHeader;
77 | var lastLi;
78 | var n;
79 | var sourceLinks = [];
80 | if (node.id in dfnMap)
81 | for (var i = 0; i < dfnMap[node.id].length; i += 1)
82 | sourceLinks.push(dfnMap[node.id][i]);
83 | if (node.parentNode.id in dfnMap)
84 | for (var i = 0; i < dfnMap[node.parentNode.id].length; i += 1)
85 | sourceLinks.push(dfnMap[node.parentNode.id][i]);
86 | for (var i = 0; i < sourceLinks.length; i += 1) {
87 | var link = sourceLinks[i];
88 | var header = dfnGetCaption(link);
89 | var a = document.createElement('a');
90 | if (!link.id)
91 | link.id = 'dfnReturnLink-' + dfnUniqueId++;
92 | a.href = '#' + link.id;
93 | if (header != lastHeader) {
94 | lastHeader = header;
95 | n = 1;
96 | var li = document.createElement('li');
97 | var cloneHeader = header.cloneNode(true);
98 | while (cloneHeader.hasChildNodes())
99 | a.appendChild(cloneHeader.firstChild);
100 | lastLi = li;
101 | li.appendChild(a);
102 | ul.appendChild(li);
103 | } else {
104 | n += 1;
105 | a.appendChild(document.createTextNode('(' + n + ')'));
106 | lastLi.appendChild(document.createTextNode(' '));
107 | lastLi.appendChild(a);
108 | }
109 | }
110 | panel.appendChild(ul);
111 | } else {
112 | p.textContent = 'No references in this file.';
113 | }
114 | node.appendChild(panel);
115 | dfnPanel = panel;
116 | }
117 | } else {
118 | dfnTimeout = setTimeout(dfnShow, 250, event);
119 | }
120 | }
121 |
122 | function dfnGetCaption(link) {
123 | var node = link;
124 | while (node) {
125 | if (node.nodeType == node.ELEMENT_NODE && node.tagName.match(/^H[1-6]$/)) {
126 | return node;
127 | } else if (!node.previousSibling) {
128 | node = node.parentNode;
129 | } else {
130 | node = node.previousSibling;
131 | if (node.nodeType == node.ELEMENT_NODE && node.className == "impl") {
132 | node = node.lastChild;
133 | }
134 | }
135 | }
136 | return null;
137 | }
138 |
139 | // setup (disabled for multipage copy)
140 | if (document.getElementById('head'))
141 | initDfn();
142 |
--------------------------------------------------------------------------------
/demos/bold.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Rangy Bold Demo
5 |
6 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
46 |
47 |
48 |
49 |
Add / remove CSS classes to / from selection
50 | Make a selection in the document on the right and use the buttons below to toggle CSS classes on the selection:
51 |
52 |
53 |
55 |
56 |
57 |
58 |
Rangy Text Commands Module Demo
59 |
60 |
61 |
62 |
63 | Please use your mouse and/or keyboard to make selections from the sample content below and use the buttons on
64 | the left hand size to toggle CSS classes applied to text content within the selection.
65 |
66 |
67 |
68 | Association football is a sport played between two teams. It is usually called football, but in
69 | some countries, such as the United States, it is called soccer. In
70 | Japan, New Zealand, South Africa, Australia, Canada and
71 | Republic of Ireland, both words are commonly used.
72 |
73 |
74 | Each team has 11 players on the field. One of these players is the goalkeeper, and the other ten are
75 | known as "outfield players." The game is played by kicking a ball into the opponent's goal. A
76 | match has 90 minutes of play, with a break of 15 minutes in the middle. The break in the middle is called
77 | half-time.
78 |
79 |
Competitions (this section is editable)
80 |
81 | There are many competitions for football, for both football clubs and countries. Football clubs usually play
82 | other teams in their own country, with a few exceptions. Cardiff City F.C. from Wales for example, play
83 | in the English leagues and in the English FA Cup.
84 |
85 |
Who plays football (this section is editable and in pre-formatted text)
86 |
87 | Football is the world's most popular sport. It is played in more
88 | countries than any other game. In fact, FIFA (the Federation
89 | Internationale de Football Association) has more members than the
90 | United Nations.
91 |
92 | It is played by both males and females.
93 |
94 |
95 |
A paragraph with bold text with italic words plus some using both.
70 |
A paragraph with bold text with italic words plus some using both.
71 | A paragraph with bold text with italic words
72 |
73 | plus some using both.
74 |
75 |
a
76 |
b
77 |
78 |
79 |
80 |
81 |
82 |
A paragraph with bold text with italic words plus some using both.
83 | A paragraph with bold text with bold italic text and italic words plus some using both.
84 |
85 |
86 |
a
87 |
b
88 |
89 |
90 |
91 | Some preformatted how it'll do
92 |
93 | with this, plus some line breaks
94 |
95 |
96 |
105 | Rangy's Events module provides mouse and
106 | touch (NOT YET IMPLEMENTED) events on Ranges. Please use your mouse to make a selection in the sample
107 | content below and hover your mouse over the selection. Events are logged in the text box on the left.
108 |
109 |
110 | Association football is a sport played between two teams. It is usually called football, but in
111 | some countries, such as the United States, it is called soccer. In
112 | Japan, New Zealand, South Africa, Australia, Canada and
113 | Republic of Ireland, both words are commonly used.
114 |
115 |
116 | Each team has 11 players on the field. One of these players is the goalkeeper, and the other ten are
117 | known as "outfield players." The game is played by kicking a ball into the opponent's goal. A
118 | match has 90 minutes of play, with a break of 15 minutes in the middle. The break in the middle is called
119 | half-time.
120 |
121 |
Competitions (this section is editable)
122 |
123 | There are many competitions for football, for both football clubs and countries. Football clubs usually play
124 | other teams in their own country, with a few exceptions. Cardiff City F.C. from Wales for example, play
125 | in the English leagues and in the English FA Cup.
126 |
127 |
Who plays football (this section is editable and in pre-formatted text)
128 |
129 | Football is the world's most popular sport. It is played in more
130 | countries than any other game. In fact, FIFA (the Federation
131 | Internationale de Football Association) has more members than the
132 | United Nations.
133 |
134 | It is played by both males and females.
135 |
136 |
137 |
138 |
139 |
140 |
141 |
--------------------------------------------------------------------------------
/external/log4javascript_stub.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2008 Tim Down.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 |
18 | var log4javascript_stub=(function(){var log4javascript;function ff(){return function(){};}
19 | function copy(obj,props){for(var i in props){obj[i]=props[i];}}
20 | var f=ff();var Logger=ff();copy(Logger.prototype,{addChild:f,getEffectiveAppenders:f,invalidateAppenderCache:f,getAdditivity:f,setAdditivity:f,addAppender:f,removeAppender:f,removeAllAppenders:f,log:f,setLevel:f,getLevel:f,getEffectiveLevel:f,trace:f,debug:f,info:f,warn:f,error:f,fatal:f,isEnabledFor:f,isTraceEnabled:f,isDebugEnabled:f,isInfoEnabled:f,isWarnEnabled:f,isErrorEnabled:f,isFatalEnabled:f,callAppenders:f,group:f,groupEnd:f,time:f,timeEnd:f,assert:f,parent:new Logger()});var getLogger=function(){return new Logger();};function EventSupport(){};copy(EventSupport.prototype,{setEventTypes:f,addEventListener:f,removeEventListener:f,dispatchEvent:f,eventTypes:[],eventListeners:{}});function Log4JavaScript(){}
21 | Log4JavaScript.prototype=new EventSupport();log4javascript=new Log4JavaScript();log4javascript={isStub:true,version:"1.4",edition:"log4javascript",setEventTypes:f,addEventListener:f,removeEventListener:f,dispatchEvent:f,eventTypes:[],eventListeners:{},logLog:{setQuietMode:f,setAlertAllErrors:f,debug:f,displayDebug:f,warn:f,error:f},handleError:f,setEnabled:f,isEnabled:f,setTimeStampsInMilliseconds:f,isTimeStampsInMilliseconds:f,evalInScope:f,setShowStackTraces:f,getLogger:getLogger,getDefaultLogger:getLogger,getNullLogger:getLogger,getRootLogger:getLogger,resetConfiguration:f,Level:ff(),LoggingEvent:ff(),Layout:ff(),Appender:ff()};log4javascript.LoggingEvent.prototype={getThrowableStrRep:f,getCombinedMessages:f};log4javascript.Level.prototype={toString:f,equals:f,isGreaterOrEqual:f};var level=new log4javascript.Level();copy(log4javascript.Level,{ALL:level,TRACE:level,DEBUG:level,INFO:level,WARN:level,ERROR:level,FATAL:level,OFF:level});log4javascript.Layout.prototype={defaults:{},format:f,ignoresThrowable:f,getContentType:f,allowBatching:f,getDataValues:f,setKeys:f,setCustomField:f,hasCustomFields:f,setTimeStampsInMilliseconds:f,isTimeStampsInMilliseconds:f,getTimeStampValue:f,toString:f};log4javascript.SimpleDateFormat=ff();log4javascript.SimpleDateFormat.prototype = {setMinimalDaysInFirstWeek:f,getMinimalDaysInFirstWeek:f,format:f};
22 | log4javascript.PatternLayout=ff();log4javascript.PatternLayout.prototype=new log4javascript.Layout();log4javascript.Appender=ff();log4javascript.Appender.prototype=new EventSupport();copy(log4javascript.Appender.prototype,{layout:new log4javascript.PatternLayout(),threshold:log4javascript.Level.ALL,loggers:[],doAppend:f,append:f,setLayout:f,getLayout:f,setThreshold:f,getThreshold:f,setAddedToLogger:f,setRemovedFromLogger:f,group:f,groupEnd:f,toString:f});log4javascript.SimpleLayout=ff();log4javascript.SimpleLayout.prototype=new log4javascript.Layout();log4javascript.NullLayout=ff();log4javascript.NullLayout.prototype=new log4javascript.Layout();log4javascript.XmlLayout=ff();log4javascript.XmlLayout.prototype=new log4javascript.Layout();copy(log4javascript.XmlLayout.prototype,{escapeCdata:f,isCombinedMessages:f});log4javascript.JsonLayout=ff();log4javascript.JsonLayout.prototype=new log4javascript.Layout();copy(log4javascript.JsonLayout.prototype,{isReadable:f,isCombinedMessages:f});log4javascript.HttpPostDataLayout=ff();log4javascript.HttpPostDataLayout.prototype=new log4javascript.Layout();log4javascript.PatternLayout=ff();log4javascript.PatternLayout.prototype=new log4javascript.Layout();log4javascript.AlertAppender=ff();log4javascript.AlertAppender.prototype=new log4javascript.Appender();log4javascript.BrowserConsoleAppender=ff();log4javascript.BrowserConsoleAppender.prototype=new log4javascript.Appender();log4javascript.AjaxAppender=ff();log4javascript.AjaxAppender.prototype=new log4javascript.Appender();copy(log4javascript.AjaxAppender.prototype,{getSessionId:f,setSessionId:f,isTimed:f,setTimed:f,getTimerInterval:f,setTimerInterval:f,isWaitForResponse:f,setWaitForResponse:f,getBatchSize:f,setBatchSize:f,isSendAllOnUnload:f,setSendAllOnUnload:f,setRequestSuccessCallback:f,setFailCallback:f,getPostVarName:f,setPostVarName:f,sendAll:f,defaults:{requestSuccessCallback:null,failCallback:null}});function ConsoleAppender(){}
23 | ConsoleAppender.prototype=new log4javascript.Appender();copy(ConsoleAppender.prototype,{create:f,isNewestMessageAtTop:f,setNewestMessageAtTop:f,isScrollToLatestMessage:f,setScrollToLatestMessage:f,getWidth:f,setWidth:f,getHeight:f,setHeight:f,getMaxMessages:f,setMaxMessages:f,isShowCommandLine:f,setShowCommandLine:f,isShowHideButton:f,setShowHideButton:f,isShowCloseButton:f,setShowCloseButton:f,getCommandLineObjectExpansionDepth:f,setCommandLineObjectExpansionDepth:f,isInitiallyMinimized:f,setInitiallyMinimized:f,isUseDocumentWrite:f,setUseDocumentWrite:f,group:f,groupEnd:f,clear:f,focus:f,focusCommandLine:f,focusSearch:f,getCommandWindow:f,setCommandWindow:f,executeLastCommand:f,getCommandLayout:f,setCommandLayout:f,evalCommandAndAppend:f,addCommandLineFunction:f,storeCommandHistory:f,unload:f});ConsoleAppender.addGlobalCommandLineFunction=f;log4javascript.InPageAppender=ff();log4javascript.InPageAppender.prototype=new ConsoleAppender();copy(log4javascript.InPageAppender.prototype,{addCssProperty:f,hide:f,show:f,isVisible:f,close:f,defaults:{layout:new log4javascript.PatternLayout(),maxMessages:null}});log4javascript.InlineAppender=log4javascript.InPageAppender;log4javascript.PopUpAppender=ff();log4javascript.PopUpAppender.prototype=new ConsoleAppender();copy(log4javascript.PopUpAppender.prototype,{isUseOldPopUp:f,setUseOldPopUp:f,isComplainAboutPopUpBlocking:f,setComplainAboutPopUpBlocking:f,isFocusPopUp:f,setFocusPopUp:f,isReopenWhenClosed:f,setReopenWhenClosed:f,close:f,hide:f,show:f,defaults:{layout:new log4javascript.PatternLayout(),maxMessages:null}});return log4javascript;})();if(typeof window.log4javascript=="undefined"){var log4javascript=log4javascript_stub;}
--------------------------------------------------------------------------------
/test/textrangelength.html:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 | Text Range length
6 |
136 |
137 |
76 | Select something in the main page area to the right. Click on the "Save selection" button. Now click somewhere
77 | on the page to destroy the selection, and then press "Restore selection".
78 |
79 |
80 |
81 |
82 |
83 |
Rangy Save / Restore Selection Module Demo
84 |
85 |
86 |
87 |
88 | Please use your mouse and/or keyboard to make selections from the sample content below and use the buttons
89 | on the left hand size to save and restore the selection.
90 |
91 |
92 |
93 | Association football is a sport played between two teams. It is usually called football, but in
94 | some countries, such as the United States, it is called soccer. In
95 | Japan, New Zealand, South Africa, Australia, Canada and
96 | Republic of Ireland, both words are commonly used.
97 |
98 |
99 | Each team has 11 players on the field. One of these players is the goalkeeper, and the other ten are
100 | known as "outfield players." The game is played by kicking a ball into the opponent's goal. A
101 | match has 90 minutes of play, with a break of 15 minutes in the middle. The break in the middle is called
102 | half-time.
103 |
104 |
Competitions (this section is editable)
105 |
106 | There are many competitions for football, for both football clubs and countries. Football clubs usually play
107 | other teams in their own country, with a few exceptions. Cardiff City F.C. from Wales for example, play
108 | in the English leagues and in the English FA Cup.
109 |
110 |
Who plays football (this section is editable and in pre-formatted text)
111 |
112 | Football is the world's most popular sport. It is played in more
113 | countries than any other game. In fact, FIFA (the Federation
114 | Internationale de Football Association) has more members than the
115 | United Nations.
116 |
117 | It is played by both males and females.
118 |
119 |
120 |
121 |
122 | Some controls to put in a ControlRange: and and
123 |
70 | Click the button to serialize the selection. The serialized selection will appear in the text box.
71 |
72 |
73 |
74 |
Deserialize selection
75 | Paste a serialized selection into the text box below and click the button to restore the serialized selection.
76 |
77 |
78 |
79 |
Preserving the selection between page requests
80 | The selection on this page will be preserved between page requests. Press the following button or your browser's
81 | refresh button to refresh the page
82 |
83 |
84 |
85 |
86 |
87 |
Rangy Serializer Module Demo
88 |
89 |
90 |
91 |
92 | Please use your mouse and/or keyboard to make selections from the sample content below and use the buttons on
93 | the left hand size to serialize and deserialize the selection. Also, the selection will be preserved when you
94 | refresh the page.
95 |
96 |
97 |
98 | Association football is a sport played between two teams. It is usually called football, but in
99 | some countries, such as the United States, it is called soccer. In
100 | Japan, New Zealand, South Africa, Australia, Canada and
101 | Republic of Ireland, both words are commonly used.
102 |
103 |
104 | Each team has 11 players on the field. One of these players is the goalkeeper, and the other ten are
105 | known as "outfield players." The game is played by kicking a ball into the opponent's goal. A
106 | match has 90 minutes of play, with a break of 15 minutes in the middle. The break in the middle is called
107 | half-time.
108 |
109 |
Competitions (this section is editable)
110 |
111 | There are many competitions for football, for both football clubs and countries. Football clubs usually play
112 | other teams in their own country, with a few exceptions. Cardiff City F.C. from Wales for example, play
113 | in the English leagues and in the English FA Cup.
114 |
115 |
Who plays football (this section is editable and in pre-formatted text)
116 |
117 | Football is the world's most popular sport. It is played in more
118 | countries than any other game. In fact, FIFA (the Federation
119 | Internationale de Football Association) has more members than the
120 | United Nations.
121 |
122 | It is played by both males and females.
123 |
124 |
125 |
126 |
127 | Some controls to put in a ControlRange: and and
128 |
Make a selection in the document and use the buttons below to highlight and unhighlight.
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
Preserving highlights between page requests
99 |
106 |
107 |
108 |
109 |
Rangy Highlighter Module Demo
110 |
111 | Please use your mouse and/or keyboard to make selections from the sample content below and use the buttons
112 | on the left hand size to create and remove highlights.
113 |
114 |
115 | Association football is a sport played between two teams. It is usually called football, but in
116 | some countries, such as the United States, it is called soccer. In
117 | Japan, New Zealand, South Africa, Australia, Canada and
118 | Republic of Ireland, both words are commonly used.
119 |
120 |
121 | Each team has 11 players on the field. One of these players is the goalkeeper, and the other ten are
122 | known as "outfield players." The game is played by kicking a ball into the opponent's goal. A
123 | match has 90 minutes of play, with a break of 15 minutes in the middle. The break in the middle is called
124 | half-time.
125 |
126 |
Competitions
127 |
128 | There are many competitions for football, for both football clubs and countries. Football clubs usually play
129 | other teams in their own country, with a few exceptions. Cardiff City F.C. from Wales for example, play
130 | in the English leagues and in the English FA Cup.
131 |
132 |
Who plays football (this section is in pre-formatted text)
133 |
134 | Football is the world's most popular sport. It is played in more
135 | countries than any other game. In fact, FIFA (the Federation
136 | Internationale de Football Association) has more members than the
137 | United Nations.
138 |
139 | It is played by both males and females.
140 |
141 |
142 |
151 |
152 |
--------------------------------------------------------------------------------
/src/modules/inactive/commands/rangy-applyclass.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Selection save and restore module for Rangy.
3 | * ApplyClass command
4 | *
5 | * Part of Rangy, a cross-browser JavaScript range and selection library
6 | * https://github.com/timdown/rangy
7 | *
8 | * Depends on Rangy core.
9 | *
10 | * Copyright %%build:year%%, Tim Down
11 | * Licensed under the MIT license.
12 | * Version: %%build:version%%
13 | * Build date: %%build:date%%
14 | */
15 | rangy.createModule("ApplyClassCommand", function(api, module) {
16 | api.requireModules( ["Commands"] );
17 |
18 | var dom = api.dom, commandUtil = api.Command.util;
19 | var log = log4javascript.getLogger("rangy.ApplyClassCommand");
20 |
21 | var defaultTagNames = ["span"];
22 |
23 | function hasClass(el, className) {
24 | return el.className && new RegExp("(?:^|\\s)" + className + "(?:\\s|$)").test(el.className);
25 | }
26 |
27 | function addClass(el, className) {
28 | if (el.className) {
29 | if (!hasClass(el, className)) {
30 | el.className += " " + className;
31 | }
32 | } else {
33 | el.className = className;
34 | }
35 | }
36 |
37 | var removeClass = (function() {
38 | function replacer(matched, whitespaceBefore, whitespaceAfter) {
39 | return (whitespaceBefore && whitespaceAfter) ? " " : "";
40 | }
41 |
42 | return function(el, className) {
43 | if (el.className) {
44 | el.className = el.className.replace(new RegExp("(?:^|\\s)" + className + "(?:\\s|$)"), replacer);
45 | }
46 | };
47 | })();
48 |
49 | function sortClassName(className) {
50 | return className.split(/\s+/).sort().join(" ");
51 | }
52 |
53 | function getSortedClassName(el) {
54 | return sortClassName(el.className);
55 | }
56 |
57 | function haveSameClasses(el1, el2) {
58 | return getSortedClassName(el1) == getSortedClassName(el2);
59 | }
60 |
61 | function ApplyClassCommand() {
62 | }
63 |
64 | api.Command.create(ApplyClassCommand, {
65 | defaultOptions: {
66 | tagName: "span",
67 | validTagNames: ["span"]
68 | },
69 |
70 | isValidElementForClass: function(el, validTagNames) {
71 | return new RegExp("^(" + validTagNames.join("|") + ")$", "i").test(el.tagName);
72 | },
73 |
74 | isModifiableElement: function(el, context) {
75 | if (!this.isValidElementForClass(el, context.options.validTagNames)) {
76 | return false;
77 | }
78 |
79 | // Extract attributes once and quit if more than one is found or the attribute is not "class"
80 | var hasAnyAttrs = false;
81 | for (var i = 0, len = el.attributes.length; i < len; ++i) {
82 | if (el.attributes[i].specified) {
83 | // If it's got more than one attribute, everything after this fails.
84 | if (hasAnyAttrs || el.attributes[i].name != "class") {
85 | return false;
86 | }
87 | hasAnyAttrs = true;
88 | }
89 | }
90 | },
91 |
92 | isSimpleModifiableElement: function(el, context) {
93 | if (!this.isValidElementForClass(el, context.options.validTagNames)) {
94 | return false;
95 | }
96 |
97 | // Extract attributes once and quit if more than one is found or the attribute is not "class"
98 | var hasAnyAttrs = false;
99 | for (var i = 0, len = el.attributes.length; i < len; ++i) {
100 | if (el.attributes[i].specified) {
101 | // If it's got more than one attribute, everything after this fails.
102 | if (hasAnyAttrs || el.attributes[i].name != "class") {
103 | return false;
104 | }
105 | hasAnyAttrs = true;
106 | }
107 | }
108 |
109 | return true;
110 | },
111 |
112 | createCssElement: function(doc, context) {
113 | return doc.createElement(context.options.tagName);
114 | },
115 |
116 | styleCssElement: function(el, value) {
117 | el.className = value;
118 | },
119 |
120 | getAncestorOrSelfWithClass: function(node, validTagNames, className) {
121 | while (node) {
122 | if (node.nodeType == 1 && this.isValidElementForClass(node, validTagNames) && hasClass(node, className)) {
123 | return node;
124 | }
125 | node = node.parentNode;
126 | }
127 | return null;
128 | },
129 |
130 | getSpecifiedValue: function(element, context) {
131 | return hasClass(element, context.value) ? context.value : null;
132 | },
133 |
134 | getEffectiveValue: function(element, context) {
135 | return this.getAncestorOrSelfWithClass(element, context.options.validTagNames, context.value) ?
136 | context.value : null;
137 | },
138 |
139 | createNonCssElement: function(node, value) {
140 | return (value == "bold" || value == "700") ? dom.getDocument(node).createElement("b") : null;
141 | },
142 |
143 | getRangeValue: function(range, context) {
144 | var textNodes = commandUtil.getEffectiveTextNodes(range, context), i = textNodes.length, value;
145 | log.info("getRangeValue on " + range.inspect() + ", text nodes: " + textNodes);
146 | while (i--) {
147 | log.warn("effective value on " + textNodes[i].data + ": " + commandUtil.getEffectiveValue(textNodes[i], context));
148 | if (commandUtil.getEffectiveValue(textNodes[i], context) === null) {
149 | return false;
150 | }
151 | }
152 | log.info("getRangeValue returning true");
153 | return textNodes.length > 0;
154 | },
155 |
156 | getSelectionValue: function(sel, context) {
157 | var selRanges = sel.getAllRanges();
158 | for (var i = 0, len = selRanges.length; i < len; ++i) {
159 | if (!this.getRangeValue(selRanges[i], context)) {
160 | return false;
161 | }
162 | }
163 | return len > 0;
164 | },
165 |
166 | getNewSelectionValue: function(sel, context) {
167 | return this.getSelectionValue(sel, context) ? "" : context.value;
168 | },
169 |
170 | applyValueToRange: function(range, context) {
171 | var decomposed = range.decompose(context.rangesToPreserve);
172 |
173 | for (var i = 0, len = decomposed.length; i < len; ++i) {
174 | commandUtil.setNodeValue(decomposed[i], context);
175 | }
176 | }
177 | });
178 |
179 | api.registerCommand("applyclass", new ApplyClassCommand());
180 |
181 | });
182 |
--------------------------------------------------------------------------------
/demos/classapplier.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Rangy CSS Class Applier Module Demo
5 |
6 |
26 |
27 |
28 |
96 |
97 |
98 |
99 |
Add / remove CSS classes to / from selection
100 | Make a selection in the document on the right and use the buttons below to toggle CSS classes on the selection:
101 |
102 |
103 |
105 |
106 |
108 |
109 |
111 |
112 |
113 |
114 |
Rangy CSS Class Applier Module Demo
115 |
116 |
117 |
118 |
119 | Please use your mouse and/or keyboard to make selections from the sample content below and use the buttons
120 | on the left hand size to toggle CSS classes applied to content (now also including images) within the
121 | selection.
122 |
123 |
124 |
125 | Association football is a sport played between two teams. It is usually called
126 | football, but in some countries, such as the United States, it is called
127 | soccer. In Japan, New Zealand, South Africa,
128 | Australia, Canada and Republic of Ireland, both words are commonly used.
129 |
130 |
131 | Each team has 11 players on the field. One of these players is the goalkeeper, and the other ten are
132 | known as "outfield players." The game is played by kicking a ball
133 | into the opponent's goal. A
134 | match has 90 minutes of play, with a break of 15 minutes in the middle. The break in the middle is called
135 | half-time.
136 |
137 |
Competitions (this section is editable)
138 |
139 | There are many competitions for football, for both football clubs and countries. Football clubs usually play
140 | other teams in their own country, with a few exceptions. Cardiff City F.C. from Wales for example, play
141 | in the English leagues and in the English FA Cup.
142 |
143 |
Who plays football (this section is editable and in pre-formatted text)
144 |
145 | Football is the world's most popular sport. It is played in more
146 | countries than any other game. In fact, FIFA (the Federation
147 | Internationale de Football Association) has more members than the
148 | United Nations.
149 |
150 | It is played by both males and females.
151 |
152 |