Mercurial > moin > 2.0
changeset 2084:d366d1af5e1e
fixes : Transcluding and Linking subitems bug, changed transcluding and linking buttons to only one InsertName
author | Ashutosh Singla <ashu1461@gmail.com> |
---|---|
date | Tue, 09 Apr 2013 15:14:08 +0530 |
parents | 88660eb0ca43 |
children | 7f4520c9b5f1 |
files | MoinMoin/templates/common.js MoinMoin/templates/modify.html MoinMoin/themes/foobar/static/css/stylus/main.styl MoinMoin/themes/modernized/static/css/stylus/main.styl |
diffstat | 4 files changed, 14 insertions(+), 102 deletions(-) [+] |
line wrap: on
line diff
--- a/MoinMoin/templates/common.js Mon Apr 08 01:56:51 2013 +0200 +++ b/MoinMoin/templates/common.js Tue Apr 09 15:14:08 2013 +0530 @@ -228,92 +228,18 @@ -// guessContentType is a helper function for the transcludeSubitem and linkSubItem functions defined below. -function guessContentType() { - "use strict"; - // Used in the modify_text template to guess the data content type client-side - // This approach has the advantage of reacting to content type changes for the - // link/transclude code without having to re-fetch the page - var match, - meta_text = $("#f_meta_text").val(), - ctype_regex = /["']contenttype["']\s*:\s*["']([\w-_+.]+\/[\w-_+.]+)(;|["'])/; - if (meta_text) { - match = ctype_regex.exec(meta_text); - if (match) {return match[1]; } - } - // text/plain is the default value - return "text/plain"; -} - -// Executed when user clicks transclude-action button defined in modify_text.html. +// Executed when user clicks insert-name button defined in modify.html. // When a page with subitems is modified, a subitems sidebar is present. User may -// position caret in textarea and click button to insert transclusion into textarea. -function transcludeSubitem(subitem_name, fullname) { +// position caret in textarea and click button to insert name into textarea. +function InsertName(fullname) { "use strict"; - function moinwiki(subitem_name, fullname) { - // note: keep the many plusses, to avoid jinja2 templating kicking in - // when seeing two curly opening / closing braces - return "{" + "{" + fullname.replace("{" + "{", "\\" + "}" + "}") + "}" + "} "; - } - function mediawiki(subitem_name, fullname) { - // note: keep the many plusses, to avoid jinja2 templating kicking in - // when seeing two curly opening / closing braces - return "{" + "{:" + fullname.replace("}" + "}", "\\" + "}" + "}") + "}" + "} "; - } - function rst(subitem_name, fullname) { - return "\n.. include:: " + subitem_name + "\n"; - } - function docbook(subitem_name, fullname) { - return ""; //XXX: the docbook converter currently doesn't handle transclusion with <ref> tags - } - var transclude_formats = { - "text/x.moin.wiki" : moinwiki, - "text/x.moin.creole" : moinwiki, - "text/x-mediawiki" : mediawiki, - "text/x-rst" : rst, - "application/docbook+xml" : docbook, - "text/plain" : function (x) {return x + " "; } - }, - ctype = guessContentType(), - input_element = $("#f_content_form_data_text"), - ctype_format = transclude_formats[ctype]; - if (!ctype_format) { - ctype_format = transclude_formats["text/plain"]; - } - input_element.val(input_element.val() + ctype_format(subitem_name, fullname)); - input_element.focus(); -} - -// Executed when user clicks link-action button defined in modify_text.html. -// When a page with subitems is modified, a subitems sidebar is present. User may -// position caret in textarea and click button to insert link into textarea. -function linkSubitem(subitem_name, fullname) { - "use strict"; - function moinwiki(subitem_name, fullname) { - return "[[" + fullname.replace("]", "\\]") + "|" + subitem_name.replace("]", "\\]") + "]] "; - } - function rst(subitem_name, fullname) { - return "`" + subitem_name.replace(">", "\\>").replace("`", "\\`") + " <" + fullname.replace(">", "\\>") + ">`_ "; - } - function docbook(subitem_name, fullname) { - return '<ulink url="/' + fullname.replace('"', '\\"') + '">' + subitem_name + "</ulink>"; - } - var link_formats = { - "text/x.moin.wiki" : moinwiki, - "text/x.moin.creole" : moinwiki, - "text/x-mediawiki" : moinwiki, - "text/x-rst" : rst, - "application/docbook+xml" : docbook, - "text/plain" : function (x) {return x + " "; } - }, - ctype = guessContentType(), - input_element = $("#f_content_form_data_text"), - ctype_format = link_formats[ctype]; - if (!ctype_format) { - ctype_format = link_formats["text/plain"]; - } - input_element.val(input_element.val() + ctype_format(subitem_name, fullname)); - input_element.focus(); + var textArea, scrollTop, endPos, startPos; + textArea = document.getElementById('f_content_form_data_text'); + startPos = textArea.selectionStart; + endPos = textArea.selectionEnd; + textArea.value = textArea.value.substring(0, startPos) + fullname + textArea.value.substring(endPos, textArea.value.length); + textArea.focus(); + textArea.setSelectionRange(startPos+fullname.length,startPos+fullname.length); }
--- a/MoinMoin/templates/modify.html Mon Apr 08 01:56:51 2013 +0200 +++ b/MoinMoin/templates/modify.html Tue Apr 09 15:14:08 2013 +0530 @@ -23,11 +23,8 @@ {% call(fullname, shortname, contenttype, has_children) utils.render_subitem_navigation(item_name, True) %} {% set shortname = shortname|json_dumps %} {% set fullname = fullname|json_dumps %} - <button class="link-action" onclick='linkSubitem({{ shortname }}, {{ fullname }})' - title="{{ _('Link to Subitem') }}">{{ _('Link') }}</button> - <button class="transclude-action" - onclick='transcludeSubitem({{ shortname }}, {{ fullname }})' - title="{{ _('Transclude Subitem') }}">{{ _('Transclude') }}</button> + <button class="moin-insertname-action" onclick='InsertName({{ fullname }})' + title="{{ _('Insert Name') }}">{{ _('Insert Name') }}</button> {% endcall %} {% endblock %}
--- a/MoinMoin/themes/foobar/static/css/stylus/main.styl Mon Apr 08 01:56:51 2013 +0200 +++ b/MoinMoin/themes/foobar/static/css/stylus/main.styl Tue Apr 09 15:14:08 2013 +0530 @@ -1037,8 +1037,7 @@ text-indent -9000% box-shadow none -.link-action, -.transclude-action +.moin-insertname-action border: hidden text-indent: -9000% padding: 0 @@ -1049,12 +1048,8 @@ overflow: hidden cursor: pointer box-shadow none - -.link-action background: url(../img/moin-link.png) no-repeat center center -.transclude-action - background: url(../img/moin-transclusion.png) no-repeat center center // transclusion .moin-transclusion
--- a/MoinMoin/themes/modernized/static/css/stylus/main.styl Mon Apr 08 01:56:51 2013 +0200 +++ b/MoinMoin/themes/modernized/static/css/stylus/main.styl Tue Apr 09 15:14:08 2013 +0530 @@ -1412,8 +1412,7 @@ border hidden text-indent -9000% -.link-action, -.transclude-action +.moin-insertname-action border hidden text-indent -9000% padding 0 @@ -1424,13 +1423,8 @@ overflow hidden cursor pointer box-shadow none - -.moin-subitem-navigation .link-action background url(../img/moin-link.png) no-repeat center center -.moin-subitem-navigation .transclude-action - background url(../img/moin-transclusion.png) no-repeat center center - #moin-footer clear both margin 0 0