npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng-wysiwyg

v0.6.2

Published

true angular WYSIWYG

Downloads

156

Readme

ngWYSIWYG

Folks, for your judgement and, hopefully, contributions, here is the true angular WYSIWYG. I took images and layout from the tinyeditor, so kudos to Michael Leigeber.

Here is the Demo

Why iFrame?

A real rich text editor must reflect the true stage of the editing content. Any CSS and/or Javascript on the host page must not overide the specifics of the content. Moreover, iframe allows to isolate your security issues (any possible Javascript code in the content may polute your window's scope).

Installation

Requirements

  1. AngularJS1.2.x
  2. Angular Sanitize1.2.x

Bower

$ bower install ngWYSIWYG --save
```

Include the ngWYSIWYG files in your index.html:
````HTML
<link rel="stylesheet" href="bower_components/ngWYSIWYG/dist/editor.min.css" />
<script src="bower_components/ngWYSIWYG/dist/wysiwyg.min.js"></script>
```

Add it as module to your app.js:

````JavaScript
['ngWYSIWYG']

Use it wherever you want:

<wysiwyg-edit content="your_variable"></wysiwyg-edit>

Configuration

You can configure the editor for two options (will extend l8r). First option is if you want to sanitize input from the user and prevent XSS attacks. This option uses angular's $sanitize. The second option will allow to configure toolbar buttons. You will be able to configure which buttons you want to show. Please see example.

angular.module('myApp', ['ngWYSIWYG']).
controller('demoController', ['$scope', '$q', '$timeout', function($scope, $q, $timeout) {
	$scope.your_variable = 'some HTML text here';
	$scope.api = {
		scope: $scope,
		$scope.editorConfig = {
		    sanitize: false,
		    toolbar: [
			{ name: 'basicStyling', items: ['bold', 'italic', 'underline', 'strikethrough', 'subscript', 'superscript', '-', 'leftAlign', 'centerAlign', 'rightAlign', 'blockJustify', '-'] },
			{ name: 'paragraph', items: ['orderedList', 'unorderedList', 'outdent', 'indent', '-'] },
			{ name: 'doers', items: ['removeFormatting', 'undo', 'redo', '-'] },
			{ name: 'colors', items: ['fontColor', 'backgroundColor', '-'] },
			{ name: 'links', items: ['image', 'hr', 'symbols', 'link', 'unlink', '-'] },
			{ name: 'tools', items: ['print', '-'] },
			{ name: 'styling', items: ['font', 'size', 'format'] },
		    ]
		};
	};
}]);
<wysiwyg-edit content="your_variable" config="editorConfig"></wysiwyg-edit>

Custom content style

This option enables you to specify a custom CSS file to be used within the editor (the editable area).

<wysiwyg-edit content="your_variable" config="editorConfig" content-style="some_style.css"></wysiwyg-edit>
```

If you specify a relative path, it is resolved in relation to the URL of the (HTML) file that includes ngWYSIWYG,
NOT relative to ngWYSIWYG itself. In the example above, if the HTML file is hosted at http://www.example.com/wysiwyg.html, 
then the css URL will be resolved to: http://www.example.com/some_style.css.

### Use case

This configuration is useful when you want your editor's content area to show the content exactly like its going to be
show in the destination, without adding inline css to it. For example, let's say that the destination has a black background color
with a white font-color. In this case your some_style.css file would have the following properties:

```CSS
html, body {
    background-color: black;
    color: #ffffff;
}
```

## API

There is an idea on the api functions to delegate some responsibilities to the customer's scope.
The first thing which is implemented is insert image delegation. By default the directive uses a simple prompt function to accept image's url. However,
there is a way to bring up a custom dialog box on the customer's side and return promise.

````JavaScript
angular.module('myApp', ['ngWYSIWYG']).
controller('demoController', ['$scope', '$q', '$timeout', function($scope, $q, $timeout) {
	$scope.your_variable = 'some HTML text here';
	$scope.api = {
		scope: $scope,
		$scope.editorConfig = {
		    sanitize: false,
		    toolbar: [
			{ name: 'basicStyling', items: ['bold', 'italic', 'underline', 'strikethrough', 'subscript', 'superscript', '-', 'leftAlign', 'centerAlign', 'rightAlign', 'blockJustify', '-'] },
			{ name: 'paragraph', items: ['orderedList', 'unorderedList', 'outdent', 'indent', '-'] },
			{ name: 'doers', items: ['removeFormatting', 'undo', 'redo', '-'] },
			{ name: 'colors', items: ['fontColor', 'backgroundColor', '-'] },
			{ name: 'links', items: ['image', 'hr', 'symbols', 'link', 'unlink', '-'] },
			{ name: 'tools', items: ['print', '-'] },
			{ name: 'styling', items: ['font', 'size', 'format'] },
		    ]
		};
		insertImage: function() {
			var deferred = $q.defer();
			$timeout(function() {
				var val = prompt('Enter image url', 'http://');
				if(val) {
					deferred.resolve('<img src="' + val + '" style="width: 30%;">');
				}
				else {
				    deferred.reject(null);
				}
			}, 1000);
			return deferred.promise;
		}
	};
}]);

Make sure you feed the api object to the directive like this:

<wysiwyg-edit content="your_variable" api="api"></wysiwyg-edit>

Simple download (aka git clone/fork)

  1. Include dist/wysiwyg.min.js in your project using script tag.
  2. Include dist/editor.min.js in your project using link tag.
  3. Add dependency to ngWYSIWYG to your app module. Example: angular.module('myApp', ['ngWYSIWYG']).
  4. Add element <wysiwyg-edit content="your_variable"></wysiwyg-edit>.

Maintenance

Roadmap

  • Current cursor/caret position style reflection on the toolbar
  • Material Design
  • Implement tests
  • Look for the Angular 2.0

Issues?

If you find any, please let me know by sumbitting an issue request. I will be working on it actively.

Contributers

Contributions are welcome and special thanks to all the contributions!

License

MIT license