Skip to content

GuangTianLi/sockpad

 
 

Repository files navigation

sockpad

该项目是将Firepad所依赖的Firebase替换为Socket.io

特性

  • firebase对象替换为socket.io对象
  • 移除headless模式

安装

npm

npm i sockpad

CDN

<head>
  <!-- socket.io -->
  <script src="https://cdn.bootcss.com/socket.io/2.1.1/socket.io.slim.dev.js"></script>

  <!-- CodeMirror -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.17.0/codemirror.js"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.17.0/codemirror.css"/>

  <!-- Firepad -->
  <link rel="stylesheet" href="https://cdn.firebase.com/libs/firepad/1.5.0/firepad.css" />
  <script src="https://cdn.jsdelivr.net/npm/sockpad@1.5.2/dist/firepad.min.js"></script>
</head>

Then, you need to initialize the Firebase SDK and Firepad:

<body onload="init()">
  <div id="firepad"></div>
  <script>
    function init() {
      // 初始化socket.io
      var socket = io('http://localhost');

      // Create CodeMirror (with lineWrapping on).
      var codeMirror = CodeMirror(document.getElementById('firepad'), { lineWrapping: true });

      // Create Firepad (with rich text toolbar and shortcuts enabled).
      var firepad = Firepad.fromCodeMirror(socket, codeMirror,
          { richTextShortcuts: true, richTextToolbar: true, defaultText: 'Hello, World!' });
    }
  </script>
</body>

Firepad Build Status Coverage Status Version

Firepad is an open-source, collaborative code and text editor. It is designed to be embedded inside larger web applications.

Join our Firebase Google Group to ask questions, request features, or share your Firepad apps with the community.

Table of Contents

Getting Started With Firebase

Firepad requires Firebase in order to sync and store data. Firebase is a suite of integrated products designed to help you develop your app, grow your user base, and earn money. You can sign up here for a free account.

Live Demo

Visit firepad.io to see a live demo of Firepad in rich text mode, or the examples page to see it setup for collaborative code editing.

a screenshot of demo.firepad.io including a picture of two cats and a discussion about fonts

Documentation

Firepad supports rich text editing with CodeMirror and code editing via Ace. Check out the detailed setup instructions at firepad.io/docs.

Examples

You can find some Firepad examples here.

Contributing

If you'd like to contribute to Firepad, please first read through our contribution guidelines. Local setup instructions are available here.

Repo Structure

Here are some highlights of the directory structure and notable source files:

  • dist/ - output directory for all files generated by grunt (firepad.js, firepad.min.js, firepad.css, firepad.eot).
  • examples/ - examples of embedding Firepad.
  • font/ - icon font used for rich text toolbar.
  • lib/
    • firepad.js - Entry point for Firepad.
    • text-operation.js, client.js - Heart of the Operation Transformation implementation. Based on ot.js but extended to allow arbitrary attributes on text (for representing rich-text).
    • annotation-list.js - A data model for representing annotations on text (i.e. spans of text with a particular set of attributes).
    • rich-text-codemirror.js - Uses AnnotationList to track annotations on the text and maintain the appropriate set of markers on a CodeMirror instance.
    • firebase-adapter.js - Handles integration with Firebase (appending operations, triggering retries, presence, etc.).
  • test/ - Jasmine tests for Firepad (many of these were borrowed from ot.js).

About

Collaborative Text Editor Powered by socket.io

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 90.3%
  • CSS 7.1%
  • CoffeeScript 2.2%
  • HTML 0.4%