mirror of
https://github.com/discourse/discourse.git
synced 2025-02-21 19:55:43 +00:00
Allow basic emoticons to work too.
This commit is contained in:
parent
af18cc87fd
commit
eeef24b9da
@ -3,6 +3,49 @@
|
|||||||
|
|
||||||
@module $.fn.autocomplete
|
@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) {
|
$.fn.autocomplete = function(options) {
|
||||||
|
|
||||||
var autocompletePlugin = this;
|
var autocompletePlugin = this;
|
||||||
@ -338,11 +381,15 @@ $.fn.autocomplete = function(options) {
|
|||||||
}
|
}
|
||||||
term = me.val().substring(completeStart + (options.key ? 1 : 0), caretPosition);
|
term = me.val().substring(completeStart + (options.key ? 1 : 0), caretPosition);
|
||||||
if (e.which >= 48 && e.which <= 90) {
|
if (e.which >= 48 && e.which <= 90) {
|
||||||
term += String.fromCharCode(e.which);
|
term += mapKeyPressToActualCharacter(e.shiftKey, e.which);
|
||||||
} else if (e.which === 187) {
|
} else if (e.which === 187) {
|
||||||
term += "+";
|
term += "+";
|
||||||
} else if (e.which === 189) {
|
} else if (e.which === 189) {
|
||||||
term += (e.shiftKey) ? "_" : "-";
|
term += (e.shiftKey) ? "_" : "-";
|
||||||
|
} else if (e.which === 220) {
|
||||||
|
term += (e.shiftKey) ? "|" : "]";
|
||||||
|
} else if (e.which === 222) {
|
||||||
|
term += (e.shiftKey) ? "\"" : "'";
|
||||||
} else {
|
} else {
|
||||||
if (e.which !== 8) {
|
if (e.which !== 8) {
|
||||||
term += ",";
|
term += ",";
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
@param {function} emitter the function that creates JsonML for the tag
|
@param {function} emitter the function that creates JsonML for the tag
|
||||||
**/
|
**/
|
||||||
function replaceBBCode(tag, emitter) {
|
function replaceBBCode(tag, emitter) {
|
||||||
Discourse.Dialect.inlineReplace({
|
Discourse.Dialect.inlineBetween({
|
||||||
start: "[" + tag + "]",
|
start: "[" + tag + "]",
|
||||||
stop: "[/" + tag + "]",
|
stop: "[/" + tag + "]",
|
||||||
emitter: emitter
|
emitter: emitter
|
||||||
@ -21,7 +21,7 @@ function replaceBBCode(tag, emitter) {
|
|||||||
@param {function} emitter the function that creates JsonML for the tag
|
@param {function} emitter the function that creates JsonML for the tag
|
||||||
**/
|
**/
|
||||||
function replaceBBCodeParamsRaw(tag, emitter) {
|
function replaceBBCodeParamsRaw(tag, emitter) {
|
||||||
Discourse.Dialect.inlineReplace({
|
Discourse.Dialect.inlineBetween({
|
||||||
start: "[" + tag + "=",
|
start: "[" + tag + "=",
|
||||||
stop: "[/" + tag + "]",
|
stop: "[/" + tag + "]",
|
||||||
rawContents: true,
|
rawContents: true,
|
||||||
@ -59,21 +59,21 @@ replaceBBCode('li', function(contents) { return ['li'].concat(contents); });
|
|||||||
|
|
||||||
replaceBBCode('spoiler', function(contents) { return ['span', {'class': 'spoiler'}].concat(contents); });
|
replaceBBCode('spoiler', function(contents) { return ['span', {'class': 'spoiler'}].concat(contents); });
|
||||||
|
|
||||||
Discourse.Dialect.inlineReplace({
|
Discourse.Dialect.inlineBetween({
|
||||||
start: '[img]',
|
start: '[img]',
|
||||||
stop: '[/img]',
|
stop: '[/img]',
|
||||||
rawContents: true,
|
rawContents: true,
|
||||||
emitter: function(contents) { return ['img', {href: contents}]; }
|
emitter: function(contents) { return ['img', {href: contents}]; }
|
||||||
});
|
});
|
||||||
|
|
||||||
Discourse.Dialect.inlineReplace({
|
Discourse.Dialect.inlineBetween({
|
||||||
start: '[email]',
|
start: '[email]',
|
||||||
stop: '[/email]',
|
stop: '[/email]',
|
||||||
rawContents: true,
|
rawContents: true,
|
||||||
emitter: function(contents) { return ['a', {href: "mailto:" + contents, 'data-bbcode': true}, contents]; }
|
emitter: function(contents) { return ['a', {href: "mailto:" + contents, 'data-bbcode': true}, contents]; }
|
||||||
});
|
});
|
||||||
|
|
||||||
Discourse.Dialect.inlineReplace({
|
Discourse.Dialect.inlineBetween({
|
||||||
start: '[url]',
|
start: '[url]',
|
||||||
stop: '[/url]',
|
stop: '[/url]',
|
||||||
rawContents: true,
|
rawContents: true,
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
// Support for simultaneous bold and italics
|
// Support for simultaneous bold and italics
|
||||||
Discourse.Dialect.inlineReplace({
|
Discourse.Dialect.inlineBetween({
|
||||||
between: '***',
|
between: '***',
|
||||||
wordBoundary: true,
|
wordBoundary: true,
|
||||||
emitter: function(contents) { return ['strong', ['em'].concat(contents)]; }
|
emitter: function(contents) { return ['strong', ['em'].concat(contents)]; }
|
||||||
@ -12,7 +12,7 @@ Discourse.Dialect.inlineReplace({
|
|||||||
|
|
||||||
// Builds a common markdown replacer
|
// Builds a common markdown replacer
|
||||||
var replaceMarkdown = function(match, tag) {
|
var replaceMarkdown = function(match, tag) {
|
||||||
Discourse.Dialect.inlineReplace({
|
Discourse.Dialect.inlineBetween({
|
||||||
between: match,
|
between: match,
|
||||||
wordBoundary: true,
|
wordBoundary: true,
|
||||||
emitter: function(contents) { return [tag].concat(contents) }
|
emitter: function(contents) { return [tag].concat(contents) }
|
||||||
|
@ -128,6 +128,25 @@ Discourse.Dialect = {
|
|||||||
return parser.renderJsonML(parseTree(tree));
|
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
|
Matches inline using a regular expression. The emitter function is passed
|
||||||
the matches from the regular expression.
|
the matches from the regular expression.
|
||||||
@ -146,7 +165,7 @@ Discourse.Dialect = {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
@method inlineReplace
|
@method inlineRegexp
|
||||||
@param {Object} args Our replacement options
|
@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 {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
|
@param {String} [opts.start] The starting token we want to find
|
||||||
@ -178,7 +197,7 @@ Discourse.Dialect = {
|
|||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
|
||||||
Discourse.Dialect.inlineReplace({
|
Discourse.Dialect.inlineBetween({
|
||||||
between: '**',
|
between: '**',
|
||||||
wordBoundary: true.
|
wordBoundary: true.
|
||||||
emitter: function(contents) {
|
emitter: function(contents) {
|
||||||
@ -187,7 +206,7 @@ Discourse.Dialect = {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
@method inlineReplace
|
@method inlineBetween
|
||||||
@param {Object} args Our replacement options
|
@param {Object} args Our replacement options
|
||||||
@param {Function} [opts.emitter] The function that will be called with the contents and returns JsonML.
|
@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
|
@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.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
|
@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,
|
var start = args.start || args.between,
|
||||||
stop = args.stop || args.between,
|
stop = args.stop || args.between,
|
||||||
startLength = start.length;
|
startLength = start.length;
|
||||||
|
@ -1057,7 +1057,7 @@ Markdown.buildInlinePatterns = function(d) {
|
|||||||
for ( var i in d ) {
|
for ( var i in d ) {
|
||||||
// __foo__ is reserved and not a pattern
|
// __foo__ is reserved and not a pattern
|
||||||
if ( i.match( /^__.*__$/) ) continue;
|
if ( i.match( /^__.*__$/) ) continue;
|
||||||
var l = i.replace( /([\\.*+?|()\[\]{}])/g, "\\$1" )
|
var l = i.replace( /([\\.*+?$|()\[\]{}])/g, "\\$1" )
|
||||||
.replace( /\n/, "\\n" );
|
.replace( /\n/, "\\n" );
|
||||||
patterns.push( i.length == 1 ? l : "(?:" + l + ")" );
|
patterns.push( i.length == 1 ? l : "(?:" + l + ")" );
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user