{"__v":5,"_id":"5683c92f4aecbd0d00a465c2","category":{"__v":2,"_id":"5681681330018c0d006bf7ff","pages":["5683c92f4aecbd0d00a465c2","5683e9ed72bb720d0091f64e"],"project":"559a61d2dbcfd20d00710b39","version":"559a61d2dbcfd20d00710b3c","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-12-28T16:49:23.982Z","from_sync":false,"order":13,"slug":"cordova-api-reference","title":"Cordova / PhoneGap SDK Reference"},"parentDoc":null,"project":"559a61d2dbcfd20d00710b39","user":"55a61860249a40190051d941","version":{"__v":23,"_id":"559a61d2dbcfd20d00710b3c","project":"559a61d2dbcfd20d00710b39","createdAt":"2015-07-06T11:09:06.510Z","releaseDate":"2015-07-06T11:09:06.510Z","categories":["559a61d3dbcfd20d00710b3d","55a589ddaaf9cf1900114dd0","55a589e30f354f0d00fd0312","55a589ea80c8a30d00b323cc","55a589f6aaf9cf1900114dd1","55a58d4e80c8a30d00b323e6","55a8e7a227a17d21005251a2","55a93098cf45e1390093f351","55afb085f202b12100cd9e83","55afb22e902fd51700f5f8bf","55afb260902fd51700f5f8c2","55afb28ec8a85321007a5462","55afb294f202b12100cd9e95","55afb29b902fd51700f5f8c5","55afb2a1c8a85321007a5463","55afb2a7902fd51700f5f8c7","55afb2ad902fd51700f5f8c8","55afb2b5902fd51700f5f8ca","55b74b2131bccb190081bedc","55bb441b54f9640d006e6cf2","565711085cb2420d00d70071","5681681330018c0d006bf7ff","588f38b5923d610f00c72dad"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-12-30T12:08:15.390Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":3,"body":"###Action Object\n \nAll action callbacks return the Action Object with the same format. The available action names can be found in \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"detail\\\": {\\n    \\\"action_name\\\": \\\"action_message\\\"\\n  }\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\n###Handle Custom Action\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"//\\n// Method invoked when a custom action is invoked.\\n//\\nMOCA.addCustomActionListener (function (e) {\\n\\te.detail.customAction; // string with custom action\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Handle Simple Message Action\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"//\\n// Method invoked when a message action is invoked.\\n//\\n// args: (false, callback) to allow MOCA to show the experience.\\n//       (true, callback) to prevent MOCA from showing the experience. (No message will be shown)\\n//\\nMOCA.addDisplayAlertListener (false, function (e) {\\n\\te.detail.displayAlert // String with Message to show\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Handle Open URL Action\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"//\\n// Method invoked when an \\\"open url\\\" action is invoked.\\n//\\n// args: (false, callback) to allow MOCA to show the experience.\\n//       (true, callback) to prevent MOCA from showing the experience. (No webview will be shown)\\n//\\nMOCA.addOpenUrlListener (false, function (e) {\\n\\te.detail.openUrl // String with URL\\n});\\n//\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Handle Show HTML Action\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"//\\n// Method invoked when an embedded html action is invoked.\\n//\\n//\\n// args: (false, callback) to allow MOCA to show the experience.\\n//       (true, callback) to prevent MOCA from showing the experience. (No webview will be shown)\\n//\\nMOCA.addShowEmbeddedHtmlListener (false, function (e) {\\n\\te.detail.showEmbeddedHtml // String with embedded HTML\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Handle Video Action\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"//\\n// Method invoked when a video action is invoked.\\n//\\n//\\n// args: (false, callback) to allow MOCA to show the experience.\\n//       (true, callback) to prevent MOCA from showing the experience. (No video will be played)\\n//\\nMOCA.addPlayVideoListener (false, function (e) {\\n\\te.detail.playVideo // String with video URL\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Handle Image Action\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"//\\n// Method invoked when a image action is invoked.\\n//\\n//\\n// args: (false, callback) to allow MOCA to show the experience.\\n//       (true, callback) to prevent MOCA from showing the experience. (No image will be shown)\\n//\\nMOCA.addShowImageListener (false, function (e) {\\n\\te.detail.showImage // String with Image URL\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Handle Passbook Action\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"//\\n// Method invoked when a passbook action is invoked.\\n//\\n//\\n// args: (false, callback) to allow MOCA to show the experience.\\n//       (true, callback) to prevent MOCA from showing the experience. (No passbook will be shown)\\n//\\nMOCA.addAddPassbookListener (false, function (e) {\\n\\te.detail.addPassbook // String with Passbook URL\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Handle Tag Action\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"//\\n// Method invoked when a tag action is invoked.\\n//\\nMOCA.addAddTagListener (function (e) {\\n\\te.detail.addTag // JSONObject with tagName and tagValue\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Handle Sound Action\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"//\\n// Method invoked when a sound action is invoked.\\n//\\n//\\n// args: (false, callback) to allow MOCA to show the experience.\\n//       (true, callback) to prevent MOCA from showing the experience. (No sound will be played)\\n//\\nMOCA.addPlaySoundListener (false, function (e) {\\n\\te.detail.playSound // String with sound path\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"javascript-action-events","type":"basic","title":"Javascript Action Events"}

Javascript Action Events


###Action Object All action callbacks return the Action Object with the same format. The available action names can be found in [block:code] { "codes": [ { "code": "{\n \"detail\": {\n \"action_name\": \"action_message\"\n }\n}", "language": "json" } ] } [/block] ###Handle Custom Action [block:code] { "codes": [ { "code": "//\n// Method invoked when a custom action is invoked.\n//\nMOCA.addCustomActionListener (function (e) {\n\te.detail.customAction; // string with custom action\n});", "language": "javascript" } ] } [/block] ###Handle Simple Message Action [block:code] { "codes": [ { "code": "//\n// Method invoked when a message action is invoked.\n//\n// args: (false, callback) to allow MOCA to show the experience.\n// (true, callback) to prevent MOCA from showing the experience. (No message will be shown)\n//\nMOCA.addDisplayAlertListener (false, function (e) {\n\te.detail.displayAlert // String with Message to show\n});", "language": "javascript" } ] } [/block] ###Handle Open URL Action [block:code] { "codes": [ { "code": "//\n// Method invoked when an \"open url\" action is invoked.\n//\n// args: (false, callback) to allow MOCA to show the experience.\n// (true, callback) to prevent MOCA from showing the experience. (No webview will be shown)\n//\nMOCA.addOpenUrlListener (false, function (e) {\n\te.detail.openUrl // String with URL\n});\n//", "language": "javascript" } ] } [/block] ###Handle Show HTML Action [block:code] { "codes": [ { "code": "//\n// Method invoked when an embedded html action is invoked.\n//\n//\n// args: (false, callback) to allow MOCA to show the experience.\n// (true, callback) to prevent MOCA from showing the experience. (No webview will be shown)\n//\nMOCA.addShowEmbeddedHtmlListener (false, function (e) {\n\te.detail.showEmbeddedHtml // String with embedded HTML\n});", "language": "javascript" } ] } [/block] ###Handle Video Action [block:code] { "codes": [ { "code": "//\n// Method invoked when a video action is invoked.\n//\n//\n// args: (false, callback) to allow MOCA to show the experience.\n// (true, callback) to prevent MOCA from showing the experience. (No video will be played)\n//\nMOCA.addPlayVideoListener (false, function (e) {\n\te.detail.playVideo // String with video URL\n});", "language": "javascript" } ] } [/block] ###Handle Image Action [block:code] { "codes": [ { "code": "//\n// Method invoked when a image action is invoked.\n//\n//\n// args: (false, callback) to allow MOCA to show the experience.\n// (true, callback) to prevent MOCA from showing the experience. (No image will be shown)\n//\nMOCA.addShowImageListener (false, function (e) {\n\te.detail.showImage // String with Image URL\n});", "language": "javascript" } ] } [/block] ###Handle Passbook Action [block:code] { "codes": [ { "code": "//\n// Method invoked when a passbook action is invoked.\n//\n//\n// args: (false, callback) to allow MOCA to show the experience.\n// (true, callback) to prevent MOCA from showing the experience. (No passbook will be shown)\n//\nMOCA.addAddPassbookListener (false, function (e) {\n\te.detail.addPassbook // String with Passbook URL\n});", "language": "javascript" } ] } [/block] ###Handle Tag Action [block:code] { "codes": [ { "code": "//\n// Method invoked when a tag action is invoked.\n//\nMOCA.addAddTagListener (function (e) {\n\te.detail.addTag // JSONObject with tagName and tagValue\n});", "language": "javascript" } ] } [/block] ###Handle Sound Action [block:code] { "codes": [ { "code": "//\n// Method invoked when a sound action is invoked.\n//\n//\n// args: (false, callback) to allow MOCA to show the experience.\n// (true, callback) to prevent MOCA from showing the experience. (No sound will be played)\n//\nMOCA.addPlaySoundListener (false, function (e) {\n\te.detail.playSound // String with sound path\n});", "language": "javascript" } ] } [/block]