{"action":"created","comment":{"url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/pulls/comments/59893317","id":59893317,"diff_hunk":"@@ -23,47 +23,110 @@ angular.module('angularPromiseButtons')\n                 var cfg = providerCfg;\n                 var promiseWatcher;\n \n-\n-                function handleLoading(btnEl)\n+                function setLoadingState(btnEl)\n                 {\n                     if (cfg.btnLoadingClass && !cfg.addClassToCurrentBtnOnly) {\n                         btnEl.addClass(cfg.btnLoadingClass);\n                     }\n                     if (cfg.disableBtn && !cfg.disableCurrentBtnOnly) {\n                         btnEl.attr('disabled', 'disabled');\n                     }\n+                    if (cfg.btnLoadingHtml)\n+                    {\n+                        btnEl.html(cfg.btnLoadingHtml);\n+                    }\n+                }\n+\n+                function handleLoadingFinished(btnEl, defaultHtml, onEndFn, onEndConfig)\n+                {\n+                    removeLoadingState(btnEl);\n+                    setFinishedState(btnEl, onEndConfig);\n+\n+                    //OnSuccess or OnError\n+                    if (onEndFn && typeof onEndFn === 'function')\n+                    {\n+                        onEndFn();\n+                    }\n+\n+                    if (cfg.onComplete && typeof cfg.onComplete === 'function')\n+                    {\n+                        cfg.onComplete();\n+                    }\n+\n+                    var waitTime = 0;\n+                    if (onEndConfig && onEndConfig.resultWaitTime && onEndConfig.resultWaitTime >= 0) {\n+                        waitTime = onEndConfig.resultWaitTime;\n+                    }\n+\n+                    return $timeout(function() {\n+                        revertToNormalState(btnEl, defaultHtml, onEndConfig);\n+                    }, waitTime);\n+                }\n+\n+                function setFinishedState(btnEl, onEndConfig)\n+                {\n+                    if (onEndConfig)\n+                    {\n+                        if (onEndConfig.resultHtml)\n+                        {\n+                            btnEl.html(onEndConfig.resultHtml);\n+                        }\n+                        if (onEndConfig.resultCssClass)\n+                        {\n+                            btnEl.addClass(onEndConfig.resultCssClass);\n+                        }\n+                    }\n                 }\n \n-                function handleLoadingFinished(btnEl)\n+                function removeLoadingState(btnEl)\n                 {\n                     if (cfg.btnLoadingClass) {\n                         btnEl.removeClass(cfg.btnLoadingClass);\n                     }\n+                }\n+\n+                function revertToNormalState(btnEl, defaultHtml, onEndConfig)\n+                {\n                     if (cfg.disableBtn) {\n                         btnEl.removeAttr('disabled');\n                     }\n+                    if (defaultHtml) {\n+                        btnEl.html(defaultHtml);\n+                    }\n+                    if (onEndConfig && onEndConfig.resultCssClass)\n+                    {\n+                        btnEl.removeClass(onEndConfig.resultCssClass);\n+                    }\n                 }\n \n                 function initPromiseWatcher(watchExpressionForPromise, btnEl)\n                 {\n                     // watch promise to resolve or fail\n                     scope.$watch(watchExpressionForPromise, function (mVal)\n                     {\n+                        var initPromise = null;\n                         // for regular promises\n-                        if (mVal && mVal.then) {\n-                            handleLoading(btnEl);\n-                            mVal.finally(function ()\n-                            {\n-                                handleLoadingFinished(btnEl);\n-                            });\n+                        if (mVal && mVal.then)\n+                        {\n+                            initPromise = mVal;\n                         }\n                         // for $resource\n-                        else if (mVal && mVal.$promise) {\n-                            handleLoading(btnEl);\n-                            mVal.$promise.finally(function ()\n-                            {\n-                                handleLoadingFinished(btnEl);\n-                            });\n+                        else if (mVal && mVal.$promise)\n+                        {\n+                            initPromise = mVal.$promise;\n+                        }\n+\n+                        if (initPromise)\n+                        {\n+                            var defaultHtml = cfg.defaultHtml || btnEl.html();\n+                            setLoadingState(btnEl);\n+                            initPromise.then(","path":"dist/angular-promise-buttons.js","position":125,"original_position":125,"commit_id":"46d0bf5b92e3e16109853ccc9df0f69b98e1434b","original_commit_id":"ad1d302b2cdd708abe96c9bb4ef4031b3923b9be","user":{"login":"NewDark90","id":12650208,"avatar_url":"https://avatars.githubusercontent.com/u/12650208?v=3","gravatar_id":"","url":"https://api.github.com/users/NewDark90","html_url":"https://github.com/NewDark90","followers_url":"https://api.github.com/users/NewDark90/followers","following_url":"https://api.github.com/users/NewDark90/following{/other_user}","gists_url":"https://api.github.com/users/NewDark90/gists{/gist_id}","starred_url":"https://api.github.com/users/NewDark90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NewDark90/subscriptions","organizations_url":"https://api.github.com/users/NewDark90/orgs","repos_url":"https://api.github.com/users/NewDark90/repos","events_url":"https://api.github.com/users/NewDark90/events{/privacy}","received_events_url":"https://api.github.com/users/NewDark90/received_events","type":"User","site_admin":false},"body":"They should be. \r\n\r\nIf you look at the interface for a promise from angular.d.ts, it shows that .then, .catch, and finally are always defined. \r\n\r\ninterface IPromise<T> {\r\n        /**\r\n         * Regardless of when the promise was or will be resolved or rejected, then calls one of the success or error callbacks asynchronously as soon as the result is available. The callbacks are called with a single argument: the result or rejection reason. Additionally, the notify callback may be called zero or more times to provide a progress indication, before the promise is resolved or rejected.\r\n         * The successCallBack may return IPromise<void> for when a $q.reject() needs to be returned\r\n         * This method returns a new promise which is resolved or rejected via the return value of the successCallback, errorCallback. It also notifies via the return value of the notifyCallback method. The promise can not be resolved or rejected from the notifyCallback method.\r\n         */\r\n        then<TResult>(successCallback: (promiseValue: T) => IHttpPromise<TResult>|IPromise<TResult>|TResult|IPromise<void>, errorCallback?: (reason: any) => any, notifyCallback?: (state: any) => any): IPromise<TResult>;\r\n\r\n        /**\r\n         * Shorthand for promise.then(null, errorCallback)\r\n         */\r\n        catch<TResult>(onRejected: (reason: any) => IHttpPromise<TResult>|IPromise<TResult>|TResult): IPromise<TResult>;\r\n\r\n        /**\r\n         * Allows you to observe either the fulfillment or rejection of a promise, but to do so without modifying the final value. This is useful to release resources or do some clean-up that needs to be done whether the promise was rejected or resolved. See the full specification for more information.\r\n         *\r\n         * Because finally is a reserved word in JavaScript and reserved keywords are not supported as property names by ES3, you'll need to invoke the method like promise['finally'](callback) to make your code IE8 and Android 2.x compatible.\r\n         */\r\n        finally(finallyCallback: () => any): IPromise<T>;\r\n    }","created_at":"2016-04-15T15:33:53Z","updated_at":"2016-04-15T15:33:53Z","html_url":"https://github.com/johannesjo/angular-promise-buttons/pull/15#discussion_r59893317","pull_request_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/pulls/15","_links":{"self":{"href":"https://api.github.com/repos/johannesjo/angular-promise-buttons/pulls/comments/59893317"},"html":{"href":"https://github.com/johannesjo/angular-promise-buttons/pull/15#discussion_r59893317"},"pull_request":{"href":"https://api.github.com/repos/johannesjo/angular-promise-buttons/pulls/15"}}},"pull_request":{"url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/pulls/15","id":66550552,"html_url":"https://github.com/johannesjo/angular-promise-buttons/pull/15","diff_url":"https://github.com/johannesjo/angular-promise-buttons/pull/15.diff","patch_url":"https://github.com/johannesjo/angular-promise-buttons/pull/15.patch","issue_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/issues/15","number":15,"state":"open","locked":false,"title":"Display buttons and loading functions","user":{"login":"NewDark90","id":12650208,"avatar_url":"https://avatars.githubusercontent.com/u/12650208?v=3","gravatar_id":"","url":"https://api.github.com/users/NewDark90","html_url":"https://github.com/NewDark90","followers_url":"https://api.github.com/users/NewDark90/followers","following_url":"https://api.github.com/users/NewDark90/following{/other_user}","gists_url":"https://api.github.com/users/NewDark90/gists{/gist_id}","starred_url":"https://api.github.com/users/NewDark90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NewDark90/subscriptions","organizations_url":"https://api.github.com/users/NewDark90/orgs","repos_url":"https://api.github.com/users/NewDark90/repos","events_url":"https://api.github.com/users/NewDark90/events{/privacy}","received_events_url":"https://api.github.com/users/NewDark90/received_events","type":"User","site_admin":false},"body":"Added messages and delay on success/error of button.\r\nAdded handlers for onSuccess/onError.\r\nAdded in examples","created_at":"2016-04-14T20:43:23Z","updated_at":"2016-04-15T15:33:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c26333d0ae9466a09ef3d063fe6c2eecbef390c1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/pulls/15/commits","review_comments_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/pulls/15/comments","review_comment_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/pulls/comments{/number}","comments_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/issues/15/comments","statuses_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/statuses/46d0bf5b92e3e16109853ccc9df0f69b98e1434b","head":{"label":"NewDark90:Display_Buttons_and_Loading_Functions","ref":"Display_Buttons_and_Loading_Functions","sha":"46d0bf5b92e3e16109853ccc9df0f69b98e1434b","user":{"login":"NewDark90","id":12650208,"avatar_url":"https://avatars.githubusercontent.com/u/12650208?v=3","gravatar_id":"","url":"https://api.github.com/users/NewDark90","html_url":"https://github.com/NewDark90","followers_url":"https://api.github.com/users/NewDark90/followers","following_url":"https://api.github.com/users/NewDark90/following{/other_user}","gists_url":"https://api.github.com/users/NewDark90/gists{/gist_id}","starred_url":"https://api.github.com/users/NewDark90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NewDark90/subscriptions","organizations_url":"https://api.github.com/users/NewDark90/orgs","repos_url":"https://api.github.com/users/NewDark90/repos","events_url":"https://api.github.com/users/NewDark90/events{/privacy}","received_events_url":"https://api.github.com/users/NewDark90/received_events","type":"User","site_admin":false},"repo":{"id":56264138,"name":"angular-promise-buttons","full_name":"NewDark90/angular-promise-buttons","owner":{"login":"NewDark90","id":12650208,"avatar_url":"https://avatars.githubusercontent.com/u/12650208?v=3","gravatar_id":"","url":"https://api.github.com/users/NewDark90","html_url":"https://github.com/NewDark90","followers_url":"https://api.github.com/users/NewDark90/followers","following_url":"https://api.github.com/users/NewDark90/following{/other_user}","gists_url":"https://api.github.com/users/NewDark90/gists{/gist_id}","starred_url":"https://api.github.com/users/NewDark90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NewDark90/subscriptions","organizations_url":"https://api.github.com/users/NewDark90/orgs","repos_url":"https://api.github.com/users/NewDark90/repos","events_url":"https://api.github.com/users/NewDark90/events{/privacy}","received_events_url":"https://api.github.com/users/NewDark90/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/NewDark90/angular-promise-buttons","description":"Chilled loading buttons for AngularJS","fork":true,"url":"https://api.github.com/repos/NewDark90/angular-promise-buttons","forks_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/forks","keys_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/teams","hooks_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/hooks","issue_events_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/issues/events{/number}","events_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/events","assignees_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/assignees{/user}","branches_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/branches{/branch}","tags_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/tags","blobs_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/git/refs{/sha}","trees_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/statuses/{sha}","languages_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/languages","stargazers_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/stargazers","contributors_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/contributors","subscribers_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/subscribers","subscription_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/subscription","commits_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/commits{/sha}","git_commits_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/git/commits{/sha}","comments_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/comments{/number}","issue_comment_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/issues/comments{/number}","contents_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/contents/{+path}","compare_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/merges","archive_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/downloads","issues_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/issues{/number}","pulls_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/pulls{/number}","milestones_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/milestones{/number}","notifications_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/labels{/name}","releases_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/releases{/id}","deployments_url":"https://api.github.com/repos/NewDark90/angular-promise-buttons/deployments","created_at":"2016-04-14T19:22:18Z","updated_at":"2016-04-14T19:22:19Z","pushed_at":"2016-04-14T20:41:46Z","git_url":"git://github.com/NewDark90/angular-promise-buttons.git","ssh_url":"git@github.com:NewDark90/angular-promise-buttons.git","clone_url":"https://github.com/NewDark90/angular-promise-buttons.git","svn_url":"https://github.com/NewDark90/angular-promise-buttons","homepage":"http://johannesjo.github.io/angular-promise-buttons/","size":1892,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"johannesjo:master","ref":"master","sha":"3cd88363ccc4b99d36838b97d465e2d98ad82491","user":{"login":"johannesjo","id":1456265,"avatar_url":"https://avatars.githubusercontent.com/u/1456265?v=3","gravatar_id":"","url":"https://api.github.com/users/johannesjo","html_url":"https://github.com/johannesjo","followers_url":"https://api.github.com/users/johannesjo/followers","following_url":"https://api.github.com/users/johannesjo/following{/other_user}","gists_url":"https://api.github.com/users/johannesjo/gists{/gist_id}","starred_url":"https://api.github.com/users/johannesjo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johannesjo/subscriptions","organizations_url":"https://api.github.com/users/johannesjo/orgs","repos_url":"https://api.github.com/users/johannesjo/repos","events_url":"https://api.github.com/users/johannesjo/events{/privacy}","received_events_url":"https://api.github.com/users/johannesjo/received_events","type":"User","site_admin":false},"repo":{"id":32182282,"name":"angular-promise-buttons","full_name":"johannesjo/angular-promise-buttons","owner":{"login":"johannesjo","id":1456265,"avatar_url":"https://avatars.githubusercontent.com/u/1456265?v=3","gravatar_id":"","url":"https://api.github.com/users/johannesjo","html_url":"https://github.com/johannesjo","followers_url":"https://api.github.com/users/johannesjo/followers","following_url":"https://api.github.com/users/johannesjo/following{/other_user}","gists_url":"https://api.github.com/users/johannesjo/gists{/gist_id}","starred_url":"https://api.github.com/users/johannesjo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johannesjo/subscriptions","organizations_url":"https://api.github.com/users/johannesjo/orgs","repos_url":"https://api.github.com/users/johannesjo/repos","events_url":"https://api.github.com/users/johannesjo/events{/privacy}","received_events_url":"https://api.github.com/users/johannesjo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/johannesjo/angular-promise-buttons","description":"Chilled loading buttons for AngularJS","fork":false,"url":"https://api.github.com/repos/johannesjo/angular-promise-buttons","forks_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/forks","keys_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/keys{/key_id}","collaborators_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/teams","hooks_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/hooks","issue_events_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/issues/events{/number}","events_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/events","assignees_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/assignees{/user}","branches_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/branches{/branch}","tags_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/tags","blobs_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/git/refs{/sha}","trees_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/git/trees{/sha}","statuses_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/statuses/{sha}","languages_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/languages","stargazers_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/stargazers","contributors_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/contributors","subscribers_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/subscribers","subscription_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/subscription","commits_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/commits{/sha}","git_commits_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/git/commits{/sha}","comments_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/comments{/number}","issue_comment_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/issues/comments{/number}","contents_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/contents/{+path}","compare_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/compare/{base}...{head}","merges_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/merges","archive_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/downloads","issues_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/issues{/number}","pulls_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/pulls{/number}","milestones_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/milestones{/number}","notifications_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/labels{/name}","releases_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/releases{/id}","deployments_url":"https://api.github.com/repos/johannesjo/angular-promise-buttons/deployments","created_at":"2015-03-13T21:41:38Z","updated_at":"2016-04-13T18:54:58Z","pushed_at":"2016-04-15T14:21:48Z","git_url":"git://github.com/johannesjo/angular-promise-buttons.git","ssh_url":"git@github.com:johannesjo/angular-promise-buttons.git","clone_url":"https://github.com/johannesjo/angular-promise-buttons.git","svn_url":"https://github.com/johannesjo/angular-promise-buttons","homepage":"http://johannesjo.github.io/angular-promise-buttons/","size":1897,"stargazers_count":68,"watchers_count":68,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":5,"mirror_url":null,"open_issues_count":3,"forks":5,"open_issues":3,"watchers":68,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/johannesjo/angular-promise-buttons/pulls/15"},"html":{"href":"https://github.com/johannesjo/angular-promise-buttons/pull/15"},"issue":{"href":"https://api.github.com/repos/johannesjo/angular-promise-buttons/issues/15"},"comments":{"href":"https://api.github.com/repos/johannesjo/angular-promise-buttons/issues/15/comments"},"review_comments":{"href":"https://api.github.com/repos/johannesjo/angular-promise-buttons/pulls/15/comments"},"review_comment":{"href":"https://api.github.com/repos/johannesjo/angular-promise-buttons/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/johannesjo/angular-promise-buttons/pulls/15/commits"},"statuses":{"href":"https://api.github.com/repos/johannesjo/angular-promise-buttons/statuses/46d0bf5b92e3e16109853ccc9df0f69b98e1434b"}}}}