mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-17 04:01:29 -05:00
Allow basic emoticons to work too.
This commit is contained in:
parent
af18cc87fd
commit
eeef24b9da
6 changed files with 114 additions and 26 deletions
|
@ -3,6 +3,49 @@
|
|||
|
||||
@module $.fn.autocomplete
|
||||
**/
|
||||
|
||||
var shiftMap = [];
|
||||
shiftMap[192] = "~";
|
||||
shiftMap[49] = "!";
|
||||
shiftMap[50] = "@";
|
||||
shiftMap[51] = "#";
|
||||
shiftMap[52] = "$";
|
||||
shiftMap[53] = "%";
|
||||
shiftMap[54] = "^";
|
||||
shiftMap[55] = "&";
|
||||
shiftMap[56] = "*";
|
||||
shiftMap[57] = "(";
|
||||
shiftMap[48] = ")";
|
||||
shiftMap[109] = "_";
|
||||
shiftMap[107] = "+";
|
||||
shiftMap[219] = "{";
|
||||
shiftMap[221] = "}";
|
||||
shiftMap[220] = "|";
|
||||
shiftMap[59] = ":";
|
||||
shiftMap[222] = "\"";
|
||||
shiftMap[188] = "<";
|
||||
shiftMap[190] = ">";
|
||||
shiftMap[191] = "?";
|
||||
shiftMap[32] = " ";
|
||||
|
||||
function mapKeyPressToActualCharacter(isShiftKey, characterCode) {
|
||||
if ( characterCode === 27 || characterCode === 8 || characterCode === 9 || characterCode === 20 || characterCode === 16 || characterCode === 17 || characterCode === 91 || characterCode === 13 || characterCode === 92 || characterCode === 18 ) { return false; }
|
||||
|
||||
if (isShiftKey) {
|
||||
if ( characterCode >= 65 && characterCode <= 90 ) {
|
||||
return String.fromCharCode(characterCode);
|
||||
} else {
|
||||
return shiftMap[characterCode];
|
||||
}
|
||||
} else {
|
||||
if ( characterCode >= 65 && characterCode <= 90 ) {
|
||||
return String.fromCharCode(characterCode).toLowerCase();
|
||||
} else {
|
||||
return String.fromCharCode(characterCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$.fn.autocomplete = function(options) {
|
||||
|
||||
var autocompletePlugin = this;
|
||||
|
@ -338,11 +381,15 @@ $.fn.autocomplete = function(options) {
|
|||
}
|
||||
term = me.val().substring(completeStart + (options.key ? 1 : 0), caretPosition);
|
||||
if (e.which >= 48 && e.which <= 90) {
|
||||
term += String.fromCharCode(e.which);
|
||||
term += mapKeyPressToActualCharacter(e.shiftKey, e.which);
|
||||
} else if (e.which === 187) {
|
||||
term += "+";
|
||||
} else if (e.which === 189) {
|
||||
term += (e.shiftKey) ? "_" : "-";
|
||||
} else if (e.which === 220) {
|
||||
term += (e.shiftKey) ? "|" : "]";
|
||||
} else if (e.which === 222) {
|
||||
term += (e.shiftKey) ? "\"" : "'";
|
||||
} else {
|
||||
if (e.which !== 8) {
|
||||
term += ",";
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
@param {function} emitter the function that creates JsonML for the tag
|
||||
**/
|
||||
function replaceBBCode(tag, emitter) {
|
||||
Discourse.Dialect.inlineReplace({
|
||||
Discourse.Dialect.inlineBetween({
|
||||
start: "[" + tag + "]",
|
||||
stop: "[/" + tag + "]",
|
||||
emitter: emitter
|
||||
|
@ -21,7 +21,7 @@ function replaceBBCode(tag, emitter) {
|
|||
@param {function} emitter the function that creates JsonML for the tag
|
||||
**/
|
||||
function replaceBBCodeParamsRaw(tag, emitter) {
|
||||
Discourse.Dialect.inlineReplace({
|
||||
Discourse.Dialect.inlineBetween({
|
||||
start: "[" + tag + "=",
|
||||
stop: "[/" + tag + "]",
|
||||
rawContents: true,
|
||||
|
@ -59,21 +59,21 @@ replaceBBCode('li', function(contents) { return ['li'].concat(contents); });
|
|||
|
||||
replaceBBCode('spoiler', function(contents) { return ['span', {'class': 'spoiler'}].concat(contents); });
|
||||
|
||||
Discourse.Dialect.inlineReplace({
|
||||
Discourse.Dialect.inlineBetween({
|
||||
start: '[img]',
|
||||
stop: '[/img]',
|
||||
rawContents: true,
|
||||
emitter: function(contents) { return ['img', {href: contents}]; }
|
||||
});
|
||||
|
||||
Discourse.Dialect.inlineReplace({
|
||||
Discourse.Dialect.inlineBetween({
|
||||
start: '[email]',
|
||||
stop: '[/email]',
|
||||
rawContents: true,
|
||||
emitter: function(contents) { return ['a', {href: "mailto:" + contents, 'data-bbcode': true}, contents]; }
|
||||
});
|
||||
|
||||
Discourse.Dialect.inlineReplace({
|
||||
Discourse.Dialect.inlineBetween({
|
||||
start: '[url]',
|
||||
stop: '[/url]',
|
||||
rawContents: true,
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
**/
|
||||
|
||||
// Support for simultaneous bold and italics
|
||||
Discourse.Dialect.inlineReplace({
|
||||
Discourse.Dialect.inlineBetween({
|
||||
between: '***',
|
||||
wordBoundary: true,
|
||||
emitter: function(contents) { return ['strong', ['em'].concat(contents)]; }
|
||||
|
@ -12,7 +12,7 @@ Discourse.Dialect.inlineReplace({
|
|||
|
||||
// Builds a common markdown replacer
|
||||
var replaceMarkdown = function(match, tag) {
|
||||
Discourse.Dialect.inlineReplace({
|
||||
Discourse.Dialect.inlineBetween({
|
||||
between: match,
|
||||
wordBoundary: true,
|
||||
emitter: function(contents) { return [tag].concat(contents) }
|
||||
|
|
|
@ -128,6 +128,25 @@ Discourse.Dialect = {
|
|||
return parser.renderJsonML(parseTree(tree));
|
||||
},
|
||||
|
||||
/**
|
||||
The simplest kind of replacement possible. Replace a stirng token with JsonML.
|
||||
|
||||
For example to replace all occurrances of :) with a smile image:
|
||||
|
||||
```javascript
|
||||
Discourse.Dialect.inlineReplace(':)', ['img', {src: '/images/smile.gif'}])
|
||||
```
|
||||
|
||||
@method inlineReplace
|
||||
@param {String} token The token we want to replace
|
||||
@param {Array} jsonml The JsonML to replace it with.
|
||||
**/
|
||||
inlineReplace: function(token, jsonml) {
|
||||
dialect.inline[token] = function(text, match, prev) {
|
||||
return [token.length, jsonml];
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
Matches inline using a regular expression. The emitter function is passed
|
||||
the matches from the regular expression.
|
||||
|
@ -146,7 +165,7 @@ Discourse.Dialect = {
|
|||
});
|
||||
```
|
||||
|
||||
@method inlineReplace
|
||||
@method inlineRegexp
|
||||
@param {Object} args Our replacement options
|
||||
@param {Function} [opts.emitter] The function that will be called with the contents and regular expresison match and returns JsonML.
|
||||
@param {String} [opts.start] The starting token we want to find
|
||||
|
@ -178,7 +197,7 @@ Discourse.Dialect = {
|
|||
|
||||
```javascript
|
||||
|
||||
Discourse.Dialect.inlineReplace({
|
||||
Discourse.Dialect.inlineBetween({
|
||||
between: '**',
|
||||
wordBoundary: true.
|
||||
emitter: function(contents) {
|
||||
|
@ -187,7 +206,7 @@ Discourse.Dialect = {
|
|||
});
|
||||
```
|
||||
|
||||
@method inlineReplace
|
||||
@method inlineBetween
|
||||
@param {Object} args Our replacement options
|
||||
@param {Function} [opts.emitter] The function that will be called with the contents and returns JsonML.
|
||||
@param {String} [opts.start] The starting token we want to find
|
||||
|
@ -197,7 +216,7 @@ Discourse.Dialect = {
|
|||
@param {Boolean} [opts.wordBoundary] If true, the match must be on a word boundary
|
||||
@param {Boolean} [opts.spaceBoundary] If true, the match must be on a sppace boundary
|
||||
**/
|
||||
inlineReplace: function(args) {
|
||||
inlineBetween: function(args) {
|
||||
var start = args.start || args.between,
|
||||
stop = args.stop || args.between,
|
||||
startLength = start.length;
|
||||
|
|
|
@ -1057,7 +1057,7 @@ Markdown.buildInlinePatterns = function(d) {
|
|||
for ( var i in d ) {
|
||||
// __foo__ is reserved and not a pattern
|
||||
if ( i.match( /^__.*__$/) ) continue;
|
||||
var l = i.replace( /([\\.*+?|()\[\]{}])/g, "\\$1" )
|
||||
var l = i.replace( /([\\.*+?$|()\[\]{}])/g, "\\$1" )
|
||||
.replace( /\n/, "\\n" );
|
||||
patterns.push( i.length == 1 ? l : "(?:" + l + ")" );
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue