webapp.html 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <!DOCTYPE>
  2. <html>
  3. <head>
  4. <title></title>
  5. <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
  6. <script type="text/javascript" src="../internal.js"></script>
  7. <style type="text/css">
  8. .wrapper {
  9. width: 540px;
  10. margin: 10px auto;
  11. }
  12. #appShow {
  13. border: 1px solid #ddd;
  14. }
  15. .errorMsg {
  16. font-size: 13px;
  17. margin: 10px;
  18. color: #dd0000
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <div class="wrapper">
  24. <div id="appShow"></div>
  25. </div>
  26. <script type="text/javascript">
  27. //此处配置您在百度上申请到的appkey。
  28. var apikey = editor.options.webAppKey;
  29. if (apikey && apikey.length == 24) {
  30. var searchConfig = {
  31. container: 'appShow', //容器ID
  32. tips: "", //该值用于自动清空
  33. search: 1, //是否显示搜索框
  34. ps: 12, //每页显示的条数
  35. suggest: 1, //是否开启搜索自动完成
  36. limit: 0, //搜索结果显示条数,0表示无限制
  37. searchNow: 0, //是否在初始化完成时立即搜索
  38. apikey: apikey, //每人得
  39. pager: 1,
  40. cid: 7134562,
  41. outputHTML: 1
  42. }, baiduApp;
  43. function clickCallback() {
  44. baiduApp.addEventListener('getAppHTML', function (e, data) {
  45. var url = 'http://app.baidu.com/app/enter?appid=' + data.data['app_id'] + '&tn=app_canvas&app_spce_id=1&apikey=' + apikey + '&api_key=' + apikey;
  46. editor.execCommand("webapp", {url: url, width: data.uniWidth, height: data.uniHeight + 60, logo: data.data['app_logo'], title: data.data['app_name']});
  47. dialog.close();
  48. });
  49. }
  50. var script = document.createElement("script");
  51. script.type = "text/javascript";
  52. script.src = "http://app.baidu.com/appweb/api/search?auto=yes&container=container&apikey=" + apikey + "&instanceName=baiduApp&callback=clickCallback&config=searchConfig";
  53. document.body.appendChild(script);
  54. } else {
  55. $G("appShow").innerHTML = "<p class='errorMsg'>" + lang.tip1 + "<a title='" + lang.anthorApi + "' href='http://app.baidu.com/static/cms/getapikey.html' target='_blank'>" + lang.applyFor + "</a></p><p class='errorMsg'>" + lang.tip2 + "</p>";
  56. }
  57. </script>
  58. </body>
  59. </html>