wysihtml5_with_ps 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Makefile +98 -0
- data/Rakefile +38 -0
- data/lib/base/base.js +139 -0
- data/lib/rangy/rangy-core.js +3211 -0
- data/lib/wysihtml5_with_ps/version.rb +3 -0
- data/test/assert/html_equal_test.js +32 -0
- data/test/browser_test.js +85 -0
- data/test/dom/auto_link_test.js +105 -0
- data/test/dom/contains_test.js +18 -0
- data/test/dom/convert_to_list_test.js +101 -0
- data/test/dom/copy_attributes_test.js +51 -0
- data/test/dom/copy_styles_test.js +110 -0
- data/test/dom/delegate_test.js +62 -0
- data/test/dom/get_as_dom_test.js +55 -0
- data/test/dom/get_parent_element_test.js +161 -0
- data/test/dom/get_style_test.js +54 -0
- data/test/dom/has_element_with_class_name_test.js +29 -0
- data/test/dom/has_element_with_tag_name_test.js +25 -0
- data/test/dom/insert_css_test.js +31 -0
- data/test/dom/observe_test.js +83 -0
- data/test/dom/parse_test.js +614 -0
- data/test/dom/rename_element_test.js +28 -0
- data/test/dom/resolve_list_test.js +46 -0
- data/test/dom/sandbox_test.js +184 -0
- data/test/dom/set_attributes_test.js +15 -0
- data/test/dom/set_styles_test.js +19 -0
- data/test/editor_test.js +547 -0
- data/test/incompatible_test.js +60 -0
- data/test/index.html +126 -0
- data/test/lang/array_test.js +22 -0
- data/test/lang/object_test.js +22 -0
- data/test/lang/string_test.js +19 -0
- data/test/quirks/clean_pasted_html_test.js +11 -0
- data/test/undo_manager_test.js +94 -0
- metadata +116 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
module("wysihtml5.assert.htmlEqual");
|
2
|
+
|
3
|
+
test("Basic tests", function() {
|
4
|
+
wysihtml5.assert.htmlEqual("<span>foo</span>", "<span>foo</span>");
|
5
|
+
wysihtml5.assert.htmlEqual("<SPAN>foo</SPAN>", "<span>foo</span>");
|
6
|
+
wysihtml5.assert.htmlEqual("<IMG SRC=foo.gif>", '<img src="foo.gif">');
|
7
|
+
|
8
|
+
var container = document.createElement("div"),
|
9
|
+
image = document.createElement("img");
|
10
|
+
image.setAttribute("alt", "foo");
|
11
|
+
image.setAttribute("border", 0);
|
12
|
+
image.setAttribute("src", "foo.gif");
|
13
|
+
image.setAttribute("width", 25);
|
14
|
+
image.setAttribute("height", 25);
|
15
|
+
container.appendChild(image);
|
16
|
+
|
17
|
+
wysihtml5.assert.htmlEqual(container.innerHTML, '<img alt="foo" border="0" src="foo.gif" width="25" height="25">');
|
18
|
+
|
19
|
+
var inlineElement = document.createElement("span");
|
20
|
+
inlineElement.innerHTML = "<p>foo</p>";
|
21
|
+
container.innerHTML = "";
|
22
|
+
container.appendChild(inlineElement);
|
23
|
+
wysihtml5.assert.htmlEqual(container.innerHTML, '<span><p>foo</p></span>');
|
24
|
+
|
25
|
+
wysihtml5.assert.htmlEqual("<p>foo bar</p>", '<p>foo bar</p>', "", {
|
26
|
+
normalizeWhiteSpace: true
|
27
|
+
});
|
28
|
+
|
29
|
+
wysihtml5.assert.htmlEqual("<div><pre><p>foo bar</p></pre></div>", '<div><pre><p>foo bar</p></pre></div>', "", {
|
30
|
+
normalizeWhiteSpace: true
|
31
|
+
});
|
32
|
+
});
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module("wysihtml5.browser", {
|
2
|
+
userAgents: {
|
3
|
+
iPad_iOS3: "Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10",
|
4
|
+
iPhone_iOS3: "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3",
|
5
|
+
iPad_iOS5: "Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3",
|
6
|
+
Android2: "Mozilla/5.0 (Linux; U; Android 2.1; en-us; Nexus One Build/ERD62) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17",
|
7
|
+
Android4: "Mozilla/5.0 (Linux; U; Android 4.0.4; en-gb; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
|
8
|
+
Chrome: "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.44 Safari/534.7",
|
9
|
+
OperaMobile: "Opera/9.80 (S60; SymbOS; Opera Mobi/498; U; en-GB) Presto/2.4.18 Version/10.00",
|
10
|
+
IE6: "Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0) (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
|
11
|
+
IE7: "Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; c .NET CLR 3.0.04506; .NET CLR 3.5.30707; InfoPath.1; el-GR)",
|
12
|
+
IE8: "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322)",
|
13
|
+
IE9: "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; Media Center PC 6.0; InfoPath.3; MS-RTC LM 8; Zune 4.7)"
|
14
|
+
},
|
15
|
+
|
16
|
+
setup: function() {
|
17
|
+
this.originalUserAgent = wysihtml5.browser.USER_AGENT;
|
18
|
+
this.originalExecCommand = document.execCommand;
|
19
|
+
this.originalQuerySelector = document.querySelector;
|
20
|
+
this.originalQuerySelectorAll = document.querySelectorAll;
|
21
|
+
},
|
22
|
+
|
23
|
+
teardown: function() {
|
24
|
+
wysihtml5.browser.USER_AGENT = this.originalUserAgent;
|
25
|
+
document.execCommand = this.originalExecCommand;
|
26
|
+
document.querySelector = this.originalQuerySelector;
|
27
|
+
document.querySelectorAll = this.originalQuerySelectorAll;
|
28
|
+
}
|
29
|
+
});
|
30
|
+
|
31
|
+
|
32
|
+
test("Check mobile contentEditable support", function() {
|
33
|
+
document.querySelector = document.querySelectorAll = function() {};
|
34
|
+
|
35
|
+
wysihtml5.browser.USER_AGENT = this.userAgents.iPad_iOS3;
|
36
|
+
ok(!wysihtml5.browser.supported(), "iPad is correctly unsupported");
|
37
|
+
|
38
|
+
wysihtml5.browser.USER_AGENT = this.userAgents.iPhone_iOS3;
|
39
|
+
ok(!wysihtml5.browser.supported(), "iPhone is correctly unsupported");
|
40
|
+
|
41
|
+
wysihtml5.browser.USER_AGENT = this.userAgents.iPad_iOS5;
|
42
|
+
ok(wysihtml5.browser.supported(), "iOS 5 is correctly supported");
|
43
|
+
|
44
|
+
wysihtml5.browser.USER_AGENT = this.userAgents.Android2;
|
45
|
+
ok(!wysihtml5.browser.supported(), "Android 2 is correctly unsupported");
|
46
|
+
|
47
|
+
wysihtml5.browser.USER_AGENT = this.userAgents.Android4;
|
48
|
+
ok(!wysihtml5.browser.supported(), "Android 4 is correctly supported");
|
49
|
+
|
50
|
+
wysihtml5.browser.USER_AGENT = this.userAgents.OperaMobile;
|
51
|
+
ok(!wysihtml5.browser.supported(), "Opera Mobile is correctly unsupported");
|
52
|
+
});
|
53
|
+
|
54
|
+
|
55
|
+
test("Check with missing document.execCommand", function() {
|
56
|
+
document.execCommand = null;
|
57
|
+
// I've no idea why this test fails in Opera... (if you run the test alone, everything works)
|
58
|
+
ok(!wysihtml5.browser.supported(), "Missing document.execCommand causes editor to be unsupported");
|
59
|
+
});
|
60
|
+
|
61
|
+
|
62
|
+
test("Check IE support", function() {
|
63
|
+
wysihtml5.browser.USER_AGENT = this.userAgents.IE6;
|
64
|
+
document.querySelector = document.querySelectorAll = null;
|
65
|
+
ok(!wysihtml5.browser.supported(), "IE6 is correctly unsupported");
|
66
|
+
|
67
|
+
wysihtml5.browser.USER_AGENT = this.userAgents.IE7;
|
68
|
+
document.querySelector = document.querySelectorAll = null;
|
69
|
+
ok(!wysihtml5.browser.supported(), "IE7 is correctly unsupported");
|
70
|
+
|
71
|
+
wysihtml5.browser.USER_AGENT = this.userAgents.IE8;
|
72
|
+
document.querySelector = document.querySelectorAll = function() {};
|
73
|
+
ok(wysihtml5.browser.supported(), "IE8 is correctly supported");
|
74
|
+
|
75
|
+
wysihtml5.browser.USER_AGENT = this.userAgents.IE9;
|
76
|
+
document.querySelector = document.querySelectorAll = function() {};
|
77
|
+
ok(wysihtml5.browser.supported(), "IE9 is correctly supported");
|
78
|
+
});
|
79
|
+
|
80
|
+
|
81
|
+
test("Check placeholder support", function() {
|
82
|
+
var pseudoElement = document.createElement("div");
|
83
|
+
pseudoElement.placeholder = "";
|
84
|
+
ok(wysihtml5.browser.supportsPlaceholderAttributeOn(pseudoElement));
|
85
|
+
});
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module("wysihtml5.dom.autoLink", {
|
2
|
+
equal: function(actual, expected, message) {
|
3
|
+
return wysihtml5.assert.htmlEqual(actual, expected, message);
|
4
|
+
},
|
5
|
+
|
6
|
+
autoLink: function(html) {
|
7
|
+
var container = wysihtml5.dom.getAsDom(html);
|
8
|
+
return wysihtml5.dom.autoLink(container).innerHTML;
|
9
|
+
}
|
10
|
+
});
|
11
|
+
|
12
|
+
|
13
|
+
test("Basic test", function() {
|
14
|
+
ok(wysihtml5.dom.autoLink.URL_REG_EXP, "URL reg exp is revealed to be access globally");
|
15
|
+
|
16
|
+
this.equal(
|
17
|
+
this.autoLink("hey check out this search engine http://www.google.com"),
|
18
|
+
"hey check out this search engine <a href=\"http://www.google.com\">http://www.google.com</a>",
|
19
|
+
"Urls starting with http:// are correctly linked"
|
20
|
+
);
|
21
|
+
|
22
|
+
this.equal(
|
23
|
+
this.autoLink("hey check out this search engine https://www.google.com"),
|
24
|
+
"hey check out this search engine <a href=\"https://www.google.com\">https://www.google.com</a>",
|
25
|
+
"Urls starting with https:// are correctly linked"
|
26
|
+
);
|
27
|
+
|
28
|
+
this.equal(
|
29
|
+
this.autoLink("hey check out this search engine www.google.com"),
|
30
|
+
"hey check out this search engine <a href=\"http://www.google.com\">www.google.com</a>",
|
31
|
+
"Urls starting with www. are correctly linked"
|
32
|
+
);
|
33
|
+
|
34
|
+
this.equal(
|
35
|
+
this.autoLink("hey check out this mail christopher.blum@xing.com"),
|
36
|
+
"hey check out this mail christopher.blum@xing.com",
|
37
|
+
"E-Mails are not linked"
|
38
|
+
);
|
39
|
+
|
40
|
+
this.equal(
|
41
|
+
this.autoLink("http://google.de"),
|
42
|
+
"<a href=\"http://google.de\">http://google.de</a>",
|
43
|
+
"Single url without www. but with http:// is auto linked"
|
44
|
+
);
|
45
|
+
|
46
|
+
this.equal(
|
47
|
+
this.autoLink("hey check out this search engine <a href=\"http://www.google.com\">www.google.com</a>"),
|
48
|
+
"hey check out this search engine <a href=\"http://www.google.com\">www.google.com</a>",
|
49
|
+
"Already auto-linked stuff isn't causing a relinking"
|
50
|
+
);
|
51
|
+
|
52
|
+
this.equal(
|
53
|
+
this.autoLink("hey check out this search engine <code><span>http://www.google.com</span></code>"),
|
54
|
+
"hey check out this search engine <code><span>http://www.google.com</span></code>",
|
55
|
+
"Urls inside 'code' elements are not auto linked"
|
56
|
+
);
|
57
|
+
|
58
|
+
this.equal(
|
59
|
+
this.autoLink("hey check out this search engine <pre>http://www.google.com</pre>"),
|
60
|
+
"hey check out this search engine <pre>http://www.google.com</pre>",
|
61
|
+
"Urls inside 'pre' elements are not auto linked"
|
62
|
+
);
|
63
|
+
|
64
|
+
this.equal(
|
65
|
+
this.autoLink("hey check out this search engine (http://www.google.com)"),
|
66
|
+
"hey check out this search engine (<a href=\"http://www.google.com\">http://www.google.com</a>)",
|
67
|
+
"Parenthesis around url are not part of url #1"
|
68
|
+
);
|
69
|
+
|
70
|
+
this.equal(
|
71
|
+
this.autoLink("hey check out this search engine (http://www.google.com?q=hello(spencer))"),
|
72
|
+
"hey check out this search engine (<a href=\"http://www.google.com?q=hello(spencer)\">http://www.google.com?q=hello(spencer)</a>)",
|
73
|
+
"Parenthesis around url are not part of url #2"
|
74
|
+
);
|
75
|
+
|
76
|
+
this.equal(
|
77
|
+
this.autoLink("hey check out this search engine <span>http://www.google.com?q=hello(spencer)</span>"),
|
78
|
+
"hey check out this search engine <span><a href=\"http://www.google.com?q=hello(spencer)\">http://www.google.com?q=hello(spencer)</a></span>",
|
79
|
+
"Urls in tags are correctly auto linked"
|
80
|
+
);
|
81
|
+
|
82
|
+
this.equal(
|
83
|
+
this.autoLink("http://google.de and http://yahoo.com as well as <span>http://de.finance.yahoo.com</span> <a href=\"http://google.com\" class=\"more\">http://google.com</a>"),
|
84
|
+
"<a href=\"http://google.de\">http://google.de</a> and <a href=\"http://yahoo.com\">http://yahoo.com</a> as well as <span><a href=\"http://de.finance.yahoo.com\">http://de.finance.yahoo.com</a></span> <a href=\"http://google.com\" class=\"more\">http://google.com</a>",
|
85
|
+
"Multiple urls are correctly auto linked"
|
86
|
+
);
|
87
|
+
|
88
|
+
this.equal(
|
89
|
+
this.autoLink("<script>http://google.de</script>"),
|
90
|
+
"<script>http://google.de</script>",
|
91
|
+
"Urls in SCRIPT elements are not touched"
|
92
|
+
);
|
93
|
+
|
94
|
+
this.equal(
|
95
|
+
this.autoLink("<script>http://google.de</script>"),
|
96
|
+
"<script>http://google.de</script>",
|
97
|
+
"Urls in SCRIPT elements are not touched"
|
98
|
+
);
|
99
|
+
|
100
|
+
this.equal(
|
101
|
+
this.autoLink(" http://www.google.de"),
|
102
|
+
" <a href=\"http://www.google.de\">http://www.google.de</a>",
|
103
|
+
"Check if white space in front of url is preserved"
|
104
|
+
);
|
105
|
+
});
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module("wysihtml5.dom.contains", {
|
2
|
+
setup: function() {
|
3
|
+
this.container = document.createElement("div");
|
4
|
+
document.body.appendChild(this.container);
|
5
|
+
},
|
6
|
+
|
7
|
+
teardown: function() {
|
8
|
+
this.container.parentNode.removeChild(this.container);
|
9
|
+
}
|
10
|
+
});
|
11
|
+
|
12
|
+
|
13
|
+
test("Basic test", function() {
|
14
|
+
ok(wysihtml5.dom.contains(document.documentElement, document.body));
|
15
|
+
ok(wysihtml5.dom.contains(document.body, this.container));
|
16
|
+
ok(!wysihtml5.dom.contains(this.container, document.body));
|
17
|
+
ok(!wysihtml5.dom.contains(document.body, document.body));
|
18
|
+
});
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module("wysihtml5.dom.convertToList", {
|
2
|
+
equal: function(actual, expected, message) {
|
3
|
+
return wysihtml5.assert.htmlEqual(actual, expected, message);
|
4
|
+
},
|
5
|
+
|
6
|
+
convertToList: function(html, type) {
|
7
|
+
var container = wysihtml5.dom.getAsDom(html);
|
8
|
+
document.body.appendChild(container);
|
9
|
+
wysihtml5.dom.convertToList(container.firstChild, type);
|
10
|
+
var innerHTML = container.innerHTML;
|
11
|
+
container.parentNode.removeChild(container);
|
12
|
+
return innerHTML;
|
13
|
+
}
|
14
|
+
});
|
15
|
+
|
16
|
+
test("Basic tests for UL", function() {
|
17
|
+
this.equal(
|
18
|
+
this.convertToList("<div>foo</div>", "ul"),
|
19
|
+
"<ul><li>foo</li></ul>"
|
20
|
+
);
|
21
|
+
|
22
|
+
this.equal(
|
23
|
+
this.convertToList("<span></span>", "ul"),
|
24
|
+
"<ul></ul>"
|
25
|
+
);
|
26
|
+
|
27
|
+
this.equal(
|
28
|
+
this.convertToList("<span>foo<br>bar</span>", "ul"),
|
29
|
+
"<ul><li>foo</li><li>bar</li></ul>"
|
30
|
+
);
|
31
|
+
|
32
|
+
this.equal(
|
33
|
+
this.convertToList("<span>foo<br>bar<div>baz</div></span>", "ul"),
|
34
|
+
"<ul><li>foo</li><li>bar</li><li><div>baz</div></li></ul>"
|
35
|
+
);
|
36
|
+
|
37
|
+
this.equal(
|
38
|
+
this.convertToList("<span><div></div><h1></h1><p>yeah</p></span>", "ul"),
|
39
|
+
"<ul><li><div></div></li><li><h1></h1></li><li><p>yeah</p></li></ul>"
|
40
|
+
);
|
41
|
+
|
42
|
+
this.equal(
|
43
|
+
this.convertToList("<span><b>foo bar<br></b><b>foo bar</b></span>", "ul"),
|
44
|
+
"<ul><li><b>foo bar</b></li><li><b>foo bar</b></li></ul>"
|
45
|
+
);
|
46
|
+
|
47
|
+
this.equal(
|
48
|
+
this.convertToList("<span><div>foo</div><br><div>bar</div></span>", "ul"),
|
49
|
+
"<ul><li><div>foo</div></li><li><div>bar</div></li></ul>"
|
50
|
+
);
|
51
|
+
|
52
|
+
this.equal(
|
53
|
+
this.convertToList("<span><div>foo<br></div><div>bar</div></span>", "ul"),
|
54
|
+
"<ul><li><div>foo</div></li><li><div>bar</div></li></ul>"
|
55
|
+
);
|
56
|
+
});
|
57
|
+
|
58
|
+
test("Basic tests for OL", function() {
|
59
|
+
this.equal(
|
60
|
+
this.convertToList("<div>foo</div>", "ol"),
|
61
|
+
"<ol><li>foo</li></ol>"
|
62
|
+
);
|
63
|
+
|
64
|
+
this.equal(
|
65
|
+
this.convertToList("<span></span>", "ol"),
|
66
|
+
"<ol></ol>"
|
67
|
+
);
|
68
|
+
|
69
|
+
this.equal(
|
70
|
+
this.convertToList("<span>foo<br>bar</span>", "ol"),
|
71
|
+
"<ol><li>foo</li><li>bar</li></ol>"
|
72
|
+
);
|
73
|
+
|
74
|
+
this.equal(
|
75
|
+
this.convertToList("<span>foo<br>bar<div>baz</div></span>", "ol"),
|
76
|
+
"<ol><li>foo</li><li>bar</li><li><div>baz</div></li></ol>"
|
77
|
+
);
|
78
|
+
|
79
|
+
this.equal(
|
80
|
+
this.convertToList("<span><div></div><h1></h1><p>yeah</p></span>", "ol"),
|
81
|
+
"<ol><li><div></div></li><li><h1></h1></li><li><p>yeah</p></li></ol>"
|
82
|
+
);
|
83
|
+
});
|
84
|
+
|
85
|
+
|
86
|
+
test("Test whether it doesn't convert dom trees that are already a list", function() {
|
87
|
+
this.equal(
|
88
|
+
this.convertToList("<ol><li>foo</li></ol>", "ol"),
|
89
|
+
"<ol><li>foo</li></ol>"
|
90
|
+
);
|
91
|
+
|
92
|
+
this.equal(
|
93
|
+
this.convertToList("<menu><li>foo</li></menu>", "ol"),
|
94
|
+
"<menu><li>foo</li></menu>"
|
95
|
+
);
|
96
|
+
|
97
|
+
this.equal(
|
98
|
+
this.convertToList("<ul><li>foo</li></ul>", "ol"),
|
99
|
+
"<ul><li>foo</li></ul>"
|
100
|
+
);
|
101
|
+
});
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module("wysihtml5.dom.copyAttributes", {
|
2
|
+
setup: function() {
|
3
|
+
this.div = document.createElement("div");
|
4
|
+
this.span = document.createElement("span");
|
5
|
+
this.anotherDiv = document.createElement("div");
|
6
|
+
this.iframe = document.createElement("iframe");
|
7
|
+
|
8
|
+
this.iframe.src = "javascript:'<html></html>'";
|
9
|
+
document.body.appendChild(this.iframe);
|
10
|
+
},
|
11
|
+
|
12
|
+
teardown: function() {
|
13
|
+
this.iframe.parentNode.removeChild(this.iframe);
|
14
|
+
}
|
15
|
+
});
|
16
|
+
|
17
|
+
|
18
|
+
test("Basic Tests", function() {
|
19
|
+
var attributes = { title: "foobar", lang: "en", className: "foo bar" };
|
20
|
+
wysihtml5.dom.setAttributes(attributes).on(this.div);
|
21
|
+
wysihtml5.dom.copyAttributes(["title", "lang", "className"]).from(this.div).to(this.span);
|
22
|
+
|
23
|
+
equal(this.span.title, attributes.title, "Title correctly copied");
|
24
|
+
equal(this.span.lang, attributes.lang, "Lang correctly copied");
|
25
|
+
equal(this.span.className, attributes.className, "Class correctly copied");
|
26
|
+
});
|
27
|
+
|
28
|
+
|
29
|
+
asyncTest("Test copying attributes from one element to another element which is in an iframe", function() {
|
30
|
+
expect(1);
|
31
|
+
|
32
|
+
var that = this;
|
33
|
+
|
34
|
+
// Timeout needed to make sure that the iframe is ready
|
35
|
+
setTimeout(function() {
|
36
|
+
var iframeDocument = that.iframe.contentWindow.document,
|
37
|
+
iframeElement = iframeDocument.createElement("div");
|
38
|
+
|
39
|
+
iframeDocument.body.appendChild(iframeElement);
|
40
|
+
that.span.title = "heya!";
|
41
|
+
|
42
|
+
wysihtml5.dom
|
43
|
+
.copyAttributes(["title"])
|
44
|
+
.from(that.span)
|
45
|
+
.to(iframeElement);
|
46
|
+
|
47
|
+
equal(iframeElement.title, "heya!", "Element in iframe correctly got attributes copied over");
|
48
|
+
|
49
|
+
start();
|
50
|
+
}, 1000);
|
51
|
+
});
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module("wysihtml5.dom.copyStyles", {
|
2
|
+
setup: function() {
|
3
|
+
this.div = document.createElement("div");
|
4
|
+
this.span = document.createElement("span");
|
5
|
+
this.anotherDiv = document.createElement("div");
|
6
|
+
this.iframe = document.createElement("iframe");
|
7
|
+
|
8
|
+
this.span.id = "wysihtml5-test-span";
|
9
|
+
this.iframe.id = "javascript:'<html></html>'";
|
10
|
+
|
11
|
+
document.body.appendChild(this.div);
|
12
|
+
document.body.appendChild(this.span);
|
13
|
+
document.body.appendChild(this.anotherDiv);
|
14
|
+
document.body.appendChild(this.iframe);
|
15
|
+
},
|
16
|
+
|
17
|
+
teardown: function() {
|
18
|
+
this.div.parentNode.removeChild(this.div);
|
19
|
+
this.span.parentNode.removeChild(this.span);
|
20
|
+
this.anotherDiv.parentNode.removeChild(this.anotherDiv);
|
21
|
+
this.iframe.parentNode.removeChild(this.iframe);
|
22
|
+
}
|
23
|
+
});
|
24
|
+
|
25
|
+
|
26
|
+
test("Basic Tests", function() {
|
27
|
+
this.div.style.cssText = "width: 400px; height: 200px; text-align: right; float: left;";
|
28
|
+
|
29
|
+
wysihtml5.dom.copyStyles(["width", "height", "text-align", "float"]).from(this.div).to(this.span);
|
30
|
+
|
31
|
+
equal(wysihtml5.dom.getStyle("width") .from(this.span), "400px", "Width correctly copied");
|
32
|
+
equal(wysihtml5.dom.getStyle("height") .from(this.span), "200px", "Height correctly copied");
|
33
|
+
equal(wysihtml5.dom.getStyle("text-align") .from(this.span), "right", "Text-align correctly copied");
|
34
|
+
equal(wysihtml5.dom.getStyle("float") .from(this.span), "left", "Float correctly copied");
|
35
|
+
});
|
36
|
+
|
37
|
+
|
38
|
+
test("Whether it copies native user agent styles", function() {
|
39
|
+
wysihtml5.dom.copyStyles(["display"]).from(this.span).to(this.div);
|
40
|
+
|
41
|
+
equal(wysihtml5.dom.getStyle("display").from(this.div), "inline", "Display correctly copied");
|
42
|
+
});
|
43
|
+
|
44
|
+
|
45
|
+
test("Advanced tests", function() {
|
46
|
+
this.span.style.cssText = "color: rgb(255, 0, 0); -moz-border-radius: 5px 5px 5px 5px;";
|
47
|
+
this.div.style.cssText = "color: rgb(0, 255, 0); text-decoration: underline;";
|
48
|
+
|
49
|
+
wysihtml5.dom
|
50
|
+
.copyStyles(["color", "-moz-border-radius", "unknown-style"])
|
51
|
+
.from(this.span)
|
52
|
+
.to(this.div)
|
53
|
+
.andTo(this.anotherDiv);
|
54
|
+
|
55
|
+
// Opera and IE internally convert color values either to rgb or hexcode, and some version of IE either
|
56
|
+
// strip or add white spaces between rgb values
|
57
|
+
var divColor = wysihtml5.dom.getStyle("color").from(this.div).replace(/\s+/g, "");
|
58
|
+
ok(divColor == "rgb(255,0,0)" || divColor == "#ff0000", "First div has correct color");
|
59
|
+
|
60
|
+
var anotherDivColor = wysihtml5.dom.getStyle("color").from(this.anotherDiv).replace(/\s+/g, "");
|
61
|
+
ok(anotherDivColor == "rgb(255,0,0)" || anotherDivColor == "#ff0000", "Second div has correct color");
|
62
|
+
|
63
|
+
equal(wysihtml5.dom.getStyle("text-decoration").from(this.div), "underline", "Text-decoration hasn't been overwritten");
|
64
|
+
|
65
|
+
if ("MozBorderRadius" in this.div.style) {
|
66
|
+
equal(wysihtml5.dom.getStyle("-moz-border-radius").from(this.div), "5px 5px 5px 5px", "First div has correct border-radius");
|
67
|
+
equal(wysihtml5.dom.getStyle("-moz-border-radius").from(this.anotherDiv), "5px 5px 5px 5px", "Second div has correct border-radius");
|
68
|
+
}
|
69
|
+
});
|
70
|
+
|
71
|
+
|
72
|
+
asyncTest("Test copying styles from one element to another element which is in an iframe", function() {
|
73
|
+
expect(1);
|
74
|
+
|
75
|
+
var that = this;
|
76
|
+
|
77
|
+
// Timeout needed to make sure that the iframe is ready
|
78
|
+
setTimeout(function() {
|
79
|
+
var iframeDocument = that.iframe.contentWindow.document,
|
80
|
+
iframeElement = iframeDocument.createElement("div");
|
81
|
+
|
82
|
+
iframeDocument.body.appendChild(iframeElement);
|
83
|
+
that.span.style.cssText = "float: left;";
|
84
|
+
|
85
|
+
wysihtml5.dom
|
86
|
+
.copyStyles(["float"])
|
87
|
+
.from(that.span)
|
88
|
+
.to(iframeElement);
|
89
|
+
|
90
|
+
equal(iframeElement.style.styleFloat || iframeElement.style.cssFloat, "left", "Element in iframe correctly got css float copied over");
|
91
|
+
|
92
|
+
start();
|
93
|
+
}, 1000);
|
94
|
+
});
|
95
|
+
|
96
|
+
|
97
|
+
test("Test copying styles that were set via style element", function() {
|
98
|
+
wysihtml5.dom
|
99
|
+
.insertCSS(["span#wysihtml5-test-span { font-size: 16px; }"])
|
100
|
+
.into(document);
|
101
|
+
|
102
|
+
wysihtml5.dom
|
103
|
+
.copyStyles(["font-size"])
|
104
|
+
.from(this.span)
|
105
|
+
.to(this.div);
|
106
|
+
|
107
|
+
equal(
|
108
|
+
wysihtml5.dom.getStyle("font-size").from(this.div), "16px", "Font-size correctly copied"
|
109
|
+
);
|
110
|
+
});
|