Commits

Matt Ryall committed 22f939b

Initial cut - not inserting link correctly yet

  • Participants

Comments (0)

Files changed (7)

+.idea/
+*.ipr
+*.iml
+*.iws
+target/
+Copyright (c) 2012, Atlassian Pty Ltd.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+Neither the name of the Atlassian Pty Ltd nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>com.atlassian.demo.plugin</groupId>
+    <artifactId>confluence-insert-link-demo-plugin</artifactId>
+    <version>1.0-SNAPSHOT</version>
+
+    <name>confluence-insert-link-demo-plugin</name>
+    <description>Demo Insert Link Plugin</description>
+    <packaging>atlassian-plugin</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.atlassian.confluence</groupId>
+            <artifactId>confluence</artifactId>
+            <version>${confluence.version}</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>com.atlassian.maven.plugins</groupId>
+                <artifactId>maven-confluence-plugin</artifactId>
+                <version>3.2.3</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <productVersion>${confluence.version}</productVersion>
+                    <productDataVersion>${confluence.data.version}</productDataVersion>
+                </configuration>
+            </plugin>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.6</source>
+                    <target>1.6</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <properties>
+        <confluence.version>4.0.5</confluence.version>
+        <confluence.data.version>3.5</confluence.data.version>
+    </properties>
+</project>

File src/main/resources/atlassian-plugin.xml

+<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2">
+    <plugin-info>
+        <description>${project.description}</description>
+        <version>${project.version}</version>
+    </plugin-info>
+
+    <resource name="i18n" type="i18n" location="insert-link/i18n" />
+
+    <web-item key="link-browser-tab" name="Link Browser Tab" section="system.editor.link.browser.tabs" weight="60">
+        <description>Displays a custom tab in the Link Browser.</description>
+        <label key="link.browser.tab.name.demo"/>
+        <link linkId="demo"/><!-- has to match the 'key' specified in the panel JS file -->
+    </web-item>
+
+    <web-resource key="insert-link-javascript" name="Insert Link Dialog JavaScript">
+        <transformation extension="js">
+            <transformer key="jsI18n"/>
+        </transformation>
+        <transformation extension="soy">
+            <transformer key="soyTransformer">
+                <functions>com.atlassian.confluence.plugins.soy:soy-core-functions</functions>
+            </transformer>
+        </transformation>
+
+        <resource name="demo.js" type="download" location="insert-link/demo.js"/>
+        <resource name="demo-panel-soy.js" type="download" location="insert-link/demo-panel.soy"/>
+
+        <dependency>com.atlassian.confluence.tinymceplugin:editor-javascript-resources</dependency>
+        <context>editor</context>
+    </web-resource>
+
+</atlassian-plugin>

File src/main/resources/insert-link/demo-panel.soy

+{namespace Confluence.Templates.LinkBrowser}
+
+/**
+ * The contents of the panel.
+ */
+{template .demoPanel}
+    <div class="input-field">
+        <label for="demo-panel-destination">{getText('link.browser.demo.link.label')}:</label>
+        <input type="text" tabindex="0" class="text" id="demo-panel-destination" name="destination" size="60">
+    </div>
+    <div class="description">{getText('link.browser.demo.link.desc')}</div>
+{/template}

File src/main/resources/insert-link/demo.js

+(function($) {
+
+    // The tab registers itself when the Link Browser is created.
+    AJS.bind("dialog-created.link-browser", function (e, linkBrowser) {
+
+        var key = 'demo',                   // This panel's key: must match the ID of the web-item link and panel template
+            $linkField,                     // The jQueryfied link input element.
+            thisPanel,                      // A reference to this panel.
+            tab;
+
+        // Define the available Link Browser Advanced tab methods.
+        tab = linkBrowser.tabs[key] = {
+
+            createPanel: function (context) {
+                thisPanel = context.baseElement;
+                $linkField = thisPanel.find("input[name='destination']");
+                thisPanel.find("form").keydown(function(e) {
+                    if(e.keyCode == 13 && !linkBrowser.isSubmitButtonEnabled()) {
+                        e.preventDefault();
+                    }
+                });
+                $linkField.keyup(function (e) {
+                    $linkField.val();
+                    var linkObj = url ? Confluence.Link.makeExternalLink(url) : null;
+                    if (linkObj) {
+                        linkBrowser.setLink(linkObj); // will enable the Submit button when a URL is added
+                    }
+                });
+            },
+
+            setLink: function (text) {
+                $linkField.val(text);
+                $linkField.keyup();
+                $linkField.change();
+            },
+
+            // Called when the panel is selected
+            onSelect: function () {
+                // Defer focus to after dialog is shown, gets around AJS.Dialog tabindex issues
+                setTimeout(function() {
+                    $linkField.focus();
+                });
+            },
+
+            // Called when this panel is no longer selected
+            onDeselect: function () {
+
+            },
+
+            handlesLink: function (linkObj) {
+                // return true if the link should be cause this panel to be selected when editing
+                return false;
+            }
+        };
+    });
+
+})(jQuery);

File src/main/resources/insert-link/i18n.properties

+link.browser.tab.name.demo=Demo
+
+link.browser.demo.link.label=Destination
+link.browser.demo.link.desc=The destination for the link