Issues with executing simple javascript in description field

JIRA Autobot July 22, 2012

Hi,

I have following code and it works if i click on Create Issues while i look at an issue. If i click on Create Issue on the dashboard it does not work.

If i cancel the create dialog and click Create issue again i hang on the wheel of fortune. What am i doing wrong ?

<script type="text/javascript">
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {     
 $('#summary').keyup(function() {
    var text = $(this).val(),
        count = encodeURIComponent(text).replace(/%[A-F\d]{2}/g, 'U').length;

switch (true)
    {
        case (count<50):
            $('#count').text("Characters: " + count);
            break;
        case (count>50 && count<60):
            $('#count').css("color","green");
            $('#count').text("Seems like a good length of a summary!");
            break;
        case (count>60 && count<80):
            $('#count').css("color","green");
            $('#count').text("You done ?");
            break;
        case (count>80):
            $('#count').css("color","red");
            $('#count').text("Hey! You can use the description field, it's just below, use it!");
            break;
    }
});
});
</script>
<div id="count"></div>
Summary

/donnib

3 answers

0 votes
JIRA Autobot August 5, 2012

@Lukas Maruniak thank you but i don't quite follow you. I tried reading the link u gave me but i don't see anywhere they discuss atlassian-plugin.xml. Is that a file i need to create ? How do i link the JavaScript with the summary field ?

Lukas Maruniak August 12, 2012

Well, it's the main descpriptor file in which are defined all plugin modules which you created.

I think this could be helpfull for you -> https://developer.atlassian.com/display/DOCS/Set+up+the+Atlassian+Plugin+SDK+and+Build+a+Project

0 votes
Lukas Maruniak July 31, 2012

I would like to recommend you to use your javascript as webresource - >

First try to move your js to separate file(e.g. summary.js) :

JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {     
 $('#summary').keyup(function() {
    var text = $(this).val(),
        count = encodeURIComponent(text).replace(/%[A-F\d]{2}/g, 'U').length;
 
switch (true)
    {
        case (count<50):
            $('#count').text("Characters: " + count);
            break;
        case (count>50 && count<60):
            $('#count').css("color","green");
            $('#count').text("Seems like a good length of a summary!");
            break;
        case (count>60 && count<80):
            $('#count').css("color","green");
            $('#count').text("You done ?");
            break;
        case (count>80):
            $('#count').css("color","red");
            $('#count').text("Hey! You can use the description field, it's just below, use it!");
            break;
    }
});
});

And then define it in atlassian-plugin.xml ->

<web-resource name="Resources" key="resources">
        <context>atl.general</context>
        <resource name="summary.js" type="download" location="summary.js"></resource>
    </web-resource>

Lukas Maruniak July 31, 2012

Also there is another event - > JIRA.Events.NEW_PAGE_ADDED - so try it with this also - maybe it's better for your purpose.

0 votes
JIRA Autobot July 30, 2012

No one has an idea ?

Suggest an answer

Log in or Sign up to answer