comparison src/sceditor.js @ 39:9f63c8f506d1

simplify emoticons
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 18 Aug 2022 22:00:55 -0600
parents 2dfdaaac9482
children 69654081643b
comparison
equal deleted inserted replaced
38:2dfdaaac9482 39:9f63c8f506d1
1312 appendChild(node, next); 1312 appendChild(node, next);
1313 removeKeepChildren(next); 1313 removeKeepChildren(next);
1314 } 1314 }
1315 } 1315 }
1316 1316
1317 let emoticonsRoot = baseUrl + 'emoticons/';
1318
1317 /** 1319 /**
1318 * Default options for SCEditor 1320 * Default options for SCEditor
1319 * @type {Object} 1321 * @type {Object}
1320 */ 1322 */
1321 var defaultOptions = { 1323 var defaultOptions = {
1415 * @type {string} 1417 * @type {string}
1416 */ 1418 */
1417 emoticonsRoot: baseUrl, 1419 emoticonsRoot: baseUrl,
1418 emoticons: { 1420 emoticons: {
1419 dropdown: { 1421 dropdown: {
1420 ':)': 'emoticons/smile.png', 1422 ':)': emoticonsRoot + 'smile.png',
1421 ':angel:': 'emoticons/angel.png', 1423 ':angel:': emoticonsRoot + 'angel.png',
1422 ':angry:': 'emoticons/angry.png', 1424 ':angry:': emoticonsRoot + 'angry.png',
1423 '8-)': 'emoticons/cool.png', 1425 '8-)': emoticonsRoot + 'cool.png',
1424 ':\'(': 'emoticons/cwy.png', 1426 ':\'(': emoticonsRoot + 'cwy.png',
1425 ':ermm:': 'emoticons/ermm.png', 1427 ':ermm:': emoticonsRoot + 'ermm.png',
1426 ':D': 'emoticons/grin.png', 1428 ':D': emoticonsRoot + 'grin.png',
1427 '<3': 'emoticons/heart.png', 1429 '<3': emoticonsRoot + 'heart.png',
1428 ':(': 'emoticons/sad.png', 1430 ':(': emoticonsRoot + 'sad.png',
1429 ':O': 'emoticons/shocked.png', 1431 ':O': emoticonsRoot + 'shocked.png',
1430 ':P': 'emoticons/tongue.png', 1432 ':P': emoticonsRoot + 'tongue.png',
1431 ';)': 'emoticons/wink.png' 1433 ';)': emoticonsRoot + 'wink.png'
1432 }, 1434 },
1433 more: { 1435 more: {
1434 ':alien:': 'emoticons/alien.png', 1436 ':alien:': emoticonsRoot + 'alien.png',
1435 ':blink:': 'emoticons/blink.png', 1437 ':blink:': emoticonsRoot + 'blink.png',
1436 ':blush:': 'emoticons/blush.png', 1438 ':blush:': emoticonsRoot + 'blush.png',
1437 ':cheerful:': 'emoticons/cheerful.png', 1439 ':cheerful:': emoticonsRoot + 'cheerful.png',
1438 ':devil:': 'emoticons/devil.png', 1440 ':devil:': emoticonsRoot + 'devil.png',
1439 ':dizzy:': 'emoticons/dizzy.png', 1441 ':dizzy:': emoticonsRoot + 'dizzy.png',
1440 ':getlost:': 'emoticons/getlost.png', 1442 ':getlost:': emoticonsRoot + 'getlost.png',
1441 ':happy:': 'emoticons/happy.png', 1443 ':happy:': emoticonsRoot + 'happy.png',
1442 ':kissing:': 'emoticons/kissing.png', 1444 ':kissing:': emoticonsRoot + 'kissing.png',
1443 ':ninja:': 'emoticons/ninja.png', 1445 ':ninja:': emoticonsRoot + 'ninja.png',
1444 ':pinch:': 'emoticons/pinch.png', 1446 ':pinch:': emoticonsRoot + 'pinch.png',
1445 ':pouty:': 'emoticons/pouty.png', 1447 ':pouty:': emoticonsRoot + 'pouty.png',
1446 ':sick:': 'emoticons/sick.png', 1448 ':sick:': emoticonsRoot + 'sick.png',
1447 ':sideways:': 'emoticons/sideways.png', 1449 ':sideways:': emoticonsRoot + 'sideways.png',
1448 ':silly:': 'emoticons/silly.png', 1450 ':silly:': emoticonsRoot + 'silly.png',
1449 ':sleeping:': 'emoticons/sleeping.png', 1451 ':sleeping:': emoticonsRoot + 'sleeping.png',
1450 ':unsure:': 'emoticons/unsure.png', 1452 ':unsure:': emoticonsRoot + 'unsure.png',
1451 ':woot:': 'emoticons/w00t.png', 1453 ':woot:': emoticonsRoot + 'w00t.png',
1452 ':wassat:': 'emoticons/wassat.png' 1454 ':wassat:': emoticonsRoot + 'wassat.png'
1453 }, 1455 },
1454 hidden: { 1456 hidden: {
1455 ':whistling:': 'emoticons/whistling.png', 1457 ':whistling:': emoticonsRoot + 'whistling.png',
1456 ':love:': 'emoticons/wub.png' 1458 ':love:': emoticonsRoot + 'wub.png'
1457 } 1459 }
1458 }, 1460 },
1459 1461
1460 /** 1462 /**
1461 * Width of the editor. Set to null for automatic with 1463 * Width of the editor. Set to null for automatic with
2577 emoticon: { 2579 emoticon: {
2578 base: function (editor, caller, targetToHtml) { 2580 base: function (editor, caller, targetToHtml) {
2579 var createContent = function (includeMore) { 2581 var createContent = function (includeMore) {
2580 var moreLink, 2582 var moreLink,
2581 opts = editor.opts, 2583 opts = editor.opts,
2582 emoticonsRoot = opts.emoticonsRoot || '',
2583 emoticonsCompat = opts.emoticonsCompat, 2584 emoticonsCompat = opts.emoticonsCompat,
2584 content = createElement('div'), 2585 content = createElement('div'),
2585 line = createElement('div'), 2586 line = createElement('div'),
2586 perLine = 0, 2587 perLine = 0,
2587 emoticons = extend( 2588 emoticons = extend(
2601 e.preventDefault(); 2602 e.preventDefault();
2602 }); 2603 });
2603 2604
2604 each(emoticons, function (code, emoticon) { 2605 each(emoticons, function (code, emoticon) {
2605 appendChild(line, createElement('img', { 2606 appendChild(line, createElement('img', {
2606 src: emoticonsRoot + (emoticon.url || emoticon), 2607 src: emoticon,
2607 'data-sceditor-emoticon': code, 2608 'data-sceditor-emoticon': code,
2608 alt: code, 2609 alt: code,
2609 title: emoticon.tooltip || code 2610 title: code
2610 })); 2611 }));
2611 2612
2612 if (line.children.length >= perLine) { 2613 if (line.children.length >= perLine) {
2613 line = createElement('div'); 2614 line = createElement('div');
2614 appendChild(content, line); 2615 appendChild(content, line);
4947 * Prefixes and preloads the emoticon images 4948 * Prefixes and preloads the emoticon images
4948 * @private 4949 * @private
4949 */ 4950 */
4950 initEmoticons = function () { 4951 initEmoticons = function () {
4951 var emoticons = options.emoticons; 4952 var emoticons = options.emoticons;
4952 var root = options.emoticonsRoot || '';
4953 4953
4954 if (emoticons) { 4954 if (emoticons) {
4955 allEmoticons = extend( 4955 allEmoticons = extend(
4956 {}, emoticons.more, emoticons.dropdown, emoticons.hidden 4956 {}, emoticons.more, emoticons.dropdown, emoticons.hidden
4957 ); 4957 );
4959 4959
4960 each(allEmoticons, function (key, url) { 4960 each(allEmoticons, function (key, url) {
4961 allEmoticons[key] = _tmpl('emoticon', { 4961 allEmoticons[key] = _tmpl('emoticon', {
4962 key: key, 4962 key: key,
4963 // Prefix emoticon root to emoticon urls 4963 // Prefix emoticon root to emoticon urls
4964 url: root + (url.url || url), 4964 url: url,
4965 tooltip: url.tooltip || key 4965 tooltip: key
4966 }); 4966 });
4967 }); 4967 });
4968 }; 4968 };
4969 4969
4970 /** 4970 /**