dante-editor 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +6 -1
- data/app/assets/javascripts/dante/editor.js.coffee +25 -20
- data/app/assets/javascripts/dante/tooltip.js.coffee +1 -0
- data/bower.json +1 -1
- data/dist/0.0.10/css/dante-editor.css +1116 -0
- data/dist/0.0.10/fonts/dante/dante.eot +0 -0
- data/dist/0.0.10/fonts/dante/dante.svg +14 -0
- data/dist/0.0.10/fonts/dante/dante.ttf +0 -0
- data/dist/0.0.10/fonts/dante/dante.woff +0 -0
- data/dist/0.0.10/fonts/dante/fontello.eot +0 -0
- data/dist/0.0.10/fonts/dante/fontello.svg +36 -0
- data/dist/0.0.10/fonts/dante/fontello.ttf +0 -0
- data/dist/0.0.10/fonts/dante/fontello.woff +0 -0
- data/dist/0.0.10/images/dante/media-loading-placeholder.png +0 -0
- data/dist/0.0.10/js/dante-editor.js +2584 -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,2584 @@
|
|
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.10"
|
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
|
+
var bodyplaceholder, embedplaceholder, extractplaceholder, titleplaceholder;
|
446
|
+
if (opts == null) {
|
447
|
+
opts = {};
|
448
|
+
}
|
449
|
+
this.editor_options = opts;
|
450
|
+
this.initial_html = $(this.el).html();
|
451
|
+
this.current_range = null;
|
452
|
+
this.current_node = null;
|
453
|
+
this.el = opts.el || "#editor";
|
454
|
+
this.upload_url = opts.upload_url || "/uploads.json";
|
455
|
+
this.upload_callback = opts.upload_callback;
|
456
|
+
this.oembed_url = opts.oembed_url || "http://api.embed.ly/1/oembed?url=";
|
457
|
+
this.extract_url = opts.extract_url || "http://api.embed.ly/1/extract?key=86c28a410a104c8bb58848733c82f840&url=";
|
458
|
+
this.default_loading_placeholder = opts.default_loading_placeholder || Dante.defaults.image_placeholder;
|
459
|
+
this.store_url = opts.store_url;
|
460
|
+
this.spell_check = opts.spellcheck || false;
|
461
|
+
this.disable_title = opts.disable_title || false;
|
462
|
+
this.store_interval = opts.store_interval || 15000;
|
463
|
+
this.paste_element_id = "#dante-paste-div";
|
464
|
+
window.debugMode = opts.debug || false;
|
465
|
+
if (window.debugMode) {
|
466
|
+
$(this.el).addClass("debug");
|
467
|
+
}
|
468
|
+
if (localStorage.getItem('contenteditable')) {
|
469
|
+
$(this.el).html(localStorage.getItem('contenteditable'));
|
470
|
+
}
|
471
|
+
this.store();
|
472
|
+
titleplaceholder = opts.title_placeholder || 'Title';
|
473
|
+
this.title_placeholder = "<span class='defaultValue defaultValue--root'>" + titleplaceholder + "</span><br>";
|
474
|
+
bodyplaceholder = opts.body_placeholder || 'Tell your story…';
|
475
|
+
this.body_placeholder = "<span class='defaultValue defaultValue--root'>" + bodyplaceholder + "</span><br>";
|
476
|
+
embedplaceholder = opts.embed_placeholder || 'Paste a YouTube, Vine, Vimeo, or other video link, and press Enter';
|
477
|
+
this.embed_placeholder = "<span class='defaultValue defaultValue--root'>" + embedplaceholder + "</span><br>";
|
478
|
+
extractplaceholder = opts.extract_placeholder || "Paste a link to embed content from another site (e.g. Twitter) and press Enter";
|
479
|
+
return this.extract_placeholder = "<span class='defaultValue defaultValue--root'>" + extractplaceholder + "</span><br>";
|
480
|
+
};
|
481
|
+
|
482
|
+
Editor.prototype.store = function() {
|
483
|
+
if (!this.store_url) {
|
484
|
+
return;
|
485
|
+
}
|
486
|
+
return setTimeout((function(_this) {
|
487
|
+
return function() {
|
488
|
+
return _this.checkforStore();
|
489
|
+
};
|
490
|
+
})(this), this.store_interval);
|
491
|
+
};
|
492
|
+
|
493
|
+
Editor.prototype.checkforStore = function() {
|
494
|
+
if (this.content === this.getContent()) {
|
495
|
+
utils.log("content not changed skip store");
|
496
|
+
return this.store();
|
497
|
+
} else {
|
498
|
+
utils.log("content changed! update");
|
499
|
+
this.content = this.getContent();
|
500
|
+
return $.ajax({
|
501
|
+
url: this.store_url,
|
502
|
+
method: "post",
|
503
|
+
data: this.getContent(),
|
504
|
+
success: function(res) {
|
505
|
+
utils.log("store!");
|
506
|
+
return utils.log(res);
|
507
|
+
},
|
508
|
+
complete: (function(_this) {
|
509
|
+
return function(jxhr) {
|
510
|
+
return _this.store();
|
511
|
+
};
|
512
|
+
})(this)
|
513
|
+
});
|
514
|
+
}
|
515
|
+
};
|
516
|
+
|
517
|
+
Editor.prototype.getContent = function() {
|
518
|
+
return $(this.el).find(".section-inner").html();
|
519
|
+
};
|
520
|
+
|
521
|
+
Editor.prototype.renderTitle = function() {
|
522
|
+
return "<h3 class='graf graf--h3'>" + this.title_placeholder + " </h3>";
|
523
|
+
};
|
524
|
+
|
525
|
+
Editor.prototype.template = function() {
|
526
|
+
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>";
|
527
|
+
};
|
528
|
+
|
529
|
+
Editor.prototype.baseParagraphTmpl = function() {
|
530
|
+
return "<p class='graf--p' name='" + (utils.generateUniqueName()) + "'><br></p>";
|
531
|
+
};
|
532
|
+
|
533
|
+
Editor.prototype.appendMenus = function() {
|
534
|
+
$("<div id='dante-menu' class='dante-menu'></div>").insertAfter(this.el);
|
535
|
+
$("<div class='inlineTooltip'></div>").insertAfter(this.el);
|
536
|
+
this.editor_menu = new Dante.Editor.Menu({
|
537
|
+
editor: this
|
538
|
+
});
|
539
|
+
this.tooltip_view = new Dante.Editor.Tooltip({
|
540
|
+
editor: this
|
541
|
+
});
|
542
|
+
this.pop_over = new Dante.Editor.PopOver({
|
543
|
+
editor: this
|
544
|
+
});
|
545
|
+
this.pop_over.render().hide();
|
546
|
+
return this.tooltip_view.render().hide();
|
547
|
+
};
|
548
|
+
|
549
|
+
Editor.prototype.appendInitialContent = function() {
|
550
|
+
$(this.el).find(".section-inner").html(this.initial_html);
|
551
|
+
return $(this.el).attr("spellcheck", this.spell_check);
|
552
|
+
};
|
553
|
+
|
554
|
+
Editor.prototype.start = function() {
|
555
|
+
this.render();
|
556
|
+
$(this.el).attr("contenteditable", "true");
|
557
|
+
$(this.el).addClass("postField postField--body editable smart-media-plugin");
|
558
|
+
$(this.el).wrap("<article class='postArticle'><div class='postContent'><div class='notesSource'></div></div></article>");
|
559
|
+
this.appendMenus();
|
560
|
+
if (!_.isEmpty(this.initial_html.trim())) {
|
561
|
+
this.appendInitialContent();
|
562
|
+
}
|
563
|
+
return this.parseInitialMess();
|
564
|
+
};
|
565
|
+
|
566
|
+
Editor.prototype.restart = function() {
|
567
|
+
return this.render();
|
568
|
+
};
|
569
|
+
|
570
|
+
Editor.prototype.render = function() {
|
571
|
+
this.template();
|
572
|
+
return $(this.el).html(this.template());
|
573
|
+
};
|
574
|
+
|
575
|
+
Editor.prototype.getSelectedText = function() {
|
576
|
+
var text;
|
577
|
+
text = "";
|
578
|
+
if (typeof window.getSelection !== "undefined") {
|
579
|
+
text = window.getSelection().toString();
|
580
|
+
} else if (typeof document.selection !== "undefined" && document.selection.type === "Text") {
|
581
|
+
text = document.selection.createRange().text;
|
582
|
+
}
|
583
|
+
return text;
|
584
|
+
};
|
585
|
+
|
586
|
+
Editor.prototype.selection = function() {
|
587
|
+
selection;
|
588
|
+
var selection;
|
589
|
+
if (window.getSelection) {
|
590
|
+
return selection = window.getSelection();
|
591
|
+
} else if (document.selection && document.selection.type !== "Control") {
|
592
|
+
return selection = document.selection;
|
593
|
+
}
|
594
|
+
};
|
595
|
+
|
596
|
+
Editor.prototype.getRange = function() {
|
597
|
+
var editor, range;
|
598
|
+
editor = $(this.el)[0];
|
599
|
+
range = selection && selection.rangeCount && selection.getRangeAt(0);
|
600
|
+
if (!range) {
|
601
|
+
range = document.createRange();
|
602
|
+
}
|
603
|
+
if (!editor.contains(range.commonAncestorContainer)) {
|
604
|
+
range.selectNodeContents(editor);
|
605
|
+
range.collapse(false);
|
606
|
+
}
|
607
|
+
return range;
|
608
|
+
};
|
609
|
+
|
610
|
+
Editor.prototype.setRange = function(range) {
|
611
|
+
range = range || this.current_range;
|
612
|
+
if (!range) {
|
613
|
+
range = this.getRange();
|
614
|
+
range.collapse(false);
|
615
|
+
}
|
616
|
+
this.selection().removeAllRanges();
|
617
|
+
this.selection().addRange(range);
|
618
|
+
return this;
|
619
|
+
};
|
620
|
+
|
621
|
+
Editor.prototype.getCharacterPrecedingCaret = function() {
|
622
|
+
var precedingChar, precedingRange, range, sel;
|
623
|
+
precedingChar = "";
|
624
|
+
sel = void 0;
|
625
|
+
range = void 0;
|
626
|
+
precedingRange = void 0;
|
627
|
+
if (window.getSelection) {
|
628
|
+
sel = window.getSelection();
|
629
|
+
if (sel.rangeCount > 0) {
|
630
|
+
range = sel.getRangeAt(0).cloneRange();
|
631
|
+
range.collapse(true);
|
632
|
+
range.setStart(this.getNode(), 0);
|
633
|
+
precedingChar = range.toString().slice(0);
|
634
|
+
}
|
635
|
+
} else if ((sel = document.selection) && sel.type !== "Control") {
|
636
|
+
range = sel.createRange();
|
637
|
+
precedingRange = range.duplicate();
|
638
|
+
precedingRange.moveToElementText(containerEl);
|
639
|
+
precedingRange.setEndPoint("EndToStart", range);
|
640
|
+
precedingChar = precedingRange.text.slice(0);
|
641
|
+
}
|
642
|
+
return precedingChar;
|
643
|
+
};
|
644
|
+
|
645
|
+
Editor.prototype.isLastChar = function() {
|
646
|
+
return $(this.getNode()).text().trim().length === this.getCharacterPrecedingCaret().trim().length;
|
647
|
+
};
|
648
|
+
|
649
|
+
Editor.prototype.isFirstChar = function() {
|
650
|
+
return this.getCharacterPrecedingCaret().trim().length === 0;
|
651
|
+
};
|
652
|
+
|
653
|
+
Editor.prototype.isSelectingAll = function(element) {
|
654
|
+
var a, b;
|
655
|
+
a = this.getSelectedText().killWhiteSpace().length;
|
656
|
+
b = $(element).text().killWhiteSpace().length;
|
657
|
+
return a === b;
|
658
|
+
};
|
659
|
+
|
660
|
+
Editor.prototype.setRangeAt = function(element, int) {
|
661
|
+
var range, sel;
|
662
|
+
if (int == null) {
|
663
|
+
int = 0;
|
664
|
+
}
|
665
|
+
range = document.createRange();
|
666
|
+
sel = window.getSelection();
|
667
|
+
range.setStart(element, int);
|
668
|
+
range.collapse(true);
|
669
|
+
sel.removeAllRanges();
|
670
|
+
sel.addRange(range);
|
671
|
+
return element.focus();
|
672
|
+
};
|
673
|
+
|
674
|
+
Editor.prototype.setRangeAtText = function(element, int) {
|
675
|
+
var node, range, sel;
|
676
|
+
if (int == null) {
|
677
|
+
int = 0;
|
678
|
+
}
|
679
|
+
range = document.createRange();
|
680
|
+
sel = window.getSelection();
|
681
|
+
node = element.firstChild;
|
682
|
+
range.setStart(node, 0);
|
683
|
+
range.setEnd(node, 0);
|
684
|
+
range.collapse(true);
|
685
|
+
sel.removeAllRanges();
|
686
|
+
sel.addRange(range);
|
687
|
+
return element.focus();
|
688
|
+
};
|
689
|
+
|
690
|
+
Editor.prototype.focus = function(focusStart) {
|
691
|
+
if (!focusStart) {
|
692
|
+
this.setRange();
|
693
|
+
}
|
694
|
+
$(this.el).focus();
|
695
|
+
return this;
|
696
|
+
};
|
697
|
+
|
698
|
+
Editor.prototype.focusNode = function(node, range) {
|
699
|
+
range.setStartAfter(node);
|
700
|
+
range.setEndBefore(node);
|
701
|
+
range.collapse(false);
|
702
|
+
return this.setRange(range);
|
703
|
+
};
|
704
|
+
|
705
|
+
Editor.prototype.getNode = function() {
|
706
|
+
var node, range, root;
|
707
|
+
node = void 0;
|
708
|
+
root = $(this.el).find(".section-inner")[0];
|
709
|
+
if (this.selection().rangeCount < 1) {
|
710
|
+
return;
|
711
|
+
}
|
712
|
+
range = this.selection().getRangeAt(0);
|
713
|
+
node = range.commonAncestorContainer;
|
714
|
+
if (!node || node === root) {
|
715
|
+
return null;
|
716
|
+
}
|
717
|
+
while (node && (node.nodeType !== 1 || !$(node).hasClass("graf")) && (node.parentNode !== root)) {
|
718
|
+
node = node.parentNode;
|
719
|
+
}
|
720
|
+
if (!$(node).hasClass("graf--li")) {
|
721
|
+
while (node && (node.parentNode !== root)) {
|
722
|
+
node = node.parentNode;
|
723
|
+
}
|
724
|
+
}
|
725
|
+
if (root && root.contains(node)) {
|
726
|
+
return node;
|
727
|
+
} else {
|
728
|
+
return null;
|
729
|
+
}
|
730
|
+
};
|
731
|
+
|
732
|
+
Editor.prototype.displayMenu = function(sel) {
|
733
|
+
return setTimeout((function(_this) {
|
734
|
+
return function() {
|
735
|
+
var pos;
|
736
|
+
_this.editor_menu.render();
|
737
|
+
pos = utils.getSelectionDimensions();
|
738
|
+
_this.relocateMenu(pos);
|
739
|
+
return _this.editor_menu.show();
|
740
|
+
};
|
741
|
+
})(this), 10);
|
742
|
+
};
|
743
|
+
|
744
|
+
Editor.prototype.handleDrag = function() {
|
745
|
+
return false;
|
746
|
+
};
|
747
|
+
|
748
|
+
Editor.prototype.handleGrafCaptionTyping = function(ev) {
|
749
|
+
if (_.isEmpty(utils.getNode().textContent.trim())) {
|
750
|
+
return $(this.getNode()).addClass("is-defaultValue");
|
751
|
+
} else {
|
752
|
+
return $(this.getNode()).removeClass("is-defaultValue");
|
753
|
+
}
|
754
|
+
};
|
755
|
+
|
756
|
+
Editor.prototype.handleTextSelection = function(anchor_node) {
|
757
|
+
var text;
|
758
|
+
this.editor_menu.hide();
|
759
|
+
text = this.getSelectedText();
|
760
|
+
if (!$(anchor_node).is(".graf--mixtapeEmbed, .graf--figure") && !_.isEmpty(text.trim())) {
|
761
|
+
this.current_node = anchor_node;
|
762
|
+
return this.displayMenu();
|
763
|
+
}
|
764
|
+
};
|
765
|
+
|
766
|
+
Editor.prototype.relocateMenu = function(position) {
|
767
|
+
var height, left, padd, top;
|
768
|
+
height = this.editor_menu.$el.outerHeight();
|
769
|
+
padd = this.editor_menu.$el.width() / 2;
|
770
|
+
top = position.top + $(window).scrollTop() - height;
|
771
|
+
left = position.left + (position.width / 2) - padd;
|
772
|
+
return this.editor_menu.$el.offset({
|
773
|
+
left: left,
|
774
|
+
top: top
|
775
|
+
});
|
776
|
+
};
|
777
|
+
|
778
|
+
Editor.prototype.hidePlaceholder = function(element) {
|
779
|
+
return $(element).find("span.defaultValue").remove().html("<br>");
|
780
|
+
};
|
781
|
+
|
782
|
+
Editor.prototype.displayEmptyPlaceholder = function(element) {
|
783
|
+
$(".graf--first").html(this.title_placeholder);
|
784
|
+
return $(".graf--last").html(this.body_placeholder);
|
785
|
+
};
|
786
|
+
|
787
|
+
Editor.prototype.displayPopOver = function(ev) {
|
788
|
+
return this.pop_over.displayAt(ev);
|
789
|
+
};
|
790
|
+
|
791
|
+
Editor.prototype.hidePopOver = function(ev) {
|
792
|
+
return this.pop_over.hide(ev);
|
793
|
+
};
|
794
|
+
|
795
|
+
Editor.prototype.handleGrafFigureSelectImg = function(ev) {
|
796
|
+
var element;
|
797
|
+
utils.log("FIGURE SELECT");
|
798
|
+
element = ev.currentTarget;
|
799
|
+
this.markAsSelected(element);
|
800
|
+
$(element).parent(".graf--figure").addClass("is-selected is-mediaFocused");
|
801
|
+
return this.selection().removeAllRanges();
|
802
|
+
};
|
803
|
+
|
804
|
+
Editor.prototype.handleGrafFigureSelectIframe = function(ev) {
|
805
|
+
var element;
|
806
|
+
utils.log("FIGURE IFRAME SELECT");
|
807
|
+
element = ev.currentTarget;
|
808
|
+
this.iframeSelected = element;
|
809
|
+
this.markAsSelected(element);
|
810
|
+
$(element).addClass("is-selected is-mediaFocused");
|
811
|
+
return this.selection().removeAllRanges();
|
812
|
+
};
|
813
|
+
|
814
|
+
Editor.prototype.handleGrafFigureUnSelectIframe = function(ev) {
|
815
|
+
var element;
|
816
|
+
utils.log("FIGURE IFRAME UNSELECT");
|
817
|
+
element = ev.currentTarget;
|
818
|
+
this.iframeSelected = null;
|
819
|
+
return $(element).removeClass("is-selected is-mediaFocused");
|
820
|
+
};
|
821
|
+
|
822
|
+
Editor.prototype.handleGrafFigureSelectCaption = function(ev) {
|
823
|
+
var element;
|
824
|
+
utils.log("FIGCAPTION");
|
825
|
+
element = ev.currentTarget;
|
826
|
+
return $(element).parent(".graf--figure").removeClass("is-mediaFocused");
|
827
|
+
};
|
828
|
+
|
829
|
+
Editor.prototype.handleMouseUp = function(ev) {
|
830
|
+
var anchor_node;
|
831
|
+
utils.log("MOUSE UP");
|
832
|
+
anchor_node = this.getNode();
|
833
|
+
if (_.isNull(anchor_node)) {
|
834
|
+
return;
|
835
|
+
}
|
836
|
+
this.prev_current_node = anchor_node;
|
837
|
+
this.handleTextSelection(anchor_node);
|
838
|
+
this.hidePlaceholder(anchor_node);
|
839
|
+
this.markAsSelected(anchor_node);
|
840
|
+
return this.displayTooltipAt(anchor_node);
|
841
|
+
};
|
842
|
+
|
843
|
+
Editor.prototype.scrollTo = function(node) {
|
844
|
+
var top;
|
845
|
+
if (utils.isElementInViewport($(node))) {
|
846
|
+
return;
|
847
|
+
}
|
848
|
+
top = node.offset().top;
|
849
|
+
return $('html, body').animate({
|
850
|
+
scrollTop: top
|
851
|
+
}, 20);
|
852
|
+
};
|
853
|
+
|
854
|
+
Editor.prototype.handleArrow = function(ev) {
|
855
|
+
var current_node;
|
856
|
+
current_node = $(this.getNode());
|
857
|
+
if (current_node.length > 0) {
|
858
|
+
this.markAsSelected(current_node);
|
859
|
+
return this.displayTooltipAt(current_node);
|
860
|
+
}
|
861
|
+
};
|
862
|
+
|
863
|
+
Editor.prototype.handleArrowForKeyDown = function(ev) {
|
864
|
+
var caret_node, current_node, ev_type, n, next_node, num, prev_node;
|
865
|
+
caret_node = this.getNode();
|
866
|
+
current_node = $(caret_node);
|
867
|
+
utils.log(ev);
|
868
|
+
ev_type = ev.originalEvent.key || ev.originalEvent.keyIdentifier;
|
869
|
+
utils.log("ENTER ARROW for key " + ev_type);
|
870
|
+
switch (ev_type) {
|
871
|
+
case "Down":
|
872
|
+
if (_.isUndefined(current_node) || !current_node.exists()) {
|
873
|
+
if ($(".is-selected").exists()) {
|
874
|
+
current_node = $(".is-selected");
|
875
|
+
}
|
876
|
+
}
|
877
|
+
next_node = current_node.next();
|
878
|
+
utils.log("NEXT NODE IS " + (next_node.attr('class')));
|
879
|
+
utils.log("CURRENT NODE IS " + (current_node.attr('class')));
|
880
|
+
if (!$(current_node).hasClass("graf")) {
|
881
|
+
return;
|
882
|
+
}
|
883
|
+
if (!(current_node.hasClass("graf--figure") || $(current_node).editableCaretOnLastLine())) {
|
884
|
+
return;
|
885
|
+
}
|
886
|
+
utils.log("ENTER ARROW PASSED RETURNS");
|
887
|
+
if (next_node.hasClass("graf--figure") && caret_node) {
|
888
|
+
n = next_node.find(".imageCaption");
|
889
|
+
this.scrollTo(n);
|
890
|
+
utils.log("1 down");
|
891
|
+
utils.log(n[0]);
|
892
|
+
this.skip_keyup = true;
|
893
|
+
this.selection().removeAllRanges();
|
894
|
+
this.markAsSelected(next_node);
|
895
|
+
next_node.addClass("is-mediaFocused is-selected");
|
896
|
+
return false;
|
897
|
+
} else if (next_node.hasClass("graf--mixtapeEmbed")) {
|
898
|
+
n = current_node.next(".graf--mixtapeEmbed");
|
899
|
+
num = n[0].childNodes.length;
|
900
|
+
this.setRangeAt(n[0], num);
|
901
|
+
this.scrollTo(n);
|
902
|
+
utils.log("2 down");
|
903
|
+
return false;
|
904
|
+
}
|
905
|
+
if (current_node.hasClass("graf--figure") && next_node.hasClass("graf")) {
|
906
|
+
this.scrollTo(next_node);
|
907
|
+
utils.log("3 down, from figure to next graf");
|
908
|
+
this.markAsSelected(next_node);
|
909
|
+
this.setRangeAt(next_node[0]);
|
910
|
+
return false;
|
911
|
+
}
|
912
|
+
break;
|
913
|
+
case "Up":
|
914
|
+
prev_node = current_node.prev();
|
915
|
+
utils.log("PREV NODE IS " + (prev_node.attr('class')));
|
916
|
+
utils.log("CURRENT NODE IS up " + (current_node.attr('class')));
|
917
|
+
if (!$(current_node).hasClass("graf")) {
|
918
|
+
return;
|
919
|
+
}
|
920
|
+
if (!$(current_node).editableCaretOnFirstLine()) {
|
921
|
+
return;
|
922
|
+
}
|
923
|
+
utils.log("ENTER ARROW PASSED RETURNS");
|
924
|
+
if (prev_node.hasClass("graf--figure")) {
|
925
|
+
utils.log("1 up");
|
926
|
+
n = prev_node.find(".imageCaption");
|
927
|
+
this.scrollTo(n);
|
928
|
+
this.skip_keyup = true;
|
929
|
+
this.selection().removeAllRanges();
|
930
|
+
this.markAsSelected(prev_node);
|
931
|
+
prev_node.addClass("is-mediaFocused");
|
932
|
+
return false;
|
933
|
+
} else if (prev_node.hasClass("graf--mixtapeEmbed")) {
|
934
|
+
n = current_node.prev(".graf--mixtapeEmbed");
|
935
|
+
num = n[0].childNodes.length;
|
936
|
+
this.setRangeAt(n[0], num);
|
937
|
+
this.scrollTo(n);
|
938
|
+
utils.log("2 up");
|
939
|
+
return false;
|
940
|
+
}
|
941
|
+
if (current_node.hasClass("graf--figure") && prev_node.hasClass("graf")) {
|
942
|
+
this.setRangeAt(prev_node[0]);
|
943
|
+
this.scrollTo(prev_node);
|
944
|
+
utils.log("3 up");
|
945
|
+
return false;
|
946
|
+
} else if (prev_node.hasClass("graf")) {
|
947
|
+
n = current_node.prev(".graf");
|
948
|
+
num = n[0].childNodes.length;
|
949
|
+
this.scrollTo(n);
|
950
|
+
utils.log("4 up");
|
951
|
+
this.skip_keyup = true;
|
952
|
+
this.markAsSelected(prev_node);
|
953
|
+
return false;
|
954
|
+
}
|
955
|
+
}
|
956
|
+
};
|
957
|
+
|
958
|
+
Editor.prototype.parseInitialMess = function() {
|
959
|
+
return this.setupElementsClasses($(this.el).find('.section-inner'), (function(_this) {
|
960
|
+
return function() {
|
961
|
+
return _this.handleUnwrappedImages($(_this.el).find('.section-inner'));
|
962
|
+
};
|
963
|
+
})(this));
|
964
|
+
};
|
965
|
+
|
966
|
+
Editor.prototype.handleDblclick = function() {
|
967
|
+
var node;
|
968
|
+
utils.log("handleDblclick");
|
969
|
+
node = this.getNode();
|
970
|
+
if (_.isNull(node)) {
|
971
|
+
this.setRangeAt(this.prev_current_node);
|
972
|
+
}
|
973
|
+
return false;
|
974
|
+
};
|
975
|
+
|
976
|
+
Editor.prototype.handlePaste = function(ev) {
|
977
|
+
var cbd, pastedText;
|
978
|
+
utils.log("pasted!");
|
979
|
+
this.aa = this.getNode();
|
980
|
+
pastedText = void 0;
|
981
|
+
if (window.clipboardData && window.clipboardData.getData) {
|
982
|
+
pastedText = window.clipboardData.getData('Text');
|
983
|
+
} else if (ev.originalEvent.clipboardData && ev.originalEvent.clipboardData.getData) {
|
984
|
+
cbd = ev.originalEvent.clipboardData;
|
985
|
+
pastedText = _.isEmpty(cbd.getData('text/html')) ? cbd.getData('text/plain') : cbd.getData('text/html');
|
986
|
+
}
|
987
|
+
utils.log("Process and handle text...");
|
988
|
+
if (pastedText.match(/<\/*[a-z][^>]+?>/gi)) {
|
989
|
+
utils.log("HTML DETECTED ON PASTE");
|
990
|
+
pastedText = pastedText.replace(/&.*;/g, "");
|
991
|
+
pastedText = pastedText.replace(/<div>([\w\W]*?)<\/div>/gi, '<p>$1</p>');
|
992
|
+
document.body.appendChild($("<div id='" + (this.paste_element_id.replace('#', '')) + "'></div>")[0]);
|
993
|
+
$(this.paste_element_id).html("<span>" + pastedText + "</span>");
|
994
|
+
this.setupElementsClasses($(this.paste_element_id), (function(_this) {
|
995
|
+
return function() {
|
996
|
+
var last_node, new_node, nodes, num, top;
|
997
|
+
nodes = $($(_this.paste_element_id).html()).insertAfter($(_this.aa));
|
998
|
+
$(_this.paste_element_id).remove();
|
999
|
+
last_node = nodes.last()[0];
|
1000
|
+
num = last_node.childNodes.length;
|
1001
|
+
_this.setRangeAt(last_node, num);
|
1002
|
+
new_node = $(_this.getNode());
|
1003
|
+
top = new_node.offset().top;
|
1004
|
+
_this.markAsSelected(new_node);
|
1005
|
+
_this.displayTooltipAt($(_this.el).find(".is-selected"));
|
1006
|
+
_this.handleUnwrappedImages(nodes);
|
1007
|
+
return $('html, body').animate({
|
1008
|
+
scrollTop: top
|
1009
|
+
}, 200);
|
1010
|
+
};
|
1011
|
+
})(this));
|
1012
|
+
return false;
|
1013
|
+
}
|
1014
|
+
};
|
1015
|
+
|
1016
|
+
Editor.prototype.handleUnwrappedImages = function(elements) {
|
1017
|
+
return _.each(elements.find("img"), (function(_this) {
|
1018
|
+
return function(image) {
|
1019
|
+
utils.log("process image here!");
|
1020
|
+
return _this.tooltip_view.uploadExistentImage(image);
|
1021
|
+
};
|
1022
|
+
})(this));
|
1023
|
+
};
|
1024
|
+
|
1025
|
+
Editor.prototype.handleInmediateDeletion = function(element) {
|
1026
|
+
var new_node;
|
1027
|
+
this.inmediateDeletion = false;
|
1028
|
+
new_node = $(this.baseParagraphTmpl()).insertBefore($(element));
|
1029
|
+
new_node.addClass("is-selected");
|
1030
|
+
this.setRangeAt($(element).prev()[0]);
|
1031
|
+
return $(element).remove();
|
1032
|
+
};
|
1033
|
+
|
1034
|
+
Editor.prototype.handleUnwrappedNode = function(element) {
|
1035
|
+
var new_node, tmpl;
|
1036
|
+
tmpl = $(this.baseParagraphTmpl());
|
1037
|
+
this.setElementName(tmpl);
|
1038
|
+
$(element).wrap(tmpl);
|
1039
|
+
new_node = $("[name='" + (tmpl.attr('name')) + "']");
|
1040
|
+
new_node.addClass("is-selected");
|
1041
|
+
this.setRangeAt(new_node[0]);
|
1042
|
+
return false;
|
1043
|
+
};
|
1044
|
+
|
1045
|
+
|
1046
|
+
/*
|
1047
|
+
This is a rare hack only for FF (I hope),
|
1048
|
+
when there is no range it creates a new element as a placeholder,
|
1049
|
+
then finds previous element from that placeholder,
|
1050
|
+
then it focus the prev and removes the placeholder.
|
1051
|
+
a nasty nasty one...
|
1052
|
+
*/
|
1053
|
+
|
1054
|
+
Editor.prototype.handleNullAnchor = function() {
|
1055
|
+
var node, num, prev, range, sel, span;
|
1056
|
+
utils.log("WARNING! this is an empty node");
|
1057
|
+
sel = this.selection();
|
1058
|
+
if (sel.isCollapsed && sel.rangeCount > 0) {
|
1059
|
+
range = sel.getRangeAt(0);
|
1060
|
+
span = $(this.baseParagraphTmpl())[0];
|
1061
|
+
range.insertNode(span);
|
1062
|
+
range.setStart(span, 0);
|
1063
|
+
range.setEnd(span, 0);
|
1064
|
+
sel.removeAllRanges();
|
1065
|
+
sel.addRange(range);
|
1066
|
+
node = $(range.commonAncestorContainer);
|
1067
|
+
prev = node.prev();
|
1068
|
+
num = prev[0].childNodes.length;
|
1069
|
+
utils.log(prev);
|
1070
|
+
if (prev.hasClass("graf")) {
|
1071
|
+
this.setRangeAt(prev[0], num);
|
1072
|
+
node.remove();
|
1073
|
+
this.markAsSelected(this.getNode());
|
1074
|
+
} else if (prev.hasClass("graf--mixtapeEmbed")) {
|
1075
|
+
this.setRangeAt(prev[0], num);
|
1076
|
+
node.remove();
|
1077
|
+
this.markAsSelected(this.getNode());
|
1078
|
+
} else if (!prev) {
|
1079
|
+
this.setRangeAt(this.$el.find(".section-inner p")[0]);
|
1080
|
+
}
|
1081
|
+
return this.displayTooltipAt($(this.el).find(".is-selected"));
|
1082
|
+
}
|
1083
|
+
};
|
1084
|
+
|
1085
|
+
Editor.prototype.handleCompleteDeletion = function(element) {
|
1086
|
+
if (_.isEmpty($(element).text().trim())) {
|
1087
|
+
utils.log("HANDLE COMPLETE DELETION");
|
1088
|
+
this.selection().removeAllRanges();
|
1089
|
+
this.render();
|
1090
|
+
setTimeout((function(_this) {
|
1091
|
+
return function() {
|
1092
|
+
return _this.setRangeAt($(_this.el).find(".section-inner p")[0]);
|
1093
|
+
};
|
1094
|
+
})(this), 20);
|
1095
|
+
return this.completeDeletion = true;
|
1096
|
+
}
|
1097
|
+
};
|
1098
|
+
|
1099
|
+
Editor.prototype.handleTab = function(anchor_node) {
|
1100
|
+
var classes, next;
|
1101
|
+
utils.log("HANDLE TAB");
|
1102
|
+
classes = ".graf, .graf--mixtapeEmbed, .graf--figure, .graf--figure";
|
1103
|
+
next = $(anchor_node).next(classes);
|
1104
|
+
if ($(next).hasClass("graf--figure")) {
|
1105
|
+
next = $(next).find("figcaption");
|
1106
|
+
this.setRangeAt(next[0]);
|
1107
|
+
this.markAsSelected($(next).parent(".graf--figure"));
|
1108
|
+
this.displayTooltipAt(next);
|
1109
|
+
this.scrollTo($(next));
|
1110
|
+
return false;
|
1111
|
+
}
|
1112
|
+
if (_.isEmpty(next) || _.isUndefined(next[0])) {
|
1113
|
+
next = $(".graf:first");
|
1114
|
+
}
|
1115
|
+
this.setRangeAt(next[0]);
|
1116
|
+
this.markAsSelected(next);
|
1117
|
+
this.displayTooltipAt(next);
|
1118
|
+
return this.scrollTo($(next));
|
1119
|
+
};
|
1120
|
+
|
1121
|
+
Editor.prototype.handleKeyDown = function(e) {
|
1122
|
+
var $node, anchor_node, li, parent, utils_anchor_node;
|
1123
|
+
utils.log("KEYDOWN");
|
1124
|
+
anchor_node = this.getNode();
|
1125
|
+
$node = $(anchor_node);
|
1126
|
+
if (anchor_node) {
|
1127
|
+
this.markAsSelected(anchor_node);
|
1128
|
+
}
|
1129
|
+
if (e.which === 9) {
|
1130
|
+
this.handleTab(anchor_node);
|
1131
|
+
return false;
|
1132
|
+
}
|
1133
|
+
if (e.which === 13) {
|
1134
|
+
$(this.el).find(".is-selected").removeClass("is-selected");
|
1135
|
+
parent = $(anchor_node);
|
1136
|
+
utils.log(this.isLastChar());
|
1137
|
+
if ($node.hasClass("graf--p")) {
|
1138
|
+
li = this.handleSmartList($node, e);
|
1139
|
+
if (li) {
|
1140
|
+
anchor_node = li;
|
1141
|
+
}
|
1142
|
+
} else if ($node.hasClass("graf--li")) {
|
1143
|
+
this.handleListLineBreak($node, e);
|
1144
|
+
}
|
1145
|
+
if (parent.hasClass("is-embedable")) {
|
1146
|
+
this.tooltip_view.getEmbedFromNode($(anchor_node));
|
1147
|
+
} else if (parent.hasClass("is-extractable")) {
|
1148
|
+
this.tooltip_view.getExtractFromNode($(anchor_node));
|
1149
|
+
}
|
1150
|
+
if (parent.hasClass("graf--mixtapeEmbed") || parent.hasClass("graf--iframe") || parent.hasClass("graf--figure")) {
|
1151
|
+
utils.log("supress linebreak from embed !(last char)");
|
1152
|
+
if (!this.isLastChar()) {
|
1153
|
+
return false;
|
1154
|
+
}
|
1155
|
+
}
|
1156
|
+
if (parent.hasClass("graf--iframe") || parent.hasClass("graf--figure")) {
|
1157
|
+
if (this.isLastChar()) {
|
1158
|
+
this.handleLineBreakWith("p", parent);
|
1159
|
+
this.setRangeAtText($(".is-selected")[0]);
|
1160
|
+
$(".is-selected").trigger("mouseup");
|
1161
|
+
return false;
|
1162
|
+
} else {
|
1163
|
+
return false;
|
1164
|
+
}
|
1165
|
+
}
|
1166
|
+
this.tooltip_view.cleanOperationClasses($(anchor_node));
|
1167
|
+
if (anchor_node && this.editor_menu.lineBreakReg.test(anchor_node.nodeName)) {
|
1168
|
+
if (this.isLastChar()) {
|
1169
|
+
utils.log("new paragraph if it's the last character");
|
1170
|
+
e.preventDefault();
|
1171
|
+
this.handleLineBreakWith("p", parent);
|
1172
|
+
}
|
1173
|
+
}
|
1174
|
+
setTimeout((function(_this) {
|
1175
|
+
return function() {
|
1176
|
+
var node;
|
1177
|
+
node = _this.getNode();
|
1178
|
+
if (_.isUndefined(node)) {
|
1179
|
+
return;
|
1180
|
+
}
|
1181
|
+
_this.setElementName($(node));
|
1182
|
+
if (node.nodeName.toLowerCase() === "div") {
|
1183
|
+
node = _this.replaceWith("p", $(node))[0];
|
1184
|
+
}
|
1185
|
+
_this.markAsSelected($(node));
|
1186
|
+
_this.setupFirstAndLast();
|
1187
|
+
if (_.isEmpty($(node).text().trim())) {
|
1188
|
+
_.each($(node).children(), function(n) {
|
1189
|
+
return $(n).remove();
|
1190
|
+
});
|
1191
|
+
$(node).append("<br>");
|
1192
|
+
}
|
1193
|
+
return _this.displayTooltipAt($(_this.el).find(".is-selected"));
|
1194
|
+
};
|
1195
|
+
})(this), 2);
|
1196
|
+
}
|
1197
|
+
if (e.which === 8) {
|
1198
|
+
this.tooltip_view.hide();
|
1199
|
+
utils.log("removing from down");
|
1200
|
+
if (this.reachedTop) {
|
1201
|
+
utils.log("REACHED TOP");
|
1202
|
+
}
|
1203
|
+
if (this.prevented || this.reachedTop && this.isFirstChar()) {
|
1204
|
+
return false;
|
1205
|
+
}
|
1206
|
+
utils.log("pass initial validations");
|
1207
|
+
anchor_node = this.getNode();
|
1208
|
+
utils_anchor_node = utils.getNode();
|
1209
|
+
if ($node.hasClass("graf--li") && this.getCharacterPrecedingCaret().length === 0) {
|
1210
|
+
return this.handleListBackspace($node, e);
|
1211
|
+
}
|
1212
|
+
if ($(utils_anchor_node).hasClass("section-content") || $(utils_anchor_node).hasClass("graf--first")) {
|
1213
|
+
utils.log("SECTION DETECTED FROM KEYDOWN " + (_.isEmpty($(utils_anchor_node).text())));
|
1214
|
+
if (_.isEmpty($(utils_anchor_node).text())) {
|
1215
|
+
return false;
|
1216
|
+
}
|
1217
|
+
}
|
1218
|
+
if (anchor_node && anchor_node.nodeType === 3) {
|
1219
|
+
utils.log("TextNode detected from Down!");
|
1220
|
+
}
|
1221
|
+
if ($(anchor_node).hasClass("graf--mixtapeEmbed") || $(anchor_node).hasClass("graf--iframe")) {
|
1222
|
+
if (_.isEmpty($(anchor_node).text().trim() || this.isFirstChar())) {
|
1223
|
+
utils.log("Check for inmediate deletion on empty embed text");
|
1224
|
+
this.inmediateDeletion = this.isSelectingAll(anchor_node);
|
1225
|
+
if (this.inmediateDeletion) {
|
1226
|
+
this.handleInmediateDeletion($(anchor_node));
|
1227
|
+
}
|
1228
|
+
return false;
|
1229
|
+
}
|
1230
|
+
}
|
1231
|
+
if ($(anchor_node).prev().hasClass("graf--mixtapeEmbed")) {
|
1232
|
+
if (this.isFirstChar() && !_.isEmpty($(anchor_node).text().trim())) {
|
1233
|
+
return false;
|
1234
|
+
}
|
1235
|
+
}
|
1236
|
+
if ($(".is-selected").hasClass("graf--figure") && (anchor_node == null)) {
|
1237
|
+
this.replaceWith("p", $(".is-selected"));
|
1238
|
+
this.setRangeAt($(".is-selected")[0]);
|
1239
|
+
return false;
|
1240
|
+
}
|
1241
|
+
}
|
1242
|
+
if (e.which === 32) {
|
1243
|
+
utils.log("SPACEBAR");
|
1244
|
+
if ($node.hasClass("graf--p")) {
|
1245
|
+
this.handleSmartList($node, e);
|
1246
|
+
}
|
1247
|
+
}
|
1248
|
+
if (_.contains([38, 40], e.which)) {
|
1249
|
+
utils.log(e.which);
|
1250
|
+
this.handleArrowForKeyDown(e);
|
1251
|
+
}
|
1252
|
+
if (anchor_node) {
|
1253
|
+
if (!_.isEmpty($(anchor_node).text())) {
|
1254
|
+
this.tooltip_view.hide();
|
1255
|
+
$(anchor_node).removeClass("graf--empty");
|
1256
|
+
}
|
1257
|
+
}
|
1258
|
+
if (_.isUndefined(anchor_node) && $(".is-selected").hasClass("is-mediaFocused")) {
|
1259
|
+
this.setRangeAt($(".is-selected").find("figcaption")[0]);
|
1260
|
+
$(".is-selected").removeClass("is-mediaFocused");
|
1261
|
+
return false;
|
1262
|
+
}
|
1263
|
+
};
|
1264
|
+
|
1265
|
+
Editor.prototype.handleKeyUp = function(e, node) {
|
1266
|
+
var anchor_node, next_graf, utils_anchor_node;
|
1267
|
+
if (this.skip_keyup) {
|
1268
|
+
this.skip_keyup = null;
|
1269
|
+
utils.log("SKIP KEYUP");
|
1270
|
+
return false;
|
1271
|
+
}
|
1272
|
+
utils.log("KEYUP");
|
1273
|
+
this.editor_menu.hide();
|
1274
|
+
this.reachedTop = false;
|
1275
|
+
anchor_node = this.getNode();
|
1276
|
+
utils_anchor_node = utils.getNode();
|
1277
|
+
this.handleTextSelection(anchor_node);
|
1278
|
+
if (_.contains([8, 32, 13], e.which)) {
|
1279
|
+
if ($(anchor_node).hasClass("graf--li")) {
|
1280
|
+
this.removeSpanTag($(anchor_node));
|
1281
|
+
}
|
1282
|
+
}
|
1283
|
+
if (e.which === 8) {
|
1284
|
+
if ($(utils_anchor_node).hasClass("postField--body")) {
|
1285
|
+
utils.log("ALL GONE from UP");
|
1286
|
+
this.handleCompleteDeletion($(this.el));
|
1287
|
+
if (this.completeDeletion) {
|
1288
|
+
this.completeDeletion = false;
|
1289
|
+
return false;
|
1290
|
+
}
|
1291
|
+
}
|
1292
|
+
if ($(utils_anchor_node).hasClass("section-content") || $(utils_anchor_node).hasClass("graf--first")) {
|
1293
|
+
utils.log("SECTION DETECTED FROM KEYUP " + (_.isEmpty($(utils_anchor_node).text())));
|
1294
|
+
if (_.isEmpty($(utils_anchor_node).text())) {
|
1295
|
+
next_graf = $(utils_anchor_node).next(".graf")[0];
|
1296
|
+
if (next_graf) {
|
1297
|
+
this.setRangeAt(next_graf);
|
1298
|
+
$(utils_anchor_node).remove();
|
1299
|
+
this.setupFirstAndLast();
|
1300
|
+
}
|
1301
|
+
return false;
|
1302
|
+
}
|
1303
|
+
}
|
1304
|
+
if (_.isNull(anchor_node)) {
|
1305
|
+
this.handleNullAnchor();
|
1306
|
+
return false;
|
1307
|
+
}
|
1308
|
+
if ($(anchor_node).hasClass("graf--first")) {
|
1309
|
+
utils.log("THE FIRST ONE! UP");
|
1310
|
+
if (this.getSelectedText() === this.getNode().textContent) {
|
1311
|
+
utils.log("remove selection dectected");
|
1312
|
+
this.getNode().innerHTML = "<br>";
|
1313
|
+
}
|
1314
|
+
this.markAsSelected(anchor_node);
|
1315
|
+
this.setupFirstAndLast();
|
1316
|
+
false;
|
1317
|
+
}
|
1318
|
+
}
|
1319
|
+
if (_.contains([37, 38, 39, 40], e.which)) {
|
1320
|
+
return this.handleArrow(e);
|
1321
|
+
}
|
1322
|
+
};
|
1323
|
+
|
1324
|
+
Editor.prototype.handleLineBreakWith = function(element_type, from_element) {
|
1325
|
+
var new_paragraph;
|
1326
|
+
new_paragraph = $("<" + element_type + " class='graf graf--" + element_type + " graf--empty is-selected'><br/></" + element_type + ">");
|
1327
|
+
if (from_element.parent().is('[class^="graf--"]')) {
|
1328
|
+
new_paragraph.insertAfter(from_element.parent());
|
1329
|
+
} else {
|
1330
|
+
new_paragraph.insertAfter(from_element);
|
1331
|
+
}
|
1332
|
+
this.setRangeAt(new_paragraph[0]);
|
1333
|
+
return this.scrollTo(new_paragraph);
|
1334
|
+
};
|
1335
|
+
|
1336
|
+
Editor.prototype.replaceWith = function(element_type, from_element) {
|
1337
|
+
var new_paragraph;
|
1338
|
+
new_paragraph = $("<" + element_type + " class='graf graf--" + element_type + " graf--empty is-selected'><br/></" + element_type + ">");
|
1339
|
+
from_element.replaceWith(new_paragraph);
|
1340
|
+
this.setRangeAt(new_paragraph[0]);
|
1341
|
+
this.scrollTo(new_paragraph);
|
1342
|
+
return new_paragraph;
|
1343
|
+
};
|
1344
|
+
|
1345
|
+
Editor.prototype.displayTooltipAt = function(element) {
|
1346
|
+
utils.log("POSITION FOR TOOLTIP");
|
1347
|
+
element = $(element);
|
1348
|
+
if (!element || _.isUndefined(element) || _.isEmpty(element) || element[0].tagName === "LI") {
|
1349
|
+
return;
|
1350
|
+
}
|
1351
|
+
this.tooltip_view.hide();
|
1352
|
+
if (!_.isEmpty(element.text())) {
|
1353
|
+
return;
|
1354
|
+
}
|
1355
|
+
this.positions = element.offset();
|
1356
|
+
this.tooltip_view.render();
|
1357
|
+
return this.tooltip_view.move(this.positions);
|
1358
|
+
};
|
1359
|
+
|
1360
|
+
Editor.prototype.markAsSelected = function(element) {
|
1361
|
+
if (_.isUndefined(element)) {
|
1362
|
+
return;
|
1363
|
+
}
|
1364
|
+
$(this.el).find(".is-selected").removeClass("is-mediaFocused is-selected");
|
1365
|
+
$(element).addClass("is-selected");
|
1366
|
+
$(element).find(".defaultValue").remove();
|
1367
|
+
if ($(element).hasClass("graf--first")) {
|
1368
|
+
this.reachedTop = true;
|
1369
|
+
if ($(element).find("br").length === 0) {
|
1370
|
+
return $(element).append("<br>");
|
1371
|
+
}
|
1372
|
+
}
|
1373
|
+
};
|
1374
|
+
|
1375
|
+
Editor.prototype.addClassesToElement = function(element) {
|
1376
|
+
var n, name, new_el;
|
1377
|
+
n = element;
|
1378
|
+
name = n.nodeName.toLowerCase();
|
1379
|
+
switch (name) {
|
1380
|
+
case "p":
|
1381
|
+
case "pre":
|
1382
|
+
case "div":
|
1383
|
+
if (!$(n).hasClass("graf--mixtapeEmbed")) {
|
1384
|
+
$(n).removeClass().addClass("graf graf--" + name);
|
1385
|
+
}
|
1386
|
+
if (name === "p" && $(n).find("br").length === 0) {
|
1387
|
+
$(n).append("<br>");
|
1388
|
+
}
|
1389
|
+
break;
|
1390
|
+
case "h1":
|
1391
|
+
case "h2":
|
1392
|
+
case "h3":
|
1393
|
+
case "h4":
|
1394
|
+
case "h5":
|
1395
|
+
case "h6":
|
1396
|
+
if (name === "h1") {
|
1397
|
+
new_el = $("<h2 class='graf graf--h2'>" + ($(n).text()) + "</h2>");
|
1398
|
+
$(n).replaceWith(new_el);
|
1399
|
+
this.setElementName(n);
|
1400
|
+
} else {
|
1401
|
+
$(n).removeClass().addClass("graf graf--" + name);
|
1402
|
+
}
|
1403
|
+
break;
|
1404
|
+
case "code":
|
1405
|
+
$(n).unwrap().wrap("<p class='graf graf--pre'></p>");
|
1406
|
+
n = $(n).parent();
|
1407
|
+
break;
|
1408
|
+
case "ol":
|
1409
|
+
case "ul":
|
1410
|
+
utils.log("lists");
|
1411
|
+
$(n).removeClass().addClass("postList");
|
1412
|
+
_.each($(n).find("li"), function(li) {
|
1413
|
+
return $(li).removeClass().addClass("graf graf--li");
|
1414
|
+
});
|
1415
|
+
break;
|
1416
|
+
case "img":
|
1417
|
+
utils.log("images");
|
1418
|
+
this.tooltip_view.uploadExistentImage(n);
|
1419
|
+
break;
|
1420
|
+
case "a":
|
1421
|
+
case 'strong':
|
1422
|
+
case 'em':
|
1423
|
+
case 'br':
|
1424
|
+
case 'b':
|
1425
|
+
case 'u':
|
1426
|
+
case 'i':
|
1427
|
+
utils.log("links");
|
1428
|
+
$(n).wrap("<p class='graf graf--p'></p>");
|
1429
|
+
n = $(n).parent();
|
1430
|
+
break;
|
1431
|
+
case "blockquote":
|
1432
|
+
n = $(n).removeClass().addClass("graf graf--" + name);
|
1433
|
+
break;
|
1434
|
+
case "figure":
|
1435
|
+
if ($(n).hasClass(".graf--figure")) {
|
1436
|
+
n = $(n);
|
1437
|
+
}
|
1438
|
+
break;
|
1439
|
+
default:
|
1440
|
+
$(n).wrap("<p class='graf graf--" + name + "'></p>");
|
1441
|
+
n = $(n).parent();
|
1442
|
+
}
|
1443
|
+
return n;
|
1444
|
+
};
|
1445
|
+
|
1446
|
+
Editor.prototype.setupElementsClasses = function(element, cb) {
|
1447
|
+
if (_.isUndefined(element)) {
|
1448
|
+
this.element = $(this.el).find('.section-inner');
|
1449
|
+
} else {
|
1450
|
+
this.element = element;
|
1451
|
+
}
|
1452
|
+
return setTimeout((function(_this) {
|
1453
|
+
return function() {
|
1454
|
+
_this.cleanContents(_this.element);
|
1455
|
+
_this.wrapTextNodes(_this.element);
|
1456
|
+
_.each(_this.element.children(), function(n) {
|
1457
|
+
var name;
|
1458
|
+
name = $(n).prop("tagName").toLowerCase();
|
1459
|
+
n = _this.addClassesToElement(n);
|
1460
|
+
return _this.setElementName(n);
|
1461
|
+
});
|
1462
|
+
_this.setupLinks(_this.element.find("a"));
|
1463
|
+
_this.setupFirstAndLast();
|
1464
|
+
if (_.isFunction(cb)) {
|
1465
|
+
return cb();
|
1466
|
+
}
|
1467
|
+
};
|
1468
|
+
})(this), 20);
|
1469
|
+
};
|
1470
|
+
|
1471
|
+
Editor.prototype.cleanContents = function(element) {
|
1472
|
+
var s;
|
1473
|
+
if (_.isUndefined(element)) {
|
1474
|
+
this.element = $(this.el).find('.section-inner');
|
1475
|
+
} else {
|
1476
|
+
this.element = element;
|
1477
|
+
}
|
1478
|
+
s = new Sanitize({
|
1479
|
+
elements: ['strong', 'img', 'em', 'br', 'a', 'blockquote', 'b', 'u', 'i', 'pre', 'p', 'h1', 'h2', 'h3', 'h4', 'ul', 'ol', 'li'],
|
1480
|
+
attributes: {
|
1481
|
+
'__ALL__': ['class'],
|
1482
|
+
a: ['href', 'title', 'target'],
|
1483
|
+
img: ['src']
|
1484
|
+
},
|
1485
|
+
protocols: {
|
1486
|
+
a: {
|
1487
|
+
href: ['http', 'https', 'mailto']
|
1488
|
+
}
|
1489
|
+
},
|
1490
|
+
transformers: [
|
1491
|
+
function(input) {
|
1492
|
+
if (input.node_name === "span" && $(input.node).hasClass("defaultValue")) {
|
1493
|
+
return {
|
1494
|
+
whitelist_nodes: [input.node]
|
1495
|
+
};
|
1496
|
+
} else {
|
1497
|
+
return null;
|
1498
|
+
}
|
1499
|
+
}, function(input) {
|
1500
|
+
if (input.node_name === 'div' && $(input.node).hasClass("graf--mixtapeEmbed")) {
|
1501
|
+
return {
|
1502
|
+
whitelist_nodes: [input.node]
|
1503
|
+
};
|
1504
|
+
} else if (input.node_name === 'a' && $(input.node).parent(".graf--mixtapeEmbed").exists()) {
|
1505
|
+
return {
|
1506
|
+
attr_whitelist: ["style"]
|
1507
|
+
};
|
1508
|
+
} else {
|
1509
|
+
return null;
|
1510
|
+
}
|
1511
|
+
}, function(input) {
|
1512
|
+
if (input.node_name === 'figure' && $(input.node).hasClass("graf--iframe")) {
|
1513
|
+
return {
|
1514
|
+
whitelist_nodes: [input.node]
|
1515
|
+
};
|
1516
|
+
} else if (input.node_name === 'div' && $(input.node).hasClass("iframeContainer") && $(input.node).parent(".graf--iframe").exists()) {
|
1517
|
+
return {
|
1518
|
+
whitelist_nodes: [input.node]
|
1519
|
+
};
|
1520
|
+
} else if (input.node_name === 'iframe' && $(input.node).parent(".iframeContainer").exists()) {
|
1521
|
+
return {
|
1522
|
+
whitelist_nodes: [input.node]
|
1523
|
+
};
|
1524
|
+
} else if (input.node_name === 'figcaption' && $(input.node).parent(".graf--iframe").exists()) {
|
1525
|
+
return {
|
1526
|
+
whitelist_nodes: [input.node]
|
1527
|
+
};
|
1528
|
+
} else {
|
1529
|
+
return null;
|
1530
|
+
}
|
1531
|
+
}, function(input) {
|
1532
|
+
if (input.node_name === 'figure' && $(input.node).hasClass("graf--figure")) {
|
1533
|
+
return {
|
1534
|
+
whitelist_nodes: [input.node]
|
1535
|
+
};
|
1536
|
+
} else if (input.node_name === 'div' && ($(input.node).hasClass("aspectRatioPlaceholder") && $(input.node).parent(".graf--figure").exists())) {
|
1537
|
+
return {
|
1538
|
+
whitelist_nodes: [input.node]
|
1539
|
+
};
|
1540
|
+
} else if (input.node_name === 'div' && ($(input.node).hasClass("aspect-ratio-fill") && $(input.node).parent(".aspectRatioPlaceholder").exists())) {
|
1541
|
+
return {
|
1542
|
+
whitelist_nodes: [input.node]
|
1543
|
+
};
|
1544
|
+
} else if (input.node_name === 'img' && $(input.node).parent(".graf--figure").exists()) {
|
1545
|
+
return {
|
1546
|
+
whitelist_nodes: [input.node]
|
1547
|
+
};
|
1548
|
+
} else if (input.node_name === 'a' && $(input.node).parent(".graf--mixtapeEmbed").exists()) {
|
1549
|
+
return {
|
1550
|
+
attr_whitelist: ["style"]
|
1551
|
+
};
|
1552
|
+
} else if (input.node_name === 'figcaption' && $(input.node).parent(".graf--figure").exists()) {
|
1553
|
+
return {
|
1554
|
+
whitelist_nodes: [input.node]
|
1555
|
+
};
|
1556
|
+
} else if (input.node_name === 'span' && $(input.node).parent(".imageCaption").exists()) {
|
1557
|
+
return {
|
1558
|
+
whitelist_nodes: [input.node]
|
1559
|
+
};
|
1560
|
+
} else {
|
1561
|
+
return null;
|
1562
|
+
}
|
1563
|
+
}
|
1564
|
+
]
|
1565
|
+
});
|
1566
|
+
if (this.element.exists()) {
|
1567
|
+
utils.log("CLEAN HTML " + this.element[0].tagName);
|
1568
|
+
return this.element.html(s.clean_node(this.element[0]));
|
1569
|
+
}
|
1570
|
+
};
|
1571
|
+
|
1572
|
+
Editor.prototype.setupLinks = function(elems) {
|
1573
|
+
return _.each(elems, (function(_this) {
|
1574
|
+
return function(n) {
|
1575
|
+
return _this.setupLink(n);
|
1576
|
+
};
|
1577
|
+
})(this));
|
1578
|
+
};
|
1579
|
+
|
1580
|
+
Editor.prototype.setupLink = function(n) {
|
1581
|
+
var href, parent_name;
|
1582
|
+
parent_name = $(n).parent().prop("tagName").toLowerCase();
|
1583
|
+
$(n).addClass("markup--anchor markup--" + parent_name + "-anchor");
|
1584
|
+
href = $(n).attr("href");
|
1585
|
+
return $(n).attr("data-href", href);
|
1586
|
+
};
|
1587
|
+
|
1588
|
+
Editor.prototype.preCleanNode = function(element) {
|
1589
|
+
var s;
|
1590
|
+
s = new Sanitize({
|
1591
|
+
elements: ['strong', 'em', 'br', 'a', 'b', 'u', 'i', 'ul', 'ol', 'li'],
|
1592
|
+
attributes: {
|
1593
|
+
a: ['href', 'title', 'target']
|
1594
|
+
},
|
1595
|
+
protocols: {
|
1596
|
+
a: {
|
1597
|
+
href: ['http', 'https', 'mailto']
|
1598
|
+
}
|
1599
|
+
}
|
1600
|
+
});
|
1601
|
+
$(element).html(s.clean_node(element[0]));
|
1602
|
+
element = this.addClassesToElement($(element)[0]);
|
1603
|
+
return $(element);
|
1604
|
+
};
|
1605
|
+
|
1606
|
+
Editor.prototype.setupFirstAndLast = function() {
|
1607
|
+
var childs;
|
1608
|
+
childs = $(this.el).find(".section-inner").children();
|
1609
|
+
childs.removeClass("graf--last , graf--first");
|
1610
|
+
childs.first().addClass("graf--first");
|
1611
|
+
return childs.last().addClass("graf--last");
|
1612
|
+
};
|
1613
|
+
|
1614
|
+
Editor.prototype.wrapTextNodes = function(element) {
|
1615
|
+
if (_.isUndefined(element)) {
|
1616
|
+
element = $(this.el).find('.section-inner');
|
1617
|
+
} else {
|
1618
|
+
element = element;
|
1619
|
+
}
|
1620
|
+
return element.contents().filter(function() {
|
1621
|
+
return this.nodeType === 3 && this.data.trim().length > 0;
|
1622
|
+
}).wrap("<p class='graf grap--p'></p>");
|
1623
|
+
};
|
1624
|
+
|
1625
|
+
Editor.prototype.setElementName = function(element) {
|
1626
|
+
return $(element).attr("name", utils.generateUniqueName());
|
1627
|
+
};
|
1628
|
+
|
1629
|
+
Editor.prototype.listify = function($paragraph, listType, regex) {
|
1630
|
+
var $li, $list, content;
|
1631
|
+
utils.log("LISTIFY PARAGRAPH");
|
1632
|
+
this.removeSpanTag($paragraph);
|
1633
|
+
content = $paragraph.html().replace(/ /g, " ").replace(regex, "");
|
1634
|
+
switch (listType) {
|
1635
|
+
case "ul":
|
1636
|
+
$list = $("<ul></ul>");
|
1637
|
+
break;
|
1638
|
+
case "ol":
|
1639
|
+
$list = $("<ol></ol>");
|
1640
|
+
break;
|
1641
|
+
default:
|
1642
|
+
return false;
|
1643
|
+
}
|
1644
|
+
this.addClassesToElement($list[0]);
|
1645
|
+
this.replaceWith("li", $paragraph);
|
1646
|
+
$li = $(".is-selected");
|
1647
|
+
this.setElementName($li[0]);
|
1648
|
+
$li.html(content).wrap($list);
|
1649
|
+
if ($li.find("br").length === 0) {
|
1650
|
+
$li.append("<br/>");
|
1651
|
+
}
|
1652
|
+
this.setRangeAt($li[0]);
|
1653
|
+
return $li[0];
|
1654
|
+
};
|
1655
|
+
|
1656
|
+
Editor.prototype.handleSmartList = function($item, e) {
|
1657
|
+
var $li, chars, match, regex;
|
1658
|
+
utils.log("HANDLE A SMART LIST");
|
1659
|
+
chars = this.getCharacterPrecedingCaret();
|
1660
|
+
match = chars.match(/^\s*(\-|\*)\s*$/);
|
1661
|
+
if (match) {
|
1662
|
+
utils.log("CREATING LIST ITEM");
|
1663
|
+
e.preventDefault();
|
1664
|
+
regex = new RegExp(/\s*(\-|\*)\s*/);
|
1665
|
+
$li = this.listify($item, "ul", regex);
|
1666
|
+
} else {
|
1667
|
+
match = chars.match(/^\s*1(\.|\))\s*$/);
|
1668
|
+
if (match) {
|
1669
|
+
utils.log("CREATING LIST ITEM");
|
1670
|
+
e.preventDefault();
|
1671
|
+
regex = new RegExp(/\s*1(\.|\))\s*/);
|
1672
|
+
$li = this.listify($item, "ol", regex);
|
1673
|
+
}
|
1674
|
+
}
|
1675
|
+
return $li;
|
1676
|
+
};
|
1677
|
+
|
1678
|
+
Editor.prototype.handleListLineBreak = function($li, e) {
|
1679
|
+
var $list, $paragraph, content;
|
1680
|
+
utils.log("LIST LINE BREAK");
|
1681
|
+
this.tooltip_view.hide();
|
1682
|
+
$list = $li.parent("ol, ul");
|
1683
|
+
$paragraph = $("<p></p>");
|
1684
|
+
utils.log($li.prev());
|
1685
|
+
if ($list.children().length === 1 && $li.text() === "") {
|
1686
|
+
this.replaceWith("p", $list);
|
1687
|
+
} else if ($li.text() === "" && ($li.next().length !== 0)) {
|
1688
|
+
e.preventDefault();
|
1689
|
+
} else if ($li.next().length === 0) {
|
1690
|
+
if ($li.text() === "") {
|
1691
|
+
e.preventDefault();
|
1692
|
+
utils.log("BREAK FROM LIST");
|
1693
|
+
$list.after($paragraph);
|
1694
|
+
$li.addClass("graf--removed").remove();
|
1695
|
+
} else if ($li.prev().length !== 0 && $li.prev().text() === "" && this.getCharacterPrecedingCaret() === "") {
|
1696
|
+
e.preventDefault();
|
1697
|
+
utils.log("PREV IS EMPTY");
|
1698
|
+
content = $li.html();
|
1699
|
+
$list.after($paragraph);
|
1700
|
+
$li.prev().remove();
|
1701
|
+
$li.addClass("graf--removed").remove();
|
1702
|
+
$paragraph.html(content);
|
1703
|
+
}
|
1704
|
+
}
|
1705
|
+
if ($list && $list.children().length === 0) {
|
1706
|
+
$list.remove();
|
1707
|
+
}
|
1708
|
+
utils.log($li);
|
1709
|
+
if ($li.hasClass("graf--removed")) {
|
1710
|
+
utils.log("ELEMENT REMOVED");
|
1711
|
+
this.addClassesToElement($paragraph[0]);
|
1712
|
+
this.setRangeAt($paragraph[0]);
|
1713
|
+
this.markAsSelected($paragraph[0]);
|
1714
|
+
return this.scrollTo($paragraph);
|
1715
|
+
}
|
1716
|
+
};
|
1717
|
+
|
1718
|
+
Editor.prototype.handleListBackspace = function($li, e) {
|
1719
|
+
var $list, $paragraph, content;
|
1720
|
+
$list = $li.parent("ol, ul");
|
1721
|
+
utils.log("LIST BACKSPACE");
|
1722
|
+
if ($li.prev().length === 0) {
|
1723
|
+
e.preventDefault();
|
1724
|
+
$list.before($li);
|
1725
|
+
content = $li.html();
|
1726
|
+
this.replaceWith("p", $li);
|
1727
|
+
$paragraph = $(".is-selected");
|
1728
|
+
$paragraph.removeClass("graf--empty").html(content);
|
1729
|
+
if ($list.children().length === 0) {
|
1730
|
+
$list.remove();
|
1731
|
+
}
|
1732
|
+
return this.setupFirstAndLast();
|
1733
|
+
}
|
1734
|
+
};
|
1735
|
+
|
1736
|
+
Editor.prototype.removeSpanTag = function($item) {
|
1737
|
+
var $spans, span, _i, _len;
|
1738
|
+
$spans = $item.find("span");
|
1739
|
+
for (_i = 0, _len = $spans.length; _i < _len; _i++) {
|
1740
|
+
span = $spans[_i];
|
1741
|
+
if (!$(span).hasClass("defaultValue")) {
|
1742
|
+
$(span).replaceWith($(span).html());
|
1743
|
+
}
|
1744
|
+
}
|
1745
|
+
return $item;
|
1746
|
+
};
|
1747
|
+
|
1748
|
+
return Editor;
|
1749
|
+
|
1750
|
+
})(Dante.View);
|
1751
|
+
|
1752
|
+
}).call(this);
|
1753
|
+
(function() {
|
1754
|
+
var utils,
|
1755
|
+
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
1756
|
+
__hasProp = {}.hasOwnProperty,
|
1757
|
+
__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; };
|
1758
|
+
|
1759
|
+
utils = Dante.utils;
|
1760
|
+
|
1761
|
+
Dante.Editor.Tooltip = (function(_super) {
|
1762
|
+
__extends(Tooltip, _super);
|
1763
|
+
|
1764
|
+
function Tooltip() {
|
1765
|
+
this.hide = __bind(this.hide, this);
|
1766
|
+
this.getExtract = __bind(this.getExtract, this);
|
1767
|
+
this.getExtractFromNode = __bind(this.getExtractFromNode, this);
|
1768
|
+
this.getEmbedFromNode = __bind(this.getEmbedFromNode, this);
|
1769
|
+
this.uploadCompleted = __bind(this.uploadCompleted, this);
|
1770
|
+
this.updateProgressBar = __bind(this.updateProgressBar, this);
|
1771
|
+
this.uploadFile = __bind(this.uploadFile, this);
|
1772
|
+
this.uploadFiles = __bind(this.uploadFiles, this);
|
1773
|
+
this.toggleOptions = __bind(this.toggleOptions, this);
|
1774
|
+
this.render = __bind(this.render, this);
|
1775
|
+
this.initialize = __bind(this.initialize, this);
|
1776
|
+
return Tooltip.__super__.constructor.apply(this, arguments);
|
1777
|
+
}
|
1778
|
+
|
1779
|
+
Tooltip.prototype.el = ".inlineTooltip";
|
1780
|
+
|
1781
|
+
Tooltip.prototype.events = {
|
1782
|
+
"click .inlineTooltip-button.control": "toggleOptions",
|
1783
|
+
"click .inlineTooltip-menu button": "handleClick"
|
1784
|
+
};
|
1785
|
+
|
1786
|
+
Tooltip.prototype.initialize = function(opts) {
|
1787
|
+
if (opts == null) {
|
1788
|
+
opts = {};
|
1789
|
+
}
|
1790
|
+
this.current_editor = opts.editor;
|
1791
|
+
return this.buttons = [
|
1792
|
+
{
|
1793
|
+
icon: "icon-image",
|
1794
|
+
title: "Add an image",
|
1795
|
+
action: "image"
|
1796
|
+
}, {
|
1797
|
+
icon: "icon-video",
|
1798
|
+
title: "Add a video",
|
1799
|
+
action: "embed"
|
1800
|
+
}, {
|
1801
|
+
icon: "icon-embed",
|
1802
|
+
title: "Add an embed",
|
1803
|
+
action: "embed-extract"
|
1804
|
+
}
|
1805
|
+
];
|
1806
|
+
};
|
1807
|
+
|
1808
|
+
Tooltip.prototype.template = function() {
|
1809
|
+
var menu;
|
1810
|
+
menu = "";
|
1811
|
+
_.each(this.buttons, function(b) {
|
1812
|
+
var data_action_value;
|
1813
|
+
data_action_value = b.action_value ? "data-action-value='" + b.action_value + "'" : "";
|
1814
|
+
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>";
|
1815
|
+
});
|
1816
|
+
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>";
|
1817
|
+
};
|
1818
|
+
|
1819
|
+
Tooltip.prototype.insertTemplate = function() {
|
1820
|
+
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>";
|
1821
|
+
};
|
1822
|
+
|
1823
|
+
Tooltip.prototype.extractTemplate = function() {
|
1824
|
+
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>";
|
1825
|
+
};
|
1826
|
+
|
1827
|
+
Tooltip.prototype.embedTemplate = function() {
|
1828
|
+
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>";
|
1829
|
+
};
|
1830
|
+
|
1831
|
+
Tooltip.prototype.render = function() {
|
1832
|
+
$(this.el).html(this.template());
|
1833
|
+
$(this.el).addClass("is-active");
|
1834
|
+
return this;
|
1835
|
+
};
|
1836
|
+
|
1837
|
+
Tooltip.prototype.toggleOptions = function() {
|
1838
|
+
utils.log("Toggle Options!!");
|
1839
|
+
$(this.el).toggleClass("is-scaled");
|
1840
|
+
return false;
|
1841
|
+
};
|
1842
|
+
|
1843
|
+
Tooltip.prototype.move = function(coords) {
|
1844
|
+
var control_spacing, control_width, coord_left, coord_top, pull_size, tooltip;
|
1845
|
+
tooltip = $(this.el);
|
1846
|
+
control_width = tooltip.find(".control").css("width");
|
1847
|
+
control_spacing = tooltip.find(".inlineTooltip-menu").css("padding-left");
|
1848
|
+
pull_size = parseInt(control_width.replace(/px/, "")) + parseInt(control_spacing.replace(/px/, ""));
|
1849
|
+
coord_left = coords.left - pull_size;
|
1850
|
+
coord_top = coords.top;
|
1851
|
+
return $(this.el).offset({
|
1852
|
+
top: coord_top,
|
1853
|
+
left: coord_left
|
1854
|
+
});
|
1855
|
+
};
|
1856
|
+
|
1857
|
+
Tooltip.prototype.handleClick = function(ev) {
|
1858
|
+
var name;
|
1859
|
+
name = $(ev.currentTarget).data('action');
|
1860
|
+
utils.log(name);
|
1861
|
+
switch (name) {
|
1862
|
+
case "inline-menu-image":
|
1863
|
+
this.placeholder = "<p>PLACEHOLDER</p>";
|
1864
|
+
this.imageSelect(ev);
|
1865
|
+
break;
|
1866
|
+
case "inline-menu-embed":
|
1867
|
+
this.displayEmbedPlaceHolder();
|
1868
|
+
break;
|
1869
|
+
case "inline-menu-embed-extract":
|
1870
|
+
this.displayExtractPlaceHolder();
|
1871
|
+
break;
|
1872
|
+
case "inline-menu-hr":
|
1873
|
+
this.splitSection();
|
1874
|
+
}
|
1875
|
+
return false;
|
1876
|
+
};
|
1877
|
+
|
1878
|
+
Tooltip.prototype.uploadExistentImage = function(image_element, opts) {
|
1879
|
+
var i, img, n, node, tmpl, _i, _ref;
|
1880
|
+
if (opts == null) {
|
1881
|
+
opts = {};
|
1882
|
+
}
|
1883
|
+
utils.log("process image here!");
|
1884
|
+
tmpl = $(this.insertTemplate());
|
1885
|
+
tmpl.find("img").attr('src', this.current_editor.default_loading_placeholder);
|
1886
|
+
if ($(image_element).parents(".graf").length > 0) {
|
1887
|
+
if ($(image_element).parents(".graf").hasClass("graf--figure")) {
|
1888
|
+
return;
|
1889
|
+
}
|
1890
|
+
utils.log("UNO");
|
1891
|
+
tmpl.insertBefore($(image_element).parents(".graf"));
|
1892
|
+
node = this.current_editor.getNode();
|
1893
|
+
if (node) {
|
1894
|
+
this.current_editor.preCleanNode($(node));
|
1895
|
+
this.current_editor.addClassesToElement(node);
|
1896
|
+
}
|
1897
|
+
} else {
|
1898
|
+
utils.log("DOS");
|
1899
|
+
img = $(image_element).parentsUntil(".section-inner").first();
|
1900
|
+
$(img).replaceWith(tmpl);
|
1901
|
+
}
|
1902
|
+
utils.log($("[name='" + (tmpl.attr('name')) + "']").attr("name"));
|
1903
|
+
this.replaceImg(image_element, $("[name='" + (tmpl.attr('name')) + "']"));
|
1904
|
+
n = $("[name='" + (tmpl.attr('name')) + "']").parentsUntil(".section-inner").length;
|
1905
|
+
if (n !== 0) {
|
1906
|
+
for (i = _i = 0, _ref = n - 1; _i <= _ref; i = _i += 1) {
|
1907
|
+
$("[name='" + (tmpl.attr('name')) + "']").unwrap();
|
1908
|
+
}
|
1909
|
+
}
|
1910
|
+
return utils.log("FIG");
|
1911
|
+
};
|
1912
|
+
|
1913
|
+
Tooltip.prototype.replaceImg = function(image_element, figure) {
|
1914
|
+
var img, self;
|
1915
|
+
utils.log(figure.attr("name"));
|
1916
|
+
utils.log(figure);
|
1917
|
+
$(image_element).remove();
|
1918
|
+
img = new Image();
|
1919
|
+
img.src = image_element.src;
|
1920
|
+
self = this;
|
1921
|
+
return img.onload = function() {
|
1922
|
+
var ar;
|
1923
|
+
utils.log("replace image with loaded info");
|
1924
|
+
utils.log(figure.attr("name"));
|
1925
|
+
utils.log(this.width + 'x' + this.height);
|
1926
|
+
ar = self.getAspectRatio(this.width, this.height);
|
1927
|
+
figure.find(".aspectRatioPlaceholder").css({
|
1928
|
+
'max-width': ar.width,
|
1929
|
+
'max-height': ar.height
|
1930
|
+
});
|
1931
|
+
figure.find(".graf-image").attr({
|
1932
|
+
"data-height": this.height,
|
1933
|
+
"data-width": this.width
|
1934
|
+
});
|
1935
|
+
figure.find(".aspect-ratio-fill").css({
|
1936
|
+
"padding-bottom": "" + ar.ratio + "%"
|
1937
|
+
});
|
1938
|
+
return figure.find("img").attr("src", image_element.src);
|
1939
|
+
};
|
1940
|
+
};
|
1941
|
+
|
1942
|
+
Tooltip.prototype.displayAndUploadImages = function(file) {
|
1943
|
+
return this.displayCachedImage(file);
|
1944
|
+
};
|
1945
|
+
|
1946
|
+
Tooltip.prototype.imageSelect = function(ev) {
|
1947
|
+
var $selectFile, self;
|
1948
|
+
$selectFile = $('<input type="file" multiple="multiple">').click();
|
1949
|
+
self = this;
|
1950
|
+
return $selectFile.change(function() {
|
1951
|
+
var t;
|
1952
|
+
t = this;
|
1953
|
+
return self.uploadFiles(t.files);
|
1954
|
+
});
|
1955
|
+
};
|
1956
|
+
|
1957
|
+
Tooltip.prototype.displayCachedImage = function(file) {
|
1958
|
+
var reader;
|
1959
|
+
this.current_editor.tooltip_view.hide();
|
1960
|
+
reader = new FileReader();
|
1961
|
+
reader.onload = (function(_this) {
|
1962
|
+
return function(e) {
|
1963
|
+
var img, node, self;
|
1964
|
+
img = new Image;
|
1965
|
+
img.src = e.target.result;
|
1966
|
+
node = _this.current_editor.getNode();
|
1967
|
+
self = _this;
|
1968
|
+
return img.onload = function() {
|
1969
|
+
var ar, img_tag, new_tmpl, replaced_node;
|
1970
|
+
new_tmpl = $(self.insertTemplate());
|
1971
|
+
replaced_node = $(new_tmpl).insertBefore($(node));
|
1972
|
+
img_tag = new_tmpl.find('img.graf-image').attr('src', e.target.result);
|
1973
|
+
img_tag.height = this.height;
|
1974
|
+
img_tag.width = this.width;
|
1975
|
+
utils.log("UPLOADED SHOW FROM CACHE");
|
1976
|
+
ar = self.getAspectRatio(this.width, this.height);
|
1977
|
+
replaced_node.find(".aspectRatioPlaceholder").css({
|
1978
|
+
'max-width': ar.width,
|
1979
|
+
'max-height': ar.height
|
1980
|
+
});
|
1981
|
+
replaced_node.find(".graf-image").attr({
|
1982
|
+
"data-height": this.height,
|
1983
|
+
"data-width": this.width
|
1984
|
+
});
|
1985
|
+
replaced_node.find(".aspect-ratio-fill").css({
|
1986
|
+
"padding-bottom": "" + ar.ratio + "%"
|
1987
|
+
});
|
1988
|
+
return self.uploadFile(file, replaced_node);
|
1989
|
+
};
|
1990
|
+
};
|
1991
|
+
})(this);
|
1992
|
+
return reader.readAsDataURL(file);
|
1993
|
+
};
|
1994
|
+
|
1995
|
+
Tooltip.prototype.getAspectRatio = function(w, h) {
|
1996
|
+
var fill_ratio, height, maxHeight, maxWidth, ratio, result, width;
|
1997
|
+
maxWidth = 700;
|
1998
|
+
maxHeight = 700;
|
1999
|
+
ratio = 0;
|
2000
|
+
width = w;
|
2001
|
+
height = h;
|
2002
|
+
if (width > maxWidth) {
|
2003
|
+
ratio = maxWidth / width;
|
2004
|
+
height = height * ratio;
|
2005
|
+
width = width * ratio;
|
2006
|
+
} else if (height > maxHeight) {
|
2007
|
+
ratio = maxHeight / height;
|
2008
|
+
width = width * ratio;
|
2009
|
+
height = height * ratio;
|
2010
|
+
}
|
2011
|
+
fill_ratio = height / width * 100;
|
2012
|
+
result = {
|
2013
|
+
width: width,
|
2014
|
+
height: height,
|
2015
|
+
ratio: fill_ratio
|
2016
|
+
};
|
2017
|
+
utils.log(result);
|
2018
|
+
return result;
|
2019
|
+
};
|
2020
|
+
|
2021
|
+
Tooltip.prototype.formatData = function(file) {
|
2022
|
+
var formData;
|
2023
|
+
formData = new FormData();
|
2024
|
+
formData.append('file', file);
|
2025
|
+
return formData;
|
2026
|
+
};
|
2027
|
+
|
2028
|
+
Tooltip.prototype.uploadFiles = function(files) {
|
2029
|
+
var acceptedTypes, file, i, _results;
|
2030
|
+
acceptedTypes = {
|
2031
|
+
"image/png": true,
|
2032
|
+
"image/jpeg": true,
|
2033
|
+
"image/gif": true
|
2034
|
+
};
|
2035
|
+
i = 0;
|
2036
|
+
_results = [];
|
2037
|
+
while (i < files.length) {
|
2038
|
+
file = files[i];
|
2039
|
+
if (acceptedTypes[file.type] === true) {
|
2040
|
+
$(this.placeholder).append("<progress class=\"progress\" min=\"0\" max=\"100\" value=\"0\">0</progress>");
|
2041
|
+
this.displayAndUploadImages(file);
|
2042
|
+
}
|
2043
|
+
_results.push(i++);
|
2044
|
+
}
|
2045
|
+
return _results;
|
2046
|
+
};
|
2047
|
+
|
2048
|
+
Tooltip.prototype.uploadFile = function(file, node) {
|
2049
|
+
var handleUp, n;
|
2050
|
+
n = node;
|
2051
|
+
handleUp = (function(_this) {
|
2052
|
+
return function(jqxhr) {
|
2053
|
+
return _this.uploadCompleted(jqxhr, n);
|
2054
|
+
};
|
2055
|
+
})(this);
|
2056
|
+
return $.ajax({
|
2057
|
+
type: "post",
|
2058
|
+
url: this.current_editor.upload_url,
|
2059
|
+
xhr: (function(_this) {
|
2060
|
+
return function() {
|
2061
|
+
var xhr;
|
2062
|
+
xhr = new XMLHttpRequest();
|
2063
|
+
xhr.upload.onprogress = _this.updateProgressBar;
|
2064
|
+
return xhr;
|
2065
|
+
};
|
2066
|
+
})(this),
|
2067
|
+
cache: false,
|
2068
|
+
contentType: false,
|
2069
|
+
success: (function(_this) {
|
2070
|
+
return function(response) {
|
2071
|
+
if (_this.current_editor.upload_callback) {
|
2072
|
+
response = _this.current_editor.upload_callback(response);
|
2073
|
+
}
|
2074
|
+
handleUp(response);
|
2075
|
+
};
|
2076
|
+
})(this),
|
2077
|
+
error: (function(_this) {
|
2078
|
+
return function(jqxhr) {
|
2079
|
+
return utils.log("ERROR: got error uploading file " + jqxhr.responseText);
|
2080
|
+
};
|
2081
|
+
})(this),
|
2082
|
+
processData: false,
|
2083
|
+
data: this.formatData(file)
|
2084
|
+
});
|
2085
|
+
};
|
2086
|
+
|
2087
|
+
Tooltip.prototype.updateProgressBar = function(e) {
|
2088
|
+
var $progress, complete;
|
2089
|
+
$progress = $('.progress:first', this.$el);
|
2090
|
+
complete = "";
|
2091
|
+
if (e.lengthComputable) {
|
2092
|
+
complete = e.loaded / e.total * 100;
|
2093
|
+
complete = complete != null ? complete : {
|
2094
|
+
complete: 0
|
2095
|
+
};
|
2096
|
+
utils.log("complete");
|
2097
|
+
return utils.log(complete);
|
2098
|
+
}
|
2099
|
+
};
|
2100
|
+
|
2101
|
+
Tooltip.prototype.uploadCompleted = function(url, node) {
|
2102
|
+
return node.find("img").attr("src", url);
|
2103
|
+
};
|
2104
|
+
|
2105
|
+
Tooltip.prototype.displayEmbedPlaceHolder = function() {
|
2106
|
+
var ph;
|
2107
|
+
ph = this.current_editor.embed_placeholder;
|
2108
|
+
this.node = this.current_editor.getNode();
|
2109
|
+
$(this.node).html(ph).addClass("is-embedable");
|
2110
|
+
this.current_editor.setRangeAt(this.node);
|
2111
|
+
this.hide();
|
2112
|
+
return false;
|
2113
|
+
};
|
2114
|
+
|
2115
|
+
Tooltip.prototype.getEmbedFromNode = function(node) {
|
2116
|
+
this.node = $(node);
|
2117
|
+
this.node_name = this.node.attr("name");
|
2118
|
+
this.node.addClass("spinner");
|
2119
|
+
return $.getJSON("" + this.current_editor.oembed_url + ($(this.node).text())).success((function(_this) {
|
2120
|
+
return function(data) {
|
2121
|
+
var iframe_src, replaced_node, tmpl, url;
|
2122
|
+
_this.node = $("[name=" + _this.node_name + "]");
|
2123
|
+
iframe_src = $(data.html).prop("src");
|
2124
|
+
tmpl = $(_this.embedTemplate());
|
2125
|
+
tmpl.attr("name", _this.node.attr("name"));
|
2126
|
+
$(_this.node).replaceWith(tmpl);
|
2127
|
+
replaced_node = $(".graf--iframe[name=" + (_this.node.attr("name")) + "]");
|
2128
|
+
replaced_node.find("iframe").attr("src", iframe_src);
|
2129
|
+
url = data.url || data.author_url;
|
2130
|
+
utils.log("URL IS " + url);
|
2131
|
+
replaced_node.find(".markup--anchor").attr("href", url).text(url);
|
2132
|
+
return _this.hide();
|
2133
|
+
};
|
2134
|
+
})(this));
|
2135
|
+
};
|
2136
|
+
|
2137
|
+
Tooltip.prototype.displayExtractPlaceHolder = function() {
|
2138
|
+
var ph;
|
2139
|
+
ph = this.current_editor.extract_placeholder;
|
2140
|
+
this.node = this.current_editor.getNode();
|
2141
|
+
$(this.node).html(ph).addClass("is-extractable");
|
2142
|
+
this.current_editor.setRangeAt(this.node);
|
2143
|
+
this.hide();
|
2144
|
+
return false;
|
2145
|
+
};
|
2146
|
+
|
2147
|
+
Tooltip.prototype.getExtractFromNode = function(node) {
|
2148
|
+
this.node = $(node);
|
2149
|
+
this.node_name = this.node.attr("name");
|
2150
|
+
this.node.addClass("spinner");
|
2151
|
+
return $.getJSON("" + this.current_editor.extract_url + ($(this.node).text())).success((function(_this) {
|
2152
|
+
return function(data) {
|
2153
|
+
var iframe_src, image_node, replaced_node, tmpl;
|
2154
|
+
_this.node = $("[name=" + _this.node_name + "]");
|
2155
|
+
iframe_src = $(data.html).prop("src");
|
2156
|
+
tmpl = $(_this.extractTemplate());
|
2157
|
+
tmpl.attr("name", _this.node.attr("name"));
|
2158
|
+
$(_this.node).replaceWith(tmpl);
|
2159
|
+
replaced_node = $(".graf--mixtapeEmbed[name=" + (_this.node.attr("name")) + "]");
|
2160
|
+
replaced_node.find("strong").text(data.title);
|
2161
|
+
replaced_node.find("em").text(data.description);
|
2162
|
+
replaced_node.append(data.provider_url);
|
2163
|
+
replaced_node.find(".markup--anchor").attr("href", data.url);
|
2164
|
+
if (!_.isEmpty(data.images)) {
|
2165
|
+
image_node = replaced_node.find(".mixtapeImage");
|
2166
|
+
image_node.css("background-image", "url(" + data.images[0].url + ")");
|
2167
|
+
image_node.removeClass("mixtapeImage--empty u-ignoreBlock");
|
2168
|
+
}
|
2169
|
+
return _this.hide();
|
2170
|
+
};
|
2171
|
+
})(this));
|
2172
|
+
};
|
2173
|
+
|
2174
|
+
Tooltip.prototype.getExtract = function(url) {
|
2175
|
+
return $.getJSON("" + this.current_editor.extract_url + url).done(function(data) {
|
2176
|
+
return utils.log(data);
|
2177
|
+
});
|
2178
|
+
};
|
2179
|
+
|
2180
|
+
Tooltip.prototype.cleanOperationClasses = function(node) {
|
2181
|
+
return node.removeClass("is-embedable is-extractable");
|
2182
|
+
};
|
2183
|
+
|
2184
|
+
Tooltip.prototype.hide = function() {
|
2185
|
+
return $(this.el).removeClass("is-active is-scaled");
|
2186
|
+
};
|
2187
|
+
|
2188
|
+
return Tooltip;
|
2189
|
+
|
2190
|
+
})(Dante.View);
|
2191
|
+
|
2192
|
+
}).call(this);
|
2193
|
+
(function() {
|
2194
|
+
var utils,
|
2195
|
+
__hasProp = {}.hasOwnProperty,
|
2196
|
+
__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; };
|
2197
|
+
|
2198
|
+
utils = Dante.utils;
|
2199
|
+
|
2200
|
+
Dante.Editor.PopOver = (function(_super) {
|
2201
|
+
__extends(PopOver, _super);
|
2202
|
+
|
2203
|
+
function PopOver() {
|
2204
|
+
return PopOver.__super__.constructor.apply(this, arguments);
|
2205
|
+
}
|
2206
|
+
|
2207
|
+
PopOver.prototype.el = "body";
|
2208
|
+
|
2209
|
+
PopOver.prototype.events = {
|
2210
|
+
"mouseover .popover": "cancelHide",
|
2211
|
+
"mouseout .popover": "hide"
|
2212
|
+
};
|
2213
|
+
|
2214
|
+
PopOver.prototype.initialize = function(opts) {
|
2215
|
+
if (opts == null) {
|
2216
|
+
opts = {};
|
2217
|
+
}
|
2218
|
+
utils.log("initialized popover");
|
2219
|
+
this.editor = opts.editor;
|
2220
|
+
this.hideTimeout;
|
2221
|
+
return this.settings = {
|
2222
|
+
timeout: 300
|
2223
|
+
};
|
2224
|
+
};
|
2225
|
+
|
2226
|
+
PopOver.prototype.template = function() {
|
2227
|
+
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>";
|
2228
|
+
};
|
2229
|
+
|
2230
|
+
PopOver.prototype.positionAt = function(ev) {
|
2231
|
+
var left_value, popover_width, target, target_height, target_offset, target_positions, target_width, top_value;
|
2232
|
+
target = $(ev.currentTarget);
|
2233
|
+
target_positions = this.resolveTargetPosition(target);
|
2234
|
+
target_offset = target.offset();
|
2235
|
+
target_width = target.outerWidth();
|
2236
|
+
target_height = target.outerHeight();
|
2237
|
+
popover_width = $(this.el).find(".popover").outerWidth();
|
2238
|
+
top_value = target_positions.top + target_height;
|
2239
|
+
left_value = target_offset.left + (target_width / 2) - (popover_width / 2);
|
2240
|
+
$(this.el).find(".popover").css("top", top_value).css("left", left_value).show();
|
2241
|
+
return this.handleDirection(target);
|
2242
|
+
};
|
2243
|
+
|
2244
|
+
PopOver.prototype.displayAt = function(ev) {
|
2245
|
+
var target;
|
2246
|
+
this.cancelHide();
|
2247
|
+
target = $(ev.currentTarget);
|
2248
|
+
$(this.el).find(".popover-inner a").text(target.attr('href')).attr('href', target.attr("href"));
|
2249
|
+
this.positionAt(ev);
|
2250
|
+
$(this.el).find(".popover--tooltip").css("pointer-events", "auto");
|
2251
|
+
return $(this.el).show();
|
2252
|
+
};
|
2253
|
+
|
2254
|
+
PopOver.prototype.cancelHide = function() {
|
2255
|
+
utils.log("Cancel Hide");
|
2256
|
+
return clearTimeout(this.hideTimeout);
|
2257
|
+
};
|
2258
|
+
|
2259
|
+
PopOver.prototype.hide = function(ev) {
|
2260
|
+
this.cancelHide();
|
2261
|
+
return this.hideTimeout = setTimeout((function(_this) {
|
2262
|
+
return function() {
|
2263
|
+
return $(_this.el).find(".popover").hide();
|
2264
|
+
};
|
2265
|
+
})(this), this.settings.timeout);
|
2266
|
+
};
|
2267
|
+
|
2268
|
+
PopOver.prototype.resolveTargetPosition = function(target) {
|
2269
|
+
if (target.parents(".graf--mixtapeEmbed").exists()) {
|
2270
|
+
return target.parents(".graf--mixtapeEmbed").position();
|
2271
|
+
} else {
|
2272
|
+
return target.position();
|
2273
|
+
}
|
2274
|
+
};
|
2275
|
+
|
2276
|
+
PopOver.prototype.handleDirection = function(target) {
|
2277
|
+
if (target.parents(".graf--mixtapeEmbed").exists()) {
|
2278
|
+
return $(this.el).find(".popover").removeClass("popover--bottom").addClass("popover--top");
|
2279
|
+
} else {
|
2280
|
+
return $(this.el).find(".popover").removeClass("popover--top").addClass("popover--bottom");
|
2281
|
+
}
|
2282
|
+
};
|
2283
|
+
|
2284
|
+
PopOver.prototype.render = function() {
|
2285
|
+
return $(this.template()).insertAfter(this.editor.$el);
|
2286
|
+
};
|
2287
|
+
|
2288
|
+
return PopOver;
|
2289
|
+
|
2290
|
+
})(Dante.View);
|
2291
|
+
|
2292
|
+
}).call(this);
|
2293
|
+
(function() {
|
2294
|
+
var utils,
|
2295
|
+
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
2296
|
+
__hasProp = {}.hasOwnProperty,
|
2297
|
+
__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; };
|
2298
|
+
|
2299
|
+
utils = Dante.utils;
|
2300
|
+
|
2301
|
+
Dante.Editor.Menu = (function(_super) {
|
2302
|
+
__extends(Menu, _super);
|
2303
|
+
|
2304
|
+
function Menu() {
|
2305
|
+
this.createlink = __bind(this.createlink, this);
|
2306
|
+
this.handleInputEnter = __bind(this.handleInputEnter, this);
|
2307
|
+
this.render = __bind(this.render, this);
|
2308
|
+
this.template = __bind(this.template, this);
|
2309
|
+
this.initialize = __bind(this.initialize, this);
|
2310
|
+
return Menu.__super__.constructor.apply(this, arguments);
|
2311
|
+
}
|
2312
|
+
|
2313
|
+
Menu.prototype.el = "#dante-menu";
|
2314
|
+
|
2315
|
+
Menu.prototype.events = {
|
2316
|
+
"mousedown li": "handleClick",
|
2317
|
+
"click .dante-menu-linkinput .dante-menu-button": "closeInput",
|
2318
|
+
"keypress input": "handleInputEnter"
|
2319
|
+
};
|
2320
|
+
|
2321
|
+
Menu.prototype.initialize = function(opts) {
|
2322
|
+
if (opts == null) {
|
2323
|
+
opts = {};
|
2324
|
+
}
|
2325
|
+
this.config = opts.buttons || this.default_config();
|
2326
|
+
this.current_editor = opts.editor;
|
2327
|
+
this.commandsReg = {
|
2328
|
+
block: /^(?:p|h[1-6]|blockquote|pre)$/,
|
2329
|
+
inline: /^(?:bold|italic|underline|insertorderedlist|insertunorderedlist|indent|outdent)$/,
|
2330
|
+
source: /^(?:insertimage|createlink|unlink)$/,
|
2331
|
+
insert: /^(?:inserthorizontalrule|insert)$/,
|
2332
|
+
wrap: /^(?:code)$/
|
2333
|
+
};
|
2334
|
+
this.lineBreakReg = /^(?:blockquote|pre|div|p)$/i;
|
2335
|
+
this.effectNodeReg = /(?:[pubia]|h[1-6]|blockquote|[uo]l|li)/i;
|
2336
|
+
return this.strReg = {
|
2337
|
+
whiteSpace: /(^\s+)|(\s+$)/g,
|
2338
|
+
mailTo: /^(?!mailto:|.+\/|.+#|.+\?)(.*@.*\..+)$/,
|
2339
|
+
http: /^(?!\w+?:\/\/|mailto:|\/|\.\/|\?|#)(.*)$/
|
2340
|
+
};
|
2341
|
+
};
|
2342
|
+
|
2343
|
+
Menu.prototype.default_config = function() {
|
2344
|
+
return {
|
2345
|
+
|
2346
|
+
/*
|
2347
|
+
buttons: [
|
2348
|
+
'blockquote', 'h2', 'h3', 'p', 'code', 'insertorderedlist', 'insertunorderedlist', 'inserthorizontalrule',
|
2349
|
+
'indent', 'outdent', 'bold', 'italic', 'underline', 'createlink'
|
2350
|
+
]
|
2351
|
+
*/
|
2352
|
+
buttons: ['bold', 'italic', 'h2', 'h3', 'h4', 'blockquote', 'createlink']
|
2353
|
+
};
|
2354
|
+
};
|
2355
|
+
|
2356
|
+
Menu.prototype.template = function() {
|
2357
|
+
var html;
|
2358
|
+
html = "<div class='dante-menu-linkinput'><input class='dante-menu-input' placeholder='http://'><div class='dante-menu-button'>x</div></div>";
|
2359
|
+
html += "<ul class='dante-menu-buttons'>";
|
2360
|
+
_.each(this.config.buttons, function(item) {
|
2361
|
+
return html += "<li class='dante-menu-button'><i class=\"dante-icon icon-" + item + "\" data-action=\"" + item + "\"></i></li>";
|
2362
|
+
});
|
2363
|
+
html += "</ul>";
|
2364
|
+
return html;
|
2365
|
+
};
|
2366
|
+
|
2367
|
+
Menu.prototype.render = function() {
|
2368
|
+
$(this.el).html(this.template());
|
2369
|
+
return this.show();
|
2370
|
+
};
|
2371
|
+
|
2372
|
+
Menu.prototype.handleClick = function(ev) {
|
2373
|
+
var action, element, input;
|
2374
|
+
element = $(ev.currentTarget).find('.dante-icon');
|
2375
|
+
action = element.data("action");
|
2376
|
+
input = $(this.el).find("input.dante-menu-input");
|
2377
|
+
utils.log("menu " + action + " item clicked!");
|
2378
|
+
this.savedSel = utils.saveSelection();
|
2379
|
+
if (/(?:createlink)/.test(action)) {
|
2380
|
+
if ($(ev.currentTarget).hasClass("active")) {
|
2381
|
+
this.removeLink();
|
2382
|
+
} else {
|
2383
|
+
$(this.el).addClass("dante-menu--linkmode");
|
2384
|
+
input.focus();
|
2385
|
+
}
|
2386
|
+
} else {
|
2387
|
+
this.menuApply(action);
|
2388
|
+
}
|
2389
|
+
return false;
|
2390
|
+
};
|
2391
|
+
|
2392
|
+
Menu.prototype.closeInput = function(e) {
|
2393
|
+
$(this.el).removeClass("dante-menu--linkmode");
|
2394
|
+
return false;
|
2395
|
+
};
|
2396
|
+
|
2397
|
+
Menu.prototype.handleInputEnter = function(e) {
|
2398
|
+
if (e.which === 13) {
|
2399
|
+
utils.restoreSelection(this.savedSel);
|
2400
|
+
return this.createlink($(e.target));
|
2401
|
+
}
|
2402
|
+
};
|
2403
|
+
|
2404
|
+
Menu.prototype.removeLink = function() {
|
2405
|
+
var elem;
|
2406
|
+
this.menuApply("unlink");
|
2407
|
+
elem = this.current_editor.getNode();
|
2408
|
+
return this.current_editor.cleanContents($(elem));
|
2409
|
+
};
|
2410
|
+
|
2411
|
+
Menu.prototype.createlink = function(input) {
|
2412
|
+
var action, inputValue;
|
2413
|
+
$(this.el).removeClass("dante-menu--linkmode");
|
2414
|
+
if (input.val()) {
|
2415
|
+
inputValue = input.val().replace(this.strReg.whiteSpace, "").replace(this.strReg.mailTo, "mailto:$1").replace(this.strReg.http, "http://$1");
|
2416
|
+
return this.menuApply("createlink", inputValue);
|
2417
|
+
}
|
2418
|
+
action = "unlink";
|
2419
|
+
return this.menuApply(action);
|
2420
|
+
};
|
2421
|
+
|
2422
|
+
Menu.prototype.menuApply = function(action, value) {
|
2423
|
+
if (this.commandsReg.block.test(action)) {
|
2424
|
+
utils.log("block here");
|
2425
|
+
this.commandBlock(action);
|
2426
|
+
} else if (this.commandsReg.inline.test(action) || this.commandsReg.source.test(action)) {
|
2427
|
+
utils.log("overall here");
|
2428
|
+
this.commandOverall(action, value);
|
2429
|
+
} else if (this.commandsReg.insert.test(action)) {
|
2430
|
+
utils.log("insert here");
|
2431
|
+
this.commandInsert(action);
|
2432
|
+
} else if (this.commandsReg.wrap.test(action)) {
|
2433
|
+
utils.log("wrap here");
|
2434
|
+
this.commandWrap(action);
|
2435
|
+
} else {
|
2436
|
+
utils.log("can't find command function for action: " + action);
|
2437
|
+
}
|
2438
|
+
return false;
|
2439
|
+
};
|
2440
|
+
|
2441
|
+
Menu.prototype.setupInsertedElement = function(element) {
|
2442
|
+
var n;
|
2443
|
+
n = this.current_editor.addClassesToElement(element);
|
2444
|
+
this.current_editor.setElementName(n);
|
2445
|
+
return this.current_editor.markAsSelected(n);
|
2446
|
+
};
|
2447
|
+
|
2448
|
+
Menu.prototype.cleanContents = function() {
|
2449
|
+
return this.current_editor.cleanContents();
|
2450
|
+
};
|
2451
|
+
|
2452
|
+
Menu.prototype.commandOverall = function(cmd, val) {
|
2453
|
+
var message, n;
|
2454
|
+
message = " to exec 「" + cmd + "」 command" + (val ? " with value: " + val : "");
|
2455
|
+
if (document.execCommand(cmd, false, val)) {
|
2456
|
+
utils.log("success" + message);
|
2457
|
+
n = this.current_editor.getNode();
|
2458
|
+
this.current_editor.setupLinks($(n).find("a"));
|
2459
|
+
this.displayHighlights();
|
2460
|
+
if ($(n).parent().hasClass("section-inner")) {
|
2461
|
+
n = this.current_editor.addClassesToElement(n);
|
2462
|
+
this.current_editor.setElementName(n);
|
2463
|
+
}
|
2464
|
+
this.current_editor.handleTextSelection(n);
|
2465
|
+
} else {
|
2466
|
+
utils.log("fail" + message, true);
|
2467
|
+
}
|
2468
|
+
};
|
2469
|
+
|
2470
|
+
Menu.prototype.commandInsert = function(name) {
|
2471
|
+
var node;
|
2472
|
+
node = this.current_editor.current_node;
|
2473
|
+
if (!node) {
|
2474
|
+
return;
|
2475
|
+
}
|
2476
|
+
this.current_editor.current_range.selectNode(node);
|
2477
|
+
this.current_editor.current_range.collapse(false);
|
2478
|
+
return this.commandOverall(node, name);
|
2479
|
+
};
|
2480
|
+
|
2481
|
+
Menu.prototype.commandBlock = function(name) {
|
2482
|
+
var list, node;
|
2483
|
+
node = this.current_editor.current_node;
|
2484
|
+
list = this.effectNode(this.current_editor.getNode(node), true);
|
2485
|
+
if (list.indexOf(name) !== -1) {
|
2486
|
+
name = "p";
|
2487
|
+
}
|
2488
|
+
return this.commandOverall("formatblock", name);
|
2489
|
+
};
|
2490
|
+
|
2491
|
+
Menu.prototype.commandWrap = function(tag) {
|
2492
|
+
var node, val;
|
2493
|
+
node = this.current_editor.current_node;
|
2494
|
+
val = "<" + tag + ">" + selection + "</" + tag + ">";
|
2495
|
+
return this.commandOverall("insertHTML", val);
|
2496
|
+
};
|
2497
|
+
|
2498
|
+
Menu.prototype.effectNode = function(el, returnAsNodeName) {
|
2499
|
+
var nodes;
|
2500
|
+
nodes = [];
|
2501
|
+
el = el || this.current_editor.$el[0];
|
2502
|
+
while (el !== this.current_editor.$el[0]) {
|
2503
|
+
if (el.nodeName.match(this.effectNodeReg)) {
|
2504
|
+
nodes.push((returnAsNodeName ? el.nodeName.toLowerCase() : el));
|
2505
|
+
}
|
2506
|
+
el = el.parentNode;
|
2507
|
+
}
|
2508
|
+
return nodes;
|
2509
|
+
};
|
2510
|
+
|
2511
|
+
Menu.prototype.displayHighlights = function() {
|
2512
|
+
var nodes;
|
2513
|
+
$(this.el).find(".active").removeClass("active");
|
2514
|
+
nodes = this.effectNode(utils.getNode());
|
2515
|
+
utils.log(nodes);
|
2516
|
+
return _.each(nodes, (function(_this) {
|
2517
|
+
return function(node) {
|
2518
|
+
var tag;
|
2519
|
+
tag = node.nodeName.toLowerCase();
|
2520
|
+
switch (tag) {
|
2521
|
+
case "a":
|
2522
|
+
$(_this.el).find('input').val($(node).attr("href"));
|
2523
|
+
tag = "createlink";
|
2524
|
+
break;
|
2525
|
+
case "i":
|
2526
|
+
tag = "italic";
|
2527
|
+
break;
|
2528
|
+
case "u":
|
2529
|
+
tag = "underline";
|
2530
|
+
break;
|
2531
|
+
case "b":
|
2532
|
+
tag = "bold";
|
2533
|
+
break;
|
2534
|
+
case "code":
|
2535
|
+
tag = "code";
|
2536
|
+
break;
|
2537
|
+
case "ul":
|
2538
|
+
tag = "insertunorderedlist";
|
2539
|
+
break;
|
2540
|
+
case "ol":
|
2541
|
+
tag = "insertorderedlist";
|
2542
|
+
break;
|
2543
|
+
case "li":
|
2544
|
+
tag = "indent";
|
2545
|
+
utils.log("nothing to select");
|
2546
|
+
}
|
2547
|
+
if (tag.match(/(?:h[1-6])/i)) {
|
2548
|
+
$(_this.el).find(".icon-bold, .icon-italic, .icon-blockquote").parent("li").remove();
|
2549
|
+
} else if (tag === "indent") {
|
2550
|
+
$(_this.el).find(".icon-h2, .icon-h3, .icon-h4, .icon-blockquote").parent("li").remove();
|
2551
|
+
}
|
2552
|
+
return _this.highlight(tag);
|
2553
|
+
};
|
2554
|
+
})(this));
|
2555
|
+
};
|
2556
|
+
|
2557
|
+
Menu.prototype.highlight = function(tag) {
|
2558
|
+
return $(".icon-" + tag).parent("li").addClass("active");
|
2559
|
+
};
|
2560
|
+
|
2561
|
+
Menu.prototype.show = function() {
|
2562
|
+
$(this.el).addClass("dante-menu--active");
|
2563
|
+
this.closeInput();
|
2564
|
+
return this.displayHighlights();
|
2565
|
+
};
|
2566
|
+
|
2567
|
+
Menu.prototype.hide = function() {
|
2568
|
+
return $(this.el).removeClass("dante-menu--active");
|
2569
|
+
};
|
2570
|
+
|
2571
|
+
return Menu;
|
2572
|
+
|
2573
|
+
})(Dante.View);
|
2574
|
+
|
2575
|
+
}).call(this);
|
2576
|
+
//Editor components
|
2577
|
+
|
2578
|
+
|
2579
|
+
|
2580
|
+
|
2581
|
+
|
2582
|
+
|
2583
|
+
|
2584
|
+
;
|