commit
3ca92b9770
|
@ -45,23 +45,22 @@ class I18nService extends taiga.Service
|
||||||
i18n.init(@.options)
|
i18n.init(@.options)
|
||||||
@rootscope.t = i18n.t
|
@rootscope.t = i18n.t
|
||||||
|
|
||||||
|
t: (path, opts) ->
|
||||||
|
return i18n.t(path, opts)
|
||||||
|
|
||||||
|
|
||||||
I18nDirective = ($rootscope, $i18n) ->
|
I18nDirective = ($rootscope, $i18n) ->
|
||||||
link = ($scope, $el, $attrs) ->
|
link = ($scope, $el, $attrs) ->
|
||||||
values = $attrs.tr.split(",")
|
values = $attrs.tr.split(",")
|
||||||
options = $attrs.trOpts or '{}'
|
options = $attrs.trOpts or '{}'
|
||||||
|
|
||||||
applyTranslation = ->
|
|
||||||
opts = $scope.$eval(options)
|
opts = $scope.$eval(options)
|
||||||
|
|
||||||
for v in values
|
for v in values
|
||||||
if v.indexOf(":") == -1
|
if v.indexOf(":") == -1
|
||||||
$el.html(_.escape($scope.t(v, opts)))
|
$el.html(_.escape($i18n.t(v, opts)))
|
||||||
else
|
else
|
||||||
[ns, v] = v.split(":")
|
[ns, v] = v.split(":")
|
||||||
$el.attr(ns, _.escape($scope.t(v, opts)))
|
$el.attr(ns, _.escape($i18n.t(v, opts)))
|
||||||
|
|
||||||
bindOnce($scope, "t", applyTranslation)
|
|
||||||
$scope.$on("i18n:changeLang", applyTranslation)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
link: link
|
link: link
|
||||||
|
|
|
@ -28,32 +28,7 @@ module = angular.module("taigaCommon")
|
||||||
#############################################################################
|
#############################################################################
|
||||||
## WYSIWYG markitup editor directive
|
## WYSIWYG markitup editor directive
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
tgMarkitupDirective = ($rootscope, $rs, $tr) ->
|
||||||
# TODO: fix when i18n is implemented
|
|
||||||
$i18next = {
|
|
||||||
t: (key) ->
|
|
||||||
keywords = {
|
|
||||||
"markdown-editor.heading-1": "First Level Heading",
|
|
||||||
"markdown-editor.heading-2": "Second Level Heading",
|
|
||||||
"markdown-editor.heading-3": "Third Level Heading",
|
|
||||||
"markdown-editor.bold": "Bold",
|
|
||||||
"markdown-editor.italic": "Italic",
|
|
||||||
"markdown-editor.strike": "Strike",
|
|
||||||
"markdown-editor.bulleted-list": "Bulleted List",
|
|
||||||
"markdown-editor.numeric-list": "Numeric List",
|
|
||||||
"markdown-editor.picture": "Picture",
|
|
||||||
"markdown-editor.link": "Link",
|
|
||||||
"markdown-editor.quotes": "Quotes",
|
|
||||||
"markdown-editor.code-block": "Code Block / Code",
|
|
||||||
"markdown-editor.preview": "Preview",
|
|
||||||
"markdown-editor.help": "Help",
|
|
||||||
"markdown-editor.placeholder": "Your title here...",
|
|
||||||
"markdown-editor.link-placeholder": "Your text to link here..."
|
|
||||||
}
|
|
||||||
return keywords[key] or key
|
|
||||||
}
|
|
||||||
|
|
||||||
tgMarkitupDirective = ($rootscope, $rs) ->
|
|
||||||
previewTemplate = _.template("""
|
previewTemplate = _.template("""
|
||||||
<div class="preview">
|
<div class="preview">
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
|
@ -70,7 +45,7 @@ tgMarkitupDirective = ($rootscope, $rs) ->
|
||||||
previewDomNode = $("<div/>", {class: "preview"})
|
previewDomNode = $("<div/>", {class: "preview"})
|
||||||
|
|
||||||
#openHelp = ->
|
#openHelp = ->
|
||||||
# window.open($rootscope.urls.wikiHelpUrl(), '_blank')
|
# window.open($rootscope.urls.wikiHelpUrl(), "_blank")
|
||||||
|
|
||||||
closePreviewMode = ->
|
closePreviewMode = ->
|
||||||
element.parents(".markdown").find(".preview").remove()
|
element.parents(".markdown").find(".preview").remove()
|
||||||
|
@ -97,7 +72,7 @@ tgMarkitupDirective = ($rootscope, $rs) ->
|
||||||
setCaretPosition = (elm, caretPos) ->
|
setCaretPosition = (elm, caretPos) ->
|
||||||
if elm.createTextRange
|
if elm.createTextRange
|
||||||
range = elm.createTextRange()
|
range = elm.createTextRange()
|
||||||
range.move('character', caretPos)
|
range.move("character", caretPos)
|
||||||
range.select()
|
range.select()
|
||||||
|
|
||||||
else if elm.selectionStart
|
else if elm.selectionStart
|
||||||
|
@ -116,8 +91,8 @@ tgMarkitupDirective = ($rootscope, $rs) ->
|
||||||
return currentCaretPosition - removedLineLength + 1
|
return currentCaretPosition - removedLineLength + 1
|
||||||
|
|
||||||
markdownSettings =
|
markdownSettings =
|
||||||
nameSpace: 'markdown'
|
nameSpace: "markdown"
|
||||||
onShiftEnter: {keepDefault:false, openWith:'\n\n'}
|
onShiftEnter: {keepDefault:false, openWith:"\n\n"}
|
||||||
onEnter:
|
onEnter:
|
||||||
keepDefault: false
|
keepDefault: false
|
||||||
replaceWith: (data) =>
|
replaceWith: (data) =>
|
||||||
|
@ -175,95 +150,95 @@ tgMarkitupDirective = ($rootscope, $rs) ->
|
||||||
|
|
||||||
markupSet: [
|
markupSet: [
|
||||||
{
|
{
|
||||||
name: $i18next.t('markdown-editor.heading-1')
|
name: $tr.t("markdown-editor.heading-1")
|
||||||
key: "1"
|
key: "1"
|
||||||
placeHolder: $i18next.t('markdown-editor.placeholder')
|
placeHolder: $tr.t("markdown-editor.placeholder")
|
||||||
closeWith: (markItUp) -> markdownTitle(markItUp, '=')
|
closeWith: (markItUp) -> markdownTitle(markItUp, "=")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: $i18next.t('markdown-editor.heading-2')
|
name: $tr.t("markdown-editor.heading-2")
|
||||||
key: "2"
|
key: "2"
|
||||||
placeHolder: $i18next.t('markdown-editor.placeholder')
|
placeHolder: $tr.t("markdown-editor.placeholder")
|
||||||
closeWith: (markItUp) -> markdownTitle(markItUp, '-')
|
closeWith: (markItUp) -> markdownTitle(markItUp, "-")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: $i18next.t('markdown-editor.heading-3')
|
name: $tr.t("markdown-editor.heading-3")
|
||||||
key: "3"
|
key: "3"
|
||||||
openWith: '### '
|
openWith: "### "
|
||||||
placeHolder: $i18next.t('markdown-editor.placeholder')
|
placeHolder: $tr.t("markdown-editor.placeholder")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
separator: '---------------'
|
separator: "---------------"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: $i18next.t('markdown-editor.bold')
|
name: $tr.t("markdown-editor.bold")
|
||||||
key: "B"
|
key: "B"
|
||||||
openWith: '**'
|
openWith: "**"
|
||||||
closeWith: '**'
|
closeWith: "**"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: $i18next.t('markdown-editor.italic')
|
name: $tr.t("markdown-editor.italic")
|
||||||
key: "I"
|
key: "I"
|
||||||
openWith: '_'
|
openWith: "_"
|
||||||
closeWith: '_'
|
closeWith: "_"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: $i18next.t('markdown-editor.strike')
|
name: $tr.t("markdown-editor.strike")
|
||||||
key: "S"
|
key: "S"
|
||||||
openWith: '~~'
|
openWith: "~~"
|
||||||
closeWith: '~~'
|
closeWith: "~~"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
separator: '---------------'
|
separator: "---------------"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: $i18next.t('markdown-editor.bulleted-list')
|
name: $tr.t("markdown-editor.bulleted-list")
|
||||||
openWith: '- '
|
openWith: "- "
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: $i18next.t('markdown-editor.numeric-list')
|
name: $tr.t("markdown-editor.numeric-list")
|
||||||
openWith: (markItUp) -> markItUp.line+'. '
|
openWith: (markItUp) -> markItUp.line+". "
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
separator: '---------------'
|
separator: "---------------"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: $i18next.t('markdown-editor.picture')
|
name: $tr.t("markdown-editor.picture")
|
||||||
key: "P"
|
key: "P"
|
||||||
replaceWith: '![[![Alternative text]!]]([![Url:!:http://]!] "[![Title]!]")'
|
replaceWith: '![[![Alternative text]!]]([![Url:!:http://]!] "[![Title]!]")'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: $i18next.t('markdown-editor.link')
|
name: $tr.t("markdown-editor.link")
|
||||||
key: "L"
|
key: "L"
|
||||||
openWith: '['
|
openWith: "["
|
||||||
closeWith: ']([![Url:!:http://]!] "[![Title]!]")'
|
closeWith: ']([![Url:!:http://]!] "[![Title]!]")'
|
||||||
placeHolder: $i18next.t('markdown-editor.link-placeholder')
|
placeHolder: $tr.t("markdown-editor.link-placeholder")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
separator: '---------------'
|
separator: "---------------"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: $i18next.t('markdown-editor.quotes')
|
name: $tr.t("markdown-editor.quotes")
|
||||||
openWith: '> '
|
openWith: "> "
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: $i18next.t('markdown-editor.code-block')
|
name: $tr.t("markdown-editor.code-block")
|
||||||
openWith: '```\n'
|
openWith: "```\n"
|
||||||
closeWith: '\n```'
|
closeWith: "\n```"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
separator: '---------------'
|
separator: "---------------"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: $i18next.t('markdown-editor.preview')
|
name: $tr.t("markdown-editor.preview")
|
||||||
call: preview
|
call: preview
|
||||||
className: "preview-icon"
|
className: "preview-icon"
|
||||||
},
|
},
|
||||||
# {
|
# {
|
||||||
# separator: '---------------'
|
# separator: "---------------"
|
||||||
# },
|
# },
|
||||||
# {
|
# {
|
||||||
# name: $i18next.t('markdown-editor.help')
|
# name: $tr.t("markdown-editor.help")
|
||||||
# call: openHelp
|
# call: openHelp
|
||||||
# className: "help"
|
# className: "help"
|
||||||
# }
|
# }
|
||||||
|
@ -273,16 +248,15 @@ tgMarkitupDirective = ($rootscope, $rs) ->
|
||||||
$model.$setViewValue(target.val())
|
$model.$setViewValue(target.val())
|
||||||
|
|
||||||
markdownTitle = (markItUp, char) ->
|
markdownTitle = (markItUp, char) ->
|
||||||
heading = ''
|
heading = ""
|
||||||
n = $.trim(markItUp.selection or markItUp.placeHolder).length
|
n = $.trim(markItUp.selection or markItUp.placeHolder).length
|
||||||
|
|
||||||
for i in [0..n-1]
|
for i in [0..n-1]
|
||||||
heading += char
|
heading += char
|
||||||
|
|
||||||
return '\n'+heading+'\n'
|
return "\n"+heading+"\n"
|
||||||
|
|
||||||
element.markItUp(markdownSettings)
|
element.markItUp(markdownSettings)
|
||||||
|
|
||||||
element.on "keypress", (event) ->
|
element.on "keypress", (event) ->
|
||||||
$scope.$apply()
|
$scope.$apply()
|
||||||
|
|
||||||
|
@ -291,4 +265,4 @@ tgMarkitupDirective = ($rootscope, $rs) ->
|
||||||
|
|
||||||
return {link:link, require:"ngModel"}
|
return {link:link, require:"ngModel"}
|
||||||
|
|
||||||
module.directive("tgMarkitup", ["$rootScope", "$tgResources", tgMarkitupDirective])
|
module.directive("tgMarkitup", ["$rootScope", "$tgResources", "$tgI18n", tgMarkitupDirective])
|
||||||
|
|
|
@ -31,7 +31,7 @@ paths.jade = [
|
||||||
|
|
||||||
paths.images = paths.app + "images/**/*"
|
paths.images = paths.app + "images/**/*"
|
||||||
paths.svg = paths.app + "svg/**/*"
|
paths.svg = paths.app + "svg/**/*"
|
||||||
paths.css = paths.app + "app/styles/vendor/*.css"
|
paths.css = paths.app + "styles/vendor/*.css"
|
||||||
paths.locales = paths.app + "locales/**/*.json"
|
paths.locales = paths.app + "locales/**/*.json"
|
||||||
paths.sass = [
|
paths.sass = [
|
||||||
paths.app + "styles/**/*.scss"
|
paths.app + "styles/**/*.scss"
|
||||||
|
|
Loading…
Reference in New Issue