diff --git a/manifest.json b/manifest.json index 0585b13..61727ce 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name": "Pivotate", - "version": "1.4", + "version": "1.9", "description": "Submit to Pivotal Tracker with screenshot", "background": { "persistent": false, @@ -15,7 +15,7 @@ "48" :"icon-48.png", "16" :"icon-16.png" }, - "permissions": [ "http://*/", "https://*/", "https://www.pivotaltracker.com/services/v3/*", "tabs" ], + "permissions": [ "", "http://*/", "https://*/", "https://www.pivotaltracker.com/services/v3/*", "tabs" ], "manifest_version": 2, "content_security_policy": "script-src 'self' https://ssl.google-analytics.com; object-src 'self'" } diff --git a/pivotate.html b/pivotate.html index 518bec2..d56b43b 100644 --- a/pivotate.html +++ b/pivotate.html @@ -63,7 +63,6 @@

- \ No newline at end of file diff --git a/pivotate.js b/pivotate.js index 11ef368..5d2fb47 100644 --- a/pivotate.js +++ b/pivotate.js @@ -9,201 +9,195 @@ window.addEventListener("load", function() { }, false); var pivotate = { - load : function(params) { + + load : function( params ) { - var self = this - - var project = document.querySelector( "#project" ), - icons = document.querySelectorAll( '.story .icons > li' ), - canvas = document.querySelector( "#canvas-background" ), - storyType = document.querySelector( "#story_type" ), - action = document.querySelector("#action"), - name = document.querySelector("#name"), - description = document.querySelector("#description"); + var self = this, + project = document.querySelector( "#project" ), + icons = document.querySelectorAll( '.story .icons > li' ), + canvas = document.querySelector( "#canvas-background" ), + storyType = document.querySelector( "#story_type" ), + action = document.querySelector( "#action" ), + name = document.querySelector( "#name" ), + description = document.querySelector( "#description" ); - canvas.setAttribute( "height", (window.innerHeight - 125) + "px" ); - canvas.setAttribute( "width", ( window.innerWidth - 305 ) + "px" ); + canvas.setAttribute( "height", ( window.innerHeight - 125 ) + "px" ); + canvas.setAttribute( "width", ( window.innerWidth - 305 ) + "px" ); - self.formatIMG = new ImgCanvas(canvas); - self.params = params || {}; + self.formatIMG = new ImgCanvas(canvas); + self.params = params || {}; - document.querySelector( "#panel" ).setAttribute( - 'style', - "width: 300px; height: " + ( window.innerHeight - 22 ) + "px" - ); - - self.token.get(function(token) { - self.pivotal = new Pivotal(token); - self.loadProjects(); - }); + document.querySelector( "#panel" ).setAttribute( + 'style', + "width: 300px; height: " + ( window.innerHeight - 22 ) + "px" + ); - document.querySelector("#set-token").addEventListener('click', function() { - self.token.form(); - }); - - document.querySelector("#clean").addEventListener('click', function() { - var screenshot = window.sessionStorage.getItem("img-" + self.params.id); - if (screenshot) { - self.formatIMG.setBackground(screenshot); - } - }); + self.token.get( function( token ) { + self.pivotal = new Pivotal( token ); + self.loadProjects(); + }); - for ( var i = 0, max = icons.length; i < max; i++ ) { - icons[i].addEventListener( 'click', function() { - - for ( var y = 0, max = icons.length; y < max; y++ ) { - var iconDisable = icons[y]; - iconDisable.className = iconDisable.getAttribute( "data-storytype" ); - } - - this.className += " active"; - storyType.value = this.getAttribute( "data-storytype" ); - }); - }; + document.querySelector( "#set-token" ).addEventListener( 'click', function() { + self.token.form(); + }); - action.addEventListener('click', function() { + document.querySelector("#clean").addEventListener('click', function() { + var screenshot = window.sessionStorage.getItem( "img-" + self.params.id ); + if ( screenshot ) { + self.formatIMG.setBackground(screenshot); + } + }); - if (name.value == "" || description.value == "" || storyType.value == "") { - alert('All fields are required'); - return; - } - - this.className += " btn-loading"; - this.setAttribute("disabled", true); - - self.pivotal.addStory({ - name : name.value, - description : description.value, - story_type : storyType.value, - project : project.value - },{ - done: function(result) { - self.pivotal.attachmentStory({ - project : project.value, - storyid : result.childNodes[0].getElementsByTagName("id")[0].textContent, - name : "screen.png", - type : "image/png", - content : atob(self.formatIMG.getImg()) - }, { - done: function() { - alert("The story has been successfully registered."); - window.close(); - }, - fail: function() { - action.className = "btn"; - action.setAttribute("disabled", false); - if (status == 401) { - self.token.form(null, "enter a valid token"); - } else { - alert("An unexpected error occurred, sorry"); + for ( var i = 0, max = icons.length; i < max; i++ ) { + + icons[i].addEventListener( 'click', function() { + for ( var y = 0, max = icons.length; y < max; y++ ) { + var iconDisable = icons[y]; + iconDisable.className = iconDisable.getAttribute( "data-storytype" ); } - } + + this.className += " active"; + storyType.value = this.getAttribute( "data-storytype" ); }); - }, - fail: function() { + }; + + action.addEventListener('click', function() { + + if (name.value == "" || description.value == "" || storyType.value == "") { + alert( 'All fields are required' ); + return; + } - action.className = "btn"; - action.setAttribute("disabled", false); - - alert("An unexpected error occurred, sorry"); - } - }); - }); + this.className += " btn-loading"; + this.setAttribute( "disabled", true ); + + self.pivotal.addStory({ + name : name.value, + description : description.value, + story_type : storyType.value, + project : project.value + },{ + done: function( result ) { + self.pivotal.attachmentStory({ + project : project.value, + storyid : result.childNodes[0].getElementsByTagName("id")[0].textContent, + name : "screen.png", + type : "image/png", + content : atob(self.formatIMG.getImg()) + }, { + done: function() { + alert( "The story has been successfully registered." ); + window.close(); + }, + fail: function() { + action.className = "btn"; + action.setAttribute( "disabled", false ); + if (status == 401) { + self.token.form( null, "enter a valid token") ; + } else { + alert( "An unexpected error occurred, sorry" ); + } + } + }); + }, + fail: function() { + action.className = "btn"; + action.setAttribute( "disabled", false ); + alert( "An unexpected error occurred, sorry" ); + } + }); + }); - var screenshot = window.sessionStorage.getItem("img-" + this.params.id); - if (screenshot) { - this.formatIMG.setBackground(screenshot); - } + var screenshot = window.sessionStorage.getItem( "img-" + this.params.id ); + if ( screenshot ) { + this.formatIMG.setBackground( screenshot ); + } - window.onresize = function() { - var currentImg = self.formatIMG.getDataUrl(); - canvas.setAttribute( "height", (window.innerHeight - 125) + "px" ); - canvas.setAttribute( "width", ( window.innerWidth - 305 ) + "px" ); - self.formatIMG.setBackground(currentImg); - } + window.onresize = function() { + var currentImg = self.formatIMG.getDataUrl(); + canvas.setAttribute( "height", ( window.innerHeight - 125 ) + "px" ); + canvas.setAttribute( "width", ( window.innerWidth - 305 ) + "px" ); + self.formatIMG.setBackground( currentImg ); + } }, - setScreenShot: function(img, id) { - window.sessionStorage.setItem("img-" + id, img); - if (this.formatIMG) { - this.formatIMG.setBackground(img); - } + setScreenShot: function( img, id ) { + window.sessionStorage.setItem( "img-" + id, img ); + if ( this.formatIMG ) { + this.formatIMG.setBackground( img ); + } }, loadProjects: function() { - var self = this, - project = document.querySelector( "#project" ); + var self = this, + project = document.querySelector( "#project" ); - this.pivotal.getProjects({ - done: function(result) { - - result = result.childNodes[0].getElementsByTagName("project"); - for ( var i = 0, max = result.length; i < max; i++ ) { - var option = document.createElement('option'); - option.text = result[i].getElementsByTagName("name")[0].textContent; - option.value = result[i].getElementsByTagName("id")[0].textContent; - project.add( - option, - project.options[project.selectedIndex] - ); - } - }, - fail : function(status, e) { - if (status == 401) { - self.token.form(function(token) { - self.pivotal.setToken(token); - self.loadProjects(); - }, "enter a valid token"); - } else { - alert("An unexpected error occurred, sorry"); - } - } - }); + this.pivotal.getProjects({ + done: function( result ) { + result = result.childNodes[0].getElementsByTagName( "project" ); + for ( var i = 0, max = result.length; i < max; i++ ) { + var option = document.createElement( 'option' ); + option.text = result[i].getElementsByTagName("name")[0].textContent; + option.value = result[i].getElementsByTagName("id")[0].textContent; + project.add( option, project.options[project.selectedIndex] ); + } + }, + fail : function( status, e ) { + if ( status == 401 ) { + self.token.form(function( token ) { + self.pivotal.setToken( token ); + self.loadProjects(); + }, "enter a valid token"); + } else { + alert( "An unexpected error occurred, sorry" ); + } + } + }); }, token : { - form : function(callback, alert) { - - document.querySelector( "#lockscreen" ).style.display = "block"; - document.querySelector( "#show-token" ).style.display = "block"; - if (alert) { - document.querySelector( ".error" ).style.display = "block"; - document.querySelector( ".error" ).innerHTML = alert; - } - document.querySelector( "#save-token" ).addEventListener('click', function() { - var token = document.querySelector( "#token" ).value; - if (token == "") { - document.querySelector( ".error" ).style.display = "block"; - return; - } - - if (callback) { - callback(token); - } + form : function( callback, alert ) { + + document.querySelector( "#lockscreen" ).style.display = "block"; + document.querySelector( "#show-token" ).style.display = "block"; - document.querySelector( ".error" ).style.display = "none"; - window.localStorage.setItem("pivotal-api-token", token); - - document.querySelector( "#lockscreen" ).style.display = "none"; - document.querySelector( "#show-token" ).style.display = "none"; - }); - }, + if ( alert ) { + document.querySelector( ".error" ).style.display = "block"; + document.querySelector( ".error" ).innerHTML = alert; + } - get : function(callback) { - var token = window.localStorage.getItem( "pivotal-api-token" ); - if ( !token ) { - this.form(callback); - return; - } - - callback(token); - }, - set: function(token) { - window.localStorage.setItem("pivotal-api-token", token); - } + document.querySelector( "#save-token" ).addEventListener('click', function() { + + var token = document.querySelector( "#token" ).value; + if ( token == "" ) { + document.querySelector( ".error" ).style.display = "block"; + return; + } + + callback && callback( token ); + + document.querySelector( ".error" ).style.display = "none"; + window.localStorage.setItem( "pivotal-api-token", token ); + + document.querySelector( "#lockscreen" ).style.display = "none"; + document.querySelector( "#show-token" ).style.display = "none"; + }); + }, + + get : function( callback ) { + var token = window.localStorage.getItem( "pivotal-api-token" ); + if ( !token ) { + return this.form( callback ); + } + + return callback && callback( token ); + }, + + set: function( token ) { + window.localStorage.setItem( "pivotal-api-token", token ); + } } }; - \ No newline at end of file