无法使Firepad正常工作

时间:2013-10-19 20:12:03

标签: javascript html firebase codemirror firepad

我创建了一个Firebase(https://mkaminsky.firebaseio.com/),并尝试使用Firepad创建代码协作工具。我创建了这个html文件,如示例中所述(https://github.com/firebase/firepad/blob/master/examples/code.html)。

<!doctype html>
<!-- See http://www.firepad.io/docs/ for detailed embedding docs. -->
   <html>
      <head>
         <meta charset="utf-8" />
         <script src="https://cdn.firebase.com/v0/firebase.js"></script>

         <script src="codemirror/lib/codemirror.js"></script>
         <script src="codemirror/mode/javascript/javascript.js"></script>
         <link rel="stylesheet" href="codemirror/lib/codemirror.css" />

         <script src="firepad.js"></script>
         <link rel="stylesheet" href="firepad.css" />
         <style>
             html { height: 100%; }
             body { margin: 0; height: 100%; position: relative; }
             .firepad {
              position: absolute; left: 0; top: 0; bottom: 0; right: 0; height: auto;
              }
         </style>
   </head>
   <body>
      <button type="button">Test</button> 
      <div id="firepad-container"></div>

      <script>
         //// Initialize Firebase.
         var firepadRef = new Firebase('https://mkaminsky.firebaseio.com/');

         //// Create CodeMirror (with line numbers and the JavaScript mode).
         var codeMirror = CodeMirror(document.getElementById('firepad-container'), {
           lineNumbers: true,
           mode: 'javascript'
         });

         //// Create Firepad.
         var firepad = Firepad.fromCodeMirror(firepadRef, codeMirror);

         //// Initialize contents.
         firepad.on('ready', function() {
           if (firepad.isHistoryEmpty()) {
            firepad.setText('//hello');
           }
         });
    </script>
</body>
</html>

但是,此代码无法正常工作。它显示代码编辑器,带有语法高亮,但不执行“setText('// hello');”方法。放在其中的任何其他命令也不起作用。

此外,该按钮不会显示在html页面中。

我已测试并验证Firebase是否正常运行。

2 个答案:

答案 0 :(得分:0)

isHistoryEmpty()代码是不是只为你运行一次而现在历史记录不是空的?

$ curl  https://mkaminsky.firebaseio.com/.json 
{"users":{"-J6J90xrR-D-XC6WE23F":{"color":"#d5b3ff"}},"history":{"A0":{"a":"-J6HUBET5icmC-yXAkJb","o":["//hello"]}}}

尝试清除firebase或使用新的命名空间作为firepad文档。测试新命名空间的最简单方法是

Firepad.fromCodeMirror(firepadRef.push(), codeMirror);

一直为我运行isHistoryEmpty()分支(在https://cben-sandbox.firebaseio.com/,Chrome和Firefox上测试)。

答案 1 :(得分:0)

很可能缺少CSS格式。根据{{​​3}},添加以下CSS规则:

.firepad {
  width: 700px;
  height: 450px;
  background-color: #f62; /* dark orange background */
}

在CSS样式之前 documentation CSS样式后 Before CSS Styling

相关问题