Coder Social home page Coder Social logo

szwork2013 / ngmeditor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from icattlecoder/ngmeditor

0.0 3.0 0.0 132 KB

Medium style editor for AngularJS

Home Page: http://icattlecoder.github.io/ngmeditor/

License: Other

JavaScript 71.52% HTML 5.74% Go 3.89% Nginx 0.88% CSS 17.96%

ngmeditor's Introduction

Medium style editor for AngularJs

Features:

  • Header1-6/Bold/Itatic/underline/(un)order list/hr/justfy.

  • Code input supported. Just input ``` at line start, or format it.

  • Tab key supported.

  • Append whitespace to URL to insert link.

  • Drop or select image to insert it, or just paste from clipboard (ff not supported, trying to figure it out), image are saved to QiniuCloud.

Demo: http://icattlecoder.github.io/ngmeditor. Not support insertting image online yet, working on it, you can test it local by implement token api.

TODO

  • IE Support.

Usage

<script type="text/javascript" src="bower_components/angular/angular.js"></script>
<script type="text/javascript" src="bower_components/ng-file-upload/angular-file-upload-shim.js"></script>
<script type="text/javascript" src="bower_components/ng-file-upload/angular-file-upload.js"></script>
<script type="text/javascript" src="src/editor.js"></script>
<link rel="stylesheet" href="src/editor.css">
<link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.css">

<ng-meditor ng-model="content" placeholder="placeholder"></ng-meditor>

ng-file-upload needed for support uploading image.

JS:

//inject ngMeditor directives and services.
angular.module("ieditor", ['angularFileUpload','ngMeditor']);

// config
angular.module("ieditor").run(function ($http, meditorProvider) {
    meditorProvider.config({
    		supportCommands:['justfy', 'bold', 'italic', 'underline', 'H1', 'hr', 'code', 'insertOrderedList', 'eraser', 'image', 'fullscreen'],
            qnConfig: {
                endPoint: 'http://upload.qiniu.com',
                tokenFunc: function () {
                    return $http.post('/token');
                }
            }
        }
    );
})

Support Insert Image

You need implement token API, for example:

package main

import (
	"encoding/json"
	qauth "github.com/qiniu/api/auth/digest"
	qrs "github.com/qiniu/api/rs"
	"log"
	"net/http"
	"os"
	"strconv"
	"time"
)

func generateQiniuUpToken(scope, accessKey, secretKey string, sizeLimit int64) string {

	mac := qauth.Mac{AccessKey: accessKey, SecretKey: []byte(secretKey)}
	policy := qrs.PutPolicy{}
	policy.Scope = scope
	policy.ReturnBody = `{"key": $(key), "mimeType": $(mimeType), "fsize": $(fsize)}`
	policy.FsizeLimit = sizeLimit

	return policy.Token(&mac)
}

func main() {

	accessKey := os.Getenv("accessKey")
	secretKey := os.Getenv("secretKey")

	CDNDomain := "7xip0c.com1.z0.glb.clouddn.com"
	bucket := "ngmeditor"
	fsizeLimit := 1024 * 1024

	mux := http.NewServeMux()
	mux.HandleFunc("/token", func(rw http.ResponseWriter, req *http.Request) {
		encoder := json.NewEncoder(rw)
		key := strconv.FormatInt(time.Now().UnixNano(), 10)
		m := map[string]interface{}{
			"key":   key,
			"token": generateQiniuUpToken(bucket+":"+key, accessKey, secretKey, int64(fsizeLimit)),
			"url":   CDNDomain + "/" + key,
		}
		encoder.Encode(m)
	})
	log.Fatalln(http.ListenAndServe(":8088", mux))
}

ngmeditor's People

Contributors

icattlecoder avatar joebordes avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.