cordova_wrapper.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. var pluginObjects = {}
  2. function addPlugin(pluginName, pluginObject) {
  3. pluginObjects[pluginName] = pluginObject
  4. }
  5. function messageHandler(message) {
  6. var received = eval('('+message.data+')')
  7. if (typeof received == 'undefined')
  8. return false
  9. if (typeof received.messageType == 'undefined')
  10. return false
  11. if (received.messageType == "callPluginFunction") {
  12. if (typeof received.plugin == 'undefined' ||
  13. typeof received.func == 'undefined')
  14. return false
  15. execMethod(received.plugin, received.func, received.params)
  16. }
  17. return true
  18. }
  19. function execMethod(pluginName, functionName, params) {
  20. if( typeof pluginObjects[pluginName][functionName] != "function" )
  21. return false
  22. pluginObjects[pluginName][functionName].apply(this, params)
  23. return true
  24. }
  25. function execMethodOld(pluginName, functionName, params) {
  26. if( typeof pluginObjects[pluginName][functionName] != "function" )
  27. return false
  28. var paramsString = JSON.stringify(params)
  29. if (paramsString.charAt(0) == "[")
  30. paramsString = paramsString.substring(1, paramsString.length-1)
  31. eval("pluginObjects[pluginName][functionName]("+paramsString+")")
  32. return true
  33. }