dante-editor 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/javascripts/dante/editor.js.coffee +67 -26
- data/bower.json +1 -1
- data/dist/0.0.7/js/dante-editor.js +1 -1
- data/dist/0.0.9/css/dante-editor.css +1116 -0
- data/dist/0.0.9/fonts/dante/dante.eot +0 -0
- data/dist/0.0.9/fonts/dante/dante.svg +14 -0
- data/dist/0.0.9/fonts/dante/dante.ttf +0 -0
- data/dist/0.0.9/fonts/dante/dante.woff +0 -0
- data/dist/0.0.9/fonts/dante/fontello.eot +0 -0
- data/dist/0.0.9/fonts/dante/fontello.svg +36 -0
- data/dist/0.0.9/fonts/dante/fontello.ttf +0 -0
- data/dist/0.0.9/fonts/dante/fontello.woff +0 -0
- data/dist/0.0.9/images/dante/media-loading-placeholder.png +0 -0
- data/dist/0.0.9/js/dante-editor.js +2575 -0
- data/lib/dante-editor/version.rb +1 -1
- metadata +13 -2
Binary file
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<?xml version="1.0" standalone="no"?>
|
2
|
+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
|
3
|
+
<svg xmlns="http://www.w3.org/2000/svg">
|
4
|
+
<metadata>Generated by IcoMoon</metadata>
|
5
|
+
<defs>
|
6
|
+
<font id="icomoon" horiz-adv-x="1024">
|
7
|
+
<font-face units-per-em="1024" ascent="960" descent="-64" />
|
8
|
+
<missing-glyph horiz-adv-x="1024" />
|
9
|
+
<glyph unicode=" " d="" horiz-adv-x="512" />
|
10
|
+
<glyph unicode="" d="M256 759.559v-623.174c0-70.118 47.316-95.291 105.683-55.222l428.634 294.258c58.622 40.244 58.367 105.034 0 145.103l-428.634 294.258c-58.622 40.244-105.683 15.345-105.683-55.222zM320 766.664l426.195-293.488c30.527-20.25 29.832-31 0-51.070l-426.195-295.039v639.598z" />
|
11
|
+
<glyph unicode="" d="M294.4 768l0.489 2.446c13.868 69.342 82.599 125.554 152.977 125.554h128.267c70.619 0 139.014-55.74 152.977-125.554l0.489-2.446h166.78c70.483 0 127.62-57.611 127.62-127.489v-449.022c0-70.41-57.249-127.489-127.62-127.489h-768.76c-70.483 0-127.62 57.611-127.62 127.489v449.022c0 70.41 57.249 127.489 127.62 127.489h166.78zM347.123 704h-218.685c-35.641 0-64.438-28.583-64.438-63.843v-448.314c0-35.279 28.85-63.843 64.438-63.843h767.124c35.641 0 64.438 28.583 64.438 63.843v448.314c0 35.279-28.85 63.843-64.438 63.843h-218.816l-13.864 65.375c-7.263 34.25-41.874 62.625-77.145 62.625h-147.627c-35.433 0-69.805-28.038-77.134-62.625l-13.853-65.375zM320 448c0-105.823 85.961-192 192-192 105.823 0 192 85.961 192 192 0 105.823-85.961 192-192 192-105.823 0-192-85.961-192-192zM384 448c0 70.692 56.815 128 128 128 70.692 0 128-56.815 128-128 0-70.692-56.815-128-128-128-70.692 0-128 56.815-128 128z" />
|
12
|
+
<glyph unicode="" d="M544 416v-375.294c0-17.673-14.327-32-32-32s-32 14.327-32 32v375.294h-375.294c-17.673 0-32 14.327-32 32s14.327 32 32 32h375.294v375.294c0 17.673 14.327 32 32 32s32-14.327 32-32v-375.294h375.294c17.673 0 32-14.327 32-32s-14.327-32-32-32h-375.294z" />
|
13
|
+
<glyph unicode="" d="M882.24 449.498l-235.855 234.241c-12.497 12.411-12.497 32.534 0 44.945s32.758 12.411 45.255 0l253.704-251.968c1.872-1.201 3.645-2.616 5.284-4.244 12.497-12.411 12.497-32.534 0-44.945l-257.992-256.226c-12.497-12.411-32.758-12.411-45.255 0s-12.497 32.534 0 44.945l234.859 233.252zM67.842 461.229c-6.562-12.128-4.719-27.599 5.53-37.848 2.863-2.863 6.133-5.070 9.624-6.621l249.364-249.364c12.497-12.497 32.758-12.497 45.255 0s12.497 32.758 0 45.255l-234.859 234.859 233.863 233.863c12.497 12.497 12.497 32.758 0 45.255s-32.758 12.497-45.255 0l-251.712-251.712c-1.872-1.209-3.645-2.634-5.284-4.273-2.805-2.805-4.981-6.002-6.527-9.414v0 0z" />
|
14
|
+
</font></defs></svg>
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<?xml version="1.0" standalone="no"?>
|
2
|
+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
3
|
+
<svg xmlns="http://www.w3.org/2000/svg">
|
4
|
+
<metadata>Copyright (C) 2012 by original authors @ fontello.com</metadata>
|
5
|
+
<defs>
|
6
|
+
<font id="fontello" horiz-adv-x="1000" >
|
7
|
+
<font-face font-family="fontello" font-weight="400" font-stretch="normal" units-per-em="1000" ascent="850" descent="-150" />
|
8
|
+
<missing-glyph horiz-adv-x="1000" />
|
9
|
+
<glyph glyph-name="location" unicode="" d="M429 493q0 59-42 101t-101 42-101-42-42-101 42-101 101-42 101 42 42 101z m143 0q0-61-18-100l-203-432q-9-18-27-29t-38-11-38 11-26 29l-204 432q-18 39-18 100 0 118 84 202t202 84 202-84 84-202z" horiz-adv-x="571.429" />
|
10
|
+
<glyph glyph-name="fit" unicode="" d="M429 314l0-250q0-15-11-25t-25-11-25 11l-80 80-185-185q-6-6-13-6t-13 6l-64 64q-6 6-6 13t6 13l185 185-80 80q-11 11-11 25t11 25 25 11l250 0q15 0 25-11t11-25z m421 375q0-7-6-13l-185-185 80-80q11-11 11-25t-11-25-25-11l-250 0q-15 0-25 11t-11 25l0 250q0 15 11 25t25 11 25-11l80-80 185 185q6 6 13 6t13-6l64-64q6-6 6-13z" horiz-adv-x="857.143" />
|
11
|
+
<glyph glyph-name="bold" unicode="" d="M310 1q42-18 78-18 73 0 121 23t68 63q21 39 21 101 0 64-23 100-32 52-79 70-45 18-138 18-41 0-56-6l0-80-1-97 2-151q0-8 7-25z m-8 416q24-4 61-4 98 0 147 36t50 125q0 62-47 104t-142 42q-29 0-73-7 0-25 1-43 4-68 3-156l-1-55q0-24 1-43z m-302-496l1 52q25 5 38 7 43 7 69 17 9 15 12 28 5 37 5 108l-1 277q-3 143-5 225-1 49-6 61-1 2-7 7-10 7-39 8-17 1-64 7l-2 46 145 3 212 7 25 1q3 0 8 0t8 0q1 0 12 0t23 0l41 0q49 0 107-15 24-7 54-22 32-16 57-42t36-58 12-68q0-39-18-71t-53-59q-15-11-84-43 99-23 149-81 51-59 51-132 0-42-16-90-12-35-40-65-37-40-78-60t-113-33q-46-8-110-6l-110 2q-47 1-166-6-18-2-152-6z" horiz-adv-x="785.714" />
|
12
|
+
<glyph glyph-name="italic" unicode="" d="M0-77l9 47q2 1 43 11 42 11 65 22 16 21 23 56l15 78 31 150 7 36q4 25 9 47t9 37 7 26 5 17 2 6l16 88 9 35 12 75 4 28 0 21q-23 12-80 16-16 1-21 2l11 57 177-8q22-1 41-1 37 0 119 5 18 1 38 3t20 1q-1-11-3-21-4-16-7-28-31-11-61-17-36-9-56-17-7-17-13-49-5-25-7-46-25-111-37-171l-34-174-21-88-24-131-7-25q-1-4 1-15 36-8 66-12 20-3 37-6-1-16-4-32-4-17-5-23-10 0-13-1-13-1-23-1-5 0-16 2t-81 9l-110 1q-23 1-97-6-41-4-55-5z" horiz-adv-x="571.429" />
|
13
|
+
<glyph glyph-name="justifyleft" unicode="" d="M1000 100l0-71q0-15-11-25t-25-11l-929 0q-15 0-25 11t-11 25l0 71q0 15 11 25t25 11l929 0q15 0 25-11t11-25z m-214 214l0-71q0-15-11-25t-25-11l-714 0q-15 0-25 11t-11 25l0 71q0 15 11 25t25 11l714 0q15 0 25-11t11-25z m143 214l0-71q0-15-11-25t-25-11l-857 0q-15 0-25 11t-11 25l0 71q0 15 11 25t25 11l857 0q15 0 25-11t11-25z m-214 214l0-71q0-15-11-25t-25-11l-643 0q-15 0-25 11t-11 25l0 71q0 15 11 25t25 11l643 0q15 0 25-11t11-25z" horiz-adv-x="1000" />
|
14
|
+
<glyph glyph-name="justifycenter" unicode="" d="M1000 100l0-71q0-15-11-25t-25-11l-929 0q-15 0-25 11t-11 25l0 71q0 15 11 25t25 11l929 0q15 0 25-11t11-25z m-214 214l0-71q0-15-11-25t-25-11l-500 0q-15 0-25 11t-11 25l0 71q0 15 11 25t25 11l500 0q15 0 25-11t11-25z m143 214l0-71q0-15-11-25t-25-11l-786 0q-15 0-25 11t-11 25l0 71q0 15 11 25t25 11l786 0q15 0 25-11t11-25z m-214 214l0-71q0-15-11-25t-25-11l-357 0q-15 0-25 11t-11 25l0 71q0 15 11 25t25 11l357 0q15 0 25-11t11-25z" horiz-adv-x="1000" />
|
15
|
+
<glyph glyph-name="justifyright" unicode="" d="M1000 100l0-71q0-15-11-25t-25-11l-929 0q-15 0-25 11t-11 25l0 71q0 15 11 25t25 11l929 0q15 0 25-11t11-25z m0 214l0-71q0-15-11-25t-25-11l-714 0q-15 0-25 11t-11 25l0 71q0 15 11 25t25 11l714 0q15 0 25-11t11-25z m0 214l0-71q0-15-11-25t-25-11l-857 0q-15 0-25 11t-11 25l0 71q0 15 11 25t25 11l857 0q15 0 25-11t11-25z m0 214l0-71q0-15-11-25t-25-11l-643 0q-15 0-25 11t-11 25l0 71q0 15 11 25t25 11l643 0q15 0 25-11t11-25z" horiz-adv-x="1000" />
|
16
|
+
<glyph glyph-name="justifyfull" unicode="" d="M1000 100l0-71q0-15-11-25t-25-11l-929 0q-15 0-25 11t-11 25l0 71q0 15 11 25t25 11l929 0q15 0 25-11t11-25z m0 214l0-71q0-15-11-25t-25-11l-929 0q-15 0-25 11t-11 25l0 71q0 15 11 25t25 11l929 0q15 0 25-11t11-25z m0 214l0-71q0-15-11-25t-25-11l-929 0q-15 0-25 11t-11 25l0 71q0 15 11 25t25 11l929 0q15 0 25-11t11-25z m0 214l0-71q0-15-11-25t-25-11l-929 0q-15 0-25 11t-11 25l0 71q0 15 11 25t25 11l929 0q15 0 25-11t11-25z" horiz-adv-x="1000" />
|
17
|
+
<glyph glyph-name="outdent" unicode="" d="M214 546l0-321q0-7-5-13t-13-5q-8 0-13 5l-161 161q-5 5-5 13t5 13l161 161q5 5 13 5 7 0 13-5t5-13z m786-429l0-107q0-7-5-13t-13-5l-964 0q-7 0-13 5t-5 13l0 107q0 7 5 13t13 5l964 0q7 0 13-5t5-13z m0 214l0-107q0-7-5-13t-13-5l-607 0q-7 0-13 5t-5 13l0 107q0 7 5 13t13 5l607 0q7 0 13-5t5-13z m0 214l0-107q0-7-5-13t-13-5l-607 0q-7 0-13 5t-5 13l0 107q0 7 5 13t13 5l607 0q7 0 13-5t5-13z m0 214l0-107q0-7-5-13t-13-5l-964 0q-7 0-13 5t-5 13l0 107q0 7 5 13t13 5l964 0q7 0 13-5t5-13z" horiz-adv-x="1000" />
|
18
|
+
<glyph glyph-name="indent" unicode="" d="M196 386q0-8-5-13l-161-161q-5-5-13-5-7 0-13 5t-5 13l0 321q0 7 5 13t13 5q8 0 13-5l161-161q5-5 5-13z m804-268l0-107q0-7-5-13t-13-5l-964 0q-7 0-13 5t-5 13l0 107q0 7 5 13t13 5l964 0q7 0 13-5t5-13z m0 214l0-107q0-7-5-13t-13-5l-607 0q-7 0-13 5t-5 13l0 107q0 7 5 13t13 5l607 0q7 0 13-5t5-13z m0 214l0-107q0-7-5-13t-13-5l-607 0q-7 0-13 5t-5 13l0 107q0 7 5 13t13 5l607 0q7 0 13-5t5-13z m0 214l0-107q0-7-5-13t-13-5l-964 0q-7 0-13 5t-5 13l0 107q0 7 5 13t13 5l964 0q7 0 13-5t5-13z" horiz-adv-x="1000" />
|
19
|
+
<glyph glyph-name="mode" unicode="" d="M429 46l0 607q-83 0-152-41t-110-110-41-152 41-152 110-110 152-41z m429 304q0-117-57-215t-156-156-215-57-215 57-156 156-57 215 57 215 156 156 215 57 215-57 156-156 57-215z" horiz-adv-x="857.143" />
|
20
|
+
<glyph glyph-name="fullscreen" unicode="" d="M716 548l-198-198 198-198 80 80q16 17 39 8 22-9 22-33l0-250q0-15-11-25t-25-11l-250 0q-23 0-33 22-9 22 8 39l80 80-198 198-198-198 80-80q17-17 8-39t-33-22l-250 0q-15 0-25 11t-11 25l0 250q0 23 22 33 22 9 39-8l80-80 198 198-198 198-80-80q-11-11-25-11-7 0-13 3-22 9-22 33l0 250q0 15 11 25t25 11l250 0q23 0 33-22 9-22-8-39l-80-80 198-198 198 198-80 80q-17 17-8 39t33 22l250 0q15 0 25-11t11-25l0-250q0-23-22-33-7-3-14-3-15 0-25 11z" horiz-adv-x="857.143" />
|
21
|
+
<glyph glyph-name="insertunorderedlist" unicode="" d="M214 64q0-45-31-76t-76-31-76 31-31 76 31 76 76 31 76-31 31-76z m0 286q0-45-31-76t-76-31-76 31-31 76 31 76 76 31 76-31 31-76z m786-232l0-107q0-7-5-13t-13-5l-679 0q-7 0-13 5t-5 13l0 107q0 7 5 13t13 5l679 0q7 0 13-5t5-13z m-786 518q0-45-31-76t-76-31-76 31-31 76 31 76 76 31 76-31 31-76z m786-232l0-107q0-7-5-13t-13-5l-679 0q-7 0-13 5t-5 13l0 107q0 7 5 13t13 5l679 0q7 0 13-5t5-13z m0 286l0-107q0-7-5-13t-13-5l-679 0q-7 0-13 5t-5 13l0 107q0 7 5 13t13 5l679 0q7 0 13-5t5-13z" horiz-adv-x="1000" />
|
22
|
+
<glyph glyph-name="insertorderedlist" unicode="" d="M213-54q0-45-30-70t-76-26q-59 0-96 37l32 49q27-25 59-25 16 0 28 8t12 24q0 36-59 31l-15 31q4 6 18 24t24 30 21 21l0 1q-9 0-27-1t-27-1l0-30-59 0 0 85 186 0 0-49-53-64q28-7 45-27t17-49z m1 350l0-89-202 0q-3 20-3 30 0 28 13 52t32 38 37 27 32 24 13 25q0 14-8 21t-22 8q-26 0-45-32l-47 33q13 28 40 44t59 16q41 0 69-23t28-63q0-28-19-51t-42-36-42-28-20-29l71 0 0 33 59 0z m786-178l0-107q0-7-5-13t-13-5l-679 0q-7 0-13 5t-5 13l0 107q0 8 5 13t13 5l679 0q7 0 13-5t5-13z m-786 502l0-55-187 0 0 55 60 0q0 23 0 68t0 68l0 7-1 0q-4-9-28-30l-40 42 76 71 59 0 0-225 60 0z m786-216l0-107q0-7-5-13t-13-5l-679 0q-7 0-13 5t-5 13l0 107q0 8 5 13t13 5l679 0q7 0 13-5t5-13z m0 286l0-107q0-7-5-13t-13-5l-679 0q-7 0-13 5t-5 13l0 107q0 7 5 13t13 5l679 0q7 0 13-5t5-13z" horiz-adv-x="1000" />
|
23
|
+
<glyph glyph-name="strikethrough" unicode="" d="M982 350q8 0 13-5t5-13l0-36q0-8-5-13t-13-5l-964 0q-8 0-13 5t-5 13l0 36q0 8 5 13t13 5l964 0z m-713 36q-16 20-28 45-27 54-27 105 0 101 75 172 74 71 219 71 28 0 93-11 37-7 99-27 6-21 12-66 8-69 8-102 0-10-3-25l-7-2-47 3-8 1q-28 83-57 114-49 51-117 51-64 0-102-33-37-32-37-81 0-41 37-78t156-72q39-11 97-37 32-16 53-29l-415 0z m283-143l229 0q4-22 4-51 0-62-23-118-13-31-40-58-21-20-61-45-45-27-85-37-45-12-113-12-64 0-109 13l-78 22q-32 9-40 16-4 4-4 12l0 7q0 60-1 87-1 17 0 38l1 21 0 25 57 1q8-19 17-40t13-31 7-15q20-32 45-52 24-20 59-32 33-12 74-12 36 0 78 15 43 15 68 48 26 34 26 72 0 47-45 88-19 16-76 40z" horiz-adv-x="1000" />
|
24
|
+
<glyph glyph-name="underline" unicode="" d="M27 726q-21 1-25 2l-2 49q7 1 22 1 33 0 62-2 74-4 93-4 48 0 94 2 65 2 81 3 31 0 48 1l-1-8 1-36 0-5q-33-5-69-5-33 0-44-14-7-8-7-74 0-7 0-18t0-14l1-128 8-156q3-69 28-113 20-33 54-51 49-26 99-26 58 0 107 16 31 10 55 28 27 20 36 36 20 31 30 64 12 41 12 128 0 44-2 71t-6 68-8 89l-2 33q-3 37-13 49-19 20-43 19l-56-1-8 2 1 48 47 0 114-6q42-2 109 6l10-1q3-21 3-28 0-4-2-17-25-7-47-7-41-6-44-9-8-8-8-23 0-4 1-15t1-17q4-11 12-221 3-109-8-170-8-42-23-68-21-36-62-69-42-32-102-50-61-18-142-18-93 0-158 26-66 26-100 68t-46 109q-9 45-9 132l0 186q0 105-9 119-14 20-82 22z m830-786l0 36q0 8-5 13t-13 5l-821 0q-8 0-13-5t-5-13l0-36q0-8 5-13t13-5l821 0q8 0 13 5t5 13z" horiz-adv-x="857.143" />
|
25
|
+
<glyph glyph-name="blockquote" unicode="" d="M429 671l0-393q0-58-23-111t-61-91-91-61-111-23l-36 0q-15 0-25 11t-11 25l0 71q0 15 11 25t25 11l36 0q59 0 101 42t42 101l0 18q0 22-16 38t-38 16l-125 0q-45 0-76 31t-31 76l0 214q0 45 31 76t76 31l214 0q45 0 76-31t31-76z m500 0l0-393q0-58-23-111t-61-91-91-61-111-23l-36 0q-15 0-25 11t-11 25l0 71q0 15 11 25t25 11l36 0q59 0 101 42t42 101l0 18q0 22-16 38t-38 16l-125 0q-45 0-76 31t-31 76l0 214q0 45 31 76t76 31l214 0q45 0 76-31t31-76z" horiz-adv-x="928.571" />
|
26
|
+
<glyph glyph-name="undo" unicode="" d="M1000 225q0-93-71-252-2-4-6-13t-8-17-7-12q-7-9-16-9-8 0-13 6t-5 14q0 5 1 15t1 13q3 38 3 69 0 56-10 101t-27 77-45 56-59 39-74 24-86 12-98 3l-125 0 0-143q0-15-11-25t-25-11-25 11l-286 286q-11 11-11 25t11 25l286 286q11 11 25 11t25-11 11-25l0-143 125 0q398 0 488-225 30-75 30-186z" horiz-adv-x="1000" />
|
27
|
+
<glyph glyph-name="code" unicode="" d="M344 69l-28-28q-6-6-13-6t-13 6l-260 260q-6 6-6 13t6 13l260 260q6 6 13 6t13-6l28-28q6-6 6-13t-6-13l-219-219 219-219q6-6 6-13t-6-13z m330 595l-208-720q-2-7-9-11t-13-1l-35 9q-7 2-11 9t-1 14l208 720q2 7 9 11t13 1l35-9q7-2 11-9t1-14z m367-363l-260-260q-6-6-13-6t-13 6l-28 28q-6 6-6 13t6 13l219 219-219 219q-6 6-6 13t6 13l28 28q6 6 13 6t13-6l260-260q6-6 6-13t-6-13z" horiz-adv-x="1071.429" />
|
28
|
+
<glyph glyph-name="unlink" unicode="" d="M245 141l-143-143q-6-5-13-5t-13 5q-5 6-5 13t5 13l143 143q6 5 13 5t13-5q5-6 5-13t-5-13z m94-23l0-179q0-8-5-13t-13-5-13 5-5 13l0 179q0 8 5 13t13 5 13-5 5-13z m-125 125q0-8-5-13t-13-5l-179 0q-8 0-13 5t-5 13 5 13 13 5l179 0q8 0 13-5t5-13z m705-71q0-67-47-113l-82-81q-46-46-113-46-68 0-114 47l-186 187q-12 12-23 31l133 10 152-153q15-15 38-15t38 15l82 81q16 16 16 37 0 22-16 38l-153 153 10 133q20-12 31-23l187-187q47-48 47-114z m-344 404l-133-10-152 153q-16 16-38 16t-38-15l-82-81q-16-16-16-37 0-22 16-38l153-153-10-134q-20 12-31 23l-187 187q-47 48-47 114 0 67 47 113l82 81q46 46 113 46 68 0 114-47l186-187q12-12 23-31z m353-47q0-8-5-13t-13-5l-179 0q-8 0-13 5t-5 13 5 13 13 5l179 0q8 0 13-5t5-13z m-304 304l0-179q0-8-5-13t-13-5-13 5-5 13l0 179q0 8 5 13t13 5 13-5 5-13z m227-84l-143-143q-6-5-13-5t-13 5q-5 6-5 13t5 13l143 143q6 5 13 5t13-5q5-6 5-13t-5-13z" horiz-adv-x="928.571" />
|
29
|
+
<glyph glyph-name="superscript" unicode="" d="M501 86l0-93-138 0-89 141-13 23q-4 5-6 12l-2 0-5-12q-6-11-14-25l-86-140-144 0 0 93 71 0 110 162-103 152-76 0 0 94 154 0 78-127q1-2 13-23 4-5 6-12l2 0q2 5 6 12l14 23 78 127 143 0 0-94-70 0-103-149 114-165 61 0z m355 379l0-115-287 0-2 15q-2 16-2 26 0 36 15 65t36 48 47 36 47 30 36 30 15 36q0 21-16 35t-39 14q-28 0-54-22-8-6-20-21l-59 51q15 21 35 37 46 36 105 36 61 0 99-33t38-88q0-31-14-57t-35-43-45-33-46-28-37-29-17-35l129 0 0 45 70 0z" horiz-adv-x="857.143" />
|
30
|
+
<glyph glyph-name="subscript" unicode="" d="M501 86l0-93-138 0-89 141-13 23q-4 5-6 12l-2 0-5-12q-6-11-14-25l-86-140-144 0 0 93 71 0 110 162-103 152-76 0 0 94 154 0 78-127q1-2 13-23 4-5 6-12l2 0q2 5 6 12l14 23 78 127 143 0 0-94-70 0-103-149 114-165 61 0z m357-121l0-115-287 0-2 15q-2 25-2 26 0 36 15 65t36 48 47 36 47 30 36 30 15 36q0 21-16 35t-39 14q-28 0-54-22-8-6-20-21l-59 51q15 21 35 37 45 36 105 36 61 0 99-33t38-88q0-37-19-66t-47-48-56-35-49-35-23-41l129 0 0 45 70 0z" horiz-adv-x="857.143" />
|
31
|
+
<glyph glyph-name="inserthorizontalrule" unicode="" d="M214 439l0-107q0-22-16-38t-38-16l-107 0q-22 0-38 16t-16 38l0 107q0 22 16 38t38 16l107 0q22 0 38-16t16-38z m286 0l0-107q0-22-16-38t-38-16l-107 0q-22 0-38 16t-16 38l0 107q0 22 16 38t38 16l107 0q22 0 38-16t16-38z m286 0l0-107q0-22-16-38t-38-16l-107 0q-22 0-38 16t-16 38l0 107q0 22 16 38t38 16l107 0q22 0 38-16t16-38z" horiz-adv-x="785.714" />
|
32
|
+
<glyph glyph-name="pin" unicode="" d="M268 368l0 250q0 8-5 13t-13 5-13-5-5-13l0-250q0-8 5-13t13-5 13 5 5 13z m375-196q0-15-11-25t-25-11l-239 0-28-270q-1-7-6-11t-11-5l-1 0q-15 0-18 15l-42 271-225 0q-15 0-25 11t-11 25q0 69 44 124t99 55l0 286q-29 0-50 21t-21 50 21 50 50 21l357 0q29 0 50-21t21-50-21-50-50-21l0-286q55 0 99-55t44-124z" horiz-adv-x="642.857" />
|
33
|
+
<glyph glyph-name="createlink" unicode="" d="M812 171q0 22-16 38l-116 116q-16 16-38 16-23 0-40-18 2-2 11-10t12-12 8-11 7-14 2-15q0-22-16-38t-38-16q-8 0-15 2t-14 7-11 8-12 12-10 11q-18-17-18-41 0-22 16-38l115-116q15-15 38-15 22 0 38 15l82 81q16 16 16 37z m-392 393q0 22-16 38l-115 116q-16 16-38 16t-38-15l-82-81q-16-16-16-37 0-22 16-38l116-116q15-15 38-15t40 17q-2 2-11 10t-12 12-8 11-7 14-2 15q0 22 16 38t38 16q8 0 15-2t14-7 11-8 12-12 10-11q18 17 18 41z m499-393q0-67-47-113l-82-81q-46-46-113-46-68 0-114 47l-115 116q-46 46-46 113 0 69 49 117l-49 49q-48-49-116-49-67 0-114 47l-116 116q-47 47-47 114t47 113l82 81q46 46 113 46 68 0 114-47l115-116q46-46 46-113 0-69-49-117l49-49q48 49 116 49 67 0 114-47l116-116q47-47 47-114z" horiz-adv-x="928.571" />
|
34
|
+
</font>
|
35
|
+
</defs>
|
36
|
+
</svg>
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,2575 @@
|
|
1
|
+
(function() {
|
2
|
+
window.Dante = {
|
3
|
+
Editor: {
|
4
|
+
ToolTip: {},
|
5
|
+
PopOver: {},
|
6
|
+
Menu: {}
|
7
|
+
},
|
8
|
+
defaults: {
|
9
|
+
image_placeholder: '../images/dante/media-loading-placeholder.png'
|
10
|
+
},
|
11
|
+
version: "0.0.9"
|
12
|
+
};
|
13
|
+
|
14
|
+
}).call(this);
|
15
|
+
(function() {
|
16
|
+
var LINE_HEIGHT, is_caret_at_end_of_node, is_caret_at_start_of_node, utils;
|
17
|
+
|
18
|
+
String.prototype.killWhiteSpace = function() {
|
19
|
+
return this.replace(/\s/g, '');
|
20
|
+
};
|
21
|
+
|
22
|
+
String.prototype.reduceWhiteSpace = function() {
|
23
|
+
return this.replace(/\s+/g, ' ');
|
24
|
+
};
|
25
|
+
|
26
|
+
utils = {};
|
27
|
+
|
28
|
+
window.Dante.utils = utils;
|
29
|
+
|
30
|
+
utils.log = function(message, force) {
|
31
|
+
if (window.debugMode || force) {
|
32
|
+
return console.log(message);
|
33
|
+
}
|
34
|
+
};
|
35
|
+
|
36
|
+
utils.getBase64Image = function(img) {
|
37
|
+
var canvas, ctx, dataURL;
|
38
|
+
canvas = document.createElement("canvas");
|
39
|
+
canvas.width = img.width;
|
40
|
+
canvas.height = img.height;
|
41
|
+
ctx = canvas.getContext("2d");
|
42
|
+
ctx.drawImage(img, 0, 0);
|
43
|
+
dataURL = canvas.toDataURL("image/png");
|
44
|
+
return dataURL;
|
45
|
+
};
|
46
|
+
|
47
|
+
utils.generateUniqueName = function() {
|
48
|
+
return Math.random().toString(36).slice(8);
|
49
|
+
};
|
50
|
+
|
51
|
+
utils.saveSelection = function() {
|
52
|
+
var i, len, ranges, sel;
|
53
|
+
if (window.getSelection) {
|
54
|
+
sel = window.getSelection();
|
55
|
+
if (sel.getRangeAt && sel.rangeCount) {
|
56
|
+
ranges = [];
|
57
|
+
i = 0;
|
58
|
+
len = sel.rangeCount;
|
59
|
+
while (i < len) {
|
60
|
+
ranges.push(sel.getRangeAt(i));
|
61
|
+
++i;
|
62
|
+
}
|
63
|
+
return ranges;
|
64
|
+
}
|
65
|
+
} else {
|
66
|
+
if (document.selection && document.selection.createRange) {
|
67
|
+
return document.selection.createRange();
|
68
|
+
}
|
69
|
+
}
|
70
|
+
return null;
|
71
|
+
};
|
72
|
+
|
73
|
+
utils.restoreSelection = function(savedSel) {
|
74
|
+
var i, len, sel;
|
75
|
+
if (savedSel) {
|
76
|
+
if (window.getSelection) {
|
77
|
+
sel = window.getSelection();
|
78
|
+
sel.removeAllRanges();
|
79
|
+
i = 0;
|
80
|
+
len = savedSel.length;
|
81
|
+
while (i < len) {
|
82
|
+
sel.addRange(savedSel[i]);
|
83
|
+
++i;
|
84
|
+
}
|
85
|
+
} else {
|
86
|
+
if (document.selection && savedSel.select) {
|
87
|
+
savedSel.select();
|
88
|
+
}
|
89
|
+
}
|
90
|
+
}
|
91
|
+
};
|
92
|
+
|
93
|
+
utils.getNode = function() {
|
94
|
+
var container, range, sel;
|
95
|
+
range = void 0;
|
96
|
+
sel = void 0;
|
97
|
+
container = void 0;
|
98
|
+
if (document.selection && document.selection.createRange) {
|
99
|
+
range = document.selection.createRange();
|
100
|
+
return range.parentElement();
|
101
|
+
} else if (window.getSelection) {
|
102
|
+
sel = window.getSelection();
|
103
|
+
if (sel.getRangeAt) {
|
104
|
+
if (sel.rangeCount > 0) {
|
105
|
+
range = sel.getRangeAt(0);
|
106
|
+
}
|
107
|
+
} else {
|
108
|
+
range = document.createRange();
|
109
|
+
range.setStart(sel.anchorNode, sel.anchorOffset);
|
110
|
+
range.setEnd(sel.focusNode, sel.focusOffset);
|
111
|
+
if (range.collapsed !== sel.isCollapsed) {
|
112
|
+
range.setStart(sel.focusNode, sel.focusOffset);
|
113
|
+
range.setEnd(sel.anchorNode, sel.anchorOffset);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
if (range) {
|
117
|
+
container = range.commonAncestorContainer;
|
118
|
+
if (container.nodeType === 3) {
|
119
|
+
return container.parentNode;
|
120
|
+
} else {
|
121
|
+
return container;
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
};
|
126
|
+
|
127
|
+
utils.getSelectionDimensions = function() {
|
128
|
+
var height, left, range, rect, sel, top, width;
|
129
|
+
sel = document.selection;
|
130
|
+
range = void 0;
|
131
|
+
width = 0;
|
132
|
+
height = 0;
|
133
|
+
left = 0;
|
134
|
+
top = 0;
|
135
|
+
if (sel) {
|
136
|
+
if (sel.type !== "Control") {
|
137
|
+
range = sel.createRange();
|
138
|
+
width = range.boundingWidth;
|
139
|
+
height = range.boundingHeight;
|
140
|
+
}
|
141
|
+
} else if (window.getSelection) {
|
142
|
+
sel = window.getSelection();
|
143
|
+
if (sel.rangeCount) {
|
144
|
+
range = sel.getRangeAt(0).cloneRange();
|
145
|
+
if (range.getBoundingClientRect) {
|
146
|
+
rect = range.getBoundingClientRect();
|
147
|
+
width = rect.right - rect.left;
|
148
|
+
height = rect.bottom - rect.top;
|
149
|
+
}
|
150
|
+
}
|
151
|
+
}
|
152
|
+
return {
|
153
|
+
width: width,
|
154
|
+
height: height,
|
155
|
+
top: rect.top,
|
156
|
+
left: rect.left
|
157
|
+
};
|
158
|
+
};
|
159
|
+
|
160
|
+
utils.getCaretPosition = function(editableDiv) {
|
161
|
+
var caretPos, containerEl, range, sel, tempEl, tempRange;
|
162
|
+
caretPos = 0;
|
163
|
+
containerEl = null;
|
164
|
+
sel = void 0;
|
165
|
+
range = void 0;
|
166
|
+
if (window.getSelection) {
|
167
|
+
sel = window.getSelection();
|
168
|
+
if (sel.rangeCount) {
|
169
|
+
range = sel.getRangeAt(0);
|
170
|
+
if (range.commonAncestorContainer.parentNode === editableDiv) {
|
171
|
+
caretPos = range.endOffset;
|
172
|
+
}
|
173
|
+
}
|
174
|
+
} else if (document.selection && document.selection.createRange) {
|
175
|
+
range = document.selection.createRange();
|
176
|
+
if (range.parentElement() === editableDiv) {
|
177
|
+
tempEl = document.createElement("span");
|
178
|
+
editableDiv.insertBefore(tempEl, editableDiv.firstChild);
|
179
|
+
tempRange = range.duplicate();
|
180
|
+
tempRange.moveToElementText(tempEl);
|
181
|
+
tempRange.setEndPoint("EndToEnd", range);
|
182
|
+
caretPos = tempRange.text.length;
|
183
|
+
}
|
184
|
+
}
|
185
|
+
return caretPos;
|
186
|
+
};
|
187
|
+
|
188
|
+
utils.isElementInViewport = function(el) {
|
189
|
+
var rect;
|
190
|
+
if (typeof jQuery === "function" && el instanceof jQuery) {
|
191
|
+
el = el[0];
|
192
|
+
}
|
193
|
+
rect = el.getBoundingClientRect();
|
194
|
+
return rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWidth || document.documentElement.clientWidth);
|
195
|
+
};
|
196
|
+
|
197
|
+
LINE_HEIGHT = 20;
|
198
|
+
|
199
|
+
is_caret_at_start_of_node = function(node, range) {
|
200
|
+
var pre_range;
|
201
|
+
pre_range = document.createRange();
|
202
|
+
pre_range.selectNodeContents(node);
|
203
|
+
pre_range.setEnd(range.startContainer, range.startOffset);
|
204
|
+
return pre_range.toString().trim().length === 0;
|
205
|
+
};
|
206
|
+
|
207
|
+
is_caret_at_end_of_node = function(node, range) {
|
208
|
+
var post_range;
|
209
|
+
post_range = document.createRange();
|
210
|
+
post_range.selectNodeContents(node);
|
211
|
+
post_range.setStart(range.endContainer, range.endOffset);
|
212
|
+
return post_range.toString().trim().length === 0;
|
213
|
+
};
|
214
|
+
|
215
|
+
$.fn.editableIsCaret = function() {
|
216
|
+
return window.getSelection().type === 'Caret';
|
217
|
+
};
|
218
|
+
|
219
|
+
$.fn.editableRange = function() {
|
220
|
+
var sel;
|
221
|
+
sel = window.getSelection();
|
222
|
+
if (!(sel.rangeCount > 0)) {
|
223
|
+
return;
|
224
|
+
}
|
225
|
+
return sel.getRangeAt(0);
|
226
|
+
};
|
227
|
+
|
228
|
+
$.fn.editableCaretRange = function() {
|
229
|
+
if (!this.editableIsCaret()) {
|
230
|
+
return;
|
231
|
+
}
|
232
|
+
return this.editableRange();
|
233
|
+
};
|
234
|
+
|
235
|
+
$.fn.editableSetRange = function(range) {
|
236
|
+
var sel;
|
237
|
+
sel = window.getSelection();
|
238
|
+
if (sel.rangeCount > 0) {
|
239
|
+
sel.removeAllRanges();
|
240
|
+
}
|
241
|
+
return sel.addRange(range);
|
242
|
+
};
|
243
|
+
|
244
|
+
$.fn.editableFocus = function(at_start) {
|
245
|
+
var range, sel;
|
246
|
+
if (at_start == null) {
|
247
|
+
at_start = true;
|
248
|
+
}
|
249
|
+
if (!this.attr('contenteditable')) {
|
250
|
+
return;
|
251
|
+
}
|
252
|
+
sel = window.getSelection();
|
253
|
+
if (sel.rangeCount > 0) {
|
254
|
+
sel.removeAllRanges();
|
255
|
+
}
|
256
|
+
range = document.createRange();
|
257
|
+
range.selectNodeContents(this[0]);
|
258
|
+
range.collapse(at_start);
|
259
|
+
return sel.addRange(range);
|
260
|
+
};
|
261
|
+
|
262
|
+
$.fn.editableCaretAtStart = function() {
|
263
|
+
var range;
|
264
|
+
range = this.editableRange();
|
265
|
+
if (!range) {
|
266
|
+
return false;
|
267
|
+
}
|
268
|
+
return is_caret_at_start_of_node(this[0], range);
|
269
|
+
};
|
270
|
+
|
271
|
+
$.fn.editableCaretAtEnd = function() {
|
272
|
+
var range;
|
273
|
+
range = this.editableRange();
|
274
|
+
if (!range) {
|
275
|
+
return false;
|
276
|
+
}
|
277
|
+
return is_caret_at_end_of_node(this[0], range);
|
278
|
+
};
|
279
|
+
|
280
|
+
$.fn.editableCaretOnFirstLine = function() {
|
281
|
+
var ctop, etop, range;
|
282
|
+
range = this.editableRange();
|
283
|
+
if (!range) {
|
284
|
+
return false;
|
285
|
+
}
|
286
|
+
if (is_caret_at_start_of_node(this[0], range)) {
|
287
|
+
return true;
|
288
|
+
} else if (is_caret_at_end_of_node(this[0], range)) {
|
289
|
+
ctop = this[0].getBoundingClientRect().bottom - LINE_HEIGHT;
|
290
|
+
} else {
|
291
|
+
ctop = range.getClientRects()[0].top;
|
292
|
+
}
|
293
|
+
etop = this[0].getBoundingClientRect().top;
|
294
|
+
return ctop < etop + LINE_HEIGHT;
|
295
|
+
};
|
296
|
+
|
297
|
+
$.fn.editableCaretOnLastLine = function() {
|
298
|
+
var cbtm, ebtm, range;
|
299
|
+
range = this.editableRange();
|
300
|
+
if (!range) {
|
301
|
+
return false;
|
302
|
+
}
|
303
|
+
if (is_caret_at_end_of_node(this[0], range)) {
|
304
|
+
return true;
|
305
|
+
} else if (is_caret_at_start_of_node(this[0], range)) {
|
306
|
+
cbtm = this[0].getBoundingClientRect().top + LINE_HEIGHT;
|
307
|
+
} else {
|
308
|
+
cbtm = range.getClientRects()[0].bottom;
|
309
|
+
}
|
310
|
+
ebtm = this[0].getBoundingClientRect().bottom;
|
311
|
+
return cbtm > ebtm - LINE_HEIGHT;
|
312
|
+
};
|
313
|
+
|
314
|
+
$.fn.exists = function() {
|
315
|
+
return this.length > 0;
|
316
|
+
};
|
317
|
+
|
318
|
+
}).call(this);
|
319
|
+
(function() {
|
320
|
+
Dante.View = (function() {
|
321
|
+
function View(opts) {
|
322
|
+
if (opts == null) {
|
323
|
+
opts = {};
|
324
|
+
}
|
325
|
+
if (opts.el) {
|
326
|
+
this.el = opts.el;
|
327
|
+
}
|
328
|
+
this._ensureElement();
|
329
|
+
this.initialize.apply(this, arguments);
|
330
|
+
this._ensureEvents();
|
331
|
+
}
|
332
|
+
|
333
|
+
View.prototype.initialize = function(opts) {
|
334
|
+
if (opts == null) {
|
335
|
+
opts = {};
|
336
|
+
}
|
337
|
+
};
|
338
|
+
|
339
|
+
View.prototype.events = function() {};
|
340
|
+
|
341
|
+
View.prototype.render = function() {
|
342
|
+
return this;
|
343
|
+
};
|
344
|
+
|
345
|
+
View.prototype.remove = function() {
|
346
|
+
this._removeElement();
|
347
|
+
this.stopListening();
|
348
|
+
return this;
|
349
|
+
};
|
350
|
+
|
351
|
+
View.prototype._removeElement = function() {
|
352
|
+
return this.$el.remove();
|
353
|
+
};
|
354
|
+
|
355
|
+
View.prototype.setElement = function(element) {
|
356
|
+
this._setElement(element);
|
357
|
+
return this;
|
358
|
+
};
|
359
|
+
|
360
|
+
View.prototype.setEvent = function(opts) {
|
361
|
+
if (!_.isEmpty(opts)) {
|
362
|
+
return _.each(opts, (function(_this) {
|
363
|
+
return function(f, key) {
|
364
|
+
var element, func, key_arr;
|
365
|
+
key_arr = key.split(" ");
|
366
|
+
if (_.isFunction(f)) {
|
367
|
+
func = f;
|
368
|
+
} else if (_.isString(f)) {
|
369
|
+
func = _this[f];
|
370
|
+
} else {
|
371
|
+
throw "error event needs a function or string";
|
372
|
+
}
|
373
|
+
element = key_arr.length > 1 ? key_arr.splice(1, 3).join(" ") : null;
|
374
|
+
return $(_this.el).on(key_arr[0], element, _.bind(func, _this));
|
375
|
+
};
|
376
|
+
})(this));
|
377
|
+
}
|
378
|
+
};
|
379
|
+
|
380
|
+
View.prototype._ensureElement = function() {
|
381
|
+
return this.setElement(_.result(this, 'el'));
|
382
|
+
};
|
383
|
+
|
384
|
+
View.prototype._ensureEvents = function() {
|
385
|
+
return this.setEvent(_.result(this, 'events'));
|
386
|
+
};
|
387
|
+
|
388
|
+
View.prototype._setElement = function(el) {
|
389
|
+
this.$el = el instanceof $ ? el : $(el);
|
390
|
+
return this.el = this.$el[0];
|
391
|
+
};
|
392
|
+
|
393
|
+
return View;
|
394
|
+
|
395
|
+
})();
|
396
|
+
|
397
|
+
}).call(this);
|
398
|
+
(function() {
|
399
|
+
var utils,
|
400
|
+
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
401
|
+
__hasProp = {}.hasOwnProperty,
|
402
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
403
|
+
|
404
|
+
utils = Dante.utils;
|
405
|
+
|
406
|
+
Dante.Editor = (function(_super) {
|
407
|
+
__extends(Editor, _super);
|
408
|
+
|
409
|
+
function Editor() {
|
410
|
+
this.setupFirstAndLast = __bind(this.setupFirstAndLast, this);
|
411
|
+
this.addClassesToElement = __bind(this.addClassesToElement, this);
|
412
|
+
this.handlePaste = __bind(this.handlePaste, this);
|
413
|
+
this.handleArrowForKeyDown = __bind(this.handleArrowForKeyDown, this);
|
414
|
+
this.handleArrow = __bind(this.handleArrow, this);
|
415
|
+
this.handleMouseUp = __bind(this.handleMouseUp, this);
|
416
|
+
this.selection = __bind(this.selection, this);
|
417
|
+
this.render = __bind(this.render, this);
|
418
|
+
this.restart = __bind(this.restart, this);
|
419
|
+
this.start = __bind(this.start, this);
|
420
|
+
this.appendInitialContent = __bind(this.appendInitialContent, this);
|
421
|
+
this.appendMenus = __bind(this.appendMenus, this);
|
422
|
+
this.template = __bind(this.template, this);
|
423
|
+
this.initialize = __bind(this.initialize, this);
|
424
|
+
return Editor.__super__.constructor.apply(this, arguments);
|
425
|
+
}
|
426
|
+
|
427
|
+
Editor.prototype.events = {
|
428
|
+
"mouseup": "handleMouseUp",
|
429
|
+
"keydown": "handleKeyDown",
|
430
|
+
"keyup": "handleKeyUp",
|
431
|
+
"paste": "handlePaste",
|
432
|
+
"dblclick": "handleDblclick",
|
433
|
+
"dragstart": "handleDrag",
|
434
|
+
"drop": "handleDrag",
|
435
|
+
"click .graf--figure .aspectRatioPlaceholder": "handleGrafFigureSelectImg",
|
436
|
+
"click .graf--figure figcaption": "handleGrafFigureSelectCaption",
|
437
|
+
"mouseover .graf--figure.graf--iframe": "handleGrafFigureSelectIframe",
|
438
|
+
"mouseleave .graf--figure.graf--iframe": "handleGrafFigureUnSelectIframe",
|
439
|
+
"keyup .graf--figure figcaption": "handleGrafCaptionTyping",
|
440
|
+
"mouseover .markup--anchor": "displayPopOver",
|
441
|
+
"mouseout .markup--anchor": "hidePopOver"
|
442
|
+
};
|
443
|
+
|
444
|
+
Editor.prototype.initialize = function(opts) {
|
445
|
+
if (opts == null) {
|
446
|
+
opts = {};
|
447
|
+
}
|
448
|
+
this.editor_options = opts;
|
449
|
+
this.initial_html = $(this.el).html();
|
450
|
+
this.current_range = null;
|
451
|
+
this.current_node = null;
|
452
|
+
this.el = opts.el || "#editor";
|
453
|
+
this.upload_url = opts.upload_url || "/uploads.json";
|
454
|
+
this.oembed_url = opts.oembed_url || "http://api.embed.ly/1/oembed?url=";
|
455
|
+
this.extract_url = opts.extract_url || "http://api.embed.ly/1/extract?key=86c28a410a104c8bb58848733c82f840&url=";
|
456
|
+
this.default_loading_placeholder = opts.default_loading_placeholder || Dante.defaults.image_placeholder;
|
457
|
+
this.store_url = opts.store_url;
|
458
|
+
this.spell_check = opts.spellcheck || false;
|
459
|
+
this.disable_title = opts.disable_title || false;
|
460
|
+
this.store_interval = opts.store_interval || 15000;
|
461
|
+
this.paste_element_id = "#dante-paste-div";
|
462
|
+
window.debugMode = opts.debug || false;
|
463
|
+
if (window.debugMode) {
|
464
|
+
$(this.el).addClass("debug");
|
465
|
+
}
|
466
|
+
if (localStorage.getItem('contenteditable')) {
|
467
|
+
$(this.el).html(localStorage.getItem('contenteditable'));
|
468
|
+
}
|
469
|
+
this.store();
|
470
|
+
this.title_placeholder = "<span class='defaultValue defaultValue--root'>Title</span><br>";
|
471
|
+
this.body_placeholder = "<span class='defaultValue defaultValue--root'>Tell your story…</span><br>";
|
472
|
+
this.embed_placeholder = "<span class='defaultValue defaultValue--prompt'>Paste a YouTube, Vine, Vimeo, or other video link, and press Enter</span><br>";
|
473
|
+
return this.extract_placeholder = "<span class='defaultValue defaultValue--prompt'>Paste a link to embed content from another site (e.g. Twitter) and press Enter</span><br>";
|
474
|
+
};
|
475
|
+
|
476
|
+
Editor.prototype.store = function() {
|
477
|
+
if (!this.store_url) {
|
478
|
+
return;
|
479
|
+
}
|
480
|
+
return setTimeout((function(_this) {
|
481
|
+
return function() {
|
482
|
+
return _this.checkforStore();
|
483
|
+
};
|
484
|
+
})(this), this.store_interval);
|
485
|
+
};
|
486
|
+
|
487
|
+
Editor.prototype.checkforStore = function() {
|
488
|
+
if (this.content === this.getContent()) {
|
489
|
+
utils.log("content not changed skip store");
|
490
|
+
return this.store();
|
491
|
+
} else {
|
492
|
+
utils.log("content changed! update");
|
493
|
+
this.content = this.getContent();
|
494
|
+
return $.ajax({
|
495
|
+
url: this.store_url,
|
496
|
+
method: "post",
|
497
|
+
data: this.getContent(),
|
498
|
+
success: function(res) {
|
499
|
+
utils.log("store!");
|
500
|
+
return utils.log(res);
|
501
|
+
},
|
502
|
+
complete: (function(_this) {
|
503
|
+
return function(jxhr) {
|
504
|
+
return _this.store();
|
505
|
+
};
|
506
|
+
})(this)
|
507
|
+
});
|
508
|
+
}
|
509
|
+
};
|
510
|
+
|
511
|
+
Editor.prototype.getContent = function() {
|
512
|
+
return $(this.el).find(".section-inner").html();
|
513
|
+
};
|
514
|
+
|
515
|
+
Editor.prototype.renderTitle = function() {
|
516
|
+
return "<h3 class='graf graf--h3'>" + this.title_placeholder + " </h3>";
|
517
|
+
};
|
518
|
+
|
519
|
+
Editor.prototype.template = function() {
|
520
|
+
return "<section class='section--first section--last'> <div class='section-divider layoutSingleColumn'> <hr class='section-divider'> </div> <div class='section-content'> <div class='section-inner layoutSingleColumn'> " + (this.disable_title ? '' : this.renderTitle()) + " <p class='graf graf--p'>" + this.body_placeholder + "<p> </div> </div> </section>";
|
521
|
+
};
|
522
|
+
|
523
|
+
Editor.prototype.baseParagraphTmpl = function() {
|
524
|
+
return "<p class='graf--p' name='" + (utils.generateUniqueName()) + "'><br></p>";
|
525
|
+
};
|
526
|
+
|
527
|
+
Editor.prototype.appendMenus = function() {
|
528
|
+
$("<div id='dante-menu' class='dante-menu'></div>").insertAfter(this.el);
|
529
|
+
$("<div class='inlineTooltip'></div>").insertAfter(this.el);
|
530
|
+
this.editor_menu = new Dante.Editor.Menu({
|
531
|
+
editor: this
|
532
|
+
});
|
533
|
+
this.tooltip_view = new Dante.Editor.Tooltip({
|
534
|
+
editor: this
|
535
|
+
});
|
536
|
+
this.pop_over = new Dante.Editor.PopOver({
|
537
|
+
editor: this
|
538
|
+
});
|
539
|
+
this.pop_over.render().hide();
|
540
|
+
return this.tooltip_view.render().hide();
|
541
|
+
};
|
542
|
+
|
543
|
+
Editor.prototype.appendInitialContent = function() {
|
544
|
+
$(this.el).find(".section-inner").html(this.initial_html);
|
545
|
+
return $(this.el).attr("spellcheck", this.spell_check);
|
546
|
+
};
|
547
|
+
|
548
|
+
Editor.prototype.start = function() {
|
549
|
+
this.render();
|
550
|
+
$(this.el).attr("contenteditable", "true");
|
551
|
+
$(this.el).addClass("postField postField--body editable smart-media-plugin");
|
552
|
+
$(this.el).wrap("<article class='postArticle'><div class='postContent'><div class='notesSource'></div></div></article>");
|
553
|
+
this.appendMenus();
|
554
|
+
if (!_.isEmpty(this.initial_html.trim())) {
|
555
|
+
this.appendInitialContent();
|
556
|
+
}
|
557
|
+
return this.parseInitialMess();
|
558
|
+
};
|
559
|
+
|
560
|
+
Editor.prototype.restart = function() {
|
561
|
+
return this.render();
|
562
|
+
};
|
563
|
+
|
564
|
+
Editor.prototype.render = function() {
|
565
|
+
this.template();
|
566
|
+
return $(this.el).html(this.template());
|
567
|
+
};
|
568
|
+
|
569
|
+
Editor.prototype.getSelectedText = function() {
|
570
|
+
var text;
|
571
|
+
text = "";
|
572
|
+
if (typeof window.getSelection !== "undefined") {
|
573
|
+
text = window.getSelection().toString();
|
574
|
+
} else if (typeof document.selection !== "undefined" && document.selection.type === "Text") {
|
575
|
+
text = document.selection.createRange().text;
|
576
|
+
}
|
577
|
+
return text;
|
578
|
+
};
|
579
|
+
|
580
|
+
Editor.prototype.selection = function() {
|
581
|
+
selection;
|
582
|
+
var selection;
|
583
|
+
if (window.getSelection) {
|
584
|
+
return selection = window.getSelection();
|
585
|
+
} else if (document.selection && document.selection.type !== "Control") {
|
586
|
+
return selection = document.selection;
|
587
|
+
}
|
588
|
+
};
|
589
|
+
|
590
|
+
Editor.prototype.getRange = function() {
|
591
|
+
var editor, range;
|
592
|
+
editor = $(this.el)[0];
|
593
|
+
range = selection && selection.rangeCount && selection.getRangeAt(0);
|
594
|
+
if (!range) {
|
595
|
+
range = document.createRange();
|
596
|
+
}
|
597
|
+
if (!editor.contains(range.commonAncestorContainer)) {
|
598
|
+
range.selectNodeContents(editor);
|
599
|
+
range.collapse(false);
|
600
|
+
}
|
601
|
+
return range;
|
602
|
+
};
|
603
|
+
|
604
|
+
Editor.prototype.setRange = function(range) {
|
605
|
+
range = range || this.current_range;
|
606
|
+
if (!range) {
|
607
|
+
range = this.getRange();
|
608
|
+
range.collapse(false);
|
609
|
+
}
|
610
|
+
this.selection().removeAllRanges();
|
611
|
+
this.selection().addRange(range);
|
612
|
+
return this;
|
613
|
+
};
|
614
|
+
|
615
|
+
Editor.prototype.getCharacterPrecedingCaret = function() {
|
616
|
+
var precedingChar, precedingRange, range, sel;
|
617
|
+
precedingChar = "";
|
618
|
+
sel = void 0;
|
619
|
+
range = void 0;
|
620
|
+
precedingRange = void 0;
|
621
|
+
if (window.getSelection) {
|
622
|
+
sel = window.getSelection();
|
623
|
+
if (sel.rangeCount > 0) {
|
624
|
+
range = sel.getRangeAt(0).cloneRange();
|
625
|
+
range.collapse(true);
|
626
|
+
range.setStart(this.getNode(), 0);
|
627
|
+
precedingChar = range.toString().slice(0);
|
628
|
+
}
|
629
|
+
} else if ((sel = document.selection) && sel.type !== "Control") {
|
630
|
+
range = sel.createRange();
|
631
|
+
precedingRange = range.duplicate();
|
632
|
+
precedingRange.moveToElementText(containerEl);
|
633
|
+
precedingRange.setEndPoint("EndToStart", range);
|
634
|
+
precedingChar = precedingRange.text.slice(0);
|
635
|
+
}
|
636
|
+
return precedingChar;
|
637
|
+
};
|
638
|
+
|
639
|
+
Editor.prototype.isLastChar = function() {
|
640
|
+
return $(this.getNode()).text().trim().length === this.getCharacterPrecedingCaret().trim().length;
|
641
|
+
};
|
642
|
+
|
643
|
+
Editor.prototype.isFirstChar = function() {
|
644
|
+
return this.getCharacterPrecedingCaret().trim().length === 0;
|
645
|
+
};
|
646
|
+
|
647
|
+
Editor.prototype.isSelectingAll = function(element) {
|
648
|
+
var a, b;
|
649
|
+
a = this.getSelectedText().killWhiteSpace().length;
|
650
|
+
b = $(element).text().killWhiteSpace().length;
|
651
|
+
return a === b;
|
652
|
+
};
|
653
|
+
|
654
|
+
Editor.prototype.setRangeAt = function(element, int) {
|
655
|
+
var range, sel;
|
656
|
+
if (int == null) {
|
657
|
+
int = 0;
|
658
|
+
}
|
659
|
+
range = document.createRange();
|
660
|
+
sel = window.getSelection();
|
661
|
+
range.setStart(element, int);
|
662
|
+
range.collapse(true);
|
663
|
+
sel.removeAllRanges();
|
664
|
+
sel.addRange(range);
|
665
|
+
return element.focus();
|
666
|
+
};
|
667
|
+
|
668
|
+
Editor.prototype.setRangeAtText = function(element, int) {
|
669
|
+
var node, range, sel;
|
670
|
+
if (int == null) {
|
671
|
+
int = 0;
|
672
|
+
}
|
673
|
+
range = document.createRange();
|
674
|
+
sel = window.getSelection();
|
675
|
+
node = element.firstChild;
|
676
|
+
range.setStart(node, 0);
|
677
|
+
range.setEnd(node, 0);
|
678
|
+
range.collapse(true);
|
679
|
+
sel.removeAllRanges();
|
680
|
+
sel.addRange(range);
|
681
|
+
return element.focus();
|
682
|
+
};
|
683
|
+
|
684
|
+
Editor.prototype.focus = function(focusStart) {
|
685
|
+
if (!focusStart) {
|
686
|
+
this.setRange();
|
687
|
+
}
|
688
|
+
$(this.el).focus();
|
689
|
+
return this;
|
690
|
+
};
|
691
|
+
|
692
|
+
Editor.prototype.focusNode = function(node, range) {
|
693
|
+
range.setStartAfter(node);
|
694
|
+
range.setEndBefore(node);
|
695
|
+
range.collapse(false);
|
696
|
+
return this.setRange(range);
|
697
|
+
};
|
698
|
+
|
699
|
+
Editor.prototype.getNode = function() {
|
700
|
+
var node, range, root;
|
701
|
+
node = void 0;
|
702
|
+
root = $(this.el).find(".section-inner")[0];
|
703
|
+
if (this.selection().rangeCount < 1) {
|
704
|
+
return;
|
705
|
+
}
|
706
|
+
range = this.selection().getRangeAt(0);
|
707
|
+
node = range.commonAncestorContainer;
|
708
|
+
if (!node || node === root) {
|
709
|
+
return null;
|
710
|
+
}
|
711
|
+
while (node && (node.nodeType !== 1 || !$(node).hasClass("graf")) && (node.parentNode !== root)) {
|
712
|
+
node = node.parentNode;
|
713
|
+
}
|
714
|
+
if (!$(node).hasClass("graf--li")) {
|
715
|
+
while (node && (node.parentNode !== root)) {
|
716
|
+
node = node.parentNode;
|
717
|
+
}
|
718
|
+
}
|
719
|
+
if (root && root.contains(node)) {
|
720
|
+
return node;
|
721
|
+
} else {
|
722
|
+
return null;
|
723
|
+
}
|
724
|
+
};
|
725
|
+
|
726
|
+
Editor.prototype.displayMenu = function(sel) {
|
727
|
+
return setTimeout((function(_this) {
|
728
|
+
return function() {
|
729
|
+
var pos;
|
730
|
+
_this.editor_menu.render();
|
731
|
+
pos = utils.getSelectionDimensions();
|
732
|
+
_this.relocateMenu(pos);
|
733
|
+
return _this.editor_menu.show();
|
734
|
+
};
|
735
|
+
})(this), 10);
|
736
|
+
};
|
737
|
+
|
738
|
+
Editor.prototype.handleDrag = function() {
|
739
|
+
return false;
|
740
|
+
};
|
741
|
+
|
742
|
+
Editor.prototype.handleGrafCaptionTyping = function(ev) {
|
743
|
+
if (_.isEmpty(utils.getNode().textContent.trim())) {
|
744
|
+
return $(this.getNode()).addClass("is-defaultValue");
|
745
|
+
} else {
|
746
|
+
return $(this.getNode()).removeClass("is-defaultValue");
|
747
|
+
}
|
748
|
+
};
|
749
|
+
|
750
|
+
Editor.prototype.handleTextSelection = function(anchor_node) {
|
751
|
+
var text;
|
752
|
+
this.editor_menu.hide();
|
753
|
+
text = this.getSelectedText();
|
754
|
+
if (!$(anchor_node).is(".graf--mixtapeEmbed, .graf--figure") && !_.isEmpty(text.trim())) {
|
755
|
+
this.current_node = anchor_node;
|
756
|
+
return this.displayMenu();
|
757
|
+
}
|
758
|
+
};
|
759
|
+
|
760
|
+
Editor.prototype.relocateMenu = function(position) {
|
761
|
+
var height, left, padd, top;
|
762
|
+
height = this.editor_menu.$el.outerHeight();
|
763
|
+
padd = this.editor_menu.$el.width() / 2;
|
764
|
+
top = position.top + $(window).scrollTop() - height;
|
765
|
+
left = position.left + (position.width / 2) - padd;
|
766
|
+
return this.editor_menu.$el.offset({
|
767
|
+
left: left,
|
768
|
+
top: top
|
769
|
+
});
|
770
|
+
};
|
771
|
+
|
772
|
+
Editor.prototype.hidePlaceholder = function(element) {
|
773
|
+
return $(element).find("span.defaultValue").remove().html("<br>");
|
774
|
+
};
|
775
|
+
|
776
|
+
Editor.prototype.displayEmptyPlaceholder = function(element) {
|
777
|
+
$(".graf--first").html(this.title_placeholder);
|
778
|
+
return $(".graf--last").html(this.body_placeholder);
|
779
|
+
};
|
780
|
+
|
781
|
+
Editor.prototype.displayPopOver = function(ev) {
|
782
|
+
return this.pop_over.displayAt(ev);
|
783
|
+
};
|
784
|
+
|
785
|
+
Editor.prototype.hidePopOver = function(ev) {
|
786
|
+
return this.pop_over.hide(ev);
|
787
|
+
};
|
788
|
+
|
789
|
+
Editor.prototype.handleGrafFigureSelectImg = function(ev) {
|
790
|
+
var element;
|
791
|
+
utils.log("FIGURE SELECT");
|
792
|
+
element = ev.currentTarget;
|
793
|
+
this.markAsSelected(element);
|
794
|
+
$(element).parent(".graf--figure").addClass("is-selected is-mediaFocused");
|
795
|
+
return this.selection().removeAllRanges();
|
796
|
+
};
|
797
|
+
|
798
|
+
Editor.prototype.handleGrafFigureSelectIframe = function(ev) {
|
799
|
+
var element;
|
800
|
+
utils.log("FIGURE IFRAME SELECT");
|
801
|
+
element = ev.currentTarget;
|
802
|
+
this.iframeSelected = element;
|
803
|
+
this.markAsSelected(element);
|
804
|
+
$(element).addClass("is-selected is-mediaFocused");
|
805
|
+
return this.selection().removeAllRanges();
|
806
|
+
};
|
807
|
+
|
808
|
+
Editor.prototype.handleGrafFigureUnSelectIframe = function(ev) {
|
809
|
+
var element;
|
810
|
+
utils.log("FIGURE IFRAME UNSELECT");
|
811
|
+
element = ev.currentTarget;
|
812
|
+
this.iframeSelected = null;
|
813
|
+
return $(element).removeClass("is-selected is-mediaFocused");
|
814
|
+
};
|
815
|
+
|
816
|
+
Editor.prototype.handleGrafFigureSelectCaption = function(ev) {
|
817
|
+
var element;
|
818
|
+
utils.log("FIGCAPTION");
|
819
|
+
element = ev.currentTarget;
|
820
|
+
return $(element).parent(".graf--figure").removeClass("is-mediaFocused");
|
821
|
+
};
|
822
|
+
|
823
|
+
Editor.prototype.handleMouseUp = function(ev) {
|
824
|
+
var anchor_node;
|
825
|
+
utils.log("MOUSE UP");
|
826
|
+
anchor_node = this.getNode();
|
827
|
+
if (_.isNull(anchor_node)) {
|
828
|
+
return;
|
829
|
+
}
|
830
|
+
this.prev_current_node = anchor_node;
|
831
|
+
this.handleTextSelection(anchor_node);
|
832
|
+
this.hidePlaceholder(anchor_node);
|
833
|
+
this.markAsSelected(anchor_node);
|
834
|
+
return this.displayTooltipAt(anchor_node);
|
835
|
+
};
|
836
|
+
|
837
|
+
Editor.prototype.scrollTo = function(node) {
|
838
|
+
var top;
|
839
|
+
if (utils.isElementInViewport($(node))) {
|
840
|
+
return;
|
841
|
+
}
|
842
|
+
top = node.offset().top;
|
843
|
+
return $('html, body').animate({
|
844
|
+
scrollTop: top
|
845
|
+
}, 20);
|
846
|
+
};
|
847
|
+
|
848
|
+
Editor.prototype.handleArrow = function(ev) {
|
849
|
+
var current_node;
|
850
|
+
current_node = $(this.getNode());
|
851
|
+
if (current_node.length > 0) {
|
852
|
+
this.markAsSelected(current_node);
|
853
|
+
return this.displayTooltipAt(current_node);
|
854
|
+
}
|
855
|
+
};
|
856
|
+
|
857
|
+
Editor.prototype.handleArrowForKeyDown = function(ev) {
|
858
|
+
var caret_node, current_node, ev_type, n, next_node, num, prev_node;
|
859
|
+
caret_node = this.getNode();
|
860
|
+
current_node = $(caret_node);
|
861
|
+
utils.log(ev);
|
862
|
+
ev_type = ev.originalEvent.key || ev.originalEvent.keyIdentifier;
|
863
|
+
utils.log("ENTER ARROW for key " + ev_type);
|
864
|
+
switch (ev_type) {
|
865
|
+
case "Down":
|
866
|
+
if (_.isUndefined(current_node) || !current_node.exists()) {
|
867
|
+
if ($(".is-selected").exists()) {
|
868
|
+
current_node = $(".is-selected");
|
869
|
+
}
|
870
|
+
}
|
871
|
+
next_node = current_node.next();
|
872
|
+
utils.log("NEXT NODE IS " + (next_node.attr('class')));
|
873
|
+
utils.log("CURRENT NODE IS " + (current_node.attr('class')));
|
874
|
+
if (!$(current_node).hasClass("graf")) {
|
875
|
+
return;
|
876
|
+
}
|
877
|
+
if (!(current_node.hasClass("graf--figure") || $(current_node).editableCaretOnLastLine())) {
|
878
|
+
return;
|
879
|
+
}
|
880
|
+
utils.log("ENTER ARROW PASSED RETURNS");
|
881
|
+
if (next_node.hasClass("graf--figure") && caret_node) {
|
882
|
+
n = next_node.find(".imageCaption");
|
883
|
+
this.scrollTo(n);
|
884
|
+
utils.log("1 down");
|
885
|
+
utils.log(n[0]);
|
886
|
+
this.skip_keyup = true;
|
887
|
+
this.selection().removeAllRanges();
|
888
|
+
this.markAsSelected(next_node);
|
889
|
+
next_node.addClass("is-mediaFocused is-selected");
|
890
|
+
return false;
|
891
|
+
} else if (next_node.hasClass("graf--mixtapeEmbed")) {
|
892
|
+
n = current_node.next(".graf--mixtapeEmbed");
|
893
|
+
num = n[0].childNodes.length;
|
894
|
+
this.setRangeAt(n[0], num);
|
895
|
+
this.scrollTo(n);
|
896
|
+
utils.log("2 down");
|
897
|
+
return false;
|
898
|
+
}
|
899
|
+
if (current_node.hasClass("graf--figure") && next_node.hasClass("graf")) {
|
900
|
+
this.scrollTo(next_node);
|
901
|
+
utils.log("3 down, from figure to next graf");
|
902
|
+
this.markAsSelected(next_node);
|
903
|
+
this.setRangeAt(next_node[0]);
|
904
|
+
return false;
|
905
|
+
}
|
906
|
+
break;
|
907
|
+
case "Up":
|
908
|
+
prev_node = current_node.prev();
|
909
|
+
utils.log("PREV NODE IS " + (prev_node.attr('class')));
|
910
|
+
utils.log("CURRENT NODE IS up " + (current_node.attr('class')));
|
911
|
+
if (!$(current_node).hasClass("graf")) {
|
912
|
+
return;
|
913
|
+
}
|
914
|
+
if (!$(current_node).editableCaretOnFirstLine()) {
|
915
|
+
return;
|
916
|
+
}
|
917
|
+
utils.log("ENTER ARROW PASSED RETURNS");
|
918
|
+
if (prev_node.hasClass("graf--figure")) {
|
919
|
+
utils.log("1 up");
|
920
|
+
n = prev_node.find(".imageCaption");
|
921
|
+
this.scrollTo(n);
|
922
|
+
this.skip_keyup = true;
|
923
|
+
this.selection().removeAllRanges();
|
924
|
+
this.markAsSelected(prev_node);
|
925
|
+
prev_node.addClass("is-mediaFocused");
|
926
|
+
return false;
|
927
|
+
} else if (prev_node.hasClass("graf--mixtapeEmbed")) {
|
928
|
+
n = current_node.prev(".graf--mixtapeEmbed");
|
929
|
+
num = n[0].childNodes.length;
|
930
|
+
this.setRangeAt(n[0], num);
|
931
|
+
this.scrollTo(n);
|
932
|
+
utils.log("2 up");
|
933
|
+
return false;
|
934
|
+
}
|
935
|
+
if (current_node.hasClass("graf--figure") && prev_node.hasClass("graf")) {
|
936
|
+
this.setRangeAt(prev_node[0]);
|
937
|
+
this.scrollTo(prev_node);
|
938
|
+
utils.log("3 up");
|
939
|
+
return false;
|
940
|
+
} else if (prev_node.hasClass("graf")) {
|
941
|
+
n = current_node.prev(".graf");
|
942
|
+
num = n[0].childNodes.length;
|
943
|
+
this.scrollTo(n);
|
944
|
+
utils.log("4 up");
|
945
|
+
this.skip_keyup = true;
|
946
|
+
this.markAsSelected(prev_node);
|
947
|
+
return false;
|
948
|
+
}
|
949
|
+
}
|
950
|
+
};
|
951
|
+
|
952
|
+
Editor.prototype.parseInitialMess = function() {
|
953
|
+
return this.setupElementsClasses($(this.el).find('.section-inner'), (function(_this) {
|
954
|
+
return function() {
|
955
|
+
return _this.handleUnwrappedImages($(_this.el).find('.section-inner'));
|
956
|
+
};
|
957
|
+
})(this));
|
958
|
+
};
|
959
|
+
|
960
|
+
Editor.prototype.handleDblclick = function() {
|
961
|
+
var node;
|
962
|
+
utils.log("handleDblclick");
|
963
|
+
node = this.getNode();
|
964
|
+
if (_.isNull(node)) {
|
965
|
+
this.setRangeAt(this.prev_current_node);
|
966
|
+
}
|
967
|
+
return false;
|
968
|
+
};
|
969
|
+
|
970
|
+
Editor.prototype.handlePaste = function(ev) {
|
971
|
+
var cbd, pastedText;
|
972
|
+
utils.log("pasted!");
|
973
|
+
this.aa = this.getNode();
|
974
|
+
pastedText = void 0;
|
975
|
+
if (window.clipboardData && window.clipboardData.getData) {
|
976
|
+
pastedText = window.clipboardData.getData('Text');
|
977
|
+
} else if (ev.originalEvent.clipboardData && ev.originalEvent.clipboardData.getData) {
|
978
|
+
cbd = ev.originalEvent.clipboardData;
|
979
|
+
pastedText = _.isEmpty(cbd.getData('text/html')) ? cbd.getData('text/plain') : cbd.getData('text/html');
|
980
|
+
}
|
981
|
+
utils.log("Process and handle text...");
|
982
|
+
if (pastedText.match(/<\/*[a-z][^>]+?>/gi)) {
|
983
|
+
utils.log("HTML DETECTED ON PASTE");
|
984
|
+
pastedText = pastedText.replace(/&.*;/g, "");
|
985
|
+
pastedText = pastedText.replace(/<div>([\w\W]*?)<\/div>/gi, '<p>$1</p>');
|
986
|
+
document.body.appendChild($("<div id='" + (this.paste_element_id.replace('#', '')) + "'></div>")[0]);
|
987
|
+
$(this.paste_element_id).html("<span>" + pastedText + "</span>");
|
988
|
+
this.setupElementsClasses($(this.paste_element_id), (function(_this) {
|
989
|
+
return function() {
|
990
|
+
var last_node, new_node, nodes, num, top;
|
991
|
+
nodes = $($(_this.paste_element_id).html()).insertAfter($(_this.aa));
|
992
|
+
$(_this.paste_element_id).remove();
|
993
|
+
last_node = nodes.last()[0];
|
994
|
+
num = last_node.childNodes.length;
|
995
|
+
_this.setRangeAt(last_node, num);
|
996
|
+
new_node = $(_this.getNode());
|
997
|
+
top = new_node.offset().top;
|
998
|
+
_this.markAsSelected(new_node);
|
999
|
+
_this.displayTooltipAt($(_this.el).find(".is-selected"));
|
1000
|
+
_this.handleUnwrappedImages(nodes);
|
1001
|
+
return $('html, body').animate({
|
1002
|
+
scrollTop: top
|
1003
|
+
}, 200);
|
1004
|
+
};
|
1005
|
+
})(this));
|
1006
|
+
return false;
|
1007
|
+
}
|
1008
|
+
};
|
1009
|
+
|
1010
|
+
Editor.prototype.handleUnwrappedImages = function(elements) {
|
1011
|
+
return _.each(elements.find("img"), (function(_this) {
|
1012
|
+
return function(image) {
|
1013
|
+
utils.log("process image here!");
|
1014
|
+
return _this.tooltip_view.uploadExistentImage(image);
|
1015
|
+
};
|
1016
|
+
})(this));
|
1017
|
+
};
|
1018
|
+
|
1019
|
+
Editor.prototype.handleInmediateDeletion = function(element) {
|
1020
|
+
var new_node;
|
1021
|
+
this.inmediateDeletion = false;
|
1022
|
+
new_node = $(this.baseParagraphTmpl()).insertBefore($(element));
|
1023
|
+
new_node.addClass("is-selected");
|
1024
|
+
this.setRangeAt($(element).prev()[0]);
|
1025
|
+
return $(element).remove();
|
1026
|
+
};
|
1027
|
+
|
1028
|
+
Editor.prototype.handleUnwrappedNode = function(element) {
|
1029
|
+
var new_node, tmpl;
|
1030
|
+
tmpl = $(this.baseParagraphTmpl());
|
1031
|
+
this.setElementName(tmpl);
|
1032
|
+
$(element).wrap(tmpl);
|
1033
|
+
new_node = $("[name='" + (tmpl.attr('name')) + "']");
|
1034
|
+
new_node.addClass("is-selected");
|
1035
|
+
this.setRangeAt(new_node[0]);
|
1036
|
+
return false;
|
1037
|
+
};
|
1038
|
+
|
1039
|
+
|
1040
|
+
/*
|
1041
|
+
This is a rare hack only for FF (I hope),
|
1042
|
+
when there is no range it creates a new element as a placeholder,
|
1043
|
+
then finds previous element from that placeholder,
|
1044
|
+
then it focus the prev and removes the placeholder.
|
1045
|
+
a nasty nasty one...
|
1046
|
+
*/
|
1047
|
+
|
1048
|
+
Editor.prototype.handleNullAnchor = function() {
|
1049
|
+
var node, num, prev, range, sel, span;
|
1050
|
+
utils.log("WARNING! this is an empty node");
|
1051
|
+
sel = this.selection();
|
1052
|
+
if (sel.isCollapsed && sel.rangeCount > 0) {
|
1053
|
+
range = sel.getRangeAt(0);
|
1054
|
+
span = $(this.baseParagraphTmpl())[0];
|
1055
|
+
range.insertNode(span);
|
1056
|
+
range.setStart(span, 0);
|
1057
|
+
range.setEnd(span, 0);
|
1058
|
+
sel.removeAllRanges();
|
1059
|
+
sel.addRange(range);
|
1060
|
+
node = $(range.commonAncestorContainer);
|
1061
|
+
prev = node.prev();
|
1062
|
+
num = prev[0].childNodes.length;
|
1063
|
+
utils.log(prev);
|
1064
|
+
if (prev.hasClass("graf")) {
|
1065
|
+
this.setRangeAt(prev[0], num);
|
1066
|
+
node.remove();
|
1067
|
+
this.markAsSelected(this.getNode());
|
1068
|
+
} else if (prev.hasClass("graf--mixtapeEmbed")) {
|
1069
|
+
this.setRangeAt(prev[0], num);
|
1070
|
+
node.remove();
|
1071
|
+
this.markAsSelected(this.getNode());
|
1072
|
+
} else if (!prev) {
|
1073
|
+
this.setRangeAt(this.$el.find(".section-inner p")[0]);
|
1074
|
+
}
|
1075
|
+
return this.displayTooltipAt($(this.el).find(".is-selected"));
|
1076
|
+
}
|
1077
|
+
};
|
1078
|
+
|
1079
|
+
Editor.prototype.handleCompleteDeletion = function(element) {
|
1080
|
+
if (_.isEmpty($(element).text().trim())) {
|
1081
|
+
utils.log("HANDLE COMPLETE DELETION");
|
1082
|
+
this.selection().removeAllRanges();
|
1083
|
+
this.render();
|
1084
|
+
setTimeout((function(_this) {
|
1085
|
+
return function() {
|
1086
|
+
return _this.setRangeAt($(_this.el).find(".section-inner p")[0]);
|
1087
|
+
};
|
1088
|
+
})(this), 20);
|
1089
|
+
return this.completeDeletion = true;
|
1090
|
+
}
|
1091
|
+
};
|
1092
|
+
|
1093
|
+
Editor.prototype.handleTab = function(anchor_node) {
|
1094
|
+
var classes, next;
|
1095
|
+
utils.log("HANDLE TAB");
|
1096
|
+
classes = ".graf, .graf--mixtapeEmbed, .graf--figure, .graf--figure";
|
1097
|
+
next = $(anchor_node).next(classes);
|
1098
|
+
if ($(next).hasClass("graf--figure")) {
|
1099
|
+
next = $(next).find("figcaption");
|
1100
|
+
this.setRangeAt(next[0]);
|
1101
|
+
this.markAsSelected($(next).parent(".graf--figure"));
|
1102
|
+
this.displayTooltipAt(next);
|
1103
|
+
this.scrollTo($(next));
|
1104
|
+
return false;
|
1105
|
+
}
|
1106
|
+
if (_.isEmpty(next) || _.isUndefined(next[0])) {
|
1107
|
+
next = $(".graf:first");
|
1108
|
+
}
|
1109
|
+
this.setRangeAt(next[0]);
|
1110
|
+
this.markAsSelected(next);
|
1111
|
+
this.displayTooltipAt(next);
|
1112
|
+
return this.scrollTo($(next));
|
1113
|
+
};
|
1114
|
+
|
1115
|
+
Editor.prototype.handleKeyDown = function(e) {
|
1116
|
+
var $node, anchor_node, li, parent, utils_anchor_node;
|
1117
|
+
utils.log("KEYDOWN");
|
1118
|
+
anchor_node = this.getNode();
|
1119
|
+
$node = $(anchor_node);
|
1120
|
+
if (anchor_node) {
|
1121
|
+
this.markAsSelected(anchor_node);
|
1122
|
+
}
|
1123
|
+
if (e.which === 9) {
|
1124
|
+
this.handleTab(anchor_node);
|
1125
|
+
return false;
|
1126
|
+
}
|
1127
|
+
if (e.which === 13) {
|
1128
|
+
$(this.el).find(".is-selected").removeClass("is-selected");
|
1129
|
+
parent = $(anchor_node);
|
1130
|
+
utils.log(this.isLastChar());
|
1131
|
+
if ($node.hasClass("graf--p")) {
|
1132
|
+
li = this.handleSmartList($node, e);
|
1133
|
+
if (li) {
|
1134
|
+
anchor_node = li;
|
1135
|
+
}
|
1136
|
+
} else if ($node.hasClass("graf--li")) {
|
1137
|
+
this.handleListLineBreak($node, e);
|
1138
|
+
}
|
1139
|
+
if (parent.hasClass("is-embedable")) {
|
1140
|
+
this.tooltip_view.getEmbedFromNode($(anchor_node));
|
1141
|
+
} else if (parent.hasClass("is-extractable")) {
|
1142
|
+
this.tooltip_view.getExtractFromNode($(anchor_node));
|
1143
|
+
}
|
1144
|
+
if (parent.hasClass("graf--mixtapeEmbed") || parent.hasClass("graf--iframe") || parent.hasClass("graf--figure")) {
|
1145
|
+
utils.log("supress linebreak from embed !(last char)");
|
1146
|
+
if (!this.isLastChar()) {
|
1147
|
+
return false;
|
1148
|
+
}
|
1149
|
+
}
|
1150
|
+
if (parent.hasClass("graf--iframe") || parent.hasClass("graf--figure")) {
|
1151
|
+
if (this.isLastChar()) {
|
1152
|
+
this.handleLineBreakWith("p", parent);
|
1153
|
+
this.setRangeAtText($(".is-selected")[0]);
|
1154
|
+
$(".is-selected").trigger("mouseup");
|
1155
|
+
return false;
|
1156
|
+
} else {
|
1157
|
+
return false;
|
1158
|
+
}
|
1159
|
+
}
|
1160
|
+
this.tooltip_view.cleanOperationClasses($(anchor_node));
|
1161
|
+
if (anchor_node && this.editor_menu.lineBreakReg.test(anchor_node.nodeName)) {
|
1162
|
+
if (this.isLastChar()) {
|
1163
|
+
utils.log("new paragraph if it's the last character");
|
1164
|
+
e.preventDefault();
|
1165
|
+
this.handleLineBreakWith("p", parent);
|
1166
|
+
}
|
1167
|
+
}
|
1168
|
+
setTimeout((function(_this) {
|
1169
|
+
return function() {
|
1170
|
+
var node;
|
1171
|
+
node = _this.getNode();
|
1172
|
+
if (_.isUndefined(node)) {
|
1173
|
+
return;
|
1174
|
+
}
|
1175
|
+
_this.setElementName($(node));
|
1176
|
+
if (node.nodeName.toLowerCase() === "div") {
|
1177
|
+
node = _this.replaceWith("p", $(node))[0];
|
1178
|
+
}
|
1179
|
+
_this.markAsSelected($(node));
|
1180
|
+
_this.setupFirstAndLast();
|
1181
|
+
if (_.isEmpty($(node).text().trim())) {
|
1182
|
+
_.each($(node).children(), function(n) {
|
1183
|
+
return $(n).remove();
|
1184
|
+
});
|
1185
|
+
$(node).append("<br>");
|
1186
|
+
}
|
1187
|
+
return _this.displayTooltipAt($(_this.el).find(".is-selected"));
|
1188
|
+
};
|
1189
|
+
})(this), 2);
|
1190
|
+
}
|
1191
|
+
if (e.which === 8) {
|
1192
|
+
this.tooltip_view.hide();
|
1193
|
+
utils.log("removing from down");
|
1194
|
+
if (this.reachedTop) {
|
1195
|
+
utils.log("REACHED TOP");
|
1196
|
+
}
|
1197
|
+
if (this.prevented || this.reachedTop && this.isFirstChar()) {
|
1198
|
+
return false;
|
1199
|
+
}
|
1200
|
+
utils.log("pass initial validations");
|
1201
|
+
anchor_node = this.getNode();
|
1202
|
+
utils_anchor_node = utils.getNode();
|
1203
|
+
if ($node.hasClass("graf--li") && this.getCharacterPrecedingCaret().length === 0) {
|
1204
|
+
return this.handleListBackspace($node, e);
|
1205
|
+
}
|
1206
|
+
if ($(utils_anchor_node).hasClass("section-content") || $(utils_anchor_node).hasClass("graf--first")) {
|
1207
|
+
utils.log("SECTION DETECTED FROM KEYDOWN " + (_.isEmpty($(utils_anchor_node).text())));
|
1208
|
+
if (_.isEmpty($(utils_anchor_node).text())) {
|
1209
|
+
return false;
|
1210
|
+
}
|
1211
|
+
}
|
1212
|
+
if (anchor_node && anchor_node.nodeType === 3) {
|
1213
|
+
utils.log("TextNode detected from Down!");
|
1214
|
+
}
|
1215
|
+
if ($(anchor_node).hasClass("graf--mixtapeEmbed") || $(anchor_node).hasClass("graf--iframe")) {
|
1216
|
+
if (_.isEmpty($(anchor_node).text().trim() || this.isFirstChar())) {
|
1217
|
+
utils.log("Check for inmediate deletion on empty embed text");
|
1218
|
+
this.inmediateDeletion = this.isSelectingAll(anchor_node);
|
1219
|
+
if (this.inmediateDeletion) {
|
1220
|
+
this.handleInmediateDeletion($(anchor_node));
|
1221
|
+
}
|
1222
|
+
return false;
|
1223
|
+
}
|
1224
|
+
}
|
1225
|
+
if ($(anchor_node).prev().hasClass("graf--mixtapeEmbed")) {
|
1226
|
+
if (this.isFirstChar() && !_.isEmpty($(anchor_node).text().trim())) {
|
1227
|
+
return false;
|
1228
|
+
}
|
1229
|
+
}
|
1230
|
+
if ($(".is-selected").hasClass("graf--figure") && (anchor_node == null)) {
|
1231
|
+
this.replaceWith("p", $(".is-selected"));
|
1232
|
+
this.setRangeAt($(".is-selected")[0]);
|
1233
|
+
return false;
|
1234
|
+
}
|
1235
|
+
}
|
1236
|
+
if (e.which === 32) {
|
1237
|
+
utils.log("SPACEBAR");
|
1238
|
+
if ($node.hasClass("graf--p")) {
|
1239
|
+
this.handleSmartList($node, e);
|
1240
|
+
}
|
1241
|
+
}
|
1242
|
+
if (_.contains([38, 40], e.which)) {
|
1243
|
+
utils.log(e.which);
|
1244
|
+
this.handleArrowForKeyDown(e);
|
1245
|
+
}
|
1246
|
+
if (anchor_node) {
|
1247
|
+
if (!_.isEmpty($(anchor_node).text())) {
|
1248
|
+
this.tooltip_view.hide();
|
1249
|
+
$(anchor_node).removeClass("graf--empty");
|
1250
|
+
}
|
1251
|
+
}
|
1252
|
+
if (_.isUndefined(anchor_node) && $(".is-selected").hasClass("is-mediaFocused")) {
|
1253
|
+
this.setRangeAt($(".is-selected").find("figcaption")[0]);
|
1254
|
+
$(".is-selected").removeClass("is-mediaFocused");
|
1255
|
+
return false;
|
1256
|
+
}
|
1257
|
+
};
|
1258
|
+
|
1259
|
+
Editor.prototype.handleKeyUp = function(e, node) {
|
1260
|
+
var anchor_node, next_graf, utils_anchor_node;
|
1261
|
+
if (this.skip_keyup) {
|
1262
|
+
this.skip_keyup = null;
|
1263
|
+
utils.log("SKIP KEYUP");
|
1264
|
+
return false;
|
1265
|
+
}
|
1266
|
+
utils.log("KEYUP");
|
1267
|
+
this.editor_menu.hide();
|
1268
|
+
this.reachedTop = false;
|
1269
|
+
anchor_node = this.getNode();
|
1270
|
+
utils_anchor_node = utils.getNode();
|
1271
|
+
this.handleTextSelection(anchor_node);
|
1272
|
+
if (_.contains([8, 32, 13], e.which)) {
|
1273
|
+
if ($(anchor_node).hasClass("graf--li")) {
|
1274
|
+
this.removeSpanTag($(anchor_node));
|
1275
|
+
}
|
1276
|
+
}
|
1277
|
+
if (e.which === 8) {
|
1278
|
+
if ($(utils_anchor_node).hasClass("postField--body")) {
|
1279
|
+
utils.log("ALL GONE from UP");
|
1280
|
+
this.handleCompleteDeletion($(this.el));
|
1281
|
+
if (this.completeDeletion) {
|
1282
|
+
this.completeDeletion = false;
|
1283
|
+
return false;
|
1284
|
+
}
|
1285
|
+
}
|
1286
|
+
if ($(utils_anchor_node).hasClass("section-content") || $(utils_anchor_node).hasClass("graf--first")) {
|
1287
|
+
utils.log("SECTION DETECTED FROM KEYUP " + (_.isEmpty($(utils_anchor_node).text())));
|
1288
|
+
if (_.isEmpty($(utils_anchor_node).text())) {
|
1289
|
+
next_graf = $(utils_anchor_node).next(".graf")[0];
|
1290
|
+
if (next_graf) {
|
1291
|
+
this.setRangeAt(next_graf);
|
1292
|
+
$(utils_anchor_node).remove();
|
1293
|
+
this.setupFirstAndLast();
|
1294
|
+
}
|
1295
|
+
return false;
|
1296
|
+
}
|
1297
|
+
}
|
1298
|
+
if (_.isNull(anchor_node)) {
|
1299
|
+
this.handleNullAnchor();
|
1300
|
+
return false;
|
1301
|
+
}
|
1302
|
+
if ($(anchor_node).hasClass("graf--first")) {
|
1303
|
+
utils.log("THE FIRST ONE! UP");
|
1304
|
+
if (this.getSelectedText() === this.getNode().textContent) {
|
1305
|
+
utils.log("remove selection dectected");
|
1306
|
+
this.getNode().innerHTML = "<br>";
|
1307
|
+
}
|
1308
|
+
this.markAsSelected(anchor_node);
|
1309
|
+
this.setupFirstAndLast();
|
1310
|
+
false;
|
1311
|
+
}
|
1312
|
+
}
|
1313
|
+
if (_.contains([37, 38, 39, 40], e.which)) {
|
1314
|
+
return this.handleArrow(e);
|
1315
|
+
}
|
1316
|
+
};
|
1317
|
+
|
1318
|
+
Editor.prototype.handleLineBreakWith = function(element_type, from_element) {
|
1319
|
+
var new_paragraph;
|
1320
|
+
new_paragraph = $("<" + element_type + " class='graf graf--" + element_type + " graf--empty is-selected'><br/></" + element_type + ">");
|
1321
|
+
if (from_element.parent().is('[class^="graf--"]')) {
|
1322
|
+
new_paragraph.insertAfter(from_element.parent());
|
1323
|
+
} else {
|
1324
|
+
new_paragraph.insertAfter(from_element);
|
1325
|
+
}
|
1326
|
+
this.setRangeAt(new_paragraph[0]);
|
1327
|
+
return this.scrollTo(new_paragraph);
|
1328
|
+
};
|
1329
|
+
|
1330
|
+
Editor.prototype.replaceWith = function(element_type, from_element) {
|
1331
|
+
var new_paragraph;
|
1332
|
+
new_paragraph = $("<" + element_type + " class='graf graf--" + element_type + " graf--empty is-selected'><br/></" + element_type + ">");
|
1333
|
+
from_element.replaceWith(new_paragraph);
|
1334
|
+
this.setRangeAt(new_paragraph[0]);
|
1335
|
+
this.scrollTo(new_paragraph);
|
1336
|
+
return new_paragraph;
|
1337
|
+
};
|
1338
|
+
|
1339
|
+
Editor.prototype.displayTooltipAt = function(element) {
|
1340
|
+
utils.log("POSITION FOR TOOLTIP");
|
1341
|
+
element = $(element);
|
1342
|
+
if (!element || _.isEmpty(element) || element[0].tagName === "LI") {
|
1343
|
+
return;
|
1344
|
+
}
|
1345
|
+
this.tooltip_view.hide();
|
1346
|
+
if (!_.isEmpty(element.text())) {
|
1347
|
+
return;
|
1348
|
+
}
|
1349
|
+
this.positions = element.offset();
|
1350
|
+
this.tooltip_view.render();
|
1351
|
+
return this.tooltip_view.move(this.positions);
|
1352
|
+
};
|
1353
|
+
|
1354
|
+
Editor.prototype.markAsSelected = function(element) {
|
1355
|
+
if (_.isUndefined(element)) {
|
1356
|
+
return;
|
1357
|
+
}
|
1358
|
+
$(this.el).find(".is-selected").removeClass("is-mediaFocused is-selected");
|
1359
|
+
$(element).addClass("is-selected");
|
1360
|
+
$(element).find(".defaultValue").remove();
|
1361
|
+
if ($(element).hasClass("graf--first")) {
|
1362
|
+
this.reachedTop = true;
|
1363
|
+
if ($(element).find("br").length === 0) {
|
1364
|
+
return $(element).append("<br>");
|
1365
|
+
}
|
1366
|
+
}
|
1367
|
+
};
|
1368
|
+
|
1369
|
+
Editor.prototype.addClassesToElement = function(element) {
|
1370
|
+
var n, name, new_el;
|
1371
|
+
n = element;
|
1372
|
+
name = n.nodeName.toLowerCase();
|
1373
|
+
switch (name) {
|
1374
|
+
case "p":
|
1375
|
+
case "pre":
|
1376
|
+
case "div":
|
1377
|
+
if (!$(n).hasClass("graf--mixtapeEmbed")) {
|
1378
|
+
$(n).removeClass().addClass("graf graf--" + name);
|
1379
|
+
}
|
1380
|
+
if (name === "p" && $(n).find("br").length === 0) {
|
1381
|
+
$(n).append("<br>");
|
1382
|
+
}
|
1383
|
+
break;
|
1384
|
+
case "h1":
|
1385
|
+
case "h2":
|
1386
|
+
case "h3":
|
1387
|
+
case "h4":
|
1388
|
+
case "h5":
|
1389
|
+
case "h6":
|
1390
|
+
if (name === "h1") {
|
1391
|
+
new_el = $("<h2 class='graf graf--h2'>" + ($(n).text()) + "</h2>");
|
1392
|
+
$(n).replaceWith(new_el);
|
1393
|
+
this.setElementName(n);
|
1394
|
+
} else {
|
1395
|
+
$(n).removeClass().addClass("graf graf--" + name);
|
1396
|
+
}
|
1397
|
+
break;
|
1398
|
+
case "code":
|
1399
|
+
$(n).unwrap().wrap("<p class='graf graf--pre'></p>");
|
1400
|
+
n = $(n).parent();
|
1401
|
+
break;
|
1402
|
+
case "ol":
|
1403
|
+
case "ul":
|
1404
|
+
utils.log("lists");
|
1405
|
+
$(n).removeClass().addClass("postList");
|
1406
|
+
_.each($(n).find("li"), function(li) {
|
1407
|
+
return $(li).removeClass().addClass("graf graf--li");
|
1408
|
+
});
|
1409
|
+
break;
|
1410
|
+
case "img":
|
1411
|
+
utils.log("images");
|
1412
|
+
this.tooltip_view.uploadExistentImage(n);
|
1413
|
+
break;
|
1414
|
+
case "a":
|
1415
|
+
case 'strong':
|
1416
|
+
case 'em':
|
1417
|
+
case 'br':
|
1418
|
+
case 'b':
|
1419
|
+
case 'u':
|
1420
|
+
case 'i':
|
1421
|
+
utils.log("links");
|
1422
|
+
$(n).wrap("<p class='graf graf--p'></p>");
|
1423
|
+
n = $(n).parent();
|
1424
|
+
break;
|
1425
|
+
case "blockquote":
|
1426
|
+
n = $(n).removeClass().addClass("graf graf--" + name);
|
1427
|
+
break;
|
1428
|
+
case "figure":
|
1429
|
+
if ($(n).hasClass(".graf--figure")) {
|
1430
|
+
n = $(n);
|
1431
|
+
}
|
1432
|
+
break;
|
1433
|
+
default:
|
1434
|
+
$(n).wrap("<p class='graf graf--" + name + "'></p>");
|
1435
|
+
n = $(n).parent();
|
1436
|
+
}
|
1437
|
+
return n;
|
1438
|
+
};
|
1439
|
+
|
1440
|
+
Editor.prototype.setupElementsClasses = function(element, cb) {
|
1441
|
+
if (_.isUndefined(element)) {
|
1442
|
+
this.element = $(this.el).find('.section-inner');
|
1443
|
+
} else {
|
1444
|
+
this.element = element;
|
1445
|
+
}
|
1446
|
+
return setTimeout((function(_this) {
|
1447
|
+
return function() {
|
1448
|
+
_this.cleanContents(_this.element);
|
1449
|
+
_this.wrapTextNodes(_this.element);
|
1450
|
+
_.each(_this.element.children(), function(n) {
|
1451
|
+
var name;
|
1452
|
+
name = $(n).prop("tagName").toLowerCase();
|
1453
|
+
n = _this.addClassesToElement(n);
|
1454
|
+
return _this.setElementName(n);
|
1455
|
+
});
|
1456
|
+
_this.setupLinks(_this.element.find("a"));
|
1457
|
+
_this.setupFirstAndLast();
|
1458
|
+
if (_.isFunction(cb)) {
|
1459
|
+
return cb();
|
1460
|
+
}
|
1461
|
+
};
|
1462
|
+
})(this), 20);
|
1463
|
+
};
|
1464
|
+
|
1465
|
+
Editor.prototype.cleanContents = function(element) {
|
1466
|
+
var s;
|
1467
|
+
if (_.isUndefined(element)) {
|
1468
|
+
this.element = $(this.el).find('.section-inner');
|
1469
|
+
} else {
|
1470
|
+
this.element = element;
|
1471
|
+
}
|
1472
|
+
s = new Sanitize({
|
1473
|
+
elements: ['strong', 'img', 'em', 'br', 'a', 'blockquote', 'b', 'u', 'i', 'pre', 'p', 'h1', 'h2', 'h3', 'h4', 'ul', 'ol', 'li'],
|
1474
|
+
attributes: {
|
1475
|
+
'__ALL__': ['class'],
|
1476
|
+
a: ['href', 'title', 'target'],
|
1477
|
+
img: ['src']
|
1478
|
+
},
|
1479
|
+
protocols: {
|
1480
|
+
a: {
|
1481
|
+
href: ['http', 'https', 'mailto']
|
1482
|
+
}
|
1483
|
+
},
|
1484
|
+
transformers: [
|
1485
|
+
function(input) {
|
1486
|
+
if (input.node_name === "span" && $(input.node).hasClass("defaultValue")) {
|
1487
|
+
return {
|
1488
|
+
whitelist_nodes: [input.node]
|
1489
|
+
};
|
1490
|
+
} else {
|
1491
|
+
return null;
|
1492
|
+
}
|
1493
|
+
}, function(input) {
|
1494
|
+
if (input.node_name === 'div' && $(input.node).hasClass("graf--mixtapeEmbed")) {
|
1495
|
+
return {
|
1496
|
+
whitelist_nodes: [input.node]
|
1497
|
+
};
|
1498
|
+
} else if (input.node_name === 'a' && $(input.node).parent(".graf--mixtapeEmbed").exists()) {
|
1499
|
+
return {
|
1500
|
+
attr_whitelist: ["style"]
|
1501
|
+
};
|
1502
|
+
} else {
|
1503
|
+
return null;
|
1504
|
+
}
|
1505
|
+
}, function(input) {
|
1506
|
+
if (input.node_name === 'figure' && $(input.node).hasClass("graf--iframe")) {
|
1507
|
+
return {
|
1508
|
+
whitelist_nodes: [input.node]
|
1509
|
+
};
|
1510
|
+
} else if (input.node_name === 'div' && $(input.node).hasClass("iframeContainer") && $(input.node).parent(".graf--iframe").exists()) {
|
1511
|
+
return {
|
1512
|
+
whitelist_nodes: [input.node]
|
1513
|
+
};
|
1514
|
+
} else if (input.node_name === 'iframe' && $(input.node).parent(".iframeContainer").exists()) {
|
1515
|
+
return {
|
1516
|
+
whitelist_nodes: [input.node]
|
1517
|
+
};
|
1518
|
+
} else if (input.node_name === 'figcaption' && $(input.node).parent(".graf--iframe").exists()) {
|
1519
|
+
return {
|
1520
|
+
whitelist_nodes: [input.node]
|
1521
|
+
};
|
1522
|
+
} else {
|
1523
|
+
return null;
|
1524
|
+
}
|
1525
|
+
}, function(input) {
|
1526
|
+
if (input.node_name === 'figure' && $(input.node).hasClass("graf--figure")) {
|
1527
|
+
return {
|
1528
|
+
whitelist_nodes: [input.node]
|
1529
|
+
};
|
1530
|
+
} else if (input.node_name === 'div' && ($(input.node).hasClass("aspectRatioPlaceholder") && $(input.node).parent(".graf--figure").exists())) {
|
1531
|
+
return {
|
1532
|
+
whitelist_nodes: [input.node]
|
1533
|
+
};
|
1534
|
+
} else if (input.node_name === 'div' && ($(input.node).hasClass("aspect-ratio-fill") && $(input.node).parent(".aspectRatioPlaceholder").exists())) {
|
1535
|
+
return {
|
1536
|
+
whitelist_nodes: [input.node]
|
1537
|
+
};
|
1538
|
+
} else if (input.node_name === 'img' && $(input.node).parent(".graf--figure").exists()) {
|
1539
|
+
return {
|
1540
|
+
whitelist_nodes: [input.node]
|
1541
|
+
};
|
1542
|
+
} else if (input.node_name === 'a' && $(input.node).parent(".graf--mixtapeEmbed").exists()) {
|
1543
|
+
return {
|
1544
|
+
attr_whitelist: ["style"]
|
1545
|
+
};
|
1546
|
+
} else if (input.node_name === 'figcaption' && $(input.node).parent(".graf--figure").exists()) {
|
1547
|
+
return {
|
1548
|
+
whitelist_nodes: [input.node]
|
1549
|
+
};
|
1550
|
+
} else if (input.node_name === 'span' && $(input.node).parent(".imageCaption").exists()) {
|
1551
|
+
return {
|
1552
|
+
whitelist_nodes: [input.node]
|
1553
|
+
};
|
1554
|
+
} else {
|
1555
|
+
return null;
|
1556
|
+
}
|
1557
|
+
}
|
1558
|
+
]
|
1559
|
+
});
|
1560
|
+
if (this.element.exists()) {
|
1561
|
+
utils.log("CLEAN HTML " + this.element[0].tagName);
|
1562
|
+
return this.element.html(s.clean_node(this.element[0]));
|
1563
|
+
}
|
1564
|
+
};
|
1565
|
+
|
1566
|
+
Editor.prototype.setupLinks = function(elems) {
|
1567
|
+
return _.each(elems, (function(_this) {
|
1568
|
+
return function(n) {
|
1569
|
+
return _this.setupLink(n);
|
1570
|
+
};
|
1571
|
+
})(this));
|
1572
|
+
};
|
1573
|
+
|
1574
|
+
Editor.prototype.setupLink = function(n) {
|
1575
|
+
var href, parent_name;
|
1576
|
+
parent_name = $(n).parent().prop("tagName").toLowerCase();
|
1577
|
+
$(n).addClass("markup--anchor markup--" + parent_name + "-anchor");
|
1578
|
+
href = $(n).attr("href");
|
1579
|
+
return $(n).attr("data-href", href);
|
1580
|
+
};
|
1581
|
+
|
1582
|
+
Editor.prototype.preCleanNode = function(element) {
|
1583
|
+
var s;
|
1584
|
+
s = new Sanitize({
|
1585
|
+
elements: ['strong', 'em', 'br', 'a', 'b', 'u', 'i', 'ul', 'ol', 'li'],
|
1586
|
+
attributes: {
|
1587
|
+
a: ['href', 'title', 'target']
|
1588
|
+
},
|
1589
|
+
protocols: {
|
1590
|
+
a: {
|
1591
|
+
href: ['http', 'https', 'mailto']
|
1592
|
+
}
|
1593
|
+
}
|
1594
|
+
});
|
1595
|
+
$(element).html(s.clean_node(element[0]));
|
1596
|
+
element = this.addClassesToElement($(element)[0]);
|
1597
|
+
return $(element);
|
1598
|
+
};
|
1599
|
+
|
1600
|
+
Editor.prototype.setupFirstAndLast = function() {
|
1601
|
+
var childs;
|
1602
|
+
childs = $(this.el).find(".section-inner").children();
|
1603
|
+
childs.removeClass("graf--last , graf--first");
|
1604
|
+
childs.first().addClass("graf--first");
|
1605
|
+
return childs.last().addClass("graf--last");
|
1606
|
+
};
|
1607
|
+
|
1608
|
+
Editor.prototype.wrapTextNodes = function(element) {
|
1609
|
+
if (_.isUndefined(element)) {
|
1610
|
+
element = $(this.el).find('.section-inner');
|
1611
|
+
} else {
|
1612
|
+
element = element;
|
1613
|
+
}
|
1614
|
+
return element.contents().filter(function() {
|
1615
|
+
return this.nodeType === 3 && this.data.trim().length > 0;
|
1616
|
+
}).wrap("<p class='graf grap--p'></p>");
|
1617
|
+
};
|
1618
|
+
|
1619
|
+
Editor.prototype.setElementName = function(element) {
|
1620
|
+
return $(element).attr("name", utils.generateUniqueName());
|
1621
|
+
};
|
1622
|
+
|
1623
|
+
Editor.prototype.listify = function($paragraph, listType, regex) {
|
1624
|
+
var $li, $list, content;
|
1625
|
+
utils.log("LISTIFY PARAGRAPH");
|
1626
|
+
this.removeSpanTag($paragraph);
|
1627
|
+
content = $paragraph.html().replace(/ /g, " ").replace(regex, "");
|
1628
|
+
switch (listType) {
|
1629
|
+
case "ul":
|
1630
|
+
$list = $("<ul></ul>");
|
1631
|
+
break;
|
1632
|
+
case "ol":
|
1633
|
+
$list = $("<ol></ol>");
|
1634
|
+
break;
|
1635
|
+
default:
|
1636
|
+
return false;
|
1637
|
+
}
|
1638
|
+
this.addClassesToElement($list[0]);
|
1639
|
+
this.replaceWith("li", $paragraph);
|
1640
|
+
$li = $(".is-selected");
|
1641
|
+
this.setElementName($li[0]);
|
1642
|
+
$li.html(content).wrap($list);
|
1643
|
+
if ($li.find("br").length === 0) {
|
1644
|
+
$li.append("<br/>");
|
1645
|
+
}
|
1646
|
+
this.setRangeAt($li[0]);
|
1647
|
+
return $li[0];
|
1648
|
+
};
|
1649
|
+
|
1650
|
+
Editor.prototype.handleSmartList = function($item, e) {
|
1651
|
+
var $li, chars, match, regex;
|
1652
|
+
utils.log("HANDLE A SMART LIST");
|
1653
|
+
chars = this.getCharacterPrecedingCaret();
|
1654
|
+
match = chars.match(/^\s*(\-|\*)\s*$/);
|
1655
|
+
if (match) {
|
1656
|
+
utils.log("CREATING LIST ITEM");
|
1657
|
+
e.preventDefault();
|
1658
|
+
regex = new RegExp(/\s*(\-|\*)\s*/);
|
1659
|
+
$li = this.listify($item, "ul", regex);
|
1660
|
+
} else {
|
1661
|
+
match = chars.match(/^\s*1(\.|\))\s*$/);
|
1662
|
+
if (match) {
|
1663
|
+
utils.log("CREATING LIST ITEM");
|
1664
|
+
e.preventDefault();
|
1665
|
+
regex = new RegExp(/\s*1(\.|\))\s*/);
|
1666
|
+
$li = this.listify($item, "ol", regex);
|
1667
|
+
}
|
1668
|
+
}
|
1669
|
+
return $li;
|
1670
|
+
};
|
1671
|
+
|
1672
|
+
Editor.prototype.handleListLineBreak = function($li, e) {
|
1673
|
+
var $list, $paragraph, content;
|
1674
|
+
utils.log("LIST LINE BREAK");
|
1675
|
+
this.tooltip_view.hide();
|
1676
|
+
$list = $li.parent("ol, ul");
|
1677
|
+
$paragraph = $("<p></p>");
|
1678
|
+
utils.log($li.prev());
|
1679
|
+
if ($list.children().length === 1 && $li.text() === "") {
|
1680
|
+
this.replaceWith("p", $list);
|
1681
|
+
} else if ($li.text() === "" && ($li.next().length !== 0)) {
|
1682
|
+
e.preventDefault();
|
1683
|
+
} else if ($li.next().length === 0) {
|
1684
|
+
if ($li.text() === "") {
|
1685
|
+
e.preventDefault();
|
1686
|
+
utils.log("BREAK FROM LIST");
|
1687
|
+
$list.after($paragraph);
|
1688
|
+
$li.addClass("graf--removed").remove();
|
1689
|
+
} else if ($li.prev().length !== 0 && $li.prev().text() === "" && this.getCharacterPrecedingCaret() === "") {
|
1690
|
+
e.preventDefault();
|
1691
|
+
utils.log("PREV IS EMPTY");
|
1692
|
+
content = $li.html();
|
1693
|
+
$list.after($paragraph);
|
1694
|
+
$li.prev().remove();
|
1695
|
+
$li.addClass("graf--removed").remove();
|
1696
|
+
$paragraph.html(content);
|
1697
|
+
}
|
1698
|
+
}
|
1699
|
+
if ($list && $list.children().length === 0) {
|
1700
|
+
$list.remove();
|
1701
|
+
}
|
1702
|
+
utils.log($li);
|
1703
|
+
if ($li.hasClass("graf--removed")) {
|
1704
|
+
utils.log("ELEMENT REMOVED");
|
1705
|
+
this.addClassesToElement($paragraph[0]);
|
1706
|
+
this.setRangeAt($paragraph[0]);
|
1707
|
+
this.markAsSelected($paragraph[0]);
|
1708
|
+
return this.scrollTo($paragraph);
|
1709
|
+
}
|
1710
|
+
};
|
1711
|
+
|
1712
|
+
Editor.prototype.handleListBackspace = function($li, e) {
|
1713
|
+
var $list, $paragraph, content;
|
1714
|
+
$list = $li.parent("ol, ul");
|
1715
|
+
utils.log("LIST BACKSPACE");
|
1716
|
+
if ($li.prev().length === 0) {
|
1717
|
+
e.preventDefault();
|
1718
|
+
$list.before($li);
|
1719
|
+
content = $li.html();
|
1720
|
+
this.replaceWith("p", $li);
|
1721
|
+
$paragraph = $(".is-selected");
|
1722
|
+
$paragraph.removeClass("graf--empty").html(content);
|
1723
|
+
if ($list.children().length === 0) {
|
1724
|
+
$list.remove();
|
1725
|
+
}
|
1726
|
+
return this.setupFirstAndLast();
|
1727
|
+
}
|
1728
|
+
};
|
1729
|
+
|
1730
|
+
Editor.prototype.removeSpanTag = function($item) {
|
1731
|
+
var $spans, span, _i, _len;
|
1732
|
+
$spans = $item.find("span");
|
1733
|
+
for (_i = 0, _len = $spans.length; _i < _len; _i++) {
|
1734
|
+
span = $spans[_i];
|
1735
|
+
if (!$(span).hasClass("defaultValue")) {
|
1736
|
+
$(span).replaceWith($(span).html());
|
1737
|
+
}
|
1738
|
+
}
|
1739
|
+
return $item;
|
1740
|
+
};
|
1741
|
+
|
1742
|
+
return Editor;
|
1743
|
+
|
1744
|
+
})(Dante.View);
|
1745
|
+
|
1746
|
+
}).call(this);
|
1747
|
+
(function() {
|
1748
|
+
var utils,
|
1749
|
+
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
1750
|
+
__hasProp = {}.hasOwnProperty,
|
1751
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
1752
|
+
|
1753
|
+
utils = Dante.utils;
|
1754
|
+
|
1755
|
+
Dante.Editor.Tooltip = (function(_super) {
|
1756
|
+
__extends(Tooltip, _super);
|
1757
|
+
|
1758
|
+
function Tooltip() {
|
1759
|
+
this.hide = __bind(this.hide, this);
|
1760
|
+
this.getExtract = __bind(this.getExtract, this);
|
1761
|
+
this.getExtractFromNode = __bind(this.getExtractFromNode, this);
|
1762
|
+
this.getEmbedFromNode = __bind(this.getEmbedFromNode, this);
|
1763
|
+
this.uploadCompleted = __bind(this.uploadCompleted, this);
|
1764
|
+
this.updateProgressBar = __bind(this.updateProgressBar, this);
|
1765
|
+
this.uploadFile = __bind(this.uploadFile, this);
|
1766
|
+
this.uploadFiles = __bind(this.uploadFiles, this);
|
1767
|
+
this.toggleOptions = __bind(this.toggleOptions, this);
|
1768
|
+
this.render = __bind(this.render, this);
|
1769
|
+
this.initialize = __bind(this.initialize, this);
|
1770
|
+
return Tooltip.__super__.constructor.apply(this, arguments);
|
1771
|
+
}
|
1772
|
+
|
1773
|
+
Tooltip.prototype.el = ".inlineTooltip";
|
1774
|
+
|
1775
|
+
Tooltip.prototype.events = {
|
1776
|
+
"click .inlineTooltip-button.control": "toggleOptions",
|
1777
|
+
"click .inlineTooltip-menu button": "handleClick"
|
1778
|
+
};
|
1779
|
+
|
1780
|
+
Tooltip.prototype.initialize = function(opts) {
|
1781
|
+
if (opts == null) {
|
1782
|
+
opts = {};
|
1783
|
+
}
|
1784
|
+
this.current_editor = opts.editor;
|
1785
|
+
return this.buttons = [
|
1786
|
+
{
|
1787
|
+
icon: "icon-image",
|
1788
|
+
title: "Add an image",
|
1789
|
+
action: "image"
|
1790
|
+
}, {
|
1791
|
+
icon: "icon-video",
|
1792
|
+
title: "Add a video",
|
1793
|
+
action: "embed"
|
1794
|
+
}, {
|
1795
|
+
icon: "icon-embed",
|
1796
|
+
title: "Add an embed",
|
1797
|
+
action: "embed-extract"
|
1798
|
+
}
|
1799
|
+
];
|
1800
|
+
};
|
1801
|
+
|
1802
|
+
Tooltip.prototype.template = function() {
|
1803
|
+
var menu;
|
1804
|
+
menu = "";
|
1805
|
+
_.each(this.buttons, function(b) {
|
1806
|
+
var data_action_value;
|
1807
|
+
data_action_value = b.action_value ? "data-action-value='" + b.action_value + "'" : "";
|
1808
|
+
return menu += "<button class='inlineTooltip-button scale' title='" + b.title + "' data-action='inline-menu-" + b.action + "' " + data_action_value + "> <span class='tooltip-icon " + b.icon + "'></span> </button>";
|
1809
|
+
});
|
1810
|
+
return "<button class='inlineTooltip-button control' title='Close Menu' data-action='inline-menu'> <span class='tooltip-icon icon-plus'></span> </button> <div class='inlineTooltip-menu'> " + menu + " </div>";
|
1811
|
+
};
|
1812
|
+
|
1813
|
+
Tooltip.prototype.insertTemplate = function() {
|
1814
|
+
return "<figure contenteditable='false' class='graf graf--figure is-defaultValue' name='" + (utils.generateUniqueName()) + "' tabindex='0'> <div style='' class='aspectRatioPlaceholder is-locked'> <div style='padding-bottom: 100%;' class='aspect-ratio-fill'></div> <img src='' data-height='' data-width='' data-image-id='' class='graf-image' data-delayed-src=''> </div> <figcaption contenteditable='true' data-default-value='Type caption for image (optional)' class='imageCaption'> <span class='defaultValue'>Type caption for image (optional)</span> <br> </figcaption> </figure>";
|
1815
|
+
};
|
1816
|
+
|
1817
|
+
Tooltip.prototype.extractTemplate = function() {
|
1818
|
+
return "<div class='graf graf--mixtapeEmbed is-selected' name=''> <a target='_blank' data-media-id='' class='js-mixtapeImage mixtapeImage mixtapeImage--empty u-ignoreBlock' href=''> </a> <a data-tooltip-type='link' data-tooltip-position='bottom' data-tooltip='' title='' class='markup--anchor markup--mixtapeEmbed-anchor' data-href='' href='' target='_blank'> <strong class='markup--strong markup--mixtapeEmbed-strong'></strong> <em class='markup--em markup--mixtapeEmbed-em'></em> </a> </div>";
|
1819
|
+
};
|
1820
|
+
|
1821
|
+
Tooltip.prototype.embedTemplate = function() {
|
1822
|
+
return "<figure contenteditable='false' class='graf--figure graf--iframe graf--first' name='504e' tabindex='0'> <div class='iframeContainer'> <iframe frameborder='0' width='700' height='393' data-media-id='' src='' data-height='480' data-width='854'> </iframe> </div> <figcaption contenteditable='true' data-default-value='Type caption for embed (optional)' class='imageCaption'> <a rel='nofollow' class='markup--anchor markup--figure-anchor' data-href='' href='' target='_blank'> </a> </figcaption> </figure>";
|
1823
|
+
};
|
1824
|
+
|
1825
|
+
Tooltip.prototype.render = function() {
|
1826
|
+
$(this.el).html(this.template());
|
1827
|
+
$(this.el).addClass("is-active");
|
1828
|
+
return this;
|
1829
|
+
};
|
1830
|
+
|
1831
|
+
Tooltip.prototype.toggleOptions = function() {
|
1832
|
+
utils.log("Toggle Options!!");
|
1833
|
+
$(this.el).toggleClass("is-scaled");
|
1834
|
+
return false;
|
1835
|
+
};
|
1836
|
+
|
1837
|
+
Tooltip.prototype.move = function(coords) {
|
1838
|
+
var control_spacing, control_width, coord_left, coord_top, pull_size, tooltip;
|
1839
|
+
tooltip = $(this.el);
|
1840
|
+
control_width = tooltip.find(".control").css("width");
|
1841
|
+
control_spacing = tooltip.find(".inlineTooltip-menu").css("padding-left");
|
1842
|
+
pull_size = parseInt(control_width.replace(/px/, "")) + parseInt(control_spacing.replace(/px/, ""));
|
1843
|
+
coord_left = coords.left - pull_size;
|
1844
|
+
coord_top = coords.top;
|
1845
|
+
return $(this.el).offset({
|
1846
|
+
top: coord_top,
|
1847
|
+
left: coord_left
|
1848
|
+
});
|
1849
|
+
};
|
1850
|
+
|
1851
|
+
Tooltip.prototype.handleClick = function(ev) {
|
1852
|
+
var name;
|
1853
|
+
name = $(ev.currentTarget).data('action');
|
1854
|
+
utils.log(name);
|
1855
|
+
switch (name) {
|
1856
|
+
case "inline-menu-image":
|
1857
|
+
this.placeholder = "<p>PLACEHOLDER</p>";
|
1858
|
+
this.imageSelect(ev);
|
1859
|
+
break;
|
1860
|
+
case "inline-menu-embed":
|
1861
|
+
this.displayEmbedPlaceHolder();
|
1862
|
+
break;
|
1863
|
+
case "inline-menu-embed-extract":
|
1864
|
+
this.displayExtractPlaceHolder();
|
1865
|
+
break;
|
1866
|
+
case "inline-menu-hr":
|
1867
|
+
this.splitSection();
|
1868
|
+
}
|
1869
|
+
return false;
|
1870
|
+
};
|
1871
|
+
|
1872
|
+
Tooltip.prototype.uploadExistentImage = function(image_element, opts) {
|
1873
|
+
var i, img, n, node, tmpl, _i, _ref;
|
1874
|
+
if (opts == null) {
|
1875
|
+
opts = {};
|
1876
|
+
}
|
1877
|
+
utils.log("process image here!");
|
1878
|
+
tmpl = $(this.insertTemplate());
|
1879
|
+
tmpl.find("img").attr('src', this.current_editor.default_loading_placeholder);
|
1880
|
+
if ($(image_element).parents(".graf").length > 0) {
|
1881
|
+
if ($(image_element).parents(".graf").hasClass("graf--figure")) {
|
1882
|
+
return;
|
1883
|
+
}
|
1884
|
+
utils.log("UNO");
|
1885
|
+
tmpl.insertBefore($(image_element).parents(".graf"));
|
1886
|
+
node = this.current_editor.getNode();
|
1887
|
+
if (node) {
|
1888
|
+
this.current_editor.preCleanNode($(node));
|
1889
|
+
this.current_editor.addClassesToElement(node);
|
1890
|
+
}
|
1891
|
+
} else {
|
1892
|
+
utils.log("DOS");
|
1893
|
+
img = $(image_element).parentsUntil(".section-inner").first();
|
1894
|
+
$(img).replaceWith(tmpl);
|
1895
|
+
}
|
1896
|
+
utils.log($("[name='" + (tmpl.attr('name')) + "']").attr("name"));
|
1897
|
+
this.replaceImg(image_element, $("[name='" + (tmpl.attr('name')) + "']"));
|
1898
|
+
n = $("[name='" + (tmpl.attr('name')) + "']").parentsUntil(".section-inner").length;
|
1899
|
+
if (n !== 0) {
|
1900
|
+
for (i = _i = 0, _ref = n - 1; _i <= _ref; i = _i += 1) {
|
1901
|
+
$("[name='" + (tmpl.attr('name')) + "']").unwrap();
|
1902
|
+
}
|
1903
|
+
}
|
1904
|
+
return utils.log("FIG");
|
1905
|
+
};
|
1906
|
+
|
1907
|
+
Tooltip.prototype.replaceImg = function(image_element, figure) {
|
1908
|
+
var img, self;
|
1909
|
+
utils.log(figure.attr("name"));
|
1910
|
+
utils.log(figure);
|
1911
|
+
$(image_element).remove();
|
1912
|
+
img = new Image();
|
1913
|
+
img.src = image_element.src;
|
1914
|
+
self = this;
|
1915
|
+
return img.onload = function() {
|
1916
|
+
var ar;
|
1917
|
+
utils.log("replace image with loaded info");
|
1918
|
+
utils.log(figure.attr("name"));
|
1919
|
+
utils.log(this.width + 'x' + this.height);
|
1920
|
+
ar = self.getAspectRatio(this.width, this.height);
|
1921
|
+
figure.find(".aspectRatioPlaceholder").css({
|
1922
|
+
'max-width': ar.width,
|
1923
|
+
'max-height': ar.height
|
1924
|
+
});
|
1925
|
+
figure.find(".graf-image").attr({
|
1926
|
+
"data-height": this.height,
|
1927
|
+
"data-width": this.width
|
1928
|
+
});
|
1929
|
+
figure.find(".aspect-ratio-fill").css({
|
1930
|
+
"padding-bottom": "" + ar.ratio + "%"
|
1931
|
+
});
|
1932
|
+
return figure.find("img").attr("src", image_element.src);
|
1933
|
+
};
|
1934
|
+
};
|
1935
|
+
|
1936
|
+
Tooltip.prototype.displayAndUploadImages = function(file) {
|
1937
|
+
return this.displayCachedImage(file);
|
1938
|
+
};
|
1939
|
+
|
1940
|
+
Tooltip.prototype.imageSelect = function(ev) {
|
1941
|
+
var $selectFile, self;
|
1942
|
+
$selectFile = $('<input type="file" multiple="multiple">').click();
|
1943
|
+
self = this;
|
1944
|
+
return $selectFile.change(function() {
|
1945
|
+
var t;
|
1946
|
+
t = this;
|
1947
|
+
return self.uploadFiles(t.files);
|
1948
|
+
});
|
1949
|
+
};
|
1950
|
+
|
1951
|
+
Tooltip.prototype.displayCachedImage = function(file) {
|
1952
|
+
var reader;
|
1953
|
+
this.current_editor.tooltip_view.hide();
|
1954
|
+
reader = new FileReader();
|
1955
|
+
reader.onload = (function(_this) {
|
1956
|
+
return function(e) {
|
1957
|
+
var img, node, self;
|
1958
|
+
img = new Image;
|
1959
|
+
img.src = e.target.result;
|
1960
|
+
node = _this.current_editor.getNode();
|
1961
|
+
self = _this;
|
1962
|
+
return img.onload = function() {
|
1963
|
+
var ar, img_tag, new_tmpl, replaced_node;
|
1964
|
+
new_tmpl = $(self.insertTemplate());
|
1965
|
+
replaced_node = $(new_tmpl).insertBefore($(node));
|
1966
|
+
img_tag = new_tmpl.find('img.graf-image').attr('src', e.target.result);
|
1967
|
+
img_tag.height = this.height;
|
1968
|
+
img_tag.width = this.width;
|
1969
|
+
utils.log("UPLOADED SHOW FROM CACHE");
|
1970
|
+
ar = self.getAspectRatio(this.width, this.height);
|
1971
|
+
replaced_node.find(".aspectRatioPlaceholder").css({
|
1972
|
+
'max-width': ar.width,
|
1973
|
+
'max-height': ar.height
|
1974
|
+
});
|
1975
|
+
replaced_node.find(".graf-image").attr({
|
1976
|
+
"data-height": this.height,
|
1977
|
+
"data-width": this.width
|
1978
|
+
});
|
1979
|
+
replaced_node.find(".aspect-ratio-fill").css({
|
1980
|
+
"padding-bottom": "" + ar.ratio + "%"
|
1981
|
+
});
|
1982
|
+
return self.uploadFile(file, replaced_node);
|
1983
|
+
};
|
1984
|
+
};
|
1985
|
+
})(this);
|
1986
|
+
return reader.readAsDataURL(file);
|
1987
|
+
};
|
1988
|
+
|
1989
|
+
Tooltip.prototype.getAspectRatio = function(w, h) {
|
1990
|
+
var fill_ratio, height, maxHeight, maxWidth, ratio, result, width;
|
1991
|
+
maxWidth = 700;
|
1992
|
+
maxHeight = 700;
|
1993
|
+
ratio = 0;
|
1994
|
+
width = w;
|
1995
|
+
height = h;
|
1996
|
+
if (width > maxWidth) {
|
1997
|
+
ratio = maxWidth / width;
|
1998
|
+
height = height * ratio;
|
1999
|
+
width = width * ratio;
|
2000
|
+
} else if (height > maxHeight) {
|
2001
|
+
ratio = maxHeight / height;
|
2002
|
+
width = width * ratio;
|
2003
|
+
height = height * ratio;
|
2004
|
+
}
|
2005
|
+
fill_ratio = height / width * 100;
|
2006
|
+
result = {
|
2007
|
+
width: width,
|
2008
|
+
height: height,
|
2009
|
+
ratio: fill_ratio
|
2010
|
+
};
|
2011
|
+
utils.log(result);
|
2012
|
+
return result;
|
2013
|
+
};
|
2014
|
+
|
2015
|
+
Tooltip.prototype.formatData = function(file) {
|
2016
|
+
var formData;
|
2017
|
+
formData = new FormData();
|
2018
|
+
formData.append('file', file);
|
2019
|
+
return formData;
|
2020
|
+
};
|
2021
|
+
|
2022
|
+
Tooltip.prototype.uploadFiles = function(files) {
|
2023
|
+
var acceptedTypes, file, i, _results;
|
2024
|
+
acceptedTypes = {
|
2025
|
+
"image/png": true,
|
2026
|
+
"image/jpeg": true,
|
2027
|
+
"image/gif": true
|
2028
|
+
};
|
2029
|
+
i = 0;
|
2030
|
+
_results = [];
|
2031
|
+
while (i < files.length) {
|
2032
|
+
file = files[i];
|
2033
|
+
if (acceptedTypes[file.type] === true) {
|
2034
|
+
$(this.placeholder).append("<progress class=\"progress\" min=\"0\" max=\"100\" value=\"0\">0</progress>");
|
2035
|
+
this.displayAndUploadImages(file);
|
2036
|
+
}
|
2037
|
+
_results.push(i++);
|
2038
|
+
}
|
2039
|
+
return _results;
|
2040
|
+
};
|
2041
|
+
|
2042
|
+
Tooltip.prototype.uploadFile = function(file, node) {
|
2043
|
+
var handleUp, n;
|
2044
|
+
n = node;
|
2045
|
+
handleUp = (function(_this) {
|
2046
|
+
return function(jqxhr) {
|
2047
|
+
return _this.uploadCompleted(jqxhr, n);
|
2048
|
+
};
|
2049
|
+
})(this);
|
2050
|
+
return $.ajax({
|
2051
|
+
type: "post",
|
2052
|
+
url: this.current_editor.upload_url,
|
2053
|
+
xhr: (function(_this) {
|
2054
|
+
return function() {
|
2055
|
+
var xhr;
|
2056
|
+
xhr = new XMLHttpRequest();
|
2057
|
+
xhr.upload.onprogress = _this.updateProgressBar;
|
2058
|
+
return xhr;
|
2059
|
+
};
|
2060
|
+
})(this),
|
2061
|
+
cache: false,
|
2062
|
+
contentType: false,
|
2063
|
+
success: (function(_this) {
|
2064
|
+
return function(response) {
|
2065
|
+
handleUp(response);
|
2066
|
+
};
|
2067
|
+
})(this),
|
2068
|
+
error: (function(_this) {
|
2069
|
+
return function(jqxhr) {
|
2070
|
+
return utils.log("ERROR: got error uploading file " + jqxhr.responseText);
|
2071
|
+
};
|
2072
|
+
})(this),
|
2073
|
+
processData: false,
|
2074
|
+
data: this.formatData(file)
|
2075
|
+
});
|
2076
|
+
};
|
2077
|
+
|
2078
|
+
Tooltip.prototype.updateProgressBar = function(e) {
|
2079
|
+
var $progress, complete;
|
2080
|
+
$progress = $('.progress:first', this.$el);
|
2081
|
+
complete = "";
|
2082
|
+
if (e.lengthComputable) {
|
2083
|
+
complete = e.loaded / e.total * 100;
|
2084
|
+
complete = complete != null ? complete : {
|
2085
|
+
complete: 0
|
2086
|
+
};
|
2087
|
+
utils.log("complete");
|
2088
|
+
return utils.log(complete);
|
2089
|
+
}
|
2090
|
+
};
|
2091
|
+
|
2092
|
+
Tooltip.prototype.uploadCompleted = function(url, node) {
|
2093
|
+
return node.find("img").attr("src", url);
|
2094
|
+
};
|
2095
|
+
|
2096
|
+
Tooltip.prototype.displayEmbedPlaceHolder = function() {
|
2097
|
+
var ph;
|
2098
|
+
ph = this.current_editor.embed_placeholder;
|
2099
|
+
this.node = this.current_editor.getNode();
|
2100
|
+
$(this.node).html(ph).addClass("is-embedable");
|
2101
|
+
this.current_editor.setRangeAt(this.node);
|
2102
|
+
this.hide();
|
2103
|
+
return false;
|
2104
|
+
};
|
2105
|
+
|
2106
|
+
Tooltip.prototype.getEmbedFromNode = function(node) {
|
2107
|
+
this.node = $(node);
|
2108
|
+
this.node_name = this.node.attr("name");
|
2109
|
+
this.node.addClass("spinner");
|
2110
|
+
return $.getJSON("" + this.current_editor.oembed_url + ($(this.node).text())).success((function(_this) {
|
2111
|
+
return function(data) {
|
2112
|
+
var iframe_src, replaced_node, tmpl, url;
|
2113
|
+
_this.node = $("[name=" + _this.node_name + "]");
|
2114
|
+
iframe_src = $(data.html).prop("src");
|
2115
|
+
tmpl = $(_this.embedTemplate());
|
2116
|
+
tmpl.attr("name", _this.node.attr("name"));
|
2117
|
+
$(_this.node).replaceWith(tmpl);
|
2118
|
+
replaced_node = $(".graf--iframe[name=" + (_this.node.attr("name")) + "]");
|
2119
|
+
replaced_node.find("iframe").attr("src", iframe_src);
|
2120
|
+
url = data.url || data.author_url;
|
2121
|
+
utils.log("URL IS " + url);
|
2122
|
+
replaced_node.find(".markup--anchor").attr("href", url).text(url);
|
2123
|
+
return _this.hide();
|
2124
|
+
};
|
2125
|
+
})(this));
|
2126
|
+
};
|
2127
|
+
|
2128
|
+
Tooltip.prototype.displayExtractPlaceHolder = function() {
|
2129
|
+
var ph;
|
2130
|
+
ph = this.current_editor.extract_placeholder;
|
2131
|
+
this.node = this.current_editor.getNode();
|
2132
|
+
$(this.node).html(ph).addClass("is-extractable");
|
2133
|
+
this.current_editor.setRangeAt(this.node);
|
2134
|
+
this.hide();
|
2135
|
+
return false;
|
2136
|
+
};
|
2137
|
+
|
2138
|
+
Tooltip.prototype.getExtractFromNode = function(node) {
|
2139
|
+
this.node = $(node);
|
2140
|
+
this.node_name = this.node.attr("name");
|
2141
|
+
this.node.addClass("spinner");
|
2142
|
+
return $.getJSON("" + this.current_editor.extract_url + ($(this.node).text())).success((function(_this) {
|
2143
|
+
return function(data) {
|
2144
|
+
var iframe_src, image_node, replaced_node, tmpl;
|
2145
|
+
_this.node = $("[name=" + _this.node_name + "]");
|
2146
|
+
iframe_src = $(data.html).prop("src");
|
2147
|
+
tmpl = $(_this.extractTemplate());
|
2148
|
+
tmpl.attr("name", _this.node.attr("name"));
|
2149
|
+
$(_this.node).replaceWith(tmpl);
|
2150
|
+
replaced_node = $(".graf--mixtapeEmbed[name=" + (_this.node.attr("name")) + "]");
|
2151
|
+
replaced_node.find("strong").text(data.title);
|
2152
|
+
replaced_node.find("em").text(data.description);
|
2153
|
+
replaced_node.append(data.provider_url);
|
2154
|
+
replaced_node.find(".markup--anchor").attr("href", data.url);
|
2155
|
+
if (!_.isEmpty(data.images)) {
|
2156
|
+
image_node = replaced_node.find(".mixtapeImage");
|
2157
|
+
image_node.css("background-image", "url(" + data.images[0].url + ")");
|
2158
|
+
image_node.removeClass("mixtapeImage--empty u-ignoreBlock");
|
2159
|
+
}
|
2160
|
+
return _this.hide();
|
2161
|
+
};
|
2162
|
+
})(this));
|
2163
|
+
};
|
2164
|
+
|
2165
|
+
Tooltip.prototype.getExtract = function(url) {
|
2166
|
+
return $.getJSON("" + this.current_editor.extract_url + url).done(function(data) {
|
2167
|
+
return utils.log(data);
|
2168
|
+
});
|
2169
|
+
};
|
2170
|
+
|
2171
|
+
Tooltip.prototype.cleanOperationClasses = function(node) {
|
2172
|
+
return node.removeClass("is-embedable is-extractable");
|
2173
|
+
};
|
2174
|
+
|
2175
|
+
Tooltip.prototype.hide = function() {
|
2176
|
+
return $(this.el).removeClass("is-active is-scaled");
|
2177
|
+
};
|
2178
|
+
|
2179
|
+
return Tooltip;
|
2180
|
+
|
2181
|
+
})(Dante.View);
|
2182
|
+
|
2183
|
+
}).call(this);
|
2184
|
+
(function() {
|
2185
|
+
var utils,
|
2186
|
+
__hasProp = {}.hasOwnProperty,
|
2187
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
2188
|
+
|
2189
|
+
utils = Dante.utils;
|
2190
|
+
|
2191
|
+
Dante.Editor.PopOver = (function(_super) {
|
2192
|
+
__extends(PopOver, _super);
|
2193
|
+
|
2194
|
+
function PopOver() {
|
2195
|
+
return PopOver.__super__.constructor.apply(this, arguments);
|
2196
|
+
}
|
2197
|
+
|
2198
|
+
PopOver.prototype.el = "body";
|
2199
|
+
|
2200
|
+
PopOver.prototype.events = {
|
2201
|
+
"mouseover .popover": "cancelHide",
|
2202
|
+
"mouseout .popover": "hide"
|
2203
|
+
};
|
2204
|
+
|
2205
|
+
PopOver.prototype.initialize = function(opts) {
|
2206
|
+
if (opts == null) {
|
2207
|
+
opts = {};
|
2208
|
+
}
|
2209
|
+
utils.log("initialized popover");
|
2210
|
+
this.editor = opts.editor;
|
2211
|
+
this.hideTimeout;
|
2212
|
+
return this.settings = {
|
2213
|
+
timeout: 300
|
2214
|
+
};
|
2215
|
+
};
|
2216
|
+
|
2217
|
+
PopOver.prototype.template = function() {
|
2218
|
+
return "<div class='popover popover--tooltip popover--Linktooltip popover--bottom is-active'> <div class='popover-inner'> <a href='#' target='_blank'> Link </a> </div> <div class='popover-arrow'> </div> </div>";
|
2219
|
+
};
|
2220
|
+
|
2221
|
+
PopOver.prototype.positionAt = function(ev) {
|
2222
|
+
var left_value, popover_width, target, target_height, target_offset, target_positions, target_width, top_value;
|
2223
|
+
target = $(ev.currentTarget);
|
2224
|
+
target_positions = this.resolveTargetPosition(target);
|
2225
|
+
target_offset = target.offset();
|
2226
|
+
target_width = target.outerWidth();
|
2227
|
+
target_height = target.outerHeight();
|
2228
|
+
popover_width = $(this.el).find(".popover").outerWidth();
|
2229
|
+
top_value = target_positions.top + target_height;
|
2230
|
+
left_value = target_offset.left + (target_width / 2) - (popover_width / 2);
|
2231
|
+
$(this.el).find(".popover").css("top", top_value).css("left", left_value).show();
|
2232
|
+
return this.handleDirection(target);
|
2233
|
+
};
|
2234
|
+
|
2235
|
+
PopOver.prototype.displayAt = function(ev) {
|
2236
|
+
var target;
|
2237
|
+
this.cancelHide();
|
2238
|
+
target = $(ev.currentTarget);
|
2239
|
+
$(this.el).find(".popover-inner a").text(target.attr('href')).attr('href', target.attr("href"));
|
2240
|
+
this.positionAt(ev);
|
2241
|
+
$(this.el).find(".popover--tooltip").css("pointer-events", "auto");
|
2242
|
+
return $(this.el).show();
|
2243
|
+
};
|
2244
|
+
|
2245
|
+
PopOver.prototype.cancelHide = function() {
|
2246
|
+
utils.log("Cancel Hide");
|
2247
|
+
return clearTimeout(this.hideTimeout);
|
2248
|
+
};
|
2249
|
+
|
2250
|
+
PopOver.prototype.hide = function(ev) {
|
2251
|
+
this.cancelHide();
|
2252
|
+
return this.hideTimeout = setTimeout((function(_this) {
|
2253
|
+
return function() {
|
2254
|
+
return $(_this.el).find(".popover").hide();
|
2255
|
+
};
|
2256
|
+
})(this), this.settings.timeout);
|
2257
|
+
};
|
2258
|
+
|
2259
|
+
PopOver.prototype.resolveTargetPosition = function(target) {
|
2260
|
+
if (target.parents(".graf--mixtapeEmbed").exists()) {
|
2261
|
+
return target.parents(".graf--mixtapeEmbed").position();
|
2262
|
+
} else {
|
2263
|
+
return target.position();
|
2264
|
+
}
|
2265
|
+
};
|
2266
|
+
|
2267
|
+
PopOver.prototype.handleDirection = function(target) {
|
2268
|
+
if (target.parents(".graf--mixtapeEmbed").exists()) {
|
2269
|
+
return $(this.el).find(".popover").removeClass("popover--bottom").addClass("popover--top");
|
2270
|
+
} else {
|
2271
|
+
return $(this.el).find(".popover").removeClass("popover--top").addClass("popover--bottom");
|
2272
|
+
}
|
2273
|
+
};
|
2274
|
+
|
2275
|
+
PopOver.prototype.render = function() {
|
2276
|
+
return $(this.template()).insertAfter(this.editor.$el);
|
2277
|
+
};
|
2278
|
+
|
2279
|
+
return PopOver;
|
2280
|
+
|
2281
|
+
})(Dante.View);
|
2282
|
+
|
2283
|
+
}).call(this);
|
2284
|
+
(function() {
|
2285
|
+
var utils,
|
2286
|
+
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
2287
|
+
__hasProp = {}.hasOwnProperty,
|
2288
|
+
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
2289
|
+
|
2290
|
+
utils = Dante.utils;
|
2291
|
+
|
2292
|
+
Dante.Editor.Menu = (function(_super) {
|
2293
|
+
__extends(Menu, _super);
|
2294
|
+
|
2295
|
+
function Menu() {
|
2296
|
+
this.createlink = __bind(this.createlink, this);
|
2297
|
+
this.handleInputEnter = __bind(this.handleInputEnter, this);
|
2298
|
+
this.render = __bind(this.render, this);
|
2299
|
+
this.template = __bind(this.template, this);
|
2300
|
+
this.initialize = __bind(this.initialize, this);
|
2301
|
+
return Menu.__super__.constructor.apply(this, arguments);
|
2302
|
+
}
|
2303
|
+
|
2304
|
+
Menu.prototype.el = "#dante-menu";
|
2305
|
+
|
2306
|
+
Menu.prototype.events = {
|
2307
|
+
"mousedown li": "handleClick",
|
2308
|
+
"click .dante-menu-linkinput .dante-menu-button": "closeInput",
|
2309
|
+
"keypress input": "handleInputEnter"
|
2310
|
+
};
|
2311
|
+
|
2312
|
+
Menu.prototype.initialize = function(opts) {
|
2313
|
+
if (opts == null) {
|
2314
|
+
opts = {};
|
2315
|
+
}
|
2316
|
+
this.config = opts.buttons || this.default_config();
|
2317
|
+
this.current_editor = opts.editor;
|
2318
|
+
this.commandsReg = {
|
2319
|
+
block: /^(?:p|h[1-6]|blockquote|pre)$/,
|
2320
|
+
inline: /^(?:bold|italic|underline|insertorderedlist|insertunorderedlist|indent|outdent)$/,
|
2321
|
+
source: /^(?:insertimage|createlink|unlink)$/,
|
2322
|
+
insert: /^(?:inserthorizontalrule|insert)$/,
|
2323
|
+
wrap: /^(?:code)$/
|
2324
|
+
};
|
2325
|
+
this.lineBreakReg = /^(?:blockquote|pre|div|p)$/i;
|
2326
|
+
this.effectNodeReg = /(?:[pubia]|h[1-6]|blockquote|[uo]l|li)/i;
|
2327
|
+
return this.strReg = {
|
2328
|
+
whiteSpace: /(^\s+)|(\s+$)/g,
|
2329
|
+
mailTo: /^(?!mailto:|.+\/|.+#|.+\?)(.*@.*\..+)$/,
|
2330
|
+
http: /^(?!\w+?:\/\/|mailto:|\/|\.\/|\?|#)(.*)$/
|
2331
|
+
};
|
2332
|
+
};
|
2333
|
+
|
2334
|
+
Menu.prototype.default_config = function() {
|
2335
|
+
return {
|
2336
|
+
|
2337
|
+
/*
|
2338
|
+
buttons: [
|
2339
|
+
'blockquote', 'h2', 'h3', 'p', 'code', 'insertorderedlist', 'insertunorderedlist', 'inserthorizontalrule',
|
2340
|
+
'indent', 'outdent', 'bold', 'italic', 'underline', 'createlink'
|
2341
|
+
]
|
2342
|
+
*/
|
2343
|
+
buttons: ['bold', 'italic', 'h2', 'h3', 'h4', 'blockquote', 'createlink']
|
2344
|
+
};
|
2345
|
+
};
|
2346
|
+
|
2347
|
+
Menu.prototype.template = function() {
|
2348
|
+
var html;
|
2349
|
+
html = "<div class='dante-menu-linkinput'><input class='dante-menu-input' placeholder='http://'><div class='dante-menu-button'>x</div></div>";
|
2350
|
+
html += "<ul class='dante-menu-buttons'>";
|
2351
|
+
_.each(this.config.buttons, function(item) {
|
2352
|
+
return html += "<li class='dante-menu-button'><i class=\"dante-icon icon-" + item + "\" data-action=\"" + item + "\"></i></li>";
|
2353
|
+
});
|
2354
|
+
html += "</ul>";
|
2355
|
+
return html;
|
2356
|
+
};
|
2357
|
+
|
2358
|
+
Menu.prototype.render = function() {
|
2359
|
+
$(this.el).html(this.template());
|
2360
|
+
return this.show();
|
2361
|
+
};
|
2362
|
+
|
2363
|
+
Menu.prototype.handleClick = function(ev) {
|
2364
|
+
var action, element, input;
|
2365
|
+
element = $(ev.currentTarget).find('.dante-icon');
|
2366
|
+
action = element.data("action");
|
2367
|
+
input = $(this.el).find("input.dante-menu-input");
|
2368
|
+
utils.log("menu " + action + " item clicked!");
|
2369
|
+
this.savedSel = utils.saveSelection();
|
2370
|
+
if (/(?:createlink)/.test(action)) {
|
2371
|
+
if ($(ev.currentTarget).hasClass("active")) {
|
2372
|
+
this.removeLink();
|
2373
|
+
} else {
|
2374
|
+
$(this.el).addClass("dante-menu--linkmode");
|
2375
|
+
input.focus();
|
2376
|
+
}
|
2377
|
+
} else {
|
2378
|
+
this.menuApply(action);
|
2379
|
+
}
|
2380
|
+
return false;
|
2381
|
+
};
|
2382
|
+
|
2383
|
+
Menu.prototype.closeInput = function(e) {
|
2384
|
+
$(this.el).removeClass("dante-menu--linkmode");
|
2385
|
+
return false;
|
2386
|
+
};
|
2387
|
+
|
2388
|
+
Menu.prototype.handleInputEnter = function(e) {
|
2389
|
+
if (e.which === 13) {
|
2390
|
+
utils.restoreSelection(this.savedSel);
|
2391
|
+
return this.createlink($(e.target));
|
2392
|
+
}
|
2393
|
+
};
|
2394
|
+
|
2395
|
+
Menu.prototype.removeLink = function() {
|
2396
|
+
var elem;
|
2397
|
+
this.menuApply("unlink");
|
2398
|
+
elem = this.current_editor.getNode();
|
2399
|
+
return this.current_editor.cleanContents($(elem));
|
2400
|
+
};
|
2401
|
+
|
2402
|
+
Menu.prototype.createlink = function(input) {
|
2403
|
+
var action, inputValue;
|
2404
|
+
$(this.el).removeClass("dante-menu--linkmode");
|
2405
|
+
if (input.val()) {
|
2406
|
+
inputValue = input.val().replace(this.strReg.whiteSpace, "").replace(this.strReg.mailTo, "mailto:$1").replace(this.strReg.http, "http://$1");
|
2407
|
+
return this.menuApply("createlink", inputValue);
|
2408
|
+
}
|
2409
|
+
action = "unlink";
|
2410
|
+
return this.menuApply(action);
|
2411
|
+
};
|
2412
|
+
|
2413
|
+
Menu.prototype.menuApply = function(action, value) {
|
2414
|
+
if (this.commandsReg.block.test(action)) {
|
2415
|
+
utils.log("block here");
|
2416
|
+
this.commandBlock(action);
|
2417
|
+
} else if (this.commandsReg.inline.test(action) || this.commandsReg.source.test(action)) {
|
2418
|
+
utils.log("overall here");
|
2419
|
+
this.commandOverall(action, value);
|
2420
|
+
} else if (this.commandsReg.insert.test(action)) {
|
2421
|
+
utils.log("insert here");
|
2422
|
+
this.commandInsert(action);
|
2423
|
+
} else if (this.commandsReg.wrap.test(action)) {
|
2424
|
+
utils.log("wrap here");
|
2425
|
+
this.commandWrap(action);
|
2426
|
+
} else {
|
2427
|
+
utils.log("can't find command function for action: " + action);
|
2428
|
+
}
|
2429
|
+
return false;
|
2430
|
+
};
|
2431
|
+
|
2432
|
+
Menu.prototype.setupInsertedElement = function(element) {
|
2433
|
+
var n;
|
2434
|
+
n = this.current_editor.addClassesToElement(element);
|
2435
|
+
this.current_editor.setElementName(n);
|
2436
|
+
return this.current_editor.markAsSelected(n);
|
2437
|
+
};
|
2438
|
+
|
2439
|
+
Menu.prototype.cleanContents = function() {
|
2440
|
+
return this.current_editor.cleanContents();
|
2441
|
+
};
|
2442
|
+
|
2443
|
+
Menu.prototype.commandOverall = function(cmd, val) {
|
2444
|
+
var message, n;
|
2445
|
+
message = " to exec 「" + cmd + "」 command" + (val ? " with value: " + val : "");
|
2446
|
+
if (document.execCommand(cmd, false, val)) {
|
2447
|
+
utils.log("success" + message);
|
2448
|
+
n = this.current_editor.getNode();
|
2449
|
+
this.current_editor.setupLinks($(n).find("a"));
|
2450
|
+
this.displayHighlights();
|
2451
|
+
if ($(n).parent().hasClass("section-inner")) {
|
2452
|
+
n = this.current_editor.addClassesToElement(n);
|
2453
|
+
this.current_editor.setElementName(n);
|
2454
|
+
}
|
2455
|
+
this.current_editor.handleTextSelection(n);
|
2456
|
+
} else {
|
2457
|
+
utils.log("fail" + message, true);
|
2458
|
+
}
|
2459
|
+
};
|
2460
|
+
|
2461
|
+
Menu.prototype.commandInsert = function(name) {
|
2462
|
+
var node;
|
2463
|
+
node = this.current_editor.current_node;
|
2464
|
+
if (!node) {
|
2465
|
+
return;
|
2466
|
+
}
|
2467
|
+
this.current_editor.current_range.selectNode(node);
|
2468
|
+
this.current_editor.current_range.collapse(false);
|
2469
|
+
return this.commandOverall(node, name);
|
2470
|
+
};
|
2471
|
+
|
2472
|
+
Menu.prototype.commandBlock = function(name) {
|
2473
|
+
var list, node;
|
2474
|
+
node = this.current_editor.current_node;
|
2475
|
+
list = this.effectNode(this.current_editor.getNode(node), true);
|
2476
|
+
if (list.indexOf(name) !== -1) {
|
2477
|
+
name = "p";
|
2478
|
+
}
|
2479
|
+
return this.commandOverall("formatblock", name);
|
2480
|
+
};
|
2481
|
+
|
2482
|
+
Menu.prototype.commandWrap = function(tag) {
|
2483
|
+
var node, val;
|
2484
|
+
node = this.current_editor.current_node;
|
2485
|
+
val = "<" + tag + ">" + selection + "</" + tag + ">";
|
2486
|
+
return this.commandOverall("insertHTML", val);
|
2487
|
+
};
|
2488
|
+
|
2489
|
+
Menu.prototype.effectNode = function(el, returnAsNodeName) {
|
2490
|
+
var nodes;
|
2491
|
+
nodes = [];
|
2492
|
+
el = el || this.current_editor.$el[0];
|
2493
|
+
while (el !== this.current_editor.$el[0]) {
|
2494
|
+
if (el.nodeName.match(this.effectNodeReg)) {
|
2495
|
+
nodes.push((returnAsNodeName ? el.nodeName.toLowerCase() : el));
|
2496
|
+
}
|
2497
|
+
el = el.parentNode;
|
2498
|
+
}
|
2499
|
+
return nodes;
|
2500
|
+
};
|
2501
|
+
|
2502
|
+
Menu.prototype.displayHighlights = function() {
|
2503
|
+
var nodes;
|
2504
|
+
$(this.el).find(".active").removeClass("active");
|
2505
|
+
nodes = this.effectNode(utils.getNode());
|
2506
|
+
utils.log(nodes);
|
2507
|
+
return _.each(nodes, (function(_this) {
|
2508
|
+
return function(node) {
|
2509
|
+
var tag;
|
2510
|
+
tag = node.nodeName.toLowerCase();
|
2511
|
+
switch (tag) {
|
2512
|
+
case "a":
|
2513
|
+
$(_this.el).find('input').val($(node).attr("href"));
|
2514
|
+
tag = "createlink";
|
2515
|
+
break;
|
2516
|
+
case "i":
|
2517
|
+
tag = "italic";
|
2518
|
+
break;
|
2519
|
+
case "u":
|
2520
|
+
tag = "underline";
|
2521
|
+
break;
|
2522
|
+
case "b":
|
2523
|
+
tag = "bold";
|
2524
|
+
break;
|
2525
|
+
case "code":
|
2526
|
+
tag = "code";
|
2527
|
+
break;
|
2528
|
+
case "ul":
|
2529
|
+
tag = "insertunorderedlist";
|
2530
|
+
break;
|
2531
|
+
case "ol":
|
2532
|
+
tag = "insertorderedlist";
|
2533
|
+
break;
|
2534
|
+
case "li":
|
2535
|
+
tag = "indent";
|
2536
|
+
utils.log("nothing to select");
|
2537
|
+
}
|
2538
|
+
if (tag.match(/(?:h[1-6])/i)) {
|
2539
|
+
$(_this.el).find(".icon-bold, .icon-italic, .icon-blockquote").parent("li").remove();
|
2540
|
+
} else if (tag === "indent") {
|
2541
|
+
$(_this.el).find(".icon-h2, .icon-h3, .icon-h4, .icon-blockquote").parent("li").remove();
|
2542
|
+
}
|
2543
|
+
return _this.highlight(tag);
|
2544
|
+
};
|
2545
|
+
})(this));
|
2546
|
+
};
|
2547
|
+
|
2548
|
+
Menu.prototype.highlight = function(tag) {
|
2549
|
+
return $(".icon-" + tag).parent("li").addClass("active");
|
2550
|
+
};
|
2551
|
+
|
2552
|
+
Menu.prototype.show = function() {
|
2553
|
+
$(this.el).addClass("dante-menu--active");
|
2554
|
+
this.closeInput();
|
2555
|
+
return this.displayHighlights();
|
2556
|
+
};
|
2557
|
+
|
2558
|
+
Menu.prototype.hide = function() {
|
2559
|
+
return $(this.el).removeClass("dante-menu--active");
|
2560
|
+
};
|
2561
|
+
|
2562
|
+
return Menu;
|
2563
|
+
|
2564
|
+
})(Dante.View);
|
2565
|
+
|
2566
|
+
}).call(this);
|
2567
|
+
//Editor components
|
2568
|
+
|
2569
|
+
|
2570
|
+
|
2571
|
+
|
2572
|
+
|
2573
|
+
|
2574
|
+
|
2575
|
+
;
|