#!/usr/bin/env python
# -*- coding:utf8 -*-
# Copyright (C) 2012 FinalsClub Foundation
-from django.forms import ModelForm, IntegerField, HiddenInput, Form
+from django.forms import ModelForm, IntegerField, HiddenInput, Form, CharField, Textarea
from django.forms import TextInput
from django_filepicker.widgets import FPFileWidget
+from django.template.loader import render_to_string
+from wysihtml5.widgets import RichTextEditor
-from karmaworld.apps.notes.models import Note
+from karmaworld.apps.notes.models import Note, NoteMarkdown
class NoteForm(ModelForm):
+ html = CharField(widget=RichTextEditor)
+
class Meta:
model = Note
- fields = ('name', 'tags',)
+ fields = ('name', 'tags', 'html')
widgets = {
'name': TextInput()
}
-
class NoteDeleteForm(Form):
note = IntegerField(widget=HiddenInput())
-
class FileUploadForm(ModelForm):
auto_id = False
class Meta:
--- /dev/null
+# -*- coding: utf-8 -*-
+from south.utils import datetime_utils as datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding field 'NoteMarkdown.html'
+ db.add_column(u'notes_notemarkdown', 'html',
+ self.gf('django.db.models.fields.TextField')(null=True, blank=True),
+ keep_default=False)
+
+
+ def backwards(self, orm):
+ # Deleting field 'NoteMarkdown.html'
+ db.delete_column(u'notes_notemarkdown', 'html')
+
+
+ models = {
+ u'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ u'auth.permission': {
+ 'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ u'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ u'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ u'courses.course': {
+ 'Meta': {'ordering': "['-file_count', 'school', 'name']", 'unique_together': "(('name', 'school'),)", 'object_name': 'Course'},
+ 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'department': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['courses.Department']", 'null': 'True', 'blank': 'True'}),
+ 'desc': ('django.db.models.fields.TextField', [], {'max_length': '511', 'null': 'True', 'blank': 'True'}),
+ 'file_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'flags': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'instructor_email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
+ 'instructor_name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'professor': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': u"orm['courses.Professor']", 'null': 'True', 'blank': 'True'}),
+ 'school': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['courses.School']", 'null': 'True', 'blank': 'True'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '150', 'null': 'True'}),
+ 'thank_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'updated_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.utcnow'}),
+ 'url': ('django.db.models.fields.URLField', [], {'max_length': '511', 'null': 'True', 'blank': 'True'})
+ },
+ u'courses.department': {
+ 'Meta': {'unique_together': "(('name', 'school'),)", 'object_name': 'Department'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'school': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['courses.School']"}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '150', 'null': 'True'}),
+ 'url': ('django.db.models.fields.URLField', [], {'max_length': '511', 'null': 'True', 'blank': 'True'})
+ },
+ u'courses.professor': {
+ 'Meta': {'unique_together': "(('name', 'email'),)", 'object_name': 'Professor'},
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+ },
+ u'courses.school': {
+ 'Meta': {'ordering': "['-file_count', '-priority', 'name']", 'object_name': 'School'},
+ 'alias': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'facebook_id': ('django.db.models.fields.BigIntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'file_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'hashtag': ('django.db.models.fields.CharField', [], {'max_length': '16', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'location': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'priority': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '150', 'null': 'True'}),
+ 'url': ('django.db.models.fields.URLField', [], {'max_length': '511', 'blank': 'True'}),
+ 'usde_id': ('django.db.models.fields.BigIntegerField', [], {'unique': 'True', 'null': 'True', 'blank': 'True'})
+ },
+ u'licenses.license': {
+ 'Meta': {'object_name': 'License'},
+ 'html': ('django.db.models.fields.TextField', [], {}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'})
+ },
+ u'notes.note': {
+ 'Meta': {'ordering': "['-uploaded_at']", 'unique_together': "(('fp_file', 'upstream_link'),)", 'object_name': 'Note'},
+ 'category': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True', 'blank': 'True'}),
+ 'course': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['courses.Course']"}),
+ 'flags': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'fp_file': ('django_filepicker.models.FPFileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'gdrive_url': ('django.db.models.fields.URLField', [], {'max_length': '1024', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'ip': ('django.db.models.fields.GenericIPAddressField', [], {'max_length': '39', 'null': 'True', 'blank': 'True'}),
+ 'is_hidden': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'license': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['licenses.License']", 'null': 'True', 'blank': 'True'}),
+ 'mimetype': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '255'}),
+ 'text': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'thanks': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+ 'tweeted': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'uploaded_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.utcnow', 'null': 'True'}),
+ 'upstream_link': ('django.db.models.fields.URLField', [], {'max_length': '1024', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']", 'null': 'True', 'on_delete': 'models.SET_NULL', 'blank': 'True'})
+ },
+ u'notes.notemarkdown': {
+ 'Meta': {'object_name': 'NoteMarkdown'},
+ 'html': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'markdown': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'note': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['notes.Note']", 'unique': 'True', 'primary_key': 'True'})
+ },
+ u'notes.useruploadmapping': {
+ 'Meta': {'unique_together': "(('user', 'fp_file'),)", 'object_name': 'UserUploadMapping'},
+ 'fp_file': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"})
+ },
+ u'taggit.tag': {
+ 'Meta': {'object_name': 'Tag'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '100'})
+ },
+ u'taggit.taggeditem': {
+ 'Meta': {'object_name': 'TaggedItem'},
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "u'taggit_taggeditem_tagged_items'", 'to': u"orm['contenttypes.ContentType']"}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'object_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True'}),
+ 'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "u'taggit_taggeditem_items'", 'to': u"orm['taggit.Tag']"})
+ }
+ }
+
+ complete_apps = ['notes']
\ No newline at end of file
--- /dev/null
+# -*- coding: utf-8 -*-
+from south.utils import datetime_utils as datetime
+from south.db import db
+from south.v2 import DataMigration
+from django.db import models
+import markdown
+from notes.models import NoteMarkdown
+
+class Migration(DataMigration):
+
+ def forwards(self, orm):
+ "Write your forwards methods here."
+ # Note: Don't use "from appname.models import ModelName".
+ # Use orm.ModelName to refer to models in this application,
+ # and orm['appname.ModelName'] for models in other applications.
+ for notemarkdown in orm['notes.NoteMarkdown'].objects.exclude(markdown=""):
+ notemarkdown.html = NoteMarkdown.sanitize(markdown.markdown(notemarkdown.markdown))
+ notemarkdown.save()
+
+ def backwards(self, orm):
+ "Write your backwards methods here."
+
+ models = {
+ u'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ u'auth.permission': {
+ 'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ u'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ u'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ u'courses.course': {
+ 'Meta': {'ordering': "['-file_count', 'school', 'name']", 'unique_together': "(('name', 'school'),)", 'object_name': 'Course'},
+ 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'department': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['courses.Department']", 'null': 'True', 'blank': 'True'}),
+ 'desc': ('django.db.models.fields.TextField', [], {'max_length': '511', 'null': 'True', 'blank': 'True'}),
+ 'file_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'flags': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'instructor_email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
+ 'instructor_name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'professor': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': u"orm['courses.Professor']", 'null': 'True', 'blank': 'True'}),
+ 'school': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['courses.School']", 'null': 'True', 'blank': 'True'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '150', 'null': 'True'}),
+ 'thank_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'updated_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.utcnow'}),
+ 'url': ('django.db.models.fields.URLField', [], {'max_length': '511', 'null': 'True', 'blank': 'True'})
+ },
+ u'courses.department': {
+ 'Meta': {'unique_together': "(('name', 'school'),)", 'object_name': 'Department'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'school': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['courses.School']"}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '150', 'null': 'True'}),
+ 'url': ('django.db.models.fields.URLField', [], {'max_length': '511', 'null': 'True', 'blank': 'True'})
+ },
+ u'courses.professor': {
+ 'Meta': {'unique_together': "(('name', 'email'),)", 'object_name': 'Professor'},
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'null': 'True', 'blank': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'})
+ },
+ u'courses.school': {
+ 'Meta': {'ordering': "['-file_count', '-priority', 'name']", 'object_name': 'School'},
+ 'alias': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'facebook_id': ('django.db.models.fields.BigIntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'file_count': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'hashtag': ('django.db.models.fields.CharField', [], {'max_length': '16', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'location': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ 'priority': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '150', 'null': 'True'}),
+ 'url': ('django.db.models.fields.URLField', [], {'max_length': '511', 'blank': 'True'}),
+ 'usde_id': ('django.db.models.fields.BigIntegerField', [], {'unique': 'True', 'null': 'True', 'blank': 'True'})
+ },
+ u'licenses.license': {
+ 'Meta': {'object_name': 'License'},
+ 'html': ('django.db.models.fields.TextField', [], {}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'})
+ },
+ u'notes.note': {
+ 'Meta': {'ordering': "['-uploaded_at']", 'unique_together': "(('fp_file', 'upstream_link'),)", 'object_name': 'Note'},
+ 'category': ('django.db.models.fields.CharField', [], {'max_length': '50', 'null': 'True', 'blank': 'True'}),
+ 'course': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['courses.Course']"}),
+ 'flags': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+ 'fp_file': ('django_filepicker.models.FPFileField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'gdrive_url': ('django.db.models.fields.URLField', [], {'max_length': '1024', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'ip': ('django.db.models.fields.GenericIPAddressField', [], {'max_length': '39', 'null': 'True', 'blank': 'True'}),
+ 'is_hidden': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'license': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['licenses.License']", 'null': 'True', 'blank': 'True'}),
+ 'mimetype': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '255'}),
+ 'text': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'thanks': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+ 'tweeted': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'uploaded_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.utcnow', 'null': 'True'}),
+ 'upstream_link': ('django.db.models.fields.URLField', [], {'max_length': '1024', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']", 'null': 'True', 'on_delete': 'models.SET_NULL', 'blank': 'True'})
+ },
+ u'notes.notemarkdown': {
+ 'Meta': {'object_name': 'NoteMarkdown'},
+ 'html': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'markdown': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
+ 'note': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['notes.Note']", 'unique': 'True', 'primary_key': 'True'})
+ },
+ u'notes.useruploadmapping': {
+ 'Meta': {'unique_together': "(('user', 'fp_file'),)", 'object_name': 'UserUploadMapping'},
+ 'fp_file': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"})
+ },
+ u'taggit.tag': {
+ 'Meta': {'object_name': 'Tag'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '100'})
+ },
+ u'taggit.taggeditem': {
+ 'Meta': {'object_name': 'TaggedItem'},
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "u'taggit_taggeditem_tagged_items'", 'to': u"orm['contenttypes.ContentType']"}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'object_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True'}),
+ 'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "u'taggit_taggeditem_items'", 'to': u"orm['taggit.Tag']"})
+ }
+ }
+
+ complete_apps = ['notes']
+ symmetrical = True
import django_filepicker
from bs4 import BeautifulSoup as BS
from taggit.managers import TaggableManager
+import bleach
+import bleach_whitelist
+import markdown
from karmaworld.apps.courses.models import Course
from karmaworld.apps.licenses.models import License
class NoteMarkdown(models.Model):
note = models.OneToOneField(Note, primary_key=True)
markdown = models.TextField(blank=True, null=True)
+ html = models.TextField(blank=True, null=True)
+
+ @classmethod
+ def sanitize(cls, html):
+ return bleach.clean(html,
+ bleach_whitelist.markdown_tags,
+ bleach_whitelist.markdown_attrs,
+ strip=True)
+
+ def save(self, *args, **kwargs):
+ if self.markdown and not self.html:
+ self.html = markdown.markdown(self.markdown)
+ self.html = NoteMarkdown.sanitize(self.html)
+ super(NoteMarkdown, self).save(*args, **kwargs)
auto_add_check_unique_together(Note)
#!/usr/bin/env python
# -*- coding:utf8 -*-
# Copyright (C) 2012 FinalsClub Foundation
-"""
-"""
-import karmaworld.secret.indexden as secret
-
import datetime
from django.test import TestCase
from karmaworld.apps.notes.search import SearchIndex
-from karmaworld.apps.notes.models import Note
+from karmaworld.apps.notes.models import Note, NoteMarkdown
from karmaworld.apps.courses.models import Course
from karmaworld.apps.courses.models import School
-# Tell SearchIndex to put its entries
-# in a separate index
-secret.testing = True
-
-
class TestNotes(TestCase):
def setUp(self):
self.note.save()
self.assertEqual(self.note.slug, expected)
- expected_url_prefix = u'/marshall-college/archaeology-101/'
+ expected_url_prefix = u'/note/marshall-college/archaeology-101/'
expected_slug = u'lecture-notes-concerning-the-use-of-therefore'
expected = expected_url_prefix + expected_slug
self.note.slug = None
url = self.expected_url_prefix + str(self.note.id)
self.assertEqual(self.note.get_absolute_url(), url)
+
+ def test_note_markdown_rendering(self):
+ rich = NoteMarkdown(note=self.note,
+ markdown="""# This is fun\n[oh](http://yeah.com)""")
+ rich.save()
+ self.assertEquals(rich.html,
+ """<h1>This is fun</h1>\n<p><a href="http://yeah.com">oh</a></p>""")
+
+ def test_note_rich_text_sanitization(self):
+ rich = NoteMarkdown(note=self.note, html="""
+ <script>unsafe</script>
+ <h1 class='obtrusive'>Something</h1>
+ <h2>OK</h2>
+ &
+ ”
+ <a href='javascript:alert("Oh no")'>This stuff</a>
+ <a href='http://google.com'>That guy</a>
+ """)
+
+ rich.save()
+ self.assertEquals(rich.html, u"""
+ unsafe
+ <h1>Something</h1>
+ <h2>OK</h2>
+ &
+ \u201d
+ <a>This stuff</a>
+ <a href="http://google.com">That guy</a>
+ """)
+
context['note_edit_form'] = NoteForm(request.POST)
else:
tags_string = ','.join([str(tag) for tag in note.tags.all()])
- context['note_edit_form'] = NoteForm(initial={'name': note.name,
- 'tags': tags_string})
+ initial = {"name": note.name, "tags": tags_string}
+ try:
+ initial["html"] = note.notemarkdown.html
+ except NoteMarkdown.DoesNotExist:
+ pass
+ print initial
+ context['note_edit_form'] = NoteForm(initial=initial)
context['note_delete_form'] = NoteDeleteForm(initial={'note': note.id})
}
return super(NoteSaveView, self).get_context_data(**context)
+ def get_form_kwargs(self):
+ """
+ Include related notemarkdown.html in form.
+ """
+ kwargs = {"initial": self.get_initial()}
+ try:
+ kwargs["initial"]["html"] = self.object.notemarkdown.html
+ except NoteMarkdown.DoesNotExist:
+ pass
+ if self.request.method in ("POST", "PUT"):
+ kwargs.update({
+ "data": self.request.POST,
+ "files": self.request.FILES,
+ })
+ return kwargs
+
def form_valid(self, form):
""" Actions to take if the submitted form is valid
namely, saving the new data to the existing note object
--- /dev/null
+function initWysihtml5(element) {
+ var editor = new wysihtml5.Editor(element, {
+ toolbar: element.id + "-toolbar",
+ parserRules: wysihtml5ParserRules
+ });
+ editor.on("change", function() { element.value = editor.value; });
+ return editor;
+}
+
+(function() {
+ var elements = document.querySelectorAll("[role='wysihtml5-rich-text']");
+ var elementArr = [];
+ for (var i = 0; i < elements.length; i++) {
+ elementArr.push(elements[i]);
+ }
+ elementArr.forEach(initWysihtml5);
+})();
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+ <link rel="stylesheet" href="/toolbar.css" />
+</head>
+<body>
+
+ <div id="test-toolbar" class='wysihtml5-toolbar'>
+ <a data-wysihtml5-command="bold">bold</a>
+ <a data-wysihtml5-command="italic">italic</a>
+ <a data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="h1">H1</a>
+ <a data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="p">P</a>
+ </div>
+ <textarea id="test" role="wysihtml5-rich-text">This is my <b>rich</b> text.</textarea>
+ <script src="/wysihtml-0.4.17/dist/wysihtml5x-toolbar.min.js"></script>
+ <script src="/wysihtml-0.4.17/parser_rules/advanced_and_extended.js"></script>
+ <script src="/init.js"></script>
+
+</body>
+</html>
--- /dev/null
+.tm_sync.config
+.idea
+.DS_Store
+.DS_Store?
+node_modules
+local_assets
+.tm_properties
--- /dev/null
+*wysihtml5x 0.4.17* (November 6, 2014)
+* Updated rangy and added as node package
+* Updated qUnit for testing
+* Fixes some selection issues with webkit and autolinking
+* Refactored composer.observer for readability
+
+*wysihtml5x 0.4.16* (October 23, 2014)
+* Fix copy being broken for plain/text
+* Change deleting and selection behaviour of uneditable containers
+
+*wysihtml5x 0.4.15* (September 17, 2014)
+* Fixes copying incorrrect source (spans, styles etc.) from texteditor in webkit and adds ability to add separate ruleset for paste cleanup if source origin is editor itself
+
+*wysihtml5x 0.4.14* (September 10, 2014)
+* Adds ability for check_attributes parameter in cleanup rules to define attributes whose name is beginning with string (ex: "data-*")
+* Toolbar buttons active and disabled classes can be configured
+* Paste logic rewrite. Pasted data is now precaught and separate rulesets can be defined for pasted data.
+
+*wysihtml5x 0.4.13* (August 11, 2014)
+* Adds option for parser to keep comments
+* Fixes list insertion problems in IE
+* Fixes some leaking varaibles reduces browser error messages
+* Updates rangy to latest (1.3alpha.20140804)
+
+*wysihtml5x 0.4.12* (July 03, 2014)
+* Fixes some placeholder problems targeting Firefox and Safari.
+
+*wysihtml5x 0.4.11* (July 03, 2014)
+* Tests are now made with up to date Qunit (tanks @Waxolunist)
+* Fixes an error that placeholder will not be displayed when whitespace present in editor
+
+*wysihtml5x 0.4.10* (June 27, 2014)
+* Solve inline formating issues when applying multiple styles
+* Add a special case when deleting into heading with caret
+
+*wysihtml5x 0.4.9* (June 17, 2014)
+* Prevent possible errors when uneditable element is passed through in parser
+* getValue api changed so passing no parameter will parse and remove all possible internals on result. Takes two parameters getValue(true /* parse content */, true /* ensure removal of all internals and selection markers */)
+
+*wysihtml5x 0.4.8* (June 9, 2014)
+*Improvements in list indent outdent handling
+* Add insertBlockQuote command and remove blockquote creation from formatBlock
+
+*wysihtml5x 0.4.7* (June 2, 2014)
+* Fixes mayor bug that prevents deleting some elements.
+
+*wysihtml5x 0.4.6* (June 2, 2014)
+* Added "hasVisibleContent" to parser check methods to clean up empty elements
+* Added list indent and outdent commands
+* TAB key handling is now optional and can be turned off
+* Minor bug fixes
+
+*wysihtml5x 0.4.5* (May 6, 2014)
+* Added "add_style" to parser rules
+* Added function "any" as parser class parameter to pass all classes
+* Some errors fixed
+
+*wysihtml5x 0.4.4* (Apr 25, 2014)
+* Adds TAB key support
+* Improves list handling and adds possibility to create nested lists
+* Improved behaviour of commands that rely on formatInline
+* Added text alignment with style commands (alignLeftStyle, alignRightStyle, alignCenterStyle)
+* Changes to grunt build rather than makefile
+* Updated to newer rangy 1.3alpha
+* Dropped Old Opera 12 support
+* Minor bug fixes
+
+*wysihtml5x 0.4.3* (Mar 02, 2014)
+* Adds command "formatCode"
+* Fixes some IE8 mayor bugs
+
+*wysihtml5x 0.4.2* (Feb 13, 2014)
+* Adds cell selection events "tableselectstart", "tableselectchange"
+* Fixes configuration file issue of overriding link target attribute
+* Add bower support
+
+*wysihtml5x 0.4.1* (Jan 28, 2014)
+* "createTable" command has one additional parameter "tableStyle" accepting CSS string
+* Selecting more than one table cell removes conflicting text selection
+* Table api has now canMerge function for checking if cell merging is allowed on cells selected
+* Method "any" added to Parser rules check_attributes enabling all attributes values to pass
+* Various bugs fixed
+
+*wysihtml5x 0.4.0* (Dec 12, 2013)
+* Changed syntax of background and foreground color with style commands
+* Anchor creting and removing logic changed
+* Default build is without internal toolbar functions and build with "-toolbar" suffix contains default toolbar functions
+
+*wysihtml5x 0.4.0-beta2* (Nov 7, 2013)
+* Support for contenteditable without iframe sandbox when initiated on div instead of textarea
+* Table creation and handling commands added
+* Improved parser with options to: unwrap tag instead of remove, keep defined styles, complex object type definitions for allowing elements.
+* Ability to add uneditable area inside editor text flow (useful when building modules like video tools, advanced image editor etc.)
+* Improved formatblock handling
+* Ability for user to remove formating with only collapsed caret. (without having to select exactly whole text)
+* Minor performance fixes
+* Ability to use inline styles if needed
+
+*wysihtml5 0.3.0* (May 18, 2012)
+
+* Support for query command groups in toolbar
+* Don't overwrite title attribute on img and a tags (thx to @bobanj, #65)
+* Fix copying of attributes (eg. spellcheck="false")
+* Allow toolbar button other than anchors
+* Fix another keyboard issue on Windows (#46)
+* Improve insertUnorderedList and insertOrderedList commands
+* Now possible to specify text of a hyperlink (thx to @jhollingworth, #45)
+
+*wysihtml5 0.3.0 RC 2* (March 29, 2012)
+
+* Changed License from GPL to MIT
+* Now possible to use multiple editors on one page (#20)
+* Fixed random IE error happening when retrieving currentStyle (#21)
+* Fixed Safari context menu issue (#27)
+* Fixed weird issue in Chrome happening when the editor was initialized when the textarea has been inserted dynamically (#15)
+* Fixed issue happening with the polish keyboard layout (#16)
+* Make sure that the editor iframe uses same IE document mode as it's parent
+
+*wysihtml5 0.3.0 RC 1* (February 5, 2012)
+
+* Basic iOS support (thx @javan for bearing with me)
+* Proper undo/redo support for all browsers except IE
+* Added more events: beforecommand:composer, aftercommand:composer, undo:composer, redo:composer, show:dialog, save:dialog, cancel:dialog (thx to @martinnormark)
+* Fixed an annoying text pasting behavior
+* Allow nested toolbar buttons (thx to @kagd)
+* Updated rangy library to version 1.2.2
+* Improve handling of line breaks in list elements for even cleaner HTML output
+* The editor now also copies border-radius styles from the textarea to the rich text element (thx to @henningthies)
+
+*wysihtml5 0.2.0* (July 13, 2011)
+
+* Library agnostic (no Prototype library needed anymore)
--- /dev/null
+module.exports = function(grunt) {
+
+ "use strict";
+
+ // List required source files that will be built into wysihtml5x.js
+ var base = [
+ "src/polyfills.js",
+ "src/wysihtml5.js",
+ "node_modules/rangy/lib/rangy-core.js",
+ "node_modules/rangy/lib/rangy-selectionsaverestore.js",
+ "lib/base/base.js",
+ "src/browser.js",
+ "src/lang/array.js",
+ "src/lang/dispatcher.js",
+ "src/lang/object.js",
+ "src/lang/string.js",
+ "src/dom/auto_link.js",
+ "src/dom/class.js",
+ "src/dom/contains.js",
+ "src/dom/convert_to_list.js",
+ "src/dom/copy_attributes.js",
+ "src/dom/copy_styles.js",
+ "src/dom/delegate.js",
+ "src/dom/dom_node.js",
+ "src/dom/get_as_dom.js",
+ "src/dom/get_parent_element.js",
+ "src/dom/get_style.js",
+ "src/dom/get_textnodes.js",
+ "src/dom/has_element_with_tag_name.js",
+ "src/dom/has_element_with_class_name.js",
+ "src/dom/insert.js",
+ "src/dom/insert_css.js",
+ "src/dom/line_breaks.js",
+ "src/dom/observe.js",
+ "src/dom/parse.js",
+ "src/dom/remove_empty_text_nodes.js",
+ "src/dom/rename_element.js",
+ "src/dom/replace_with_child_nodes.js",
+ "src/dom/resolve_list.js",
+ "src/dom/sandbox.js",
+ "src/dom/contenteditable_area.js",
+ "src/dom/set_attributes.js",
+ "src/dom/set_styles.js",
+ "src/dom/simulate_placeholder.js",
+ "src/dom/text_content.js",
+ "src/dom/get_attribute.js",
+ "src/dom/get_attributes.js",
+ "src/dom/is_loaded_image.js",
+ "src/dom/table.js",
+ "src/dom/query.js",
+ "src/dom/compare_document_position.js",
+ "src/dom/unwrap.js",
+ "src/dom/get_pasted_html.js",
+ "src/quirks/clean_pasted_html.js",
+ "src/quirks/ensure_proper_clearing.js",
+ "src/quirks/get_correct_inner_html.js",
+ "src/quirks/redraw.js",
+ "src/quirks/table_cells_selection.js",
+ "src/quirks/style_parser.js",
+ "src/selection/selection.js",
+ "src/selection/html_applier.js",
+ "src/commands.js",
+ "src/commands/bold.js",
+ "src/commands/createLink.js",
+ "src/commands/removeLink.js",
+ "src/commands/fontSize.js",
+ "src/commands/fontSizeStyle.js",
+ "src/commands/foreColor.js",
+ "src/commands/foreColorStyle.js",
+ "src/commands/bgColorStyle.js",
+ "src/commands/formatBlock.js",
+ "src/commands/formatCode.js",
+ "src/commands/formatInline.js",
+ "src/commands/insertBlockQuote.js",
+ "src/commands/insertHTML.js",
+ "src/commands/insertImage.js",
+ "src/commands/insertLineBreak.js",
+ "src/commands/insertOrderedList.js",
+ "src/commands/insertUnorderedList.js",
+ "src/commands/insertList.js",
+ "src/commands/italic.js",
+ "src/commands/justifyCenter.js",
+ "src/commands/justifyLeft.js",
+ "src/commands/justifyRight.js",
+ "src/commands/justifyFull.js",
+ "src/commands/alignRightStyle.js",
+ "src/commands/alignLeftStyle.js",
+ "src/commands/alignCenterStyle.js",
+ "src/commands/redo.js",
+ "src/commands/underline.js",
+ "src/commands/undo.js",
+ "src/commands/createTable.js",
+ "src/commands/mergeTableCells.js",
+ "src/commands/addTableCells.js",
+ "src/commands/deleteTableCells.js",
+ "src/commands/indentList.js",
+ "src/commands/outdentList.js",
+ "src/undo_manager.js",
+ "src/views/view.js",
+ "src/views/composer.js",
+ "src/views/composer.style.js",
+ "src/views/composer.observe.js",
+ "src/views/synchronizer.js",
+ "src/views/textarea.js",
+ "src/editor.js"
+ ];
+
+ // List of optional source files that will be built to wysihtml5x-toolbar.js
+ var toolbar = [
+ "src/toolbar/dialog.js",
+ "src/toolbar/speech.js",
+ "src/toolbar/toolbar.js",
+ "src/toolbar/dialog_createTable.js",
+ "src/toolbar/dialog_foreColorStyle.js",
+ "src/toolbar/dialog_fontSizeStyle.js"
+ ];
+
+ // Project configuration.
+ grunt.initConfig({
+ pkg: grunt.file.readJSON('package.json'),
+ concat: {
+ options: {
+ separator: ';',
+ process: function(src, filepath) {
+ return src.replace(/@VERSION/g, grunt.config.get('pkg.version'));
+ }
+ },
+ dist: {
+ src: base,
+ dest: 'dist/<%= pkg.name %>.js'
+ },
+ toolbar: {
+ src: base.concat(toolbar),
+ dest: 'dist/<%= pkg.name %>-toolbar.js'
+ }
+ },
+ uglify: {
+ options: {
+ banner: '/*! <%= pkg.name %> - v<%= pkg.version %> (<%= grunt.template.today("yyyy-mm-dd") %>) */\n',
+ sourceMap: true
+ },
+ build: {
+ files: {
+ 'dist/<%= pkg.name %>.min.js': 'dist/<%= pkg.name %>.js',
+ 'dist/<%= pkg.name %>-toolbar.min.js': 'dist/<%= pkg.name %>-toolbar.js'
+ }
+ }
+ }
+ });
+
+ grunt.loadNpmTasks('grunt-contrib-concat');
+ grunt.loadNpmTasks('grunt-contrib-uglify');
+
+ grunt.registerTask('default', ['concat', 'uglify']);
+};
--- /dev/null
+The MIT License (MIT)
+
+Copyright (c) 2012 XING AG
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
--- /dev/null
+# wysihtml5x
+
+wysihtml5x is an extended and less strict approach on xing/wysihtml5 open source rich text editor based on HTML5 technology.
+The code is completely library agnostic: No jQuery, Prototype or similar is required.
+
+This project was initiated and is supported by the [XING AG](https://www.xing.com). Thanks!
+
+## Features
+
+* Auto linking of urls as-you-type
+* Generates valid and semantic HTML5 markup (no `<font>` tags)
+* Can use class-names instead of inline styles
+* Unifies line-break handling across browsers (hitting enter will create `<br>` instead of `<p>` or `<div>`)
+* Auto-parses content inserted via copy & paste (from Word, Powerpoint, PDF, other web pages, ...)
+* Converts invalid or unknown html tags into valid/similar tags
+* Source code view for users with HTML skills
+* Uses sandboxed iframes in order to prevent identity theft through XSS
+* Editor inherits styles and attributes (placeholder, autofocus, ...) from original textarea (you only have to style one element)
+* Speech-input for Chrome
+
+Extended features not present in xing/wysihtml5:
+
+* Can be used without iframe sandbox when initiated on div instead of textarea
+* Blocking of image drag drop in editable is removed
+* Table insertion management and cell merging commands
+* Improved parser with options to: unwrap tag instead of remove, keep defined styles, complex object type definitions for allowing elements.
+* Ability to add uneditable area inside editor text flow (useful when building modules like video tools, advanced image editor etc.)
+* Improved formatblock handling
+* Ability for user to remove formating with only collapsed caret. (without having to select exactly whole text)
+* Improved speed
+* Anchor creting and removing logic changed to more universal
+* Default build is without internal toolbar functions and build with "-toolbar" suffix contains default toolbar functions
+
+## Browser Support
+
+The rich text editing interface is supported in IE8+, FF 3.5+, Safari 4+, Safari on iOS 5+, Opera 11+ and Chrome.
+**Graceful Degradation:** Users with other browsers will see the textarea and are still able to write plain HTML by themselves.
+
+## Companies using wysihtml5
+
+* [Basecamp](http://basecamp.com) - Leading web-based project management and collaboration tool
+* [XING](https://www.xing.com) - Business Social Network with more than 12 million members
+* [Qype](http://www.qype.com) - Largest user-generated local review site in Europe
+* and many more ...
+
+## Research
+
+Before starting wysihtml5 we spent a lot of time investigating the different browsers and their behaviors.
+
+Check this repository: https://github.com/tiff/wysihtml5-tests
+
+A compatibility table for rich text query commands can be found here: http://tifftiff.de/contenteditable/compliance_test.html
+
+A pure native rich text editor with HTML validator and live source preview is here: http://tifftiff.de/contenteditable/editor.html
+
+## Development
+
+wysihtml5 can be built using Grunt. Installation instructions for [Grunt can be found here](http://gruntjs.com/getting-started). Once you have it installed, wysihtml5 can be built by simply running
+
+ grunt
+
+This builds both minified and development versions, including one with toolbar support.
+
+## Contributors
+
+See the [list of contributors here](https://github.com/Edicy/wysihtml5/graphs/contributors).
--- /dev/null
+{
+ "name": "wysihtml5x",
+ "version": "0.4.17",
+ "main": [
+ "dist/wysihtml5x.min.js",
+ "dist/wysihtml5x-toolbar.min.js"
+ ],
+ "dependencies": {
+ },
+ "homepage": "https://github.com/Edicy/wysihtml5",
+ "authors": [
+ "edicy",
+ "xing"
+ ],
+ "description": "wysihtml5x is an extended and less strict approach on xing/wysihtml5 open source rich text editor based on HTML5 technology.",
+ "keywords": [
+ "wysiwyg"
+ ],
+ "license": "MIT",
+ "ignore": [
+ "**/.*",
+ "build",
+ "examples",
+ "test",
+ "Makefile",
+ "src"
+ ]
+}
--- /dev/null
+// TODO: in future try to replace most inline compability checks with polyfills for code readability
+
+// IE8 SUPPORT BLOCK
+// You can compile wuthout all this if IE8 is not needed
+
+// addEventListener, removeEventListener
+// TODO: make usage of wysihtml5.dom.observe obsolete
+(function() {
+ if (!Event.prototype.preventDefault) {
+ Event.prototype.preventDefault=function() {
+ this.returnValue=false;
+ };
+ }
+ if (!Event.prototype.stopPropagation) {
+ Event.prototype.stopPropagation=function() {
+ this.cancelBubble=true;
+ };
+ }
+ if (!Element.prototype.addEventListener) {
+ var eventListeners=[];
+
+ var addEventListener=function(type,listener /*, useCapture (will be ignored) */) {
+ var self=this;
+ var wrapper=function(e) {
+ e.target=e.srcElement;
+ e.currentTarget=self;
+ if (listener.handleEvent) {
+ listener.handleEvent(e);
+ } else {
+ listener.call(self,e);
+ }
+ };
+ if (type=="DOMContentLoaded") {
+ var wrapper2=function(e) {
+ if (document.readyState=="complete") {
+ wrapper(e);
+ }
+ };
+ document.attachEvent("onreadystatechange",wrapper2);
+ eventListeners.push({object:this,type:type,listener:listener,wrapper:wrapper2});
+
+ if (document.readyState=="complete") {
+ var e=new Event();
+ e.srcElement=window;
+ wrapper2(e);
+ }
+ } else {
+ this.attachEvent("on"+type,wrapper);
+ eventListeners.push({object:this,type:type,listener:listener,wrapper:wrapper});
+ }
+ };
+ var removeEventListener=function(type,listener /*, useCapture (will be ignored) */) {
+ var counter=0;
+ while (counter<eventListeners.length) {
+ var eventListener=eventListeners[counter];
+ if (eventListener.object==this && eventListener.type==type && eventListener.listener==listener) {
+ if (type=="DOMContentLoaded") {
+ this.detachEvent("onreadystatechange",eventListener.wrapper);
+ } else {
+ this.detachEvent("on"+type,eventListener.wrapper);
+ }
+ eventListeners.splice(counter, 1);
+ break;
+ }
+ ++counter;
+ }
+ };
+ Element.prototype.addEventListener=addEventListener;
+ Element.prototype.removeEventListener=removeEventListener;
+ if (HTMLDocument) {
+ HTMLDocument.prototype.addEventListener=addEventListener;
+ HTMLDocument.prototype.removeEventListener=removeEventListener;
+ }
+ if (Window) {
+ Window.prototype.addEventListener=addEventListener;
+ Window.prototype.removeEventListener=removeEventListener;
+ }
+ }
+})();
+
+// element.textContent polyfill.
+if (Object.defineProperty && Object.getOwnPropertyDescriptor && Object.getOwnPropertyDescriptor(Element.prototype, "textContent") && !Object.getOwnPropertyDescriptor(Element.prototype, "textContent").get) {
+ (function() {
+ var innerText = Object.getOwnPropertyDescriptor(Element.prototype, "innerText");
+ Object.defineProperty(Element.prototype, "textContent",
+ {
+ get: function() {
+ return innerText.get.call(this);
+ },
+ set: function(s) {
+ return innerText.set.call(this, s);
+ }
+ }
+ );
+ })();
+}
+
+// isArray polyfill for ie8
+if(!Array.isArray) {
+ Array.isArray = function(arg) {
+ return Object.prototype.toString.call(arg) === '[object Array]';
+ };
+}
+
+// Function.prototype.bind()
+// TODO: clean the code from variable 'that' as it can be confusing
+if (!Function.prototype.bind) {
+ Function.prototype.bind = function(oThis) {
+ if (typeof this !== 'function') {
+ // closest thing possible to the ECMAScript 5
+ // internal IsCallable function
+ throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
+ }
+
+ var aArgs = Array.prototype.slice.call(arguments, 1),
+ fToBind = this,
+ fNOP = function() {},
+ fBound = function() {
+ return fToBind.apply(this instanceof fNOP && oThis
+ ? this
+ : oThis,
+ aArgs.concat(Array.prototype.slice.call(arguments)));
+ };
+
+ fNOP.prototype = this.prototype;
+ fBound.prototype = new fNOP();
+
+ return fBound;
+ };
+};/**
+ * @license wysihtml5x v0.4.17
+ * https://github.com/Edicy/wysihtml5
+ *
+ * Author: Christopher Blum (https://github.com/tiff)
+ * Secondary author of extended features: Oliver Pulges (https://github.com/pulges)
+ *
+ * Copyright (C) 2012 XING AG
+ * Licensed under the MIT license (MIT)
+ *
+ */
+var wysihtml5 = {
+ version: "0.4.17",
+
+ // namespaces
+ commands: {},
+ dom: {},
+ quirks: {},
+ toolbar: {},
+ lang: {},
+ selection: {},
+ views: {},
+
+ INVISIBLE_SPACE: "\uFEFF",
+ INVISIBLE_SPACE_REG_EXP: /\uFEFF/g,
+
+ EMPTY_FUNCTION: function() {},
+
+ ELEMENT_NODE: 1,
+ TEXT_NODE: 3,
+
+ BACKSPACE_KEY: 8,
+ ENTER_KEY: 13,
+ ESCAPE_KEY: 27,
+ SPACE_KEY: 32,
+ TAB_KEY: 9,
+ DELETE_KEY: 46
+};
+;/**\r
+ * Rangy, a cross-browser JavaScript range and selection library\r
+ * https://github.com/timdown/rangy\r
+ *\r
+ * Copyright 2014, Tim Down\r
+ * Licensed under the MIT license.\r
+ * Version: 1.3.0-alpha.20140921\r
+ * Build date: 21 September 2014\r
+ */\r
+\r
+(function(factory, root) {\r
+ if (typeof define == "function" && define.amd) {\r
+ // AMD. Register as an anonymous module.\r
+ define(factory);\r
+ } else if (typeof module != "undefined" && typeof exports == "object") {\r
+ // Node/CommonJS style\r
+ module.exports = factory();\r
+ } else {\r
+ // No AMD or CommonJS support so we place Rangy in (probably) the global variable\r
+ root.rangy = factory();\r
+ }\r
+})(function() {\r
+\r
+ var OBJECT = "object", FUNCTION = "function", UNDEFINED = "undefined";\r
+\r
+ // Minimal set of properties required for DOM Level 2 Range compliance. Comparison constants such as START_TO_START\r
+ // are omitted because ranges in KHTML do not have them but otherwise work perfectly well. See issue 113.\r
+ var domRangeProperties = ["startContainer", "startOffset", "endContainer", "endOffset", "collapsed",\r
+ "commonAncestorContainer"];\r
+\r
+ // Minimal set of methods required for DOM Level 2 Range compliance\r
+ var domRangeMethods = ["setStart", "setStartBefore", "setStartAfter", "setEnd", "setEndBefore",\r
+ "setEndAfter", "collapse", "selectNode", "selectNodeContents", "compareBoundaryPoints", "deleteContents",\r
+ "extractContents", "cloneContents", "insertNode", "surroundContents", "cloneRange", "toString", "detach"];\r
+\r
+ var textRangeProperties = ["boundingHeight", "boundingLeft", "boundingTop", "boundingWidth", "htmlText", "text"];\r
+\r
+ // Subset of TextRange's full set of methods that we're interested in\r
+ var textRangeMethods = ["collapse", "compareEndPoints", "duplicate", "moveToElementText", "parentElement", "select",\r
+ "setEndPoint", "getBoundingClientRect"];\r
+\r
+ /*----------------------------------------------------------------------------------------------------------------*/\r
+\r
+ // Trio of functions taken from Peter Michaux's article:\r
+ // http://peter.michaux.ca/articles/feature-detection-state-of-the-art-browser-scripting\r
+ function isHostMethod(o, p) {\r
+ var t = typeof o[p];\r
+ return t == FUNCTION || (!!(t == OBJECT && o[p])) || t == "unknown";\r
+ }\r
+\r
+ function isHostObject(o, p) {\r
+ return !!(typeof o[p] == OBJECT && o[p]);\r
+ }\r
+\r
+ function isHostProperty(o, p) {\r
+ return typeof o[p] != UNDEFINED;\r
+ }\r
+\r
+ // Creates a convenience function to save verbose repeated calls to tests functions\r
+ function createMultiplePropertyTest(testFunc) {\r
+ return function(o, props) {\r
+ var i = props.length;\r
+ while (i--) {\r
+ if (!testFunc(o, props[i])) {\r
+ return false;\r
+ }\r
+ }\r
+ return true;\r
+ };\r
+ }\r
+\r
+ // Next trio of functions are a convenience to save verbose repeated calls to previous two functions\r
+ var areHostMethods = createMultiplePropertyTest(isHostMethod);\r
+ var areHostObjects = createMultiplePropertyTest(isHostObject);\r
+ var areHostProperties = createMultiplePropertyTest(isHostProperty);\r
+\r
+ function isTextRange(range) {\r
+ return range && areHostMethods(range, textRangeMethods) && areHostProperties(range, textRangeProperties);\r
+ }\r
+\r
+ function getBody(doc) {\r
+ return isHostObject(doc, "body") ? doc.body : doc.getElementsByTagName("body")[0];\r
+ }\r
+\r
+ var modules = {};\r
+\r
+ var isBrowser = (typeof window != UNDEFINED && typeof document != UNDEFINED);\r
+\r
+ var util = {\r
+ isHostMethod: isHostMethod,\r
+ isHostObject: isHostObject,\r
+ isHostProperty: isHostProperty,\r
+ areHostMethods: areHostMethods,\r
+ areHostObjects: areHostObjects,\r
+ areHostProperties: areHostProperties,\r
+ isTextRange: isTextRange,\r
+ getBody: getBody\r
+ };\r
+\r
+ var api = {\r
+ version: "1.3.0-alpha.20140921",\r
+ initialized: false,\r
+ isBrowser: isBrowser,\r
+ supported: true,\r
+ util: util,\r
+ features: {},\r
+ modules: modules,\r
+ config: {\r
+ alertOnFail: true,\r
+ alertOnWarn: false,\r
+ preferTextRange: false,\r
+ autoInitialize: (typeof rangyAutoInitialize == UNDEFINED) ? true : rangyAutoInitialize\r
+ }\r
+ };\r
+\r
+ function consoleLog(msg) {\r
+ if (typeof console != UNDEFINED && isHostMethod(console, "log")) {\r
+ console.log(msg);\r
+ }\r
+ }\r
+\r
+ function alertOrLog(msg, shouldAlert) {\r
+ if (isBrowser && shouldAlert) {\r
+ alert(msg);\r
+ } else {\r
+ consoleLog(msg);\r
+ }\r
+ }\r
+\r
+ function fail(reason) {\r
+ api.initialized = true;\r
+ api.supported = false;\r
+ alertOrLog("Rangy is not supported in this environment. Reason: " + reason, api.config.alertOnFail);\r
+ }\r
+\r
+ api.fail = fail;\r
+\r
+ function warn(msg) {\r
+ alertOrLog("Rangy warning: " + msg, api.config.alertOnWarn);\r
+ }\r
+\r
+ api.warn = warn;\r
+\r
+ // Add utility extend() method\r
+ var extend;\r
+ if ({}.hasOwnProperty) {\r
+ util.extend = extend = function(obj, props, deep) {\r
+ var o, p;\r
+ for (var i in props) {\r
+ if (props.hasOwnProperty(i)) {\r
+ o = obj[i];\r
+ p = props[i];\r
+ if (deep && o !== null && typeof o == "object" && p !== null && typeof p == "object") {\r
+ extend(o, p, true);\r
+ }\r
+ obj[i] = p;\r
+ }\r
+ }\r
+ // Special case for toString, which does not show up in for...in loops in IE <= 8\r
+ if (props.hasOwnProperty("toString")) {\r
+ obj.toString = props.toString;\r
+ }\r
+ return obj;\r
+ };\r
+\r
+ util.createOptions = function(optionsParam, defaults) {\r
+ var options = {};\r
+ extend(options, defaults);\r
+ if (optionsParam) {\r
+ extend(options, optionsParam);\r
+ }\r
+ return options;\r
+ };\r
+ } else {\r
+ fail("hasOwnProperty not supported");\r
+ }\r
+ \r
+ // Test whether we're in a browser and bail out if not\r
+ if (!isBrowser) {\r
+ fail("Rangy can only run in a browser");\r
+ }\r
+\r
+ // Test whether Array.prototype.slice can be relied on for NodeLists and use an alternative toArray() if not\r
+ (function() {\r
+ var toArray;\r
+\r
+ if (isBrowser) {\r
+ var el = document.createElement("div");\r
+ el.appendChild(document.createElement("span"));\r
+ var slice = [].slice;\r
+ try {\r
+ if (slice.call(el.childNodes, 0)[0].nodeType == 1) {\r
+ toArray = function(arrayLike) {\r
+ return slice.call(arrayLike, 0);\r
+ };\r
+ }\r
+ } catch (e) {}\r
+ }\r
+\r
+ if (!toArray) {\r
+ toArray = function(arrayLike) {\r
+ var arr = [];\r
+ for (var i = 0, len = arrayLike.length; i < len; ++i) {\r
+ arr[i] = arrayLike[i];\r
+ }\r
+ return arr;\r
+ };\r
+ }\r
+\r
+ util.toArray = toArray;\r
+ })();\r
+\r
+ // Very simple event handler wrapper function that doesn't attempt to solve issues such as "this" handling or\r
+ // normalization of event properties\r
+ var addListener;\r
+ if (isBrowser) {\r
+ if (isHostMethod(document, "addEventListener")) {\r
+ addListener = function(obj, eventType, listener) {\r
+ obj.addEventListener(eventType, listener, false);\r
+ };\r
+ } else if (isHostMethod(document, "attachEvent")) {\r
+ addListener = function(obj, eventType, listener) {\r
+ obj.attachEvent("on" + eventType, listener);\r
+ };\r
+ } else {\r
+ fail("Document does not have required addEventListener or attachEvent method");\r
+ }\r
+\r
+ util.addListener = addListener;\r
+ }\r
+\r
+ var initListeners = [];\r
+\r
+ function getErrorDesc(ex) {\r
+ return ex.message || ex.description || String(ex);\r
+ }\r
+\r
+ // Initialization\r
+ function init() {\r
+ if (!isBrowser || api.initialized) {\r
+ return;\r
+ }\r
+ var testRange;\r
+ var implementsDomRange = false, implementsTextRange = false;\r
+\r
+ // First, perform basic feature tests\r
+\r
+ if (isHostMethod(document, "createRange")) {\r
+ testRange = document.createRange();\r
+ if (areHostMethods(testRange, domRangeMethods) && areHostProperties(testRange, domRangeProperties)) {\r
+ implementsDomRange = true;\r
+ }\r
+ }\r
+\r
+ var body = getBody(document);\r
+ if (!body || body.nodeName.toLowerCase() != "body") {\r
+ fail("No body element found");\r
+ return;\r
+ }\r
+\r
+ if (body && isHostMethod(body, "createTextRange")) {\r
+ testRange = body.createTextRange();\r
+ if (isTextRange(testRange)) {\r
+ implementsTextRange = true;\r
+ }\r
+ }\r
+\r
+ if (!implementsDomRange && !implementsTextRange) {\r
+ fail("Neither Range nor TextRange are available");\r
+ return;\r
+ }\r
+\r
+ api.initialized = true;\r
+ api.features = {\r
+ implementsDomRange: implementsDomRange,\r
+ implementsTextRange: implementsTextRange\r
+ };\r
+\r
+ // Initialize modules\r
+ var module, errorMessage;\r
+ for (var moduleName in modules) {\r
+ if ( (module = modules[moduleName]) instanceof Module ) {\r
+ module.init(module, api);\r
+ }\r
+ }\r
+\r
+ // Call init listeners\r
+ for (var i = 0, len = initListeners.length; i < len; ++i) {\r
+ try {\r
+ initListeners[i](api);\r
+ } catch (ex) {\r
+ errorMessage = "Rangy init listener threw an exception. Continuing. Detail: " + getErrorDesc(ex);\r
+ consoleLog(errorMessage);\r
+ }\r
+ }\r
+ }\r
+\r
+ // Allow external scripts to initialize this library in case it's loaded after the document has loaded\r
+ api.init = init;\r
+\r
+ // Execute listener immediately if already initialized\r
+ api.addInitListener = function(listener) {\r
+ if (api.initialized) {\r
+ listener(api);\r
+ } else {\r
+ initListeners.push(listener);\r
+ }\r
+ };\r
+\r
+ var shimListeners = [];\r
+\r
+ api.addShimListener = function(listener) {\r
+ shimListeners.push(listener);\r
+ };\r
+\r
+ function shim(win) {\r
+ win = win || window;\r
+ init();\r
+\r
+ // Notify listeners\r
+ for (var i = 0, len = shimListeners.length; i < len; ++i) {\r
+ shimListeners[i](win);\r
+ }\r
+ }\r
+\r
+ if (isBrowser) {\r
+ api.shim = api.createMissingNativeApi = shim;\r
+ }\r
+\r
+ function Module(name, dependencies, initializer) {\r
+ this.name = name;\r
+ this.dependencies = dependencies;\r
+ this.initialized = false;\r
+ this.supported = false;\r
+ this.initializer = initializer;\r
+ }\r
+\r
+ Module.prototype = {\r
+ init: function() {\r
+ var requiredModuleNames = this.dependencies || [];\r
+ for (var i = 0, len = requiredModuleNames.length, requiredModule, moduleName; i < len; ++i) {\r
+ moduleName = requiredModuleNames[i];\r
+\r
+ requiredModule = modules[moduleName];\r
+ if (!requiredModule || !(requiredModule instanceof Module)) {\r
+ throw new Error("required module '" + moduleName + "' not found");\r
+ }\r
+\r
+ requiredModule.init();\r
+\r
+ if (!requiredModule.supported) {\r
+ throw new Error("required module '" + moduleName + "' not supported");\r
+ }\r
+ }\r
+ \r
+ // Now run initializer\r
+ this.initializer(this);\r
+ },\r
+ \r
+ fail: function(reason) {\r
+ this.initialized = true;\r
+ this.supported = false;\r
+ throw new Error("Module '" + this.name + "' failed to load: " + reason);\r
+ },\r
+\r
+ warn: function(msg) {\r
+ api.warn("Module " + this.name + ": " + msg);\r
+ },\r
+\r
+ deprecationNotice: function(deprecated, replacement) {\r
+ api.warn("DEPRECATED: " + deprecated + " in module " + this.name + "is deprecated. Please use " +\r
+ replacement + " instead");\r
+ },\r
+\r
+ createError: function(msg) {\r
+ return new Error("Error in Rangy " + this.name + " module: " + msg);\r
+ }\r
+ };\r
+ \r
+ function createModule(name, dependencies, initFunc) {\r
+ var newModule = new Module(name, dependencies, function(module) {\r
+ if (!module.initialized) {\r
+ module.initialized = true;\r
+ try {\r
+ initFunc(api, module);\r
+ module.supported = true;\r
+ } catch (ex) {\r
+ var errorMessage = "Module '" + name + "' failed to load: " + getErrorDesc(ex);\r
+ consoleLog(errorMessage);\r
+ if (ex.stack) {\r
+ consoleLog(ex.stack);\r
+ }\r
+ }\r
+ }\r
+ });\r
+ modules[name] = newModule;\r
+ return newModule;\r
+ }\r
+\r
+ api.createModule = function(name) {\r
+ // Allow 2 or 3 arguments (second argument is an optional array of dependencies)\r
+ var initFunc, dependencies;\r
+ if (arguments.length == 2) {\r
+ initFunc = arguments[1];\r
+ dependencies = [];\r
+ } else {\r
+ initFunc = arguments[2];\r
+ dependencies = arguments[1];\r
+ }\r
+\r
+ var module = createModule(name, dependencies, initFunc);\r
+\r
+ // Initialize the module immediately if the core is already initialized\r
+ if (api.initialized && api.supported) {\r
+ module.init();\r
+ }\r
+ };\r
+\r
+ api.createCoreModule = function(name, dependencies, initFunc) {\r
+ createModule(name, dependencies, initFunc);\r
+ };\r
+\r
+ /*----------------------------------------------------------------------------------------------------------------*/\r
+\r
+ // Ensure rangy.rangePrototype and rangy.selectionPrototype are available immediately\r
+\r
+ function RangePrototype() {}\r
+ api.RangePrototype = RangePrototype;\r
+ api.rangePrototype = new RangePrototype();\r
+\r
+ function SelectionPrototype() {}\r
+ api.selectionPrototype = new SelectionPrototype();\r
+\r
+ /*----------------------------------------------------------------------------------------------------------------*/\r
+\r
+ // DOM utility methods used by Rangy
+ api.createCoreModule("DomUtil", [], function(api, module) {
+ var UNDEF = "undefined";
+ var util = api.util;
+
+ // Perform feature tests
+ if (!util.areHostMethods(document, ["createDocumentFragment", "createElement", "createTextNode"])) {
+ module.fail("document missing a Node creation method");
+ }
+
+ if (!util.isHostMethod(document, "getElementsByTagName")) {
+ module.fail("document missing getElementsByTagName method");
+ }
+
+ var el = document.createElement("div");
+ if (!util.areHostMethods(el, ["insertBefore", "appendChild", "cloneNode"] ||
+ !util.areHostObjects(el, ["previousSibling", "nextSibling", "childNodes", "parentNode"]))) {
+ module.fail("Incomplete Element implementation");
+ }
+
+ // innerHTML is required for Range's createContextualFragment method
+ if (!util.isHostProperty(el, "innerHTML")) {
+ module.fail("Element is missing innerHTML property");
+ }
+
+ var textNode = document.createTextNode("test");
+ if (!util.areHostMethods(textNode, ["splitText", "deleteData", "insertData", "appendData", "cloneNode"] ||
+ !util.areHostObjects(el, ["previousSibling", "nextSibling", "childNodes", "parentNode"]) ||
+ !util.areHostProperties(textNode, ["data"]))) {
+ module.fail("Incomplete Text Node implementation");
+ }
+
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ // Removed use of indexOf because of a bizarre bug in Opera that is thrown in one of the Acid3 tests. I haven't been
+ // able to replicate it outside of the test. The bug is that indexOf returns -1 when called on an Array that
+ // contains just the document as a single element and the value searched for is the document.
+ var arrayContains = /*Array.prototype.indexOf ?
+ function(arr, val) {
+ return arr.indexOf(val) > -1;
+ }:*/
+
+ function(arr, val) {
+ var i = arr.length;
+ while (i--) {
+ if (arr[i] === val) {
+ return true;
+ }
+ }
+ return false;
+ };
+
+ // Opera 11 puts HTML elements in the null namespace, it seems, and IE 7 has undefined namespaceURI
+ function isHtmlNamespace(node) {
+ var ns;
+ return typeof node.namespaceURI == UNDEF || ((ns = node.namespaceURI) === null || ns == "http://www.w3.org/1999/xhtml");
+ }
+
+ function parentElement(node) {
+ var parent = node.parentNode;
+ return (parent.nodeType == 1) ? parent : null;
+ }
+
+ function getNodeIndex(node) {
+ var i = 0;
+ while( (node = node.previousSibling) ) {
+ ++i;
+ }
+ return i;
+ }
+
+ function getNodeLength(node) {
+ switch (node.nodeType) {
+ case 7:
+ case 10:
+ return 0;
+ case 3:
+ case 8:
+ return node.length;
+ default:
+ return node.childNodes.length;
+ }
+ }
+
+ function getCommonAncestor(node1, node2) {
+ var ancestors = [], n;
+ for (n = node1; n; n = n.parentNode) {
+ ancestors.push(n);
+ }
+
+ for (n = node2; n; n = n.parentNode) {
+ if (arrayContains(ancestors, n)) {
+ return n;
+ }
+ }
+
+ return null;
+ }
+
+ function isAncestorOf(ancestor, descendant, selfIsAncestor) {
+ var n = selfIsAncestor ? descendant : descendant.parentNode;
+ while (n) {
+ if (n === ancestor) {
+ return true;
+ } else {
+ n = n.parentNode;
+ }
+ }
+ return false;
+ }
+
+ function isOrIsAncestorOf(ancestor, descendant) {
+ return isAncestorOf(ancestor, descendant, true);
+ }
+
+ function getClosestAncestorIn(node, ancestor, selfIsAncestor) {
+ var p, n = selfIsAncestor ? node : node.parentNode;
+ while (n) {
+ p = n.parentNode;
+ if (p === ancestor) {
+ return n;
+ }
+ n = p;
+ }
+ return null;
+ }
+
+ function isCharacterDataNode(node) {
+ var t = node.nodeType;
+ return t == 3 || t == 4 || t == 8 ; // Text, CDataSection or Comment
+ }
+
+ function isTextOrCommentNode(node) {
+ if (!node) {
+ return false;
+ }
+ var t = node.nodeType;
+ return t == 3 || t == 8 ; // Text or Comment
+ }
+
+ function insertAfter(node, precedingNode) {
+ var nextNode = precedingNode.nextSibling, parent = precedingNode.parentNode;
+ if (nextNode) {
+ parent.insertBefore(node, nextNode);
+ } else {
+ parent.appendChild(node);
+ }
+ return node;
+ }
+
+ // Note that we cannot use splitText() because it is bugridden in IE 9.
+ function splitDataNode(node, index, positionsToPreserve) {
+ var newNode = node.cloneNode(false);
+ newNode.deleteData(0, index);
+ node.deleteData(index, node.length - index);
+ insertAfter(newNode, node);
+
+ // Preserve positions
+ if (positionsToPreserve) {
+ for (var i = 0, position; position = positionsToPreserve[i++]; ) {
+ // Handle case where position was inside the portion of node after the split point
+ if (position.node == node && position.offset > index) {
+ position.node = newNode;
+ position.offset -= index;
+ }
+ // Handle the case where the position is a node offset within node's parent
+ else if (position.node == node.parentNode && position.offset > getNodeIndex(node)) {
+ ++position.offset;
+ }
+ }
+ }
+ return newNode;
+ }
+
+ function getDocument(node) {
+ if (node.nodeType == 9) {
+ return node;
+ } else if (typeof node.ownerDocument != UNDEF) {
+ return node.ownerDocument;
+ } else if (typeof node.document != UNDEF) {
+ return node.document;
+ } else if (node.parentNode) {
+ return getDocument(node.parentNode);
+ } else {
+ throw module.createError("getDocument: no document found for node");
+ }
+ }
+
+ function getWindow(node) {
+ var doc = getDocument(node);
+ if (typeof doc.defaultView != UNDEF) {
+ return doc.defaultView;
+ } else if (typeof doc.parentWindow != UNDEF) {
+ return doc.parentWindow;
+ } else {
+ throw module.createError("Cannot get a window object for node");
+ }
+ }
+
+ function getIframeDocument(iframeEl) {
+ if (typeof iframeEl.contentDocument != UNDEF) {
+ return iframeEl.contentDocument;
+ } else if (typeof iframeEl.contentWindow != UNDEF) {
+ return iframeEl.contentWindow.document;
+ } else {
+ throw module.createError("getIframeDocument: No Document object found for iframe element");
+ }
+ }
+
+ function getIframeWindow(iframeEl) {
+ if (typeof iframeEl.contentWindow != UNDEF) {
+ return iframeEl.contentWindow;
+ } else if (typeof iframeEl.contentDocument != UNDEF) {
+ return iframeEl.contentDocument.defaultView;
+ } else {
+ throw module.createError("getIframeWindow: No Window object found for iframe element");
+ }
+ }
+
+ // This looks bad. Is it worth it?
+ function isWindow(obj) {
+ return obj && util.isHostMethod(obj, "setTimeout") && util.isHostObject(obj, "document");
+ }
+
+ function getContentDocument(obj, module, methodName) {
+ var doc;
+
+ if (!obj) {
+ doc = document;
+ }
+
+ // Test if a DOM node has been passed and obtain a document object for it if so
+ else if (util.isHostProperty(obj, "nodeType")) {
+ doc = (obj.nodeType == 1 && obj.tagName.toLowerCase() == "iframe") ?
+ getIframeDocument(obj) : getDocument(obj);
+ }
+
+ // Test if the doc parameter appears to be a Window object
+ else if (isWindow(obj)) {
+ doc = obj.document;
+ }
+
+ if (!doc) {
+ throw module.createError(methodName + "(): Parameter must be a Window object or DOM node");
+ }
+
+ return doc;
+ }
+
+ function getRootContainer(node) {
+ var parent;
+ while ( (parent = node.parentNode) ) {
+ node = parent;
+ }
+ return node;
+ }
+
+ function comparePoints(nodeA, offsetA, nodeB, offsetB) {
+ // See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html#Level-2-Range-Comparing
+ var nodeC, root, childA, childB, n;
+ if (nodeA == nodeB) {
+ // Case 1: nodes are the same
+ return offsetA === offsetB ? 0 : (offsetA < offsetB) ? -1 : 1;
+ } else if ( (nodeC = getClosestAncestorIn(nodeB, nodeA, true)) ) {
+ // Case 2: node C (container B or an ancestor) is a child node of A
+ return offsetA <= getNodeIndex(nodeC) ? -1 : 1;
+ } else if ( (nodeC = getClosestAncestorIn(nodeA, nodeB, true)) ) {
+ // Case 3: node C (container A or an ancestor) is a child node of B
+ return getNodeIndex(nodeC) < offsetB ? -1 : 1;
+ } else {
+ root = getCommonAncestor(nodeA, nodeB);
+ if (!root) {
+ throw new Error("comparePoints error: nodes have no common ancestor");
+ }
+
+ // Case 4: containers are siblings or descendants of siblings
+ childA = (nodeA === root) ? root : getClosestAncestorIn(nodeA, root, true);
+ childB = (nodeB === root) ? root : getClosestAncestorIn(nodeB, root, true);
+
+ if (childA === childB) {
+ // This shouldn't be possible
+ throw module.createError("comparePoints got to case 4 and childA and childB are the same!");
+ } else {
+ n = root.firstChild;
+ while (n) {
+ if (n === childA) {
+ return -1;
+ } else if (n === childB) {
+ return 1;
+ }
+ n = n.nextSibling;
+ }
+ }
+ }
+ }
+
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ // Test for IE's crash (IE 6/7) or exception (IE >= 8) when a reference to garbage-collected text node is queried
+ var crashyTextNodes = false;
+
+ function isBrokenNode(node) {
+ var n;
+ try {
+ n = node.parentNode;
+ return false;
+ } catch (e) {
+ return true;
+ }
+ }
+
+ (function() {
+ var el = document.createElement("b");
+ el.innerHTML = "1";
+ var textNode = el.firstChild;
+ el.innerHTML = "<br>";
+ crashyTextNodes = isBrokenNode(textNode);
+
+ api.features.crashyTextNodes = crashyTextNodes;
+ })();
+
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ function inspectNode(node) {
+ if (!node) {
+ return "[No node]";
+ }
+ if (crashyTextNodes && isBrokenNode(node)) {
+ return "[Broken node]";
+ }
+ if (isCharacterDataNode(node)) {
+ return '"' + node.data + '"';
+ }
+ if (node.nodeType == 1) {
+ var idAttr = node.id ? ' id="' + node.id + '"' : "";
+ return "<" + node.nodeName + idAttr + ">[index:" + getNodeIndex(node) + ",length:" + node.childNodes.length + "][" + (node.innerHTML || "[innerHTML not supported]").slice(0, 25) + "]";
+ }
+ return node.nodeName;
+ }
+
+ function fragmentFromNodeChildren(node) {
+ var fragment = getDocument(node).createDocumentFragment(), child;
+ while ( (child = node.firstChild) ) {
+ fragment.appendChild(child);
+ }
+ return fragment;
+ }
+
+ var getComputedStyleProperty;
+ if (typeof window.getComputedStyle != UNDEF) {
+ getComputedStyleProperty = function(el, propName) {
+ return getWindow(el).getComputedStyle(el, null)[propName];
+ };
+ } else if (typeof document.documentElement.currentStyle != UNDEF) {
+ getComputedStyleProperty = function(el, propName) {
+ return el.currentStyle[propName];
+ };
+ } else {
+ module.fail("No means of obtaining computed style properties found");
+ }
+
+ function NodeIterator(root) {
+ this.root = root;
+ this._next = root;
+ }
+
+ NodeIterator.prototype = {
+ _current: null,
+
+ hasNext: function() {
+ return !!this._next;
+ },
+
+ next: function() {
+ var n = this._current = this._next;
+ var child, next;
+ if (this._current) {
+ child = n.firstChild;
+ if (child) {
+ this._next = child;
+ } else {
+ next = null;
+ while ((n !== this.root) && !(next = n.nextSibling)) {
+ n = n.parentNode;
+ }
+ this._next = next;
+ }
+ }
+ return this._current;
+ },
+
+ detach: function() {
+ this._current = this._next = this.root = null;
+ }
+ };
+
+ function createIterator(root) {
+ return new NodeIterator(root);
+ }
+
+ function DomPosition(node, offset) {
+ this.node = node;
+ this.offset = offset;
+ }
+
+ DomPosition.prototype = {
+ equals: function(pos) {
+ return !!pos && this.node === pos.node && this.offset == pos.offset;
+ },
+
+ inspect: function() {
+ return "[DomPosition(" + inspectNode(this.node) + ":" + this.offset + ")]";
+ },
+
+ toString: function() {
+ return this.inspect();
+ }
+ };
+
+ function DOMException(codeName) {
+ this.code = this[codeName];
+ this.codeName = codeName;
+ this.message = "DOMException: " + this.codeName;
+ }
+
+ DOMException.prototype = {
+ INDEX_SIZE_ERR: 1,
+ HIERARCHY_REQUEST_ERR: 3,
+ WRONG_DOCUMENT_ERR: 4,
+ NO_MODIFICATION_ALLOWED_ERR: 7,
+ NOT_FOUND_ERR: 8,
+ NOT_SUPPORTED_ERR: 9,
+ INVALID_STATE_ERR: 11,
+ INVALID_NODE_TYPE_ERR: 24
+ };
+
+ DOMException.prototype.toString = function() {
+ return this.message;
+ };
+
+ api.dom = {
+ arrayContains: arrayContains,
+ isHtmlNamespace: isHtmlNamespace,
+ parentElement: parentElement,
+ getNodeIndex: getNodeIndex,
+ getNodeLength: getNodeLength,
+ getCommonAncestor: getCommonAncestor,
+ isAncestorOf: isAncestorOf,
+ isOrIsAncestorOf: isOrIsAncestorOf,
+ getClosestAncestorIn: getClosestAncestorIn,
+ isCharacterDataNode: isCharacterDataNode,
+ isTextOrCommentNode: isTextOrCommentNode,
+ insertAfter: insertAfter,
+ splitDataNode: splitDataNode,
+ getDocument: getDocument,
+ getWindow: getWindow,
+ getIframeWindow: getIframeWindow,
+ getIframeDocument: getIframeDocument,
+ getBody: util.getBody,
+ isWindow: isWindow,
+ getContentDocument: getContentDocument,
+ getRootContainer: getRootContainer,
+ comparePoints: comparePoints,
+ isBrokenNode: isBrokenNode,
+ inspectNode: inspectNode,
+ getComputedStyleProperty: getComputedStyleProperty,
+ fragmentFromNodeChildren: fragmentFromNodeChildren,
+ createIterator: createIterator,
+ DomPosition: DomPosition
+ };
+
+ api.DOMException = DOMException;
+ });\r
+\r
+ /*----------------------------------------------------------------------------------------------------------------*/\r
+\r
+ // Pure JavaScript implementation of DOM Range
+ api.createCoreModule("DomRange", ["DomUtil"], function(api, module) {
+ var dom = api.dom;
+ var util = api.util;
+ var DomPosition = dom.DomPosition;
+ var DOMException = api.DOMException;
+
+ var isCharacterDataNode = dom.isCharacterDataNode;
+ var getNodeIndex = dom.getNodeIndex;
+ var isOrIsAncestorOf = dom.isOrIsAncestorOf;
+ var getDocument = dom.getDocument;
+ var comparePoints = dom.comparePoints;
+ var splitDataNode = dom.splitDataNode;
+ var getClosestAncestorIn = dom.getClosestAncestorIn;
+ var getNodeLength = dom.getNodeLength;
+ var arrayContains = dom.arrayContains;
+ var getRootContainer = dom.getRootContainer;
+ var crashyTextNodes = api.features.crashyTextNodes;
+
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ // Utility functions
+
+ function isNonTextPartiallySelected(node, range) {
+ return (node.nodeType != 3) &&
+ (isOrIsAncestorOf(node, range.startContainer) || isOrIsAncestorOf(node, range.endContainer));
+ }
+
+ function getRangeDocument(range) {
+ return range.document || getDocument(range.startContainer);
+ }
+
+ function getBoundaryBeforeNode(node) {
+ return new DomPosition(node.parentNode, getNodeIndex(node));
+ }
+
+ function getBoundaryAfterNode(node) {
+ return new DomPosition(node.parentNode, getNodeIndex(node) + 1);
+ }
+
+ function insertNodeAtPosition(node, n, o) {
+ var firstNodeInserted = node.nodeType == 11 ? node.firstChild : node;
+ if (isCharacterDataNode(n)) {
+ if (o == n.length) {
+ dom.insertAfter(node, n);
+ } else {
+ n.parentNode.insertBefore(node, o == 0 ? n : splitDataNode(n, o));
+ }
+ } else if (o >= n.childNodes.length) {
+ n.appendChild(node);
+ } else {
+ n.insertBefore(node, n.childNodes[o]);
+ }
+ return firstNodeInserted;
+ }
+
+ function rangesIntersect(rangeA, rangeB, touchingIsIntersecting) {
+ assertRangeValid(rangeA);
+ assertRangeValid(rangeB);
+
+ if (getRangeDocument(rangeB) != getRangeDocument(rangeA)) {
+ throw new DOMException("WRONG_DOCUMENT_ERR");
+ }
+
+ var startComparison = comparePoints(rangeA.startContainer, rangeA.startOffset, rangeB.endContainer, rangeB.endOffset),
+ endComparison = comparePoints(rangeA.endContainer, rangeA.endOffset, rangeB.startContainer, rangeB.startOffset);
+
+ return touchingIsIntersecting ? startComparison <= 0 && endComparison >= 0 : startComparison < 0 && endComparison > 0;
+ }
+
+ function cloneSubtree(iterator) {
+ var partiallySelected;
+ for (var node, frag = getRangeDocument(iterator.range).createDocumentFragment(), subIterator; node = iterator.next(); ) {
+ partiallySelected = iterator.isPartiallySelectedSubtree();
+ node = node.cloneNode(!partiallySelected);
+ if (partiallySelected) {
+ subIterator = iterator.getSubtreeIterator();
+ node.appendChild(cloneSubtree(subIterator));
+ subIterator.detach();
+ }
+
+ if (node.nodeType == 10) { // DocumentType
+ throw new DOMException("HIERARCHY_REQUEST_ERR");
+ }
+ frag.appendChild(node);
+ }
+ return frag;
+ }
+
+ function iterateSubtree(rangeIterator, func, iteratorState) {
+ var it, n;
+ iteratorState = iteratorState || { stop: false };
+ for (var node, subRangeIterator; node = rangeIterator.next(); ) {
+ if (rangeIterator.isPartiallySelectedSubtree()) {
+ if (func(node) === false) {
+ iteratorState.stop = true;
+ return;
+ } else {
+ // The node is partially selected by the Range, so we can use a new RangeIterator on the portion of
+ // the node selected by the Range.
+ subRangeIterator = rangeIterator.getSubtreeIterator();
+ iterateSubtree(subRangeIterator, func, iteratorState);
+ subRangeIterator.detach();
+ if (iteratorState.stop) {
+ return;
+ }
+ }
+ } else {
+ // The whole node is selected, so we can use efficient DOM iteration to iterate over the node and its
+ // descendants
+ it = dom.createIterator(node);
+ while ( (n = it.next()) ) {
+ if (func(n) === false) {
+ iteratorState.stop = true;
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ function deleteSubtree(iterator) {
+ var subIterator;
+ while (iterator.next()) {
+ if (iterator.isPartiallySelectedSubtree()) {
+ subIterator = iterator.getSubtreeIterator();
+ deleteSubtree(subIterator);
+ subIterator.detach();
+ } else {
+ iterator.remove();
+ }
+ }
+ }
+
+ function extractSubtree(iterator) {
+ for (var node, frag = getRangeDocument(iterator.range).createDocumentFragment(), subIterator; node = iterator.next(); ) {
+
+ if (iterator.isPartiallySelectedSubtree()) {
+ node = node.cloneNode(false);
+ subIterator = iterator.getSubtreeIterator();
+ node.appendChild(extractSubtree(subIterator));
+ subIterator.detach();
+ } else {
+ iterator.remove();
+ }
+ if (node.nodeType == 10) { // DocumentType
+ throw new DOMException("HIERARCHY_REQUEST_ERR");
+ }
+ frag.appendChild(node);
+ }
+ return frag;
+ }
+
+ function getNodesInRange(range, nodeTypes, filter) {
+ var filterNodeTypes = !!(nodeTypes && nodeTypes.length), regex;
+ var filterExists = !!filter;
+ if (filterNodeTypes) {
+ regex = new RegExp("^(" + nodeTypes.join("|") + ")$");
+ }
+
+ var nodes = [];
+ iterateSubtree(new RangeIterator(range, false), function(node) {
+ if (filterNodeTypes && !regex.test(node.nodeType)) {
+ return;
+ }
+ if (filterExists && !filter(node)) {
+ return;
+ }
+ // Don't include a boundary container if it is a character data node and the range does not contain any
+ // of its character data. See issue 190.
+ var sc = range.startContainer;
+ if (node == sc && isCharacterDataNode(sc) && range.startOffset == sc.length) {
+ return;
+ }
+
+ var ec = range.endContainer;
+ if (node == ec && isCharacterDataNode(ec) && range.endOffset == 0) {
+ return;
+ }
+
+ nodes.push(node);
+ });
+ return nodes;
+ }
+
+ function inspect(range) {
+ var name = (typeof range.getName == "undefined") ? "Range" : range.getName();
+ return "[" + name + "(" + dom.inspectNode(range.startContainer) + ":" + range.startOffset + ", " +
+ dom.inspectNode(range.endContainer) + ":" + range.endOffset + ")]";
+ }
+
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ // RangeIterator code partially borrows from IERange by Tim Ryan (http://github.com/timcameronryan/IERange)
+
+ function RangeIterator(range, clonePartiallySelectedTextNodes) {
+ this.range = range;
+ this.clonePartiallySelectedTextNodes = clonePartiallySelectedTextNodes;
+
+
+ if (!range.collapsed) {
+ this.sc = range.startContainer;
+ this.so = range.startOffset;
+ this.ec = range.endContainer;
+ this.eo = range.endOffset;
+ var root = range.commonAncestorContainer;
+
+ if (this.sc === this.ec && isCharacterDataNode(this.sc)) {
+ this.isSingleCharacterDataNode = true;
+ this._first = this._last = this._next = this.sc;
+ } else {
+ this._first = this._next = (this.sc === root && !isCharacterDataNode(this.sc)) ?
+ this.sc.childNodes[this.so] : getClosestAncestorIn(this.sc, root, true);
+ this._last = (this.ec === root && !isCharacterDataNode(this.ec)) ?
+ this.ec.childNodes[this.eo - 1] : getClosestAncestorIn(this.ec, root, true);
+ }
+ }
+ }
+
+ RangeIterator.prototype = {
+ _current: null,
+ _next: null,
+ _first: null,
+ _last: null,
+ isSingleCharacterDataNode: false,
+
+ reset: function() {
+ this._current = null;
+ this._next = this._first;
+ },
+
+ hasNext: function() {
+ return !!this._next;
+ },
+
+ next: function() {
+ // Move to next node
+ var current = this._current = this._next;
+ if (current) {
+ this._next = (current !== this._last) ? current.nextSibling : null;
+
+ // Check for partially selected text nodes
+ if (isCharacterDataNode(current) && this.clonePartiallySelectedTextNodes) {
+ if (current === this.ec) {
+ (current = current.cloneNode(true)).deleteData(this.eo, current.length - this.eo);
+ }
+ if (this._current === this.sc) {
+ (current = current.cloneNode(true)).deleteData(0, this.so);
+ }
+ }
+ }
+
+ return current;
+ },
+
+ remove: function() {
+ var current = this._current, start, end;
+
+ if (isCharacterDataNode(current) && (current === this.sc || current === this.ec)) {
+ start = (current === this.sc) ? this.so : 0;
+ end = (current === this.ec) ? this.eo : current.length;
+ if (start != end) {
+ current.deleteData(start, end - start);
+ }
+ } else {
+ if (current.parentNode) {
+ current.parentNode.removeChild(current);
+ } else {
+ }
+ }
+ },
+
+ // Checks if the current node is partially selected
+ isPartiallySelectedSubtree: function() {
+ var current = this._current;
+ return isNonTextPartiallySelected(current, this.range);
+ },
+
+ getSubtreeIterator: function() {
+ var subRange;
+ if (this.isSingleCharacterDataNode) {
+ subRange = this.range.cloneRange();
+ subRange.collapse(false);
+ } else {
+ subRange = new Range(getRangeDocument(this.range));
+ var current = this._current;
+ var startContainer = current, startOffset = 0, endContainer = current, endOffset = getNodeLength(current);
+
+ if (isOrIsAncestorOf(current, this.sc)) {
+ startContainer = this.sc;
+ startOffset = this.so;
+ }
+ if (isOrIsAncestorOf(current, this.ec)) {
+ endContainer = this.ec;
+ endOffset = this.eo;
+ }
+
+ updateBoundaries(subRange, startContainer, startOffset, endContainer, endOffset);
+ }
+ return new RangeIterator(subRange, this.clonePartiallySelectedTextNodes);
+ },
+
+ detach: function() {
+ this.range = this._current = this._next = this._first = this._last = this.sc = this.so = this.ec = this.eo = null;
+ }
+ };
+
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ var beforeAfterNodeTypes = [1, 3, 4, 5, 7, 8, 10];
+ var rootContainerNodeTypes = [2, 9, 11];
+ var readonlyNodeTypes = [5, 6, 10, 12];
+ var insertableNodeTypes = [1, 3, 4, 5, 7, 8, 10, 11];
+ var surroundNodeTypes = [1, 3, 4, 5, 7, 8];
+
+ function createAncestorFinder(nodeTypes) {
+ return function(node, selfIsAncestor) {
+ var t, n = selfIsAncestor ? node : node.parentNode;
+ while (n) {
+ t = n.nodeType;
+ if (arrayContains(nodeTypes, t)) {
+ return n;
+ }
+ n = n.parentNode;
+ }
+ return null;
+ };
+ }
+
+ var getDocumentOrFragmentContainer = createAncestorFinder( [9, 11] );
+ var getReadonlyAncestor = createAncestorFinder(readonlyNodeTypes);
+ var getDocTypeNotationEntityAncestor = createAncestorFinder( [6, 10, 12] );
+
+ function assertNoDocTypeNotationEntityAncestor(node, allowSelf) {
+ if (getDocTypeNotationEntityAncestor(node, allowSelf)) {
+ throw new DOMException("INVALID_NODE_TYPE_ERR");
+ }
+ }
+
+ function assertValidNodeType(node, invalidTypes) {
+ if (!arrayContains(invalidTypes, node.nodeType)) {
+ throw new DOMException("INVALID_NODE_TYPE_ERR");
+ }
+ }
+
+ function assertValidOffset(node, offset) {
+ if (offset < 0 || offset > (isCharacterDataNode(node) ? node.length : node.childNodes.length)) {
+ throw new DOMException("INDEX_SIZE_ERR");
+ }
+ }
+
+ function assertSameDocumentOrFragment(node1, node2) {
+ if (getDocumentOrFragmentContainer(node1, true) !== getDocumentOrFragmentContainer(node2, true)) {
+ throw new DOMException("WRONG_DOCUMENT_ERR");
+ }
+ }
+
+ function assertNodeNotReadOnly(node) {
+ if (getReadonlyAncestor(node, true)) {
+ throw new DOMException("NO_MODIFICATION_ALLOWED_ERR");
+ }
+ }
+
+ function assertNode(node, codeName) {
+ if (!node) {
+ throw new DOMException(codeName);
+ }
+ }
+
+ function isOrphan(node) {
+ return (crashyTextNodes && dom.isBrokenNode(node)) ||
+ !arrayContains(rootContainerNodeTypes, node.nodeType) && !getDocumentOrFragmentContainer(node, true);
+ }
+
+ function isValidOffset(node, offset) {
+ return offset <= (isCharacterDataNode(node) ? node.length : node.childNodes.length);
+ }
+
+ function isRangeValid(range) {
+ return (!!range.startContainer && !!range.endContainer &&
+ !isOrphan(range.startContainer) &&
+ !isOrphan(range.endContainer) &&
+ isValidOffset(range.startContainer, range.startOffset) &&
+ isValidOffset(range.endContainer, range.endOffset));
+ }
+
+ function assertRangeValid(range) {
+ if (!isRangeValid(range)) {
+ throw new Error("Range error: Range is no longer valid after DOM mutation (" + range.inspect() + ")");
+ }
+ }
+
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ // Test the browser's innerHTML support to decide how to implement createContextualFragment
+ var styleEl = document.createElement("style");
+ var htmlParsingConforms = false;
+ try {
+ styleEl.innerHTML = "<b>x</b>";
+ htmlParsingConforms = (styleEl.firstChild.nodeType == 3); // Opera incorrectly creates an element node
+ } catch (e) {
+ // IE 6 and 7 throw
+ }
+
+ api.features.htmlParsingConforms = htmlParsingConforms;
+
+ var createContextualFragment = htmlParsingConforms ?
+
+ // Implementation as per HTML parsing spec, trusting in the browser's implementation of innerHTML. See
+ // discussion and base code for this implementation at issue 67.
+ // Spec: http://html5.org/specs/dom-parsing.html#extensions-to-the-range-interface
+ // Thanks to Aleks Williams.
+ function(fragmentStr) {
+ // "Let node the context object's start's node."
+ var node = this.startContainer;
+ var doc = getDocument(node);
+
+ // "If the context object's start's node is null, raise an INVALID_STATE_ERR
+ // exception and abort these steps."
+ if (!node) {
+ throw new DOMException("INVALID_STATE_ERR");
+ }
+
+ // "Let element be as follows, depending on node's interface:"
+ // Document, Document Fragment: null
+ var el = null;
+
+ // "Element: node"
+ if (node.nodeType == 1) {
+ el = node;
+
+ // "Text, Comment: node's parentElement"
+ } else if (isCharacterDataNode(node)) {
+ el = dom.parentElement(node);
+ }
+
+ // "If either element is null or element's ownerDocument is an HTML document
+ // and element's local name is "html" and element's namespace is the HTML
+ // namespace"
+ if (el === null || (
+ el.nodeName == "HTML" &&
+ dom.isHtmlNamespace(getDocument(el).documentElement) &&
+ dom.isHtmlNamespace(el)
+ )) {
+
+ // "let element be a new Element with "body" as its local name and the HTML
+ // namespace as its namespace.""
+ el = doc.createElement("body");
+ } else {
+ el = el.cloneNode(false);
+ }
+
+ // "If the node's document is an HTML document: Invoke the HTML fragment parsing algorithm."
+ // "If the node's document is an XML document: Invoke the XML fragment parsing algorithm."
+ // "In either case, the algorithm must be invoked with fragment as the input
+ // and element as the context element."
+ el.innerHTML = fragmentStr;
+
+ // "If this raises an exception, then abort these steps. Otherwise, let new
+ // children be the nodes returned."
+
+ // "Let fragment be a new DocumentFragment."
+ // "Append all new children to fragment."
+ // "Return fragment."
+ return dom.fragmentFromNodeChildren(el);
+ } :
+
+ // In this case, innerHTML cannot be trusted, so fall back to a simpler, non-conformant implementation that
+ // previous versions of Rangy used (with the exception of using a body element rather than a div)
+ function(fragmentStr) {
+ var doc = getRangeDocument(this);
+ var el = doc.createElement("body");
+ el.innerHTML = fragmentStr;
+
+ return dom.fragmentFromNodeChildren(el);
+ };
+
+ function splitRangeBoundaries(range, positionsToPreserve) {
+ assertRangeValid(range);
+
+ var sc = range.startContainer, so = range.startOffset, ec = range.endContainer, eo = range.endOffset;
+ var startEndSame = (sc === ec);
+
+ if (isCharacterDataNode(ec) && eo > 0 && eo < ec.length) {
+ splitDataNode(ec, eo, positionsToPreserve);
+ }
+
+ if (isCharacterDataNode(sc) && so > 0 && so < sc.length) {
+ sc = splitDataNode(sc, so, positionsToPreserve);
+ if (startEndSame) {
+ eo -= so;
+ ec = sc;
+ } else if (ec == sc.parentNode && eo >= getNodeIndex(sc)) {
+ eo++;
+ }
+ so = 0;
+ }
+ range.setStartAndEnd(sc, so, ec, eo);
+ }
+
+ function rangeToHtml(range) {
+ assertRangeValid(range);
+ var container = range.commonAncestorContainer.parentNode.cloneNode(false);
+ container.appendChild( range.cloneContents() );
+ return container.innerHTML;
+ }
+
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ var rangeProperties = ["startContainer", "startOffset", "endContainer", "endOffset", "collapsed",
+ "commonAncestorContainer"];
+
+ var s2s = 0, s2e = 1, e2e = 2, e2s = 3;
+ var n_b = 0, n_a = 1, n_b_a = 2, n_i = 3;
+
+ util.extend(api.rangePrototype, {
+ compareBoundaryPoints: function(how, range) {
+ assertRangeValid(this);
+ assertSameDocumentOrFragment(this.startContainer, range.startContainer);
+
+ var nodeA, offsetA, nodeB, offsetB;
+ var prefixA = (how == e2s || how == s2s) ? "start" : "end";
+ var prefixB = (how == s2e || how == s2s) ? "start" : "end";
+ nodeA = this[prefixA + "Container"];
+ offsetA = this[prefixA + "Offset"];
+ nodeB = range[prefixB + "Container"];
+ offsetB = range[prefixB + "Offset"];
+ return comparePoints(nodeA, offsetA, nodeB, offsetB);
+ },
+
+ insertNode: function(node) {
+ assertRangeValid(this);
+ assertValidNodeType(node, insertableNodeTypes);
+ assertNodeNotReadOnly(this.startContainer);
+
+ if (isOrIsAncestorOf(node, this.startContainer)) {
+ throw new DOMException("HIERARCHY_REQUEST_ERR");
+ }
+
+ // No check for whether the container of the start of the Range is of a type that does not allow
+ // children of the type of node: the browser's DOM implementation should do this for us when we attempt
+ // to add the node
+
+ var firstNodeInserted = insertNodeAtPosition(node, this.startContainer, this.startOffset);
+ this.setStartBefore(firstNodeInserted);
+ },
+
+ cloneContents: function() {
+ assertRangeValid(this);
+
+ var clone, frag;
+ if (this.collapsed) {
+ return getRangeDocument(this).createDocumentFragment();
+ } else {
+ if (this.startContainer === this.endContainer && isCharacterDataNode(this.startContainer)) {
+ clone = this.startContainer.cloneNode(true);
+ clone.data = clone.data.slice(this.startOffset, this.endOffset);
+ frag = getRangeDocument(this).createDocumentFragment();
+ frag.appendChild(clone);
+ return frag;
+ } else {
+ var iterator = new RangeIterator(this, true);
+ clone = cloneSubtree(iterator);
+ iterator.detach();
+ }
+ return clone;
+ }
+ },
+
+ canSurroundContents: function() {
+ assertRangeValid(this);
+ assertNodeNotReadOnly(this.startContainer);
+ assertNodeNotReadOnly(this.endContainer);
+
+ // Check if the contents can be surrounded. Specifically, this means whether the range partially selects
+ // no non-text nodes.
+ var iterator = new RangeIterator(this, true);
+ var boundariesInvalid = (iterator._first && (isNonTextPartiallySelected(iterator._first, this)) ||
+ (iterator._last && isNonTextPartiallySelected(iterator._last, this)));
+ iterator.detach();
+ return !boundariesInvalid;
+ },
+
+ surroundContents: function(node) {
+ assertValidNodeType(node, surroundNodeTypes);
+
+ if (!this.canSurroundContents()) {
+ throw new DOMException("INVALID_STATE_ERR");
+ }
+
+ // Extract the contents
+ var content = this.extractContents();
+
+ // Clear the children of the node
+ if (node.hasChildNodes()) {
+ while (node.lastChild) {
+ node.removeChild(node.lastChild);
+ }
+ }
+
+ // Insert the new node and add the extracted contents
+ insertNodeAtPosition(node, this.startContainer, this.startOffset);
+ node.appendChild(content);
+
+ this.selectNode(node);
+ },
+
+ cloneRange: function() {
+ assertRangeValid(this);
+ var range = new Range(getRangeDocument(this));
+ var i = rangeProperties.length, prop;
+ while (i--) {
+ prop = rangeProperties[i];
+ range[prop] = this[prop];
+ }
+ return range;
+ },
+
+ toString: function() {
+ assertRangeValid(this);
+ var sc = this.startContainer;
+ if (sc === this.endContainer && isCharacterDataNode(sc)) {
+ return (sc.nodeType == 3 || sc.nodeType == 4) ? sc.data.slice(this.startOffset, this.endOffset) : "";
+ } else {
+ var textParts = [], iterator = new RangeIterator(this, true);
+ iterateSubtree(iterator, function(node) {
+ // Accept only text or CDATA nodes, not comments
+ if (node.nodeType == 3 || node.nodeType == 4) {
+ textParts.push(node.data);
+ }
+ });
+ iterator.detach();
+ return textParts.join("");
+ }
+ },
+
+ // The methods below are all non-standard. The following batch were introduced by Mozilla but have since
+ // been removed from Mozilla.
+
+ compareNode: function(node) {
+ assertRangeValid(this);
+
+ var parent = node.parentNode;
+ var nodeIndex = getNodeIndex(node);
+
+ if (!parent) {
+ throw new DOMException("NOT_FOUND_ERR");
+ }
+
+ var startComparison = this.comparePoint(parent, nodeIndex),
+ endComparison = this.comparePoint(parent, nodeIndex + 1);
+
+ if (startComparison < 0) { // Node starts before
+ return (endComparison > 0) ? n_b_a : n_b;
+ } else {
+ return (endComparison > 0) ? n_a : n_i;
+ }
+ },
+
+ comparePoint: function(node, offset) {
+ assertRangeValid(this);
+ assertNode(node, "HIERARCHY_REQUEST_ERR");
+ assertSameDocumentOrFragment(node, this.startContainer);
+
+ if (comparePoints(node, offset, this.startContainer, this.startOffset) < 0) {
+ return -1;
+ } else if (comparePoints(node, offset, this.endContainer, this.endOffset) > 0) {
+ return 1;
+ }
+ return 0;
+ },
+
+ createContextualFragment: createContextualFragment,
+
+ toHtml: function() {
+ return rangeToHtml(this);
+ },
+
+ // touchingIsIntersecting determines whether this method considers a node that borders a range intersects
+ // with it (as in WebKit) or not (as in Gecko pre-1.9, and the default)
+ intersectsNode: function(node, touchingIsIntersecting) {
+ assertRangeValid(this);
+ assertNode(node, "NOT_FOUND_ERR");
+ if (getDocument(node) !== getRangeDocument(this)) {
+ return false;
+ }
+
+ var parent = node.parentNode, offset = getNodeIndex(node);
+ assertNode(parent, "NOT_FOUND_ERR");
+
+ var startComparison = comparePoints(parent, offset, this.endContainer, this.endOffset),
+ endComparison = comparePoints(parent, offset + 1, this.startContainer, this.startOffset);
+
+ return touchingIsIntersecting ? startComparison <= 0 && endComparison >= 0 : startComparison < 0 && endComparison > 0;
+ },
+
+ isPointInRange: function(node, offset) {
+ assertRangeValid(this);
+ assertNode(node, "HIERARCHY_REQUEST_ERR");
+ assertSameDocumentOrFragment(node, this.startContainer);
+
+ return (comparePoints(node, offset, this.startContainer, this.startOffset) >= 0) &&
+ (comparePoints(node, offset, this.endContainer, this.endOffset) <= 0);
+ },
+
+ // The methods below are non-standard and invented by me.
+
+ // Sharing a boundary start-to-end or end-to-start does not count as intersection.
+ intersectsRange: function(range) {
+ return rangesIntersect(this, range, false);
+ },
+
+ // Sharing a boundary start-to-end or end-to-start does count as intersection.
+ intersectsOrTouchesRange: function(range) {
+ return rangesIntersect(this, range, true);
+ },
+
+ intersection: function(range) {
+ if (this.intersectsRange(range)) {
+ var startComparison = comparePoints(this.startContainer, this.startOffset, range.startContainer, range.startOffset),
+ endComparison = comparePoints(this.endContainer, this.endOffset, range.endContainer, range.endOffset);
+
+ var intersectionRange = this.cloneRange();
+ if (startComparison == -1) {
+ intersectionRange.setStart(range.startContainer, range.startOffset);
+ }
+ if (endComparison == 1) {
+ intersectionRange.setEnd(range.endContainer, range.endOffset);
+ }
+ return intersectionRange;
+ }
+ return null;
+ },
+
+ union: function(range) {
+ if (this.intersectsOrTouchesRange(range)) {
+ var unionRange = this.cloneRange();
+ if (comparePoints(range.startContainer, range.startOffset, this.startContainer, this.startOffset) == -1) {
+ unionRange.setStart(range.startContainer, range.startOffset);
+ }
+ if (comparePoints(range.endContainer, range.endOffset, this.endContainer, this.endOffset) == 1) {
+ unionRange.setEnd(range.endContainer, range.endOffset);
+ }
+ return unionRange;
+ } else {
+ throw new DOMException("Ranges do not intersect");
+ }
+ },
+
+ containsNode: function(node, allowPartial) {
+ if (allowPartial) {
+ return this.intersectsNode(node, false);
+ } else {
+ return this.compareNode(node) == n_i;
+ }
+ },
+
+ containsNodeContents: function(node) {
+ return this.comparePoint(node, 0) >= 0 && this.comparePoint(node, getNodeLength(node)) <= 0;
+ },
+
+ containsRange: function(range) {
+ var intersection = this.intersection(range);
+ return intersection !== null && range.equals(intersection);
+ },
+
+ containsNodeText: function(node) {
+ var nodeRange = this.cloneRange();
+ nodeRange.selectNode(node);
+ var textNodes = nodeRange.getNodes([3]);
+ if (textNodes.length > 0) {
+ nodeRange.setStart(textNodes[0], 0);
+ var lastTextNode = textNodes.pop();
+ nodeRange.setEnd(lastTextNode, lastTextNode.length);
+ return this.containsRange(nodeRange);
+ } else {
+ return this.containsNodeContents(node);
+ }
+ },
+
+ getNodes: function(nodeTypes, filter) {
+ assertRangeValid(this);
+ return getNodesInRange(this, nodeTypes, filter);
+ },
+
+ getDocument: function() {
+ return getRangeDocument(this);
+ },
+
+ collapseBefore: function(node) {
+ this.setEndBefore(node);
+ this.collapse(false);
+ },
+
+ collapseAfter: function(node) {
+ this.setStartAfter(node);
+ this.collapse(true);
+ },
+
+ getBookmark: function(containerNode) {
+ var doc = getRangeDocument(this);
+ var preSelectionRange = api.createRange(doc);
+ containerNode = containerNode || dom.getBody(doc);
+ preSelectionRange.selectNodeContents(containerNode);
+ var range = this.intersection(preSelectionRange);
+ var start = 0, end = 0;
+ if (range) {
+ preSelectionRange.setEnd(range.startContainer, range.startOffset);
+ start = preSelectionRange.toString().length;
+ end = start + range.toString().length;
+ }
+
+ return {
+ start: start,
+ end: end,
+ containerNode: containerNode
+ };
+ },
+
+ moveToBookmark: function(bookmark) {
+ var containerNode = bookmark.containerNode;
+ var charIndex = 0;
+ this.setStart(containerNode, 0);
+ this.collapse(true);
+ var nodeStack = [containerNode], node, foundStart = false, stop = false;
+ var nextCharIndex, i, childNodes;
+
+ while (!stop && (node = nodeStack.pop())) {
+ if (node.nodeType == 3) {
+ nextCharIndex = charIndex + node.length;
+ if (!foundStart && bookmark.start >= charIndex && bookmark.start <= nextCharIndex) {
+ this.setStart(node, bookmark.start - charIndex);
+ foundStart = true;
+ }
+ if (foundStart && bookmark.end >= charIndex && bookmark.end <= nextCharIndex) {
+ this.setEnd(node, bookmark.end - charIndex);
+ stop = true;
+ }
+ charIndex = nextCharIndex;
+ } else {
+ childNodes = node.childNodes;
+ i = childNodes.length;
+ while (i--) {
+ nodeStack.push(childNodes[i]);
+ }
+ }
+ }
+ },
+
+ getName: function() {
+ return "DomRange";
+ },
+
+ equals: function(range) {
+ return Range.rangesEqual(this, range);
+ },
+
+ isValid: function() {
+ return isRangeValid(this);
+ },
+
+ inspect: function() {
+ return inspect(this);
+ },
+
+ detach: function() {
+ // In DOM4, detach() is now a no-op.
+ }
+ });
+
+ function copyComparisonConstantsToObject(obj) {
+ obj.START_TO_START = s2s;
+ obj.START_TO_END = s2e;
+ obj.END_TO_END = e2e;
+ obj.END_TO_START = e2s;
+
+ obj.NODE_BEFORE = n_b;
+ obj.NODE_AFTER = n_a;
+ obj.NODE_BEFORE_AND_AFTER = n_b_a;
+ obj.NODE_INSIDE = n_i;
+ }
+
+ function copyComparisonConstants(constructor) {
+ copyComparisonConstantsToObject(constructor);
+ copyComparisonConstantsToObject(constructor.prototype);
+ }
+
+ function createRangeContentRemover(remover, boundaryUpdater) {
+ return function() {
+ assertRangeValid(this);
+
+ var sc = this.startContainer, so = this.startOffset, root = this.commonAncestorContainer;
+
+ var iterator = new RangeIterator(this, true);
+
+ // Work out where to position the range after content removal
+ var node, boundary;
+ if (sc !== root) {
+ node = getClosestAncestorIn(sc, root, true);
+ boundary = getBoundaryAfterNode(node);
+ sc = boundary.node;
+ so = boundary.offset;
+ }
+
+ // Check none of the range is read-only
+ iterateSubtree(iterator, assertNodeNotReadOnly);
+
+ iterator.reset();
+
+ // Remove the content
+ var returnValue = remover(iterator);
+ iterator.detach();
+
+ // Move to the new position
+ boundaryUpdater(this, sc, so, sc, so);
+
+ return returnValue;
+ };
+ }
+
+ function createPrototypeRange(constructor, boundaryUpdater) {
+ function createBeforeAfterNodeSetter(isBefore, isStart) {
+ return function(node) {
+ assertValidNodeType(node, beforeAfterNodeTypes);
+ assertValidNodeType(getRootContainer(node), rootContainerNodeTypes);
+
+ var boundary = (isBefore ? getBoundaryBeforeNode : getBoundaryAfterNode)(node);
+ (isStart ? setRangeStart : setRangeEnd)(this, boundary.node, boundary.offset);
+ };
+ }
+
+ function setRangeStart(range, node, offset) {
+ var ec = range.endContainer, eo = range.endOffset;
+ if (node !== range.startContainer || offset !== range.startOffset) {
+ // Check the root containers of the range and the new boundary, and also check whether the new boundary
+ // is after the current end. In either case, collapse the range to the new position
+ if (getRootContainer(node) != getRootContainer(ec) || comparePoints(node, offset, ec, eo) == 1) {
+ ec = node;
+ eo = offset;
+ }
+ boundaryUpdater(range, node, offset, ec, eo);
+ }
+ }
+
+ function setRangeEnd(range, node, offset) {
+ var sc = range.startContainer, so = range.startOffset;
+ if (node !== range.endContainer || offset !== range.endOffset) {
+ // Check the root containers of the range and the new boundary, and also check whether the new boundary
+ // is after the current end. In either case, collapse the range to the new position
+ if (getRootContainer(node) != getRootContainer(sc) || comparePoints(node, offset, sc, so) == -1) {
+ sc = node;
+ so = offset;
+ }
+ boundaryUpdater(range, sc, so, node, offset);
+ }
+ }
+
+ // Set up inheritance
+ var F = function() {};
+ F.prototype = api.rangePrototype;
+ constructor.prototype = new F();
+
+ util.extend(constructor.prototype, {
+ setStart: function(node, offset) {
+ assertNoDocTypeNotationEntityAncestor(node, true);
+ assertValidOffset(node, offset);
+
+ setRangeStart(this, node, offset);
+ },
+
+ setEnd: function(node, offset) {
+ assertNoDocTypeNotationEntityAncestor(node, true);
+ assertValidOffset(node, offset);
+
+ setRangeEnd(this, node, offset);
+ },
+
+ /**
+ * Convenience method to set a range's start and end boundaries. Overloaded as follows:
+ * - Two parameters (node, offset) creates a collapsed range at that position
+ * - Three parameters (node, startOffset, endOffset) creates a range contained with node starting at
+ * startOffset and ending at endOffset
+ * - Four parameters (startNode, startOffset, endNode, endOffset) creates a range starting at startOffset in
+ * startNode and ending at endOffset in endNode
+ */
+ setStartAndEnd: function() {
+ var args = arguments;
+ var sc = args[0], so = args[1], ec = sc, eo = so;
+
+ switch (args.length) {
+ case 3:
+ eo = args[2];
+ break;
+ case 4:
+ ec = args[2];
+ eo = args[3];
+ break;
+ }
+
+ boundaryUpdater(this, sc, so, ec, eo);
+ },
+
+ setBoundary: function(node, offset, isStart) {
+ this["set" + (isStart ? "Start" : "End")](node, offset);
+ },
+
+ setStartBefore: createBeforeAfterNodeSetter(true, true),
+ setStartAfter: createBeforeAfterNodeSetter(false, true),
+ setEndBefore: createBeforeAfterNodeSetter(true, false),
+ setEndAfter: createBeforeAfterNodeSetter(false, false),
+
+ collapse: function(isStart) {
+ assertRangeValid(this);
+ if (isStart) {
+ boundaryUpdater(this, this.startContainer, this.startOffset, this.startContainer, this.startOffset);
+ } else {
+ boundaryUpdater(this, this.endContainer, this.endOffset, this.endContainer, this.endOffset);
+ }
+ },
+
+ selectNodeContents: function(node) {
+ assertNoDocTypeNotationEntityAncestor(node, true);
+
+ boundaryUpdater(this, node, 0, node, getNodeLength(node));
+ },
+
+ selectNode: function(node) {
+ assertNoDocTypeNotationEntityAncestor(node, false);
+ assertValidNodeType(node, beforeAfterNodeTypes);
+
+ var start = getBoundaryBeforeNode(node), end = getBoundaryAfterNode(node);
+ boundaryUpdater(this, start.node, start.offset, end.node, end.offset);
+ },
+
+ extractContents: createRangeContentRemover(extractSubtree, boundaryUpdater),
+
+ deleteContents: createRangeContentRemover(deleteSubtree, boundaryUpdater),
+
+ canSurroundContents: function() {
+ assertRangeValid(this);
+ assertNodeNotReadOnly(this.startContainer);
+ assertNodeNotReadOnly(this.endContainer);
+
+ // Check if the contents can be surrounded. Specifically, this means whether the range partially selects
+ // no non-text nodes.
+ var iterator = new RangeIterator(this, true);
+ var boundariesInvalid = (iterator._first && isNonTextPartiallySelected(iterator._first, this) ||
+ (iterator._last && isNonTextPartiallySelected(iterator._last, this)));
+ iterator.detach();
+ return !boundariesInvalid;
+ },
+
+ splitBoundaries: function() {
+ splitRangeBoundaries(this);
+ },
+
+ splitBoundariesPreservingPositions: function(positionsToPreserve) {
+ splitRangeBoundaries(this, positionsToPreserve);
+ },
+
+ normalizeBoundaries: function() {
+ assertRangeValid(this);
+
+ var sc = this.startContainer, so = this.startOffset, ec = this.endContainer, eo = this.endOffset;
+
+ var mergeForward = function(node) {
+ var sibling = node.nextSibling;
+ if (sibling && sibling.nodeType == node.nodeType) {
+ ec = node;
+ eo = node.length;
+ node.appendData(sibling.data);
+ sibling.parentNode.removeChild(sibling);
+ }
+ };
+
+ var mergeBackward = function(node) {
+ var sibling = node.previousSibling;
+ if (sibling && sibling.nodeType == node.nodeType) {
+ sc = node;
+ var nodeLength = node.length;
+ so = sibling.length;
+ node.insertData(0, sibling.data);
+ sibling.parentNode.removeChild(sibling);
+ if (sc == ec) {
+ eo += so;
+ ec = sc;
+ } else if (ec == node.parentNode) {
+ var nodeIndex = getNodeIndex(node);
+ if (eo == nodeIndex) {
+ ec = node;
+ eo = nodeLength;
+ } else if (eo > nodeIndex) {
+ eo--;
+ }
+ }
+ }
+ };
+
+ var normalizeStart = true;
+
+ if (isCharacterDataNode(ec)) {
+ if (ec.length == eo) {
+ mergeForward(ec);
+ }
+ } else {
+ if (eo > 0) {
+ var endNode = ec.childNodes[eo - 1];
+ if (endNode && isCharacterDataNode(endNode)) {
+ mergeForward(endNode);
+ }
+ }
+ normalizeStart = !this.collapsed;
+ }
+
+ if (normalizeStart) {
+ if (isCharacterDataNode(sc)) {
+ if (so == 0) {
+ mergeBackward(sc);
+ }
+ } else {
+ if (so < sc.childNodes.length) {
+ var startNode = sc.childNodes[so];
+ if (startNode && isCharacterDataNode(startNode)) {
+ mergeBackward(startNode);
+ }
+ }
+ }
+ } else {
+ sc = ec;
+ so = eo;
+ }
+
+ boundaryUpdater(this, sc, so, ec, eo);
+ },
+
+ collapseToPoint: function(node, offset) {
+ assertNoDocTypeNotationEntityAncestor(node, true);
+ assertValidOffset(node, offset);
+ this.setStartAndEnd(node, offset);
+ }
+ });
+
+ copyComparisonConstants(constructor);
+ }
+
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ // Updates commonAncestorContainer and collapsed after boundary change
+ function updateCollapsedAndCommonAncestor(range) {
+ range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
+ range.commonAncestorContainer = range.collapsed ?
+ range.startContainer : dom.getCommonAncestor(range.startContainer, range.endContainer);
+ }
+
+ function updateBoundaries(range, startContainer, startOffset, endContainer, endOffset) {
+ range.startContainer = startContainer;
+ range.startOffset = startOffset;
+ range.endContainer = endContainer;
+ range.endOffset = endOffset;
+ range.document = dom.getDocument(startContainer);
+
+ updateCollapsedAndCommonAncestor(range);
+ }
+
+ function Range(doc) {
+ this.startContainer = doc;
+ this.startOffset = 0;
+ this.endContainer = doc;
+ this.endOffset = 0;
+ this.document = doc;
+ updateCollapsedAndCommonAncestor(this);
+ }
+
+ createPrototypeRange(Range, updateBoundaries);
+
+ util.extend(Range, {
+ rangeProperties: rangeProperties,
+ RangeIterator: RangeIterator,
+ copyComparisonConstants: copyComparisonConstants,
+ createPrototypeRange: createPrototypeRange,
+ inspect: inspect,
+ toHtml: rangeToHtml,
+ getRangeDocument: getRangeDocument,
+ rangesEqual: function(r1, r2) {
+ return r1.startContainer === r2.startContainer &&
+ r1.startOffset === r2.startOffset &&
+ r1.endContainer === r2.endContainer &&
+ r1.endOffset === r2.endOffset;
+ }
+ });
+
+ api.DomRange = Range;
+ });\r
+\r
+ /*----------------------------------------------------------------------------------------------------------------*/\r
+\r
+ // Wrappers for the browser's native DOM Range and/or TextRange implementation
+ api.createCoreModule("WrappedRange", ["DomRange"], function(api, module) {
+ var WrappedRange, WrappedTextRange;
+ var dom = api.dom;
+ var util = api.util;
+ var DomPosition = dom.DomPosition;
+ var DomRange = api.DomRange;
+ var getBody = dom.getBody;
+ var getContentDocument = dom.getContentDocument;
+ var isCharacterDataNode = dom.isCharacterDataNode;
+
+
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ if (api.features.implementsDomRange) {
+ // This is a wrapper around the browser's native DOM Range. It has two aims:
+ // - Provide workarounds for specific browser bugs
+ // - provide convenient extensions, which are inherited from Rangy's DomRange
+
+ (function() {
+ var rangeProto;
+ var rangeProperties = DomRange.rangeProperties;
+
+ function updateRangeProperties(range) {
+ var i = rangeProperties.length, prop;
+ while (i--) {
+ prop = rangeProperties[i];
+ range[prop] = range.nativeRange[prop];
+ }
+ // Fix for broken collapsed property in IE 9.
+ range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
+ }
+
+ function updateNativeRange(range, startContainer, startOffset, endContainer, endOffset) {
+ var startMoved = (range.startContainer !== startContainer || range.startOffset != startOffset);
+ var endMoved = (range.endContainer !== endContainer || range.endOffset != endOffset);
+ var nativeRangeDifferent = !range.equals(range.nativeRange);
+
+ // Always set both boundaries for the benefit of IE9 (see issue 35)
+ if (startMoved || endMoved || nativeRangeDifferent) {
+ range.setEnd(endContainer, endOffset);
+ range.setStart(startContainer, startOffset);
+ }
+ }
+
+ var createBeforeAfterNodeSetter;
+
+ WrappedRange = function(range) {
+ if (!range) {
+ throw module.createError("WrappedRange: Range must be specified");
+ }
+ this.nativeRange = range;
+ updateRangeProperties(this);
+ };
+
+ DomRange.createPrototypeRange(WrappedRange, updateNativeRange);
+
+ rangeProto = WrappedRange.prototype;
+
+ rangeProto.selectNode = function(node) {
+ this.nativeRange.selectNode(node);
+ updateRangeProperties(this);
+ };
+
+ rangeProto.cloneContents = function() {
+ return this.nativeRange.cloneContents();
+ };
+
+ // Due to a long-standing Firefox bug that I have not been able to find a reliable way to detect,
+ // insertNode() is never delegated to the native range.
+
+ rangeProto.surroundContents = function(node) {
+ this.nativeRange.surroundContents(node);
+ updateRangeProperties(this);
+ };
+
+ rangeProto.collapse = function(isStart) {
+ this.nativeRange.collapse(isStart);
+ updateRangeProperties(this);
+ };
+
+ rangeProto.cloneRange = function() {
+ return new WrappedRange(this.nativeRange.cloneRange());
+ };
+
+ rangeProto.refresh = function() {
+ updateRangeProperties(this);
+ };
+
+ rangeProto.toString = function() {
+ return this.nativeRange.toString();
+ };
+
+ // Create test range and node for feature detection
+
+ var testTextNode = document.createTextNode("test");
+ getBody(document).appendChild(testTextNode);
+ var range = document.createRange();
+
+ /*--------------------------------------------------------------------------------------------------------*/
+
+ // Test for Firefox 2 bug that prevents moving the start of a Range to a point after its current end and
+ // correct for it
+
+ range.setStart(testTextNode, 0);
+ range.setEnd(testTextNode, 0);
+
+ try {
+ range.setStart(testTextNode, 1);
+
+ rangeProto.setStart = function(node, offset) {
+ this.nativeRange.setStart(node, offset);
+ updateRangeProperties(this);
+ };
+
+ rangeProto.setEnd = function(node, offset) {
+ this.nativeRange.setEnd(node, offset);
+ updateRangeProperties(this);
+ };
+
+ createBeforeAfterNodeSetter = function(name) {
+ return function(node) {
+ this.nativeRange[name](node);
+ updateRangeProperties(this);
+ };
+ };
+
+ } catch(ex) {
+
+ rangeProto.setStart = function(node, offset) {
+ try {
+ this.nativeRange.setStart(node, offset);
+ } catch (ex) {
+ this.nativeRange.setEnd(node, offset);
+ this.nativeRange.setStart(node, offset);
+ }
+ updateRangeProperties(this);
+ };
+
+ rangeProto.setEnd = function(node, offset) {
+ try {
+ this.nativeRange.setEnd(node, offset);
+ } catch (ex) {
+ this.nativeRange.setStart(node, offset);
+ this.nativeRange.setEnd(node, offset);
+ }
+ updateRangeProperties(this);
+ };
+
+ createBeforeAfterNodeSetter = function(name, oppositeName) {
+ return function(node) {
+ try {
+ this.nativeRange[name](node);
+ } catch (ex) {
+ this.nativeRange[oppositeName](node);
+ this.nativeRange[name](node);
+ }
+ updateRangeProperties(this);
+ };
+ };
+ }
+
+ rangeProto.setStartBefore = createBeforeAfterNodeSetter("setStartBefore", "setEndBefore");
+ rangeProto.setStartAfter = createBeforeAfterNodeSetter("setStartAfter", "setEndAfter");
+ rangeProto.setEndBefore = createBeforeAfterNodeSetter("setEndBefore", "setStartBefore");
+ rangeProto.setEndAfter = createBeforeAfterNodeSetter("setEndAfter", "setStartAfter");
+
+ /*--------------------------------------------------------------------------------------------------------*/
+
+ // Always use DOM4-compliant selectNodeContents implementation: it's simpler and less code than testing
+ // whether the native implementation can be trusted
+ rangeProto.selectNodeContents = function(node) {
+ this.setStartAndEnd(node, 0, dom.getNodeLength(node));
+ };
+
+ /*--------------------------------------------------------------------------------------------------------*/
+
+ // Test for and correct WebKit bug that has the behaviour of compareBoundaryPoints round the wrong way for
+ // constants START_TO_END and END_TO_START: https://bugs.webkit.org/show_bug.cgi?id=20738
+
+ range.selectNodeContents(testTextNode);
+ range.setEnd(testTextNode, 3);
+
+ var range2 = document.createRange();
+ range2.selectNodeContents(testTextNode);
+ range2.setEnd(testTextNode, 4);
+ range2.setStart(testTextNode, 2);
+
+ if (range.compareBoundaryPoints(range.START_TO_END, range2) == -1 &&
+ range.compareBoundaryPoints(range.END_TO_START, range2) == 1) {
+ // This is the wrong way round, so correct for it
+
+ rangeProto.compareBoundaryPoints = function(type, range) {
+ range = range.nativeRange || range;
+ if (type == range.START_TO_END) {
+ type = range.END_TO_START;
+ } else if (type == range.END_TO_START) {
+ type = range.START_TO_END;
+ }
+ return this.nativeRange.compareBoundaryPoints(type, range);
+ };
+ } else {
+ rangeProto.compareBoundaryPoints = function(type, range) {
+ return this.nativeRange.compareBoundaryPoints(type, range.nativeRange || range);
+ };
+ }
+
+ /*--------------------------------------------------------------------------------------------------------*/
+
+ // Test for IE deleteContents() and extractContents() bug and correct it. See issue 107.
+
+ var el = document.createElement("div");
+ el.innerHTML = "123";
+ var textNode = el.firstChild;
+ var body = getBody(document);
+ body.appendChild(el);
+
+ range.setStart(textNode, 1);
+ range.setEnd(textNode, 2);
+ range.deleteContents();
+
+ if (textNode.data == "13") {
+ // Behaviour is correct per DOM4 Range so wrap the browser's implementation of deleteContents() and
+ // extractContents()
+ rangeProto.deleteContents = function() {
+ this.nativeRange.deleteContents();
+ updateRangeProperties(this);
+ };
+
+ rangeProto.extractContents = function() {
+ var frag = this.nativeRange.extractContents();
+ updateRangeProperties(this);
+ return frag;
+ };
+ } else {
+ }
+
+ body.removeChild(el);
+ body = null;
+
+ /*--------------------------------------------------------------------------------------------------------*/
+
+ // Test for existence of createContextualFragment and delegate to it if it exists
+ if (util.isHostMethod(range, "createContextualFragment")) {
+ rangeProto.createContextualFragment = function(fragmentStr) {
+ return this.nativeRange.createContextualFragment(fragmentStr);
+ };
+ }
+
+ /*--------------------------------------------------------------------------------------------------------*/
+
+ // Clean up
+ getBody(document).removeChild(testTextNode);
+
+ rangeProto.getName = function() {
+ return "WrappedRange";
+ };
+
+ api.WrappedRange = WrappedRange;
+
+ api.createNativeRange = function(doc) {
+ doc = getContentDocument(doc, module, "createNativeRange");
+ return doc.createRange();
+ };
+ })();
+ }
+
+ if (api.features.implementsTextRange) {
+ /*
+ This is a workaround for a bug where IE returns the wrong container element from the TextRange's parentElement()
+ method. For example, in the following (where pipes denote the selection boundaries):
+
+ <ul id="ul"><li id="a">| a </li><li id="b"> b |</li></ul>
+
+ var range = document.selection.createRange();
+ alert(range.parentElement().id); // Should alert "ul" but alerts "b"
+
+ This method returns the common ancestor node of the following:
+ - the parentElement() of the textRange
+ - the parentElement() of the textRange after calling collapse(true)
+ - the parentElement() of the textRange after calling collapse(false)
+ */
+ var getTextRangeContainerElement = function(textRange) {
+ var parentEl = textRange.parentElement();
+ var range = textRange.duplicate();
+ range.collapse(true);
+ var startEl = range.parentElement();
+ range = textRange.duplicate();
+ range.collapse(false);
+ var endEl = range.parentElement();
+ var startEndContainer = (startEl == endEl) ? startEl : dom.getCommonAncestor(startEl, endEl);
+
+ return startEndContainer == parentEl ? startEndContainer : dom.getCommonAncestor(parentEl, startEndContainer);
+ };
+
+ var textRangeIsCollapsed = function(textRange) {
+ return textRange.compareEndPoints("StartToEnd", textRange) == 0;
+ };
+
+ // Gets the boundary of a TextRange expressed as a node and an offset within that node. This function started
+ // out as an improved version of code found in Tim Cameron Ryan's IERange (http://code.google.com/p/ierange/)
+ // but has grown, fixing problems with line breaks in preformatted text, adding workaround for IE TextRange
+ // bugs, handling for inputs and images, plus optimizations.
+ var getTextRangeBoundaryPosition = function(textRange, wholeRangeContainerElement, isStart, isCollapsed, startInfo) {
+ var workingRange = textRange.duplicate();
+ workingRange.collapse(isStart);
+ var containerElement = workingRange.parentElement();
+
+ // Sometimes collapsing a TextRange that's at the start of a text node can move it into the previous node, so
+ // check for that
+ if (!dom.isOrIsAncestorOf(wholeRangeContainerElement, containerElement)) {
+ containerElement = wholeRangeContainerElement;
+ }
+
+
+ // Deal with nodes that cannot "contain rich HTML markup". In practice, this means form inputs, images and
+ // similar. See http://msdn.microsoft.com/en-us/library/aa703950%28VS.85%29.aspx
+ if (!containerElement.canHaveHTML) {
+ var pos = new DomPosition(containerElement.parentNode, dom.getNodeIndex(containerElement));
+ return {
+ boundaryPosition: pos,
+ nodeInfo: {
+ nodeIndex: pos.offset,
+ containerElement: pos.node
+ }
+ };
+ }
+
+ var workingNode = dom.getDocument(containerElement).createElement("span");
+
+ // Workaround for HTML5 Shiv's insane violation of document.createElement(). See Rangy issue 104 and HTML5
+ // Shiv issue 64: https://github.com/aFarkas/html5shiv/issues/64
+ if (workingNode.parentNode) {
+ workingNode.parentNode.removeChild(workingNode);
+ }
+
+ var comparison, workingComparisonType = isStart ? "StartToStart" : "StartToEnd";
+ var previousNode, nextNode, boundaryPosition, boundaryNode;
+ var start = (startInfo && startInfo.containerElement == containerElement) ? startInfo.nodeIndex : 0;
+ var childNodeCount = containerElement.childNodes.length;
+ var end = childNodeCount;
+
+ // Check end first. Code within the loop assumes that the endth child node of the container is definitely
+ // after the range boundary.
+ var nodeIndex = end;
+
+ while (true) {
+ if (nodeIndex == childNodeCount) {
+ containerElement.appendChild(workingNode);
+ } else {
+ containerElement.insertBefore(workingNode, containerElement.childNodes[nodeIndex]);
+ }
+ workingRange.moveToElementText(workingNode);
+ comparison = workingRange.compareEndPoints(workingComparisonType, textRange);
+ if (comparison == 0 || start == end) {
+ break;
+ } else if (comparison == -1) {
+ if (end == start + 1) {
+ // We know the endth child node is after the range boundary, so we must be done.
+ break;
+ } else {
+ start = nodeIndex;
+ }
+ } else {
+ end = (end == start + 1) ? start : nodeIndex;
+ }
+ nodeIndex = Math.floor((start + end) / 2);
+ containerElement.removeChild(workingNode);
+ }
+
+
+ // We've now reached or gone past the boundary of the text range we're interested in
+ // so have identified the node we want
+ boundaryNode = workingNode.nextSibling;
+
+ if (comparison == -1 && boundaryNode && isCharacterDataNode(boundaryNode)) {
+ // This is a character data node (text, comment, cdata). The working range is collapsed at the start of
+ // the node containing the text range's boundary, so we move the end of the working range to the
+ // boundary point and measure the length of its text to get the boundary's offset within the node.
+ workingRange.setEndPoint(isStart ? "EndToStart" : "EndToEnd", textRange);
+
+ var offset;
+
+ if (/[\r\n]/.test(boundaryNode.data)) {
+ /*
+ For the particular case of a boundary within a text node containing rendered line breaks (within a
+ <pre> element, for example), we need a slightly complicated approach to get the boundary's offset in
+ IE. The facts:
+
+ - Each line break is represented as \r in the text node's data/nodeValue properties
+ - Each line break is represented as \r\n in the TextRange's 'text' property
+ - The 'text' property of the TextRange does not contain trailing line breaks
+
+ To get round the problem presented by the final fact above, we can use the fact that TextRange's
+ moveStart() and moveEnd() methods return the actual number of characters moved, which is not
+ necessarily the same as the number of characters it was instructed to move. The simplest approach is
+ to use this to store the characters moved when moving both the start and end of the range to the
+ start of the document body and subtracting the start offset from the end offset (the
+ "move-negative-gazillion" method). However, this is extremely slow when the document is large and
+ the range is near the end of it. Clearly doing the mirror image (i.e. moving the range boundaries to
+ the end of the document) has the same problem.
+
+ Another approach that works is to use moveStart() to move the start boundary of the range up to the
+ end boundary one character at a time and incrementing a counter with the value returned by the
+ moveStart() call. However, the check for whether the start boundary has reached the end boundary is
+ expensive, so this method is slow (although unlike "move-negative-gazillion" is largely unaffected
+ by the location of the range within the document).
+
+ The approach used below is a hybrid of the two methods above. It uses the fact that a string
+ containing the TextRange's 'text' property with each \r\n converted to a single \r character cannot
+ be longer than the text of the TextRange, so the start of the range is moved that length initially
+ and then a character at a time to make up for any trailing line breaks not contained in the 'text'
+ property. This has good performance in most situations compared to the previous two methods.
+ */
+ var tempRange = workingRange.duplicate();
+ var rangeLength = tempRange.text.replace(/\r\n/g, "\r").length;
+
+ offset = tempRange.moveStart("character", rangeLength);
+ while ( (comparison = tempRange.compareEndPoints("StartToEnd", tempRange)) == -1) {
+ offset++;
+ tempRange.moveStart("character", 1);
+ }
+ } else {
+ offset = workingRange.text.length;
+ }
+ boundaryPosition = new DomPosition(boundaryNode, offset);
+ } else {
+
+ // If the boundary immediately follows a character data node and this is the end boundary, we should favour
+ // a position within that, and likewise for a start boundary preceding a character data node
+ previousNode = (isCollapsed || !isStart) && workingNode.previousSibling;
+ nextNode = (isCollapsed || isStart) && workingNode.nextSibling;
+ if (nextNode && isCharacterDataNode(nextNode)) {
+ boundaryPosition = new DomPosition(nextNode, 0);
+ } else if (previousNode && isCharacterDataNode(previousNode)) {
+ boundaryPosition = new DomPosition(previousNode, previousNode.data.length);
+ } else {
+ boundaryPosition = new DomPosition(containerElement, dom.getNodeIndex(workingNode));
+ }
+ }
+
+ // Clean up
+ workingNode.parentNode.removeChild(workingNode);
+
+ return {
+ boundaryPosition: boundaryPosition,
+ nodeInfo: {
+ nodeIndex: nodeIndex,
+ containerElement: containerElement
+ }
+ };
+ };
+
+ // Returns a TextRange representing the boundary of a TextRange expressed as a node and an offset within that
+ // node. This function started out as an optimized version of code found in Tim Cameron Ryan's IERange
+ // (http://code.google.com/p/ierange/)
+ var createBoundaryTextRange = function(boundaryPosition, isStart) {
+ var boundaryNode, boundaryParent, boundaryOffset = boundaryPosition.offset;
+ var doc = dom.getDocument(boundaryPosition.node);
+ var workingNode, childNodes, workingRange = getBody(doc).createTextRange();
+ var nodeIsDataNode = isCharacterDataNode(boundaryPosition.node);
+
+ if (nodeIsDataNode) {
+ boundaryNode = boundaryPosition.node;
+ boundaryParent = boundaryNode.parentNode;
+ } else {
+ childNodes = boundaryPosition.node.childNodes;
+ boundaryNode = (boundaryOffset < childNodes.length) ? childNodes[boundaryOffset] : null;
+ boundaryParent = boundaryPosition.node;
+ }
+
+ // Position the range immediately before the node containing the boundary
+ workingNode = doc.createElement("span");
+
+ // Making the working element non-empty element persuades IE to consider the TextRange boundary to be within
+ // the element rather than immediately before or after it
+ workingNode.innerHTML = "&#feff;";
+
+ // insertBefore is supposed to work like appendChild if the second parameter is null. However, a bug report
+ // for IERange suggests that it can crash the browser: http://code.google.com/p/ierange/issues/detail?id=12
+ if (boundaryNode) {
+ boundaryParent.insertBefore(workingNode, boundaryNode);
+ } else {
+ boundaryParent.appendChild(workingNode);
+ }
+
+ workingRange.moveToElementText(workingNode);
+ workingRange.collapse(!isStart);
+
+ // Clean up
+ boundaryParent.removeChild(workingNode);
+
+ // Move the working range to the text offset, if required
+ if (nodeIsDataNode) {
+ workingRange[isStart ? "moveStart" : "moveEnd"]("character", boundaryOffset);
+ }
+
+ return workingRange;
+ };
+
+ /*------------------------------------------------------------------------------------------------------------*/
+
+ // This is a wrapper around a TextRange, providing full DOM Range functionality using rangy's DomRange as a
+ // prototype
+
+ WrappedTextRange = function(textRange) {
+ this.textRange = textRange;
+ this.refresh();
+ };
+
+ WrappedTextRange.prototype = new DomRange(document);
+
+ WrappedTextRange.prototype.refresh = function() {
+ var start, end, startBoundary;
+
+ // TextRange's parentElement() method cannot be trusted. getTextRangeContainerElement() works around that.
+ var rangeContainerElement = getTextRangeContainerElement(this.textRange);
+
+ if (textRangeIsCollapsed(this.textRange)) {
+ end = start = getTextRangeBoundaryPosition(this.textRange, rangeContainerElement, true,
+ true).boundaryPosition;
+ } else {
+ startBoundary = getTextRangeBoundaryPosition(this.textRange, rangeContainerElement, true, false);
+ start = startBoundary.boundaryPosition;
+
+ // An optimization used here is that if the start and end boundaries have the same parent element, the
+ // search scope for the end boundary can be limited to exclude the portion of the element that precedes
+ // the start boundary
+ end = getTextRangeBoundaryPosition(this.textRange, rangeContainerElement, false, false,
+ startBoundary.nodeInfo).boundaryPosition;
+ }
+
+ this.setStart(start.node, start.offset);
+ this.setEnd(end.node, end.offset);
+ };
+
+ WrappedTextRange.prototype.getName = function() {
+ return "WrappedTextRange";
+ };
+
+ DomRange.copyComparisonConstants(WrappedTextRange);
+
+ var rangeToTextRange = function(range) {
+ if (range.collapsed) {
+ return createBoundaryTextRange(new DomPosition(range.startContainer, range.startOffset), true);
+ } else {
+ var startRange = createBoundaryTextRange(new DomPosition(range.startContainer, range.startOffset), true);
+ var endRange = createBoundaryTextRange(new DomPosition(range.endContainer, range.endOffset), false);
+ var textRange = getBody( DomRange.getRangeDocument(range) ).createTextRange();
+ textRange.setEndPoint("StartToStart", startRange);
+ textRange.setEndPoint("EndToEnd", endRange);
+ return textRange;
+ }
+ };
+
+ WrappedTextRange.rangeToTextRange = rangeToTextRange;
+
+ WrappedTextRange.prototype.toTextRange = function() {
+ return rangeToTextRange(this);
+ };
+
+ api.WrappedTextRange = WrappedTextRange;
+
+ // IE 9 and above have both implementations and Rangy makes both available. The next few lines sets which
+ // implementation to use by default.
+ if (!api.features.implementsDomRange || api.config.preferTextRange) {
+ // Add WrappedTextRange as the Range property of the global object to allow expression like Range.END_TO_END to work
+ var globalObj = (function(f) { return f("return this;")(); })(Function);
+ if (typeof globalObj.Range == "undefined") {
+ globalObj.Range = WrappedTextRange;
+ }
+
+ api.createNativeRange = function(doc) {
+ doc = getContentDocument(doc, module, "createNativeRange");
+ return getBody(doc).createTextRange();
+ };
+
+ api.WrappedRange = WrappedTextRange;
+ }
+ }
+
+ api.createRange = function(doc) {
+ doc = getContentDocument(doc, module, "createRange");
+ return new api.WrappedRange(api.createNativeRange(doc));
+ };
+
+ api.createRangyRange = function(doc) {
+ doc = getContentDocument(doc, module, "createRangyRange");
+ return new DomRange(doc);
+ };
+
+ api.createIframeRange = function(iframeEl) {
+ module.deprecationNotice("createIframeRange()", "createRange(iframeEl)");
+ return api.createRange(iframeEl);
+ };
+
+ api.createIframeRangyRange = function(iframeEl) {
+ module.deprecationNotice("createIframeRangyRange()", "createRangyRange(iframeEl)");
+ return api.createRangyRange(iframeEl);
+ };
+
+ api.addShimListener(function(win) {
+ var doc = win.document;
+ if (typeof doc.createRange == "undefined") {
+ doc.createRange = function() {
+ return api.createRange(doc);
+ };
+ }
+ doc = win = null;
+ });
+ });\r
+\r
+ /*----------------------------------------------------------------------------------------------------------------*/\r
+\r
+ // This module creates a selection object wrapper that conforms as closely as possible to the Selection specification
+ // in the HTML Editing spec (http://dvcs.w3.org/hg/editing/raw-file/tip/editing.html#selections)
+ api.createCoreModule("WrappedSelection", ["DomRange", "WrappedRange"], function(api, module) {
+ api.config.checkSelectionRanges = true;
+
+ var BOOLEAN = "boolean";
+ var NUMBER = "number";
+ var dom = api.dom;
+ var util = api.util;
+ var isHostMethod = util.isHostMethod;
+ var DomRange = api.DomRange;
+ var WrappedRange = api.WrappedRange;
+ var DOMException = api.DOMException;
+ var DomPosition = dom.DomPosition;
+ var getNativeSelection;
+ var selectionIsCollapsed;
+ var features = api.features;
+ var CONTROL = "Control";
+ var getDocument = dom.getDocument;
+ var getBody = dom.getBody;
+ var rangesEqual = DomRange.rangesEqual;
+
+
+ // Utility function to support direction parameters in the API that may be a string ("backward" or "forward") or a
+ // Boolean (true for backwards).
+ function isDirectionBackward(dir) {
+ return (typeof dir == "string") ? /^backward(s)?$/i.test(dir) : !!dir;
+ }
+
+ function getWindow(win, methodName) {
+ if (!win) {
+ return window;
+ } else if (dom.isWindow(win)) {
+ return win;
+ } else if (win instanceof WrappedSelection) {
+ return win.win;
+ } else {
+ var doc = dom.getContentDocument(win, module, methodName);
+ return dom.getWindow(doc);
+ }
+ }
+
+ function getWinSelection(winParam) {
+ return getWindow(winParam, "getWinSelection").getSelection();
+ }
+
+ function getDocSelection(winParam) {
+ return getWindow(winParam, "getDocSelection").document.selection;
+ }
+
+ function winSelectionIsBackward(sel) {
+ var backward = false;
+ if (sel.anchorNode) {
+ backward = (dom.comparePoints(sel.anchorNode, sel.anchorOffset, sel.focusNode, sel.focusOffset) == 1);
+ }
+ return backward;
+ }
+
+ // Test for the Range/TextRange and Selection features required
+ // Test for ability to retrieve selection
+ var implementsWinGetSelection = isHostMethod(window, "getSelection"),
+ implementsDocSelection = util.isHostObject(document, "selection");
+
+ features.implementsWinGetSelection = implementsWinGetSelection;
+ features.implementsDocSelection = implementsDocSelection;
+
+ var useDocumentSelection = implementsDocSelection && (!implementsWinGetSelection || api.config.preferTextRange);
+
+ if (useDocumentSelection) {
+ getNativeSelection = getDocSelection;
+ api.isSelectionValid = function(winParam) {
+ var doc = getWindow(winParam, "isSelectionValid").document, nativeSel = doc.selection;
+
+ // Check whether the selection TextRange is actually contained within the correct document
+ return (nativeSel.type != "None" || getDocument(nativeSel.createRange().parentElement()) == doc);
+ };
+ } else if (implementsWinGetSelection) {
+ getNativeSelection = getWinSelection;
+ api.isSelectionValid = function() {
+ return true;
+ };
+ } else {
+ module.fail("Neither document.selection or window.getSelection() detected.");
+ }
+
+ api.getNativeSelection = getNativeSelection;
+
+ var testSelection = getNativeSelection();
+ var testRange = api.createNativeRange(document);
+ var body = getBody(document);
+
+ // Obtaining a range from a selection
+ var selectionHasAnchorAndFocus = util.areHostProperties(testSelection,
+ ["anchorNode", "focusNode", "anchorOffset", "focusOffset"]);
+
+ features.selectionHasAnchorAndFocus = selectionHasAnchorAndFocus;
+
+ // Test for existence of native selection extend() method
+ var selectionHasExtend = isHostMethod(testSelection, "extend");
+ features.selectionHasExtend = selectionHasExtend;
+
+ // Test if rangeCount exists
+ var selectionHasRangeCount = (typeof testSelection.rangeCount == NUMBER);
+ features.selectionHasRangeCount = selectionHasRangeCount;
+
+ var selectionSupportsMultipleRanges = false;
+ var collapsedNonEditableSelectionsSupported = true;
+
+ var addRangeBackwardToNative = selectionHasExtend ?
+ function(nativeSelection, range) {
+ var doc = DomRange.getRangeDocument(range);
+ var endRange = api.createRange(doc);
+ endRange.collapseToPoint(range.endContainer, range.endOffset);
+ nativeSelection.addRange(getNativeRange(endRange));
+ nativeSelection.extend(range.startContainer, range.startOffset);
+ } : null;
+
+ if (util.areHostMethods(testSelection, ["addRange", "getRangeAt", "removeAllRanges"]) &&
+ typeof testSelection.rangeCount == NUMBER && features.implementsDomRange) {
+
+ (function() {
+ // Previously an iframe was used but this caused problems in some circumstances in IE, so tests are
+ // performed on the current document's selection. See issue 109.
+
+ // Note also that if a selection previously existed, it is wiped by these tests. This should usually be fine
+ // because initialization usually happens when the document loads, but could be a problem for a script that
+ // loads and initializes Rangy later. If anyone complains, code could be added to save and restore the
+ // selection.
+ var sel = window.getSelection();
+ if (sel) {
+ // Store the current selection
+ var originalSelectionRangeCount = sel.rangeCount;
+ var selectionHasMultipleRanges = (originalSelectionRangeCount > 1);
+ var originalSelectionRanges = [];
+ var originalSelectionBackward = winSelectionIsBackward(sel);
+ for (var i = 0; i < originalSelectionRangeCount; ++i) {
+ originalSelectionRanges[i] = sel.getRangeAt(i);
+ }
+
+ // Create some test elements
+ var body = getBody(document);
+ var testEl = body.appendChild( document.createElement("div") );
+ testEl.contentEditable = "false";
+ var textNode = testEl.appendChild( document.createTextNode("\u00a0\u00a0\u00a0") );
+
+ // Test whether the native selection will allow a collapsed selection within a non-editable element
+ var r1 = document.createRange();
+
+ r1.setStart(textNode, 1);
+ r1.collapse(true);
+ sel.addRange(r1);
+ collapsedNonEditableSelectionsSupported = (sel.rangeCount == 1);
+ sel.removeAllRanges();
+
+ // Test whether the native selection is capable of supporting multiple ranges.
+ if (!selectionHasMultipleRanges) {
+ // Doing the original feature test here in Chrome 36 (and presumably later versions) prints a
+ // console error of "Discontiguous selection is not supported." that cannot be suppressed. There's
+ // nothing we can do about this while retaining the feature test so we have to resort to a browser
+ // sniff. I'm not happy about it. See
+ // https://code.google.com/p/chromium/issues/detail?id=399791
+ var chromeMatch = window.navigator.appVersion.match(/Chrome\/(.*?) /);
+ if (chromeMatch && parseInt(chromeMatch[1]) >= 36) {
+ selectionSupportsMultipleRanges = false;
+ } else {
+ var r2 = r1.cloneRange();
+ r1.setStart(textNode, 0);
+ r2.setEnd(textNode, 3);
+ r2.setStart(textNode, 2);
+ sel.addRange(r1);
+ sel.addRange(r2);
+ selectionSupportsMultipleRanges = (sel.rangeCount == 2);
+ }
+ }
+
+ // Clean up
+ body.removeChild(testEl);
+ sel.removeAllRanges();
+
+ for (i = 0; i < originalSelectionRangeCount; ++i) {
+ if (i == 0 && originalSelectionBackward) {
+ if (addRangeBackwardToNative) {
+ addRangeBackwardToNative(sel, originalSelectionRanges[i]);
+ } else {
+ api.warn("Rangy initialization: original selection was backwards but selection has been restored forwards because the browser does not support Selection.extend");
+ sel.addRange(originalSelectionRanges[i]);
+ }
+ } else {
+ sel.addRange(originalSelectionRanges[i]);
+ }
+ }
+ }
+ })();
+ }
+
+ features.selectionSupportsMultipleRanges = selectionSupportsMultipleRanges;
+ features.collapsedNonEditableSelectionsSupported = collapsedNonEditableSelectionsSupported;
+
+ // ControlRanges
+ var implementsControlRange = false, testControlRange;
+
+ if (body && isHostMethod(body, "createControlRange")) {
+ testControlRange = body.createControlRange();
+ if (util.areHostProperties(testControlRange, ["item", "add"])) {
+ implementsControlRange = true;
+ }
+ }
+ features.implementsControlRange = implementsControlRange;
+
+ // Selection collapsedness
+ if (selectionHasAnchorAndFocus) {
+ selectionIsCollapsed = function(sel) {
+ return sel.anchorNode === sel.focusNode && sel.anchorOffset === sel.focusOffset;
+ };
+ } else {
+ selectionIsCollapsed = function(sel) {
+ return sel.rangeCount ? sel.getRangeAt(sel.rangeCount - 1).collapsed : false;
+ };
+ }
+
+ function updateAnchorAndFocusFromRange(sel, range, backward) {
+ var anchorPrefix = backward ? "end" : "start", focusPrefix = backward ? "start" : "end";
+ sel.anchorNode = range[anchorPrefix + "Container"];
+ sel.anchorOffset = range[anchorPrefix + "Offset"];
+ sel.focusNode = range[focusPrefix + "Container"];
+ sel.focusOffset = range[focusPrefix + "Offset"];
+ }
+
+ function updateAnchorAndFocusFromNativeSelection(sel) {
+ var nativeSel = sel.nativeSelection;
+ sel.anchorNode = nativeSel.anchorNode;
+ sel.anchorOffset = nativeSel.anchorOffset;
+ sel.focusNode = nativeSel.focusNode;
+ sel.focusOffset = nativeSel.focusOffset;
+ }
+
+ function updateEmptySelection(sel) {
+ sel.anchorNode = sel.focusNode = null;
+ sel.anchorOffset = sel.focusOffset = 0;
+ sel.rangeCount = 0;
+ sel.isCollapsed = true;
+ sel._ranges.length = 0;
+ }
+
+ function getNativeRange(range) {
+ var nativeRange;
+ if (range instanceof DomRange) {
+ nativeRange = api.createNativeRange(range.getDocument());
+ nativeRange.setEnd(range.endContainer, range.endOffset);
+ nativeRange.setStart(range.startContainer, range.startOffset);
+ } else if (range instanceof WrappedRange) {
+ nativeRange = range.nativeRange;
+ } else if (features.implementsDomRange && (range instanceof dom.getWindow(range.startContainer).Range)) {
+ nativeRange = range;
+ }
+ return nativeRange;
+ }
+
+ function rangeContainsSingleElement(rangeNodes) {
+ if (!rangeNodes.length || rangeNodes[0].nodeType != 1) {
+ return false;
+ }
+ for (var i = 1, len = rangeNodes.length; i < len; ++i) {
+ if (!dom.isAncestorOf(rangeNodes[0], rangeNodes[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ function getSingleElementFromRange(range) {
+ var nodes = range.getNodes();
+ if (!rangeContainsSingleElement(nodes)) {
+ throw module.createError("getSingleElementFromRange: range " + range.inspect() + " did not consist of a single element");
+ }
+ return nodes[0];
+ }
+
+ // Simple, quick test which only needs to distinguish between a TextRange and a ControlRange
+ function isTextRange(range) {
+ return !!range && typeof range.text != "undefined";
+ }
+
+ function updateFromTextRange(sel, range) {
+ // Create a Range from the selected TextRange
+ var wrappedRange = new WrappedRange(range);
+ sel._ranges = [wrappedRange];
+
+ updateAnchorAndFocusFromRange(sel, wrappedRange, false);
+ sel.rangeCount = 1;
+ sel.isCollapsed = wrappedRange.collapsed;
+ }
+
+ function updateControlSelection(sel) {
+ // Update the wrapped selection based on what's now in the native selection
+ sel._ranges.length = 0;
+ if (sel.docSelection.type == "None") {
+ updateEmptySelection(sel);
+ } else {
+ var controlRange = sel.docSelection.createRange();
+ if (isTextRange(controlRange)) {
+ // This case (where the selection type is "Control" and calling createRange() on the selection returns
+ // a TextRange) can happen in IE 9. It happens, for example, when all elements in the selected
+ // ControlRange have been removed from the ControlRange and removed from the document.
+ updateFromTextRange(sel, controlRange);
+ } else {
+ sel.rangeCount = controlRange.length;
+ var range, doc = getDocument(controlRange.item(0));
+ for (var i = 0; i < sel.rangeCount; ++i) {
+ range = api.createRange(doc);
+ range.selectNode(controlRange.item(i));
+ sel._ranges.push(range);
+ }
+ sel.isCollapsed = sel.rangeCount == 1 && sel._ranges[0].collapsed;
+ updateAnchorAndFocusFromRange(sel, sel._ranges[sel.rangeCount - 1], false);
+ }
+ }
+ }
+
+ function addRangeToControlSelection(sel, range) {
+ var controlRange = sel.docSelection.createRange();
+ var rangeElement = getSingleElementFromRange(range);
+
+ // Create a new ControlRange containing all the elements in the selected ControlRange plus the element
+ // contained by the supplied range
+ var doc = getDocument(controlRange.item(0));
+ var newControlRange = getBody(doc).createControlRange();
+ for (var i = 0, len = controlRange.length; i < len; ++i) {
+ newControlRange.add(controlRange.item(i));
+ }
+ try {
+ newControlRange.add(rangeElement);
+ } catch (ex) {
+ throw module.createError("addRange(): Element within the specified Range could not be added to control selection (does it have layout?)");
+ }
+ newControlRange.select();
+
+ // Update the wrapped selection based on what's now in the native selection
+ updateControlSelection(sel);
+ }
+
+ var getSelectionRangeAt;
+
+ if (isHostMethod(testSelection, "getRangeAt")) {
+ // try/catch is present because getRangeAt() must have thrown an error in some browser and some situation.
+ // Unfortunately, I didn't write a comment about the specifics and am now scared to take it out. Let that be a
+ // lesson to us all, especially me.
+ getSelectionRangeAt = function(sel, index) {
+ try {
+ return sel.getRangeAt(index);
+ } catch (ex) {
+ return null;
+ }
+ };
+ } else if (selectionHasAnchorAndFocus) {
+ getSelectionRangeAt = function(sel) {
+ var doc = getDocument(sel.anchorNode);
+ var range = api.createRange(doc);
+ range.setStartAndEnd(sel.anchorNode, sel.anchorOffset, sel.focusNode, sel.focusOffset);
+
+ // Handle the case when the selection was selected backwards (from the end to the start in the
+ // document)
+ if (range.collapsed !== this.isCollapsed) {
+ range.setStartAndEnd(sel.focusNode, sel.focusOffset, sel.anchorNode, sel.anchorOffset);
+ }
+
+ return range;
+ };
+ }
+
+ function WrappedSelection(selection, docSelection, win) {
+ this.nativeSelection = selection;
+ this.docSelection = docSelection;
+ this._ranges = [];
+ this.win = win;
+ this.refresh();
+ }
+
+ WrappedSelection.prototype = api.selectionPrototype;
+
+ function deleteProperties(sel) {
+ sel.win = sel.anchorNode = sel.focusNode = sel._ranges = null;
+ sel.rangeCount = sel.anchorOffset = sel.focusOffset = 0;
+ sel.detached = true;
+ }
+
+ var cachedRangySelections = [];
+
+ function actOnCachedSelection(win, action) {
+ var i = cachedRangySelections.length, cached, sel;
+ while (i--) {
+ cached = cachedRangySelections[i];
+ sel = cached.selection;
+ if (action == "deleteAll") {
+ deleteProperties(sel);
+ } else if (cached.win == win) {
+ if (action == "delete") {
+ cachedRangySelections.splice(i, 1);
+ return true;
+ } else {
+ return sel;
+ }
+ }
+ }
+ if (action == "deleteAll") {
+ cachedRangySelections.length = 0;
+ }
+ return null;
+ }
+
+ var getSelection = function(win) {
+ // Check if the parameter is a Rangy Selection object
+ if (win && win instanceof WrappedSelection) {
+ win.refresh();
+ return win;
+ }
+
+ win = getWindow(win, "getNativeSelection");
+
+ var sel = actOnCachedSelection(win);
+ var nativeSel = getNativeSelection(win), docSel = implementsDocSelection ? getDocSelection(win) : null;
+ if (sel) {
+ sel.nativeSelection = nativeSel;
+ sel.docSelection = docSel;
+ sel.refresh();
+ } else {
+ sel = new WrappedSelection(nativeSel, docSel, win);
+ cachedRangySelections.push( { win: win, selection: sel } );
+ }
+ return sel;
+ };
+
+ api.getSelection = getSelection;
+
+ api.getIframeSelection = function(iframeEl) {
+ module.deprecationNotice("getIframeSelection()", "getSelection(iframeEl)");
+ return api.getSelection(dom.getIframeWindow(iframeEl));
+ };
+
+ var selProto = WrappedSelection.prototype;
+
+ function createControlSelection(sel, ranges) {
+ // Ensure that the selection becomes of type "Control"
+ var doc = getDocument(ranges[0].startContainer);
+ var controlRange = getBody(doc).createControlRange();
+ for (var i = 0, el, len = ranges.length; i < len; ++i) {
+ el = getSingleElementFromRange(ranges[i]);
+ try {
+ controlRange.add(el);
+ } catch (ex) {
+ throw module.createError("setRanges(): Element within one of the specified Ranges could not be added to control selection (does it have layout?)");
+ }
+ }
+ controlRange.select();
+
+ // Update the wrapped selection based on what's now in the native selection
+ updateControlSelection(sel);
+ }
+
+ // Selecting a range
+ if (!useDocumentSelection && selectionHasAnchorAndFocus && util.areHostMethods(testSelection, ["removeAllRanges", "addRange"])) {
+ selProto.removeAllRanges = function() {
+ this.nativeSelection.removeAllRanges();
+ updateEmptySelection(this);
+ };
+
+ var addRangeBackward = function(sel, range) {
+ addRangeBackwardToNative(sel.nativeSelection, range);
+ sel.refresh();
+ };
+
+ if (selectionHasRangeCount) {
+ selProto.addRange = function(range, direction) {
+ if (implementsControlRange && implementsDocSelection && this.docSelection.type == CONTROL) {
+ addRangeToControlSelection(this, range);
+ } else {
+ if (isDirectionBackward(direction) && selectionHasExtend) {
+ addRangeBackward(this, range);
+ } else {
+ var previousRangeCount;
+ if (selectionSupportsMultipleRanges) {
+ previousRangeCount = this.rangeCount;
+ } else {
+ this.removeAllRanges();
+ previousRangeCount = 0;
+ }
+ // Clone the native range so that changing the selected range does not affect the selection.
+ // This is contrary to the spec but is the only way to achieve consistency between browsers. See
+ // issue 80.
+ var clonedNativeRange = getNativeRange(range).cloneRange();
+ try {
+ this.nativeSelection.addRange(clonedNativeRange);
+ } catch (ex) {
+ }
+
+ // Check whether adding the range was successful
+ this.rangeCount = this.nativeSelection.rangeCount;
+
+ if (this.rangeCount == previousRangeCount + 1) {
+ // The range was added successfully
+
+ // Check whether the range that we added to the selection is reflected in the last range extracted from
+ // the selection
+ if (api.config.checkSelectionRanges) {
+ var nativeRange = getSelectionRangeAt(this.nativeSelection, this.rangeCount - 1);
+ if (nativeRange && !rangesEqual(nativeRange, range)) {
+ // Happens in WebKit with, for example, a selection placed at the start of a text node
+ range = new WrappedRange(nativeRange);
+ }
+ }
+ this._ranges[this.rangeCount - 1] = range;
+ updateAnchorAndFocusFromRange(this, range, selectionIsBackward(this.nativeSelection));
+ this.isCollapsed = selectionIsCollapsed(this);
+ } else {
+ // The range was not added successfully. The simplest thing is to refresh
+ this.refresh();
+ }
+ }
+ }
+ };
+ } else {
+ selProto.addRange = function(range, direction) {
+ if (isDirectionBackward(direction) && selectionHasExtend) {
+ addRangeBackward(this, range);
+ } else {
+ this.nativeSelection.addRange(getNativeRange(range));
+ this.refresh();
+ }
+ };
+ }
+
+ selProto.setRanges = function(ranges) {
+ if (implementsControlRange && implementsDocSelection && ranges.length > 1) {
+ createControlSelection(this, ranges);
+ } else {
+ this.removeAllRanges();
+ for (var i = 0, len = ranges.length; i < len; ++i) {
+ this.addRange(ranges[i]);
+ }
+ }
+ };
+ } else if (isHostMethod(testSelection, "empty") && isHostMethod(testRange, "select") &&
+ implementsControlRange && useDocumentSelection) {
+
+ selProto.removeAllRanges = function() {
+ // Added try/catch as fix for issue #21
+ try {
+ this.docSelection.empty();
+
+ // Check for empty() not working (issue #24)
+ if (this.docSelection.type != "None") {
+ // Work around failure to empty a control selection by instead selecting a TextRange and then
+ // calling empty()
+ var doc;
+ if (this.anchorNode) {
+ doc = getDocument(this.anchorNode);
+ } else if (this.docSelection.type == CONTROL) {
+ var controlRange = this.docSelection.createRange();
+ if (controlRange.length) {
+ doc = getDocument( controlRange.item(0) );
+ }
+ }
+ if (doc) {
+ var textRange = getBody(doc).createTextRange();
+ textRange.select();
+ this.docSelection.empty();
+ }
+ }
+ } catch(ex) {}
+ updateEmptySelection(this);
+ };
+
+ selProto.addRange = function(range) {
+ if (this.docSelection.type == CONTROL) {
+ addRangeToControlSelection(this, range);
+ } else {
+ api.WrappedTextRange.rangeToTextRange(range).select();
+ this._ranges[0] = range;
+ this.rangeCount = 1;
+ this.isCollapsed = this._ranges[0].collapsed;
+ updateAnchorAndFocusFromRange(this, range, false);
+ }
+ };
+
+ selProto.setRanges = function(ranges) {
+ this.removeAllRanges();
+ var rangeCount = ranges.length;
+ if (rangeCount > 1) {
+ createControlSelection(this, ranges);
+ } else if (rangeCount) {
+ this.addRange(ranges[0]);
+ }
+ };
+ } else {
+ module.fail("No means of selecting a Range or TextRange was found");
+ return false;
+ }
+
+ selProto.getRangeAt = function(index) {
+ if (index < 0 || index >= this.rangeCount) {
+ throw new DOMException("INDEX_SIZE_ERR");
+ } else {
+ // Clone the range to preserve selection-range independence. See issue 80.
+ return this._ranges[index].cloneRange();
+ }
+ };
+
+ var refreshSelection;
+
+ if (useDocumentSelection) {
+ refreshSelection = function(sel) {
+ var range;
+ if (api.isSelectionValid(sel.win)) {
+ range = sel.docSelection.createRange();
+ } else {
+ range = getBody(sel.win.document).createTextRange();
+ range.collapse(true);
+ }
+
+ if (sel.docSelection.type == CONTROL) {
+ updateControlSelection(sel);
+ } else if (isTextRange(range)) {
+ updateFromTextRange(sel, range);
+ } else {
+ updateEmptySelection(sel);
+ }
+ };
+ } else if (isHostMethod(testSelection, "getRangeAt") && typeof testSelection.rangeCount == NUMBER) {
+ refreshSelection = function(sel) {
+ if (implementsControlRange && implementsDocSelection && sel.docSelection.type == CONTROL) {
+ updateControlSelection(sel);
+ } else {
+ sel._ranges.length = sel.rangeCount = sel.nativeSelection.rangeCount;
+ if (sel.rangeCount) {
+ for (var i = 0, len = sel.rangeCount; i < len; ++i) {
+ sel._ranges[i] = new api.WrappedRange(sel.nativeSelection.getRangeAt(i));
+ }
+ updateAnchorAndFocusFromRange(sel, sel._ranges[sel.rangeCount - 1], selectionIsBackward(sel.nativeSelection));
+ sel.isCollapsed = selectionIsCollapsed(sel);
+ } else {
+ updateEmptySelection(sel);
+ }
+ }
+ };
+ } else if (selectionHasAnchorAndFocus && typeof testSelection.isCollapsed == BOOLEAN && typeof testRange.collapsed == BOOLEAN && features.implementsDomRange) {
+ refreshSelection = function(sel) {
+ var range, nativeSel = sel.nativeSelection;
+ if (nativeSel.anchorNode) {
+ range = getSelectionRangeAt(nativeSel, 0);
+ sel._ranges = [range];
+ sel.rangeCount = 1;
+ updateAnchorAndFocusFromNativeSelection(sel);
+ sel.isCollapsed = selectionIsCollapsed(sel);
+ } else {
+ updateEmptySelection(sel);
+ }
+ };
+ } else {
+ module.fail("No means of obtaining a Range or TextRange from the user's selection was found");
+ return false;
+ }
+
+ selProto.refresh = function(checkForChanges) {
+ var oldRanges = checkForChanges ? this._ranges.slice(0) : null;
+ var oldAnchorNode = this.anchorNode, oldAnchorOffset = this.anchorOffset;
+
+ refreshSelection(this);
+ if (checkForChanges) {
+ // Check the range count first
+ var i = oldRanges.length;
+ if (i != this._ranges.length) {
+ return true;
+ }
+
+ // Now check the direction. Checking the anchor position is the same is enough since we're checking all the
+ // ranges after this
+ if (this.anchorNode != oldAnchorNode || this.anchorOffset != oldAnchorOffset) {
+ return true;
+ }
+
+ // Finally, compare each range in turn
+ while (i--) {
+ if (!rangesEqual(oldRanges[i], this._ranges[i])) {
+ return true;
+ }
+ }
+ return false;
+ }
+ };
+
+ // Removal of a single range
+ var removeRangeManually = function(sel, range) {
+ var ranges = sel.getAllRanges();
+ sel.removeAllRanges();
+ for (var i = 0, len = ranges.length; i < len; ++i) {
+ if (!rangesEqual(range, ranges[i])) {
+ sel.addRange(ranges[i]);
+ }
+ }
+ if (!sel.rangeCount) {
+ updateEmptySelection(sel);
+ }
+ };
+
+ if (implementsControlRange && implementsDocSelection) {
+ selProto.removeRange = function(range) {
+ if (this.docSelection.type == CONTROL) {
+ var controlRange = this.docSelection.createRange();
+ var rangeElement = getSingleElementFromRange(range);
+
+ // Create a new ControlRange containing all the elements in the selected ControlRange minus the
+ // element contained by the supplied range
+ var doc = getDocument(controlRange.item(0));
+ var newControlRange = getBody(doc).createControlRange();
+ var el, removed = false;
+ for (var i = 0, len = controlRange.length; i < len; ++i) {
+ el = controlRange.item(i);
+ if (el !== rangeElement || removed) {
+ newControlRange.add(controlRange.item(i));
+ } else {
+ removed = true;
+ }
+ }
+ newControlRange.select();
+
+ // Update the wrapped selection based on what's now in the native selection
+ updateControlSelection(this);
+ } else {
+ removeRangeManually(this, range);
+ }
+ };
+ } else {
+ selProto.removeRange = function(range) {
+ removeRangeManually(this, range);
+ };
+ }
+
+ // Detecting if a selection is backward
+ var selectionIsBackward;
+ if (!useDocumentSelection && selectionHasAnchorAndFocus && features.implementsDomRange) {
+ selectionIsBackward = winSelectionIsBackward;
+
+ selProto.isBackward = function() {
+ return selectionIsBackward(this);
+ };
+ } else {
+ selectionIsBackward = selProto.isBackward = function() {
+ return false;
+ };
+ }
+
+ // Create an alias for backwards compatibility. From 1.3, everything is "backward" rather than "backwards"
+ selProto.isBackwards = selProto.isBackward;
+
+ // Selection stringifier
+ // This is conformant to the old HTML5 selections draft spec but differs from WebKit and Mozilla's implementation.
+ // The current spec does not yet define this method.
+ selProto.toString = function() {
+ var rangeTexts = [];
+ for (var i = 0, len = this.rangeCount; i < len; ++i) {
+ rangeTexts[i] = "" + this._ranges[i];
+ }
+ return rangeTexts.join("");
+ };
+
+ function assertNodeInSameDocument(sel, node) {
+ if (sel.win.document != getDocument(node)) {
+ throw new DOMException("WRONG_DOCUMENT_ERR");
+ }
+ }
+
+ // No current browser conforms fully to the spec for this method, so Rangy's own method is always used
+ selProto.collapse = function(node, offset) {
+ assertNodeInSameDocument(this, node);
+ var range = api.createRange(node);
+ range.collapseToPoint(node, offset);
+ this.setSingleRange(range);
+ this.isCollapsed = true;
+ };
+
+ selProto.collapseToStart = function() {
+ if (this.rangeCount) {
+ var range = this._ranges[0];
+ this.collapse(range.startContainer, range.startOffset);
+ } else {
+ throw new DOMException("INVALID_STATE_ERR");
+ }
+ };
+
+ selProto.collapseToEnd = function() {
+ if (this.rangeCount) {
+ var range = this._ranges[this.rangeCount - 1];
+ this.collapse(range.endContainer, range.endOffset);
+ } else {
+ throw new DOMException("INVALID_STATE_ERR");
+ }
+ };
+
+ // The spec is very specific on how selectAllChildren should be implemented so the native implementation is
+ // never used by Rangy.
+ selProto.selectAllChildren = function(node) {
+ assertNodeInSameDocument(this, node);
+ var range = api.createRange(node);
+ range.selectNodeContents(node);
+ this.setSingleRange(range);
+ };
+
+ selProto.deleteFromDocument = function() {
+ // Sepcial behaviour required for IE's control selections
+ if (implementsControlRange && implementsDocSelection && this.docSelection.type == CONTROL) {
+ var controlRange = this.docSelection.createRange();
+ var element;
+ while (controlRange.length) {
+ element = controlRange.item(0);
+ controlRange.remove(element);
+ element.parentNode.removeChild(element);
+ }
+ this.refresh();
+ } else if (this.rangeCount) {
+ var ranges = this.getAllRanges();
+ if (ranges.length) {
+ this.removeAllRanges();
+ for (var i = 0, len = ranges.length; i < len; ++i) {
+ ranges[i].deleteContents();
+ }
+ // The spec says nothing about what the selection should contain after calling deleteContents on each
+ // range. Firefox moves the selection to where the final selected range was, so we emulate that
+ this.addRange(ranges[len - 1]);
+ }
+ }
+ };
+
+ // The following are non-standard extensions
+ selProto.eachRange = function(func, returnValue) {
+ for (var i = 0, len = this._ranges.length; i < len; ++i) {
+ if ( func( this.getRangeAt(i) ) ) {
+ return returnValue;
+ }
+ }
+ };
+
+ selProto.getAllRanges = function() {
+ var ranges = [];
+ this.eachRange(function(range) {
+ ranges.push(range);
+ });
+ return ranges;
+ };
+
+ selProto.setSingleRange = function(range, direction) {
+ this.removeAllRanges();
+ this.addRange(range, direction);
+ };
+
+ selProto.callMethodOnEachRange = function(methodName, params) {
+ var results = [];
+ this.eachRange( function(range) {
+ results.push( range[methodName].apply(range, params) );
+ } );
+ return results;
+ };
+
+ function createStartOrEndSetter(isStart) {
+ return function(node, offset) {
+ var range;
+ if (this.rangeCount) {
+ range = this.getRangeAt(0);
+ range["set" + (isStart ? "Start" : "End")](node, offset);
+ } else {
+ range = api.createRange(this.win.document);
+ range.setStartAndEnd(node, offset);
+ }
+ this.setSingleRange(range, this.isBackward());
+ };
+ }
+
+ selProto.setStart = createStartOrEndSetter(true);
+ selProto.setEnd = createStartOrEndSetter(false);
+
+ // Add select() method to Range prototype. Any existing selection will be removed.
+ api.rangePrototype.select = function(direction) {
+ getSelection( this.getDocument() ).setSingleRange(this, direction);
+ };
+
+ selProto.changeEachRange = function(func) {
+ var ranges = [];
+ var backward = this.isBackward();
+
+ this.eachRange(function(range) {
+ func(range);
+ ranges.push(range);
+ });
+
+ this.removeAllRanges();
+ if (backward && ranges.length == 1) {
+ this.addRange(ranges[0], "backward");
+ } else {
+ this.setRanges(ranges);
+ }
+ };
+
+ selProto.containsNode = function(node, allowPartial) {
+ return this.eachRange( function(range) {
+ return range.containsNode(node, allowPartial);
+ }, true ) || false;
+ };
+
+ selProto.getBookmark = function(containerNode) {
+ return {
+ backward: this.isBackward(),
+ rangeBookmarks: this.callMethodOnEachRange("getBookmark", [containerNode])
+ };
+ };
+
+ selProto.moveToBookmark = function(bookmark) {
+ var selRanges = [];
+ for (var i = 0, rangeBookmark, range; rangeBookmark = bookmark.rangeBookmarks[i++]; ) {
+ range = api.createRange(this.win);
+ range.moveToBookmark(rangeBookmark);
+ selRanges.push(range);
+ }
+ if (bookmark.backward) {
+ this.setSingleRange(selRanges[0], "backward");
+ } else {
+ this.setRanges(selRanges);
+ }
+ };
+
+ selProto.toHtml = function() {
+ var rangeHtmls = [];
+ this.eachRange(function(range) {
+ rangeHtmls.push( DomRange.toHtml(range) );
+ });
+ return rangeHtmls.join("");
+ };
+
+ if (features.implementsTextRange) {
+ selProto.getNativeTextRange = function() {
+ var sel, textRange;
+ if ( (sel = this.docSelection) ) {
+ var range = sel.createRange();
+ if (isTextRange(range)) {
+ return range;
+ } else {
+ throw module.createError("getNativeTextRange: selection is a control selection");
+ }
+ } else if (this.rangeCount > 0) {
+ return api.WrappedTextRange.rangeToTextRange( this.getRangeAt(0) );
+ } else {
+ throw module.createError("getNativeTextRange: selection contains no range");
+ }
+ };
+ }
+
+ function inspect(sel) {
+ var rangeInspects = [];
+ var anchor = new DomPosition(sel.anchorNode, sel.anchorOffset);
+ var focus = new DomPosition(sel.focusNode, sel.focusOffset);
+ var name = (typeof sel.getName == "function") ? sel.getName() : "Selection";
+
+ if (typeof sel.rangeCount != "undefined") {
+ for (var i = 0, len = sel.rangeCount; i < len; ++i) {
+ rangeInspects[i] = DomRange.inspect(sel.getRangeAt(i));
+ }
+ }
+ return "[" + name + "(Ranges: " + rangeInspects.join(", ") +
+ ")(anchor: " + anchor.inspect() + ", focus: " + focus.inspect() + "]";
+ }
+
+ selProto.getName = function() {
+ return "WrappedSelection";
+ };
+
+ selProto.inspect = function() {
+ return inspect(this);
+ };
+
+ selProto.detach = function() {
+ actOnCachedSelection(this.win, "delete");
+ deleteProperties(this);
+ };
+
+ WrappedSelection.detachAll = function() {
+ actOnCachedSelection(null, "deleteAll");
+ };
+
+ WrappedSelection.inspect = inspect;
+ WrappedSelection.isDirectionBackward = isDirectionBackward;
+
+ api.Selection = WrappedSelection;
+
+ api.selectionPrototype = selProto;
+
+ api.addShimListener(function(win) {
+ if (typeof win.getSelection == "undefined") {
+ win.getSelection = function() {
+ return getSelection(win);
+ };
+ }
+ win = null;
+ });
+ });
+ \r
+\r
+ /*----------------------------------------------------------------------------------------------------------------*/\r
+\r
+ // Wait for document to load before initializing\r
+ var docReady = false;\r
+\r
+ var loadHandler = function(e) {\r
+ if (!docReady) {\r
+ docReady = true;\r
+ if (!api.initialized && api.config.autoInitialize) {\r
+ init();\r
+ }\r
+ }\r
+ };\r
+\r
+ if (isBrowser) {\r
+ // Test whether the document has already been loaded and initialize immediately if so\r
+ if (document.readyState == "complete") {\r
+ loadHandler();\r
+ } else {\r
+ if (isHostMethod(document, "addEventListener")) {\r
+ document.addEventListener("DOMContentLoaded", loadHandler, false);\r
+ }\r
+\r
+ // Add a fallback in case the DOMContentLoaded event isn't supported\r
+ addListener(window, "load", loadHandler);\r
+ }\r
+ }\r
+\r
+ return api;\r
+}, this);;/**\r
+ * Selection save and restore module for Rangy.\r
+ * Saves and restores user selections using marker invisible elements in the DOM.\r
+ *\r
+ * Part of Rangy, a cross-browser JavaScript range and selection library\r
+ * https://github.com/timdown/rangy\r
+ *\r
+ * Depends on Rangy core.\r
+ *\r
+ * Copyright 2014, Tim Down\r
+ * Licensed under the MIT license.\r
+ * Version: 1.3.0-alpha.20140921\r
+ * Build date: 21 September 2014\r
+ */\r
+(function(factory, root) {
+ if (typeof define == "function" && define.amd) {
+ // AMD. Register as an anonymous module with a dependency on Rangy.
+ define(["./rangy-core"], factory);
+ } else if (typeof module != "undefined" && typeof exports == "object") {
+ // Node/CommonJS style
+ module.exports = factory( require("rangy") );
+ } else {
+ // No AMD or CommonJS support so we use the rangy property of root (probably the global variable)
+ factory(root.rangy);
+ }
+})(function(rangy) {
+ rangy.createModule("SaveRestore", ["WrappedRange"], function(api, module) {
+ var dom = api.dom;
+
+ var markerTextChar = "\ufeff";
+
+ function gEBI(id, doc) {
+ return (doc || document).getElementById(id);
+ }
+
+ function insertRangeBoundaryMarker(range, atStart) {
+ var markerId = "selectionBoundary_" + (+new Date()) + "_" + ("" + Math.random()).slice(2);
+ var markerEl;
+ var doc = dom.getDocument(range.startContainer);
+
+ // Clone the Range and collapse to the appropriate boundary point
+ var boundaryRange = range.cloneRange();
+ boundaryRange.collapse(atStart);
+
+ // Create the marker element containing a single invisible character using DOM methods and insert it
+ markerEl = doc.createElement("span");
+ markerEl.id = markerId;
+ markerEl.style.lineHeight = "0";
+ markerEl.style.display = "none";
+ markerEl.className = "rangySelectionBoundary";
+ markerEl.appendChild(doc.createTextNode(markerTextChar));
+
+ boundaryRange.insertNode(markerEl);
+ return markerEl;
+ }
+
+ function setRangeBoundary(doc, range, markerId, atStart) {
+ var markerEl = gEBI(markerId, doc);
+ if (markerEl) {
+ range[atStart ? "setStartBefore" : "setEndBefore"](markerEl);
+ markerEl.parentNode.removeChild(markerEl);
+ } else {
+ module.warn("Marker element has been removed. Cannot restore selection.");
+ }
+ }
+
+ function compareRanges(r1, r2) {
+ return r2.compareBoundaryPoints(r1.START_TO_START, r1);
+ }
+
+ function saveRange(range, backward) {
+ var startEl, endEl, doc = api.DomRange.getRangeDocument(range), text = range.toString();
+
+ if (range.collapsed) {
+ endEl = insertRangeBoundaryMarker(range, false);
+ return {
+ document: doc,
+ markerId: endEl.id,
+ collapsed: true
+ };
+ } else {
+ endEl = insertRangeBoundaryMarker(range, false);
+ startEl = insertRangeBoundaryMarker(range, true);
+
+ return {
+ document: doc,
+ startMarkerId: startEl.id,
+ endMarkerId: endEl.id,
+ collapsed: false,
+ backward: backward,
+ toString: function() {
+ return "original text: '" + text + "', new text: '" + range.toString() + "'";
+ }
+ };
+ }
+ }
+
+ function restoreRange(rangeInfo, normalize) {
+ var doc = rangeInfo.document;
+ if (typeof normalize == "undefined") {
+ normalize = true;
+ }
+ var range = api.createRange(doc);
+ if (rangeInfo.collapsed) {
+ var markerEl = gEBI(rangeInfo.markerId, doc);
+ if (markerEl) {
+ markerEl.style.display = "inline";
+ var previousNode = markerEl.previousSibling;
+
+ // Workaround for issue 17
+ if (previousNode && previousNode.nodeType == 3) {
+ markerEl.parentNode.removeChild(markerEl);
+ range.collapseToPoint(previousNode, previousNode.length);
+ } else {
+ range.collapseBefore(markerEl);
+ markerEl.parentNode.removeChild(markerEl);
+ }
+ } else {
+ module.warn("Marker element has been removed. Cannot restore selection.");
+ }
+ } else {
+ setRangeBoundary(doc, range, rangeInfo.startMarkerId, true);
+ setRangeBoundary(doc, range, rangeInfo.endMarkerId, false);
+ }
+
+ if (normalize) {
+ range.normalizeBoundaries();
+ }
+
+ return range;
+ }
+
+ function saveRanges(ranges, backward) {
+ var rangeInfos = [], range, doc;
+
+ // Order the ranges by position within the DOM, latest first, cloning the array to leave the original untouched
+ ranges = ranges.slice(0);
+ ranges.sort(compareRanges);
+
+ for (var i = 0, len = ranges.length; i < len; ++i) {
+ rangeInfos[i] = saveRange(ranges[i], backward);
+ }
+
+ // Now that all the markers are in place and DOM manipulation over, adjust each range's boundaries to lie
+ // between its markers
+ for (i = len - 1; i >= 0; --i) {
+ range = ranges[i];
+ doc = api.DomRange.getRangeDocument(range);
+ if (range.collapsed) {
+ range.collapseAfter(gEBI(rangeInfos[i].markerId, doc));
+ } else {
+ range.setEndBefore(gEBI(rangeInfos[i].endMarkerId, doc));
+ range.setStartAfter(gEBI(rangeInfos[i].startMarkerId, doc));
+ }
+ }
+
+ return rangeInfos;
+ }
+
+ function saveSelection(win) {
+ if (!api.isSelectionValid(win)) {
+ module.warn("Cannot save selection. This usually happens when the selection is collapsed and the selection document has lost focus.");
+ return null;
+ }
+ var sel = api.getSelection(win);
+ var ranges = sel.getAllRanges();
+ var backward = (ranges.length == 1 && sel.isBackward());
+
+ var rangeInfos = saveRanges(ranges, backward);
+
+ // Ensure current selection is unaffected
+ if (backward) {
+ sel.setSingleRange(ranges[0], "backward");
+ } else {
+ sel.setRanges(ranges);
+ }
+
+ return {
+ win: win,
+ rangeInfos: rangeInfos,
+ restored: false
+ };
+ }
+
+ function restoreRanges(rangeInfos) {
+ var ranges = [];
+
+ // Ranges are in reverse order of appearance in the DOM. We want to restore earliest first to avoid
+ // normalization affecting previously restored ranges.
+ var rangeCount = rangeInfos.length;
+
+ for (var i = rangeCount - 1; i >= 0; i--) {
+ ranges[i] = restoreRange(rangeInfos[i], true);
+ }
+
+ return ranges;
+ }
+
+ function restoreSelection(savedSelection, preserveDirection) {
+ if (!savedSelection.restored) {
+ var rangeInfos = savedSelection.rangeInfos;
+ var sel = api.getSelection(savedSelection.win);
+ var ranges = restoreRanges(rangeInfos), rangeCount = rangeInfos.length;
+
+ if (rangeCount == 1 && preserveDirection && api.features.selectionHasExtend && rangeInfos[0].backward) {
+ sel.removeAllRanges();
+ sel.addRange(ranges[0], true);
+ } else {
+ sel.setRanges(ranges);
+ }
+
+ savedSelection.restored = true;
+ }
+ }
+
+ function removeMarkerElement(doc, markerId) {
+ var markerEl = gEBI(markerId, doc);
+ if (markerEl) {
+ markerEl.parentNode.removeChild(markerEl);
+ }
+ }
+
+ function removeMarkers(savedSelection) {
+ var rangeInfos = savedSelection.rangeInfos;
+ for (var i = 0, len = rangeInfos.length, rangeInfo; i < len; ++i) {
+ rangeInfo = rangeInfos[i];
+ if (rangeInfo.collapsed) {
+ removeMarkerElement(savedSelection.doc, rangeInfo.markerId);
+ } else {
+ removeMarkerElement(savedSelection.doc, rangeInfo.startMarkerId);
+ removeMarkerElement(savedSelection.doc, rangeInfo.endMarkerId);
+ }
+ }
+ }
+
+ api.util.extend(api, {
+ saveRange: saveRange,
+ restoreRange: restoreRange,
+ saveRanges: saveRanges,
+ restoreRanges: restoreRanges,
+ saveSelection: saveSelection,
+ restoreSelection: restoreSelection,
+ removeMarkerElement: removeMarkerElement,
+ removeMarkers: removeMarkers
+ });
+ });
+
+}, this);;/*
+ Base.js, version 1.1a
+ Copyright 2006-2010, Dean Edwards
+ License: http://www.opensource.org/licenses/mit-license.php
+*/
+
+var Base = function() {
+ // dummy
+};
+
+Base.extend = function(_instance, _static) { // subclass
+ var extend = Base.prototype.extend;
+
+ // build the prototype
+ Base._prototyping = true;
+ var proto = new this;
+ extend.call(proto, _instance);
+ proto.base = function() {
+ // call this method from any other method to invoke that method's ancestor
+ };
+ delete Base._prototyping;
+
+ // create the wrapper for the constructor function
+ //var constructor = proto.constructor.valueOf(); //-dean
+ var constructor = proto.constructor;
+ var klass = proto.constructor = function() {
+ if (!Base._prototyping) {
+ if (this._constructing || this.constructor == klass) { // instantiation
+ this._constructing = true;
+ constructor.apply(this, arguments);
+ delete this._constructing;
+ } else if (arguments[0] != null) { // casting
+ return (arguments[0].extend || extend).call(arguments[0], proto);
+ }
+ }
+ };
+
+ // build the class interface
+ klass.ancestor = this;
+ klass.extend = this.extend;
+ klass.forEach = this.forEach;
+ klass.implement = this.implement;
+ klass.prototype = proto;
+ klass.toString = this.toString;
+ klass.valueOf = function(type) {
+ //return (type == "object") ? klass : constructor; //-dean
+ return (type == "object") ? klass : constructor.valueOf();
+ };
+ extend.call(klass, _static);
+ // class initialisation
+ if (typeof klass.init == "function") klass.init();
+ return klass;
+};
+
+Base.prototype = {
+ extend: function(source, value) {
+ if (arguments.length > 1) { // extending with a name/value pair
+ var ancestor = this[source];
+ if (ancestor && (typeof value == "function") && // overriding a method?
+ // the valueOf() comparison is to avoid circular references
+ (!ancestor.valueOf || ancestor.valueOf() != value.valueOf()) &&
+ /\bbase\b/.test(value)) {
+ // get the underlying method
+ var method = value.valueOf();
+ // override
+ value = function() {
+ var previous = this.base || Base.prototype.base;
+ this.base = ancestor;
+ var returnValue = method.apply(this, arguments);
+ this.base = previous;
+ return returnValue;
+ };
+ // point to the underlying method
+ value.valueOf = function(type) {
+ return (type == "object") ? value : method;
+ };
+ value.toString = Base.toString;
+ }
+ this[source] = value;
+ } else if (source) { // extending with an object literal
+ var extend = Base.prototype.extend;
+ // if this object has a customised extend method then use it
+ if (!Base._prototyping && typeof this != "function") {
+ extend = this.extend || extend;
+ }
+ var proto = {toSource: null};
+ // do the "toString" and other methods manually
+ var hidden = ["constructor", "toString", "valueOf"];
+ // if we are prototyping then include the constructor
+ var i = Base._prototyping ? 0 : 1;
+ while (key = hidden[i++]) {
+ if (source[key] != proto[key]) {
+ extend.call(this, key, source[key]);
+
+ }
+ }
+ // copy each of the source object's properties to this object
+ for (var key in source) {
+ if (!proto[key]) extend.call(this, key, source[key]);
+ }
+ }
+ return this;
+ }
+};
+
+// initialise
+Base = Base.extend({
+ constructor: function() {
+ this.extend(arguments[0]);
+ }
+}, {
+ ancestor: Object,
+ version: "1.1",
+
+ forEach: function(object, block, context) {
+ for (var key in object) {
+ if (this.prototype[key] === undefined) {
+ block.call(context, object[key], key, object);
+ }
+ }
+ },
+
+ implement: function() {
+ for (var i = 0; i < arguments.length; i++) {
+ if (typeof arguments[i] == "function") {
+ // if it's a function, call it
+ arguments[i](this.prototype);
+ } else {
+ // add the interface using the extend method
+ this.prototype.extend(arguments[i]);
+ }
+ }
+ return this;
+ },
+
+ toString: function() {
+ return String(this.valueOf());
+ }
+});;/**
+ * Detect browser support for specific features
+ */
+wysihtml5.browser = (function() {
+ var userAgent = navigator.userAgent,
+ testElement = document.createElement("div"),
+ // Browser sniffing is unfortunately needed since some behaviors are impossible to feature detect
+ isGecko = userAgent.indexOf("Gecko") !== -1 && userAgent.indexOf("KHTML") === -1,
+ isWebKit = userAgent.indexOf("AppleWebKit/") !== -1,
+ isChrome = userAgent.indexOf("Chrome/") !== -1,
+ isOpera = userAgent.indexOf("Opera/") !== -1;
+
+ function iosVersion(userAgent) {
+ return +((/ipad|iphone|ipod/.test(userAgent) && userAgent.match(/ os (\d+).+? like mac os x/)) || [undefined, 0])[1];
+ }
+
+ function androidVersion(userAgent) {
+ return +(userAgent.match(/android (\d+)/) || [undefined, 0])[1];
+ }
+
+ function isIE(version, equation) {
+ var rv = -1,
+ re;
+
+ if (navigator.appName == 'Microsoft Internet Explorer') {
+ re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
+ } else if (navigator.appName == 'Netscape') {
+ re = new RegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})");
+ }
+
+ if (re && re.exec(navigator.userAgent) != null) {
+ rv = parseFloat(RegExp.$1);
+ }
+
+ if (rv === -1) { return false; }
+ if (!version) { return true; }
+ if (!equation) { return version === rv; }
+ if (equation === "<") { return version < rv; }
+ if (equation === ">") { return version > rv; }
+ if (equation === "<=") { return version <= rv; }
+ if (equation === ">=") { return version >= rv; }
+ }
+
+ return {
+ // Static variable needed, publicly accessible, to be able override it in unit tests
+ USER_AGENT: userAgent,
+
+ /**
+ * Exclude browsers that are not capable of displaying and handling
+ * contentEditable as desired:
+ * - iPhone, iPad (tested iOS 4.2.2) and Android (tested 2.2) refuse to make contentEditables focusable
+ * - IE < 8 create invalid markup and crash randomly from time to time
+ *
+ * @return {Boolean}
+ */
+ supported: function() {
+ var userAgent = this.USER_AGENT.toLowerCase(),
+ // Essential for making html elements editable
+ hasContentEditableSupport = "contentEditable" in testElement,
+ // Following methods are needed in order to interact with the contentEditable area
+ hasEditingApiSupport = document.execCommand && document.queryCommandSupported && document.queryCommandState,
+ // document selector apis are only supported by IE 8+, Safari 4+, Chrome and Firefox 3.5+
+ hasQuerySelectorSupport = document.querySelector && document.querySelectorAll,
+ // contentEditable is unusable in mobile browsers (tested iOS 4.2.2, Android 2.2, Opera Mobile, WebOS 3.05)
+ isIncompatibleMobileBrowser = (this.isIos() && iosVersion(userAgent) < 5) || (this.isAndroid() && androidVersion(userAgent) < 4) || userAgent.indexOf("opera mobi") !== -1 || userAgent.indexOf("hpwos/") !== -1;
+ return hasContentEditableSupport
+ && hasEditingApiSupport
+ && hasQuerySelectorSupport
+ && !isIncompatibleMobileBrowser;
+ },
+
+ isTouchDevice: function() {
+ return this.supportsEvent("touchmove");
+ },
+
+ isIos: function() {
+ return (/ipad|iphone|ipod/i).test(this.USER_AGENT);
+ },
+
+ isAndroid: function() {
+ return this.USER_AGENT.indexOf("Android") !== -1;
+ },
+
+ /**
+ * Whether the browser supports sandboxed iframes
+ * Currently only IE 6+ offers such feature <iframe security="restricted">
+ *
+ * http://msdn.microsoft.com/en-us/library/ms534622(v=vs.85).aspx
+ * http://blogs.msdn.com/b/ie/archive/2008/01/18/using-frames-more-securely.aspx
+ *
+ * HTML5 sandboxed iframes are still buggy and their DOM is not reachable from the outside (except when using postMessage)
+ */
+ supportsSandboxedIframes: function() {
+ return isIE();
+ },
+
+ /**
+ * IE6+7 throw a mixed content warning when the src of an iframe
+ * is empty/unset or about:blank
+ * window.querySelector is implemented as of IE8
+ */
+ throwsMixedContentWarningWhenIframeSrcIsEmpty: function() {
+ return !("querySelector" in document);
+ },
+
+ /**
+ * Whether the caret is correctly displayed in contentEditable elements
+ * Firefox sometimes shows a huge caret in the beginning after focusing
+ */
+ displaysCaretInEmptyContentEditableCorrectly: function() {
+ return isIE();
+ },
+
+ /**
+ * Opera and IE are the only browsers who offer the css value
+ * in the original unit, thx to the currentStyle object
+ * All other browsers provide the computed style in px via window.getComputedStyle
+ */
+ hasCurrentStyleProperty: function() {
+ return "currentStyle" in testElement;
+ },
+
+ /**
+ * Whether the browser inserts a <br> when pressing enter in a contentEditable element
+ */
+ insertsLineBreaksOnReturn: function() {
+ return isGecko;
+ },
+
+ supportsPlaceholderAttributeOn: function(element) {
+ return "placeholder" in element;
+ },
+
+ supportsEvent: function(eventName) {
+ return "on" + eventName in testElement || (function() {
+ testElement.setAttribute("on" + eventName, "return;");
+ return typeof(testElement["on" + eventName]) === "function";
+ })();
+ },
+
+ /**
+ * Opera doesn't correctly fire focus/blur events when clicking in- and outside of iframe
+ */
+ supportsEventsInIframeCorrectly: function() {
+ return !isOpera;
+ },
+
+ /**
+ * Everything below IE9 doesn't know how to treat HTML5 tags
+ *
+ * @param {Object} context The document object on which to check HTML5 support
+ *
+ * @example
+ * wysihtml5.browser.supportsHTML5Tags(document);
+ */
+ supportsHTML5Tags: function(context) {
+ var element = context.createElement("div"),
+ html5 = "<article>foo</article>";
+ element.innerHTML = html5;
+ return element.innerHTML.toLowerCase() === html5;
+ },
+
+ /**
+ * Checks whether a document supports a certain queryCommand
+ * In particular, Opera needs a reference to a document that has a contentEditable in it's dom tree
+ * in oder to report correct results
+ *
+ * @param {Object} doc Document object on which to check for a query command
+ * @param {String} command The query command to check for
+ * @return {Boolean}
+ *
+ * @example
+ * wysihtml5.browser.supportsCommand(document, "bold");
+ */
+ supportsCommand: (function() {
+ // Following commands are supported but contain bugs in some browsers
+ var buggyCommands = {
+ // formatBlock fails with some tags (eg. <blockquote>)
+ "formatBlock": isIE(10, "<="),
+ // When inserting unordered or ordered lists in Firefox, Chrome or Safari, the current selection or line gets
+ // converted into a list (<ul><li>...</li></ul>, <ol><li>...</li></ol>)
+ // IE and Opera act a bit different here as they convert the entire content of the current block element into a list
+ "insertUnorderedList": isIE(),
+ "insertOrderedList": isIE()
+ };
+
+ // Firefox throws errors for queryCommandSupported, so we have to build up our own object of supported commands
+ var supported = {
+ "insertHTML": isGecko
+ };
+
+ return function(doc, command) {
+ var isBuggy = buggyCommands[command];
+ if (!isBuggy) {
+ // Firefox throws errors when invoking queryCommandSupported or queryCommandEnabled
+ try {
+ return doc.queryCommandSupported(command);
+ } catch(e1) {}
+
+ try {
+ return doc.queryCommandEnabled(command);
+ } catch(e2) {
+ return !!supported[command];
+ }
+ }
+ return false;
+ };
+ })(),
+
+ /**
+ * IE: URLs starting with:
+ * www., http://, https://, ftp://, gopher://, mailto:, new:, snews:, telnet:, wasis:, file://,
+ * nntp://, newsrc:, ldap://, ldaps://, outlook:, mic:// and url:
+ * will automatically be auto-linked when either the user inserts them via copy&paste or presses the
+ * space bar when the caret is directly after such an url.
+ * This behavior cannot easily be avoided in IE < 9 since the logic is hardcoded in the mshtml.dll
+ * (related blog post on msdn
+ * http://blogs.msdn.com/b/ieinternals/archive/2009/09/17/prevent-automatic-hyperlinking-in-contenteditable-html.aspx).
+ */
+ doesAutoLinkingInContentEditable: function() {
+ return isIE();
+ },
+
+ /**
+ * As stated above, IE auto links urls typed into contentEditable elements
+ * Since IE9 it's possible to prevent this behavior
+ */
+ canDisableAutoLinking: function() {
+ return this.supportsCommand(document, "AutoUrlDetect");
+ },
+
+ /**
+ * IE leaves an empty paragraph in the contentEditable element after clearing it
+ * Chrome/Safari sometimes an empty <div>
+ */
+ clearsContentEditableCorrectly: function() {
+ return isGecko || isOpera || isWebKit;
+ },
+
+ /**
+ * IE gives wrong results for getAttribute
+ */
+ supportsGetAttributeCorrectly: function() {
+ var td = document.createElement("td");
+ return td.getAttribute("rowspan") != "1";
+ },
+
+ /**
+ * When clicking on images in IE, Opera and Firefox, they are selected, which makes it easy to interact with them.
+ * Chrome and Safari both don't support this
+ */
+ canSelectImagesInContentEditable: function() {
+ return isGecko || isIE() || isOpera;
+ },
+
+ /**
+ * All browsers except Safari and Chrome automatically scroll the range/caret position into view
+ */
+ autoScrollsToCaret: function() {
+ return !isWebKit;
+ },
+
+ /**
+ * Check whether the browser automatically closes tags that don't need to be opened
+ */
+ autoClosesUnclosedTags: function() {
+ var clonedTestElement = testElement.cloneNode(false),
+ returnValue,
+ innerHTML;
+
+ clonedTestElement.innerHTML = "<p><div></div>";
+ innerHTML = clonedTestElement.innerHTML.toLowerCase();
+ returnValue = innerHTML === "<p></p><div></div>" || innerHTML === "<p><div></div></p>";
+
+ // Cache result by overwriting current function
+ this.autoClosesUnclosedTags = function() { return returnValue; };
+
+ return returnValue;
+ },
+
+ /**
+ * Whether the browser supports the native document.getElementsByClassName which returns live NodeLists
+ */
+ supportsNativeGetElementsByClassName: function() {
+ return String(document.getElementsByClassName).indexOf("[native code]") !== -1;
+ },
+
+ /**
+ * As of now (19.04.2011) only supported by Firefox 4 and Chrome
+ * See https://developer.mozilla.org/en/DOM/Selection/modify
+ */
+ supportsSelectionModify: function() {
+ return "getSelection" in window && "modify" in window.getSelection();
+ },
+
+ /**
+ * Opera needs a white space after a <br> in order to position the caret correctly
+ */
+ needsSpaceAfterLineBreak: function() {
+ return isOpera;
+ },
+
+ /**
+ * Whether the browser supports the speech api on the given element
+ * See http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/
+ *
+ * @example
+ * var input = document.createElement("input");
+ * if (wysihtml5.browser.supportsSpeechApiOn(input)) {
+ * // ...
+ * }
+ */
+ supportsSpeechApiOn: function(input) {
+ var chromeVersion = userAgent.match(/Chrome\/(\d+)/) || [undefined, 0];
+ return chromeVersion[1] >= 11 && ("onwebkitspeechchange" in input || "speech" in input);
+ },
+
+ /**
+ * IE9 crashes when setting a getter via Object.defineProperty on XMLHttpRequest or XDomainRequest
+ * See https://connect.microsoft.com/ie/feedback/details/650112
+ * or try the POC http://tifftiff.de/ie9_crash/
+ */
+ crashesWhenDefineProperty: function(property) {
+ return isIE(9) && (property === "XMLHttpRequest" || property === "XDomainRequest");
+ },
+
+ /**
+ * IE is the only browser who fires the "focus" event not immediately when .focus() is called on an element
+ */
+ doesAsyncFocus: function() {
+ return isIE();
+ },
+
+ /**
+ * In IE it's impssible for the user and for the selection library to set the caret after an <img> when it's the lastChild in the document
+ */
+ hasProblemsSettingCaretAfterImg: function() {
+ return isIE();
+ },
+
+ hasUndoInContextMenu: function() {
+ return isGecko || isChrome || isOpera;
+ },
+
+ /**
+ * Opera sometimes doesn't insert the node at the right position when range.insertNode(someNode)
+ * is used (regardless if rangy or native)
+ * This especially happens when the caret is positioned right after a <br> because then
+ * insertNode() will insert the node right before the <br>
+ */
+ hasInsertNodeIssue: function() {
+ return isOpera;
+ },
+
+ /**
+ * IE 8+9 don't fire the focus event of the <body> when the iframe gets focused (even though the caret gets set into the <body>)
+ */
+ hasIframeFocusIssue: function() {
+ return isIE();
+ },
+
+ /**
+ * Chrome + Safari create invalid nested markup after paste
+ *
+ * <p>
+ * foo
+ * <p>bar</p> <!-- BOO! -->
+ * </p>
+ */
+ createsNestedInvalidMarkupAfterPaste: function() {
+ return isWebKit;
+ },
+
+ supportsMutationEvents: function() {
+ return ("MutationEvent" in window);
+ },
+
+ /**
+ IE (at least up to 11) does not support clipboardData on event.
+ It is on window but cannot return text/html
+ Should actually check for clipboardData on paste event, but cannot in firefox
+ */
+ supportsModenPaste: function () {
+ return !("clipboardData" in window);
+ }
+ };
+})();
+;wysihtml5.lang.array = function(arr) {
+ return {
+ /**
+ * Check whether a given object exists in an array
+ *
+ * @example
+ * wysihtml5.lang.array([1, 2]).contains(1);
+ * // => true
+ *
+ * Can be used to match array with array. If intersection is found true is returned
+ */
+ contains: function(needle) {
+ if (Array.isArray(needle)) {
+ for (var i = needle.length; i--;) {
+ if (wysihtml5.lang.array(arr).indexOf(needle[i]) !== -1) {
+ return true;
+ }
+ }
+ return false;
+ } else {
+ return wysihtml5.lang.array(arr).indexOf(needle) !== -1;
+ }
+ },
+
+ /**
+ * Check whether a given object exists in an array and return index
+ * If no elelemt found returns -1
+ *
+ * @example
+ * wysihtml5.lang.array([1, 2]).indexOf(2);
+ * // => 1
+ */
+ indexOf: function(needle) {
+ if (arr.indexOf) {
+ return arr.indexOf(needle);
+ } else {
+ for (var i=0, length=arr.length; i<length; i++) {
+ if (arr[i] === needle) { return i; }
+ }
+ return -1;
+ }
+ },
+
+ /**
+ * Substract one array from another
+ *
+ * @example
+ * wysihtml5.lang.array([1, 2, 3, 4]).without([3, 4]);
+ * // => [1, 2]
+ */
+ without: function(arrayToSubstract) {
+ arrayToSubstract = wysihtml5.lang.array(arrayToSubstract);
+ var newArr = [],
+ i = 0,
+ length = arr.length;
+ for (; i<length; i++) {
+ if (!arrayToSubstract.contains(arr[i])) {
+ newArr.push(arr[i]);
+ }
+ }
+ return newArr;
+ },
+
+ /**
+ * Return a clean native array
+ *
+ * Following will convert a Live NodeList to a proper Array
+ * @example
+ * var childNodes = wysihtml5.lang.array(document.body.childNodes).get();
+ */
+ get: function() {
+ var i = 0,
+ length = arr.length,
+ newArray = [];
+ for (; i<length; i++) {
+ newArray.push(arr[i]);
+ }
+ return newArray;
+ },
+
+ /**
+ * Creates a new array with the results of calling a provided function on every element in this array.
+ * optionally this can be provided as second argument
+ *
+ * @example
+ * var childNodes = wysihtml5.lang.array([1,2,3,4]).map(function (value, index, array) {
+ return value * 2;
+ * });
+ * // => [2,4,6,8]
+ */
+ map: function(callback, thisArg) {
+ if (Array.prototype.map) {
+ return arr.map(callback, thisArg);
+ } else {
+ var len = arr.length >>> 0,
+ A = new Array(len),
+ i = 0;
+ for (; i < len; i++) {
+ A[i] = callback.call(thisArg, arr[i], i, arr);
+ }
+ return A;
+ }
+ },
+
+ /* ReturnS new array without duplicate entries
+ *
+ * @example
+ * var uniq = wysihtml5.lang.array([1,2,3,2,1,4]).unique();
+ * // => [1,2,3,4]
+ */
+ unique: function() {
+ var vals = [],
+ max = arr.length,
+ idx = 0;
+
+ while (idx < max) {
+ if (!wysihtml5.lang.array(vals).contains(arr[idx])) {
+ vals.push(arr[idx]);
+ }
+ idx++;
+ }
+ return vals;
+ }
+
+ };
+};
+;wysihtml5.lang.Dispatcher = Base.extend(
+ /** @scope wysihtml5.lang.Dialog.prototype */ {
+ on: function(eventName, handler) {
+ this.events = this.events || {};
+ this.events[eventName] = this.events[eventName] || [];
+ this.events[eventName].push(handler);
+ return this;
+ },
+
+ off: function(eventName, handler) {
+ this.events = this.events || {};
+ var i = 0,
+ handlers,
+ newHandlers;
+ if (eventName) {
+ handlers = this.events[eventName] || [],
+ newHandlers = [];
+ for (; i<handlers.length; i++) {
+ if (handlers[i] !== handler && handler) {
+ newHandlers.push(handlers[i]);
+ }
+ }
+ this.events[eventName] = newHandlers;
+ } else {
+ // Clean up all events
+ this.events = {};
+ }
+ return this;
+ },
+
+ fire: function(eventName, payload) {
+ this.events = this.events || {};
+ var handlers = this.events[eventName] || [],
+ i = 0;
+ for (; i<handlers.length; i++) {
+ handlers[i].call(this, payload);
+ }
+ return this;
+ },
+
+ // deprecated, use .on()
+ observe: function() {
+ return this.on.apply(this, arguments);
+ },
+
+ // deprecated, use .off()
+ stopObserving: function() {
+ return this.off.apply(this, arguments);
+ }
+});
+;wysihtml5.lang.object = function(obj) {
+ return {
+ /**
+ * @example
+ * wysihtml5.lang.object({ foo: 1, bar: 1 }).merge({ bar: 2, baz: 3 }).get();
+ * // => { foo: 1, bar: 2, baz: 3 }
+ */
+ merge: function(otherObj) {
+ for (var i in otherObj) {
+ obj[i] = otherObj[i];
+ }
+ return this;
+ },
+
+ get: function() {
+ return obj;
+ },
+
+ /**
+ * @example
+ * wysihtml5.lang.object({ foo: 1 }).clone();
+ * // => { foo: 1 }
+ *
+ * v0.4.14 adds options for deep clone : wysihtml5.lang.object({ foo: 1 }).clone(true);
+ */
+ clone: function(deep) {
+ var newObj = {},
+ i;
+
+ if (obj === null || !wysihtml5.lang.object(obj).isPlainObject()) {
+ return obj;
+ }
+
+ for (i in obj) {
+ if(obj.hasOwnProperty(i)) {
+ if (deep) {
+ newObj[i] = wysihtml5.lang.object(obj[i]).clone(deep);
+ } else {
+ newObj[i] = obj[i];
+ }
+ }
+ }
+ return newObj;
+ },
+
+ /**
+ * @example
+ * wysihtml5.lang.object([]).isArray();
+ * // => true
+ */
+ isArray: function() {
+ return Object.prototype.toString.call(obj) === "[object Array]";
+ },
+
+ /**
+ * @example
+ * wysihtml5.lang.object(function() {}).isFunction();
+ * // => true
+ */
+ isFunction: function() {
+ return Object.prototype.toString.call(obj) === '[object Function]';
+ },
+
+ isPlainObject: function () {
+ return Object.prototype.toString.call(obj) === '[object Object]';
+ }
+ };
+};
+;(function() {
+ var WHITE_SPACE_START = /^\s+/,
+ WHITE_SPACE_END = /\s+$/,
+ ENTITY_REG_EXP = /[&<>\t"]/g,
+ ENTITY_MAP = {
+ '&': '&',
+ '<': '<',
+ '>': '>',
+ '"': """,
+ '\t':" "
+ };
+ wysihtml5.lang.string = function(str) {
+ str = String(str);
+ return {
+ /**
+ * @example
+ * wysihtml5.lang.string(" foo ").trim();
+ * // => "foo"
+ */
+ trim: function() {
+ return str.replace(WHITE_SPACE_START, "").replace(WHITE_SPACE_END, "");
+ },
+
+ /**
+ * @example
+ * wysihtml5.lang.string("Hello #{name}").interpolate({ name: "Christopher" });
+ * // => "Hello Christopher"
+ */
+ interpolate: function(vars) {
+ for (var i in vars) {
+ str = this.replace("#{" + i + "}").by(vars[i]);
+ }
+ return str;
+ },
+
+ /**
+ * @example
+ * wysihtml5.lang.string("Hello Tom").replace("Tom").with("Hans");
+ * // => "Hello Hans"
+ */
+ replace: function(search) {
+ return {
+ by: function(replace) {
+ return str.split(search).join(replace);
+ }
+ };
+ },
+
+ /**
+ * @example
+ * wysihtml5.lang.string("hello<br>").escapeHTML();
+ * // => "hello<br>"
+ */
+ escapeHTML: function(linebreaks, convertSpaces) {
+ var html = str.replace(ENTITY_REG_EXP, function(c) { return ENTITY_MAP[c]; });
+ if (linebreaks) {
+ html = html.replace(/(?:\r\n|\r|\n)/g, '<br />');
+ }
+ if (convertSpaces) {
+ html = html.replace(/ /gi, " ");
+ }
+ return html;
+ }
+ };
+ };
+})();
+;/**
+ * Find urls in descendant text nodes of an element and auto-links them
+ * Inspired by http://james.padolsey.com/javascript/find-and-replace-text-with-javascript/
+ *
+ * @param {Element} element Container element in which to search for urls
+ *
+ * @example
+ * <div id="text-container">Please click here: www.google.com</div>
+ * <script>wysihtml5.dom.autoLink(document.getElementById("text-container"));</script>
+ */
+(function(wysihtml5) {
+ var /**
+ * Don't auto-link urls that are contained in the following elements:
+ */
+ IGNORE_URLS_IN = wysihtml5.lang.array(["CODE", "PRE", "A", "SCRIPT", "HEAD", "TITLE", "STYLE"]),
+ /**
+ * revision 1:
+ * /(\S+\.{1}[^\s\,\.\!]+)/g
+ *
+ * revision 2:
+ * /(\b(((https?|ftp):\/\/)|(www\.))[-A-Z0-9+&@#\/%?=~_|!:,.;\[\]]*[-A-Z0-9+&@#\/%=~_|])/gim
+ *
+ * put this in the beginning if you don't wan't to match within a word
+ * (^|[\>\(\{\[\s\>])
+ */
+ URL_REG_EXP = /((https?:\/\/|www\.)[^\s<]{3,})/gi,
+ TRAILING_CHAR_REG_EXP = /([^\w\/\-](,?))$/i,
+ MAX_DISPLAY_LENGTH = 100,
+ BRACKETS = { ")": "(", "]": "[", "}": "{" };
+
+ function autoLink(element, ignoreInClasses) {
+ if (_hasParentThatShouldBeIgnored(element, ignoreInClasses)) {
+ return element;
+ }
+
+ if (element === element.ownerDocument.documentElement) {
+ element = element.ownerDocument.body;
+ }
+
+ return _parseNode(element, ignoreInClasses);
+ }
+
+ /**
+ * This is basically a rebuild of
+ * the rails auto_link_urls text helper
+ */
+ function _convertUrlsToLinks(str) {
+ return str.replace(URL_REG_EXP, function(match, url) {
+ var punctuation = (url.match(TRAILING_CHAR_REG_EXP) || [])[1] || "",
+ opening = BRACKETS[punctuation];
+ url = url.replace(TRAILING_CHAR_REG_EXP, "");
+
+ if (url.split(opening).length > url.split(punctuation).length) {
+ url = url + punctuation;
+ punctuation = "";
+ }
+ var realUrl = url,
+ displayUrl = url;
+ if (url.length > MAX_DISPLAY_LENGTH) {
+ displayUrl = displayUrl.substr(0, MAX_DISPLAY_LENGTH) + "...";
+ }
+ // Add http prefix if necessary
+ if (realUrl.substr(0, 4) === "www.") {
+ realUrl = "http://" + realUrl;
+ }
+
+ return '<a href="' + realUrl + '">' + displayUrl + '</a>' + punctuation;
+ });
+ }
+
+ /**
+ * Creates or (if already cached) returns a temp element
+ * for the given document object
+ */
+ function _getTempElement(context) {
+ var tempElement = context._wysihtml5_tempElement;
+ if (!tempElement) {
+ tempElement = context._wysihtml5_tempElement = context.createElement("div");
+ }
+ return tempElement;
+ }
+
+ /**
+ * Replaces the original text nodes with the newly auto-linked dom tree
+ */
+ function _wrapMatchesInNode(textNode) {
+ var parentNode = textNode.parentNode,
+ nodeValue = wysihtml5.lang.string(textNode.data).escapeHTML(),
+ tempElement = _getTempElement(parentNode.ownerDocument);
+
+ // We need to insert an empty/temporary <span /> to fix IE quirks
+ // Elsewise IE would strip white space in the beginning
+ tempElement.innerHTML = "<span></span>" + _convertUrlsToLinks(nodeValue);
+ tempElement.removeChild(tempElement.firstChild);
+
+ while (tempElement.firstChild) {
+ // inserts tempElement.firstChild before textNode
+ parentNode.insertBefore(tempElement.firstChild, textNode);
+ }
+ parentNode.removeChild(textNode);
+ }
+
+ function _hasParentThatShouldBeIgnored(node, ignoreInClasses) {
+ var nodeName;
+ while (node.parentNode) {
+ node = node.parentNode;
+ nodeName = node.nodeName;
+ if (node.className && wysihtml5.lang.array(node.className.split(' ')).contains(ignoreInClasses)) {
+ return true;
+ }
+ if (IGNORE_URLS_IN.contains(nodeName)) {
+ return true;
+ } else if (nodeName === "body") {
+ return false;
+ }
+ }
+ return false;
+ }
+
+ function _parseNode(element, ignoreInClasses) {
+ if (IGNORE_URLS_IN.contains(element.nodeName)) {
+ return;
+ }
+
+ if (element.className && wysihtml5.lang.array(element.className.split(' ')).contains(ignoreInClasses)) {
+ return;
+ }
+
+ if (element.nodeType === wysihtml5.TEXT_NODE && element.data.match(URL_REG_EXP)) {
+ _wrapMatchesInNode(element);
+ return;
+ }
+
+ var childNodes = wysihtml5.lang.array(element.childNodes).get(),
+ childNodesLength = childNodes.length,
+ i = 0;
+
+ for (; i<childNodesLength; i++) {
+ _parseNode(childNodes[i], ignoreInClasses);
+ }
+
+ return element;
+ }
+
+ wysihtml5.dom.autoLink = autoLink;
+
+ // Reveal url reg exp to the outside
+ wysihtml5.dom.autoLink.URL_REG_EXP = URL_REG_EXP;
+})(wysihtml5);
+;(function(wysihtml5) {
+ var api = wysihtml5.dom;
+
+ api.addClass = function(element, className) {
+ var classList = element.classList;
+ if (classList) {
+ return classList.add(className);
+ }
+ if (api.hasClass(element, className)) {
+ return;
+ }
+ element.className += " " + className;
+ };
+
+ api.removeClass = function(element, className) {
+ var classList = element.classList;
+ if (classList) {
+ return classList.remove(className);
+ }
+
+ element.className = element.className.replace(new RegExp("(^|\\s+)" + className + "(\\s+|$)"), " ");
+ };
+
+ api.hasClass = function(element, className) {
+ var classList = element.classList;
+ if (classList) {
+ return classList.contains(className);
+ }
+
+ var elementClassName = element.className;
+ return (elementClassName.length > 0 && (elementClassName == className || new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName)));
+ };
+})(wysihtml5);
+;wysihtml5.dom.contains = (function() {
+ var documentElement = document.documentElement;
+ if (documentElement.contains) {
+ return function(container, element) {
+ if (element.nodeType !== wysihtml5.ELEMENT_NODE) {
+ element = element.parentNode;
+ }
+ return container !== element && container.contains(element);
+ };
+ } else if (documentElement.compareDocumentPosition) {
+ return function(container, element) {
+ // https://developer.mozilla.org/en/DOM/Node.compareDocumentPosition
+ return !!(container.compareDocumentPosition(element) & 16);
+ };
+ }
+})();
+;/**
+ * Converts an HTML fragment/element into a unordered/ordered list
+ *
+ * @param {Element} element The element which should be turned into a list
+ * @param {String} listType The list type in which to convert the tree (either "ul" or "ol")
+ * @return {Element} The created list
+ *
+ * @example
+ * <!-- Assume the following dom: -->
+ * <span id="pseudo-list">
+ * eminem<br>
+ * dr. dre
+ * <div>50 Cent</div>
+ * </span>
+ *
+ * <script>
+ * wysihtml5.dom.convertToList(document.getElementById("pseudo-list"), "ul");
+ * </script>
+ *
+ * <!-- Will result in: -->
+ * <ul>
+ * <li>eminem</li>
+ * <li>dr. dre</li>
+ * <li>50 Cent</li>
+ * </ul>
+ */
+wysihtml5.dom.convertToList = (function() {
+ function _createListItem(doc, list) {
+ var listItem = doc.createElement("li");
+ list.appendChild(listItem);
+ return listItem;
+ }
+
+ function _createList(doc, type) {
+ return doc.createElement(type);
+ }
+
+ function convertToList(element, listType, uneditableClass) {
+ if (element.nodeName === "UL" || element.nodeName === "OL" || element.nodeName === "MENU") {
+ // Already a list
+ return element;
+ }
+
+ var doc = element.ownerDocument,
+ list = _createList(doc, listType),
+ lineBreaks = element.querySelectorAll("br"),
+ lineBreaksLength = lineBreaks.length,
+ childNodes,
+ childNodesLength,
+ childNode,
+ lineBreak,
+ parentNode,
+ isBlockElement,
+ isLineBreak,
+ currentListItem,
+ i;
+
+ // First find <br> at the end of inline elements and move them behind them
+ for (i=0; i<lineBreaksLength; i++) {
+ lineBreak = lineBreaks[i];
+ while ((parentNode = lineBreak.parentNode) && parentNode !== element && parentNode.lastChild === lineBreak) {
+ if (wysihtml5.dom.getStyle("display").from(parentNode) === "block") {
+ parentNode.removeChild(lineBreak);
+ break;
+ }
+ wysihtml5.dom.insert(lineBreak).after(lineBreak.parentNode);
+ }
+ }
+
+ childNodes = wysihtml5.lang.array(element.childNodes).get();
+ childNodesLength = childNodes.length;
+
+ for (i=0; i<childNodesLength; i++) {
+ currentListItem = currentListItem || _createListItem(doc, list);
+ childNode = childNodes[i];
+ isBlockElement = wysihtml5.dom.getStyle("display").from(childNode) === "block";
+ isLineBreak = childNode.nodeName === "BR";
+
+ // consider uneditable as an inline element
+ if (isBlockElement && (!uneditableClass || !wysihtml5.dom.hasClass(childNode, uneditableClass))) {
+ // Append blockElement to current <li> if empty, otherwise create a new one
+ currentListItem = currentListItem.firstChild ? _createListItem(doc, list) : currentListItem;
+ currentListItem.appendChild(childNode);
+ currentListItem = null;
+ continue;
+ }
+
+ if (isLineBreak) {
+ // Only create a new list item in the next iteration when the current one has already content
+ currentListItem = currentListItem.firstChild ? null : currentListItem;
+ continue;
+ }
+
+ currentListItem.appendChild(childNode);
+ }
+
+ if (childNodes.length === 0) {
+ _createListItem(doc, list);
+ }
+
+ element.parentNode.replaceChild(list, element);
+ return list;
+ }
+
+ return convertToList;
+})();
+;/**
+ * Copy a set of attributes from one element to another
+ *
+ * @param {Array} attributesToCopy List of attributes which should be copied
+ * @return {Object} Returns an object which offers the "from" method which can be invoked with the element where to
+ * copy the attributes from., this again returns an object which provides a method named "to" which can be invoked
+ * with the element where to copy the attributes to (see example)
+ *
+ * @example
+ * var textarea = document.querySelector("textarea"),
+ * div = document.querySelector("div[contenteditable=true]"),
+ * anotherDiv = document.querySelector("div.preview");
+ * wysihtml5.dom.copyAttributes(["spellcheck", "value", "placeholder"]).from(textarea).to(div).andTo(anotherDiv);
+ *
+ */
+wysihtml5.dom.copyAttributes = function(attributesToCopy) {
+ return {
+ from: function(elementToCopyFrom) {
+ return {
+ to: function(elementToCopyTo) {
+ var attribute,
+ i = 0,
+ length = attributesToCopy.length;
+ for (; i<length; i++) {
+ attribute = attributesToCopy[i];
+ if (typeof(elementToCopyFrom[attribute]) !== "undefined" && elementToCopyFrom[attribute] !== "") {
+ elementToCopyTo[attribute] = elementToCopyFrom[attribute];
+ }
+ }
+ return { andTo: arguments.callee };
+ }
+ };
+ }
+ };
+};
+;/**
+ * Copy a set of styles from one element to another
+ * Please note that this only works properly across browsers when the element from which to copy the styles
+ * is in the dom
+ *
+ * Interesting article on how to copy styles
+ *
+ * @param {Array} stylesToCopy List of styles which should be copied
+ * @return {Object} Returns an object which offers the "from" method which can be invoked with the element where to
+ * copy the styles from., this again returns an object which provides a method named "to" which can be invoked
+ * with the element where to copy the styles to (see example)
+ *
+ * @example
+ * var textarea = document.querySelector("textarea"),
+ * div = document.querySelector("div[contenteditable=true]"),
+ * anotherDiv = document.querySelector("div.preview");
+ * wysihtml5.dom.copyStyles(["overflow-y", "width", "height"]).from(textarea).to(div).andTo(anotherDiv);
+ *
+ */
+(function(dom) {
+
+ /**
+ * Mozilla, WebKit and Opera recalculate the computed width when box-sizing: boder-box; is set
+ * So if an element has "width: 200px; -moz-box-sizing: border-box; border: 1px;" then
+ * its computed css width will be 198px
+ *
+ * See https://bugzilla.mozilla.org/show_bug.cgi?id=520992
+ */
+ var BOX_SIZING_PROPERTIES = ["-webkit-box-sizing", "-moz-box-sizing", "-ms-box-sizing", "box-sizing"];
+
+ var shouldIgnoreBoxSizingBorderBox = function(element) {
+ if (hasBoxSizingBorderBox(element)) {
+ return parseInt(dom.getStyle("width").from(element), 10) < element.offsetWidth;
+ }
+ return false;
+ };
+
+ var hasBoxSizingBorderBox = function(element) {
+ var i = 0,
+ length = BOX_SIZING_PROPERTIES.length;
+ for (; i<length; i++) {
+ if (dom.getStyle(BOX_SIZING_PROPERTIES[i]).from(element) === "border-box") {
+ return BOX_SIZING_PROPERTIES[i];
+ }
+ }
+ };
+
+ dom.copyStyles = function(stylesToCopy) {
+ return {
+ from: function(element) {
+ if (shouldIgnoreBoxSizingBorderBox(element)) {
+ stylesToCopy = wysihtml5.lang.array(stylesToCopy).without(BOX_SIZING_PROPERTIES);
+ }
+
+ var cssText = "",
+ length = stylesToCopy.length,
+ i = 0,
+ property;
+ for (; i<length; i++) {
+ property = stylesToCopy[i];
+ cssText += property + ":" + dom.getStyle(property).from(element) + ";";
+ }
+
+ return {
+ to: function(element) {
+ dom.setStyles(cssText).on(element);
+ return { andTo: arguments.callee };
+ }
+ };
+ }
+ };
+ };
+})(wysihtml5.dom);
+;/**
+ * Event Delegation
+ *
+ * @example
+ * wysihtml5.dom.delegate(document.body, "a", "click", function() {
+ * // foo
+ * });
+ */
+(function(wysihtml5) {
+
+ wysihtml5.dom.delegate = function(container, selector, eventName, handler) {
+ return wysihtml5.dom.observe(container, eventName, function(event) {
+ var target = event.target,
+ match = wysihtml5.lang.array(container.querySelectorAll(selector));
+
+ while (target && target !== container) {
+ if (match.contains(target)) {
+ handler.call(target, event);
+ break;
+ }
+ target = target.parentNode;
+ }
+ });
+ };
+
+})(wysihtml5);
+;// TODO: Refactor dom tree traversing here
+(function(wysihtml5) {
+ wysihtml5.dom.domNode = function(node) {
+ var defaultNodeTypes = [wysihtml5.ELEMENT_NODE, wysihtml5.TEXT_NODE];
+
+ var _isBlankText = function(node) {
+ return node.nodeType === wysihtml5.TEXT_NODE && (/^\s*$/g).test(node.data);
+ };
+
+ return {
+
+ // var node = wysihtml5.dom.domNode(element).prev({nodeTypes: [1,3], ignoreBlankTexts: true});
+ prev: function(options) {
+ var prevNode = node.previousSibling,
+ types = (options && options.nodeTypes) ? options.nodeTypes : defaultNodeTypes;
+
+ if (!prevNode) {
+ return null;
+ }
+
+ if (
+ (!wysihtml5.lang.array(types).contains(prevNode.nodeType)) || // nodeTypes check.
+ (options && options.ignoreBlankTexts && _isBlankText(prevNode)) // Blank text nodes bypassed if set
+ ) {
+ return wysihtml5.dom.domNode(prevNode).prev(options);
+ }
+
+ return prevNode;
+ },
+
+ // var node = wysihtml5.dom.domNode(element).next({nodeTypes: [1,3], ignoreBlankTexts: true});
+ next: function(options) {
+ var nextNode = node.nextSibling,
+ types = (options && options.nodeTypes) ? options.nodeTypes : defaultNodeTypes;
+
+ if (!nextNode) {
+ return null;
+ }
+
+ if (
+ (!wysihtml5.lang.array(types).contains(nextNode.nodeType)) || // nodeTypes check.
+ (options && options.ignoreBlankTexts && _isBlankText(nextNode)) // blank text nodes bypassed if set
+ ) {
+ return wysihtml5.dom.domNode(nextNode).next(options);
+ }
+
+ return nextNode;
+ },
+
+ // Traverses a node for last children and their chidren (including itself), and finds the last node that has no children.
+ // Array of classes for forced last-leaves (ex: uneditable-container) can be defined (options = {leafClasses: [...]})
+ // Useful for finding the actually visible element before cursor
+ lastLeafNode: function(options) {
+ var lastChild;
+
+ // Returns non-element nodes
+ if (node.nodeType !== 1) {
+ return node;
+ }
+
+ // Returns if element is leaf
+ lastChild = node.lastChild;
+ if (!lastChild) {
+ return node;
+ }
+
+ // Returns if element is of of options.leafClasses leaf
+ if (options && options.leafClasses) {
+ for (var i = options.leafClasses.length; i--;) {
+ if (wysihtml5.dom.hasClass(node, options.leafClasses[i])) {
+ return node;
+ }
+ }
+ }
+
+ return wysihtml5.dom.domNode(lastChild).lastLeafNode(options);
+ }
+
+ };
+ };
+})(wysihtml5);;/**
+ * Returns the given html wrapped in a div element
+ *
+ * Fixing IE's inability to treat unknown elements (HTML5 section, article, ...) correctly
+ * when inserted via innerHTML
+ *
+ * @param {String} html The html which should be wrapped in a dom element
+ * @param {Obejct} [context] Document object of the context the html belongs to
+ *
+ * @example
+ * wysihtml5.dom.getAsDom("<article>foo</article>");
+ */
+wysihtml5.dom.getAsDom = (function() {
+
+ var _innerHTMLShiv = function(html, context) {
+ var tempElement = context.createElement("div");
+ tempElement.style.display = "none";
+ context.body.appendChild(tempElement);
+ // IE throws an exception when trying to insert <frameset></frameset> via innerHTML
+ try { tempElement.innerHTML = html; } catch(e) {}
+ context.body.removeChild(tempElement);
+ return tempElement;
+ };
+
+ /**
+ * Make sure IE supports HTML5 tags, which is accomplished by simply creating one instance of each element
+ */
+ var _ensureHTML5Compatibility = function(context) {
+ if (context._wysihtml5_supportsHTML5Tags) {
+ return;
+ }
+ for (var i=0, length=HTML5_ELEMENTS.length; i<length; i++) {
+ context.createElement(HTML5_ELEMENTS[i]);
+ }
+ context._wysihtml5_supportsHTML5Tags = true;
+ };
+
+
+ /**
+ * List of html5 tags
+ * taken from http://simon.html5.org/html5-elements
+ */
+ var HTML5_ELEMENTS = [
+ "abbr", "article", "aside", "audio", "bdi", "canvas", "command", "datalist", "details", "figcaption",
+ "figure", "footer", "header", "hgroup", "keygen", "mark", "meter", "nav", "output", "progress",
+ "rp", "rt", "ruby", "svg", "section", "source", "summary", "time", "track", "video", "wbr"
+ ];
+
+ return function(html, context) {
+ context = context || document;
+ var tempElement;
+ if (typeof(html) === "object" && html.nodeType) {
+ tempElement = context.createElement("div");
+ tempElement.appendChild(html);
+ } else if (wysihtml5.browser.supportsHTML5Tags(context)) {
+ tempElement = context.createElement("div");
+ tempElement.innerHTML = html;
+ } else {
+ _ensureHTML5Compatibility(context);
+ tempElement = _innerHTMLShiv(html, context);
+ }
+ return tempElement;
+ };
+})();
+;/**
+ * Walks the dom tree from the given node up until it finds a match
+ * Designed for optimal performance.
+ *
+ * @param {Element} node The from which to check the parent nodes
+ * @param {Object} matchingSet Object to match against (possible properties: nodeName, className, classRegExp)
+ * @param {Number} [levels] How many parents should the function check up from the current node (defaults to 50)
+ * @return {null|Element} Returns the first element that matched the desiredNodeName(s)
+ * @example
+ * var listElement = wysihtml5.dom.getParentElement(document.querySelector("li"), { nodeName: ["MENU", "UL", "OL"] });
+ * // ... or ...
+ * var unorderedListElement = wysihtml5.dom.getParentElement(document.querySelector("li"), { nodeName: "UL" });
+ * // ... or ...
+ * var coloredElement = wysihtml5.dom.getParentElement(myTextNode, { nodeName: "SPAN", className: "wysiwyg-color-red", classRegExp: /wysiwyg-color-[a-z]/g });
+ */
+wysihtml5.dom.getParentElement = (function() {
+
+ function _isSameNodeName(nodeName, desiredNodeNames) {
+ if (!desiredNodeNames || !desiredNodeNames.length) {
+ return true;
+ }
+
+ if (typeof(desiredNodeNames) === "string") {
+ return nodeName === desiredNodeNames;
+ } else {
+ return wysihtml5.lang.array(desiredNodeNames).contains(nodeName);
+ }
+ }
+
+ function _isElement(node) {
+ return node.nodeType === wysihtml5.ELEMENT_NODE;
+ }
+
+ function _hasClassName(element, className, classRegExp) {
+ var classNames = (element.className || "").match(classRegExp) || [];
+ if (!className) {
+ return !!classNames.length;
+ }
+ return classNames[classNames.length - 1] === className;
+ }
+
+ function _hasStyle(element, cssStyle, styleRegExp) {
+ var styles = (element.getAttribute('style') || "").match(styleRegExp) || [];
+ if (!cssStyle) {
+ return !!styles.length;
+ }
+ return styles[styles.length - 1] === cssStyle;
+ }
+
+ return function(node, matchingSet, levels, container) {
+ var findByStyle = (matchingSet.cssStyle || matchingSet.styleRegExp),
+ findByClass = (matchingSet.className || matchingSet.classRegExp);
+
+ levels = levels || 50; // Go max 50 nodes upwards from current node
+
+ // make the matching class regex from class name if omitted
+ if (findByClass && !matchingSet.classRegExp) {
+ matchingSet.classRegExp = new RegExp(matchingSet.className);
+ }
+
+ while (levels-- && node && node.nodeName !== "BODY" && (!container || node !== container)) {
+ if (_isElement(node) && (!matchingSet.nodeName || _isSameNodeName(node.nodeName, matchingSet.nodeName)) &&
+ (!findByStyle || _hasStyle(node, matchingSet.cssStyle, matchingSet.styleRegExp)) &&
+ (!findByClass || _hasClassName(node, matchingSet.className, matchingSet.classRegExp))
+ ) {
+ return node;
+ }
+ node = node.parentNode;
+ }
+ return null;
+ };
+})();
+;/**
+ * Get element's style for a specific css property
+ *
+ * @param {Element} element The element on which to retrieve the style
+ * @param {String} property The CSS property to retrieve ("float", "display", "text-align", ...)
+ *
+ * @example
+ * wysihtml5.dom.getStyle("display").from(document.body);
+ * // => "block"
+ */
+wysihtml5.dom.getStyle = (function() {
+ var stylePropertyMapping = {
+ "float": ("styleFloat" in document.createElement("div").style) ? "styleFloat" : "cssFloat"
+ },
+ REG_EXP_CAMELIZE = /\-[a-z]/g;
+
+ function camelize(str) {
+ return str.replace(REG_EXP_CAMELIZE, function(match) {
+ return match.charAt(1).toUpperCase();
+ });
+ }
+
+ return function(property) {
+ return {
+ from: function(element) {
+ if (element.nodeType !== wysihtml5.ELEMENT_NODE) {
+ return;
+ }
+
+ var doc = element.ownerDocument,
+ camelizedProperty = stylePropertyMapping[property] || camelize(property),
+ style = element.style,
+ currentStyle = element.currentStyle,
+ styleValue = style[camelizedProperty];
+ if (styleValue) {
+ return styleValue;
+ }
+
+ // currentStyle is no standard and only supported by Opera and IE but it has one important advantage over the standard-compliant
+ // window.getComputedStyle, since it returns css property values in their original unit:
+ // If you set an elements width to "50%", window.getComputedStyle will give you it's current width in px while currentStyle
+ // gives you the original "50%".
+ // Opera supports both, currentStyle and window.getComputedStyle, that's why checking for currentStyle should have higher prio
+ if (currentStyle) {
+ try {
+ return currentStyle[camelizedProperty];
+ } catch(e) {
+ //ie will occasionally fail for unknown reasons. swallowing exception
+ }
+ }
+
+ var win = doc.defaultView || doc.parentWindow,
+ needsOverflowReset = (property === "height" || property === "width") && element.nodeName === "TEXTAREA",
+ originalOverflow,
+ returnValue;
+
+ if (win.getComputedStyle) {
+ // Chrome and Safari both calculate a wrong width and height for textareas when they have scroll bars
+ // therfore we remove and restore the scrollbar and calculate the value in between
+ if (needsOverflowReset) {
+ originalOverflow = style.overflow;
+ style.overflow = "hidden";
+ }
+ returnValue = win.getComputedStyle(element, null).getPropertyValue(property);
+ if (needsOverflowReset) {
+ style.overflow = originalOverflow || "";
+ }
+ return returnValue;
+ }
+ }
+ };
+ };
+})();
+;wysihtml5.dom.getTextNodes = function(node, ingoreEmpty){
+ var all = [];
+ for (node=node.firstChild;node;node=node.nextSibling){
+ if (node.nodeType == 3) {
+ if (!ingoreEmpty || !(/^\s*$/).test(node.innerText || node.textContent)) {
+ all.push(node);
+ }
+ } else {
+ all = all.concat(wysihtml5.dom.getTextNodes(node, ingoreEmpty));
+ }
+ }
+ return all;
+};;/**
+ * High performant way to check whether an element with a specific tag name is in the given document
+ * Optimized for being heavily executed
+ * Unleashes the power of live node lists
+ *
+ * @param {Object} doc The document object of the context where to check
+ * @param {String} tagName Upper cased tag name
+ * @example
+ * wysihtml5.dom.hasElementWithTagName(document, "IMG");
+ */
+wysihtml5.dom.hasElementWithTagName = (function() {
+ var LIVE_CACHE = {},
+ DOCUMENT_IDENTIFIER = 1;
+
+ function _getDocumentIdentifier(doc) {
+ return doc._wysihtml5_identifier || (doc._wysihtml5_identifier = DOCUMENT_IDENTIFIER++);
+ }
+
+ return function(doc, tagName) {
+ var key = _getDocumentIdentifier(doc) + ":" + tagName,
+ cacheEntry = LIVE_CACHE[key];
+ if (!cacheEntry) {
+ cacheEntry = LIVE_CACHE[key] = doc.getElementsByTagName(tagName);
+ }
+
+ return cacheEntry.length > 0;
+ };
+})();
+;/**
+ * High performant way to check whether an element with a specific class name is in the given document
+ * Optimized for being heavily executed
+ * Unleashes the power of live node lists
+ *
+ * @param {Object} doc The document object of the context where to check
+ * @param {String} tagName Upper cased tag name
+ * @example
+ * wysihtml5.dom.hasElementWithClassName(document, "foobar");
+ */
+(function(wysihtml5) {
+ var LIVE_CACHE = {},
+ DOCUMENT_IDENTIFIER = 1;
+
+ function _getDocumentIdentifier(doc) {
+ return doc._wysihtml5_identifier || (doc._wysihtml5_identifier = DOCUMENT_IDENTIFIER++);
+ }
+
+ wysihtml5.dom.hasElementWithClassName = function(doc, className) {
+ // getElementsByClassName is not supported by IE<9
+ // but is sometimes mocked via library code (which then doesn't return live node lists)
+ if (!wysihtml5.browser.supportsNativeGetElementsByClassName()) {
+ return !!doc.querySelector("." + className);
+ }
+
+ var key = _getDocumentIdentifier(doc) + ":" + className,
+ cacheEntry = LIVE_CACHE[key];
+ if (!cacheEntry) {
+ cacheEntry = LIVE_CACHE[key] = doc.getElementsByClassName(className);
+ }
+
+ return cacheEntry.length > 0;
+ };
+})(wysihtml5);
+;wysihtml5.dom.insert = function(elementToInsert) {
+ return {
+ after: function(element) {
+ element.parentNode.insertBefore(elementToInsert, element.nextSibling);
+ },
+
+ before: function(element) {
+ element.parentNode.insertBefore(elementToInsert, element);
+ },
+
+ into: function(element) {
+ element.appendChild(elementToInsert);
+ }
+ };
+};
+;wysihtml5.dom.insertCSS = function(rules) {
+ rules = rules.join("\n");
+
+ return {
+ into: function(doc) {
+ var styleElement = doc.createElement("style");
+ styleElement.type = "text/css";
+
+ if (styleElement.styleSheet) {
+ styleElement.styleSheet.cssText = rules;
+ } else {
+ styleElement.appendChild(doc.createTextNode(rules));
+ }
+
+ var link = doc.querySelector("head link");
+ if (link) {
+ link.parentNode.insertBefore(styleElement, link);
+ return;
+ } else {
+ var head = doc.querySelector("head");
+ if (head) {
+ head.appendChild(styleElement);
+ }
+ }
+ }
+ };
+};
+;// TODO: Refactor dom tree traversing here
+(function(wysihtml5) {
+ wysihtml5.dom.lineBreaks = function(node) {
+
+ function _isLineBreak(n) {
+ return n.nodeName === "BR";
+ }
+
+ /**
+ * Checks whether the elment causes a visual line break
+ * (<br> or block elements)
+ */
+ function _isLineBreakOrBlockElement(element) {
+ if (_isLineBreak(element)) {
+ return true;
+ }
+
+ if (wysihtml5.dom.getStyle("display").from(element) === "block") {
+ return true;
+ }
+
+ return false;
+ }
+
+ return {
+
+ /* wysihtml5.dom.lineBreaks(element).add();
+ *
+ * Adds line breaks before and after the given node if the previous and next siblings
+ * aren't already causing a visual line break (block element or <br>)
+ */
+ add: function(options) {
+ var doc = node.ownerDocument,
+ nextSibling = wysihtml5.dom.domNode(node).next({ignoreBlankTexts: true}),
+ previousSibling = wysihtml5.dom.domNode(node).prev({ignoreBlankTexts: true});
+
+ if (nextSibling && !_isLineBreakOrBlockElement(nextSibling)) {
+ wysihtml5.dom.insert(doc.createElement("br")).after(node);
+ }
+ if (previousSibling && !_isLineBreakOrBlockElement(previousSibling)) {
+ wysihtml5.dom.insert(doc.createElement("br")).before(node);
+ }
+ },
+
+ /* wysihtml5.dom.lineBreaks(element).remove();
+ *
+ * Removes line breaks before and after the given node
+ */
+ remove: function(options) {
+ var nextSibling = wysihtml5.dom.domNode(node).next({ignoreBlankTexts: true}),
+ previousSibling = wysihtml5.dom.domNode(node).prev({ignoreBlankTexts: true});
+
+ if (nextSibling && _isLineBreak(nextSibling)) {
+ nextSibling.parentNode.removeChild(nextSibling);
+ }
+ if (previousSibling && _isLineBreak(previousSibling)) {
+ previousSibling.parentNode.removeChild(previousSibling);
+ }
+ }
+ };
+ };
+})(wysihtml5);;/**
+ * Method to set dom events
+ *
+ * @example
+ * wysihtml5.dom.observe(iframe.contentWindow.document.body, ["focus", "blur"], function() { ... });
+ */
+wysihtml5.dom.observe = function(element, eventNames, handler) {
+ eventNames = typeof(eventNames) === "string" ? [eventNames] : eventNames;
+
+ var handlerWrapper,
+ eventName,
+ i = 0,
+ length = eventNames.length;
+
+ for (; i<length; i++) {
+ eventName = eventNames[i];
+ if (element.addEventListener) {
+ element.addEventListener(eventName, handler, false);
+ } else {
+ handlerWrapper = function(event) {
+ if (!("target" in event)) {
+ event.target = event.srcElement;
+ }
+ event.preventDefault = event.preventDefault || function() {
+ this.returnValue = false;
+ };
+ event.stopPropagation = event.stopPropagation || function() {
+ this.cancelBubble = true;
+ };
+ handler.call(element, event);
+ };
+ element.attachEvent("on" + eventName, handlerWrapper);
+ }
+ }
+
+ return {
+ stop: function() {
+ var eventName,
+ i = 0,
+ length = eventNames.length;
+ for (; i<length; i++) {
+ eventName = eventNames[i];
+ if (element.removeEventListener) {
+ element.removeEventListener(eventName, handler, false);
+ } else {
+ element.detachEvent("on" + eventName, handlerWrapper);
+ }
+ }
+ }
+ };
+};
+;/**
+ * HTML Sanitizer
+ * Rewrites the HTML based on given rules
+ *
+ * @param {Element|String} elementOrHtml HTML String to be sanitized OR element whose content should be sanitized
+ * @param {Object} [rules] List of rules for rewriting the HTML, if there's no rule for an element it will
+ * be converted to a "span". Each rule is a key/value pair where key is the tag to convert, and value the
+ * desired substitution.
+ * @param {Object} context Document object in which to parse the html, needed to sandbox the parsing
+ *
+ * @return {Element|String} Depends on the elementOrHtml parameter. When html then the sanitized html as string elsewise the element.
+ *
+ * @example
+ * var userHTML = '<div id="foo" onclick="alert(1);"><p><font color="red">foo</font><script>alert(1);</script></p></div>';
+ * wysihtml5.dom.parse(userHTML, {
+ * tags {
+ * p: "div", // Rename p tags to div tags
+ * font: "span" // Rename font tags to span tags
+ * div: true, // Keep them, also possible (same result when passing: "div" or true)
+ * script: undefined // Remove script elements
+ * }
+ * });
+ * // => <div><div><span>foo bar</span></div></div>
+ *
+ * var userHTML = '<table><tbody><tr><td>I'm a table!</td></tr></tbody></table>';
+ * wysihtml5.dom.parse(userHTML);
+ * // => '<span><span><span><span>I'm a table!</span></span></span></span>'
+ *
+ * var userHTML = '<div>foobar<br>foobar</div>';
+ * wysihtml5.dom.parse(userHTML, {
+ * tags: {
+ * div: undefined,
+ * br: true
+ * }
+ * });
+ * // => ''
+ *
+ * var userHTML = '<div class="red">foo</div><div class="pink">bar</div>';
+ * wysihtml5.dom.parse(userHTML, {
+ * classes: {
+ * red: 1,
+ * green: 1
+ * },
+ * tags: {
+ * div: {
+ * rename_tag: "p"
+ * }
+ * }
+ * });
+ * // => '<p class="red">foo</p><p>bar</p>'
+ */
+
+wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
+ /* TODO: Currently escaped module pattern as otherwise folloowing default swill be shared among multiple editors.
+ * Refactor whole code as this method while workind is kind of awkward too */
+
+ /**
+ * It's not possible to use a XMLParser/DOMParser as HTML5 is not always well-formed XML
+ * new DOMParser().parseFromString('<img src="foo.gif">') will cause a parseError since the
+ * node isn't closed
+ *
+ * Therefore we've to use the browser's ordinary HTML parser invoked by setting innerHTML.
+ */
+ var NODE_TYPE_MAPPING = {
+ "1": _handleElement,
+ "3": _handleText,
+ "8": _handleComment
+ },
+ // Rename unknown tags to this
+ DEFAULT_NODE_NAME = "span",
+ WHITE_SPACE_REG_EXP = /\s+/,
+ defaultRules = { tags: {}, classes: {} },
+ currentRules = {},
+ blockElements = ["ADDRESS" ,"BLOCKQUOTE" ,"CENTER" ,"DIR" ,"DIV" ,"DL" ,"FIELDSET" ,
+ "FORM", "H1" ,"H2" ,"H3" ,"H4" ,"H5" ,"H6" ,"ISINDEX" ,"MENU",
+ "NOFRAMES", "NOSCRIPT" ,"OL" ,"P" ,"PRE","TABLE", "UL"];
+
+ /**
+ * Iterates over all childs of the element, recreates them, appends them into a document fragment
+ * which later replaces the entire body content
+ */
+ function parse(elementOrHtml, config) {
+ wysihtml5.lang.object(currentRules).merge(defaultRules).merge(config.rules).get();
+
+ var context = config.context || elementOrHtml.ownerDocument || document,
+ fragment = context.createDocumentFragment(),
+ isString = typeof(elementOrHtml) === "string",
+ clearInternals = false,
+ element,
+ newNode,
+ firstChild;
+
+ if (config.clearInternals === true) {
+ clearInternals = true;
+ }
+
+ if (isString) {
+ element = wysihtml5.dom.getAsDom(elementOrHtml, context);
+ } else {
+ element = elementOrHtml;
+ }
+
+ if (currentRules.selectors) {
+ _applySelectorRules(element, currentRules.selectors);
+ }
+
+ while (element.firstChild) {
+ firstChild = element.firstChild;
+ newNode = _convert(firstChild, config.cleanUp, clearInternals, config.uneditableClass);
+ if (newNode) {
+ fragment.appendChild(newNode);
+ }
+ if (firstChild !== newNode) {
+ element.removeChild(firstChild);
+ }
+ }
+
+ if (config.unjoinNbsps) {
+ // replace joined non-breakable spaces with unjoined
+ var txtnodes = wysihtml5.dom.getTextNodes(fragment);
+ for (var n = txtnodes.length; n--;) {
+ txtnodes[n].nodeValue = txtnodes[n].nodeValue.replace(/([\S\u00A0])\u00A0/gi, "$1 ");
+ }
+ }
+
+ // Clear element contents
+ element.innerHTML = "";
+
+ // Insert new DOM tree
+ element.appendChild(fragment);
+
+ return isString ? wysihtml5.quirks.getCorrectInnerHTML(element) : element;
+ }
+
+ function _convert(oldNode, cleanUp, clearInternals, uneditableClass) {
+ var oldNodeType = oldNode.nodeType,
+ oldChilds = oldNode.childNodes,
+ oldChildsLength = oldChilds.length,
+ method = NODE_TYPE_MAPPING[oldNodeType],
+ i = 0,
+ fragment,
+ newNode,
+ newChild,
+ nodeDisplay;
+
+ // Passes directly elemets with uneditable class
+ if (uneditableClass && oldNodeType === 1 && wysihtml5.dom.hasClass(oldNode, uneditableClass)) {
+ return oldNode;
+ }
+
+ newNode = method && method(oldNode, clearInternals);
+
+ // Remove or unwrap node in case of return value null or false
+ if (!newNode) {
+ if (newNode === false) {
+ // false defines that tag should be removed but contents should remain (unwrap)
+ fragment = oldNode.ownerDocument.createDocumentFragment();
+
+ for (i = oldChildsLength; i--;) {
+ if (oldChilds[i]) {
+ newChild = _convert(oldChilds[i], cleanUp, clearInternals, uneditableClass);
+ if (newChild) {
+ if (oldChilds[i] === newChild) {
+ i--;
+ }
+ fragment.insertBefore(newChild, fragment.firstChild);
+ }
+ }
+ }
+
+ nodeDisplay = wysihtml5.dom.getStyle("display").from(oldNode);
+
+ if (nodeDisplay === '') {
+ // Handle display style when element not in dom
+ nodeDisplay = wysihtml5.lang.array(blockElements).contains(oldNode.tagName) ? "block" : "";
+ }
+ if (wysihtml5.lang.array(["block", "flex", "table"]).contains(nodeDisplay)) {
+ fragment.appendChild(oldNode.ownerDocument.createElement("br"));
+ }
+
+ // TODO: try to minimize surplus spaces
+ if (wysihtml5.lang.array([
+ "div", "pre", "p",
+ "table", "td", "th",
+ "ul", "ol", "li",
+ "dd", "dl",
+ "footer", "header", "section",
+ "h1", "h2", "h3", "h4", "h5", "h6"
+ ]).contains(oldNode.nodeName.toLowerCase()) && oldNode.parentNode.lastChild !== oldNode) {
+ // add space at first when unwraping non-textflow elements
+ if (!oldNode.nextSibling || oldNode.nextSibling.nodeType !== 3 || !(/^\s/).test(oldNode.nextSibling.nodeValue)) {
+ fragment.appendChild(oldNode.ownerDocument.createTextNode(" "));
+ }
+ }
+
+ if (fragment.normalize) {
+ fragment.normalize();
+ }
+ return fragment;
+ } else {
+ // Remove
+ return null;
+ }
+ }
+
+ // Converts all childnodes
+ for (i=0; i<oldChildsLength; i++) {
+ if (oldChilds[i]) {
+ newChild = _convert(oldChilds[i], cleanUp, clearInternals, uneditableClass);
+ if (newChild) {
+ if (oldChilds[i] === newChild) {
+ i--;
+ }
+ newNode.appendChild(newChild);
+ }
+ }
+ }
+
+ // Cleanup senseless <span> elements
+ if (cleanUp &&
+ newNode.nodeName.toLowerCase() === DEFAULT_NODE_NAME &&
+ (!newNode.childNodes.length ||
+ ((/^\s*$/gi).test(newNode.innerHTML) && (clearInternals || (oldNode.className !== "_wysihtml5-temp-placeholder" && oldNode.className !== "rangySelectionBoundary"))) ||
+ !newNode.attributes.length)
+ ) {
+ fragment = newNode.ownerDocument.createDocumentFragment();
+ while (newNode.firstChild) {
+ fragment.appendChild(newNode.firstChild);
+ }
+ if (fragment.normalize) {
+ fragment.normalize();
+ }
+ return fragment;
+ }
+
+ if (newNode.normalize) {
+ newNode.normalize();
+ }
+ return newNode;
+ }
+
+ function _applySelectorRules (element, selectorRules) {
+ var sel, method, els;
+
+ for (sel in selectorRules) {
+ if (selectorRules.hasOwnProperty(sel)) {
+ if (wysihtml5.lang.object(selectorRules[sel]).isFunction()) {
+ method = selectorRules[sel];
+ } else if (typeof(selectorRules[sel]) === "string" && elementHandlingMethods[selectorRules[sel]]) {
+ method = elementHandlingMethods[selectorRules[sel]];
+ }
+ els = element.querySelectorAll(sel);
+ for (var i = els.length; i--;) {
+ method(els[i]);
+ }
+ }
+ }
+ }
+
+ function _handleElement(oldNode, clearInternals) {
+ var rule,
+ newNode,
+ tagRules = currentRules.tags,
+ nodeName = oldNode.nodeName.toLowerCase(),
+ scopeName = oldNode.scopeName,
+ renameTag;
+
+ /**
+ * We already parsed that element
+ * ignore it! (yes, this sometimes happens in IE8 when the html is invalid)
+ */
+ if (oldNode._wysihtml5) {
+ return null;
+ }
+ oldNode._wysihtml5 = 1;
+
+ if (oldNode.className === "wysihtml5-temp") {
+ return null;
+ }
+
+ /**
+ * IE is the only browser who doesn't include the namespace in the
+ * nodeName, that's why we have to prepend it by ourselves
+ * scopeName is a proprietary IE feature
+ * read more here http://msdn.microsoft.com/en-us/library/ms534388(v=vs.85).aspx
+ */
+ if (scopeName && scopeName != "HTML") {
+ nodeName = scopeName + ":" + nodeName;
+ }
+ /**
+ * Repair node
+ * IE is a bit bitchy when it comes to invalid nested markup which includes unclosed tags
+ * A <p> doesn't need to be closed according HTML4-5 spec, we simply replace it with a <div> to preserve its content and layout
+ */
+ if ("outerHTML" in oldNode) {
+ if (!wysihtml5.browser.autoClosesUnclosedTags() &&
+ oldNode.nodeName === "P" &&
+ oldNode.outerHTML.slice(-4).toLowerCase() !== "</p>") {
+ nodeName = "div";
+ }
+ }
+
+ if (nodeName in tagRules) {
+ rule = tagRules[nodeName];
+ if (!rule || rule.remove) {
+ return null;
+ } else if (rule.unwrap) {
+ return false;
+ }
+ rule = typeof(rule) === "string" ? { rename_tag: rule } : rule;
+ } else if (oldNode.firstChild) {
+ rule = { rename_tag: DEFAULT_NODE_NAME };
+ } else {
+ // Remove empty unknown elements
+ return null;
+ }
+
+ // tests if type condition is met or node should be removed/unwrapped/renamed
+ if (rule.one_of_type && !_testTypes(oldNode, currentRules, rule.one_of_type, clearInternals)) {
+ if (rule.remove_action) {
+ if (rule.remove_action === "unwrap") {
+ return false;
+ } else if (rule.remove_action === "rename") {
+ renameTag = rule.remove_action_rename_to || DEFAULT_NODE_NAME;
+ } else {
+ return null;
+ }
+ } else {
+ return null;
+ }
+ }
+
+ newNode = oldNode.ownerDocument.createElement(renameTag || rule.rename_tag || nodeName);
+ _handleAttributes(oldNode, newNode, rule, clearInternals);
+ _handleStyles(oldNode, newNode, rule);
+
+ oldNode = null;
+
+ if (newNode.normalize) { newNode.normalize(); }
+ return newNode;
+ }
+
+ function _testTypes(oldNode, rules, types, clearInternals) {
+ var definition, type;
+
+ // do not interfere with placeholder span or pasting caret position is not maintained
+ if (oldNode.nodeName === "SPAN" && !clearInternals && (oldNode.className === "_wysihtml5-temp-placeholder" || oldNode.className === "rangySelectionBoundary")) {
+ return true;
+ }
+
+ for (type in types) {
+ if (types.hasOwnProperty(type) && rules.type_definitions && rules.type_definitions[type]) {
+ definition = rules.type_definitions[type];
+ if (_testType(oldNode, definition)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ function array_contains(a, obj) {
+ var i = a.length;
+ while (i--) {
+ if (a[i] === obj) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ function _testType(oldNode, definition) {
+
+ var nodeClasses = oldNode.getAttribute("class"),
+ nodeStyles = oldNode.getAttribute("style"),
+ classesLength, s, s_corrected, a, attr, currentClass, styleProp;
+
+ // test for methods
+ if (definition.methods) {
+ for (var m in definition.methods) {
+ if (definition.methods.hasOwnProperty(m) && typeCeckMethods[m]) {
+
+ if (typeCeckMethods[m](oldNode)) {
+ return true;
+ }
+ }
+ }
+ }
+
+ // test for classes, if one found return true
+ if (nodeClasses && definition.classes) {
+ nodeClasses = nodeClasses.replace(/^\s+/g, '').replace(/\s+$/g, '').split(WHITE_SPACE_REG_EXP);
+ classesLength = nodeClasses.length;
+ for (var i = 0; i < classesLength; i++) {
+ if (definition.classes[nodeClasses[i]]) {
+ return true;
+ }
+ }
+ }
+
+ // test for styles, if one found return true
+ if (nodeStyles && definition.styles) {
+
+ nodeStyles = nodeStyles.split(';');
+ for (s in definition.styles) {
+ if (definition.styles.hasOwnProperty(s)) {
+ for (var sp = nodeStyles.length; sp--;) {
+ styleProp = nodeStyles[sp].split(':');
+
+ if (styleProp[0].replace(/\s/g, '').toLowerCase() === s) {
+ if (definition.styles[s] === true || definition.styles[s] === 1 || wysihtml5.lang.array(definition.styles[s]).contains(styleProp[1].replace(/\s/g, '').toLowerCase()) ) {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // test for attributes in general against regex match
+ if (definition.attrs) {
+ for (a in definition.attrs) {
+ if (definition.attrs.hasOwnProperty(a)) {
+ attr = wysihtml5.dom.getAttribute(oldNode, a);
+ if (typeof(attr) === "string") {
+ if (attr.search(definition.attrs[a]) > -1) {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ function _handleStyles(oldNode, newNode, rule) {
+ var s, v;
+ if(rule && rule.keep_styles) {
+ for (s in rule.keep_styles) {
+ if (rule.keep_styles.hasOwnProperty(s)) {
+ v = (s === "float") ? oldNode.style.styleFloat || oldNode.style.cssFloat : oldNode.style[s];
+ // value can be regex and if so should match or style skipped
+ if (rule.keep_styles[s] instanceof RegExp && !(rule.keep_styles[s].test(v))) {
+ continue;
+ }
+ if (s === "float") {
+ // IE compability
+ newNode.style[(oldNode.style.styleFloat) ? 'styleFloat': 'cssFloat'] = v;
+ } else if (oldNode.style[s]) {
+ newNode.style[s] = v;
+ }
+ }
+ }
+ }
+ };
+
+ function _getAttributesBeginningWith(beginning, attributes) {
+ var returnAttributes = [];
+ for (var attr in attributes) {
+ if (attributes.hasOwnProperty(attr) && attr.indexOf(beginning) === 0) {
+ returnAttributes.push(attr);
+ }
+ }
+ return returnAttributes;
+ }
+
+ function _checkAttribute(attributeName, attributeValue, methodName, nodeName) {
+ var method = attributeCheckMethods[methodName],
+ newAttributeValue;
+
+ if (method) {
+ if (attributeValue || (attributeName === "alt" && nodeName == "IMG")) {
+ newAttributeValue = method(attributeValue);
+ if (typeof(newAttributeValue) === "string") {
+ return newAttributeValue;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ function _checkAttributes(oldNode, local_attributes) {
+ var globalAttributes = wysihtml5.lang.object(currentRules.attributes || {}).clone(), // global values for check/convert values of attributes
+ checkAttributes = wysihtml5.lang.object(globalAttributes).merge( wysihtml5.lang.object(local_attributes || {}).clone()).get(),
+ attributes = {},
+ oldAttributes = wysihtml5.dom.getAttributes(oldNode),
+ attributeName, newValue, matchingAttributes;
+
+ for (attributeName in checkAttributes) {
+ if ((/\*$/).test(attributeName)) {
+
+ matchingAttributes = _getAttributesBeginningWith(attributeName.slice(0,-1), oldAttributes);
+ for (var i = 0, imax = matchingAttributes.length; i < imax; i++) {
+
+ newValue = _checkAttribute(matchingAttributes[i], oldAttributes[matchingAttributes[i]], checkAttributes[attributeName], oldNode.nodeName);
+ if (newValue !== false) {
+ attributes[matchingAttributes[i]] = newValue;
+ }
+ }
+ } else {
+ newValue = _checkAttribute(attributeName, oldAttributes[attributeName], checkAttributes[attributeName], oldNode.nodeName);
+ if (newValue !== false) {
+ attributes[attributeName] = newValue;
+ }
+ }
+ }
+
+ return attributes;
+ }
+
+ // TODO: refactor. Too long to read
+ function _handleAttributes(oldNode, newNode, rule, clearInternals) {
+ var attributes = {}, // fresh new set of attributes to set on newNode
+ setClass = rule.set_class, // classes to set
+ addClass = rule.add_class, // add classes based on existing attributes
+ addStyle = rule.add_style, // add styles based on existing attributes
+ setAttributes = rule.set_attributes, // attributes to set on the current node
+ allowedClasses = currentRules.classes,
+ i = 0,
+ classes = [],
+ styles = [],
+ newClasses = [],
+ oldClasses = [],
+ classesLength,
+ newClassesLength,
+ currentClass,
+ newClass,
+ attributeName,
+ method;
+
+ if (setAttributes) {
+ attributes = wysihtml5.lang.object(setAttributes).clone();
+ }
+
+ // check/convert values of attributes
+ attributes = wysihtml5.lang.object(attributes).merge(_checkAttributes(oldNode, rule.check_attributes)).get();
+
+ if (setClass) {
+ classes.push(setClass);
+ }
+
+ if (addClass) {
+ for (attributeName in addClass) {
+ method = addClassMethods[addClass[attributeName]];
+ if (!method) {
+ continue;
+ }
+ newClass = method(wysihtml5.dom.getAttribute(oldNode, attributeName));
+ if (typeof(newClass) === "string") {
+ classes.push(newClass);
+ }
+ }
+ }
+
+ if (addStyle) {
+ for (attributeName in addStyle) {
+ method = addStyleMethods[addStyle[attributeName]];
+ if (!method) {
+ continue;
+ }
+
+ newStyle = method(wysihtml5.dom.getAttribute(oldNode, attributeName));
+ if (typeof(newStyle) === "string") {
+ styles.push(newStyle);
+ }
+ }
+ }
+
+
+ if (typeof(allowedClasses) === "string" && allowedClasses === "any" && oldNode.getAttribute("class")) {
+ if (currentRules.classes_blacklist) {
+ oldClasses = oldNode.getAttribute("class");
+ if (oldClasses) {
+ classes = classes.concat(oldClasses.split(WHITE_SPACE_REG_EXP));
+ }
+
+ classesLength = classes.length;
+ for (; i<classesLength; i++) {
+ currentClass = classes[i];
+ if (!currentRules.classes_blacklist[currentClass]) {
+ newClasses.push(currentClass);
+ }
+ }
+
+ if (newClasses.length) {
+ attributes["class"] = wysihtml5.lang.array(newClasses).unique().join(" ");
+ }
+
+ } else {
+ attributes["class"] = oldNode.getAttribute("class");
+ }
+ } else {
+ // make sure that wysihtml5 temp class doesn't get stripped out
+ if (!clearInternals) {
+ allowedClasses["_wysihtml5-temp-placeholder"] = 1;
+ allowedClasses["_rangySelectionBoundary"] = 1;
+ allowedClasses["wysiwyg-tmp-selected-cell"] = 1;
+ }
+
+ // add old classes last
+ oldClasses = oldNode.getAttribute("class");
+ if (oldClasses) {
+ classes = classes.concat(oldClasses.split(WHITE_SPACE_REG_EXP));
+ }
+ classesLength = classes.length;
+ for (; i<classesLength; i++) {
+ currentClass = classes[i];
+ if (allowedClasses[currentClass]) {
+ newClasses.push(currentClass);
+ }
+ }
+
+ if (newClasses.length) {
+ attributes["class"] = wysihtml5.lang.array(newClasses).unique().join(" ");
+ }
+ }
+
+ // remove table selection class if present
+ if (attributes["class"] && clearInternals) {
+ attributes["class"] = attributes["class"].replace("wysiwyg-tmp-selected-cell", "");
+ if ((/^\s*$/g).test(attributes["class"])) {
+ delete attributes["class"];
+ }
+ }
+
+ if (styles.length) {
+ attributes["style"] = wysihtml5.lang.array(styles).unique().join(" ");
+ }
+
+ // set attributes on newNode
+ for (attributeName in attributes) {
+ // Setting attributes can cause a js error in IE under certain circumstances
+ // eg. on a <img> under https when it's new attribute value is non-https
+ // TODO: Investigate this further and check for smarter handling
+ try {
+ newNode.setAttribute(attributeName, attributes[attributeName]);
+ } catch(e) {}
+ }
+
+ // IE8 sometimes loses the width/height attributes when those are set before the "src"
+ // so we make sure to set them again
+ if (attributes.src) {
+ if (typeof(attributes.width) !== "undefined") {
+ newNode.setAttribute("width", attributes.width);
+ }
+ if (typeof(attributes.height) !== "undefined") {
+ newNode.setAttribute("height", attributes.height);
+ }
+ }
+ }
+
+ function _handleText(oldNode) {
+ var nextSibling = oldNode.nextSibling;
+ if (nextSibling && nextSibling.nodeType === wysihtml5.TEXT_NODE) {
+ // Concatenate text nodes
+ nextSibling.data = oldNode.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "") + nextSibling.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "");
+ } else {
+ // \uFEFF = wysihtml5.INVISIBLE_SPACE (used as a hack in certain rich text editing situations)
+ var data = oldNode.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "");
+ return oldNode.ownerDocument.createTextNode(data);
+ }
+ }
+
+ function _handleComment(oldNode) {
+ if (currentRules.comments) {
+ return oldNode.ownerDocument.createComment(oldNode.nodeValue);
+ }
+ }
+
+ // ------------ attribute checks ------------ \\
+ var attributeCheckMethods = {
+ url: (function() {
+ var REG_EXP = /^https?:\/\//i;
+ return function(attributeValue) {
+ if (!attributeValue || !attributeValue.match(REG_EXP)) {
+ return null;
+ }
+ return attributeValue.replace(REG_EXP, function(match) {
+ return match.toLowerCase();
+ });
+ };
+ })(),
+
+ src: (function() {
+ var REG_EXP = /^(\/|https?:\/\/)/i;
+ return function(attributeValue) {
+ if (!attributeValue || !attributeValue.match(REG_EXP)) {
+ return null;
+ }
+ return attributeValue.replace(REG_EXP, function(match) {
+ return match.toLowerCase();
+ });
+ };
+ })(),
+
+ href: (function() {
+ var REG_EXP = /^(#|\/|https?:\/\/|mailto:)/i;
+ return function(attributeValue) {
+ if (!attributeValue || !attributeValue.match(REG_EXP)) {
+ return null;
+ }
+ return attributeValue.replace(REG_EXP, function(match) {
+ return match.toLowerCase();
+ });
+ };
+ })(),
+
+ alt: (function() {
+ var REG_EXP = /[^ a-z0-9_\-]/gi;
+ return function(attributeValue) {
+ if (!attributeValue) {
+ return "";
+ }
+ return attributeValue.replace(REG_EXP, "");
+ };
+ })(),
+
+ numbers: (function() {
+ var REG_EXP = /\D/g;
+ return function(attributeValue) {
+ attributeValue = (attributeValue || "").replace(REG_EXP, "");
+ return attributeValue || null;
+ };
+ })(),
+
+ any: (function() {
+ return function(attributeValue) {
+ return attributeValue;
+ };
+ })()
+ };
+
+ // ------------ style converter (converts an html attribute to a style) ------------ \\
+ var addStyleMethods = {
+ align_text: (function() {
+ var mapping = {
+ left: "text-align: left;",
+ right: "text-align: right;",
+ center: "text-align: center;"
+ };
+ return function(attributeValue) {
+ return mapping[String(attributeValue).toLowerCase()];
+ };
+ })(),
+ };
+
+ // ------------ class converter (converts an html attribute to a class name) ------------ \\
+ var addClassMethods = {
+ align_img: (function() {
+ var mapping = {
+ left: "wysiwyg-float-left",
+ right: "wysiwyg-float-right"
+ };
+ return function(attributeValue) {
+ return mapping[String(attributeValue).toLowerCase()];
+ };
+ })(),
+
+ align_text: (function() {
+ var mapping = {
+ left: "wysiwyg-text-align-left",
+ right: "wysiwyg-text-align-right",
+ center: "wysiwyg-text-align-center",
+ justify: "wysiwyg-text-align-justify"
+ };
+ return function(attributeValue) {
+ return mapping[String(attributeValue).toLowerCase()];
+ };
+ })(),
+
+ clear_br: (function() {
+ var mapping = {
+ left: "wysiwyg-clear-left",
+ right: "wysiwyg-clear-right",
+ both: "wysiwyg-clear-both",
+ all: "wysiwyg-clear-both"
+ };
+ return function(attributeValue) {
+ return mapping[String(attributeValue).toLowerCase()];
+ };
+ })(),
+
+ size_font: (function() {
+ var mapping = {
+ "1": "wysiwyg-font-size-xx-small",
+ "2": "wysiwyg-font-size-small",
+ "3": "wysiwyg-font-size-medium",
+ "4": "wysiwyg-font-size-large",
+ "5": "wysiwyg-font-size-x-large",
+ "6": "wysiwyg-font-size-xx-large",
+ "7": "wysiwyg-font-size-xx-large",
+ "-": "wysiwyg-font-size-smaller",
+ "+": "wysiwyg-font-size-larger"
+ };
+ return function(attributeValue) {
+ return mapping[String(attributeValue).charAt(0)];
+ };
+ })()
+ };
+
+ // checks if element is possibly visible
+ var typeCeckMethods = {
+ has_visible_contet: (function() {
+ var txt,
+ isVisible = false,
+ visibleElements = ['img', 'video', 'picture', 'br', 'script', 'noscript',
+ 'style', 'table', 'iframe', 'object', 'embed', 'audio',
+ 'svg', 'input', 'button', 'select','textarea', 'canvas'];
+
+ return function(el) {
+
+ // has visible innertext. so is visible
+ txt = (el.innerText || el.textContent).replace(/\s/g, '');
+ if (txt && txt.length > 0) {
+ return true;
+ }
+
+ // matches list of visible dimensioned elements
+ for (var i = visibleElements.length; i--;) {
+ if (el.querySelector(visibleElements[i])) {
+ return true;
+ }
+ }
+
+ // try to measure dimesions in last resort. (can find only of elements in dom)
+ if (el.offsetWidth && el.offsetWidth > 0 && el.offsetHeight && el.offsetHeight > 0) {
+ return true;
+ }
+
+ return false;
+ };
+ })()
+ };
+
+ var elementHandlingMethods = {
+ unwrap: function (element) {
+ wysihtml5.dom.unwrap(element);
+ },
+
+ remove: function (element) {
+ element.parentNode.removeChild(element);
+ }
+ };
+
+ return parse(elementOrHtml_current, config_current);
+};
+;/**
+ * Checks for empty text node childs and removes them
+ *
+ * @param {Element} node The element in which to cleanup
+ * @example
+ * wysihtml5.dom.removeEmptyTextNodes(element);
+ */
+wysihtml5.dom.removeEmptyTextNodes = function(node) {
+ var childNode,
+ childNodes = wysihtml5.lang.array(node.childNodes).get(),
+ childNodesLength = childNodes.length,
+ i = 0;
+ for (; i<childNodesLength; i++) {
+ childNode = childNodes[i];
+ if (childNode.nodeType === wysihtml5.TEXT_NODE && childNode.data === "") {
+ childNode.parentNode.removeChild(childNode);
+ }
+ }
+};
+;/**
+ * Renames an element (eg. a <div> to a <p>) and keeps its childs
+ *
+ * @param {Element} element The list element which should be renamed
+ * @param {Element} newNodeName The desired tag name
+ *
+ * @example
+ * <!-- Assume the following dom: -->
+ * <ul id="list">
+ * <li>eminem</li>
+ * <li>dr. dre</li>
+ * <li>50 Cent</li>
+ * </ul>
+ *
+ * <script>
+ * wysihtml5.dom.renameElement(document.getElementById("list"), "ol");
+ * </script>
+ *
+ * <!-- Will result in: -->
+ * <ol>
+ * <li>eminem</li>
+ * <li>dr. dre</li>
+ * <li>50 Cent</li>
+ * </ol>
+ */
+wysihtml5.dom.renameElement = function(element, newNodeName) {
+ var newElement = element.ownerDocument.createElement(newNodeName),
+ firstChild;
+ while (firstChild = element.firstChild) {
+ newElement.appendChild(firstChild);
+ }
+ wysihtml5.dom.copyAttributes(["align", "className"]).from(element).to(newElement);
+ element.parentNode.replaceChild(newElement, element);
+ return newElement;
+};
+;/**
+ * Takes an element, removes it and replaces it with it's childs
+ *
+ * @param {Object} node The node which to replace with it's child nodes
+ * @example
+ * <div id="foo">
+ * <span>hello</span>
+ * </div>
+ * <script>
+ * // Remove #foo and replace with it's children
+ * wysihtml5.dom.replaceWithChildNodes(document.getElementById("foo"));
+ * </script>
+ */
+wysihtml5.dom.replaceWithChildNodes = function(node) {
+ if (!node.parentNode) {
+ return;
+ }
+
+ if (!node.firstChild) {
+ node.parentNode.removeChild(node);
+ return;
+ }
+
+ var fragment = node.ownerDocument.createDocumentFragment();
+ while (node.firstChild) {
+ fragment.appendChild(node.firstChild);
+ }
+ node.parentNode.replaceChild(fragment, node);
+ node = fragment = null;
+};
+;/**
+ * Unwraps an unordered/ordered list
+ *
+ * @param {Element} element The list element which should be unwrapped
+ *
+ * @example
+ * <!-- Assume the following dom: -->
+ * <ul id="list">
+ * <li>eminem</li>
+ * <li>dr. dre</li>
+ * <li>50 Cent</li>
+ * </ul>
+ *
+ * <script>
+ * wysihtml5.dom.resolveList(document.getElementById("list"));
+ * </script>
+ *
+ * <!-- Will result in: -->
+ * eminem<br>
+ * dr. dre<br>
+ * 50 Cent<br>
+ */
+(function(dom) {
+ function _isBlockElement(node) {
+ return dom.getStyle("display").from(node) === "block";
+ }
+
+ function _isLineBreak(node) {
+ return node.nodeName === "BR";
+ }
+
+ function _appendLineBreak(element) {
+ var lineBreak = element.ownerDocument.createElement("br");
+ element.appendChild(lineBreak);
+ }
+
+ function resolveList(list, useLineBreaks) {
+ if (!list.nodeName.match(/^(MENU|UL|OL)$/)) {
+ return;
+ }
+
+ var doc = list.ownerDocument,
+ fragment = doc.createDocumentFragment(),
+ previousSibling = wysihtml5.dom.domNode(list).prev({ignoreBlankTexts: true}),
+ firstChild,
+ lastChild,
+ isLastChild,
+ shouldAppendLineBreak,
+ paragraph,
+ listItem;
+
+ if (useLineBreaks) {
+ // Insert line break if list is after a non-block element
+ if (previousSibling && !_isBlockElement(previousSibling) && !_isLineBreak(previousSibling)) {
+ _appendLineBreak(fragment);
+ }
+
+ while (listItem = (list.firstElementChild || list.firstChild)) {
+ lastChild = listItem.lastChild;
+ while (firstChild = listItem.firstChild) {
+ isLastChild = firstChild === lastChild;
+ // This needs to be done before appending it to the fragment, as it otherwise will lose style information
+ shouldAppendLineBreak = isLastChild && !_isBlockElement(firstChild) && !_isLineBreak(firstChild);
+ fragment.appendChild(firstChild);
+ if (shouldAppendLineBreak) {
+ _appendLineBreak(fragment);
+ }
+ }
+
+ listItem.parentNode.removeChild(listItem);
+ }
+ } else {
+ while (listItem = (list.firstElementChild || list.firstChild)) {
+ if (listItem.querySelector && listItem.querySelector("div, p, ul, ol, menu, blockquote, h1, h2, h3, h4, h5, h6")) {
+ while (firstChild = listItem.firstChild) {
+ fragment.appendChild(firstChild);
+ }
+ } else {
+ paragraph = doc.createElement("p");
+ while (firstChild = listItem.firstChild) {
+ paragraph.appendChild(firstChild);
+ }
+ fragment.appendChild(paragraph);
+ }
+ listItem.parentNode.removeChild(listItem);
+ }
+ }
+
+ list.parentNode.replaceChild(fragment, list);
+ }
+
+ dom.resolveList = resolveList;
+})(wysihtml5.dom);
+;/**
+ * Sandbox for executing javascript, parsing css styles and doing dom operations in a secure way
+ *
+ * Browser Compatibility:
+ * - Secure in MSIE 6+, but only when the user hasn't made changes to his security level "restricted"
+ * - Partially secure in other browsers (Firefox, Opera, Safari, Chrome, ...)
+ *
+ * Please note that this class can't benefit from the HTML5 sandbox attribute for the following reasons:
+ * - sandboxing doesn't work correctly with inlined content (src="javascript:'<html>...</html>'")
+ * - sandboxing of physical documents causes that the dom isn't accessible anymore from the outside (iframe.contentWindow, ...)
+ * - setting the "allow-same-origin" flag would fix that, but then still javascript and dom events refuse to fire
+ * - therefore the "allow-scripts" flag is needed, which then would deactivate any security, as the js executed inside the iframe
+ * can do anything as if the sandbox attribute wasn't set
+ *
+ * @param {Function} [readyCallback] Method that gets invoked when the sandbox is ready
+ * @param {Object} [config] Optional parameters
+ *
+ * @example
+ * new wysihtml5.dom.Sandbox(function(sandbox) {
+ * sandbox.getWindow().document.body.innerHTML = '<img src=foo.gif onerror="alert(document.cookie)">';
+ * });
+ */
+(function(wysihtml5) {
+ var /**
+ * Default configuration
+ */
+ doc = document,
+ /**
+ * Properties to unset/protect on the window object
+ */
+ windowProperties = [
+ "parent", "top", "opener", "frameElement", "frames",
+ "localStorage", "globalStorage", "sessionStorage", "indexedDB"
+ ],
+ /**
+ * Properties on the window object which are set to an empty function
+ */
+ windowProperties2 = [
+ "open", "close", "openDialog", "showModalDialog",
+ "alert", "confirm", "prompt",
+ "openDatabase", "postMessage",
+ "XMLHttpRequest", "XDomainRequest"
+ ],
+ /**
+ * Properties to unset/protect on the document object
+ */
+ documentProperties = [
+ "referrer",
+ "write", "open", "close"
+ ];
+
+ wysihtml5.dom.Sandbox = Base.extend(
+ /** @scope wysihtml5.dom.Sandbox.prototype */ {
+
+ constructor: function(readyCallback, config) {
+ this.callback = readyCallback || wysihtml5.EMPTY_FUNCTION;
+ this.config = wysihtml5.lang.object({}).merge(config).get();
+ this.editableArea = this._createIframe();
+ },
+
+ insertInto: function(element) {
+ if (typeof(element) === "string") {
+ element = doc.getElementById(element);
+ }
+
+ element.appendChild(this.editableArea);
+ },
+
+ getIframe: function() {
+ return this.editableArea;
+ },
+
+ getWindow: function() {
+ this._readyError();
+ },
+
+ getDocument: function() {
+ this._readyError();
+ },
+
+ destroy: function() {
+ var iframe = this.getIframe();
+ iframe.parentNode.removeChild(iframe);
+ },
+
+ _readyError: function() {
+ throw new Error("wysihtml5.Sandbox: Sandbox iframe isn't loaded yet");
+ },
+
+ /**
+ * Creates the sandbox iframe
+ *
+ * Some important notes:
+ * - We can't use HTML5 sandbox for now:
+ * setting it causes that the iframe's dom can't be accessed from the outside
+ * Therefore we need to set the "allow-same-origin" flag which enables accessing the iframe's dom
+ * But then there's another problem, DOM events (focus, blur, change, keypress, ...) aren't fired.
+ * In order to make this happen we need to set the "allow-scripts" flag.
+ * A combination of allow-scripts and allow-same-origin is almost the same as setting no sandbox attribute at all.
+ * - Chrome & Safari, doesn't seem to support sandboxing correctly when the iframe's html is inlined (no physical document)
+ * - IE needs to have the security="restricted" attribute set before the iframe is
+ * inserted into the dom tree
+ * - Believe it or not but in IE "security" in document.createElement("iframe") is false, even
+ * though it supports it
+ * - When an iframe has security="restricted", in IE eval() & execScript() don't work anymore
+ * - IE doesn't fire the onload event when the content is inlined in the src attribute, therefore we rely
+ * on the onreadystatechange event
+ */
+ _createIframe: function() {
+ var that = this,
+ iframe = doc.createElement("iframe");
+ iframe.className = "wysihtml5-sandbox";
+ wysihtml5.dom.setAttributes({
+ "security": "restricted",
+ "allowtransparency": "true",
+ "frameborder": 0,
+ "width": 0,
+ "height": 0,
+ "marginwidth": 0,
+ "marginheight": 0
+ }).on(iframe);
+
+ // Setting the src like this prevents ssl warnings in IE6
+ if (wysihtml5.browser.throwsMixedContentWarningWhenIframeSrcIsEmpty()) {
+ iframe.src = "javascript:'<html></html>'";
+ }
+
+ iframe.onload = function() {
+ iframe.onreadystatechange = iframe.onload = null;
+ that._onLoadIframe(iframe);
+ };
+
+ iframe.onreadystatechange = function() {
+ if (/loaded|complete/.test(iframe.readyState)) {
+ iframe.onreadystatechange = iframe.onload = null;
+ that._onLoadIframe(iframe);
+ }
+ };
+
+ return iframe;
+ },
+
+ /**
+ * Callback for when the iframe has finished loading
+ */
+ _onLoadIframe: function(iframe) {
+ // don't resume when the iframe got unloaded (eg. by removing it from the dom)
+ if (!wysihtml5.dom.contains(doc.documentElement, iframe)) {
+ return;
+ }
+
+ var that = this,
+ iframeWindow = iframe.contentWindow,
+ iframeDocument = iframe.contentWindow.document,
+ charset = doc.characterSet || doc.charset || "utf-8",
+ sandboxHtml = this._getHtml({
+ charset: charset,
+ stylesheets: this.config.stylesheets
+ });
+
+ // Create the basic dom tree including proper DOCTYPE and charset
+ iframeDocument.open("text/html", "replace");
+ iframeDocument.write(sandboxHtml);
+ iframeDocument.close();
+
+ this.getWindow = function() { return iframe.contentWindow; };
+ this.getDocument = function() { return iframe.contentWindow.document; };
+
+ // Catch js errors and pass them to the parent's onerror event
+ // addEventListener("error") doesn't work properly in some browsers
+ // TODO: apparently this doesn't work in IE9!
+ iframeWindow.onerror = function(errorMessage, fileName, lineNumber) {
+ throw new Error("wysihtml5.Sandbox: " + errorMessage, fileName, lineNumber);
+ };
+
+ if (!wysihtml5.browser.supportsSandboxedIframes()) {
+ // Unset a bunch of sensitive variables
+ // Please note: This isn't hack safe!
+ // It more or less just takes care of basic attacks and prevents accidental theft of sensitive information
+ // IE is secure though, which is the most important thing, since IE is the only browser, who
+ // takes over scripts & styles into contentEditable elements when copied from external websites
+ // or applications (Microsoft Word, ...)
+ var i, length;
+ for (i=0, length=windowProperties.length; i<length; i++) {
+ this._unset(iframeWindow, windowProperties[i]);
+ }
+ for (i=0, length=windowProperties2.length; i<length; i++) {
+ this._unset(iframeWindow, windowProperties2[i], wysihtml5.EMPTY_FUNCTION);
+ }
+ for (i=0, length=documentProperties.length; i<length; i++) {
+ this._unset(iframeDocument, documentProperties[i]);
+ }
+ // This doesn't work in Safari 5
+ // See http://stackoverflow.com/questions/992461/is-it-possible-to-override-document-cookie-in-webkit
+ this._unset(iframeDocument, "cookie", "", true);
+ }
+
+ this.loaded = true;
+
+ // Trigger the callback
+ setTimeout(function() { that.callback(that); }, 0);
+ },
+
+ _getHtml: function(templateVars) {
+ var stylesheets = templateVars.stylesheets,
+ html = "",
+ i = 0,
+ length;
+ stylesheets = typeof(stylesheets) === "string" ? [stylesheets] : stylesheets;
+ if (stylesheets) {
+ length = stylesheets.length;
+ for (; i<length; i++) {
+ html += '<link rel="stylesheet" href="' + stylesheets[i] + '">';
+ }
+ }
+ templateVars.stylesheets = html;
+
+ return wysihtml5.lang.string(
+ '<!DOCTYPE html><html><head>'
+ + '<meta charset="#{charset}">#{stylesheets}</head>'
+ + '<body></body></html>'
+ ).interpolate(templateVars);
+ },
+
+ /**
+ * Method to unset/override existing variables
+ * @example
+ * // Make cookie unreadable and unwritable
+ * this._unset(document, "cookie", "", true);
+ */
+ _unset: function(object, property, value, setter) {
+ try { object[property] = value; } catch(e) {}
+
+ try { object.__defineGetter__(property, function() { return value; }); } catch(e) {}
+ if (setter) {
+ try { object.__defineSetter__(property, function() {}); } catch(e) {}
+ }
+
+ if (!wysihtml5.browser.crashesWhenDefineProperty(property)) {
+ try {
+ var config = {
+ get: function() { return value; }
+ };
+ if (setter) {
+ config.set = function() {};
+ }
+ Object.defineProperty(object, property, config);
+ } catch(e) {}
+ }
+ }
+ });
+})(wysihtml5);
+;(function(wysihtml5) {
+ var doc = document;
+ wysihtml5.dom.ContentEditableArea = Base.extend({
+ getContentEditable: function() {
+ return this.element;
+ },
+
+ getWindow: function() {
+ return this.element.ownerDocument.defaultView;
+ },
+
+ getDocument: function() {
+ return this.element.ownerDocument;
+ },
+
+ constructor: function(readyCallback, config, contentEditable) {
+ this.callback = readyCallback || wysihtml5.EMPTY_FUNCTION;
+ this.config = wysihtml5.lang.object({}).merge(config).get();
+ if (contentEditable) {
+ this.element = this._bindElement(contentEditable);
+ } else {
+ this.element = this._createElement();
+ }
+ },
+
+ // creates a new contenteditable and initiates it
+ _createElement: function() {
+ var element = doc.createElement("div");
+ element.className = "wysihtml5-sandbox";
+ this._loadElement(element);
+ return element;
+ },
+
+ // initiates an allready existent contenteditable
+ _bindElement: function(contentEditable) {
+ contentEditable.className = (contentEditable.className && contentEditable.className != '') ? contentEditable.className + " wysihtml5-sandbox" : "wysihtml5-sandbox";
+ this._loadElement(contentEditable, true);
+ return contentEditable;
+ },
+
+ _loadElement: function(element, contentExists) {
+ var that = this;
+ if (!contentExists) {
+ var sandboxHtml = this._getHtml();
+ element.innerHTML = sandboxHtml;
+ }
+
+ this.getWindow = function() { return element.ownerDocument.defaultView; };
+ this.getDocument = function() { return element.ownerDocument; };
+
+ // Catch js errors and pass them to the parent's onerror event
+ // addEventListener("error") doesn't work properly in some browsers
+ // TODO: apparently this doesn't work in IE9!
+ // TODO: figure out and bind the errors logic for contenteditble mode
+ /*iframeWindow.onerror = function(errorMessage, fileName, lineNumber) {
+ throw new Error("wysihtml5.Sandbox: " + errorMessage, fileName, lineNumber);
+ }
+ */
+ this.loaded = true;
+ // Trigger the callback
+ setTimeout(function() { that.callback(that); }, 0);
+ },
+
+ _getHtml: function(templateVars) {
+ return '';
+ }
+
+ });
+})(wysihtml5);
+;(function() {
+ var mapping = {
+ "className": "class"
+ };
+ wysihtml5.dom.setAttributes = function(attributes) {
+ return {
+ on: function(element) {
+ for (var i in attributes) {
+ element.setAttribute(mapping[i] || i, attributes[i]);
+ }
+ }
+ };
+ };
+})();
+;wysihtml5.dom.setStyles = function(styles) {
+ return {
+ on: function(element) {
+ var style = element.style;
+ if (typeof(styles) === "string") {
+ style.cssText += ";" + styles;
+ return;
+ }
+ for (var i in styles) {
+ if (i === "float") {
+ style.cssFloat = styles[i];
+ style.styleFloat = styles[i];
+ } else {
+ style[i] = styles[i];
+ }
+ }
+ }
+ };
+};
+;/**
+ * Simulate HTML5 placeholder attribute
+ *
+ * Needed since
+ * - div[contentEditable] elements don't support it
+ * - older browsers (such as IE8 and Firefox 3.6) don't support it at all
+ *
+ * @param {Object} parent Instance of main wysihtml5.Editor class
+ * @param {Element} view Instance of wysihtml5.views.* class
+ * @param {String} placeholderText
+ *
+ * @example
+ * wysihtml.dom.simulatePlaceholder(this, composer, "Foobar");
+ */
+(function(dom) {
+ dom.simulatePlaceholder = function(editor, view, placeholderText) {
+ var CLASS_NAME = "placeholder",
+ unset = function() {
+ var composerIsVisible = view.element.offsetWidth > 0 && view.element.offsetHeight > 0;
+ if (view.hasPlaceholderSet()) {
+ view.clear();
+ view.element.focus();
+ if (composerIsVisible ) {
+ setTimeout(function() {
+ var sel = view.selection.getSelection();
+ if (!sel.focusNode || !sel.anchorNode) {
+ view.selection.selectNode(view.element.firstChild || view.element);
+ }
+ }, 0);
+ }
+ }
+ view.placeholderSet = false;
+ dom.removeClass(view.element, CLASS_NAME);
+ },
+ set = function() {
+ if (view.isEmpty()) {
+ view.placeholderSet = true;
+ view.setValue(placeholderText);
+ dom.addClass(view.element, CLASS_NAME);
+ }
+ };
+
+ editor
+ .on("set_placeholder", set)
+ .on("unset_placeholder", unset)
+ .on("focus:composer", unset)
+ .on("paste:composer", unset)
+ .on("blur:composer", set);
+
+ set();
+ };
+})(wysihtml5.dom);
+;(function(dom) {
+ var documentElement = document.documentElement;
+ if ("textContent" in documentElement) {
+ dom.setTextContent = function(element, text) {
+ element.textContent = text;
+ };
+
+ dom.getTextContent = function(element) {
+ return element.textContent;
+ };
+ } else if ("innerText" in documentElement) {
+ dom.setTextContent = function(element, text) {
+ element.innerText = text;
+ };
+
+ dom.getTextContent = function(element) {
+ return element.innerText;
+ };
+ } else {
+ dom.setTextContent = function(element, text) {
+ element.nodeValue = text;
+ };
+
+ dom.getTextContent = function(element) {
+ return element.nodeValue;
+ };
+ }
+})(wysihtml5.dom);
+
+;/**
+ * Get a set of attribute from one element
+ *
+ * IE gives wrong results for hasAttribute/getAttribute, for example:
+ * var td = document.createElement("td");
+ * td.getAttribute("rowspan"); // => "1" in IE
+ *
+ * Therefore we have to check the element's outerHTML for the attribute
+*/
+
+wysihtml5.dom.getAttribute = function(node, attributeName) {
+ var HAS_GET_ATTRIBUTE_BUG = !wysihtml5.browser.supportsGetAttributeCorrectly();
+ attributeName = attributeName.toLowerCase();
+ var nodeName = node.nodeName;
+ if (nodeName == "IMG" && attributeName == "src" && wysihtml5.dom.isLoadedImage(node) === true) {
+ // Get 'src' attribute value via object property since this will always contain the
+ // full absolute url (http://...)
+ // this fixes a very annoying bug in firefox (ver 3.6 & 4) and IE 8 where images copied from the same host
+ // will have relative paths, which the sanitizer strips out (see attributeCheckMethods.url)
+ return node.src;
+ } else if (HAS_GET_ATTRIBUTE_BUG && "outerHTML" in node) {
+ // Don't trust getAttribute/hasAttribute in IE 6-8, instead check the element's outerHTML
+ var outerHTML = node.outerHTML.toLowerCase(),
+ // TODO: This might not work for attributes without value: <input disabled>
+ hasAttribute = outerHTML.indexOf(" " + attributeName + "=") != -1;
+
+ return hasAttribute ? node.getAttribute(attributeName) : null;
+ } else{
+ return node.getAttribute(attributeName);
+ }
+};
+;/**
+ * Get all attributes of an element
+ *
+ * IE gives wrong results for hasAttribute/getAttribute, for example:
+ * var td = document.createElement("td");
+ * td.getAttribute("rowspan"); // => "1" in IE
+ *
+ * Therefore we have to check the element's outerHTML for the attribute
+*/
+
+wysihtml5.dom.getAttributes = function(node) {
+ var HAS_GET_ATTRIBUTE_BUG = !wysihtml5.browser.supportsGetAttributeCorrectly(),
+ nodeName = node.nodeName,
+ attributes = [],
+ attr;
+
+ for (attr in node.attributes) {
+ if ((node.attributes.hasOwnProperty && node.attributes.hasOwnProperty(attr)) || (!node.attributes.hasOwnProperty && Object.prototype.hasOwnProperty.call(node.attributes, attr))) {
+ if (node.attributes[attr].specified) {
+ if (nodeName == "IMG" && node.attributes[attr].name.toLowerCase() == "src" && wysihtml5.dom.isLoadedImage(node) === true) {
+ attributes['src'] = node.src;
+ } else if (wysihtml5.lang.array(['rowspan', 'colspan']).contains(node.attributes[attr].name.toLowerCase()) && HAS_GET_ATTRIBUTE_BUG) {
+ if (node.attributes[attr].value !== 1) {
+ attributes[node.attributes[attr].name] = node.attributes[attr].value;
+ }
+ } else {
+ attributes[node.attributes[attr].name] = node.attributes[attr].value;
+ }
+ }
+ }
+ }
+ return attributes;
+};;/**
+ * Check whether the given node is a proper loaded image
+ * FIXME: Returns undefined when unknown (Chrome, Safari)
+*/
+
+wysihtml5.dom.isLoadedImage = function (node) {
+ try {
+ return node.complete && !node.mozMatchesSelector(":-moz-broken");
+ } catch(e) {
+ if (node.complete && node.readyState === "complete") {
+ return true;
+ }
+ }
+};
+;(function(wysihtml5) {
+
+ var api = wysihtml5.dom;
+
+ var MapCell = function(cell) {
+ this.el = cell;
+ this.isColspan= false;
+ this.isRowspan= false;
+ this.firstCol= true;
+ this.lastCol= true;
+ this.firstRow= true;
+ this.lastRow= true;
+ this.isReal= true;
+ this.spanCollection= [];
+ this.modified = false;
+ };
+
+ var TableModifyerByCell = function (cell, table) {
+ if (cell) {
+ this.cell = cell;
+ this.table = api.getParentElement(cell, { nodeName: ["TABLE"] });
+ } else if (table) {
+ this.table = table;
+ this.cell = this.table.querySelectorAll('th, td')[0];
+ }
+ };
+
+ function queryInList(list, query) {
+ var ret = [],
+ q;
+ for (var e = 0, len = list.length; e < len; e++) {
+ q = list[e].querySelectorAll(query);
+ if (q) {
+ for(var i = q.length; i--; ret.unshift(q[i]));
+ }
+ }
+ return ret;
+ }
+
+ function removeElement(el) {
+ el.parentNode.removeChild(el);
+ }
+
+ function insertAfter(referenceNode, newNode) {
+ referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
+ }
+
+ function nextNode(node, tag) {
+ var element = node.nextSibling;
+ while (element.nodeType !=1) {
+ element = element.nextSibling;
+ if (!tag || tag == element.tagName.toLowerCase()) {
+ return element;
+ }
+ }
+ return null;
+ }
+
+ TableModifyerByCell.prototype = {
+
+ addSpannedCellToMap: function(cell, map, r, c, cspan, rspan) {
+ var spanCollect = [],
+ rmax = r + ((rspan) ? parseInt(rspan, 10) - 1 : 0),
+ cmax = c + ((cspan) ? parseInt(cspan, 10) - 1 : 0);
+
+ for (var rr = r; rr <= rmax; rr++) {
+ if (typeof map[rr] == "undefined") { map[rr] = []; }
+ for (var cc = c; cc <= cmax; cc++) {
+ map[rr][cc] = new MapCell(cell);
+ map[rr][cc].isColspan = (cspan && parseInt(cspan, 10) > 1);
+ map[rr][cc].isRowspan = (rspan && parseInt(rspan, 10) > 1);
+ map[rr][cc].firstCol = cc == c;
+ map[rr][cc].lastCol = cc == cmax;
+ map[rr][cc].firstRow = rr == r;
+ map[rr][cc].lastRow = rr == rmax;
+ map[rr][cc].isReal = cc == c && rr == r;
+ map[rr][cc].spanCollection = spanCollect;
+
+ spanCollect.push(map[rr][cc]);
+ }
+ }
+ },
+
+ setCellAsModified: function(cell) {
+ cell.modified = true;
+ if (cell.spanCollection.length > 0) {
+ for (var s = 0, smax = cell.spanCollection.length; s < smax; s++) {
+ cell.spanCollection[s].modified = true;
+ }
+ }
+ },
+
+ setTableMap: function() {
+ var map = [];
+ var tableRows = this.getTableRows(),
+ ridx, row, cells, cidx, cell,
+ c,
+ cspan, rspan;
+
+ for (ridx = 0; ridx < tableRows.length; ridx++) {
+ row = tableRows[ridx];
+ cells = this.getRowCells(row);
+ c = 0;
+ if (typeof map[ridx] == "undefined") { map[ridx] = []; }
+ for (cidx = 0; cidx < cells.length; cidx++) {
+ cell = cells[cidx];
+
+ // If cell allready set means it is set by col or rowspan,
+ // so increase cols index until free col is found
+ while (typeof map[ridx][c] != "undefined") { c++; }
+
+ cspan = api.getAttribute(cell, 'colspan');
+ rspan = api.getAttribute(cell, 'rowspan');
+
+ if (cspan || rspan) {
+ this.addSpannedCellToMap(cell, map, ridx, c, cspan, rspan);
+ c = c + ((cspan) ? parseInt(cspan, 10) : 1);
+ } else {
+ map[ridx][c] = new MapCell(cell);
+ c++;
+ }
+ }
+ }
+ this.map = map;
+ return map;
+ },
+
+ getRowCells: function(row) {
+ var inlineTables = this.table.querySelectorAll('table'),
+ inlineCells = (inlineTables) ? queryInList(inlineTables, 'th, td') : [],
+ allCells = row.querySelectorAll('th, td'),
+ tableCells = (inlineCells.length > 0) ? wysihtml5.lang.array(allCells).without(inlineCells) : allCells;
+
+ return tableCells;
+ },
+
+ getTableRows: function() {
+ var inlineTables = this.table.querySelectorAll('table'),
+ inlineRows = (inlineTables) ? queryInList(inlineTables, 'tr') : [],
+ allRows = this.table.querySelectorAll('tr'),
+ tableRows = (inlineRows.length > 0) ? wysihtml5.lang.array(allRows).without(inlineRows) : allRows;
+
+ return tableRows;
+ },
+
+ getMapIndex: function(cell) {
+ var r_length = this.map.length,
+ c_length = (this.map && this.map[0]) ? this.map[0].length : 0;
+
+ for (var r_idx = 0;r_idx < r_length; r_idx++) {
+ for (var c_idx = 0;c_idx < c_length; c_idx++) {
+ if (this.map[r_idx][c_idx].el === cell) {
+ return {'row': r_idx, 'col': c_idx};
+ }
+ }
+ }
+ return false;
+ },
+
+ getElementAtIndex: function(idx) {
+ this.setTableMap();
+ if (this.map[idx.row] && this.map[idx.row][idx.col] && this.map[idx.row][idx.col].el) {
+ return this.map[idx.row][idx.col].el;
+ }
+ return null;
+ },
+
+ getMapElsTo: function(to_cell) {
+ var els = [];
+ this.setTableMap();
+ this.idx_start = this.getMapIndex(this.cell);
+ this.idx_end = this.getMapIndex(to_cell);
+
+ // switch indexes if start is bigger than end
+ if (this.idx_start.row > this.idx_end.row || (this.idx_start.row == this.idx_end.row && this.idx_start.col > this.idx_end.col)) {
+ var temp_idx = this.idx_start;
+ this.idx_start = this.idx_end;
+ this.idx_end = temp_idx;
+ }
+ if (this.idx_start.col > this.idx_end.col) {
+ var temp_cidx = this.idx_start.col;
+ this.idx_start.col = this.idx_end.col;
+ this.idx_end.col = temp_cidx;
+ }
+
+ if (this.idx_start != null && this.idx_end != null) {
+ for (var row = this.idx_start.row, maxr = this.idx_end.row; row <= maxr; row++) {
+ for (var col = this.idx_start.col, maxc = this.idx_end.col; col <= maxc; col++) {
+ els.push(this.map[row][col].el);
+ }
+ }
+ }
+ return els;
+ },
+
+ orderSelectionEnds: function(secondcell) {
+ this.setTableMap();
+ this.idx_start = this.getMapIndex(this.cell);
+ this.idx_end = this.getMapIndex(secondcell);
+
+ // switch indexes if start is bigger than end
+ if (this.idx_start.row > this.idx_end.row || (this.idx_start.row == this.idx_end.row && this.idx_start.col > this.idx_end.col)) {
+ var temp_idx = this.idx_start;
+ this.idx_start = this.idx_end;
+ this.idx_end = temp_idx;
+ }
+ if (this.idx_start.col > this.idx_end.col) {
+ var temp_cidx = this.idx_start.col;
+ this.idx_start.col = this.idx_end.col;
+ this.idx_end.col = temp_cidx;
+ }
+
+ return {
+ "start": this.map[this.idx_start.row][this.idx_start.col].el,
+ "end": this.map[this.idx_end.row][this.idx_end.col].el
+ };
+ },
+
+ createCells: function(tag, nr, attrs) {
+ var doc = this.table.ownerDocument,
+ frag = doc.createDocumentFragment(),
+ cell;
+ for (var i = 0; i < nr; i++) {
+ cell = doc.createElement(tag);
+
+ if (attrs) {
+ for (var attr in attrs) {
+ if (attrs.hasOwnProperty(attr)) {
+ cell.setAttribute(attr, attrs[attr]);
+ }
+ }
+ }
+
+ // add non breaking space
+ cell.appendChild(document.createTextNode("\u00a0"));
+
+ frag.appendChild(cell);
+ }
+ return frag;
+ },
+
+ // Returns next real cell (not part of spanned cell unless first) on row if selected index is not real. I no real cells -1 will be returned
+ correctColIndexForUnreals: function(col, row) {
+ var r = this.map[row],
+ corrIdx = -1;
+ for (var i = 0, max = col; i < col; i++) {
+ if (r[i].isReal){
+ corrIdx++;
+ }
+ }
+ return corrIdx;
+ },
+
+ getLastNewCellOnRow: function(row, rowLimit) {
+ var cells = this.getRowCells(row),
+ cell, idx;
+
+ for (var cidx = 0, cmax = cells.length; cidx < cmax; cidx++) {
+ cell = cells[cidx];
+ idx = this.getMapIndex(cell);
+ if (idx === false || (typeof rowLimit != "undefined" && idx.row != rowLimit)) {
+ return cell;
+ }
+ }
+ return null;
+ },
+
+ removeEmptyTable: function() {
+ var cells = this.table.querySelectorAll('td, th');
+ if (!cells || cells.length == 0) {
+ removeElement(this.table);
+ return true;
+ } else {
+ return false;
+ }
+ },
+
+ // Splits merged cell on row to unique cells
+ splitRowToCells: function(cell) {
+ if (cell.isColspan) {
+ var colspan = parseInt(api.getAttribute(cell.el, 'colspan') || 1, 10),
+ cType = cell.el.tagName.toLowerCase();
+ if (colspan > 1) {
+ var newCells = this.createCells(cType, colspan -1);
+ insertAfter(cell.el, newCells);
+ }
+ cell.el.removeAttribute('colspan');
+ }
+ },
+
+ getRealRowEl: function(force, idx) {
+ var r = null,
+ c = null;
+
+ idx = idx || this.idx;
+
+ for (var cidx = 0, cmax = this.map[idx.row].length; cidx < cmax; cidx++) {
+ c = this.map[idx.row][cidx];
+ if (c.isReal) {
+ r = api.getParentElement(c.el, { nodeName: ["TR"] });
+ if (r) {
+ return r;
+ }
+ }
+ }
+
+ if (r === null && force) {
+ r = api.getParentElement(this.map[idx.row][idx.col].el, { nodeName: ["TR"] }) || null;
+ }
+
+ return r;
+ },
+
+ injectRowAt: function(row, col, colspan, cType, c) {
+ var r = this.getRealRowEl(false, {'row': row, 'col': col}),
+ new_cells = this.createCells(cType, colspan);
+
+ if (r) {
+ var n_cidx = this.correctColIndexForUnreals(col, row);
+ if (n_cidx >= 0) {
+ insertAfter(this.getRowCells(r)[n_cidx], new_cells);
+ } else {
+ r.insertBefore(new_cells, r.firstChild);
+ }
+ } else {
+ var rr = this.table.ownerDocument.createElement('tr');
+ rr.appendChild(new_cells);
+ insertAfter(api.getParentElement(c.el, { nodeName: ["TR"] }), rr);
+ }
+ },
+
+ canMerge: function(to) {
+ this.to = to;
+ this.setTableMap();
+ this.idx_start = this.getMapIndex(this.cell);
+ this.idx_end = this.getMapIndex(this.to);
+
+ // switch indexes if start is bigger than end
+ if (this.idx_start.row > this.idx_end.row || (this.idx_start.row == this.idx_end.row && this.idx_start.col > this.idx_end.col)) {
+ var temp_idx = this.idx_start;
+ this.idx_start = this.idx_end;
+ this.idx_end = temp_idx;
+ }
+ if (this.idx_start.col > this.idx_end.col) {
+ var temp_cidx = this.idx_start.col;
+ this.idx_start.col = this.idx_end.col;
+ this.idx_end.col = temp_cidx;
+ }
+
+ for (var row = this.idx_start.row, maxr = this.idx_end.row; row <= maxr; row++) {
+ for (var col = this.idx_start.col, maxc = this.idx_end.col; col <= maxc; col++) {
+ if (this.map[row][col].isColspan || this.map[row][col].isRowspan) {
+ return false;
+ }
+ }
+ }
+ return true;
+ },
+
+ decreaseCellSpan: function(cell, span) {
+ var nr = parseInt(api.getAttribute(cell.el, span), 10) - 1;
+ if (nr >= 1) {
+ cell.el.setAttribute(span, nr);
+ } else {
+ cell.el.removeAttribute(span);
+ if (span == 'colspan') {
+ cell.isColspan = false;
+ }
+ if (span == 'rowspan') {
+ cell.isRowspan = false;
+ }
+ cell.firstCol = true;
+ cell.lastCol = true;
+ cell.firstRow = true;
+ cell.lastRow = true;
+ cell.isReal = true;
+ }
+ },
+
+ removeSurplusLines: function() {
+ var row, cell, ridx, rmax, cidx, cmax, allRowspan;
+
+ this.setTableMap();
+ if (this.map) {
+ ridx = 0;
+ rmax = this.map.length;
+ for (;ridx < rmax; ridx++) {
+ row = this.map[ridx];
+ allRowspan = true;
+ cidx = 0;
+ cmax = row.length;
+ for (; cidx < cmax; cidx++) {
+ cell = row[cidx];
+ if (!(api.getAttribute(cell.el, "rowspan") && parseInt(api.getAttribute(cell.el, "rowspan"), 10) > 1 && cell.firstRow !== true)) {
+ allRowspan = false;
+ break;
+ }
+ }
+ if (allRowspan) {
+ cidx = 0;
+ for (; cidx < cmax; cidx++) {
+ this.decreaseCellSpan(row[cidx], 'rowspan');
+ }
+ }
+ }
+
+ // remove rows without cells
+ var tableRows = this.getTableRows();
+ ridx = 0;
+ rmax = tableRows.length;
+ for (;ridx < rmax; ridx++) {
+ row = tableRows[ridx];
+ if (row.childNodes.length == 0 && (/^\s*$/.test(row.textContent || row.innerText))) {
+ removeElement(row);
+ }
+ }
+ }
+ },
+
+ fillMissingCells: function() {
+ var r_max = 0,
+ c_max = 0,
+ prevcell = null;
+
+ this.setTableMap();
+ if (this.map) {
+
+ // find maximal dimensions of broken table
+ r_max = this.map.length;
+ for (var ridx = 0; ridx < r_max; ridx++) {
+ if (this.map[ridx].length > c_max) { c_max = this.map[ridx].length; }
+ }
+
+ for (var row = 0; row < r_max; row++) {
+ for (var col = 0; col < c_max; col++) {
+ if (this.map[row] && !this.map[row][col]) {
+ if (col > 0) {
+ this.map[row][col] = new MapCell(this.createCells('td', 1));
+ prevcell = this.map[row][col-1];
+ if (prevcell && prevcell.el && prevcell.el.parent) { // if parent does not exist element is removed from dom
+ insertAfter(this.map[row][col-1].el, this.map[row][col].el);
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+
+ rectify: function() {
+ if (!this.removeEmptyTable()) {
+ this.removeSurplusLines();
+ this.fillMissingCells();
+ return true;
+ } else {
+ return false;
+ }
+ },
+
+ unmerge: function() {
+ if (this.rectify()) {
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+
+ if (this.idx) {
+ var thisCell = this.map[this.idx.row][this.idx.col],
+ colspan = (api.getAttribute(thisCell.el, "colspan")) ? parseInt(api.getAttribute(thisCell.el, "colspan"), 10) : 1,
+ cType = thisCell.el.tagName.toLowerCase();
+
+ if (thisCell.isRowspan) {
+ var rowspan = parseInt(api.getAttribute(thisCell.el, "rowspan"), 10);
+ if (rowspan > 1) {
+ for (var nr = 1, maxr = rowspan - 1; nr <= maxr; nr++){
+ this.injectRowAt(this.idx.row + nr, this.idx.col, colspan, cType, thisCell);
+ }
+ }
+ thisCell.el.removeAttribute('rowspan');
+ }
+ this.splitRowToCells(thisCell);
+ }
+ }
+ },
+
+ // merges cells from start cell (defined in creating obj) to "to" cell
+ merge: function(to) {
+ if (this.rectify()) {
+ if (this.canMerge(to)) {
+ var rowspan = this.idx_end.row - this.idx_start.row + 1,
+ colspan = this.idx_end.col - this.idx_start.col + 1;
+
+ for (var row = this.idx_start.row, maxr = this.idx_end.row; row <= maxr; row++) {
+ for (var col = this.idx_start.col, maxc = this.idx_end.col; col <= maxc; col++) {
+
+ if (row == this.idx_start.row && col == this.idx_start.col) {
+ if (rowspan > 1) {
+ this.map[row][col].el.setAttribute('rowspan', rowspan);
+ }
+ if (colspan > 1) {
+ this.map[row][col].el.setAttribute('colspan', colspan);
+ }
+ } else {
+ // transfer content
+ if (!(/^\s*<br\/?>\s*$/.test(this.map[row][col].el.innerHTML.toLowerCase()))) {
+ this.map[this.idx_start.row][this.idx_start.col].el.innerHTML += ' ' + this.map[row][col].el.innerHTML;
+ }
+ removeElement(this.map[row][col].el);
+ }
+ }
+ }
+ this.rectify();
+ } else {
+ if (window.console) {
+ console.log('Do not know how to merge allready merged cells.');
+ }
+ }
+ }
+ },
+
+ // Decreases rowspan of a cell if it is done on first cell of rowspan row (real cell)
+ // Cell is moved to next row (if it is real)
+ collapseCellToNextRow: function(cell) {
+ var cellIdx = this.getMapIndex(cell.el),
+ newRowIdx = cellIdx.row + 1,
+ newIdx = {'row': newRowIdx, 'col': cellIdx.col};
+
+ if (newRowIdx < this.map.length) {
+
+ var row = this.getRealRowEl(false, newIdx);
+ if (row !== null) {
+ var n_cidx = this.correctColIndexForUnreals(newIdx.col, newIdx.row);
+ if (n_cidx >= 0) {
+ insertAfter(this.getRowCells(row)[n_cidx], cell.el);
+ } else {
+ var lastCell = this.getLastNewCellOnRow(row, newRowIdx);
+ if (lastCell !== null) {
+ insertAfter(lastCell, cell.el);
+ } else {
+ row.insertBefore(cell.el, row.firstChild);
+ }
+ }
+ if (parseInt(api.getAttribute(cell.el, 'rowspan'), 10) > 2) {
+ cell.el.setAttribute('rowspan', parseInt(api.getAttribute(cell.el, 'rowspan'), 10) - 1);
+ } else {
+ cell.el.removeAttribute('rowspan');
+ }
+ }
+ }
+ },
+
+ // Removes a cell when removing a row
+ // If is rowspan cell then decreases the rowspan
+ // and moves cell to next row if needed (is first cell of rowspan)
+ removeRowCell: function(cell) {
+ if (cell.isReal) {
+ if (cell.isRowspan) {
+ this.collapseCellToNextRow(cell);
+ } else {
+ removeElement(cell.el);
+ }
+ } else {
+ if (parseInt(api.getAttribute(cell.el, 'rowspan'), 10) > 2) {
+ cell.el.setAttribute('rowspan', parseInt(api.getAttribute(cell.el, 'rowspan'), 10) - 1);
+ } else {
+ cell.el.removeAttribute('rowspan');
+ }
+ }
+ },
+
+ getRowElementsByCell: function() {
+ var cells = [];
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+ if (this.idx !== false) {
+ var modRow = this.map[this.idx.row];
+ for (var cidx = 0, cmax = modRow.length; cidx < cmax; cidx++) {
+ if (modRow[cidx].isReal) {
+ cells.push(modRow[cidx].el);
+ }
+ }
+ }
+ return cells;
+ },
+
+ getColumnElementsByCell: function() {
+ var cells = [];
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+ if (this.idx !== false) {
+ for (var ridx = 0, rmax = this.map.length; ridx < rmax; ridx++) {
+ if (this.map[ridx][this.idx.col] && this.map[ridx][this.idx.col].isReal) {
+ cells.push(this.map[ridx][this.idx.col].el);
+ }
+ }
+ }
+ return cells;
+ },
+
+ // Removes the row of selected cell
+ removeRow: function() {
+ var oldRow = api.getParentElement(this.cell, { nodeName: ["TR"] });
+ if (oldRow) {
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+ if (this.idx !== false) {
+ var modRow = this.map[this.idx.row];
+ for (var cidx = 0, cmax = modRow.length; cidx < cmax; cidx++) {
+ if (!modRow[cidx].modified) {
+ this.setCellAsModified(modRow[cidx]);
+ this.removeRowCell(modRow[cidx]);
+ }
+ }
+ }
+ removeElement(oldRow);
+ }
+ },
+
+ removeColCell: function(cell) {
+ if (cell.isColspan) {
+ if (parseInt(api.getAttribute(cell.el, 'colspan'), 10) > 2) {
+ cell.el.setAttribute('colspan', parseInt(api.getAttribute(cell.el, 'colspan'), 10) - 1);
+ } else {
+ cell.el.removeAttribute('colspan');
+ }
+ } else if (cell.isReal) {
+ removeElement(cell.el);
+ }
+ },
+
+ removeColumn: function() {
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+ if (this.idx !== false) {
+ for (var ridx = 0, rmax = this.map.length; ridx < rmax; ridx++) {
+ if (!this.map[ridx][this.idx.col].modified) {
+ this.setCellAsModified(this.map[ridx][this.idx.col]);
+ this.removeColCell(this.map[ridx][this.idx.col]);
+ }
+ }
+ }
+ },
+
+ // removes row or column by selected cell element
+ remove: function(what) {
+ if (this.rectify()) {
+ switch (what) {
+ case 'row':
+ this.removeRow();
+ break;
+ case 'column':
+ this.removeColumn();
+ break;
+ }
+ this.rectify();
+ }
+ },
+
+ addRow: function(where) {
+ var doc = this.table.ownerDocument;
+
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+ if (where == "below" && api.getAttribute(this.cell, 'rowspan')) {
+ this.idx.row = this.idx.row + parseInt(api.getAttribute(this.cell, 'rowspan'), 10) - 1;
+ }
+
+ if (this.idx !== false) {
+ var modRow = this.map[this.idx.row],
+ newRow = doc.createElement('tr');
+
+ for (var ridx = 0, rmax = modRow.length; ridx < rmax; ridx++) {
+ if (!modRow[ridx].modified) {
+ this.setCellAsModified(modRow[ridx]);
+ this.addRowCell(modRow[ridx], newRow, where);
+ }
+ }
+
+ switch (where) {
+ case 'below':
+ insertAfter(this.getRealRowEl(true), newRow);
+ break;
+ case 'above':
+ var cr = api.getParentElement(this.map[this.idx.row][this.idx.col].el, { nodeName: ["TR"] });
+ if (cr) {
+ cr.parentNode.insertBefore(newRow, cr);
+ }
+ break;
+ }
+ }
+ },
+
+ addRowCell: function(cell, row, where) {
+ var colSpanAttr = (cell.isColspan) ? {"colspan" : api.getAttribute(cell.el, 'colspan')} : null;
+ if (cell.isReal) {
+ if (where != 'above' && cell.isRowspan) {
+ cell.el.setAttribute('rowspan', parseInt(api.getAttribute(cell.el,'rowspan'), 10) + 1);
+ } else {
+ row.appendChild(this.createCells('td', 1, colSpanAttr));
+ }
+ } else {
+ if (where != 'above' && cell.isRowspan && cell.lastRow) {
+ row.appendChild(this.createCells('td', 1, colSpanAttr));
+ } else if (c.isRowspan) {
+ cell.el.attr('rowspan', parseInt(api.getAttribute(cell.el, 'rowspan'), 10) + 1);
+ }
+ }
+ },
+
+ add: function(where) {
+ if (this.rectify()) {
+ if (where == 'below' || where == 'above') {
+ this.addRow(where);
+ }
+ if (where == 'before' || where == 'after') {
+ this.addColumn(where);
+ }
+ }
+ },
+
+ addColCell: function (cell, ridx, where) {
+ var doAdd,
+ cType = cell.el.tagName.toLowerCase();
+
+ // defines add cell vs expand cell conditions
+ // true means add
+ switch (where) {
+ case "before":
+ doAdd = (!cell.isColspan || cell.firstCol);
+ break;
+ case "after":
+ doAdd = (!cell.isColspan || cell.lastCol || (cell.isColspan && c.el == this.cell));
+ break;
+ }
+
+ if (doAdd){
+ // adds a cell before or after current cell element
+ switch (where) {
+ case "before":
+ cell.el.parentNode.insertBefore(this.createCells(cType, 1), cell.el);
+ break;
+ case "after":
+ insertAfter(cell.el, this.createCells(cType, 1));
+ break;
+ }
+
+ // handles if cell has rowspan
+ if (cell.isRowspan) {
+ this.handleCellAddWithRowspan(cell, ridx+1, where);
+ }
+
+ } else {
+ // expands cell
+ cell.el.setAttribute('colspan', parseInt(api.getAttribute(cell.el, 'colspan'), 10) + 1);
+ }
+ },
+
+ addColumn: function(where) {
+ var row, modCell;
+
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+ if (where == "after" && api.getAttribute(this.cell, 'colspan')) {
+ this.idx.col = this.idx.col + parseInt(api.getAttribute(this.cell, 'colspan'), 10) - 1;
+ }
+
+ if (this.idx !== false) {
+ for (var ridx = 0, rmax = this.map.length; ridx < rmax; ridx++ ) {
+ row = this.map[ridx];
+ if (row[this.idx.col]) {
+ modCell = row[this.idx.col];
+ if (!modCell.modified) {
+ this.setCellAsModified(modCell);
+ this.addColCell(modCell, ridx , where);
+ }
+ }
+ }
+ }
+ },
+
+ handleCellAddWithRowspan: function (cell, ridx, where) {
+ var addRowsNr = parseInt(api.getAttribute(this.cell, 'rowspan'), 10) - 1,
+ crow = api.getParentElement(cell.el, { nodeName: ["TR"] }),
+ cType = cell.el.tagName.toLowerCase(),
+ cidx, temp_r_cells,
+ doc = this.table.ownerDocument,
+ nrow;
+
+ for (var i = 0; i < addRowsNr; i++) {
+ cidx = this.correctColIndexForUnreals(this.idx.col, (ridx + i));
+ crow = nextNode(crow, 'tr');
+ if (crow) {
+ if (cidx > 0) {
+ switch (where) {
+ case "before":
+ temp_r_cells = this.getRowCells(crow);
+ if (cidx > 0 && this.map[ridx + i][this.idx.col].el != temp_r_cells[cidx] && cidx == temp_r_cells.length - 1) {
+ insertAfter(temp_r_cells[cidx], this.createCells(cType, 1));
+ } else {
+ temp_r_cells[cidx].parentNode.insertBefore(this.createCells(cType, 1), temp_r_cells[cidx]);
+ }
+
+ break;
+ case "after":
+ insertAfter(this.getRowCells(crow)[cidx], this.createCells(cType, 1));
+ break;
+ }
+ } else {
+ crow.insertBefore(this.createCells(cType, 1), crow.firstChild);
+ }
+ } else {
+ nrow = doc.createElement('tr');
+ nrow.appendChild(this.createCells(cType, 1));
+ this.table.appendChild(nrow);
+ }
+ }
+ }
+ };
+
+ api.table = {
+ getCellsBetween: function(cell1, cell2) {
+ var c1 = new TableModifyerByCell(cell1);
+ return c1.getMapElsTo(cell2);
+ },
+
+ addCells: function(cell, where) {
+ var c = new TableModifyerByCell(cell);
+ c.add(where);
+ },
+
+ removeCells: function(cell, what) {
+ var c = new TableModifyerByCell(cell);
+ c.remove(what);
+ },
+
+ mergeCellsBetween: function(cell1, cell2) {
+ var c1 = new TableModifyerByCell(cell1);
+ c1.merge(cell2);
+ },
+
+ unmergeCell: function(cell) {
+ var c = new TableModifyerByCell(cell);
+ c.unmerge();
+ },
+
+ orderSelectionEnds: function(cell, cell2) {
+ var c = new TableModifyerByCell(cell);
+ return c.orderSelectionEnds(cell2);
+ },
+
+ indexOf: function(cell) {
+ var c = new TableModifyerByCell(cell);
+ c.setTableMap();
+ return c.getMapIndex(cell);
+ },
+
+ findCell: function(table, idx) {
+ var c = new TableModifyerByCell(null, table);
+ return c.getElementAtIndex(idx);
+ },
+
+ findRowByCell: function(cell) {
+ var c = new TableModifyerByCell(cell);
+ return c.getRowElementsByCell();
+ },
+
+ findColumnByCell: function(cell) {
+ var c = new TableModifyerByCell(cell);
+ return c.getColumnElementsByCell();
+ },
+
+ canMerge: function(cell1, cell2) {
+ var c = new TableModifyerByCell(cell1);
+ return c.canMerge(cell2);
+ }
+ };
+
+
+
+})(wysihtml5);
+;// does a selector query on element or array of elements
+
+wysihtml5.dom.query = function(elements, query) {
+ var ret = [],
+ q;
+
+ if (elements.nodeType) {
+ elements = [elements];
+ }
+
+ for (var e = 0, len = elements.length; e < len; e++) {
+ q = elements[e].querySelectorAll(query);
+ if (q) {
+ for(var i = q.length; i--; ret.unshift(q[i]));
+ }
+ }
+ return ret;
+};
+;wysihtml5.dom.compareDocumentPosition = (function() {
+ var documentElement = document.documentElement;
+ if (documentElement.compareDocumentPosition) {
+ return function(container, element) {
+ return container.compareDocumentPosition(element);
+ };
+ } else {
+ return function( container, element ) {
+ // implementation borrowed from https://github.com/tmpvar/jsdom/blob/681a8524b663281a0f58348c6129c8c184efc62c/lib/jsdom/level3/core.js // MIT license
+ var thisOwner, otherOwner;
+
+ if( container.nodeType === 9) // Node.DOCUMENT_NODE
+ thisOwner = container;
+ else
+ thisOwner = container.ownerDocument;
+
+ if( element.nodeType === 9) // Node.DOCUMENT_NODE
+ otherOwner = element;
+ else
+ otherOwner = element.ownerDocument;
+
+ if( container === element ) return 0;
+ if( container === element.ownerDocument ) return 4 + 16; //Node.DOCUMENT_POSITION_FOLLOWING + Node.DOCUMENT_POSITION_CONTAINED_BY;
+ if( container.ownerDocument === element ) return 2 + 8; //Node.DOCUMENT_POSITION_PRECEDING + Node.DOCUMENT_POSITION_CONTAINS;
+ if( thisOwner !== otherOwner ) return 1; // Node.DOCUMENT_POSITION_DISCONNECTED;
+
+ // Text nodes for attributes does not have a _parentNode. So we need to find them as attribute child.
+ if( container.nodeType === 2 /*Node.ATTRIBUTE_NODE*/ && container.childNodes && wysihtml5.lang.array(container.childNodes).indexOf( element ) !== -1)
+ return 4 + 16; //Node.DOCUMENT_POSITION_FOLLOWING + Node.DOCUMENT_POSITION_CONTAINED_BY;
+
+ if( element.nodeType === 2 /*Node.ATTRIBUTE_NODE*/ && element.childNodes && wysihtml5.lang.array(element.childNodes).indexOf( container ) !== -1)
+ return 2 + 8; //Node.DOCUMENT_POSITION_PRECEDING + Node.DOCUMENT_POSITION_CONTAINS;
+
+ var point = container;
+ var parents = [ ];
+ var previous = null;
+ while( point ) {
+ if( point == element ) return 2 + 8; //Node.DOCUMENT_POSITION_PRECEDING + Node.DOCUMENT_POSITION_CONTAINS;
+ parents.push( point );
+ point = point.parentNode;
+ }
+ point = element;
+ previous = null;
+ while( point ) {
+ if( point == container ) return 4 + 16; //Node.DOCUMENT_POSITION_FOLLOWING + Node.DOCUMENT_POSITION_CONTAINED_BY;
+ var location_index = wysihtml5.lang.array(parents).indexOf( point );
+ if( location_index !== -1) {
+ var smallest_common_ancestor = parents[ location_index ];
+ var this_index = wysihtml5.lang.array(smallest_common_ancestor.childNodes).indexOf( parents[location_index - 1]);//smallest_common_ancestor.childNodes.toArray().indexOf( parents[location_index - 1] );
+ var other_index = wysihtml5.lang.array(smallest_common_ancestor.childNodes).indexOf( previous ); //smallest_common_ancestor.childNodes.toArray().indexOf( previous );
+ if( this_index > other_index ) {
+ return 2; //Node.DOCUMENT_POSITION_PRECEDING;
+ }
+ else {
+ return 4; //Node.DOCUMENT_POSITION_FOLLOWING;
+ }
+ }
+ previous = point;
+ point = point.parentNode;
+ }
+ return 1; //Node.DOCUMENT_POSITION_DISCONNECTED;
+ };
+ }
+})();
+;wysihtml5.dom.unwrap = function(node) {
+ if (node.parentNode) {
+ while (node.lastChild) {
+ wysihtml5.dom.insert(node.lastChild).after(node);
+ }
+ node.parentNode.removeChild(node);
+ }
+};;/*
+ * Methods for fetching pasted html before it gets inserted into content
+**/
+
+/* Modern event.clipboardData driven approach.
+ * Advantage is that it does not have to loose selection or modify dom to catch the data.
+ * IE does not support though.
+**/
+wysihtml5.dom.getPastedHtml = function(event) {
+ var html;
+ if (event.clipboardData) {
+ if (wysihtml5.lang.array(event.clipboardData.types).contains('text/html')) {
+ html = event.clipboardData.getData('text/html');
+ } else if (wysihtml5.lang.array(event.clipboardData.types).contains('text/plain')) {
+ html = wysihtml5.lang.string(event.clipboardData.getData('text/plain')).escapeHTML(true, true);
+ }
+ }
+ return html;
+};
+
+/* Older temprorary contenteditable as paste source catcher method for fallbacks */
+wysihtml5.dom.getPastedHtmlWithDiv = function (composer, f) {
+ var selBookmark = composer.selection.getBookmark(),
+ doc = composer.element.ownerDocument,
+ cleanerDiv = doc.createElement('DIV');
+
+ doc.body.appendChild(cleanerDiv);
+
+ cleanerDiv.style.width = "1px";
+ cleanerDiv.style.height = "1px";
+ cleanerDiv.style.overflow = "hidden";
+
+ cleanerDiv.setAttribute('contenteditable', 'true');
+ cleanerDiv.focus();
+
+ setTimeout(function () {
+ composer.selection.setBookmark(selBookmark);
+ f(cleanerDiv.innerHTML);
+ cleanerDiv.parentNode.removeChild(cleanerDiv);
+ }, 0);
+};;/**
+ * Fix most common html formatting misbehaviors of browsers implementation when inserting
+ * content via copy & paste contentEditable
+ *
+ * @author Christopher Blum
+ */
+wysihtml5.quirks.cleanPastedHTML = (function() {
+
+ var styleToRegex = function (styleStr) {
+ var trimmedStr = wysihtml5.lang.string(styleStr).trim(),
+ escapedStr = trimmedStr.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
+
+ return new RegExp("^((?!^" + escapedStr + "$).)*$", "i");
+ };
+
+ var extendRulesWithStyleExceptions = function (rules, exceptStyles) {
+ var newRules = wysihtml5.lang.object(rules).clone(true),
+ tag, style;
+
+ for (tag in newRules.tags) {
+
+ if (newRules.tags.hasOwnProperty(tag)) {
+ if (newRules.tags[tag].keep_styles) {
+ for (style in newRules.tags[tag].keep_styles) {
+ if (newRules.tags[tag].keep_styles.hasOwnProperty(style)) {
+ if (exceptStyles[style]) {
+ newRules.tags[tag].keep_styles[style] = styleToRegex(exceptStyles[style]);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return newRules;
+ };
+
+ var pickRuleset = function(ruleset, html) {
+ var pickedSet, defaultSet;
+
+ if (!ruleset) {
+ return null;
+ }
+
+ for (var i = 0, max = ruleset.length; i < max; i++) {
+ if (!ruleset[i].condition) {
+ defaultSet = ruleset[i].set;
+ }
+ if (ruleset[i].condition && ruleset[i].condition.test(html)) {
+ return ruleset[i].set;
+ }
+ }
+
+ return defaultSet;
+ };
+
+ return function(html, options) {
+ var exceptStyles = {
+ 'color': wysihtml5.dom.getStyle("color").from(options.referenceNode),
+ 'fontSize': wysihtml5.dom.getStyle("font-size").from(options.referenceNode)
+ },
+ rules = extendRulesWithStyleExceptions(pickRuleset(options.rules, html) || {}, exceptStyles),
+ newHtml;
+
+ newHtml = wysihtml5.dom.parse(html, {
+ "rules": rules,
+ "cleanUp": true, // <span> elements, empty or without attributes, should be removed/replaced with their content
+ "context": options.referenceNode.ownerDocument,
+ "uneditableClass": options.uneditableClass,
+ "clearInternals" : true, // don't paste temprorary selection and other markings
+ "unjoinNbsps" : true
+ });
+
+ return newHtml;
+ };
+
+})();;/**
+ * IE and Opera leave an empty paragraph in the contentEditable element after clearing it
+ *
+ * @param {Object} contentEditableElement The contentEditable element to observe for clearing events
+ * @exaple
+ * wysihtml5.quirks.ensureProperClearing(myContentEditableElement);
+ */
+wysihtml5.quirks.ensureProperClearing = (function() {
+ var clearIfNecessary = function() {
+ var element = this;
+ setTimeout(function() {
+ var innerHTML = element.innerHTML.toLowerCase();
+ if (innerHTML == "<p> </p>" ||
+ innerHTML == "<p> </p><p> </p>") {
+ element.innerHTML = "";
+ }
+ }, 0);
+ };
+
+ return function(composer) {
+ wysihtml5.dom.observe(composer.element, ["cut", "keydown"], clearIfNecessary);
+ };
+})();
+;// See https://bugzilla.mozilla.org/show_bug.cgi?id=664398
+//
+// In Firefox this:
+// var d = document.createElement("div");
+// d.innerHTML ='<a href="~"></a>';
+// d.innerHTML;
+// will result in:
+// <a href="%7E"></a>
+// which is wrong
+(function(wysihtml5) {
+ var TILDE_ESCAPED = "%7E";
+ wysihtml5.quirks.getCorrectInnerHTML = function(element) {
+ var innerHTML = element.innerHTML;
+ if (innerHTML.indexOf(TILDE_ESCAPED) === -1) {
+ return innerHTML;
+ }
+
+ var elementsWithTilde = element.querySelectorAll("[href*='~'], [src*='~']"),
+ url,
+ urlToSearch,
+ length,
+ i;
+ for (i=0, length=elementsWithTilde.length; i<length; i++) {
+ url = elementsWithTilde[i].href || elementsWithTilde[i].src;
+ urlToSearch = wysihtml5.lang.string(url).replace("~").by(TILDE_ESCAPED);
+ innerHTML = wysihtml5.lang.string(innerHTML).replace(urlToSearch).by(url);
+ }
+ return innerHTML;
+ };
+})(wysihtml5);
+;/**
+ * Force rerendering of a given element
+ * Needed to fix display misbehaviors of IE
+ *
+ * @param {Element} element The element object which needs to be rerendered
+ * @example
+ * wysihtml5.quirks.redraw(document.body);
+ */
+(function(wysihtml5) {
+ var CLASS_NAME = "wysihtml5-quirks-redraw";
+
+ wysihtml5.quirks.redraw = function(element) {
+ wysihtml5.dom.addClass(element, CLASS_NAME);
+ wysihtml5.dom.removeClass(element, CLASS_NAME);
+
+ // Following hack is needed for firefox to make sure that image resize handles are properly removed
+ try {
+ var doc = element.ownerDocument;
+ doc.execCommand("italic", false, null);
+ doc.execCommand("italic", false, null);
+ } catch(e) {}
+ };
+})(wysihtml5);
+;wysihtml5.quirks.tableCellsSelection = function(editable, editor) {
+
+ var dom = wysihtml5.dom,
+ select = {
+ table: null,
+ start: null,
+ end: null,
+ cells: null,
+ select: selectCells
+ },
+ selection_class = "wysiwyg-tmp-selected-cell",
+ moveHandler = null,
+ upHandler = null;
+
+ function init () {
+
+ dom.observe(editable, "mousedown", function(event) {
+ var target = wysihtml5.dom.getParentElement(event.target, { nodeName: ["TD", "TH"] });
+ if (target) {
+ handleSelectionMousedown(target);
+ }
+ });
+
+ return select;
+ }
+
+ function handleSelectionMousedown (target) {
+ select.start = target;
+ select.end = target;
+ select.cells = [target];
+ select.table = dom.getParentElement(select.start, { nodeName: ["TABLE"] });
+
+ if (select.table) {
+ removeCellSelections();
+ dom.addClass(target, selection_class);
+ moveHandler = dom.observe(editable, "mousemove", handleMouseMove);
+ upHandler = dom.observe(editable, "mouseup", handleMouseUp);
+ editor.fire("tableselectstart").fire("tableselectstart:composer");
+ }
+ }
+
+ // remove all selection classes
+ function removeCellSelections () {
+ if (editable) {
+ var selectedCells = editable.querySelectorAll('.' + selection_class);
+ if (selectedCells.length > 0) {
+ for (var i = 0; i < selectedCells.length; i++) {
+ dom.removeClass(selectedCells[i], selection_class);
+ }
+ }
+ }
+ }
+
+ function addSelections (cells) {
+ for (var i = 0; i < cells.length; i++) {
+ dom.addClass(cells[i], selection_class);
+ }
+ }
+
+ function handleMouseMove (event) {
+ var curTable = null,
+ cell = dom.getParentElement(event.target, { nodeName: ["TD","TH"] }),
+ oldEnd;
+
+ if (cell && select.table && select.start) {
+ curTable = dom.getParentElement(cell, { nodeName: ["TABLE"] });
+ if (curTable && curTable === select.table) {
+ removeCellSelections();
+ oldEnd = select.end;
+ select.end = cell;
+ select.cells = dom.table.getCellsBetween(select.start, cell);
+ if (select.cells.length > 1) {
+ editor.composer.selection.deselect();
+ }
+ addSelections(select.cells);
+ if (select.end !== oldEnd) {
+ editor.fire("tableselectchange").fire("tableselectchange:composer");
+ }
+ }
+ }
+ }
+
+ function handleMouseUp (event) {
+ moveHandler.stop();
+ upHandler.stop();
+ editor.fire("tableselect").fire("tableselect:composer");
+ setTimeout(function() {
+ bindSideclick();
+ },0);
+ }
+
+ function bindSideclick () {
+ var sideClickHandler = dom.observe(editable.ownerDocument, "click", function(event) {
+ sideClickHandler.stop();
+ if (dom.getParentElement(event.target, { nodeName: ["TABLE"] }) != select.table) {
+ removeCellSelections();
+ select.table = null;
+ select.start = null;
+ select.end = null;
+ editor.fire("tableunselect").fire("tableunselect:composer");
+ }
+ });
+ }
+
+ function selectCells (start, end) {
+ select.start = start;
+ select.end = end;
+ select.table = dom.getParentElement(select.start, { nodeName: ["TABLE"] });
+ selectedCells = dom.table.getCellsBetween(select.start, select.end);
+ addSelections(selectedCells);
+ bindSideclick();
+ editor.fire("tableselect").fire("tableselect:composer");
+ }
+
+ return init();
+
+};
+;(function(wysihtml5) {
+ var RGBA_REGEX = /^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*([\d\.]+)\s*\)/i,
+ RGB_REGEX = /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/i,
+ HEX6_REGEX = /^#([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])/i,
+ HEX3_REGEX = /^#([0-9a-f])([0-9a-f])([0-9a-f])/i;
+
+ var param_REGX = function (p) {
+ return new RegExp("(^|\\s|;)" + p + "\\s*:\\s*[^;$]+" , "gi");
+ };
+
+ wysihtml5.quirks.styleParser = {
+
+ parseColor: function(stylesStr, paramName) {
+ var paramRegex = param_REGX(paramName),
+ params = stylesStr.match(paramRegex),
+ radix = 10,
+ str, colorMatch;
+
+ if (params) {
+ for (var i = params.length; i--;) {
+ params[i] = wysihtml5.lang.string(params[i].split(':')[1]).trim();
+ }
+ str = params[params.length-1];
+
+ if (RGBA_REGEX.test(str)) {
+ colorMatch = str.match(RGBA_REGEX);
+ } else if (RGB_REGEX.test(str)) {
+ colorMatch = str.match(RGB_REGEX);
+ } else if (HEX6_REGEX.test(str)) {
+ colorMatch = str.match(HEX6_REGEX);
+ radix = 16;
+ } else if (HEX3_REGEX.test(str)) {
+ colorMatch = str.match(HEX3_REGEX);
+ colorMatch.shift();
+ colorMatch.push(1);
+ return wysihtml5.lang.array(colorMatch).map(function(d, idx) {
+ return (idx < 3) ? (parseInt(d, 16) * 16) + parseInt(d, 16): parseFloat(d);
+ });
+ }
+
+ if (colorMatch) {
+ colorMatch.shift();
+ if (!colorMatch[3]) {
+ colorMatch.push(1);
+ }
+ return wysihtml5.lang.array(colorMatch).map(function(d, idx) {
+ return (idx < 3) ? parseInt(d, radix): parseFloat(d);
+ });
+ }
+ }
+ return false;
+ },
+
+ unparseColor: function(val, props) {
+ if (props) {
+ if (props == "hex") {
+ return (val[0].toString(16).toUpperCase()) + (val[1].toString(16).toUpperCase()) + (val[2].toString(16).toUpperCase());
+ } else if (props == "hash") {
+ return "#" + (val[0].toString(16).toUpperCase()) + (val[1].toString(16).toUpperCase()) + (val[2].toString(16).toUpperCase());
+ } else if (props == "rgb") {
+ return "rgb(" + val[0] + "," + val[1] + "," + val[2] + ")";
+ } else if (props == "rgba") {
+ return "rgba(" + val[0] + "," + val[1] + "," + val[2] + "," + val[3] + ")";
+ } else if (props == "csv") {
+ return val[0] + "," + val[1] + "," + val[2] + "," + val[3];
+ }
+ }
+
+ if (val[3] && val[3] !== 1) {
+ return "rgba(" + val[0] + "," + val[1] + "," + val[2] + "," + val[3] + ")";
+ } else {
+ return "rgb(" + val[0] + "," + val[1] + "," + val[2] + ")";
+ }
+ },
+
+ parseFontSize: function(stylesStr) {
+ var params = stylesStr.match(param_REGX('font-size'));
+ if (params) {
+ return wysihtml5.lang.string(params[params.length - 1].split(':')[1]).trim();
+ }
+ return false;
+ }
+ };
+
+})(wysihtml5);
+;/**
+ * Selection API
+ *
+ * @example
+ * var selection = new wysihtml5.Selection(editor);
+ */
+(function(wysihtml5) {
+ var dom = wysihtml5.dom;
+
+ function _getCumulativeOffsetTop(element) {
+ var top = 0;
+ if (element.parentNode) {
+ do {
+ top += element.offsetTop || 0;
+ element = element.offsetParent;
+ } while (element);
+ }
+ return top;
+ }
+
+ // Provides the depth of ``descendant`` relative to ``ancestor``
+ function getDepth(ancestor, descendant) {
+ var ret = 0;
+ while (descendant !== ancestor) {
+ ret++;
+ descendant = descendant.parentNode;
+ if (!descendant)
+ throw new Error("not a descendant of ancestor!");
+ }
+ return ret;
+ }
+
+ // Should fix the obtained ranges that cannot surrond contents normally to apply changes upon
+ // Being considerate to firefox that sets range start start out of span and end inside on doubleclick initiated selection
+ function expandRangeToSurround(range) {
+ if (range.canSurroundContents()) return;
+
+ var common = range.commonAncestorContainer,
+ start_depth = getDepth(common, range.startContainer),
+ end_depth = getDepth(common, range.endContainer);
+
+ while(!range.canSurroundContents()) {
+ // In the following branches, we cannot just decrement the depth variables because the setStartBefore/setEndAfter may move the start or end of the range more than one level relative to ``common``. So we need to recompute the depth.
+ if (start_depth > end_depth) {
+ range.setStartBefore(range.startContainer);
+ start_depth = getDepth(common, range.startContainer);
+ }
+ else {
+ range.setEndAfter(range.endContainer);
+ end_depth = getDepth(common, range.endContainer);
+ }
+ }
+ }
+
+ wysihtml5.Selection = Base.extend(
+ /** @scope wysihtml5.Selection.prototype */ {
+ constructor: function(editor, contain, unselectableClass) {
+ // Make sure that our external range library is initialized
+ window.rangy.init();
+
+ this.editor = editor;
+ this.composer = editor.composer;
+ this.doc = this.composer.doc;
+ this.contain = contain;
+ this.unselectableClass = unselectableClass || false;
+ },
+
+ /**
+ * Get the current selection as a bookmark to be able to later restore it
+ *
+ * @return {Object} An object that represents the current selection
+ */
+ getBookmark: function() {
+ var range = this.getRange();
+ if (range) expandRangeToSurround(range);
+ return range && range.cloneRange();
+ },
+
+ /**
+ * Restore a selection retrieved via wysihtml5.Selection.prototype.getBookmark
+ *
+ * @param {Object} bookmark An object that represents the current selection
+ */
+ setBookmark: function(bookmark) {
+ if (!bookmark) {
+ return;
+ }
+
+ this.setSelection(bookmark);
+ },
+
+ /**
+ * Set the caret in front of the given node
+ *
+ * @param {Object} node The element or text node where to position the caret in front of
+ * @example
+ * selection.setBefore(myElement);
+ */
+ setBefore: function(node) {
+ var range = rangy.createRange(this.doc);
+ range.setStartBefore(node);
+ range.setEndBefore(node);
+ return this.setSelection(range);
+ },
+
+ // Constructs a self removing whitespace (ain absolute positioned span) for placing selection caret when normal methods fail.
+ // Webkit has an issue with placing caret into places where there are no textnodes near by.
+ creteTemporaryCaretSpaceAfter: function (node) {
+ var caretPlaceholder = this.doc.createElement('span'),
+ caretPlaceholderText = this.doc.createTextNode(wysihtml5.INVISIBLE_SPACE),
+ placeholderRemover = (function(event) {
+ // Self-destructs the caret and keeps the text inserted into it by user
+ var lastChild;
+
+ this.contain.removeEventListener('mouseup', placeholderRemover);
+ this.contain.removeEventListener('keydown', keyDownHandler);
+ this.contain.removeEventListener('touchstart', placeholderRemover);
+ this.contain.removeEventListener('focus', placeholderRemover);
+ this.contain.removeEventListener('blur', placeholderRemover);
+ this.contain.removeEventListener('paste', delayedPlaceholderRemover);
+ this.contain.removeEventListener('drop', delayedPlaceholderRemover);
+ this.contain.removeEventListener('beforepaste', delayedPlaceholderRemover);
+
+ // If user inserted sth it is in the placeholder and sgould be unwrapped and stripped of invisible whitespace hack
+ // Otherwise the wrapper can just be removed
+ if (caretPlaceholder && caretPlaceholder.parentNode) {
+ caretPlaceholder.innerHTML = caretPlaceholder.innerHTML.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "");
+ if ((/[^\s]+/).test(caretPlaceholder.innerHTML)) {
+ lastChild = caretPlaceholder.lastChild;
+ wysihtml5.dom.unwrap(caretPlaceholder);
+ this.setAfter(lastChild);
+ } else {
+ caretPlaceholder.parentNode.removeChild(caretPlaceholder);
+ }
+
+ }
+ }).bind(this),
+ delayedPlaceholderRemover = function (event) {
+ if (caretPlaceholder && caretPlaceholder.parentNode) {
+ setTimeout(placeholderRemover, 0);
+ }
+ },
+ keyDownHandler = function(event) {
+ if (event.which !== 8 && event.which !== 91 && event.which !== 17 && (event.which !== 86 || (!event.ctrlKey && !event.metaKey))) {
+ placeholderRemover();
+ }
+ };
+
+ caretPlaceholder.style.position = 'absolute';
+ caretPlaceholder.style.display = 'block';
+ caretPlaceholder.style.minWidth = '1px';
+ caretPlaceholder.style.zIndex = '99999';
+ caretPlaceholder.appendChild(caretPlaceholderText);
+
+ node.parentNode.insertBefore(caretPlaceholder, node.nextSibling);
+ this.setBefore(caretPlaceholderText);
+
+ // Remove the caret fix on any of the following events (some are delayed as content change happens after event)
+ this.contain.addEventListener('mouseup', placeholderRemover);
+ this.contain.addEventListener('keydown', keyDownHandler);
+ this.contain.addEventListener('touchstart', placeholderRemover);
+ this.contain.addEventListener('focus', placeholderRemover);
+ this.contain.addEventListener('blur', placeholderRemover);
+ this.contain.addEventListener('paste', delayedPlaceholderRemover);
+ this.contain.addEventListener('drop', delayedPlaceholderRemover);
+ this.contain.addEventListener('beforepaste', delayedPlaceholderRemover);
+
+ return caretPlaceholder;
+ },
+
+ /**
+ * Set the caret after the given node
+ *
+ * @param {Object} node The element or text node where to position the caret in front of
+ * @example
+ * selection.setBefore(myElement);
+ */
+ setAfter: function(node) {
+ var range = rangy.createRange(this.doc),
+ originalScrollTop = this.doc.documentElement.scrollTop || this.doc.body.scrollTop || this.doc.defaultView.pageYOffset,
+ originalScrollLeft = this.doc.documentElement.scrollLeft || this.doc.body.scrollLeft || this.doc.defaultView.pageXOffset,
+ sel;
+
+ range.setStartAfter(node);
+ range.setEndAfter(node);
+ this.composer.element.focus();
+ this.doc.defaultView.scrollTo(originalScrollLeft, originalScrollTop);
+ sel = this.setSelection(range);
+
+ // Webkit fails to add selection if there are no textnodes in that region
+ // (like an uneditable container at the end of content).
+ if (!sel) {
+ this.creteTemporaryCaretSpaceAfter(node);
+ }
+ return sel;
+ },
+
+ /**
+ * Ability to select/mark nodes
+ *
+ * @param {Element} node The node/element to select
+ * @example
+ * selection.selectNode(document.getElementById("my-image"));
+ */
+ selectNode: function(node, avoidInvisibleSpace) {
+ var range = rangy.createRange(this.doc),
+ isElement = node.nodeType === wysihtml5.ELEMENT_NODE,
+ canHaveHTML = "canHaveHTML" in node ? node.canHaveHTML : (node.nodeName !== "IMG"),
+ content = isElement ? node.innerHTML : node.data,
+ isEmpty = (content === "" || content === wysihtml5.INVISIBLE_SPACE),
+ displayStyle = dom.getStyle("display").from(node),
+ isBlockElement = (displayStyle === "block" || displayStyle === "list-item");
+
+ if (isEmpty && isElement && canHaveHTML && !avoidInvisibleSpace) {
+ // Make sure that caret is visible in node by inserting a zero width no breaking space
+ try { node.innerHTML = wysihtml5.INVISIBLE_SPACE; } catch(e) {}
+ }
+
+ if (canHaveHTML) {
+ range.selectNodeContents(node);
+ } else {
+ range.selectNode(node);
+ }
+
+ if (canHaveHTML && isEmpty && isElement) {
+ range.collapse(isBlockElement);
+ } else if (canHaveHTML && isEmpty) {
+ range.setStartAfter(node);
+ range.setEndAfter(node);
+ }
+
+ this.setSelection(range);
+ },
+
+ /**
+ * Get the node which contains the selection
+ *
+ * @param {Boolean} [controlRange] (only IE) Whether it should return the selected ControlRange element when the selection type is a "ControlRange"
+ * @return {Object} The node that contains the caret
+ * @example
+ * var nodeThatContainsCaret = selection.getSelectedNode();
+ */
+ getSelectedNode: function(controlRange) {
+ var selection,
+ range;
+
+ if (controlRange && this.doc.selection && this.doc.selection.type === "Control") {
+ range = this.doc.selection.createRange();
+ if (range && range.length) {
+ return range.item(0);
+ }
+ }
+
+ selection = this.getSelection(this.doc);
+ if (selection.focusNode === selection.anchorNode) {
+ return selection.focusNode;
+ } else {
+ range = this.getRange(this.doc);
+ return range ? range.commonAncestorContainer : this.doc.body;
+ }
+ },
+
+ fixSelBorders: function() {
+ var range = this.getRange();
+ expandRangeToSurround(range);
+ this.setSelection(range);
+ },
+
+ getSelectedOwnNodes: function(controlRange) {
+ var selection,
+ ranges = this.getOwnRanges(),
+ ownNodes = [];
+
+ for (var i = 0, maxi = ranges.length; i < maxi; i++) {
+ ownNodes.push(ranges[i].commonAncestorContainer || this.doc.body);
+ }
+ return ownNodes;
+ },
+
+ findNodesInSelection: function(nodeTypes) {
+ var ranges = this.getOwnRanges(),
+ nodes = [], curNodes;
+ for (var i = 0, maxi = ranges.length; i < maxi; i++) {
+ curNodes = ranges[i].getNodes([1], function(node) {
+ return wysihtml5.lang.array(nodeTypes).contains(node.nodeName);
+ });
+ nodes = nodes.concat(curNodes);
+ }
+ return nodes;
+ },
+
+ containsUneditable: function() {
+ var uneditables = this.getOwnUneditables(),
+ selection = this.getSelection();
+
+ for (var i = 0, maxi = uneditables.length; i < maxi; i++) {
+ if (selection.containsNode(uneditables[i])) {
+ return true;
+ }
+ }
+
+ return false;
+ },
+
+ // Deletes selection contents making sure uneditables/unselectables are not partially deleted
+ // Triggers wysihtml5:uneditable:delete custom event on all deleted uneditables if customevents suppoorted
+ deleteContents: function() {
+ var range = this.getRange(),
+ startParent, endParent, uneditables, ev;
+
+ if (this.unselectableClass) {
+ if ((startParent = wysihtml5.dom.getParentElement(range.startContainer, { className: this.unselectableClass }, false, this.contain))) {
+ range.setStartBefore(startParent);
+ }
+ if ((endParent = wysihtml5.dom.getParentElement(range.endContainer, { className: this.unselectableClass }, false, this.contain))) {
+ range.setEndAfter(endParent);
+ }
+
+ // If customevents present notify uneditable elements of being deleted
+ uneditables = range.getNodes([1], (function (node) {
+ return wysihtml5.dom.hasClass(node, this.unselectableClass);
+ }).bind(this));
+ for (var i = uneditables.length; i--;) {
+ try {
+ ev = new CustomEvent("wysihtml5:uneditable:delete");
+ uneditables[i].dispatchEvent(ev);
+ } catch (err) {}
+ }
+
+ }
+ range.deleteContents();
+ this.setSelection(range);
+ },
+
+ getPreviousNode: function(node, ignoreEmpty) {
+ var displayStyle;
+ if (!node) {
+ var selection = this.getSelection();
+ node = selection.anchorNode;
+ }
+
+ if (node === this.contain) {
+ return false;
+ }
+
+ var ret = node.previousSibling,
+ parent;
+
+ if (ret === this.contain) {
+ return false;
+ }
+
+ if (ret && ret.nodeType !== 3 && ret.nodeType !== 1) {
+ // do not count comments and other node types
+ ret = this.getPreviousNode(ret, ignoreEmpty);
+ } else if (ret && ret.nodeType === 3 && (/^\s*$/).test(ret.textContent)) {
+ // do not count empty textnodes as previous nodes
+ ret = this.getPreviousNode(ret, ignoreEmpty);
+ } else if (ignoreEmpty && ret && ret.nodeType === 1) {
+ // Do not count empty nodes if param set.
+ // Contenteditable tends to bypass and delete these silently when deleting with caret when element is inline-like
+ displayStyle = wysihtml5.dom.getStyle("display").from(ret);
+ if (
+ !wysihtml5.lang.array(["BR", "HR", "IMG"]).contains(ret.nodeName) &&
+ !wysihtml5.lang.array(["block", "inline-block", "flex", "list-item", "table"]).contains(displayStyle) &&
+ (/^[\s]*$/).test(ret.innerHTML)
+ ) {
+ ret = this.getPreviousNode(ret, ignoreEmpty);
+ }
+ } else if (!ret && node !== this.contain) {
+ parent = node.parentNode;
+ if (parent !== this.contain) {
+ ret = this.getPreviousNode(parent, ignoreEmpty);
+ }
+ }
+
+ return (ret !== this.contain) ? ret : false;
+ },
+
+ getSelectionParentsByTag: function(tagName) {
+ var nodes = this.getSelectedOwnNodes(),
+ curEl, parents = [];
+
+ for (var i = 0, maxi = nodes.length; i < maxi; i++) {
+ curEl = (nodes[i].nodeName && nodes[i].nodeName === 'LI') ? nodes[i] : wysihtml5.dom.getParentElement(nodes[i], { nodeName: ['LI']}, false, this.contain);
+ if (curEl) {
+ parents.push(curEl);
+ }
+ }
+ return (parents.length) ? parents : null;
+ },
+
+ getRangeToNodeEnd: function() {
+ if (this.isCollapsed()) {
+ var range = this.getRange(),
+ sNode = range.startContainer,
+ pos = range.startOffset,
+ lastR = rangy.createRange(this.doc);
+
+ lastR.selectNodeContents(sNode);
+ lastR.setStart(sNode, pos);
+ return lastR;
+ }
+ },
+
+ caretIsLastInSelection: function() {
+ var r = rangy.createRange(this.doc),
+ s = this.getSelection(),
+ endc = this.getRangeToNodeEnd().cloneContents(),
+ endtxt = endc.textContent;
+
+ return (/^\s*$/).test(endtxt);
+ },
+
+ caretIsFirstInSelection: function() {
+ var r = rangy.createRange(this.doc),
+ s = this.getSelection(),
+ range = this.getRange(),
+ startNode = range.startContainer;
+
+ if (startNode) {
+ if (startNode.nodeType === wysihtml5.TEXT_NODE) {
+ return this.isCollapsed() && (startNode.nodeType === wysihtml5.TEXT_NODE && (/^\s*$/).test(startNode.data.substr(0,range.startOffset)));
+ } else {
+ r.selectNodeContents(this.getRange().commonAncestorContainer);
+ r.collapse(true);
+ return (this.isCollapsed() && (r.startContainer === s.anchorNode || r.endContainer === s.anchorNode) && r.startOffset === s.anchorOffset);
+ }
+ }
+ },
+
+ caretIsInTheBeginnig: function(ofNode) {
+ var selection = this.getSelection(),
+ node = selection.anchorNode,
+ offset = selection.anchorOffset;
+ if (ofNode && node) {
+ return (offset === 0 && (node.nodeName && node.nodeName === ofNode.toUpperCase() || wysihtml5.dom.getParentElement(node.parentNode, { nodeName: ofNode }, 1)));
+ } else if (node) {
+ return (offset === 0 && !this.getPreviousNode(node, true));
+ }
+ },
+
+ caretIsBeforeUneditable: function() {
+ var selection = this.getSelection(),
+ node = selection.anchorNode,
+ offset = selection.anchorOffset,
+ childNodes = [],
+ range, contentNodes, lastNode;
+
+ if (node) {
+ if (offset === 0) {
+ var prevNode = this.getPreviousNode(node, true),
+ prevLeaf = prevNode ? wysihtml5.dom.domNode(prevNode).lastLeafNode((this.unselectableClass) ? {leafClasses: [this.unselectableClass]} : false) : null;
+ if (prevLeaf) {
+ var uneditables = this.getOwnUneditables();
+ for (var i = 0, maxi = uneditables.length; i < maxi; i++) {
+ if (prevLeaf === uneditables[i]) {
+ return uneditables[i];
+ }
+ }
+ }
+ } else {
+ range = selection.getRangeAt(0);
+ range.setStart(range.startContainer, range.startOffset - 1);
+ // TODO: make getting children on range a separate funtion
+ if (range) {
+ contentNodes = range.getNodes([1,3]);
+ for (var n = 0, max = contentNodes.length; n < max; n++) {
+ if (contentNodes[n].parentNode && contentNodes[n].parentNode === node) {
+ childNodes.push(contentNodes[n]);
+ }
+ }
+ }
+ lastNode = childNodes.length > 0 ? childNodes[childNodes.length -1] : null;
+ if (lastNode && lastNode.nodeType === 1 && wysihtml5.dom.hasClass(lastNode, this.unselectableClass)) {
+ return lastNode;
+ }
+
+ }
+ }
+ return false;
+ },
+
+ // TODO: Figure out a method from following 2 that would work universally
+ executeAndRestoreRangy: function(method, restoreScrollPosition) {
+ var win = this.doc.defaultView || this.doc.parentWindow,
+ sel = rangy.saveSelection(win);
+
+ if (!sel) {
+ method();
+ } else {
+ try {
+ method();
+ } catch(e) {
+ setTimeout(function() { throw e; }, 0);
+ }
+ }
+ rangy.restoreSelection(sel);
+ },
+
+ // TODO: has problems in chrome 12. investigate block level and uneditable area inbetween
+ executeAndRestore: function(method, restoreScrollPosition) {
+ var body = this.doc.body,
+ oldScrollTop = restoreScrollPosition && body.scrollTop,
+ oldScrollLeft = restoreScrollPosition && body.scrollLeft,
+ className = "_wysihtml5-temp-placeholder",
+ placeholderHtml = '<span class="' + className + '">' + wysihtml5.INVISIBLE_SPACE + '</span>',
+ range = this.getRange(true),
+ caretPlaceholder,
+ newCaretPlaceholder,
+ nextSibling, prevSibling,
+ node, node2, range2,
+ newRange;
+
+ // Nothing selected, execute and say goodbye
+ if (!range) {
+ method(body, body);
+ return;
+ }
+
+ if (!range.collapsed) {
+ range2 = range.cloneRange();
+ node2 = range2.createContextualFragment(placeholderHtml);
+ range2.collapse(false);
+ range2.insertNode(node2);
+ range2.detach();
+ }
+
+ node = range.createContextualFragment(placeholderHtml);
+ range.insertNode(node);
+
+ if (node2) {
+ caretPlaceholder = this.contain.querySelectorAll("." + className);
+ range.setStartBefore(caretPlaceholder[0]);
+ range.setEndAfter(caretPlaceholder[caretPlaceholder.length -1]);
+ }
+ this.setSelection(range);
+
+ // Make sure that a potential error doesn't cause our placeholder element to be left as a placeholder
+ try {
+ method(range.startContainer, range.endContainer);
+ } catch(e) {
+ setTimeout(function() { throw e; }, 0);
+ }
+ caretPlaceholder = this.contain.querySelectorAll("." + className);
+ if (caretPlaceholder && caretPlaceholder.length) {
+ newRange = rangy.createRange(this.doc);
+ nextSibling = caretPlaceholder[0].nextSibling;
+ if (caretPlaceholder.length > 1) {
+ prevSibling = caretPlaceholder[caretPlaceholder.length -1].previousSibling;
+ }
+ if (prevSibling && nextSibling) {
+ newRange.setStartBefore(nextSibling);
+ newRange.setEndAfter(prevSibling);
+ } else {
+ newCaretPlaceholder = this.doc.createTextNode(wysihtml5.INVISIBLE_SPACE);
+ dom.insert(newCaretPlaceholder).after(caretPlaceholder[0]);
+ newRange.setStartBefore(newCaretPlaceholder);
+ newRange.setEndAfter(newCaretPlaceholder);
+ }
+ this.setSelection(newRange);
+ for (var i = caretPlaceholder.length; i--;) {
+ caretPlaceholder[i].parentNode.removeChild(caretPlaceholder[i]);
+ }
+
+ } else {
+ // fallback for when all hell breaks loose
+ this.contain.focus();
+ }
+
+ if (restoreScrollPosition) {
+ body.scrollTop = oldScrollTop;
+ body.scrollLeft = oldScrollLeft;
+ }
+
+ // Remove it again, just to make sure that the placeholder is definitely out of the dom tree
+ try {
+ caretPlaceholder.parentNode.removeChild(caretPlaceholder);
+ } catch(e2) {}
+ },
+
+ set: function(node, offset) {
+ var newRange = rangy.createRange(this.doc);
+ newRange.setStart(node, offset || 0);
+ this.setSelection(newRange);
+ },
+
+ /**
+ * Insert html at the caret position and move the cursor after the inserted html
+ *
+ * @param {String} html HTML string to insert
+ * @example
+ * selection.insertHTML("<p>foobar</p>");
+ */
+ insertHTML: function(html) {
+ var range = rangy.createRange(this.doc),
+ node = this.doc.createElement('DIV'),
+ fragment = this.doc.createDocumentFragment(),
+ lastChild;
+
+ node.innerHTML = html;
+ lastChild = node.lastChild;
+
+ while (node.firstChild) {
+ fragment.appendChild(node.firstChild);
+ }
+ this.insertNode(fragment);
+
+ if (lastChild) {
+ this.setAfter(lastChild);
+ }
+ },
+
+ /**
+ * Insert a node at the caret position and move the cursor behind it
+ *
+ * @param {Object} node HTML string to insert
+ * @example
+ * selection.insertNode(document.createTextNode("foobar"));
+ */
+ insertNode: function(node) {
+ var range = this.getRange();
+ if (range) {
+ range.insertNode(node);
+ }
+ },
+
+ /**
+ * Wraps current selection with the given node
+ *
+ * @param {Object} node The node to surround the selected elements with
+ */
+ surround: function(nodeOptions) {
+ var ranges = this.getOwnRanges(),
+ node, nodes = [];
+ if (ranges.length == 0) {
+ return nodes;
+ }
+
+ for (var i = ranges.length; i--;) {
+ node = this.doc.createElement(nodeOptions.nodeName);
+ nodes.push(node);
+ if (nodeOptions.className) {
+ node.className = nodeOptions.className;
+ }
+ if (nodeOptions.cssStyle) {
+ node.setAttribute('style', nodeOptions.cssStyle);
+ }
+ try {
+ // This only works when the range boundaries are not overlapping other elements
+ ranges[i].surroundContents(node);
+ this.selectNode(node);
+ } catch(e) {
+ // fallback
+ node.appendChild(ranges[i].extractContents());
+ ranges[i].insertNode(node);
+ }
+ }
+ return nodes;
+ },
+
+ deblockAndSurround: function(nodeOptions) {
+ var tempElement = this.doc.createElement('div'),
+ range = rangy.createRange(this.doc),
+ tempDivElements,
+ tempElements,
+ firstChild;
+
+ tempElement.className = nodeOptions.className;
+
+ this.composer.commands.exec("formatBlock", nodeOptions.nodeName, nodeOptions.className);
+ tempDivElements = this.contain.querySelectorAll("." + nodeOptions.className);
+ if (tempDivElements[0]) {
+ tempDivElements[0].parentNode.insertBefore(tempElement, tempDivElements[0]);
+
+ range.setStartBefore(tempDivElements[0]);
+ range.setEndAfter(tempDivElements[tempDivElements.length - 1]);
+ tempElements = range.extractContents();
+
+ while (tempElements.firstChild) {
+ firstChild = tempElements.firstChild;
+ if (firstChild.nodeType == 1 && wysihtml5.dom.hasClass(firstChild, nodeOptions.className)) {
+ while (firstChild.firstChild) {
+ tempElement.appendChild(firstChild.firstChild);
+ }
+ if (firstChild.nodeName !== "BR") { tempElement.appendChild(this.doc.createElement('br')); }
+ tempElements.removeChild(firstChild);
+ } else {
+ tempElement.appendChild(firstChild);
+ }
+ }
+ } else {
+ tempElement = null;
+ }
+
+ return tempElement;
+ },
+
+ /**
+ * Scroll the current caret position into the view
+ * FIXME: This is a bit hacky, there might be a smarter way of doing this
+ *
+ * @example
+ * selection.scrollIntoView();
+ */
+ scrollIntoView: function() {
+ var doc = this.doc,
+ tolerance = 5, // px
+ hasScrollBars = doc.documentElement.scrollHeight > doc.documentElement.offsetHeight,
+ tempElement = doc._wysihtml5ScrollIntoViewElement = doc._wysihtml5ScrollIntoViewElement || (function() {
+ var element = doc.createElement("span");
+ // The element needs content in order to be able to calculate it's position properly
+ element.innerHTML = wysihtml5.INVISIBLE_SPACE;
+ return element;
+ })(),
+ offsetTop;
+
+ if (hasScrollBars) {
+ this.insertNode(tempElement);
+ offsetTop = _getCumulativeOffsetTop(tempElement);
+ tempElement.parentNode.removeChild(tempElement);
+ if (offsetTop >= (doc.body.scrollTop + doc.documentElement.offsetHeight - tolerance)) {
+ doc.body.scrollTop = offsetTop;
+ }
+ }
+ },
+
+ /**
+ * Select line where the caret is in
+ */
+ selectLine: function() {
+ if (wysihtml5.browser.supportsSelectionModify()) {
+ this._selectLine_W3C();
+ } else if (this.doc.selection) {
+ this._selectLine_MSIE();
+ }
+ },
+
+ /**
+ * See https://developer.mozilla.org/en/DOM/Selection/modify
+ */
+ _selectLine_W3C: function() {
+ var win = this.doc.defaultView,
+ selection = win.getSelection();
+ selection.modify("move", "left", "lineboundary");
+ selection.modify("extend", "right", "lineboundary");
+ },
+
+ // collapses selection to current line beginning or end
+ toLineBoundary: function (location, collapse) {
+ collapse = (typeof collapse === 'undefined') ? false : collapse;
+ if (wysihtml5.browser.supportsSelectionModify()) {
+ var win = this.doc.defaultView,
+ selection = win.getSelection();
+
+ selection.modify("extend", location, "lineboundary");
+ if (collapse) {
+ if (location === "left") {
+ selection.collapseToStart();
+ } else if (location === "right") {
+ selection.collapseToEnd();
+ }
+ }
+ }
+ },
+
+ _selectLine_MSIE: function() {
+ var range = this.doc.selection.createRange(),
+ rangeTop = range.boundingTop,
+ scrollWidth = this.doc.body.scrollWidth,
+ rangeBottom,
+ rangeEnd,
+ measureNode,
+ i,
+ j;
+
+ if (!range.moveToPoint) {
+ return;
+ }
+
+ if (rangeTop === 0) {
+ // Don't know why, but when the selection ends at the end of a line
+ // range.boundingTop is 0
+ measureNode = this.doc.createElement("span");
+ this.insertNode(measureNode);
+ rangeTop = measureNode.offsetTop;
+ measureNode.parentNode.removeChild(measureNode);
+ }
+
+ rangeTop += 1;
+
+ for (i=-10; i<scrollWidth; i+=2) {
+ try {
+ range.moveToPoint(i, rangeTop);
+ break;
+ } catch(e1) {}
+ }
+
+ // Investigate the following in order to handle multi line selections
+ // rangeBottom = rangeTop + (rangeHeight ? (rangeHeight - 1) : 0);
+ rangeBottom = rangeTop;
+ rangeEnd = this.doc.selection.createRange();
+ for (j=scrollWidth; j>=0; j--) {
+ try {
+ rangeEnd.moveToPoint(j, rangeBottom);
+ break;
+ } catch(e2) {}
+ }
+
+ range.setEndPoint("EndToEnd", rangeEnd);
+ range.select();
+ },
+
+ getText: function() {
+ var selection = this.getSelection();
+ return selection ? selection.toString() : "";
+ },
+
+ getNodes: function(nodeType, filter) {
+ var range = this.getRange();
+ if (range) {
+ return range.getNodes([nodeType], filter);
+ } else {
+ return [];
+ }
+ },
+
+ fixRangeOverflow: function(range) {
+ if (this.contain && this.contain.firstChild && range) {
+ var containment = range.compareNode(this.contain);
+ if (containment !== 2) {
+ if (containment === 1) {
+ range.setStartBefore(this.contain.firstChild);
+ }
+ if (containment === 0) {
+ range.setEndAfter(this.contain.lastChild);
+ }
+ if (containment === 3) {
+ range.setStartBefore(this.contain.firstChild);
+ range.setEndAfter(this.contain.lastChild);
+ }
+ } else if (this._detectInlineRangeProblems(range)) {
+ var previousElementSibling = range.endContainer.previousElementSibling;
+ if (previousElementSibling) {
+ range.setEnd(previousElementSibling, this._endOffsetForNode(previousElementSibling));
+ }
+ }
+ }
+ },
+
+ _endOffsetForNode: function(node) {
+ var range = document.createRange();
+ range.selectNodeContents(node);
+ return range.endOffset;
+ },
+
+ _detectInlineRangeProblems: function(range) {
+ var position = dom.compareDocumentPosition(range.startContainer, range.endContainer);
+ return (
+ range.endOffset == 0 &&
+ position & 4 //Node.DOCUMENT_POSITION_FOLLOWING
+ );
+ },
+
+ getRange: function(dontFix) {
+ var selection = this.getSelection(),
+ range = selection && selection.rangeCount && selection.getRangeAt(0);
+
+ if (dontFix !== true) {
+ this.fixRangeOverflow(range);
+ }
+
+ return range;
+ },
+
+ getOwnUneditables: function() {
+ var allUneditables = dom.query(this.contain, '.' + this.unselectableClass),
+ deepUneditables = dom.query(allUneditables, '.' + this.unselectableClass);
+
+ return wysihtml5.lang.array(allUneditables).without(deepUneditables);
+ },
+
+ // Returns an array of ranges that belong only to this editable
+ // Needed as uneditable block in contenteditabel can split range into pieces
+ // If manipulating content reverse loop is usually needed as manipulation can shift subsequent ranges
+ getOwnRanges: function() {
+ var ranges = [],
+ r = this.getRange(),
+ tmpRanges;
+
+ if (r) { ranges.push(r); }
+
+ if (this.unselectableClass && this.contain && r) {
+ var uneditables = this.getOwnUneditables(),
+ tmpRange;
+ if (uneditables.length > 0) {
+ for (var i = 0, imax = uneditables.length; i < imax; i++) {
+ tmpRanges = [];
+ for (var j = 0, jmax = ranges.length; j < jmax; j++) {
+ if (ranges[j]) {
+ switch (ranges[j].compareNode(uneditables[i])) {
+ case 2:
+ // all selection inside uneditable. remove
+ break;
+ case 3:
+ //section begins before and ends after uneditable. spilt
+ tmpRange = ranges[j].cloneRange();
+ tmpRange.setEndBefore(uneditables[i]);
+ tmpRanges.push(tmpRange);
+
+ tmpRange = ranges[j].cloneRange();
+ tmpRange.setStartAfter(uneditables[i]);
+ tmpRanges.push(tmpRange);
+ break;
+ default:
+ // in all other cases uneditable does not touch selection. dont modify
+ tmpRanges.push(ranges[j]);
+ }
+ }
+ ranges = tmpRanges;
+ }
+ }
+ }
+ }
+ return ranges;
+ },
+
+ getSelection: function() {
+ return rangy.getSelection(this.doc.defaultView || this.doc.parentWindow);
+ },
+
+ // Sets selection in document to a given range
+ // Set selection method detects if it fails to set any selection in document and returns null on fail
+ // (especially needed in webkit where some ranges just can not create selection for no reason)
+ setSelection: function(range) {
+ var win = this.doc.defaultView || this.doc.parentWindow,
+ selection = rangy.getSelection(win);
+ selection.setSingleRange(range);
+ return (selection && selection.anchorNode && selection.focusNode) ? selection : null;
+ },
+
+ createRange: function() {
+ return rangy.createRange(this.doc);
+ },
+
+ isCollapsed: function() {
+ return this.getSelection().isCollapsed;
+ },
+
+ getHtml: function() {
+ return this.getSelection().toHtml();
+ },
+
+ getPlainText: function () {
+ return this.getSelection().toString();
+ },
+
+ isEndToEndInNode: function(nodeNames) {
+ var range = this.getRange(),
+ parentElement = range.commonAncestorContainer,
+ startNode = range.startContainer,
+ endNode = range.endContainer;
+
+
+ if (parentElement.nodeType === wysihtml5.TEXT_NODE) {
+ parentElement = parentElement.parentNode;
+ }
+
+ if (startNode.nodeType === wysihtml5.TEXT_NODE && !(/^\s*$/).test(startNode.data.substr(range.startOffset))) {
+ return false;
+ }
+
+ if (endNode.nodeType === wysihtml5.TEXT_NODE && !(/^\s*$/).test(endNode.data.substr(range.endOffset))) {
+ return false;
+ }
+
+ while (startNode && startNode !== parentElement) {
+ if (startNode.nodeType !== wysihtml5.TEXT_NODE && !wysihtml5.dom.contains(parentElement, startNode)) {
+ return false;
+ }
+ if (wysihtml5.dom.domNode(startNode).prev({ignoreBlankTexts: true})) {
+ return false;
+ }
+ startNode = startNode.parentNode;
+ }
+
+ while (endNode && endNode !== parentElement) {
+ if (endNode.nodeType !== wysihtml5.TEXT_NODE && !wysihtml5.dom.contains(parentElement, endNode)) {
+ return false;
+ }
+ if (wysihtml5.dom.domNode(endNode).next({ignoreBlankTexts: true})) {
+ return false;
+ }
+ endNode = endNode.parentNode;
+ }
+
+ return (wysihtml5.lang.array(nodeNames).contains(parentElement.nodeName)) ? parentElement : false;
+ },
+
+ deselect: function() {
+ var sel = this.getSelection();
+ sel && sel.removeAllRanges();
+ }
+ });
+
+})(wysihtml5);
+;/**
+ * Inspired by the rangy CSS Applier module written by Tim Down and licensed under the MIT license.
+ * http://code.google.com/p/rangy/
+ *
+ * changed in order to be able ...
+ * - to use custom tags
+ * - to detect and replace similar css classes via reg exp
+ */
+(function(wysihtml5, rangy) {
+ var defaultTagName = "span";
+
+ var REG_EXP_WHITE_SPACE = /\s+/g;
+
+ function hasClass(el, cssClass, regExp) {
+ if (!el.className) {
+ return false;
+ }
+
+ var matchingClassNames = el.className.match(regExp) || [];
+ return matchingClassNames[matchingClassNames.length - 1] === cssClass;
+ }
+
+ function hasStyleAttr(el, regExp) {
+ if (!el.getAttribute || !el.getAttribute('style')) {
+ return false;
+ }
+ var matchingStyles = el.getAttribute('style').match(regExp);
+ return (el.getAttribute('style').match(regExp)) ? true : false;
+ }
+
+ function addStyle(el, cssStyle, regExp) {
+ if (el.getAttribute('style')) {
+ removeStyle(el, regExp);
+ if (el.getAttribute('style') && !(/^\s*$/).test(el.getAttribute('style'))) {
+ el.setAttribute('style', cssStyle + ";" + el.getAttribute('style'));
+ } else {
+ el.setAttribute('style', cssStyle);
+ }
+ } else {
+ el.setAttribute('style', cssStyle);
+ }
+ }
+
+ function addClass(el, cssClass, regExp) {
+ if (el.className) {
+ removeClass(el, regExp);
+ el.className += " " + cssClass;
+ } else {
+ el.className = cssClass;
+ }
+ }
+
+ function removeClass(el, regExp) {
+ if (el.className) {
+ el.className = el.className.replace(regExp, "");
+ }
+ }
+
+ function removeStyle(el, regExp) {
+ var s,
+ s2 = [];
+ if (el.getAttribute('style')) {
+ s = el.getAttribute('style').split(';');
+ for (var i = s.length; i--;) {
+ if (!s[i].match(regExp) && !(/^\s*$/).test(s[i])) {
+ s2.push(s[i]);
+ }
+ }
+ if (s2.length) {
+ el.setAttribute('style', s2.join(';'));
+ } else {
+ el.removeAttribute('style');
+ }
+ }
+ }
+
+ function getMatchingStyleRegexp(el, style) {
+ var regexes = [],
+ sSplit = style.split(';'),
+ elStyle = el.getAttribute('style');
+
+ if (elStyle) {
+ elStyle = elStyle.replace(/\s/gi, '').toLowerCase();
+ regexes.push(new RegExp("(^|\\s|;)" + style.replace(/\s/gi, '').replace(/([\(\)])/gi, "\\$1").toLowerCase().replace(";", ";?").replace(/rgb\\\((\d+),(\d+),(\d+)\\\)/gi, "\\s?rgb\\($1,\\s?$2,\\s?$3\\)"), "gi"));
+
+ for (var i = sSplit.length; i-- > 0;) {
+ if (!(/^\s*$/).test(sSplit[i])) {
+ regexes.push(new RegExp("(^|\\s|;)" + sSplit[i].replace(/\s/gi, '').replace(/([\(\)])/gi, "\\$1").toLowerCase().replace(";", ";?").replace(/rgb\\\((\d+),(\d+),(\d+)\\\)/gi, "\\s?rgb\\($1,\\s?$2,\\s?$3\\)"), "gi"));
+ }
+ }
+ for (var j = 0, jmax = regexes.length; j < jmax; j++) {
+ if (elStyle.match(regexes[j])) {
+ return regexes[j];
+ }
+ }
+ }
+
+ return false;
+ }
+
+ function isMatchingAllready(node, tags, style, className) {
+ if (style) {
+ return getMatchingStyleRegexp(node, style);
+ } else if (className) {
+ return wysihtml5.dom.hasClass(node, className);
+ } else {
+ return rangy.dom.arrayContains(tags, node.tagName.toLowerCase());
+ }
+ }
+
+ function areMatchingAllready(nodes, tags, style, className) {
+ for (var i = nodes.length; i--;) {
+ if (!isMatchingAllready(nodes[i], tags, style, className)) {
+ return false;
+ }
+ }
+ return nodes.length ? true : false;
+ }
+
+ function removeOrChangeStyle(el, style, regExp) {
+
+ var exactRegex = getMatchingStyleRegexp(el, style);
+ if (exactRegex) {
+ // adding same style value on property again removes style
+ removeStyle(el, exactRegex);
+ return "remove";
+ } else {
+ // adding new style value changes value
+ addStyle(el, style, regExp);
+ return "change";
+ }
+ }
+
+ function hasSameClasses(el1, el2) {
+ return el1.className.replace(REG_EXP_WHITE_SPACE, " ") == el2.className.replace(REG_EXP_WHITE_SPACE, " ");
+ }
+
+ function replaceWithOwnChildren(el) {
+ var parent = el.parentNode;
+ while (el.firstChild) {
+ parent.insertBefore(el.firstChild, el);
+ }
+ parent.removeChild(el);
+ }
+
+ function elementsHaveSameNonClassAttributes(el1, el2) {
+ if (el1.attributes.length != el2.attributes.length) {
+ return false;
+ }
+ for (var i = 0, len = el1.attributes.length, attr1, attr2, name; i < len; ++i) {
+ attr1 = el1.attributes[i];
+ name = attr1.name;
+ if (name != "class") {
+ attr2 = el2.attributes.getNamedItem(name);
+ if (attr1.specified != attr2.specified) {
+ return false;
+ }
+ if (attr1.specified && attr1.nodeValue !== attr2.nodeValue) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ function isSplitPoint(node, offset) {
+ if (rangy.dom.isCharacterDataNode(node)) {
+ if (offset == 0) {
+ return !!node.previousSibling;
+ } else if (offset == node.length) {
+ return !!node.nextSibling;
+ } else {
+ return true;
+ }
+ }
+
+ return offset > 0 && offset < node.childNodes.length;
+ }
+
+ function splitNodeAt(node, descendantNode, descendantOffset, container) {
+ var newNode;
+ if (rangy.dom.isCharacterDataNode(descendantNode)) {
+ if (descendantOffset == 0) {
+ descendantOffset = rangy.dom.getNodeIndex(descendantNode);
+ descendantNode = descendantNode.parentNode;
+ } else if (descendantOffset == descendantNode.length) {
+ descendantOffset = rangy.dom.getNodeIndex(descendantNode) + 1;
+ descendantNode = descendantNode.parentNode;
+ } else {
+ newNode = rangy.dom.splitDataNode(descendantNode, descendantOffset);
+ }
+ }
+ if (!newNode) {
+ if (!container || descendantNode !== container) {
+
+ newNode = descendantNode.cloneNode(false);
+ if (newNode.id) {
+ newNode.removeAttribute("id");
+ }
+ var child;
+ while ((child = descendantNode.childNodes[descendantOffset])) {
+ newNode.appendChild(child);
+ }
+ rangy.dom.insertAfter(newNode, descendantNode);
+
+ }
+ }
+ return (descendantNode == node) ? newNode : splitNodeAt(node, newNode.parentNode, rangy.dom.getNodeIndex(newNode), container);
+ }
+
+ function Merge(firstNode) {
+ this.isElementMerge = (firstNode.nodeType == wysihtml5.ELEMENT_NODE);
+ this.firstTextNode = this.isElementMerge ? firstNode.lastChild : firstNode;
+ this.textNodes = [this.firstTextNode];
+ }
+
+ Merge.prototype = {
+ doMerge: function() {
+ var textBits = [], textNode, parent, text;
+ for (var i = 0, len = this.textNodes.length; i < len; ++i) {
+ textNode = this.textNodes[i];
+ parent = textNode.parentNode;
+ textBits[i] = textNode.data;
+ if (i) {
+ parent.removeChild(textNode);
+ if (!parent.hasChildNodes()) {
+ parent.parentNode.removeChild(parent);
+ }
+ }
+ }
+ this.firstTextNode.data = text = textBits.join("");
+ return text;
+ },
+
+ getLength: function() {
+ var i = this.textNodes.length, len = 0;
+ while (i--) {
+ len += this.textNodes[i].length;
+ }
+ return len;
+ },
+
+ toString: function() {
+ var textBits = [];
+ for (var i = 0, len = this.textNodes.length; i < len; ++i) {
+ textBits[i] = "'" + this.textNodes[i].data + "'";
+ }
+ return "[Merge(" + textBits.join(",") + ")]";
+ }
+ };
+
+ function HTMLApplier(tagNames, cssClass, similarClassRegExp, normalize, cssStyle, similarStyleRegExp, container) {
+ this.tagNames = tagNames || [defaultTagName];
+ this.cssClass = cssClass || ((cssClass === false) ? false : "");
+ this.similarClassRegExp = similarClassRegExp;
+ this.cssStyle = cssStyle || "";
+ this.similarStyleRegExp = similarStyleRegExp;
+ this.normalize = normalize;
+ this.applyToAnyTagName = false;
+ this.container = container;
+ }
+
+ HTMLApplier.prototype = {
+ getAncestorWithClass: function(node) {
+ var cssClassMatch;
+ while (node) {
+ cssClassMatch = this.cssClass ? hasClass(node, this.cssClass, this.similarClassRegExp) : (this.cssStyle !== "") ? false : true;
+ if (node.nodeType == wysihtml5.ELEMENT_NODE && node.getAttribute("contenteditable") != "false" && rangy.dom.arrayContains(this.tagNames, node.tagName.toLowerCase()) && cssClassMatch) {
+ return node;
+ }
+ node = node.parentNode;
+ }
+ return false;
+ },
+
+ // returns parents of node with given style attribute
+ getAncestorWithStyle: function(node) {
+ var cssStyleMatch;
+ while (node) {
+ cssStyleMatch = this.cssStyle ? hasStyleAttr(node, this.similarStyleRegExp) : false;
+
+ if (node.nodeType == wysihtml5.ELEMENT_NODE && node.getAttribute("contenteditable") != "false" && rangy.dom.arrayContains(this.tagNames, node.tagName.toLowerCase()) && cssStyleMatch) {
+ return node;
+ }
+ node = node.parentNode;
+ }
+ return false;
+ },
+
+ getMatchingAncestor: function(node) {
+ var ancestor = this.getAncestorWithClass(node),
+ matchType = false;
+
+ if (!ancestor) {
+ ancestor = this.getAncestorWithStyle(node);
+ if (ancestor) {
+ matchType = "style";
+ }
+ } else {
+ if (this.cssStyle) {
+ matchType = "class";
+ }
+ }
+
+ return {
+ "element": ancestor,
+ "type": matchType
+ };
+ },
+
+ // Normalizes nodes after applying a CSS class to a Range.
+ postApply: function(textNodes, range) {
+ var firstNode = textNodes[0], lastNode = textNodes[textNodes.length - 1];
+
+ var merges = [], currentMerge;
+
+ var rangeStartNode = firstNode, rangeEndNode = lastNode;
+ var rangeStartOffset = 0, rangeEndOffset = lastNode.length;
+
+ var textNode, precedingTextNode;
+
+ for (var i = 0, len = textNodes.length; i < len; ++i) {
+ textNode = textNodes[i];
+ precedingTextNode = null;
+ if (textNode && textNode.parentNode) {
+ precedingTextNode = this.getAdjacentMergeableTextNode(textNode.parentNode, false);
+ }
+ if (precedingTextNode) {
+ if (!currentMerge) {
+ currentMerge = new Merge(precedingTextNode);
+ merges.push(currentMerge);
+ }
+ currentMerge.textNodes.push(textNode);
+ if (textNode === firstNode) {
+ rangeStartNode = currentMerge.firstTextNode;
+ rangeStartOffset = rangeStartNode.length;
+ }
+ if (textNode === lastNode) {
+ rangeEndNode = currentMerge.firstTextNode;
+ rangeEndOffset = currentMerge.getLength();
+ }
+ } else {
+ currentMerge = null;
+ }
+ }
+ // Test whether the first node after the range needs merging
+ if(lastNode && lastNode.parentNode) {
+ var nextTextNode = this.getAdjacentMergeableTextNode(lastNode.parentNode, true);
+ if (nextTextNode) {
+ if (!currentMerge) {
+ currentMerge = new Merge(lastNode);
+ merges.push(currentMerge);
+ }
+ currentMerge.textNodes.push(nextTextNode);
+ }
+ }
+ // Do the merges
+ if (merges.length) {
+ for (i = 0, len = merges.length; i < len; ++i) {
+ merges[i].doMerge();
+ }
+ // Set the range boundaries
+ range.setStart(rangeStartNode, rangeStartOffset);
+ range.setEnd(rangeEndNode, rangeEndOffset);
+ }
+ },
+
+ getAdjacentMergeableTextNode: function(node, forward) {
+ var isTextNode = (node.nodeType == wysihtml5.TEXT_NODE);
+ var el = isTextNode ? node.parentNode : node;
+ var adjacentNode;
+ var propName = forward ? "nextSibling" : "previousSibling";
+ if (isTextNode) {
+ // Can merge if the node's previous/next sibling is a text node
+ adjacentNode = node[propName];
+ if (adjacentNode && adjacentNode.nodeType == wysihtml5.TEXT_NODE) {
+ return adjacentNode;
+ }
+ } else {
+ // Compare element with its sibling
+ adjacentNode = el[propName];
+ if (adjacentNode && this.areElementsMergeable(node, adjacentNode)) {
+ return adjacentNode[forward ? "firstChild" : "lastChild"];
+ }
+ }
+ return null;
+ },
+
+ areElementsMergeable: function(el1, el2) {
+ return rangy.dom.arrayContains(this.tagNames, (el1.tagName || "").toLowerCase())
+ && rangy.dom.arrayContains(this.tagNames, (el2.tagName || "").toLowerCase())
+ && hasSameClasses(el1, el2)
+ && elementsHaveSameNonClassAttributes(el1, el2);
+ },
+
+ createContainer: function(doc) {
+ var el = doc.createElement(this.tagNames[0]);
+ if (this.cssClass) {
+ el.className = this.cssClass;
+ }
+ if (this.cssStyle) {
+ el.setAttribute('style', this.cssStyle);
+ }
+ return el;
+ },
+
+ applyToTextNode: function(textNode) {
+ var parent = textNode.parentNode;
+ if (parent.childNodes.length == 1 && rangy.dom.arrayContains(this.tagNames, parent.tagName.toLowerCase())) {
+
+ if (this.cssClass) {
+ addClass(parent, this.cssClass, this.similarClassRegExp);
+ }
+ if (this.cssStyle) {
+ addStyle(parent, this.cssStyle, this.similarStyleRegExp);
+ }
+ } else {
+ var el = this.createContainer(rangy.dom.getDocument(textNode));
+ textNode.parentNode.insertBefore(el, textNode);
+ el.appendChild(textNode);
+ }
+ },
+
+ isRemovable: function(el) {
+ return rangy.dom.arrayContains(this.tagNames, el.tagName.toLowerCase()) &&
+ wysihtml5.lang.string(el.className).trim() === "" &&
+ (
+ !el.getAttribute('style') ||
+ wysihtml5.lang.string(el.getAttribute('style')).trim() === ""
+ );
+ },
+
+ undoToTextNode: function(textNode, range, ancestorWithClass, ancestorWithStyle) {
+ var styleMode = (ancestorWithClass) ? false : true,
+ ancestor = ancestorWithClass || ancestorWithStyle,
+ styleChanged = false;
+ if (!range.containsNode(ancestor)) {
+ // Split out the portion of the ancestor from which we can remove the CSS class
+ var ancestorRange = range.cloneRange();
+ ancestorRange.selectNode(ancestor);
+
+ if (ancestorRange.isPointInRange(range.endContainer, range.endOffset) && isSplitPoint(range.endContainer, range.endOffset)) {
+ splitNodeAt(ancestor, range.endContainer, range.endOffset, this.container);
+ range.setEndAfter(ancestor);
+ }
+ if (ancestorRange.isPointInRange(range.startContainer, range.startOffset) && isSplitPoint(range.startContainer, range.startOffset)) {
+ ancestor = splitNodeAt(ancestor, range.startContainer, range.startOffset, this.container);
+ }
+ }
+
+ if (!styleMode && this.similarClassRegExp) {
+ removeClass(ancestor, this.similarClassRegExp);
+ }
+
+ if (styleMode && this.similarStyleRegExp) {
+ styleChanged = (removeOrChangeStyle(ancestor, this.cssStyle, this.similarStyleRegExp) === "change");
+ }
+ if (this.isRemovable(ancestor) && !styleChanged) {
+ replaceWithOwnChildren(ancestor);
+ }
+ },
+
+ applyToRange: function(range) {
+ var textNodes;
+ for (var ri = range.length; ri--;) {
+ textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
+
+ if (!textNodes.length) {
+ try {
+ var node = this.createContainer(range[ri].endContainer.ownerDocument);
+ range[ri].surroundContents(node);
+ this.selectNode(range[ri], node);
+ return;
+ } catch(e) {}
+ }
+
+ range[ri].splitBoundaries();
+ textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
+ if (textNodes.length) {
+ var textNode;
+
+ for (var i = 0, len = textNodes.length; i < len; ++i) {
+ textNode = textNodes[i];
+ if (!this.getMatchingAncestor(textNode).element) {
+ this.applyToTextNode(textNode);
+ }
+ }
+
+ range[ri].setStart(textNodes[0], 0);
+ textNode = textNodes[textNodes.length - 1];
+ range[ri].setEnd(textNode, textNode.length);
+
+ if (this.normalize) {
+ this.postApply(textNodes, range[ri]);
+ }
+ }
+
+ }
+ },
+
+ undoToRange: function(range) {
+ var textNodes, textNode, ancestorWithClass, ancestorWithStyle, ancestor;
+ for (var ri = range.length; ri--;) {
+
+ textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
+ if (textNodes.length) {
+ range[ri].splitBoundaries();
+ textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
+ } else {
+ var doc = range[ri].endContainer.ownerDocument,
+ node = doc.createTextNode(wysihtml5.INVISIBLE_SPACE);
+ range[ri].insertNode(node);
+ range[ri].selectNode(node);
+ textNodes = [node];
+ }
+
+ for (var i = 0, len = textNodes.length; i < len; ++i) {
+ if (range[ri].isValid()) {
+ textNode = textNodes[i];
+
+ ancestor = this.getMatchingAncestor(textNode);
+ if (ancestor.type === "style") {
+ this.undoToTextNode(textNode, range[ri], false, ancestor.element);
+ } else if (ancestor.element) {
+ this.undoToTextNode(textNode, range[ri], ancestor.element);
+ }
+ }
+ }
+
+ if (len == 1) {
+ this.selectNode(range[ri], textNodes[0]);
+ } else {
+ range[ri].setStart(textNodes[0], 0);
+ textNode = textNodes[textNodes.length - 1];
+ range[ri].setEnd(textNode, textNode.length);
+
+ if (this.normalize) {
+ this.postApply(textNodes, range[ri]);
+ }
+ }
+
+ }
+ },
+
+ selectNode: function(range, node) {
+ var isElement = node.nodeType === wysihtml5.ELEMENT_NODE,
+ canHaveHTML = "canHaveHTML" in node ? node.canHaveHTML : true,
+ content = isElement ? node.innerHTML : node.data,
+ isEmpty = (content === "" || content === wysihtml5.INVISIBLE_SPACE);
+
+ if (isEmpty && isElement && canHaveHTML) {
+ // Make sure that caret is visible in node by inserting a zero width no breaking space
+ try { node.innerHTML = wysihtml5.INVISIBLE_SPACE; } catch(e) {}
+ }
+ range.selectNodeContents(node);
+ if (isEmpty && isElement) {
+ range.collapse(false);
+ } else if (isEmpty) {
+ range.setStartAfter(node);
+ range.setEndAfter(node);
+ }
+ },
+
+ getTextSelectedByRange: function(textNode, range) {
+ var textRange = range.cloneRange();
+ textRange.selectNodeContents(textNode);
+
+ var intersectionRange = textRange.intersection(range);
+ var text = intersectionRange ? intersectionRange.toString() : "";
+ textRange.detach();
+
+ return text;
+ },
+
+ isAppliedToRange: function(range) {
+ var ancestors = [],
+ appliedType = "full",
+ ancestor, styleAncestor, textNodes;
+
+ for (var ri = range.length; ri--;) {
+
+ textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
+ if (!textNodes.length) {
+ ancestor = this.getMatchingAncestor(range[ri].startContainer).element;
+
+ return (ancestor) ? {
+ "elements": [ancestor],
+ "coverage": appliedType
+ } : false;
+ }
+
+ for (var i = 0, len = textNodes.length, selectedText; i < len; ++i) {
+ selectedText = this.getTextSelectedByRange(textNodes[i], range[ri]);
+ ancestor = this.getMatchingAncestor(textNodes[i]).element;
+ if (ancestor && selectedText != "") {
+ ancestors.push(ancestor);
+
+ if (wysihtml5.dom.getTextNodes(ancestor, true).length === 1) {
+ appliedType = "full";
+ } else if (appliedType === "full") {
+ appliedType = "inline";
+ }
+ } else if (!ancestor) {
+ appliedType = "partial";
+ }
+ }
+
+ }
+
+ return (ancestors.length) ? {
+ "elements": ancestors,
+ "coverage": appliedType
+ } : false;
+ },
+
+ toggleRange: function(range) {
+ var isApplied = this.isAppliedToRange(range),
+ parentsExactMatch;
+
+ if (isApplied) {
+ if (isApplied.coverage === "full") {
+ this.undoToRange(range);
+ } else if (isApplied.coverage === "inline") {
+ parentsExactMatch = areMatchingAllready(isApplied.elements, this.tagNames, this.cssStyle, this.cssClass);
+ this.undoToRange(range);
+ if (!parentsExactMatch) {
+ this.applyToRange(range);
+ }
+ } else {
+ // partial
+ if (!areMatchingAllready(isApplied.elements, this.tagNames, this.cssStyle, this.cssClass)) {
+ this.undoToRange(range);
+ }
+ this.applyToRange(range);
+ }
+ } else {
+ this.applyToRange(range);
+ }
+ }
+ };
+
+ wysihtml5.selection.HTMLApplier = HTMLApplier;
+
+})(wysihtml5, rangy);
+;/**
+ * Rich Text Query/Formatting Commands
+ *
+ * @example
+ * var commands = new wysihtml5.Commands(editor);
+ */
+wysihtml5.Commands = Base.extend(
+ /** @scope wysihtml5.Commands.prototype */ {
+ constructor: function(editor) {
+ this.editor = editor;
+ this.composer = editor.composer;
+ this.doc = this.composer.doc;
+ },
+
+ /**
+ * Check whether the browser supports the given command
+ *
+ * @param {String} command The command string which to check (eg. "bold", "italic", "insertUnorderedList")
+ * @example
+ * commands.supports("createLink");
+ */
+ support: function(command) {
+ return wysihtml5.browser.supportsCommand(this.doc, command);
+ },
+
+ /**
+ * Check whether the browser supports the given command
+ *
+ * @param {String} command The command string which to execute (eg. "bold", "italic", "insertUnorderedList")
+ * @param {String} [value] The command value parameter, needed for some commands ("createLink", "insertImage", ...), optional for commands that don't require one ("bold", "underline", ...)
+ * @example
+ * commands.exec("insertImage", "http://a1.twimg.com/profile_images/113868655/schrei_twitter_reasonably_small.jpg");
+ */
+ exec: function(command, value) {
+ var obj = wysihtml5.commands[command],
+ args = wysihtml5.lang.array(arguments).get(),
+ method = obj && obj.exec,
+ result = null;
+
+ // If composer ahs placeholder unset it before command
+ // Do not apply on commands that are behavioral
+ if (this.composer.hasPlaceholderSet() && !wysihtml5.lang.array(['styleWithCSS', 'enableObjectResizing', 'enableInlineTableEditing']).contains(command)) {
+ this.composer.element.innerHTML = "";
+ this.composer.selection.selectNode(this.composer.element);
+ }
+
+ this.editor.fire("beforecommand:composer");
+
+ if (method) {
+ args.unshift(this.composer);
+ result = method.apply(obj, args);
+ } else {
+ try {
+ // try/catch for buggy firefox
+ result = this.doc.execCommand(command, false, value);
+ } catch(e) {}
+ }
+
+ this.editor.fire("aftercommand:composer");
+ return result;
+ },
+
+ /**
+ * Check whether the current command is active
+ * If the caret is within a bold text, then calling this with command "bold" should return true
+ *
+ * @param {String} command The command string which to check (eg. "bold", "italic", "insertUnorderedList")
+ * @param {String} [commandValue] The command value parameter (eg. for "insertImage" the image src)
+ * @return {Boolean} Whether the command is active
+ * @example
+ * var isCurrentSelectionBold = commands.state("bold");
+ */
+ state: function(command, commandValue) {
+ var obj = wysihtml5.commands[command],
+ args = wysihtml5.lang.array(arguments).get(),
+ method = obj && obj.state;
+ if (method) {
+ args.unshift(this.composer);
+ return method.apply(obj, args);
+ } else {
+ try {
+ // try/catch for buggy firefox
+ return this.doc.queryCommandState(command);
+ } catch(e) {
+ return false;
+ }
+ }
+ },
+
+ /* Get command state parsed value if command has stateValue parsing function */
+ stateValue: function(command) {
+ var obj = wysihtml5.commands[command],
+ args = wysihtml5.lang.array(arguments).get(),
+ method = obj && obj.stateValue;
+ if (method) {
+ args.unshift(this.composer);
+ return method.apply(obj, args);
+ } else {
+ return false;
+ }
+ }
+});
+;wysihtml5.commands.bold = {
+ exec: function(composer, command) {
+ wysihtml5.commands.formatInline.execWithToggle(composer, command, "b");
+ },
+
+ state: function(composer, command) {
+ // element.ownerDocument.queryCommandState("bold") results:
+ // firefox: only <b>
+ // chrome: <b>, <strong>, <h1>, <h2>, ...
+ // ie: <b>, <strong>
+ // opera: <b>, <strong>
+ return wysihtml5.commands.formatInline.state(composer, command, "b");
+ }
+};
+
+;(function(wysihtml5) {
+ var undef,
+ NODE_NAME = "A",
+ dom = wysihtml5.dom;
+
+ function _format(composer, attributes) {
+ var doc = composer.doc,
+ tempClass = "_wysihtml5-temp-" + (+new Date()),
+ tempClassRegExp = /non-matching-class/g,
+ i = 0,
+ length,
+ anchors,
+ anchor,
+ hasElementChild,
+ isEmpty,
+ elementToSetCaretAfter,
+ textContent,
+ whiteSpace,
+ j;
+ wysihtml5.commands.formatInline.exec(composer, undef, NODE_NAME, tempClass, tempClassRegExp, undef, undef, true, true);
+ anchors = doc.querySelectorAll(NODE_NAME + "." + tempClass);
+ length = anchors.length;
+ for (; i<length; i++) {
+ anchor = anchors[i];
+ anchor.removeAttribute("class");
+ for (j in attributes) {
+ // Do not set attribute "text" as it is meant for setting string value if created link has no textual data
+ if (j !== "text") {
+ anchor.setAttribute(j, attributes[j]);
+ }
+ }
+ }
+
+ elementToSetCaretAfter = anchor;
+ if (length === 1) {
+ textContent = dom.getTextContent(anchor);
+ hasElementChild = !!anchor.querySelector("*");
+ isEmpty = textContent === "" || textContent === wysihtml5.INVISIBLE_SPACE;
+ if (!hasElementChild && isEmpty) {
+ dom.setTextContent(anchor, attributes.text || anchor.href);
+ whiteSpace = doc.createTextNode(" ");
+ composer.selection.setAfter(anchor);
+ dom.insert(whiteSpace).after(anchor);
+ elementToSetCaretAfter = whiteSpace;
+ }
+ }
+ composer.selection.setAfter(elementToSetCaretAfter);
+ }
+
+ // Changes attributes of links
+ function _changeLinks(composer, anchors, attributes) {
+ var oldAttrs;
+ for (var a = anchors.length; a--;) {
+
+ // Remove all old attributes
+ oldAttrs = anchors[a].attributes;
+ for (var oa = oldAttrs.length; oa--;) {
+ anchors[a].removeAttribute(oldAttrs.item(oa).name);
+ }
+
+ // Set new attributes
+ for (var j in attributes) {
+ if (attributes.hasOwnProperty(j)) {
+ anchors[a].setAttribute(j, attributes[j]);
+ }
+ }
+
+ }
+ }
+
+ wysihtml5.commands.createLink = {
+ /**
+ * TODO: Use HTMLApplier or formatInline here
+ *
+ * Turns selection into a link
+ * If selection is already a link, it just changes the attributes
+ *
+ * @example
+ * // either ...
+ * wysihtml5.commands.createLink.exec(composer, "createLink", "http://www.google.de");
+ * // ... or ...
+ * wysihtml5.commands.createLink.exec(composer, "createLink", { href: "http://www.google.de", target: "_blank" });
+ */
+ exec: function(composer, command, value) {
+ var anchors = this.state(composer, command);
+ if (anchors) {
+ // Selection contains links then change attributes of these links
+ composer.selection.executeAndRestore(function() {
+ _changeLinks(composer, anchors, value);
+ });
+ } else {
+ // Create links
+ value = typeof(value) === "object" ? value : { href: value };
+ _format(composer, value);
+ }
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatInline.state(composer, command, "A");
+ }
+ };
+})(wysihtml5);
+;(function(wysihtml5) {
+ var dom = wysihtml5.dom;
+
+ function _removeFormat(composer, anchors) {
+ var length = anchors.length,
+ i = 0,
+ anchor,
+ codeElement,
+ textContent;
+ for (; i<length; i++) {
+ anchor = anchors[i];
+ codeElement = dom.getParentElement(anchor, { nodeName: "code" });
+ textContent = dom.getTextContent(anchor);
+
+ // if <a> contains url-like text content, rename it to <code> to prevent re-autolinking
+ // else replace <a> with its childNodes
+ if (textContent.match(dom.autoLink.URL_REG_EXP) && !codeElement) {
+ // <code> element is used to prevent later auto-linking of the content
+ codeElement = dom.renameElement(anchor, "code");
+ } else {
+ dom.replaceWithChildNodes(anchor);
+ }
+ }
+ }
+
+ wysihtml5.commands.removeLink = {
+ /*
+ * If selection is a link, it removes the link and wraps it with a <code> element
+ * The <code> element is needed to avoid auto linking
+ *
+ * @example
+ * wysihtml5.commands.createLink.exec(composer, "removeLink");
+ */
+
+ exec: function(composer, command) {
+ var anchors = this.state(composer, command);
+ if (anchors) {
+ composer.selection.executeAndRestore(function() {
+ _removeFormat(composer, anchors);
+ });
+ }
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatInline.state(composer, command, "A");
+ }
+ };
+})(wysihtml5);
+;/**
+ * document.execCommand("fontSize") will create either inline styles (firefox, chrome) or use font tags
+ * which we don't want
+ * Instead we set a css class
+ */
+(function(wysihtml5) {
+ var REG_EXP = /wysiwyg-font-size-[0-9a-z\-]+/g;
+
+ wysihtml5.commands.fontSize = {
+ exec: function(composer, command, size) {
+ wysihtml5.commands.formatInline.execWithToggle(composer, command, "span", "wysiwyg-font-size-" + size, REG_EXP);
+ },
+
+ state: function(composer, command, size) {
+ return wysihtml5.commands.formatInline.state(composer, command, "span", "wysiwyg-font-size-" + size, REG_EXP);
+ }
+ };
+})(wysihtml5);
+;/* In case font size adjustment to any number defined by user is preferred, we cannot use classes and must use inline styles. */
+(function(wysihtml5) {
+ var REG_EXP = /(\s|^)font-size\s*:\s*[^;\s]+;?/gi;
+
+ wysihtml5.commands.fontSizeStyle = {
+ exec: function(composer, command, size) {
+ size = (typeof(size) == "object") ? size.size : size;
+ if (!(/^\s*$/).test(size)) {
+ wysihtml5.commands.formatInline.execWithToggle(composer, command, "span", false, false, "font-size:" + size, REG_EXP);
+ }
+ },
+
+ state: function(composer, command, size) {
+ return wysihtml5.commands.formatInline.state(composer, command, "span", false, false, "font-size", REG_EXP);
+ },
+
+ stateValue: function(composer, command) {
+ var st = this.state(composer, command),
+ styleStr, fontsizeMatches,
+ val = false;
+
+ if (st && wysihtml5.lang.object(st).isArray()) {
+ st = st[0];
+ }
+ if (st) {
+ styleStr = st.getAttribute('style');
+ if (styleStr) {
+ return wysihtml5.quirks.styleParser.parseFontSize(styleStr);
+ }
+ }
+ return false;
+ }
+ };
+})(wysihtml5);
+;/**
+ * document.execCommand("foreColor") will create either inline styles (firefox, chrome) or use font tags
+ * which we don't want
+ * Instead we set a css class
+ */
+(function(wysihtml5) {
+ var REG_EXP = /wysiwyg-color-[0-9a-z]+/g;
+
+ wysihtml5.commands.foreColor = {
+ exec: function(composer, command, color) {
+ wysihtml5.commands.formatInline.execWithToggle(composer, command, "span", "wysiwyg-color-" + color, REG_EXP);
+ },
+
+ state: function(composer, command, color) {
+ return wysihtml5.commands.formatInline.state(composer, command, "span", "wysiwyg-color-" + color, REG_EXP);
+ }
+ };
+})(wysihtml5);
+;/**
+ * document.execCommand("foreColor") will create either inline styles (firefox, chrome) or use font tags
+ * which we don't want
+ * Instead we set a css class
+ */
+(function(wysihtml5) {
+ var REG_EXP = /(\s|^)color\s*:\s*[^;\s]+;?/gi;
+
+ wysihtml5.commands.foreColorStyle = {
+ exec: function(composer, command, color) {
+ var colorVals = wysihtml5.quirks.styleParser.parseColor((typeof(color) == "object") ? "color:" + color.color : "color:" + color, "color"),
+ colString;
+
+ if (colorVals) {
+ colString = "color: rgb(" + colorVals[0] + ',' + colorVals[1] + ',' + colorVals[2] + ');';
+ if (colorVals[3] !== 1) {
+ colString += "color: rgba(" + colorVals[0] + ',' + colorVals[1] + ',' + colorVals[2] + ',' + colorVals[3] + ');';
+ }
+ wysihtml5.commands.formatInline.execWithToggle(composer, command, "span", false, false, colString, REG_EXP);
+ }
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatInline.state(composer, command, "span", false, false, "color", REG_EXP);
+ },
+
+ stateValue: function(composer, command, props) {
+ var st = this.state(composer, command),
+ colorStr;
+
+ if (st && wysihtml5.lang.object(st).isArray()) {
+ st = st[0];
+ }
+
+ if (st) {
+ colorStr = st.getAttribute('style');
+ if (colorStr) {
+ if (colorStr) {
+ val = wysihtml5.quirks.styleParser.parseColor(colorStr, "color");
+ return wysihtml5.quirks.styleParser.unparseColor(val, props);
+ }
+ }
+ }
+ return false;
+ }
+
+ };
+})(wysihtml5);
+;/* In case background adjustment to any color defined by user is preferred, we cannot use classes and must use inline styles. */
+(function(wysihtml5) {
+ var REG_EXP = /(\s|^)background-color\s*:\s*[^;\s]+;?/gi;
+
+ wysihtml5.commands.bgColorStyle = {
+ exec: function(composer, command, color) {
+ var colorVals = wysihtml5.quirks.styleParser.parseColor((typeof(color) == "object") ? "background-color:" + color.color : "background-color:" + color, "background-color"),
+ colString;
+
+ if (colorVals) {
+ colString = "background-color: rgb(" + colorVals[0] + ',' + colorVals[1] + ',' + colorVals[2] + ');';
+ if (colorVals[3] !== 1) {
+ colString += "background-color: rgba(" + colorVals[0] + ',' + colorVals[1] + ',' + colorVals[2] + ',' + colorVals[3] + ');';
+ }
+ wysihtml5.commands.formatInline.execWithToggle(composer, command, "span", false, false, colString, REG_EXP);
+ }
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatInline.state(composer, command, "span", false, false, "background-color", REG_EXP);
+ },
+
+ stateValue: function(composer, command, props) {
+ var st = this.state(composer, command),
+ colorStr,
+ val = false;
+
+ if (st && wysihtml5.lang.object(st).isArray()) {
+ st = st[0];
+ }
+
+ if (st) {
+ colorStr = st.getAttribute('style');
+ if (colorStr) {
+ val = wysihtml5.quirks.styleParser.parseColor(colorStr, "background-color");
+ return wysihtml5.quirks.styleParser.unparseColor(val, props);
+ }
+ }
+ return false;
+ }
+
+ };
+})(wysihtml5);
+;(function(wysihtml5) {
+ var dom = wysihtml5.dom,
+ // Following elements are grouped
+ // when the caret is within a H1 and the H4 is invoked, the H1 should turn into H4
+ // instead of creating a H4 within a H1 which would result in semantically invalid html
+ BLOCK_ELEMENTS_GROUP = ["H1", "H2", "H3", "H4", "H5", "H6", "P", "PRE", "DIV"];
+
+ /**
+ * Remove similiar classes (based on classRegExp)
+ * and add the desired class name
+ */
+ function _addClass(element, className, classRegExp) {
+ if (element.className) {
+ _removeClass(element, classRegExp);
+ element.className = wysihtml5.lang.string(element.className + " " + className).trim();
+ } else {
+ element.className = className;
+ }
+ }
+
+ function _addStyle(element, cssStyle, styleRegExp) {
+ _removeStyle(element, styleRegExp);
+ if (element.getAttribute('style')) {
+ element.setAttribute('style', wysihtml5.lang.string(element.getAttribute('style') + " " + cssStyle).trim());
+ } else {
+ element.setAttribute('style', cssStyle);
+ }
+ }
+
+ function _removeClass(element, classRegExp) {
+ var ret = classRegExp.test(element.className);
+ element.className = element.className.replace(classRegExp, "");
+ if (wysihtml5.lang.string(element.className).trim() == '') {
+ element.removeAttribute('class');
+ }
+ return ret;
+ }
+
+ function _removeStyle(element, styleRegExp) {
+ var ret = styleRegExp.test(element.getAttribute('style'));
+ element.setAttribute('style', (element.getAttribute('style') || "").replace(styleRegExp, ""));
+ if (wysihtml5.lang.string(element.getAttribute('style') || "").trim() == '') {
+ element.removeAttribute('style');
+ }
+ return ret;
+ }
+
+ function _removeLastChildIfLineBreak(node) {
+ var lastChild = node.lastChild;
+ if (lastChild && _isLineBreak(lastChild)) {
+ lastChild.parentNode.removeChild(lastChild);
+ }
+ }
+
+ function _isLineBreak(node) {
+ return node.nodeName === "BR";
+ }
+
+ /**
+ * Execute native query command
+ * and if necessary modify the inserted node's className
+ */
+ function _execCommand(doc, composer, command, nodeName, className) {
+ var ranges = composer.selection.getOwnRanges();
+ for (var i = ranges.length; i--;){
+ composer.selection.getSelection().removeAllRanges();
+ composer.selection.setSelection(ranges[i]);
+ if (className) {
+ var eventListener = dom.observe(doc, "DOMNodeInserted", function(event) {
+ var target = event.target,
+ displayStyle;
+ if (target.nodeType !== wysihtml5.ELEMENT_NODE) {
+ return;
+ }
+ displayStyle = dom.getStyle("display").from(target);
+ if (displayStyle.substr(0, 6) !== "inline") {
+ // Make sure that only block elements receive the given class
+ target.className += " " + className;
+ }
+ });
+ }
+ doc.execCommand(command, false, nodeName);
+
+ if (eventListener) {
+ eventListener.stop();
+ }
+ }
+ }
+
+ function _selectionWrap(composer, options) {
+ if (composer.selection.isCollapsed()) {
+ composer.selection.selectLine();
+ }
+
+ var surroundedNodes = composer.selection.surround(options);
+ for (var i = 0, imax = surroundedNodes.length; i < imax; i++) {
+ wysihtml5.dom.lineBreaks(surroundedNodes[i]).remove();
+ _removeLastChildIfLineBreak(surroundedNodes[i]);
+ }
+
+ // rethink restoring selection
+ // composer.selection.selectNode(element, wysihtml5.browser.displaysCaretInEmptyContentEditableCorrectly());
+ }
+
+ function _hasClasses(element) {
+ return !!wysihtml5.lang.string(element.className).trim();
+ }
+
+ function _hasStyles(element) {
+ return !!wysihtml5.lang.string(element.getAttribute('style') || '').trim();
+ }
+
+ wysihtml5.commands.formatBlock = {
+ exec: function(composer, command, nodeName, className, classRegExp, cssStyle, styleRegExp) {
+ var doc = composer.doc,
+ blockElements = this.state(composer, command, nodeName, className, classRegExp, cssStyle, styleRegExp),
+ useLineBreaks = composer.config.useLineBreaks,
+ defaultNodeName = useLineBreaks ? "DIV" : "P",
+ selectedNodes, classRemoveAction, blockRenameFound, styleRemoveAction, blockElement;
+ nodeName = typeof(nodeName) === "string" ? nodeName.toUpperCase() : nodeName;
+
+ if (blockElements.length) {
+ composer.selection.executeAndRestoreRangy(function() {
+ for (var b = blockElements.length; b--;) {
+ if (classRegExp) {
+ classRemoveAction = _removeClass(blockElements[b], classRegExp);
+ }
+ if (styleRegExp) {
+ styleRemoveAction = _removeStyle(blockElements[b], styleRegExp);
+ }
+
+ if ((styleRemoveAction || classRemoveAction) && nodeName === null && blockElements[b].nodeName != defaultNodeName) {
+ // dont rename or remove element when just setting block formating class or style
+ return;
+ }
+
+ var hasClasses = _hasClasses(blockElements[b]),
+ hasStyles = _hasStyles(blockElements[b]);
+
+ if (!hasClasses && !hasStyles && (useLineBreaks || nodeName === "P")) {
+ // Insert a line break afterwards and beforewards when there are siblings
+ // that are not of type line break or block element
+ wysihtml5.dom.lineBreaks(blockElements[b]).add();
+ dom.replaceWithChildNodes(blockElements[b]);
+ } else {
+ // Make sure that styling is kept by renaming the element to a <div> or <p> and copying over the class name
+ dom.renameElement(blockElements[b], nodeName === "P" ? "DIV" : defaultNodeName);
+ }
+ }
+ });
+
+ return;
+ }
+
+ // Find similiar block element and rename it (<h2 class="foo"></h2> => <h1 class="foo"></h1>)
+ if (nodeName === null || wysihtml5.lang.array(BLOCK_ELEMENTS_GROUP).contains(nodeName)) {
+ selectedNodes = composer.selection.findNodesInSelection(BLOCK_ELEMENTS_GROUP).concat(composer.selection.getSelectedOwnNodes());
+ composer.selection.executeAndRestoreRangy(function() {
+ for (var n = selectedNodes.length; n--;) {
+ blockElement = dom.getParentElement(selectedNodes[n], {
+ nodeName: BLOCK_ELEMENTS_GROUP
+ });
+ if (blockElement == composer.element) {
+ blockElement = null;
+ }
+ if (blockElement) {
+ // Rename current block element to new block element and add class
+ if (nodeName) {
+ blockElement = dom.renameElement(blockElement, nodeName);
+ }
+ if (className) {
+ _addClass(blockElement, className, classRegExp);
+ }
+ if (cssStyle) {
+ _addStyle(blockElement, cssStyle, styleRegExp);
+ }
+ blockRenameFound = true;
+ }
+ }
+
+ });
+
+ if (blockRenameFound) {
+ return;
+ }
+ }
+
+ _selectionWrap(composer, {
+ "nodeName": (nodeName || defaultNodeName),
+ "className": className || null,
+ "cssStyle": cssStyle || null
+ });
+ },
+
+ state: function(composer, command, nodeName, className, classRegExp, cssStyle, styleRegExp) {
+ var nodes = composer.selection.getSelectedOwnNodes(),
+ parents = [],
+ parent;
+
+ nodeName = typeof(nodeName) === "string" ? nodeName.toUpperCase() : nodeName;
+
+ //var selectedNode = composer.selection.getSelectedNode();
+ for (var i = 0, maxi = nodes.length; i < maxi; i++) {
+ parent = dom.getParentElement(nodes[i], {
+ nodeName: nodeName,
+ className: className,
+ classRegExp: classRegExp,
+ cssStyle: cssStyle,
+ styleRegExp: styleRegExp
+ });
+ if (parent && wysihtml5.lang.array(parents).indexOf(parent) == -1) {
+ parents.push(parent);
+ }
+ }
+ if (parents.length == 0) {
+ return false;
+ }
+ return parents;
+ }
+
+
+ };
+})(wysihtml5);
+;/* Formats block for as a <pre><code class="classname"></code></pre> block
+ * Useful in conjuction for sytax highlight utility: highlight.js
+ *
+ * Usage:
+ *
+ * editorInstance.composer.commands.exec("formatCode", "language-html");
+*/
+
+wysihtml5.commands.formatCode = {
+
+ exec: function(composer, command, classname) {
+ var pre = this.state(composer),
+ code, range, selectedNodes;
+ if (pre) {
+ // caret is already within a <pre><code>...</code></pre>
+ composer.selection.executeAndRestore(function() {
+ code = pre.querySelector("code");
+ wysihtml5.dom.replaceWithChildNodes(pre);
+ if (code) {
+ wysihtml5.dom.replaceWithChildNodes(code);
+ }
+ });
+ } else {
+ // Wrap in <pre><code>...</code></pre>
+ range = composer.selection.getRange();
+ selectedNodes = range.extractContents();
+ pre = composer.doc.createElement("pre");
+ code = composer.doc.createElement("code");
+
+ if (classname) {
+ code.className = classname;
+ }
+
+ pre.appendChild(code);
+ code.appendChild(selectedNodes);
+ range.insertNode(pre);
+ composer.selection.selectNode(pre);
+ }
+ },
+
+ state: function(composer) {
+ var selectedNode = composer.selection.getSelectedNode();
+ if (selectedNode && selectedNode.nodeName && selectedNode.nodeName == "PRE"&&
+ selectedNode.firstChild && selectedNode.firstChild.nodeName && selectedNode.firstChild.nodeName == "CODE") {
+ return selectedNode;
+ } else {
+ return wysihtml5.dom.getParentElement(selectedNode, { nodeName: "CODE" }) && wysihtml5.dom.getParentElement(selectedNode, { nodeName: "PRE" });
+ }
+ }
+};;/**
+ * formatInline scenarios for tag "B" (| = caret, |foo| = selected text)
+ *
+ * #1 caret in unformatted text:
+ * abcdefg|
+ * output:
+ * abcdefg<b>|</b>
+ *
+ * #2 unformatted text selected:
+ * abc|deg|h
+ * output:
+ * abc<b>|deg|</b>h
+ *
+ * #3 unformatted text selected across boundaries:
+ * ab|c <span>defg|h</span>
+ * output:
+ * ab<b>|c </b><span><b>defg</b>|h</span>
+ *
+ * #4 formatted text entirely selected
+ * <b>|abc|</b>
+ * output:
+ * |abc|
+ *
+ * #5 formatted text partially selected
+ * <b>ab|c|</b>
+ * output:
+ * <b>ab</b>|c|
+ *
+ * #6 formatted text selected across boundaries
+ * <span>ab|c</span> <b>de|fgh</b>
+ * output:
+ * <span>ab|c</span> de|<b>fgh</b>
+ */
+(function(wysihtml5) {
+ var // Treat <b> as <strong> and vice versa
+ ALIAS_MAPPING = {
+ "strong": "b",
+ "em": "i",
+ "b": "strong",
+ "i": "em"
+ },
+ htmlApplier = {};
+
+ function _getTagNames(tagName) {
+ var alias = ALIAS_MAPPING[tagName];
+ return alias ? [tagName.toLowerCase(), alias.toLowerCase()] : [tagName.toLowerCase()];
+ }
+
+ function _getApplier(tagName, className, classRegExp, cssStyle, styleRegExp, container) {
+ var identifier = tagName;
+
+ if (className) {
+ identifier += ":" + className;
+ }
+ if (cssStyle) {
+ identifier += ":" + cssStyle;
+ }
+
+ if (!htmlApplier[identifier]) {
+ htmlApplier[identifier] = new wysihtml5.selection.HTMLApplier(_getTagNames(tagName), className, classRegExp, true, cssStyle, styleRegExp, container);
+ }
+
+ return htmlApplier[identifier];
+ }
+
+ wysihtml5.commands.formatInline = {
+ exec: function(composer, command, tagName, className, classRegExp, cssStyle, styleRegExp, dontRestoreSelect, noCleanup) {
+ var range = composer.selection.createRange(),
+ ownRanges = composer.selection.getOwnRanges();
+
+ if (!ownRanges || ownRanges.length == 0) {
+ return false;
+ }
+ composer.selection.getSelection().removeAllRanges();
+
+ _getApplier(tagName, className, classRegExp, cssStyle, styleRegExp, composer.element).toggleRange(ownRanges);
+
+ if (!dontRestoreSelect) {
+ range.setStart(ownRanges[0].startContainer, ownRanges[0].startOffset);
+ range.setEnd(
+ ownRanges[ownRanges.length - 1].endContainer,
+ ownRanges[ownRanges.length - 1].endOffset
+ );
+ composer.selection.setSelection(range);
+ composer.selection.executeAndRestore(function() {
+ if (!noCleanup) {
+ composer.cleanUp();
+ }
+ }, true, true);
+ } else if (!noCleanup) {
+ composer.cleanUp();
+ }
+ },
+
+ // Executes so that if collapsed caret is in a state and executing that state it should unformat that state
+ // It is achieved by selecting the entire state element before executing.
+ // This works on built in contenteditable inline format commands
+ execWithToggle: function(composer, command, tagName, className, classRegExp, cssStyle, styleRegExp) {
+ var that = this;
+
+ if (this.state(composer, command, tagName, className, classRegExp, cssStyle, styleRegExp) &&
+ composer.selection.isCollapsed() &&
+ !composer.selection.caretIsLastInSelection() &&
+ !composer.selection.caretIsFirstInSelection()
+ ) {
+ var state_element = that.state(composer, command, tagName, className, classRegExp)[0];
+ composer.selection.executeAndRestoreRangy(function() {
+ var parent = state_element.parentNode;
+ composer.selection.selectNode(state_element, true);
+ wysihtml5.commands.formatInline.exec(composer, command, tagName, className, classRegExp, cssStyle, styleRegExp, true, true);
+ });
+ } else {
+ if (this.state(composer, command, tagName, className, classRegExp, cssStyle, styleRegExp) && !composer.selection.isCollapsed()) {
+ composer.selection.executeAndRestoreRangy(function() {
+ wysihtml5.commands.formatInline.exec(composer, command, tagName, className, classRegExp, cssStyle, styleRegExp, true, true);
+ });
+ } else {
+ wysihtml5.commands.formatInline.exec(composer, command, tagName, className, classRegExp, cssStyle, styleRegExp);
+ }
+ }
+ },
+
+ state: function(composer, command, tagName, className, classRegExp, cssStyle, styleRegExp) {
+ var doc = composer.doc,
+ aliasTagName = ALIAS_MAPPING[tagName] || tagName,
+ ownRanges, isApplied;
+
+ // Check whether the document contains a node with the desired tagName
+ if (!wysihtml5.dom.hasElementWithTagName(doc, tagName) &&
+ !wysihtml5.dom.hasElementWithTagName(doc, aliasTagName)) {
+ return false;
+ }
+
+ // Check whether the document contains a node with the desired className
+ if (className && !wysihtml5.dom.hasElementWithClassName(doc, className)) {
+ return false;
+ }
+
+ ownRanges = composer.selection.getOwnRanges();
+
+ if (!ownRanges || ownRanges.length === 0) {
+ return false;
+ }
+
+ isApplied = _getApplier(tagName, className, classRegExp, cssStyle, styleRegExp, composer.element).isAppliedToRange(ownRanges);
+
+ return (isApplied && isApplied.elements) ? isApplied.elements : false;
+ }
+ };
+})(wysihtml5);
+;(function(wysihtml5) {
+
+ wysihtml5.commands.insertBlockQuote = {
+ exec: function(composer, command) {
+ var state = this.state(composer, command),
+ endToEndParent = composer.selection.isEndToEndInNode(['H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'P']),
+ prevNode, nextNode;
+
+ composer.selection.executeAndRestore(function() {
+ if (state) {
+ if (composer.config.useLineBreaks) {
+ wysihtml5.dom.lineBreaks(state).add();
+ }
+ wysihtml5.dom.unwrap(state);
+ } else {
+ if (composer.selection.isCollapsed()) {
+ composer.selection.selectLine();
+ }
+
+ if (endToEndParent) {
+ var qouteEl = endToEndParent.ownerDocument.createElement('blockquote');
+ wysihtml5.dom.insert(qouteEl).after(endToEndParent);
+ qouteEl.appendChild(endToEndParent);
+ } else {
+ composer.selection.surround({nodeName: "blockquote"});
+ }
+ }
+ });
+ },
+ state: function(composer, command) {
+ var selectedNode = composer.selection.getSelectedNode(),
+ node = wysihtml5.dom.getParentElement(selectedNode, { nodeName: "BLOCKQUOTE" }, false, composer.element);
+
+ return (node) ? node : false;
+ }
+ };
+
+})(wysihtml5);;wysihtml5.commands.insertHTML = {
+ exec: function(composer, command, html) {
+ if (composer.commands.support(command)) {
+ composer.doc.execCommand(command, false, html);
+ } else {
+ composer.selection.insertHTML(html);
+ }
+ },
+
+ state: function() {
+ return false;
+ }
+};
+;(function(wysihtml5) {
+ var NODE_NAME = "IMG";
+
+ wysihtml5.commands.insertImage = {
+ /**
+ * Inserts an <img>
+ * If selection is already an image link, it removes it
+ *
+ * @example
+ * // either ...
+ * wysihtml5.commands.insertImage.exec(composer, "insertImage", "http://www.google.de/logo.jpg");
+ * // ... or ...
+ * wysihtml5.commands.insertImage.exec(composer, "insertImage", { src: "http://www.google.de/logo.jpg", title: "foo" });
+ */
+ exec: function(composer, command, value) {
+ value = typeof(value) === "object" ? value : { src: value };
+
+ var doc = composer.doc,
+ image = this.state(composer),
+ textNode,
+ parent;
+
+ if (image) {
+ // Image already selected, set the caret before it and delete it
+ composer.selection.setBefore(image);
+ parent = image.parentNode;
+ parent.removeChild(image);
+
+ // and it's parent <a> too if it hasn't got any other relevant child nodes
+ wysihtml5.dom.removeEmptyTextNodes(parent);
+ if (parent.nodeName === "A" && !parent.firstChild) {
+ composer.selection.setAfter(parent);
+ parent.parentNode.removeChild(parent);
+ }
+
+ // firefox and ie sometimes don't remove the image handles, even though the image got removed
+ wysihtml5.quirks.redraw(composer.element);
+ return;
+ }
+
+ image = doc.createElement(NODE_NAME);
+
+ for (var i in value) {
+ image.setAttribute(i === "className" ? "class" : i, value[i]);
+ }
+
+ composer.selection.insertNode(image);
+ if (wysihtml5.browser.hasProblemsSettingCaretAfterImg()) {
+ textNode = doc.createTextNode(wysihtml5.INVISIBLE_SPACE);
+ composer.selection.insertNode(textNode);
+ composer.selection.setAfter(textNode);
+ } else {
+ composer.selection.setAfter(image);
+ }
+ },
+
+ state: function(composer) {
+ var doc = composer.doc,
+ selectedNode,
+ text,
+ imagesInSelection;
+
+ if (!wysihtml5.dom.hasElementWithTagName(doc, NODE_NAME)) {
+ return false;
+ }
+
+ selectedNode = composer.selection.getSelectedNode();
+ if (!selectedNode) {
+ return false;
+ }
+
+ if (selectedNode.nodeName === NODE_NAME) {
+ // This works perfectly in IE
+ return selectedNode;
+ }
+
+ if (selectedNode.nodeType !== wysihtml5.ELEMENT_NODE) {
+ return false;
+ }
+
+ text = composer.selection.getText();
+ text = wysihtml5.lang.string(text).trim();
+ if (text) {
+ return false;
+ }
+
+ imagesInSelection = composer.selection.getNodes(wysihtml5.ELEMENT_NODE, function(node) {
+ return node.nodeName === "IMG";
+ });
+
+ if (imagesInSelection.length !== 1) {
+ return false;
+ }
+
+ return imagesInSelection[0];
+ }
+ };
+})(wysihtml5);
+;(function(wysihtml5) {
+ var LINE_BREAK = "<br>" + (wysihtml5.browser.needsSpaceAfterLineBreak() ? " " : "");
+
+ wysihtml5.commands.insertLineBreak = {
+ exec: function(composer, command) {
+ if (composer.commands.support(command)) {
+ composer.doc.execCommand(command, false, null);
+ if (!wysihtml5.browser.autoScrollsToCaret()) {
+ composer.selection.scrollIntoView();
+ }
+ } else {
+ composer.commands.exec("insertHTML", LINE_BREAK);
+ }
+ },
+
+ state: function() {
+ return false;
+ }
+ };
+})(wysihtml5);
+;wysihtml5.commands.insertOrderedList = {
+ exec: function(composer, command) {
+ wysihtml5.commands.insertList.exec(composer, command, "OL");
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.insertList.state(composer, command, "OL");
+ }
+};
+;wysihtml5.commands.insertUnorderedList = {
+ exec: function(composer, command) {
+ wysihtml5.commands.insertList.exec(composer, command, "UL");
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.insertList.state(composer, command, "UL");
+ }
+};
+;wysihtml5.commands.insertList = (function(wysihtml5) {
+
+ var isNode = function(node, name) {
+ if (node && node.nodeName) {
+ if (typeof name === 'string') {
+ name = [name];
+ }
+ for (var n = name.length; n--;) {
+ if (node.nodeName === name[n]) {
+ return true;
+ }
+ }
+ }
+ return false;
+ };
+
+ var findListEl = function(node, nodeName, composer) {
+ var ret = {
+ el: null,
+ other: false
+ };
+
+ if (node) {
+ var parentLi = wysihtml5.dom.getParentElement(node, { nodeName: "LI" }),
+ otherNodeName = (nodeName === "UL") ? "OL" : "UL";
+
+ if (isNode(node, nodeName)) {
+ ret.el = node;
+ } else if (isNode(node, otherNodeName)) {
+ ret = {
+ el: node,
+ other: true
+ };
+ } else if (parentLi) {
+ if (isNode(parentLi.parentNode, nodeName)) {
+ ret.el = parentLi.parentNode;
+ } else if (isNode(parentLi.parentNode, otherNodeName)) {
+ ret = {
+ el : parentLi.parentNode,
+ other: true
+ };
+ }
+ }
+ }
+
+ // do not count list elements outside of composer
+ if (ret.el && !composer.element.contains(ret.el)) {
+ ret.el = null;
+ }
+
+ return ret;
+ };
+
+ var handleSameTypeList = function(el, nodeName, composer) {
+ var otherNodeName = (nodeName === "UL") ? "OL" : "UL",
+ otherLists, innerLists;
+ // Unwrap list
+ // <ul><li>foo</li><li>bar</li></ul>
+ // becomes:
+ // foo<br>bar<br>
+ composer.selection.executeAndRestore(function() {
+ var otherLists = getListsInSelection(otherNodeName, composer);
+ if (otherLists.length) {
+ for (var l = otherLists.length; l--;) {
+ wysihtml5.dom.renameElement(otherLists[l], nodeName.toLowerCase());
+ }
+ } else {
+ innerLists = getListsInSelection(['OL', 'UL'], composer);
+ for (var i = innerLists.length; i--;) {
+ wysihtml5.dom.resolveList(innerLists[i], composer.config.useLineBreaks);
+ }
+ wysihtml5.dom.resolveList(el, composer.config.useLineBreaks);
+ }
+ });
+ };
+
+ var handleOtherTypeList = function(el, nodeName, composer) {
+ var otherNodeName = (nodeName === "UL") ? "OL" : "UL";
+ // Turn an ordered list into an unordered list
+ // <ol><li>foo</li><li>bar</li></ol>
+ // becomes:
+ // <ul><li>foo</li><li>bar</li></ul>
+ // Also rename other lists in selection
+ composer.selection.executeAndRestore(function() {
+ var renameLists = [el].concat(getListsInSelection(otherNodeName, composer));
+
+ // All selection inner lists get renamed too
+ for (var l = renameLists.length; l--;) {
+ wysihtml5.dom.renameElement(renameLists[l], nodeName.toLowerCase());
+ }
+ });
+ };
+
+ var getListsInSelection = function(nodeName, composer) {
+ var ranges = composer.selection.getOwnRanges(),
+ renameLists = [];
+
+ for (var r = ranges.length; r--;) {
+ renameLists = renameLists.concat(ranges[r].getNodes([1], function(node) {
+ return isNode(node, nodeName);
+ }));
+ }
+
+ return renameLists;
+ };
+
+ var createListFallback = function(nodeName, composer) {
+ // Fallback for Create list
+ composer.selection.executeAndRestoreRangy(function() {
+ var tempClassName = "_wysihtml5-temp-" + new Date().getTime(),
+ tempElement = composer.selection.deblockAndSurround({
+ "nodeName": "div",
+ "className": tempClassName
+ }),
+ isEmpty, list;
+
+ // This space causes new lists to never break on enter
+ var INVISIBLE_SPACE_REG_EXP = /\uFEFF/g;
+ tempElement.innerHTML = tempElement.innerHTML.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "");
+
+ if (tempElement) {
+ isEmpty = wysihtml5.lang.array(["", "<br>", wysihtml5.INVISIBLE_SPACE]).contains(tempElement.innerHTML);
+ list = wysihtml5.dom.convertToList(tempElement, nodeName.toLowerCase(), composer.parent.config.uneditableContainerClassname);
+ if (isEmpty) {
+ composer.selection.selectNode(list.querySelector("li"), true);
+ }
+ }
+ });
+ };
+
+ return {
+ exec: function(composer, command, nodeName) {
+ var doc = composer.doc,
+ cmd = (nodeName === "OL") ? "insertOrderedList" : "insertUnorderedList",
+ selectedNode = composer.selection.getSelectedNode(),
+ list = findListEl(selectedNode, nodeName, composer);
+
+ if (!list.el) {
+ if (composer.commands.support(cmd)) {
+ doc.execCommand(cmd, false, null);
+ } else {
+ createListFallback(nodeName, composer);
+ }
+ } else if (list.other) {
+ handleOtherTypeList(list.el, nodeName, composer);
+ } else {
+ handleSameTypeList(list.el, nodeName, composer);
+ }
+ },
+
+ state: function(composer, command, nodeName) {
+ var selectedNode = composer.selection.getSelectedNode(),
+ list = findListEl(selectedNode, nodeName, composer);
+
+ return (list.el && !list.other) ? list.el : false;
+ }
+ };
+
+})(wysihtml5);;wysihtml5.commands.italic = {
+ exec: function(composer, command) {
+ wysihtml5.commands.formatInline.execWithToggle(composer, command, "i");
+ },
+
+ state: function(composer, command) {
+ // element.ownerDocument.queryCommandState("italic") results:
+ // firefox: only <i>
+ // chrome: <i>, <em>, <blockquote>, ...
+ // ie: <i>, <em>
+ // opera: only <i>
+ return wysihtml5.commands.formatInline.state(composer, command, "i");
+ }
+};
+;(function(wysihtml5) {
+ var CLASS_NAME = "wysiwyg-text-align-center",
+ REG_EXP = /wysiwyg-text-align-[0-9a-z]+/g;
+
+ wysihtml5.commands.justifyCenter = {
+ exec: function(composer, command) {
+ return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", null, CLASS_NAME, REG_EXP);
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatBlock.state(composer, "formatBlock", null, CLASS_NAME, REG_EXP);
+ }
+ };
+})(wysihtml5);
+;(function(wysihtml5) {
+ var CLASS_NAME = "wysiwyg-text-align-left",
+ REG_EXP = /wysiwyg-text-align-[0-9a-z]+/g;
+
+ wysihtml5.commands.justifyLeft = {
+ exec: function(composer, command) {
+ return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", null, CLASS_NAME, REG_EXP);
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatBlock.state(composer, "formatBlock", null, CLASS_NAME, REG_EXP);
+ }
+ };
+})(wysihtml5);
+;(function(wysihtml5) {
+ var CLASS_NAME = "wysiwyg-text-align-right",
+ REG_EXP = /wysiwyg-text-align-[0-9a-z]+/g;
+
+ wysihtml5.commands.justifyRight = {
+ exec: function(composer, command) {
+ return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", null, CLASS_NAME, REG_EXP);
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatBlock.state(composer, "formatBlock", null, CLASS_NAME, REG_EXP);
+ }
+ };
+})(wysihtml5);
+;(function(wysihtml5) {
+ var CLASS_NAME = "wysiwyg-text-align-justify",
+ REG_EXP = /wysiwyg-text-align-[0-9a-z]+/g;
+
+ wysihtml5.commands.justifyFull = {
+ exec: function(composer, command) {
+ return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", null, CLASS_NAME, REG_EXP);
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatBlock.state(composer, "formatBlock", null, CLASS_NAME, REG_EXP);
+ }
+ };
+})(wysihtml5);
+;(function(wysihtml5) {
+ var STYLE_STR = "text-align: right;",
+ REG_EXP = /(\s|^)text-align\s*:\s*[^;\s]+;?/gi;
+
+ wysihtml5.commands.alignRightStyle = {
+ exec: function(composer, command) {
+ return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", null, null, null, STYLE_STR, REG_EXP);
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatBlock.state(composer, "formatBlock", null, null, null, STYLE_STR, REG_EXP);
+ }
+ };
+})(wysihtml5);
+;(function(wysihtml5) {
+ var STYLE_STR = "text-align: left;",
+ REG_EXP = /(\s|^)text-align\s*:\s*[^;\s]+;?/gi;
+
+ wysihtml5.commands.alignLeftStyle = {
+ exec: function(composer, command) {
+ return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", null, null, null, STYLE_STR, REG_EXP);
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatBlock.state(composer, "formatBlock", null, null, null, STYLE_STR, REG_EXP);
+ }
+ };
+})(wysihtml5);
+;(function(wysihtml5) {
+ var STYLE_STR = "text-align: center;",
+ REG_EXP = /(\s|^)text-align\s*:\s*[^;\s]+;?/gi;
+
+ wysihtml5.commands.alignCenterStyle = {
+ exec: function(composer, command) {
+ return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", null, null, null, STYLE_STR, REG_EXP);
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatBlock.state(composer, "formatBlock", null, null, null, STYLE_STR, REG_EXP);
+ }
+ };
+})(wysihtml5);
+;wysihtml5.commands.redo = {
+ exec: function(composer) {
+ return composer.undoManager.redo();
+ },
+
+ state: function(composer) {
+ return false;
+ }
+};
+;wysihtml5.commands.underline = {
+ exec: function(composer, command) {
+ wysihtml5.commands.formatInline.execWithToggle(composer, command, "u");
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatInline.state(composer, command, "u");
+ }
+};
+;wysihtml5.commands.undo = {
+ exec: function(composer) {
+ return composer.undoManager.undo();
+ },
+
+ state: function(composer) {
+ return false;
+ }
+};
+;wysihtml5.commands.createTable = {
+ exec: function(composer, command, value) {
+ var col, row, html;
+ if (value && value.cols && value.rows && parseInt(value.cols, 10) > 0 && parseInt(value.rows, 10) > 0) {
+ if (value.tableStyle) {
+ html = "<table style=\"" + value.tableStyle + "\">";
+ } else {
+ html = "<table>";
+ }
+ html += "<tbody>";
+ for (row = 0; row < value.rows; row ++) {
+ html += '<tr>';
+ for (col = 0; col < value.cols; col ++) {
+ html += "<td> </td>";
+ }
+ html += '</tr>';
+ }
+ html += "</tbody></table>";
+ composer.commands.exec("insertHTML", html);
+ //composer.selection.insertHTML(html);
+ }
+
+
+ },
+
+ state: function(composer, command) {
+ return false;
+ }
+};
+;wysihtml5.commands.mergeTableCells = {
+ exec: function(composer, command) {
+ if (composer.tableSelection && composer.tableSelection.start && composer.tableSelection.end) {
+ if (this.state(composer, command)) {
+ wysihtml5.dom.table.unmergeCell(composer.tableSelection.start);
+ } else {
+ wysihtml5.dom.table.mergeCellsBetween(composer.tableSelection.start, composer.tableSelection.end);
+ }
+ }
+ },
+
+ state: function(composer, command) {
+ if (composer.tableSelection) {
+ var start = composer.tableSelection.start,
+ end = composer.tableSelection.end;
+ if (start && end && start == end &&
+ ((
+ wysihtml5.dom.getAttribute(start, "colspan") &&
+ parseInt(wysihtml5.dom.getAttribute(start, "colspan"), 10) > 1
+ ) || (
+ wysihtml5.dom.getAttribute(start, "rowspan") &&
+ parseInt(wysihtml5.dom.getAttribute(start, "rowspan"), 10) > 1
+ ))
+ ) {
+ return [start];
+ }
+ }
+ return false;
+ }
+};
+;wysihtml5.commands.addTableCells = {
+ exec: function(composer, command, value) {
+ if (composer.tableSelection && composer.tableSelection.start && composer.tableSelection.end) {
+
+ // switches start and end if start is bigger than end (reverse selection)
+ var tableSelect = wysihtml5.dom.table.orderSelectionEnds(composer.tableSelection.start, composer.tableSelection.end);
+ if (value == "before" || value == "above") {
+ wysihtml5.dom.table.addCells(tableSelect.start, value);
+ } else if (value == "after" || value == "below") {
+ wysihtml5.dom.table.addCells(tableSelect.end, value);
+ }
+ setTimeout(function() {
+ composer.tableSelection.select(tableSelect.start, tableSelect.end);
+ },0);
+ }
+ },
+
+ state: function(composer, command) {
+ return false;
+ }
+};
+;wysihtml5.commands.deleteTableCells = {
+ exec: function(composer, command, value) {
+ if (composer.tableSelection && composer.tableSelection.start && composer.tableSelection.end) {
+ var tableSelect = wysihtml5.dom.table.orderSelectionEnds(composer.tableSelection.start, composer.tableSelection.end),
+ idx = wysihtml5.dom.table.indexOf(tableSelect.start),
+ selCell,
+ table = composer.tableSelection.table;
+
+ wysihtml5.dom.table.removeCells(tableSelect.start, value);
+ setTimeout(function() {
+ // move selection to next or previous if not present
+ selCell = wysihtml5.dom.table.findCell(table, idx);
+
+ if (!selCell){
+ if (value == "row") {
+ selCell = wysihtml5.dom.table.findCell(table, {
+ "row": idx.row - 1,
+ "col": idx.col
+ });
+ }
+
+ if (value == "column") {
+ selCell = wysihtml5.dom.table.findCell(table, {
+ "row": idx.row,
+ "col": idx.col - 1
+ });
+ }
+ }
+ if (selCell) {
+ composer.tableSelection.select(selCell, selCell);
+ }
+ }, 0);
+
+ }
+ },
+
+ state: function(composer, command) {
+ return false;
+ }
+};
+;wysihtml5.commands.indentList = {
+ exec: function(composer, command, value) {
+ var listEls = composer.selection.getSelectionParentsByTag('LI');
+ if (listEls) {
+ return this.tryToPushLiLevel(listEls, composer.selection);
+ }
+ return false;
+ },
+
+ state: function(composer, command) {
+ return false;
+ },
+
+ tryToPushLiLevel: function(liNodes, selection) {
+ var listTag, list, prevLi, liNode, prevLiList,
+ found = false;
+
+ selection.executeAndRestoreRangy(function() {
+
+ for (var i = liNodes.length; i--;) {
+ liNode = liNodes[i];
+ listTag = (liNode.parentNode.nodeName === 'OL') ? 'OL' : 'UL';
+ list = liNode.ownerDocument.createElement(listTag);
+ prevLi = wysihtml5.dom.domNode(liNode).prev({nodeTypes: [wysihtml5.ELEMENT_NODE]});
+ prevLiList = (prevLi) ? prevLi.querySelector('ul, ol') : null;
+
+ if (prevLi) {
+ if (prevLiList) {
+ prevLiList.appendChild(liNode);
+ } else {
+ list.appendChild(liNode);
+ prevLi.appendChild(list);
+ }
+ found = true;
+ }
+ }
+
+ });
+ return found;
+ }
+};
+;wysihtml5.commands.outdentList = {
+ exec: function(composer, command, value) {
+ var listEls = composer.selection.getSelectionParentsByTag('LI');
+ if (listEls) {
+ return this.tryToPullLiLevel(listEls, composer);
+ }
+ return false;
+ },
+
+ state: function(composer, command) {
+ return false;
+ },
+
+ tryToPullLiLevel: function(liNodes, composer) {
+ var listNode, outerListNode, outerLiNode, list, prevLi, liNode, afterList,
+ found = false,
+ that = this;
+
+ composer.selection.executeAndRestoreRangy(function() {
+
+ for (var i = liNodes.length; i--;) {
+ liNode = liNodes[i];
+ if (liNode.parentNode) {
+ listNode = liNode.parentNode;
+
+ if (listNode.tagName === 'OL' || listNode.tagName === 'UL') {
+ found = true;
+
+ outerListNode = wysihtml5.dom.getParentElement(listNode.parentNode, { nodeName: ['OL', 'UL']}, false, composer.element);
+ outerLiNode = wysihtml5.dom.getParentElement(listNode.parentNode, { nodeName: ['LI']}, false, composer.element);
+
+ if (outerListNode && outerLiNode) {
+
+ if (liNode.nextSibling) {
+ afterList = that.getAfterList(listNode, liNode);
+ liNode.appendChild(afterList);
+ }
+ outerListNode.insertBefore(liNode, outerLiNode.nextSibling);
+
+ } else {
+
+ if (liNode.nextSibling) {
+ afterList = that.getAfterList(listNode, liNode);
+ liNode.appendChild(afterList);
+ }
+
+ for (var j = liNode.childNodes.length; j--;) {
+ listNode.parentNode.insertBefore(liNode.childNodes[j], listNode.nextSibling);
+ }
+
+ listNode.parentNode.insertBefore(document.createElement('br'), listNode.nextSibling);
+ liNode.parentNode.removeChild(liNode);
+
+ }
+
+ // cleanup
+ if (listNode.childNodes.length === 0) {
+ listNode.parentNode.removeChild(listNode);
+ }
+ }
+ }
+ }
+
+ });
+ return found;
+ },
+
+ getAfterList: function(listNode, liNode) {
+ var nodeName = listNode.nodeName,
+ newList = document.createElement(nodeName);
+
+ while (liNode.nextSibling) {
+ newList.appendChild(liNode.nextSibling);
+ }
+ return newList;
+ }
+
+};;/**
+ * Undo Manager for wysihtml5
+ * slightly inspired by http://rniwa.com/editing/undomanager.html#the-undomanager-interface
+ */
+(function(wysihtml5) {
+ var Z_KEY = 90,
+ Y_KEY = 89,
+ BACKSPACE_KEY = 8,
+ DELETE_KEY = 46,
+ MAX_HISTORY_ENTRIES = 25,
+ DATA_ATTR_NODE = "data-wysihtml5-selection-node",
+ DATA_ATTR_OFFSET = "data-wysihtml5-selection-offset",
+ UNDO_HTML = '<span id="_wysihtml5-undo" class="_wysihtml5-temp">' + wysihtml5.INVISIBLE_SPACE + '</span>',
+ REDO_HTML = '<span id="_wysihtml5-redo" class="_wysihtml5-temp">' + wysihtml5.INVISIBLE_SPACE + '</span>',
+ dom = wysihtml5.dom;
+
+ function cleanTempElements(doc) {
+ var tempElement;
+ while (tempElement = doc.querySelector("._wysihtml5-temp")) {
+ tempElement.parentNode.removeChild(tempElement);
+ }
+ }
+
+ wysihtml5.UndoManager = wysihtml5.lang.Dispatcher.extend(
+ /** @scope wysihtml5.UndoManager.prototype */ {
+ constructor: function(editor) {
+ this.editor = editor;
+ this.composer = editor.composer;
+ this.element = this.composer.element;
+
+ this.position = 0;
+ this.historyStr = [];
+ this.historyDom = [];
+
+ this.transact();
+
+ this._observe();
+ },
+
+ _observe: function() {
+ var that = this,
+ doc = this.composer.sandbox.getDocument(),
+ lastKey;
+
+ // Catch CTRL+Z and CTRL+Y
+ dom.observe(this.element, "keydown", function(event) {
+ if (event.altKey || (!event.ctrlKey && !event.metaKey)) {
+ return;
+ }
+
+ var keyCode = event.keyCode,
+ isUndo = keyCode === Z_KEY && !event.shiftKey,
+ isRedo = (keyCode === Z_KEY && event.shiftKey) || (keyCode === Y_KEY);
+
+ if (isUndo) {
+ that.undo();
+ event.preventDefault();
+ } else if (isRedo) {
+ that.redo();
+ event.preventDefault();
+ }
+ });
+
+ // Catch delete and backspace
+ dom.observe(this.element, "keydown", function(event) {
+ var keyCode = event.keyCode;
+ if (keyCode === lastKey) {
+ return;
+ }
+
+ lastKey = keyCode;
+
+ if (keyCode === BACKSPACE_KEY || keyCode === DELETE_KEY) {
+ that.transact();
+ }
+ });
+
+ this.editor
+ .on("newword:composer", function() {
+ that.transact();
+ })
+
+ .on("beforecommand:composer", function() {
+ that.transact();
+ });
+ },
+
+ transact: function() {
+ var previousHtml = this.historyStr[this.position - 1],
+ currentHtml = this.composer.getValue(false, false),
+ composerIsVisible = this.element.offsetWidth > 0 && this.element.offsetHeight > 0,
+ range, node, offset, element, position;
+
+ if (currentHtml === previousHtml) {
+ return;
+ }
+
+ var length = this.historyStr.length = this.historyDom.length = this.position;
+ if (length > MAX_HISTORY_ENTRIES) {
+ this.historyStr.shift();
+ this.historyDom.shift();
+ this.position--;
+ }
+
+ this.position++;
+
+ if (composerIsVisible) {
+ // Do not start saving selection if composer is not visible
+ range = this.composer.selection.getRange();
+ node = (range && range.startContainer) ? range.startContainer : this.element;
+ offset = (range && range.startOffset) ? range.startOffset : 0;
+
+ if (node.nodeType === wysihtml5.ELEMENT_NODE) {
+ element = node;
+ } else {
+ element = node.parentNode;
+ position = this.getChildNodeIndex(element, node);
+ }
+
+ element.setAttribute(DATA_ATTR_OFFSET, offset);
+ if (typeof(position) !== "undefined") {
+ element.setAttribute(DATA_ATTR_NODE, position);
+ }
+ }
+
+ var clone = this.element.cloneNode(!!currentHtml);
+ this.historyDom.push(clone);
+ this.historyStr.push(currentHtml);
+
+ if (element) {
+ element.removeAttribute(DATA_ATTR_OFFSET);
+ element.removeAttribute(DATA_ATTR_NODE);
+ }
+
+ },
+
+ undo: function() {
+ this.transact();
+
+ if (!this.undoPossible()) {
+ return;
+ }
+
+ this.set(this.historyDom[--this.position - 1]);
+ this.editor.fire("undo:composer");
+ },
+
+ redo: function() {
+ if (!this.redoPossible()) {
+ return;
+ }
+
+ this.set(this.historyDom[++this.position - 1]);
+ this.editor.fire("redo:composer");
+ },
+
+ undoPossible: function() {
+ return this.position > 1;
+ },
+
+ redoPossible: function() {
+ return this.position < this.historyStr.length;
+ },
+
+ set: function(historyEntry) {
+ this.element.innerHTML = "";
+
+ var i = 0,
+ childNodes = historyEntry.childNodes,
+ length = historyEntry.childNodes.length;
+
+ for (; i<length; i++) {
+ this.element.appendChild(childNodes[i].cloneNode(true));
+ }
+
+ // Restore selection
+ var offset,
+ node,
+ position;
+
+ if (historyEntry.hasAttribute(DATA_ATTR_OFFSET)) {
+ offset = historyEntry.getAttribute(DATA_ATTR_OFFSET);
+ position = historyEntry.getAttribute(DATA_ATTR_NODE);
+ node = this.element;
+ } else {
+ node = this.element.querySelector("[" + DATA_ATTR_OFFSET + "]") || this.element;
+ offset = node.getAttribute(DATA_ATTR_OFFSET);
+ position = node.getAttribute(DATA_ATTR_NODE);
+ node.removeAttribute(DATA_ATTR_OFFSET);
+ node.removeAttribute(DATA_ATTR_NODE);
+ }
+
+ if (position !== null) {
+ node = this.getChildNodeByIndex(node, +position);
+ }
+
+ this.composer.selection.set(node, offset);
+ },
+
+ getChildNodeIndex: function(parent, child) {
+ var i = 0,
+ childNodes = parent.childNodes,
+ length = childNodes.length;
+ for (; i<length; i++) {
+ if (childNodes[i] === child) {
+ return i;
+ }
+ }
+ },
+
+ getChildNodeByIndex: function(parent, index) {
+ return parent.childNodes[index];
+ }
+ });
+})(wysihtml5);
+;/**
+ * TODO: the following methods still need unit test coverage
+ */
+wysihtml5.views.View = Base.extend(
+ /** @scope wysihtml5.views.View.prototype */ {
+ constructor: function(parent, textareaElement, config) {
+ this.parent = parent;
+ this.element = textareaElement;
+ this.config = config;
+ if (!this.config.noTextarea) {
+ this._observeViewChange();
+ }
+ },
+
+ _observeViewChange: function() {
+ var that = this;
+ this.parent.on("beforeload", function() {
+ that.parent.on("change_view", function(view) {
+ if (view === that.name) {
+ that.parent.currentView = that;
+ that.show();
+ // Using tiny delay here to make sure that the placeholder is set before focusing
+ setTimeout(function() { that.focus(); }, 0);
+ } else {
+ that.hide();
+ }
+ });
+ });
+ },
+
+ focus: function() {
+ if (this.element && this.element.ownerDocument && this.element.ownerDocument.querySelector(":focus") === this.element) {
+ return;
+ }
+
+ try { if(this.element) { this.element.focus(); } } catch(e) {}
+ },
+
+ hide: function() {
+ this.element.style.display = "none";
+ },
+
+ show: function() {
+ this.element.style.display = "";
+ },
+
+ disable: function() {
+ this.element.setAttribute("disabled", "disabled");
+ },
+
+ enable: function() {
+ this.element.removeAttribute("disabled");
+ }
+});
+;(function(wysihtml5) {
+ var dom = wysihtml5.dom,
+ browser = wysihtml5.browser;
+
+ wysihtml5.views.Composer = wysihtml5.views.View.extend(
+ /** @scope wysihtml5.views.Composer.prototype */ {
+ name: "composer",
+
+ // Needed for firefox in order to display a proper caret in an empty contentEditable
+ CARET_HACK: "<br>",
+
+ constructor: function(parent, editableElement, config) {
+ this.base(parent, editableElement, config);
+ if (!this.config.noTextarea) {
+ this.textarea = this.parent.textarea;
+ } else {
+ this.editableArea = editableElement;
+ }
+ if (this.config.contentEditableMode) {
+ this._initContentEditableArea();
+ } else {
+ this._initSandbox();
+ }
+ },
+
+ clear: function() {
+ this.element.innerHTML = browser.displaysCaretInEmptyContentEditableCorrectly() ? "" : this.CARET_HACK;
+ },
+
+ getValue: function(parse, clearInternals) {
+ var value = this.isEmpty() ? "" : wysihtml5.quirks.getCorrectInnerHTML(this.element);
+ if (parse !== false) {
+ value = this.parent.parse(value, (clearInternals === false) ? false : true);
+ }
+
+ return value;
+ },
+
+ setValue: function(html, parse) {
+ if (parse) {
+ html = this.parent.parse(html);
+ }
+
+ try {
+ this.element.innerHTML = html;
+ } catch (e) {
+ this.element.innerText = html;
+ }
+ },
+
+ cleanUp: function() {
+ this.parent.parse(this.element);
+ },
+
+ show: function() {
+ this.editableArea.style.display = this._displayStyle || "";
+
+ if (!this.config.noTextarea && !this.textarea.element.disabled) {
+ // Firefox needs this, otherwise contentEditable becomes uneditable
+ this.disable();
+ this.enable();
+ }
+ },
+
+ hide: function() {
+ this._displayStyle = dom.getStyle("display").from(this.editableArea);
+ if (this._displayStyle === "none") {
+ this._displayStyle = null;
+ }
+ this.editableArea.style.display = "none";
+ },
+
+ disable: function() {
+ this.parent.fire("disable:composer");
+ this.element.removeAttribute("contentEditable");
+ },
+
+ enable: function() {
+ this.parent.fire("enable:composer");
+ this.element.setAttribute("contentEditable", "true");
+ },
+
+ focus: function(setToEnd) {
+ // IE 8 fires the focus event after .focus()
+ // This is needed by our simulate_placeholder.js to work
+ // therefore we clear it ourselves this time
+ if (wysihtml5.browser.doesAsyncFocus() && this.hasPlaceholderSet()) {
+ this.clear();
+ }
+
+ this.base();
+
+ var lastChild = this.element.lastChild;
+ if (setToEnd && lastChild && this.selection) {
+ if (lastChild.nodeName === "BR") {
+ this.selection.setBefore(this.element.lastChild);
+ } else {
+ this.selection.setAfter(this.element.lastChild);
+ }
+ }
+ },
+
+ getTextContent: function() {
+ return dom.getTextContent(this.element);
+ },
+
+ hasPlaceholderSet: function() {
+ return this.getTextContent() == ((this.config.noTextarea) ? this.editableArea.getAttribute("data-placeholder") : this.textarea.element.getAttribute("placeholder")) && this.placeholderSet;
+ },
+
+ isEmpty: function() {
+ var innerHTML = this.element.innerHTML.toLowerCase();
+ return (/^(\s|<br>|<\/br>|<p>|<\/p>)*$/i).test(innerHTML) ||
+ innerHTML === "" ||
+ innerHTML === "<br>" ||
+ innerHTML === "<p></p>" ||
+ innerHTML === "<p><br></p>" ||
+ this.hasPlaceholderSet();
+ },
+
+ _initContentEditableArea: function() {
+ var that = this;
+
+ if (this.config.noTextarea) {
+ this.sandbox = new dom.ContentEditableArea(function() {
+ that._create();
+ }, {}, this.editableArea);
+ } else {
+ this.sandbox = new dom.ContentEditableArea(function() {
+ that._create();
+ });
+ this.editableArea = this.sandbox.getContentEditable();
+ dom.insert(this.editableArea).after(this.textarea.element);
+ this._createWysiwygFormField();
+ }
+ },
+
+ _initSandbox: function() {
+ var that = this;
+
+ this.sandbox = new dom.Sandbox(function() {
+ that._create();
+ }, {
+ stylesheets: this.config.stylesheets
+ });
+ this.editableArea = this.sandbox.getIframe();
+
+ var textareaElement = this.textarea.element;
+ dom.insert(this.editableArea).after(textareaElement);
+
+ this._createWysiwygFormField();
+ },
+
+ // Creates hidden field which tells the server after submit, that the user used an wysiwyg editor
+ _createWysiwygFormField: function() {
+ if (this.textarea.element.form) {
+ var hiddenField = document.createElement("input");
+ hiddenField.type = "hidden";
+ hiddenField.name = "_wysihtml5_mode";
+ hiddenField.value = 1;
+ dom.insert(hiddenField).after(this.textarea.element);
+ }
+ },
+
+ _create: function() {
+ var that = this;
+ this.doc = this.sandbox.getDocument();
+ this.element = (this.config.contentEditableMode) ? this.sandbox.getContentEditable() : this.doc.body;
+ if (!this.config.noTextarea) {
+ this.textarea = this.parent.textarea;
+ this.element.innerHTML = this.textarea.getValue(true, false);
+ } else {
+ this.cleanUp(); // cleans contenteditable on initiation as it may contain html
+ }
+
+ // Make sure our selection handler is ready
+ this.selection = new wysihtml5.Selection(this.parent, this.element, this.config.uneditableContainerClassname);
+
+ // Make sure commands dispatcher is ready
+ this.commands = new wysihtml5.Commands(this.parent);
+
+ if (!this.config.noTextarea) {
+ dom.copyAttributes([
+ "className", "spellcheck", "title", "lang", "dir", "accessKey"
+ ]).from(this.textarea.element).to(this.element);
+ }
+
+ dom.addClass(this.element, this.config.composerClassName);
+ //
+ // Make the editor look like the original textarea, by syncing styles
+ if (this.config.style && !this.config.contentEditableMode) {
+ this.style();
+ }
+
+ this.observe();
+
+ var name = this.config.name;
+ if (name) {
+ dom.addClass(this.element, name);
+ if (!this.config.contentEditableMode) { dom.addClass(this.editableArea, name); }
+ }
+
+ this.enable();
+
+ if (!this.config.noTextarea && this.textarea.element.disabled) {
+ this.disable();
+ }
+
+ // Simulate html5 placeholder attribute on contentEditable element
+ var placeholderText = typeof(this.config.placeholder) === "string"
+ ? this.config.placeholder
+ : ((this.config.noTextarea) ? this.editableArea.getAttribute("data-placeholder") : this.textarea.element.getAttribute("placeholder"));
+ if (placeholderText) {
+ dom.simulatePlaceholder(this.parent, this, placeholderText);
+ }
+
+ // Make sure that the browser avoids using inline styles whenever possible
+ this.commands.exec("styleWithCSS", false);
+
+ this._initAutoLinking();
+ this._initObjectResizing();
+ this._initUndoManager();
+ this._initLineBreaking();
+
+ // Simulate html5 autofocus on contentEditable element
+ // This doesn't work on IOS (5.1.1)
+ if (!this.config.noTextarea && (this.textarea.element.hasAttribute("autofocus") || document.querySelector(":focus") == this.textarea.element) && !browser.isIos()) {
+ setTimeout(function() { that.focus(true); }, 100);
+ }
+
+ // IE sometimes leaves a single paragraph, which can't be removed by the user
+ if (!browser.clearsContentEditableCorrectly()) {
+ wysihtml5.quirks.ensureProperClearing(this);
+ }
+
+ // Set up a sync that makes sure that textarea and editor have the same content
+ if (this.initSync && this.config.sync) {
+ this.initSync();
+ }
+
+ // Okay hide the textarea, we are ready to go
+ if (!this.config.noTextarea) { this.textarea.hide(); }
+
+ // Fire global (before-)load event
+ this.parent.fire("beforeload").fire("load");
+ },
+
+ _initAutoLinking: function() {
+ var that = this,
+ supportsDisablingOfAutoLinking = browser.canDisableAutoLinking(),
+ supportsAutoLinking = browser.doesAutoLinkingInContentEditable();
+ if (supportsDisablingOfAutoLinking) {
+ this.commands.exec("autoUrlDetect", false);
+ }
+
+ if (!this.config.autoLink) {
+ return;
+ }
+
+ // Only do the auto linking by ourselves when the browser doesn't support auto linking
+ // OR when he supports auto linking but we were able to turn it off (IE9+)
+ if (!supportsAutoLinking || (supportsAutoLinking && supportsDisablingOfAutoLinking)) {
+ this.parent.on("newword:composer", function() {
+ if (dom.getTextContent(that.element).match(dom.autoLink.URL_REG_EXP)) {
+ var nodeWithSelection = that.selection.getSelectedNode(),
+ uneditables = that.element.querySelectorAll("." + that.config.uneditableContainerClassname),
+ isInUneditable = false;
+
+ for (var i = uneditables.length; i--;) {
+ if (wysihtml5.dom.contains(uneditables[i], nodeWithSelection)) {
+ isInUneditable = true;
+ }
+ }
+
+ if (!isInUneditable) dom.autoLink(nodeWithSelection, [that.config.uneditableContainerClassname]);
+ }
+ });
+
+ dom.observe(this.element, "blur", function() {
+ dom.autoLink(that.element, [that.config.uneditableContainerClassname]);
+ });
+ }
+
+ // Assuming we have the following:
+ // <a href="http://www.google.de">http://www.google.de</a>
+ // If a user now changes the url in the innerHTML we want to make sure that
+ // it's synchronized with the href attribute (as long as the innerHTML is still a url)
+ var // Use a live NodeList to check whether there are any links in the document
+ links = this.sandbox.getDocument().getElementsByTagName("a"),
+ // The autoLink helper method reveals a reg exp to detect correct urls
+ urlRegExp = dom.autoLink.URL_REG_EXP,
+ getTextContent = function(element) {
+ var textContent = wysihtml5.lang.string(dom.getTextContent(element)).trim();
+ if (textContent.substr(0, 4) === "www.") {
+ textContent = "http://" + textContent;
+ }
+ return textContent;
+ };
+
+ dom.observe(this.element, "keydown", function(event) {
+ if (!links.length) {
+ return;
+ }
+
+ var selectedNode = that.selection.getSelectedNode(event.target.ownerDocument),
+ link = dom.getParentElement(selectedNode, { nodeName: "A" }, 4),
+ textContent;
+
+ if (!link) {
+ return;
+ }
+
+ textContent = getTextContent(link);
+ // keydown is fired before the actual content is changed
+ // therefore we set a timeout to change the href
+ setTimeout(function() {
+ var newTextContent = getTextContent(link);
+ if (newTextContent === textContent) {
+ return;
+ }
+
+ // Only set href when new href looks like a valid url
+ if (newTextContent.match(urlRegExp)) {
+ link.setAttribute("href", newTextContent);
+ }
+ }, 0);
+ });
+ },
+
+ _initObjectResizing: function() {
+ this.commands.exec("enableObjectResizing", true);
+
+ // IE sets inline styles after resizing objects
+ // The following lines make sure that the width/height css properties
+ // are copied over to the width/height attributes
+ if (browser.supportsEvent("resizeend")) {
+ var properties = ["width", "height"],
+ propertiesLength = properties.length,
+ element = this.element;
+
+ dom.observe(element, "resizeend", function(event) {
+ var target = event.target || event.srcElement,
+ style = target.style,
+ i = 0,
+ property;
+
+ if (target.nodeName !== "IMG") {
+ return;
+ }
+
+ for (; i<propertiesLength; i++) {
+ property = properties[i];
+ if (style[property]) {
+ target.setAttribute(property, parseInt(style[property], 10));
+ style[property] = "";
+ }
+ }
+
+ // After resizing IE sometimes forgets to remove the old resize handles
+ wysihtml5.quirks.redraw(element);
+ });
+ }
+ },
+
+ _initUndoManager: function() {
+ this.undoManager = new wysihtml5.UndoManager(this.parent);
+ },
+
+ _initLineBreaking: function() {
+ var that = this,
+ USE_NATIVE_LINE_BREAK_INSIDE_TAGS = ["LI", "P", "H1", "H2", "H3", "H4", "H5", "H6"],
+ LIST_TAGS = ["UL", "OL", "MENU"];
+
+ function adjust(selectedNode) {
+ var parentElement = dom.getParentElement(selectedNode, { nodeName: ["P", "DIV"] }, 2);
+ if (parentElement && dom.contains(that.element, parentElement)) {
+ that.selection.executeAndRestore(function() {
+ if (that.config.useLineBreaks) {
+ dom.replaceWithChildNodes(parentElement);
+ } else if (parentElement.nodeName !== "P") {
+ dom.renameElement(parentElement, "p");
+ }
+ });
+ }
+ }
+
+ if (!this.config.useLineBreaks) {
+ dom.observe(this.element, ["focus", "keydown"], function() {
+ if (that.isEmpty()) {
+ var paragraph = that.doc.createElement("P");
+ that.element.innerHTML = "";
+ that.element.appendChild(paragraph);
+ if (!browser.displaysCaretInEmptyContentEditableCorrectly()) {
+ paragraph.innerHTML = "<br>";
+ that.selection.setBefore(paragraph.firstChild);
+ } else {
+ that.selection.selectNode(paragraph, true);
+ }
+ }
+ });
+ }
+
+ // Under certain circumstances Chrome + Safari create nested <p> or <hX> tags after paste
+ // Inserting an invisible white space in front of it fixes the issue
+ // This is too hacky and causes selection not to replace content on paste in chrome
+ /* if (browser.createsNestedInvalidMarkupAfterPaste()) {
+ dom.observe(this.element, "paste", function(event) {
+ var invisibleSpace = that.doc.createTextNode(wysihtml5.INVISIBLE_SPACE);
+ that.selection.insertNode(invisibleSpace);
+ });
+ }*/
+
+
+ dom.observe(this.element, "keydown", function(event) {
+ var keyCode = event.keyCode;
+
+ if (event.shiftKey) {
+ return;
+ }
+
+ if (keyCode !== wysihtml5.ENTER_KEY && keyCode !== wysihtml5.BACKSPACE_KEY) {
+ return;
+ }
+ var blockElement = dom.getParentElement(that.selection.getSelectedNode(), { nodeName: USE_NATIVE_LINE_BREAK_INSIDE_TAGS }, 4);
+ if (blockElement) {
+ setTimeout(function() {
+ // Unwrap paragraph after leaving a list or a H1-6
+ var selectedNode = that.selection.getSelectedNode(),
+ list;
+
+ if (blockElement.nodeName === "LI") {
+ if (!selectedNode) {
+ return;
+ }
+
+ list = dom.getParentElement(selectedNode, { nodeName: LIST_TAGS }, 2);
+
+ if (!list) {
+ adjust(selectedNode);
+ }
+ }
+
+ if (keyCode === wysihtml5.ENTER_KEY && blockElement.nodeName.match(/^H[1-6]$/)) {
+ adjust(selectedNode);
+ }
+ }, 0);
+ return;
+ }
+
+ if (that.config.useLineBreaks && keyCode === wysihtml5.ENTER_KEY && !wysihtml5.browser.insertsLineBreaksOnReturn()) {
+ event.preventDefault();
+ that.commands.exec("insertLineBreak");
+
+ }
+ });
+ }
+ });
+})(wysihtml5);
+;(function(wysihtml5) {
+ var dom = wysihtml5.dom,
+ doc = document,
+ win = window,
+ HOST_TEMPLATE = doc.createElement("div"),
+ /**
+ * Styles to copy from textarea to the composer element
+ */
+ TEXT_FORMATTING = [
+ "background-color",
+ "color", "cursor",
+ "font-family", "font-size", "font-style", "font-variant", "font-weight",
+ "line-height", "letter-spacing",
+ "text-align", "text-decoration", "text-indent", "text-rendering",
+ "word-break", "word-wrap", "word-spacing"
+ ],
+ /**
+ * Styles to copy from textarea to the iframe
+ */
+ BOX_FORMATTING = [
+ "background-color",
+ "border-collapse",
+ "border-bottom-color", "border-bottom-style", "border-bottom-width",
+ "border-left-color", "border-left-style", "border-left-width",
+ "border-right-color", "border-right-style", "border-right-width",
+ "border-top-color", "border-top-style", "border-top-width",
+ "clear", "display", "float",
+ "margin-bottom", "margin-left", "margin-right", "margin-top",
+ "outline-color", "outline-offset", "outline-width", "outline-style",
+ "padding-left", "padding-right", "padding-top", "padding-bottom",
+ "position", "top", "left", "right", "bottom", "z-index",
+ "vertical-align", "text-align",
+ "-webkit-box-sizing", "-moz-box-sizing", "-ms-box-sizing", "box-sizing",
+ "-webkit-box-shadow", "-moz-box-shadow", "-ms-box-shadow","box-shadow",
+ "-webkit-border-top-right-radius", "-moz-border-radius-topright", "border-top-right-radius",
+ "-webkit-border-bottom-right-radius", "-moz-border-radius-bottomright", "border-bottom-right-radius",
+ "-webkit-border-bottom-left-radius", "-moz-border-radius-bottomleft", "border-bottom-left-radius",
+ "-webkit-border-top-left-radius", "-moz-border-radius-topleft", "border-top-left-radius",
+ "width", "height"
+ ],
+ ADDITIONAL_CSS_RULES = [
+ "html { height: 100%; }",
+ "body { height: 100%; padding: 1px 0 0 0; margin: -1px 0 0 0; }",
+ "body > p:first-child { margin-top: 0; }",
+ "._wysihtml5-temp { display: none; }",
+ wysihtml5.browser.isGecko ?
+ "body.placeholder { color: graytext !important; }" :
+ "body.placeholder { color: #a9a9a9 !important; }",
+ // Ensure that user see's broken images and can delete them
+ "img:-moz-broken { -moz-force-broken-image-icon: 1; height: 24px; width: 24px; }"
+ ];
+
+ /**
+ * With "setActive" IE offers a smart way of focusing elements without scrolling them into view:
+ * http://msdn.microsoft.com/en-us/library/ms536738(v=vs.85).aspx
+ *
+ * Other browsers need a more hacky way: (pssst don't tell my mama)
+ * In order to prevent the element being scrolled into view when focusing it, we simply
+ * move it out of the scrollable area, focus it, and reset it's position
+ */
+ var focusWithoutScrolling = function(element) {
+ if (element.setActive) {
+ // Following line could cause a js error when the textarea is invisible
+ // See https://github.com/xing/wysihtml5/issues/9
+ try { element.setActive(); } catch(e) {}
+ } else {
+ var elementStyle = element.style,
+ originalScrollTop = doc.documentElement.scrollTop || doc.body.scrollTop,
+ originalScrollLeft = doc.documentElement.scrollLeft || doc.body.scrollLeft,
+ originalStyles = {
+ position: elementStyle.position,
+ top: elementStyle.top,
+ left: elementStyle.left,
+ WebkitUserSelect: elementStyle.WebkitUserSelect
+ };
+
+ dom.setStyles({
+ position: "absolute",
+ top: "-99999px",
+ left: "-99999px",
+ // Don't ask why but temporarily setting -webkit-user-select to none makes the whole thing performing smoother
+ WebkitUserSelect: "none"
+ }).on(element);
+
+ element.focus();
+
+ dom.setStyles(originalStyles).on(element);
+
+ if (win.scrollTo) {
+ // Some browser extensions unset this method to prevent annoyances
+ // "Better PopUp Blocker" for Chrome http://code.google.com/p/betterpopupblocker/source/browse/trunk/blockStart.js#100
+ // Issue: http://code.google.com/p/betterpopupblocker/issues/detail?id=1
+ win.scrollTo(originalScrollLeft, originalScrollTop);
+ }
+ }
+ };
+
+
+ wysihtml5.views.Composer.prototype.style = function() {
+ var that = this,
+ originalActiveElement = doc.querySelector(":focus"),
+ textareaElement = this.textarea.element,
+ hasPlaceholder = textareaElement.hasAttribute("placeholder"),
+ originalPlaceholder = hasPlaceholder && textareaElement.getAttribute("placeholder"),
+ originalDisplayValue = textareaElement.style.display,
+ originalDisabled = textareaElement.disabled,
+ displayValueForCopying;
+
+ this.focusStylesHost = HOST_TEMPLATE.cloneNode(false);
+ this.blurStylesHost = HOST_TEMPLATE.cloneNode(false);
+ this.disabledStylesHost = HOST_TEMPLATE.cloneNode(false);
+
+ // Remove placeholder before copying (as the placeholder has an affect on the computed style)
+ if (hasPlaceholder) {
+ textareaElement.removeAttribute("placeholder");
+ }
+
+ if (textareaElement === originalActiveElement) {
+ textareaElement.blur();
+ }
+
+ // enable for copying styles
+ textareaElement.disabled = false;
+
+ // set textarea to display="none" to get cascaded styles via getComputedStyle
+ textareaElement.style.display = displayValueForCopying = "none";
+
+ if ((textareaElement.getAttribute("rows") && dom.getStyle("height").from(textareaElement) === "auto") ||
+ (textareaElement.getAttribute("cols") && dom.getStyle("width").from(textareaElement) === "auto")) {
+ textareaElement.style.display = displayValueForCopying = originalDisplayValue;
+ }
+
+ // --------- iframe styles (has to be set before editor styles, otherwise IE9 sets wrong fontFamily on blurStylesHost) ---------
+ dom.copyStyles(BOX_FORMATTING).from(textareaElement).to(this.editableArea).andTo(this.blurStylesHost);
+
+ // --------- editor styles ---------
+ dom.copyStyles(TEXT_FORMATTING).from(textareaElement).to(this.element).andTo(this.blurStylesHost);
+
+ // --------- apply standard rules ---------
+ dom.insertCSS(ADDITIONAL_CSS_RULES).into(this.element.ownerDocument);
+
+ // --------- :disabled styles ---------
+ textareaElement.disabled = true;
+ dom.copyStyles(BOX_FORMATTING).from(textareaElement).to(this.disabledStylesHost);
+ dom.copyStyles(TEXT_FORMATTING).from(textareaElement).to(this.disabledStylesHost);
+ textareaElement.disabled = originalDisabled;
+
+ // --------- :focus styles ---------
+ textareaElement.style.display = originalDisplayValue;
+ focusWithoutScrolling(textareaElement);
+ textareaElement.style.display = displayValueForCopying;
+
+ dom.copyStyles(BOX_FORMATTING).from(textareaElement).to(this.focusStylesHost);
+ dom.copyStyles(TEXT_FORMATTING).from(textareaElement).to(this.focusStylesHost);
+
+ // reset textarea
+ textareaElement.style.display = originalDisplayValue;
+
+ dom.copyStyles(["display"]).from(textareaElement).to(this.editableArea);
+
+ // Make sure that we don't change the display style of the iframe when copying styles oblur/onfocus
+ // this is needed for when the change_view event is fired where the iframe is hidden and then
+ // the blur event fires and re-displays it
+ var boxFormattingStyles = wysihtml5.lang.array(BOX_FORMATTING).without(["display"]);
+
+ // --------- restore focus ---------
+ if (originalActiveElement) {
+ originalActiveElement.focus();
+ } else {
+ textareaElement.blur();
+ }
+
+ // --------- restore placeholder ---------
+ if (hasPlaceholder) {
+ textareaElement.setAttribute("placeholder", originalPlaceholder);
+ }
+
+ // --------- Sync focus/blur styles ---------
+ this.parent.on("focus:composer", function() {
+ dom.copyStyles(boxFormattingStyles) .from(that.focusStylesHost).to(that.editableArea);
+ dom.copyStyles(TEXT_FORMATTING) .from(that.focusStylesHost).to(that.element);
+ });
+
+ this.parent.on("blur:composer", function() {
+ dom.copyStyles(boxFormattingStyles) .from(that.blurStylesHost).to(that.editableArea);
+ dom.copyStyles(TEXT_FORMATTING) .from(that.blurStylesHost).to(that.element);
+ });
+
+ this.parent.observe("disable:composer", function() {
+ dom.copyStyles(boxFormattingStyles) .from(that.disabledStylesHost).to(that.editableArea);
+ dom.copyStyles(TEXT_FORMATTING) .from(that.disabledStylesHost).to(that.element);
+ });
+
+ this.parent.observe("enable:composer", function() {
+ dom.copyStyles(boxFormattingStyles) .from(that.blurStylesHost).to(that.editableArea);
+ dom.copyStyles(TEXT_FORMATTING) .from(that.blurStylesHost).to(that.element);
+ });
+
+ return this;
+ };
+})(wysihtml5);
+;/**
+ * Taking care of events
+ * - Simulating 'change' event on contentEditable element
+ * - Handling drag & drop logic
+ * - Catch paste events
+ * - Dispatch proprietary newword:composer event
+ * - Keyboard shortcuts
+ */
+(function(wysihtml5) {
+ var dom = wysihtml5.dom,
+ browser = wysihtml5.browser,
+ /**
+ * Map keyCodes to query commands
+ */
+ shortcuts = {
+ "66": "bold", // B
+ "73": "italic", // I
+ "85": "underline" // U
+ };
+
+ // Adds multiple eventlisteners to target, bound to one callback
+ // TODO: If needed elsewhere make it part of wysihtml5.dom or sth
+ var addListeners = function (target, events, callback) {
+ for(var i = 0, max = events.length; i < max; i++) {
+ target.addEventListener(events[i], callback, false);
+ }
+ };
+
+ // Removes multiple eventlisteners from target, bound to one callback
+ // TODO: If needed elsewhere make it part of wysihtml5.dom or sth
+ var removeListeners = function (target, events, callback) {
+ for(var i = 0, max = events.length; i < max; i++) {
+ target.removeEventListener(events[i], callback, false);
+ }
+ };
+
+ var deleteAroundEditable = function(selection, uneditable, element) {
+ // merge node with previous node from uneditable
+ var prevNode = selection.getPreviousNode(uneditable, true),
+ curNode = selection.getSelectedNode();
+
+ if (curNode.nodeType !== 1 && curNode.parentNode !== element) { curNode = curNode.parentNode; }
+ if (prevNode) {
+ if (curNode.nodeType == 1) {
+ var first = curNode.firstChild;
+
+ if (prevNode.nodeType == 1) {
+ while (curNode.firstChild) {
+ prevNode.appendChild(curNode.firstChild);
+ }
+ } else {
+ while (curNode.firstChild) {
+ uneditable.parentNode.insertBefore(curNode.firstChild, uneditable);
+ }
+ }
+ if (curNode.parentNode) {
+ curNode.parentNode.removeChild(curNode);
+ }
+ selection.setBefore(first);
+ } else {
+ if (prevNode.nodeType == 1) {
+ prevNode.appendChild(curNode);
+ } else {
+ uneditable.parentNode.insertBefore(curNode, uneditable);
+ }
+ selection.setBefore(curNode);
+ }
+ }
+ };
+
+ var handleDeleteKeyPress = function(event, composer) {
+ var selection = composer.selection,
+ element = composer.element;
+
+ if (selection.isCollapsed()) {
+ if (selection.caretIsInTheBeginnig('LI')) {
+ event.preventDefault();
+ composer.commands.exec('outdentList');
+ } else if (selection.caretIsInTheBeginnig()) {
+ event.preventDefault();
+ } else {
+
+ if (selection.caretIsFirstInSelection() &&
+ selection.getPreviousNode() &&
+ selection.getPreviousNode().nodeName &&
+ (/^H\d$/gi).test(selection.getPreviousNode().nodeName)
+ ) {
+ var prevNode = selection.getPreviousNode();
+ event.preventDefault();
+ if ((/^\s*$/).test(prevNode.textContent || prevNode.innerText)) {
+ // heading is empty
+ prevNode.parentNode.removeChild(prevNode);
+ } else {
+ var range = prevNode.ownerDocument.createRange();
+ range.selectNodeContents(prevNode);
+ range.collapse(false);
+ selection.setSelection(range);
+ }
+ }
+
+ var beforeUneditable = selection.caretIsBeforeUneditable();
+ // Do a special delete if caret would delete uneditable
+ if (beforeUneditable) {
+ event.preventDefault();
+ // If customevents present notify element of being deleted
+ // TODO: Investigate if browser support can be extended
+ try {
+ var ev = new CustomEvent("wysihtml5:uneditable:delete");
+ beforeUneditable.dispatchEvent(ev);
+ } catch (err) {}
+ beforeUneditable.parentNode.removeChild(beforeUneditable);
+ }
+ }
+ } else {
+ if (selection.containsUneditable()) {
+ event.preventDefault();
+ selection.deleteContents();
+ }
+ }
+ };
+
+ var handleTabKeyDown = function(composer, element) {
+ if (!composer.selection.isCollapsed()) {
+ composer.selection.deleteContents();
+ } else if (composer.selection.caretIsInTheBeginnig('LI')) {
+ if (composer.commands.exec('indentList')) return;
+ }
+
+ // Is   close enough to tab. Could not find enough counter arguments for now.
+ composer.commands.exec("insertHTML", " ");
+ };
+
+ var handleDomNodeRemoved = function(event) {
+ if (this.domNodeRemovedInterval) {
+ clearInterval(domNodeRemovedInterval);
+ }
+ this.parent.fire("destroy:composer");
+ };
+
+ // Listens to "drop", "paste", "mouseup", "focus", "keyup" events and fires
+ var handleUserInteraction = function (event) {
+ this.parent.fire("beforeinteraction").fire("beforeinteraction:composer");
+ setTimeout((function() {
+ this.parent.fire("interaction").fire("interaction:composer");
+ }).bind(this), 0);
+ };
+
+ var handleFocus = function(event) {
+ this.parent.fire("focus", event).fire("focus:composer", event);
+
+ // Delay storing of state until all focus handler are fired
+ // especially the one which resets the placeholder
+ setTimeout((function() {
+ this.focusState = this.getValue(false, false);
+ }).bind(this), 0);
+ };
+
+ var handleBlur = function(event) {
+ if (this.focusState !== this.getValue(false, false)) {
+ //create change event if supported (all except IE8)
+ var changeevent = event;
+ if(typeof Object.create == 'function') {
+ changeevent = Object.create(event, { type: { value: 'change' } });
+ }
+ this.parent.fire("change", changeevent).fire("change:composer", changeevent);
+ }
+ this.parent.fire("blur", event).fire("blur:composer", event);
+ };
+
+ var handlePaste = function(event) {
+ this.parent.fire(event.type, event).fire(event.type + ":composer", event);
+ if (event.type === "paste") {
+ setTimeout((function() {
+ this.parent.fire("newword:composer");
+ }).bind(this), 0);
+ }
+ };
+
+ var handleCopy = function(event) {
+ if (this.config.copyedFromMarking) {
+ // If supported the copied source can be based directly on selection
+ // Very useful for webkit based browsers where copy will otherwise contain a lot of code and styles based on whatever and not actually in selection.
+ if (event.clipboardData) {
+ event.clipboardData.setData("text/html", this.config.copyedFromMarking + this.selection.getHtml());
+ event.clipboardData.setData("text/plain", this.selection.getPlainText());
+ event.preventDefault();
+ }
+ this.parent.fire(event.type, event).fire(event.type + ":composer", event);
+ }
+ };
+
+ var handleKeyUp = function(event) {
+ var keyCode = event.keyCode;
+ if (keyCode === wysihtml5.SPACE_KEY || keyCode === wysihtml5.ENTER_KEY) {
+ this.parent.fire("newword:composer");
+ }
+ };
+
+ var handleMouseDown = function(event) {
+ if (!browser.canSelectImagesInContentEditable()) {
+ // Make sure that images are selected when clicking on them
+ var target = event.target,
+ allImages = this.element.querySelectorAll('img'),
+ notMyImages = this.element.querySelectorAll('.' + this.config.uneditableContainerClassname + ' img'),
+ myImages = wysihtml5.lang.array(allImages).without(notMyImages);
+
+ if (target.nodeName === "IMG" && wysihtml5.lang.array(myImages).contains(target)) {
+ this.selection.selectNode(target);
+ }
+ }
+ };
+
+ // TODO: mouseover is not actually a foolproof and obvious place for this, must be changed as it modifies dom on random basis
+ // Shows url in tooltip when hovering links or images
+ var handleMouseOver = function(event) {
+ var titlePrefixes = {
+ IMG: "Image: ",
+ A: "Link: "
+ },
+ target = event.target,
+ nodeName = target.nodeName,
+ title;
+
+ if (nodeName !== "A" && nodeName !== "IMG") {
+ return;
+ }
+ if(!target.hasAttribute("title")){
+ title = titlePrefixes[nodeName] + (target.getAttribute("href") || target.getAttribute("src"));
+ target.setAttribute("title", title);
+ }
+ };
+
+ var handleClick = function(event) {
+ if (this.config.uneditableContainerClassname) {
+ // If uneditables is configured, makes clicking on uneditable move caret after clicked element (so it can be deleted like text)
+ // If uneditable needs text selection itself event.stopPropagation can be used to prevent this behaviour
+ var uneditable = wysihtml5.dom.getParentElement(event.target, { className: this.config.uneditableContainerClassname }, false, this.element);
+ if (uneditable) {
+ this.selection.setAfter(uneditable);
+ }
+ }
+ };
+
+ var handleDrop = function(event) {
+ if (!browser.canSelectImagesInContentEditable()) {
+ // TODO: if I knew how to get dropped elements list from event I could limit it to only IMG element case
+ setTimeout((function() {
+ this.selection.getSelection().removeAllRanges();
+ }).bind(this), 0);
+ }
+ };
+
+ var handleKeyDown = function(event) {
+ var keyCode = event.keyCode,
+ command = shortcuts[keyCode],
+ target, parent;
+
+ // Shortcut logic
+ if ((event.ctrlKey || event.metaKey) && !event.altKey && command) {
+ this.commands.exec(command);
+ event.preventDefault();
+ }
+
+ if (keyCode === wysihtml5.BACKSPACE_KEY) {
+ // Delete key override for special cases
+ handleDeleteKeyPress(event, this);
+ }
+
+ // Make sure that when pressing backspace/delete on selected images deletes the image and it's anchor
+ if (keyCode === wysihtml5.BACKSPACE_KEY || keyCode === wysihtml5.DELETE_KEY) {
+ target = this.selection.getSelectedNode(true);
+ if (target && target.nodeName === "IMG") {
+ event.preventDefault();
+ parent = target.parentNode;
+ parent.removeChild(target);// delete the <img>
+ // And it's parent <a> too if it hasn't got any other child nodes
+ if (parent.nodeName === "A" && !parent.firstChild) {
+ parent.parentNode.removeChild(parent);
+ }
+ setTimeout(function() {
+ wysihtml5.quirks.redraw(element);
+ }, 0);
+ }
+ }
+
+ if (this.config.handleTabKey && keyCode === wysihtml5.TAB_KEY) {
+ // TAB key handling
+ event.preventDefault();
+ handleTabKeyDown(this, element);
+ }
+
+ };
+
+ var handleIframeFocus = function(event) {
+ setTimeout((function() {
+ if (this.doc.querySelector(":focus") !== this.element) {
+ this.focus();
+ }
+ }).bind(this), 0);
+ };
+
+ var handleIframeBlur = function(event) {
+ setTimeout((function() {
+ this.selection.getSelection().removeAllRanges();
+ }).bind(this), 0);
+ };
+
+ // Table management
+ // If present enableObjectResizing and enableInlineTableEditing command should be called with false to prevent native table handlers
+ var initTableHandling = function () {
+ var hideHandlers = function () {
+ this.doc.execCommand("enableObjectResizing", false, "false");
+ this.doc.execCommand("enableInlineTableEditing", false, "false");
+ },
+ iframeInitiator = (function() {
+ hideHandlers.call(this);
+ removeListeners(this.sandbox.getIframe(), ["focus", "mouseup", "mouseover"], iframeInitiator);
+ }).bind(this);
+
+ if( this.doc.execCommand &&
+ wysihtml5.browser.supportsCommand(this.doc, "enableObjectResizing") &&
+ wysihtml5.browser.supportsCommand(this.doc, "enableInlineTableEditing"))
+ {
+ if (this.sandbox.getIframe) {
+ addListeners(this.sandbox.getIframe(), ["focus", "mouseup", "mouseover"], iframeInitiator);
+ } else {
+ setTimeout((function() {
+ hideHandlers.call(this);
+ }).bind(this), 0);
+ }
+ }
+ this.tableSelection = wysihtml5.quirks.tableCellsSelection(this.element, this.parent);
+ };
+
+ wysihtml5.views.Composer.prototype.observe = function() {
+ var that = this,
+ container = (this.sandbox.getIframe) ? this.sandbox.getIframe() : this.sandbox.getContentEditable(),
+ element = this.element,
+ focusBlurElement = (browser.supportsEventsInIframeCorrectly() || this.sandbox.getContentEditable) ? this.element : this.sandbox.getWindow();
+
+ this.focusState = this.getValue(false, false);
+
+ // --------- destroy:composer event ---------
+ container.addEventListener(["DOMNodeRemoved"], handleDomNodeRemoved.bind(this), false);
+
+ // DOMNodeRemoved event is not supported in IE 8
+ // TODO: try to figure out a polyfill style fix, so it could be transferred to polyfills and removed if ie8 is not needed
+ if (!browser.supportsMutationEvents()) {
+ this.domNodeRemovedInterval = setInterval(function() {
+ if (!dom.contains(document.documentElement, container)) {
+ handleDomNodeRemoved.call(this);
+ }
+ }, 250);
+ }
+
+ // --------- User interactions --
+ if (this.config.handleTables) {
+ // If handleTables option is true, table handling functions are bound
+ initTableHandling.call(this);
+ }
+
+ addListeners(focusBlurElement, ["drop", "paste", "mouseup", "focus", "keyup"], handleUserInteraction.bind(this));
+ focusBlurElement.addEventListener("focus", handleFocus.bind(this), false);
+ focusBlurElement.addEventListener("blur", handleBlur.bind(this), false);
+
+ addListeners(this.element, ["drop", "paste", "beforepaste"], handlePaste.bind(this), false);
+ this.element.addEventListener("copy", handleCopy.bind(this), false);
+ this.element.addEventListener("mousedown", handleMouseDown.bind(this), false);
+ this.element.addEventListener("mouseover", handleMouseOver.bind(this), false);
+ this.element.addEventListener("click", handleClick.bind(this), false);
+ this.element.addEventListener("drop", handleDrop.bind(this), false);
+ this.element.addEventListener("keyup", handleKeyUp.bind(this), false);
+ this.element.addEventListener("keydown", handleKeyDown.bind(this), false);
+
+ this.element.addEventListener("dragenter", (function() {
+ this.parent.fire("unset_placeholder");
+ }).bind(this), false);
+
+ // --------- IE 8+9 focus the editor when the iframe is clicked (without actually firing the 'focus' event on the <body>) ---------
+ if (!this.config.contentEditableMode && browser.hasIframeFocusIssue()) {
+ container.addEventListener("focus", handleIframeFocus.bind(this), false);
+ container.addEventListener("blur", handleIframeBlur.bind(this), false);
+ }
+
+ };
+})(wysihtml5);
+;/**
+ * Class that takes care that the value of the composer and the textarea is always in sync
+ */
+(function(wysihtml5) {
+ var INTERVAL = 400;
+
+ wysihtml5.views.Synchronizer = Base.extend(
+ /** @scope wysihtml5.views.Synchronizer.prototype */ {
+
+ constructor: function(editor, textarea, composer) {
+ this.editor = editor;
+ this.textarea = textarea;
+ this.composer = composer;
+
+ this._observe();
+ },
+
+ /**
+ * Sync html from composer to textarea
+ * Takes care of placeholders
+ * @param {Boolean} shouldParseHtml Whether the html should be sanitized before inserting it into the textarea
+ */
+ fromComposerToTextarea: function(shouldParseHtml) {
+ this.textarea.setValue(wysihtml5.lang.string(this.composer.getValue(false, false)).trim(), shouldParseHtml);
+ },
+
+ /**
+ * Sync value of textarea to composer
+ * Takes care of placeholders
+ * @param {Boolean} shouldParseHtml Whether the html should be sanitized before inserting it into the composer
+ */
+ fromTextareaToComposer: function(shouldParseHtml) {
+ var textareaValue = this.textarea.getValue(false, false);
+ if (textareaValue) {
+ this.composer.setValue(textareaValue, shouldParseHtml);
+ } else {
+ this.composer.clear();
+ this.editor.fire("set_placeholder");
+ }
+ },
+
+ /**
+ * Invoke syncing based on view state
+ * @param {Boolean} shouldParseHtml Whether the html should be sanitized before inserting it into the composer/textarea
+ */
+ sync: function(shouldParseHtml) {
+ if (this.editor.currentView.name === "textarea") {
+ this.fromTextareaToComposer(shouldParseHtml);
+ } else {
+ this.fromComposerToTextarea(shouldParseHtml);
+ }
+ },
+
+ /**
+ * Initializes interval-based syncing
+ * also makes sure that on-submit the composer's content is synced with the textarea
+ * immediately when the form gets submitted
+ */
+ _observe: function() {
+ var interval,
+ that = this,
+ form = this.textarea.element.form,
+ startInterval = function() {
+ interval = setInterval(function() { that.fromComposerToTextarea(); }, INTERVAL);
+ },
+ stopInterval = function() {
+ clearInterval(interval);
+ interval = null;
+ };
+
+ startInterval();
+
+ if (form) {
+ // If the textarea is in a form make sure that after onreset and onsubmit the composer
+ // has the correct state
+ wysihtml5.dom.observe(form, "submit", function() {
+ that.sync(true);
+ });
+ wysihtml5.dom.observe(form, "reset", function() {
+ setTimeout(function() { that.fromTextareaToComposer(); }, 0);
+ });
+ }
+
+ this.editor.on("change_view", function(view) {
+ if (view === "composer" && !interval) {
+ that.fromTextareaToComposer(true);
+ startInterval();
+ } else if (view === "textarea") {
+ that.fromComposerToTextarea(true);
+ stopInterval();
+ }
+ });
+
+ this.editor.on("destroy:composer", stopInterval);
+ }
+ });
+})(wysihtml5);
+;wysihtml5.views.Textarea = wysihtml5.views.View.extend(
+ /** @scope wysihtml5.views.Textarea.prototype */ {
+ name: "textarea",
+
+ constructor: function(parent, textareaElement, config) {
+ this.base(parent, textareaElement, config);
+
+ this._observe();
+ },
+
+ clear: function() {
+ this.element.value = "";
+ },
+
+ getValue: function(parse) {
+ var value = this.isEmpty() ? "" : this.element.value;
+ if (parse !== false) {
+ value = this.parent.parse(value);
+ }
+ return value;
+ },
+
+ setValue: function(html, parse) {
+ if (parse) {
+ html = this.parent.parse(html);
+ }
+ this.element.value = html;
+ },
+
+ cleanUp: function() {
+ var html = this.parent.parse(this.element.value);
+ this.element.value = html;
+ },
+
+ hasPlaceholderSet: function() {
+ var supportsPlaceholder = wysihtml5.browser.supportsPlaceholderAttributeOn(this.element),
+ placeholderText = this.element.getAttribute("placeholder") || null,
+ value = this.element.value,
+ isEmpty = !value;
+ return (supportsPlaceholder && isEmpty) || (value === placeholderText);
+ },
+
+ isEmpty: function() {
+ return !wysihtml5.lang.string(this.element.value).trim() || this.hasPlaceholderSet();
+ },
+
+ _observe: function() {
+ var element = this.element,
+ parent = this.parent,
+ eventMapping = {
+ focusin: "focus",
+ focusout: "blur"
+ },
+ /**
+ * Calling focus() or blur() on an element doesn't synchronously trigger the attached focus/blur events
+ * This is the case for focusin and focusout, so let's use them whenever possible, kkthxbai
+ */
+ events = wysihtml5.browser.supportsEvent("focusin") ? ["focusin", "focusout", "change"] : ["focus", "blur", "change"];
+
+ parent.on("beforeload", function() {
+ wysihtml5.dom.observe(element, events, function(event) {
+ var eventName = eventMapping[event.type] || event.type;
+ parent.fire(eventName).fire(eventName + ":textarea");
+ });
+
+ wysihtml5.dom.observe(element, ["paste", "drop"], function() {
+ setTimeout(function() { parent.fire("paste").fire("paste:textarea"); }, 0);
+ });
+ });
+ }
+});
+;/**
+ * WYSIHTML5 Editor
+ *
+ * @param {Element} editableElement Reference to the textarea which should be turned into a rich text interface
+ * @param {Object} [config] See defaultConfig object below for explanation of each individual config option
+ *
+ * @events
+ * load
+ * beforeload (for internal use only)
+ * focus
+ * focus:composer
+ * focus:textarea
+ * blur
+ * blur:composer
+ * blur:textarea
+ * change
+ * change:composer
+ * change:textarea
+ * paste
+ * paste:composer
+ * paste:textarea
+ * newword:composer
+ * destroy:composer
+ * undo:composer
+ * redo:composer
+ * beforecommand:composer
+ * aftercommand:composer
+ * enable:composer
+ * disable:composer
+ * change_view
+ */
+(function(wysihtml5) {
+ var undef;
+
+ var defaultConfig = {
+ // Give the editor a name, the name will also be set as class name on the iframe and on the iframe's body
+ name: undef,
+ // Whether the editor should look like the textarea (by adopting styles)
+ style: true,
+ // Id of the toolbar element, pass falsey value if you don't want any toolbar logic
+ toolbar: undef,
+ // Whether toolbar is displayed after init by script automatically.
+ // Can be set to false if toolobar is set to display only on editable area focus
+ showToolbarAfterInit: true,
+ // Whether urls, entered by the user should automatically become clickable-links
+ autoLink: true,
+ // Includes table editing events and cell selection tracking
+ handleTables: true,
+ // Tab key inserts tab into text as default behaviour. It can be disabled to regain keyboard navigation
+ handleTabKey: true,
+ // Object which includes parser rules to apply when html gets cleaned
+ // See parser_rules/*.js for examples
+ parserRules: { tags: { br: {}, span: {}, div: {}, p: {} }, classes: {} },
+ // Object which includes parser when the user inserts content via copy & paste. If null parserRules will be used instead
+ pasteParserRulesets: null,
+ // Parser method to use when the user inserts content
+ parser: wysihtml5.dom.parse,
+ // Class name which should be set on the contentEditable element in the created sandbox iframe, can be styled via the 'stylesheets' option
+ composerClassName: "wysihtml5-editor",
+ // Class name to add to the body when the wysihtml5 editor is supported
+ bodyClassName: "wysihtml5-supported",
+ // By default wysihtml5 will insert a <br> for line breaks, set this to false to use <p>
+ useLineBreaks: true,
+ // Array (or single string) of stylesheet urls to be loaded in the editor's iframe
+ stylesheets: [],
+ // Placeholder text to use, defaults to the placeholder attribute on the textarea element
+ placeholderText: undef,
+ // Whether the rich text editor should be rendered on touch devices (wysihtml5 >= 0.3.0 comes with basic support for iOS 5)
+ supportTouchDevices: true,
+ // Whether senseless <span> elements (empty or without attributes) should be removed/replaced with their content
+ cleanUp: true,
+ // Whether to use div instead of secure iframe
+ contentEditableMode: false,
+ // Classname of container that editor should not touch and pass through
+ // Pass false to disable
+ uneditableContainerClassname: "wysihtml5-uneditable-container",
+ // Browsers that support copied source handling will get a marking of the origin of the copied source (for determinig code cleanup rules on paste)
+ // Also copied source is based directly on selection -
+ // (very useful for webkit based browsers where copy will otherwise contain a lot of code and styles based on whatever and not actually in selection).
+ // If falsy value is passed source override is also disabled
+ copyedFromMarking: '<meta name="copied-from" content="wysihtml5">'
+ };
+
+ wysihtml5.Editor = wysihtml5.lang.Dispatcher.extend(
+ /** @scope wysihtml5.Editor.prototype */ {
+ constructor: function(editableElement, config) {
+ this.editableElement = typeof(editableElement) === "string" ? document.getElementById(editableElement) : editableElement;
+ this.config = wysihtml5.lang.object({}).merge(defaultConfig).merge(config).get();
+ this._isCompatible = wysihtml5.browser.supported();
+
+ if (this.editableElement.nodeName.toLowerCase() != "textarea") {
+ this.config.contentEditableMode = true;
+ this.config.noTextarea = true;
+ }
+ if (!this.config.noTextarea) {
+ this.textarea = new wysihtml5.views.Textarea(this, this.editableElement, this.config);
+ this.currentView = this.textarea;
+ }
+
+ // Sort out unsupported/unwanted browsers here
+ if (!this._isCompatible || (!this.config.supportTouchDevices && wysihtml5.browser.isTouchDevice())) {
+ var that = this;
+ setTimeout(function() { that.fire("beforeload").fire("load"); }, 0);
+ return;
+ }
+
+ // Add class name to body, to indicate that the editor is supported
+ wysihtml5.dom.addClass(document.body, this.config.bodyClassName);
+
+ this.composer = new wysihtml5.views.Composer(this, this.editableElement, this.config);
+ this.currentView = this.composer;
+
+ if (typeof(this.config.parser) === "function") {
+ this._initParser();
+ }
+
+ this.on("beforeload", this.handleBeforeLoad);
+ },
+
+ handleBeforeLoad: function() {
+ if (!this.config.noTextarea) {
+ this.synchronizer = new wysihtml5.views.Synchronizer(this, this.textarea, this.composer);
+ }
+ if (this.config.toolbar) {
+ this.toolbar = new wysihtml5.toolbar.Toolbar(this, this.config.toolbar, this.config.showToolbarAfterInit);
+ }
+ },
+
+ isCompatible: function() {
+ return this._isCompatible;
+ },
+
+ clear: function() {
+ this.currentView.clear();
+ return this;
+ },
+
+ getValue: function(parse, clearInternals) {
+ return this.currentView.getValue(parse, clearInternals);
+ },
+
+ setValue: function(html, parse) {
+ this.fire("unset_placeholder");
+
+ if (!html) {
+ return this.clear();
+ }
+
+ this.currentView.setValue(html, parse);
+ return this;
+ },
+
+ cleanUp: function() {
+ this.currentView.cleanUp();
+ },
+
+ focus: function(setToEnd) {
+ this.currentView.focus(setToEnd);
+ return this;
+ },
+
+ /**
+ * Deactivate editor (make it readonly)
+ */
+ disable: function() {
+ this.currentView.disable();
+ return this;
+ },
+
+ /**
+ * Activate editor
+ */
+ enable: function() {
+ this.currentView.enable();
+ return this;
+ },
+
+ isEmpty: function() {
+ return this.currentView.isEmpty();
+ },
+
+ hasPlaceholderSet: function() {
+ return this.currentView.hasPlaceholderSet();
+ },
+
+ parse: function(htmlOrElement, clearInternals) {
+ var parseContext = (this.config.contentEditableMode) ? document : ((this.composer) ? this.composer.sandbox.getDocument() : null);
+ var returnValue = this.config.parser(htmlOrElement, {
+ "rules": this.config.parserRules,
+ "cleanUp": this.config.cleanUp,
+ "context": parseContext,
+ "uneditableClass": this.config.uneditableContainerClassname,
+ "clearInternals" : clearInternals
+ });
+ if (typeof(htmlOrElement) === "object") {
+ wysihtml5.quirks.redraw(htmlOrElement);
+ }
+ return returnValue;
+ },
+
+ /**
+ * Prepare html parser logic
+ * - Observes for paste and drop
+ */
+ _initParser: function() {
+ var that = this,
+ oldHtml,
+ cleanHtml;
+
+ if (wysihtml5.browser.supportsModenPaste()) {
+ this.on("paste:composer", function(event) {
+ event.preventDefault();
+ oldHtml = wysihtml5.dom.getPastedHtml(event);
+ if (oldHtml) {
+ that._cleanAndPaste(oldHtml);
+ }
+ });
+
+ } else {
+ this.on("beforepaste:composer", function(event) {
+ event.preventDefault();
+ wysihtml5.dom.getPastedHtmlWithDiv(that.composer, function(pastedHTML) {
+ if (pastedHTML) {
+ that._cleanAndPaste(pastedHTML);
+ }
+ });
+ });
+
+ }
+ },
+
+ _cleanAndPaste: function (oldHtml) {
+ var cleanHtml = wysihtml5.quirks.cleanPastedHTML(oldHtml, {
+ "referenceNode": this.composer.element,
+ "rules": this.config.pasteParserRulesets || [{"set": this.config.parserRules}],
+ "uneditableClass": this.config.uneditableContainerClassname
+ });
+ this.composer.selection.deleteContents();
+ this.composer.selection.insertHTML(cleanHtml);
+ }
+ });
+})(wysihtml5);
+;/**
+ * Toolbar Dialog
+ *
+ * @param {Element} link The toolbar link which causes the dialog to show up
+ * @param {Element} container The dialog container
+ *
+ * @example
+ * <!-- Toolbar link -->
+ * <a data-wysihtml5-command="insertImage">insert an image</a>
+ *
+ * <!-- Dialog -->
+ * <div data-wysihtml5-dialog="insertImage" style="display: none;">
+ * <label>
+ * URL: <input data-wysihtml5-dialog-field="src" value="http://">
+ * </label>
+ * <label>
+ * Alternative text: <input data-wysihtml5-dialog-field="alt" value="">
+ * </label>
+ * </div>
+ *
+ * <script>
+ * var dialog = new wysihtml5.toolbar.Dialog(
+ * document.querySelector("[data-wysihtml5-command='insertImage']"),
+ * document.querySelector("[data-wysihtml5-dialog='insertImage']")
+ * );
+ * dialog.observe("save", function(attributes) {
+ * // do something
+ * });
+ * </script>
+ */
+(function(wysihtml5) {
+ var dom = wysihtml5.dom,
+ CLASS_NAME_OPENED = "wysihtml5-command-dialog-opened",
+ SELECTOR_FORM_ELEMENTS = "input, select, textarea",
+ SELECTOR_FIELDS = "[data-wysihtml5-dialog-field]",
+ ATTRIBUTE_FIELDS = "data-wysihtml5-dialog-field";
+
+
+ wysihtml5.toolbar.Dialog = wysihtml5.lang.Dispatcher.extend(
+ /** @scope wysihtml5.toolbar.Dialog.prototype */ {
+ constructor: function(link, container) {
+ this.link = link;
+ this.container = container;
+ },
+
+ _observe: function() {
+ if (this._observed) {
+ return;
+ }
+
+ var that = this,
+ callbackWrapper = function(event) {
+ var attributes = that._serialize();
+ if (attributes == that.elementToChange) {
+ that.fire("edit", attributes);
+ } else {
+ that.fire("save", attributes);
+ }
+ that.hide();
+ event.preventDefault();
+ event.stopPropagation();
+ };
+
+ dom.observe(that.link, "click", function() {
+ if (dom.hasClass(that.link, CLASS_NAME_OPENED)) {
+ setTimeout(function() { that.hide(); }, 0);
+ }
+ });
+
+ dom.observe(this.container, "keydown", function(event) {
+ var keyCode = event.keyCode;
+ if (keyCode === wysihtml5.ENTER_KEY) {
+ callbackWrapper(event);
+ }
+ if (keyCode === wysihtml5.ESCAPE_KEY) {
+ that.fire("cancel");
+ that.hide();
+ }
+ });
+
+ dom.delegate(this.container, "[data-wysihtml5-dialog-action=save]", "click", callbackWrapper);
+
+ dom.delegate(this.container, "[data-wysihtml5-dialog-action=cancel]", "click", function(event) {
+ that.fire("cancel");
+ that.hide();
+ event.preventDefault();
+ event.stopPropagation();
+ });
+
+ var formElements = this.container.querySelectorAll(SELECTOR_FORM_ELEMENTS),
+ i = 0,
+ length = formElements.length,
+ _clearInterval = function() { clearInterval(that.interval); };
+ for (; i<length; i++) {
+ dom.observe(formElements[i], "change", _clearInterval);
+ }
+
+ this._observed = true;
+ },
+
+ /**
+ * Grabs all fields in the dialog and puts them in key=>value style in an object which
+ * then gets returned
+ */
+ _serialize: function() {
+ var data = this.elementToChange || {},
+ fields = this.container.querySelectorAll(SELECTOR_FIELDS),
+ length = fields.length,
+ i = 0;
+
+ for (; i<length; i++) {
+ data[fields[i].getAttribute(ATTRIBUTE_FIELDS)] = fields[i].value;
+ }
+ return data;
+ },
+
+ /**
+ * Takes the attributes of the "elementToChange"
+ * and inserts them in their corresponding dialog input fields
+ *
+ * Assume the "elementToChange" looks like this:
+ * <a href="http://www.google.com" target="_blank">foo</a>
+ *
+ * and we have the following dialog:
+ * <input type="text" data-wysihtml5-dialog-field="href" value="">
+ * <input type="text" data-wysihtml5-dialog-field="target" value="">
+ *
+ * after calling _interpolate() the dialog will look like this
+ * <input type="text" data-wysihtml5-dialog-field="href" value="http://www.google.com">
+ * <input type="text" data-wysihtml5-dialog-field="target" value="_blank">
+ *
+ * Basically it adopted the attribute values into the corresponding input fields
+ *
+ */
+ _interpolate: function(avoidHiddenFields) {
+ var field,
+ fieldName,
+ newValue,
+ focusedElement = document.querySelector(":focus"),
+ fields = this.container.querySelectorAll(SELECTOR_FIELDS),
+ length = fields.length,
+ i = 0;
+ for (; i<length; i++) {
+ field = fields[i];
+
+ // Never change elements where the user is currently typing in
+ if (field === focusedElement) {
+ continue;
+ }
+
+ // Don't update hidden fields
+ // See https://github.com/xing/wysihtml5/pull/14
+ if (avoidHiddenFields && field.type === "hidden") {
+ continue;
+ }
+
+ fieldName = field.getAttribute(ATTRIBUTE_FIELDS);
+ newValue = (this.elementToChange && typeof(this.elementToChange) !== 'boolean') ? (this.elementToChange.getAttribute(fieldName) || "") : field.defaultValue;
+ field.value = newValue;
+ }
+ },
+
+ /**
+ * Show the dialog element
+ */
+ show: function(elementToChange) {
+ if (dom.hasClass(this.link, CLASS_NAME_OPENED)) {
+ return;
+ }
+
+ var that = this,
+ firstField = this.container.querySelector(SELECTOR_FORM_ELEMENTS);
+ this.elementToChange = elementToChange;
+ this._observe();
+ this._interpolate();
+ if (elementToChange) {
+ this.interval = setInterval(function() { that._interpolate(true); }, 500);
+ }
+ dom.addClass(this.link, CLASS_NAME_OPENED);
+ this.container.style.display = "";
+ this.fire("show");
+ if (firstField && !elementToChange) {
+ try {
+ firstField.focus();
+ } catch(e) {}
+ }
+ },
+
+ /**
+ * Hide the dialog element
+ */
+ hide: function() {
+ clearInterval(this.interval);
+ this.elementToChange = null;
+ dom.removeClass(this.link, CLASS_NAME_OPENED);
+ this.container.style.display = "none";
+ this.fire("hide");
+ }
+ });
+})(wysihtml5);
+;/**
+ * Converts speech-to-text and inserts this into the editor
+ * As of now (2011/03/25) this only is supported in Chrome >= 11
+ *
+ * Note that it sends the recorded audio to the google speech recognition api:
+ * http://stackoverflow.com/questions/4361826/does-chrome-have-buil-in-speech-recognition-for-input-type-text-x-webkit-speec
+ *
+ * Current HTML5 draft can be found here
+ * http://lists.w3.org/Archives/Public/public-xg-htmlspeech/2011Feb/att-0020/api-draft.html
+ *
+ * "Accessing Google Speech API Chrome 11"
+ * http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/
+ */
+(function(wysihtml5) {
+ var dom = wysihtml5.dom;
+
+ var linkStyles = {
+ position: "relative"
+ };
+
+ var wrapperStyles = {
+ left: 0,
+ margin: 0,
+ opacity: 0,
+ overflow: "hidden",
+ padding: 0,
+ position: "absolute",
+ top: 0,
+ zIndex: 1
+ };
+
+ var inputStyles = {
+ cursor: "inherit",
+ fontSize: "50px",
+ height: "50px",
+ marginTop: "-25px",
+ outline: 0,
+ padding: 0,
+ position: "absolute",
+ right: "-4px",
+ top: "50%"
+ };
+
+ var inputAttributes = {
+ "x-webkit-speech": "",
+ "speech": ""
+ };
+
+ wysihtml5.toolbar.Speech = function(parent, link) {
+ var input = document.createElement("input");
+ if (!wysihtml5.browser.supportsSpeechApiOn(input)) {
+ link.style.display = "none";
+ return;
+ }
+ var lang = parent.editor.textarea.element.getAttribute("lang");
+ if (lang) {
+ inputAttributes.lang = lang;
+ }
+
+ var wrapper = document.createElement("div");
+
+ wysihtml5.lang.object(wrapperStyles).merge({
+ width: link.offsetWidth + "px",
+ height: link.offsetHeight + "px"
+ });
+
+ dom.insert(input).into(wrapper);
+ dom.insert(wrapper).into(link);
+
+ dom.setStyles(inputStyles).on(input);
+ dom.setAttributes(inputAttributes).on(input);
+
+ dom.setStyles(wrapperStyles).on(wrapper);
+ dom.setStyles(linkStyles).on(link);
+
+ var eventName = "onwebkitspeechchange" in input ? "webkitspeechchange" : "speechchange";
+ dom.observe(input, eventName, function() {
+ parent.execCommand("insertText", input.value);
+ input.value = "";
+ });
+
+ dom.observe(input, "click", function(event) {
+ if (dom.hasClass(link, "wysihtml5-command-disabled")) {
+ event.preventDefault();
+ }
+
+ event.stopPropagation();
+ });
+ };
+})(wysihtml5);
+;/**
+ * Toolbar
+ *
+ * @param {Object} parent Reference to instance of Editor instance
+ * @param {Element} container Reference to the toolbar container element
+ *
+ * @example
+ * <div id="toolbar">
+ * <a data-wysihtml5-command="createLink">insert link</a>
+ * <a data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="h1">insert h1</a>
+ * </div>
+ *
+ * <script>
+ * var toolbar = new wysihtml5.toolbar.Toolbar(editor, document.getElementById("toolbar"));
+ * </script>
+ */
+(function(wysihtml5) {
+ var CLASS_NAME_COMMAND_DISABLED = "wysihtml5-command-disabled",
+ CLASS_NAME_COMMANDS_DISABLED = "wysihtml5-commands-disabled",
+ CLASS_NAME_COMMAND_ACTIVE = "wysihtml5-command-active",
+ CLASS_NAME_ACTION_ACTIVE = "wysihtml5-action-active",
+ dom = wysihtml5.dom;
+
+ wysihtml5.toolbar.Toolbar = Base.extend(
+ /** @scope wysihtml5.toolbar.Toolbar.prototype */ {
+ constructor: function(editor, container, showOnInit) {
+ this.editor = editor;
+ this.container = typeof(container) === "string" ? document.getElementById(container) : container;
+ this.composer = editor.composer;
+
+ this._getLinks("command");
+ this._getLinks("action");
+
+ this._observe();
+ if (showOnInit) { this.show(); }
+
+ if (editor.config.classNameCommandDisabled != null) {
+ CLASS_NAME_COMMAND_DISABLED = editor.config.classNameCommandDisabled;
+ }
+ if (editor.config.classNameCommandsDisabled != null) {
+ CLASS_NAME_COMMANDS_DISABLED = editor.config.classNameCommandsDisabled;
+ }
+ if (editor.config.classNameCommandActive != null) {
+ CLASS_NAME_COMMAND_ACTIVE = editor.config.classNameCommandActive;
+ }
+ if (editor.config.classNameActionActive != null) {
+ CLASS_NAME_ACTION_ACTIVE = editor.config.classNameActionActive;
+ }
+
+ var speechInputLinks = this.container.querySelectorAll("[data-wysihtml5-command=insertSpeech]"),
+ length = speechInputLinks.length,
+ i = 0;
+ for (; i<length; i++) {
+ new wysihtml5.toolbar.Speech(this, speechInputLinks[i]);
+ }
+ },
+
+ _getLinks: function(type) {
+ var links = this[type + "Links"] = wysihtml5.lang.array(this.container.querySelectorAll("[data-wysihtml5-" + type + "]")).get(),
+ length = links.length,
+ i = 0,
+ mapping = this[type + "Mapping"] = {},
+ link,
+ group,
+ name,
+ value,
+ dialog;
+ for (; i<length; i++) {
+ link = links[i];
+ name = link.getAttribute("data-wysihtml5-" + type);
+ value = link.getAttribute("data-wysihtml5-" + type + "-value");
+ group = this.container.querySelector("[data-wysihtml5-" + type + "-group='" + name + "']");
+ dialog = this._getDialog(link, name);
+
+ mapping[name + ":" + value] = {
+ link: link,
+ group: group,
+ name: name,
+ value: value,
+ dialog: dialog,
+ state: false
+ };
+ }
+ },
+
+ _getDialog: function(link, command) {
+ var that = this,
+ dialogElement = this.container.querySelector("[data-wysihtml5-dialog='" + command + "']"),
+ dialog,
+ caretBookmark;
+
+ if (dialogElement) {
+ if (wysihtml5.toolbar["Dialog_" + command]) {
+ dialog = new wysihtml5.toolbar["Dialog_" + command](link, dialogElement);
+ } else {
+ dialog = new wysihtml5.toolbar.Dialog(link, dialogElement);
+ }
+
+ dialog.on("show", function() {
+ caretBookmark = that.composer.selection.getBookmark();
+
+ that.editor.fire("show:dialog", { command: command, dialogContainer: dialogElement, commandLink: link });
+ });
+
+ dialog.on("save", function(attributes) {
+ if (caretBookmark) {
+ that.composer.selection.setBookmark(caretBookmark);
+ }
+ that._execCommand(command, attributes);
+
+ that.editor.fire("save:dialog", { command: command, dialogContainer: dialogElement, commandLink: link });
+ });
+
+ dialog.on("cancel", function() {
+ that.editor.focus(false);
+ that.editor.fire("cancel:dialog", { command: command, dialogContainer: dialogElement, commandLink: link });
+ });
+ }
+ return dialog;
+ },
+
+ /**
+ * @example
+ * var toolbar = new wysihtml5.Toolbar();
+ * // Insert a <blockquote> element or wrap current selection in <blockquote>
+ * toolbar.execCommand("formatBlock", "blockquote");
+ */
+ execCommand: function(command, commandValue) {
+ if (this.commandsDisabled) {
+ return;
+ }
+
+ var commandObj = this.commandMapping[command + ":" + commandValue];
+
+ // Show dialog when available
+ if (commandObj && commandObj.dialog && !commandObj.state) {
+ commandObj.dialog.show();
+ } else {
+ this._execCommand(command, commandValue);
+ }
+ },
+
+ _execCommand: function(command, commandValue) {
+ // Make sure that composer is focussed (false => don't move caret to the end)
+ this.editor.focus(false);
+
+ this.composer.commands.exec(command, commandValue);
+ this._updateLinkStates();
+ },
+
+ execAction: function(action) {
+ var editor = this.editor;
+ if (action === "change_view") {
+ if (editor.textarea) {
+ if (editor.currentView === editor.textarea) {
+ editor.fire("change_view", "composer");
+ } else {
+ editor.fire("change_view", "textarea");
+ }
+ }
+ }
+ if (action == "showSource") {
+ editor.fire("showSource");
+ }
+ },
+
+ _observe: function() {
+ var that = this,
+ editor = this.editor,
+ container = this.container,
+ links = this.commandLinks.concat(this.actionLinks),
+ length = links.length,
+ i = 0;
+
+ for (; i<length; i++) {
+ // 'javascript:;' and unselectable=on Needed for IE, but done in all browsers to make sure that all get the same css applied
+ // (you know, a:link { ... } doesn't match anchors with missing href attribute)
+ if (links[i].nodeName === "A") {
+ dom.setAttributes({
+ href: "javascript:;",
+ unselectable: "on"
+ }).on(links[i]);
+ } else {
+ dom.setAttributes({ unselectable: "on" }).on(links[i]);
+ }
+ }
+
+ // Needed for opera and chrome
+ dom.delegate(container, "[data-wysihtml5-command], [data-wysihtml5-action]", "mousedown", function(event) { event.preventDefault(); });
+
+ dom.delegate(container, "[data-wysihtml5-command]", "click", function(event) {
+ var link = this,
+ command = link.getAttribute("data-wysihtml5-command"),
+ commandValue = link.getAttribute("data-wysihtml5-command-value");
+ that.execCommand(command, commandValue);
+ event.preventDefault();
+ });
+
+ dom.delegate(container, "[data-wysihtml5-action]", "click", function(event) {
+ var action = this.getAttribute("data-wysihtml5-action");
+ that.execAction(action);
+ event.preventDefault();
+ });
+
+ editor.on("interaction:composer", function() {
+ that._updateLinkStates();
+ });
+
+ editor.on("focus:composer", function() {
+ that.bookmark = null;
+ });
+
+ if (this.editor.config.handleTables) {
+ editor.on("tableselect:composer", function() {
+ that.container.querySelectorAll('[data-wysihtml5-hiddentools="table"]')[0].style.display = "";
+ });
+ editor.on("tableunselect:composer", function() {
+ that.container.querySelectorAll('[data-wysihtml5-hiddentools="table"]')[0].style.display = "none";
+ });
+ }
+
+ editor.on("change_view", function(currentView) {
+ // Set timeout needed in order to let the blur event fire first
+ if (editor.textarea) {
+ setTimeout(function() {
+ that.commandsDisabled = (currentView !== "composer");
+ that._updateLinkStates();
+ if (that.commandsDisabled) {
+ dom.addClass(container, CLASS_NAME_COMMANDS_DISABLED);
+ } else {
+ dom.removeClass(container, CLASS_NAME_COMMANDS_DISABLED);
+ }
+ }, 0);
+ }
+ });
+ },
+
+ _updateLinkStates: function() {
+
+ var commandMapping = this.commandMapping,
+ actionMapping = this.actionMapping,
+ i,
+ state,
+ action,
+ command;
+ // every millisecond counts... this is executed quite often
+ for (i in commandMapping) {
+ command = commandMapping[i];
+ if (this.commandsDisabled) {
+ state = false;
+ dom.removeClass(command.link, CLASS_NAME_COMMAND_ACTIVE);
+ if (command.group) {
+ dom.removeClass(command.group, CLASS_NAME_COMMAND_ACTIVE);
+ }
+ if (command.dialog) {
+ command.dialog.hide();
+ }
+ } else {
+ state = this.composer.commands.state(command.name, command.value);
+ dom.removeClass(command.link, CLASS_NAME_COMMAND_DISABLED);
+ if (command.group) {
+ dom.removeClass(command.group, CLASS_NAME_COMMAND_DISABLED);
+ }
+ }
+ if (command.state === state) {
+ continue;
+ }
+
+ command.state = state;
+ if (state) {
+ dom.addClass(command.link, CLASS_NAME_COMMAND_ACTIVE);
+ if (command.group) {
+ dom.addClass(command.group, CLASS_NAME_COMMAND_ACTIVE);
+ }
+ if (command.dialog) {
+ if (typeof(state) === "object" || wysihtml5.lang.object(state).isArray()) {
+
+ if (!command.dialog.multiselect && wysihtml5.lang.object(state).isArray()) {
+ // Grab first and only object/element in state array, otherwise convert state into boolean
+ // to avoid showing a dialog for multiple selected elements which may have different attributes
+ // eg. when two links with different href are selected, the state will be an array consisting of both link elements
+ // but the dialog interface can only update one
+ state = state.length === 1 ? state[0] : true;
+ command.state = state;
+ }
+ command.dialog.show(state);
+ } else {
+ command.dialog.hide();
+ }
+ }
+ } else {
+ dom.removeClass(command.link, CLASS_NAME_COMMAND_ACTIVE);
+ if (command.group) {
+ dom.removeClass(command.group, CLASS_NAME_COMMAND_ACTIVE);
+ }
+ if (command.dialog) {
+ command.dialog.hide();
+ }
+ }
+ }
+
+ for (i in actionMapping) {
+ action = actionMapping[i];
+
+ if (action.name === "change_view") {
+ action.state = this.editor.currentView === this.editor.textarea;
+ if (action.state) {
+ dom.addClass(action.link, CLASS_NAME_ACTION_ACTIVE);
+ } else {
+ dom.removeClass(action.link, CLASS_NAME_ACTION_ACTIVE);
+ }
+ }
+ }
+ },
+
+ show: function() {
+ this.container.style.display = "";
+ },
+
+ hide: function() {
+ this.container.style.display = "none";
+ }
+ });
+
+})(wysihtml5);
+;(function(wysihtml5) {
+ wysihtml5.toolbar.Dialog_createTable = wysihtml5.toolbar.Dialog.extend({
+ show: function(elementToChange) {
+ this.base(elementToChange);
+
+ }
+
+ });
+})(wysihtml5);
+;(function(wysihtml5) {
+ var dom = wysihtml5.dom,
+ SELECTOR_FIELDS = "[data-wysihtml5-dialog-field]",
+ ATTRIBUTE_FIELDS = "data-wysihtml5-dialog-field";
+
+ wysihtml5.toolbar.Dialog_foreColorStyle = wysihtml5.toolbar.Dialog.extend({
+ multiselect: true,
+
+ _serialize: function() {
+ var data = {},
+ fields = this.container.querySelectorAll(SELECTOR_FIELDS),
+ length = fields.length,
+ i = 0;
+
+ for (; i<length; i++) {
+ data[fields[i].getAttribute(ATTRIBUTE_FIELDS)] = fields[i].value;
+ }
+ return data;
+ },
+
+ _interpolate: function(avoidHiddenFields) {
+ var field,
+ fieldName,
+ newValue,
+ focusedElement = document.querySelector(":focus"),
+ fields = this.container.querySelectorAll(SELECTOR_FIELDS),
+ length = fields.length,
+ i = 0,
+ firstElement = (this.elementToChange) ? ((wysihtml5.lang.object(this.elementToChange).isArray()) ? this.elementToChange[0] : this.elementToChange) : null,
+ colorStr = (firstElement) ? firstElement.getAttribute('style') : null,
+ color = (colorStr) ? wysihtml5.quirks.styleParser.parseColor(colorStr, "color") : null;
+
+ for (; i<length; i++) {
+ field = fields[i];
+ // Never change elements where the user is currently typing in
+ if (field === focusedElement) {
+ continue;
+ }
+ // Don't update hidden fields3
+ if (avoidHiddenFields && field.type === "hidden") {
+ continue;
+ }
+ if (field.getAttribute(ATTRIBUTE_FIELDS) === "color") {
+ if (color) {
+ if (color[3] && color[3] != 1) {
+ field.value = "rgba(" + color[0] + "," + color[1] + "," + color[2] + "," + color[3] + ");";
+ } else {
+ field.value = "rgb(" + color[0] + "," + color[1] + "," + color[2] + ");";
+ }
+ } else {
+ field.value = "rgb(0,0,0);";
+ }
+ }
+ }
+ }
+
+ });
+})(wysihtml5);
+;(function(wysihtml5) {
+ var dom = wysihtml5.dom,
+ SELECTOR_FIELDS = "[data-wysihtml5-dialog-field]",
+ ATTRIBUTE_FIELDS = "data-wysihtml5-dialog-field";
+
+ wysihtml5.toolbar.Dialog_fontSizeStyle = wysihtml5.toolbar.Dialog.extend({
+ multiselect: true,
+
+ _serialize: function() {
+ return {"size" : this.container.querySelector('[data-wysihtml5-dialog-field="size"]').value};
+ },
+
+ _interpolate: function(avoidHiddenFields) {
+ var focusedElement = document.querySelector(":focus"),
+ field = this.container.querySelector("[data-wysihtml5-dialog-field='size']"),
+ firstElement = (this.elementToChange) ? ((wysihtml5.lang.object(this.elementToChange).isArray()) ? this.elementToChange[0] : this.elementToChange) : null,
+ styleStr = (firstElement) ? firstElement.getAttribute('style') : null,
+ size = (styleStr) ? wysihtml5.quirks.styleParser.parseFontSize(styleStr) : null;
+
+ if (field && field !== focusedElement && size && !(/^\s*$/).test(size)) {
+ field.value = size;
+ }
+ }
+
+ });
+})(wysihtml5);
--- /dev/null
+/*! wysihtml5x - v0.4.17 (2014-11-06) */
+
+!function(){if(Event.prototype.preventDefault||(Event.prototype.preventDefault=function(){this.returnValue=!1}),Event.prototype.stopPropagation||(Event.prototype.stopPropagation=function(){this.cancelBubble=!0}),!Element.prototype.addEventListener){var a=[],b=function(b,c){var d=this,e=function(a){a.target=a.srcElement,a.currentTarget=d,c.handleEvent?c.handleEvent(a):c.call(d,a)};if("DOMContentLoaded"==b){var f=function(a){"complete"==document.readyState&&e(a)};if(document.attachEvent("onreadystatechange",f),a.push({object:this,type:b,listener:c,wrapper:f}),"complete"==document.readyState){var g=new Event;g.srcElement=window,f(g)}}else this.attachEvent("on"+b,e),a.push({object:this,type:b,listener:c,wrapper:e})},c=function(b,c){for(var d=0;d<a.length;){var e=a[d];if(e.object==this&&e.type==b&&e.listener==c){"DOMContentLoaded"==b?this.detachEvent("onreadystatechange",e.wrapper):this.detachEvent("on"+b,e.wrapper),a.splice(d,1);break}++d}};Element.prototype.addEventListener=b,Element.prototype.removeEventListener=c,HTMLDocument&&(HTMLDocument.prototype.addEventListener=b,HTMLDocument.prototype.removeEventListener=c),Window&&(Window.prototype.addEventListener=b,Window.prototype.removeEventListener=c)}}(),Object.defineProperty&&Object.getOwnPropertyDescriptor&&Object.getOwnPropertyDescriptor(Element.prototype,"textContent")&&!Object.getOwnPropertyDescriptor(Element.prototype,"textContent").get&&!function(){var a=Object.getOwnPropertyDescriptor(Element.prototype,"innerText");Object.defineProperty(Element.prototype,"textContent",{get:function(){return a.get.call(this)},set:function(b){return a.set.call(this,b)}})}(),Array.isArray||(Array.isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)}),Function.prototype.bind||(Function.prototype.bind=function(a){if("function"!=typeof this)throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");var b=Array.prototype.slice.call(arguments,1),c=this,d=function(){},e=function(){return c.apply(this instanceof d&&a?this:a,b.concat(Array.prototype.slice.call(arguments)))};return d.prototype=this.prototype,e.prototype=new d,e});var wysihtml5={version:"0.4.17",commands:{},dom:{},quirks:{},toolbar:{},lang:{},selection:{},views:{},INVISIBLE_SPACE:"",INVISIBLE_SPACE_REG_EXP:/\uFEFF/g,EMPTY_FUNCTION:function(){},ELEMENT_NODE:1,TEXT_NODE:3,BACKSPACE_KEY:8,ENTER_KEY:13,ESCAPE_KEY:27,SPACE_KEY:32,TAB_KEY:9,DELETE_KEY:46};!function(a,b){"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"object"==typeof exports?module.exports=a():b.rangy=a()}(function(){function a(a,b){var c=typeof a[b];return c==s||!(c!=r||!a[b])||"unknown"==c}function b(a,b){return!(typeof a[b]!=r||!a[b])}function c(a,b){return typeof a[b]!=t}function d(a){return function(b,c){for(var d=c.length;d--;)if(!a(b,c[d]))return!1;return!0}}function e(a){return a&&y(a,x)&&A(a,w)}function f(a){return b(a,"body")?a.body:a.getElementsByTagName("body")[0]}function g(b){typeof console!=t&&a(console,"log")&&console.log(b)}function h(a,b){C&&b?alert(a):g(a)}function i(a){E.initialized=!0,E.supported=!1,h("Rangy is not supported in this environment. Reason: "+a,E.config.alertOnFail)}function j(a){h("Rangy warning: "+a,E.config.alertOnWarn)}function k(a){return a.message||a.description||String(a)}function l(){if(C&&!E.initialized){var b,c=!1,d=!1;a(document,"createRange")&&(b=document.createRange(),y(b,v)&&A(b,u)&&(c=!0));var h=f(document);if(!h||"body"!=h.nodeName.toLowerCase())return void i("No body element found");if(h&&a(h,"createTextRange")&&(b=h.createTextRange(),e(b)&&(d=!0)),!c&&!d)return void i("Neither Range nor TextRange are available");E.initialized=!0,E.features={implementsDomRange:c,implementsTextRange:d};var j,l;for(var m in B)(j=B[m])instanceof n&&j.init(j,E);for(var o=0,p=H.length;p>o;++o)try{H[o](E)}catch(q){l="Rangy init listener threw an exception. Continuing. Detail: "+k(q),g(l)}}}function m(a){a=a||window,l();for(var b=0,c=I.length;c>b;++b)I[b](a)}function n(a,b,c){this.name=a,this.dependencies=b,this.initialized=!1,this.supported=!1,this.initializer=c}function o(a,b,c){var d=new n(a,b,function(b){if(!b.initialized){b.initialized=!0;try{c(E,b),b.supported=!0}catch(d){var e="Module '"+a+"' failed to load: "+k(d);g(e),d.stack&&g(d.stack)}}});return B[a]=d,d}function p(){}function q(){}var r="object",s="function",t="undefined",u=["startContainer","startOffset","endContainer","endOffset","collapsed","commonAncestorContainer"],v=["setStart","setStartBefore","setStartAfter","setEnd","setEndBefore","setEndAfter","collapse","selectNode","selectNodeContents","compareBoundaryPoints","deleteContents","extractContents","cloneContents","insertNode","surroundContents","cloneRange","toString","detach"],w=["boundingHeight","boundingLeft","boundingTop","boundingWidth","htmlText","text"],x=["collapse","compareEndPoints","duplicate","moveToElementText","parentElement","select","setEndPoint","getBoundingClientRect"],y=d(a),z=d(b),A=d(c),B={},C=typeof window!=t&&typeof document!=t,D={isHostMethod:a,isHostObject:b,isHostProperty:c,areHostMethods:y,areHostObjects:z,areHostProperties:A,isTextRange:e,getBody:f},E={version:"1.3.0-alpha.20140921",initialized:!1,isBrowser:C,supported:!0,util:D,features:{},modules:B,config:{alertOnFail:!0,alertOnWarn:!1,preferTextRange:!1,autoInitialize:typeof rangyAutoInitialize==t?!0:rangyAutoInitialize}};E.fail=i,E.warn=j;var F;({}).hasOwnProperty?(D.extend=F=function(a,b,c){var d,e;for(var f in b)b.hasOwnProperty(f)&&(d=a[f],e=b[f],c&&null!==d&&"object"==typeof d&&null!==e&&"object"==typeof e&&F(d,e,!0),a[f]=e);return b.hasOwnProperty("toString")&&(a.toString=b.toString),a},D.createOptions=function(a,b){var c={};return F(c,b),a&&F(c,a),c}):i("hasOwnProperty not supported"),C||i("Rangy can only run in a browser"),function(){var a;if(C){var b=document.createElement("div");b.appendChild(document.createElement("span"));var c=[].slice;try{1==c.call(b.childNodes,0)[0].nodeType&&(a=function(a){return c.call(a,0)})}catch(d){}}a||(a=function(a){for(var b=[],c=0,d=a.length;d>c;++c)b[c]=a[c];return b}),D.toArray=a}();var G;C&&(a(document,"addEventListener")?G=function(a,b,c){a.addEventListener(b,c,!1)}:a(document,"attachEvent")?G=function(a,b,c){a.attachEvent("on"+b,c)}:i("Document does not have required addEventListener or attachEvent method"),D.addListener=G);var H=[];E.init=l,E.addInitListener=function(a){E.initialized?a(E):H.push(a)};var I=[];E.addShimListener=function(a){I.push(a)},C&&(E.shim=E.createMissingNativeApi=m),n.prototype={init:function(){for(var a,b,c=this.dependencies||[],d=0,e=c.length;e>d;++d){if(b=c[d],a=B[b],!(a&&a instanceof n))throw new Error("required module '"+b+"' not found");if(a.init(),!a.supported)throw new Error("required module '"+b+"' not supported")}this.initializer(this)},fail:function(a){throw this.initialized=!0,this.supported=!1,new Error("Module '"+this.name+"' failed to load: "+a)},warn:function(a){E.warn("Module "+this.name+": "+a)},deprecationNotice:function(a,b){E.warn("DEPRECATED: "+a+" in module "+this.name+"is deprecated. Please use "+b+" instead")},createError:function(a){return new Error("Error in Rangy "+this.name+" module: "+a)}},E.createModule=function(a){var b,c;2==arguments.length?(b=arguments[1],c=[]):(b=arguments[2],c=arguments[1]);var d=o(a,c,b);E.initialized&&E.supported&&d.init()},E.createCoreModule=function(a,b,c){o(a,b,c)},E.RangePrototype=p,E.rangePrototype=new p,E.selectionPrototype=new q,E.createCoreModule("DomUtil",[],function(a,b){function c(a){var b;return typeof a.namespaceURI==D||null===(b=a.namespaceURI)||"http://www.w3.org/1999/xhtml"==b}function d(a){var b=a.parentNode;return 1==b.nodeType?b:null}function e(a){for(var b=0;a=a.previousSibling;)++b;return b}function f(a){switch(a.nodeType){case 7:case 10:return 0;case 3:case 8:return a.length;default:return a.childNodes.length}}function g(a,b){var c,d=[];for(c=a;c;c=c.parentNode)d.push(c);for(c=b;c;c=c.parentNode)if(H(d,c))return c;return null}function h(a,b,c){for(var d=c?b:b.parentNode;d;){if(d===a)return!0;d=d.parentNode}return!1}function i(a,b){return h(a,b,!0)}function j(a,b,c){for(var d,e=c?a:a.parentNode;e;){if(d=e.parentNode,d===b)return e;e=d}return null}function k(a){var b=a.nodeType;return 3==b||4==b||8==b}function l(a){if(!a)return!1;var b=a.nodeType;return 3==b||8==b}function m(a,b){var c=b.nextSibling,d=b.parentNode;return c?d.insertBefore(a,c):d.appendChild(a),a}function n(a,b,c){var d=a.cloneNode(!1);if(d.deleteData(0,b),a.deleteData(b,a.length-b),m(d,a),c)for(var f,g=0;f=c[g++];)f.node==a&&f.offset>b?(f.node=d,f.offset-=b):f.node==a.parentNode&&f.offset>e(a)&&++f.offset;return d}function o(a){if(9==a.nodeType)return a;if(typeof a.ownerDocument!=D)return a.ownerDocument;if(typeof a.document!=D)return a.document;if(a.parentNode)return o(a.parentNode);throw b.createError("getDocument: no document found for node")}function p(a){var c=o(a);if(typeof c.defaultView!=D)return c.defaultView;if(typeof c.parentWindow!=D)return c.parentWindow;throw b.createError("Cannot get a window object for node")}function q(a){if(typeof a.contentDocument!=D)return a.contentDocument;if(typeof a.contentWindow!=D)return a.contentWindow.document;throw b.createError("getIframeDocument: No Document object found for iframe element")}function r(a){if(typeof a.contentWindow!=D)return a.contentWindow;if(typeof a.contentDocument!=D)return a.contentDocument.defaultView;throw b.createError("getIframeWindow: No Window object found for iframe element")}function s(a){return a&&E.isHostMethod(a,"setTimeout")&&E.isHostObject(a,"document")}function t(a,b,c){var d;if(a?E.isHostProperty(a,"nodeType")?d=1==a.nodeType&&"iframe"==a.tagName.toLowerCase()?q(a):o(a):s(a)&&(d=a.document):d=document,!d)throw b.createError(c+"(): Parameter must be a Window object or DOM node");return d}function u(a){for(var b;b=a.parentNode;)a=b;return a}function v(a,c,d,f){var h,i,k,l,m;if(a==d)return c===f?0:f>c?-1:1;if(h=j(d,a,!0))return c<=e(h)?-1:1;if(h=j(a,d,!0))return e(h)<f?-1:1;if(i=g(a,d),!i)throw new Error("comparePoints error: nodes have no common ancestor");if(k=a===i?i:j(a,i,!0),l=d===i?i:j(d,i,!0),k===l)throw b.createError("comparePoints got to case 4 and childA and childB are the same!");for(m=i.firstChild;m;){if(m===k)return-1;if(m===l)return 1;m=m.nextSibling}}function w(a){var b;try{return b=a.parentNode,!1}catch(c){return!0}}function x(a){if(!a)return"[No node]";if(I&&w(a))return"[Broken node]";if(k(a))return'"'+a.data+'"';if(1==a.nodeType){var b=a.id?' id="'+a.id+'"':"";return"<"+a.nodeName+b+">[index:"+e(a)+",length:"+a.childNodes.length+"]["+(a.innerHTML||"[innerHTML not supported]").slice(0,25)+"]"}return a.nodeName}function y(a){for(var b,c=o(a).createDocumentFragment();b=a.firstChild;)c.appendChild(b);return c}function z(a){this.root=a,this._next=a}function A(a){return new z(a)}function B(a,b){this.node=a,this.offset=b}function C(a){this.code=this[a],this.codeName=a,this.message="DOMException: "+this.codeName}var D="undefined",E=a.util;E.areHostMethods(document,["createDocumentFragment","createElement","createTextNode"])||b.fail("document missing a Node creation method"),E.isHostMethod(document,"getElementsByTagName")||b.fail("document missing getElementsByTagName method");var F=document.createElement("div");E.areHostMethods(F,["insertBefore","appendChild","cloneNode"]||!E.areHostObjects(F,["previousSibling","nextSibling","childNodes","parentNode"]))||b.fail("Incomplete Element implementation"),E.isHostProperty(F,"innerHTML")||b.fail("Element is missing innerHTML property");var G=document.createTextNode("test");E.areHostMethods(G,["splitText","deleteData","insertData","appendData","cloneNode"]||!E.areHostObjects(F,["previousSibling","nextSibling","childNodes","parentNode"])||!E.areHostProperties(G,["data"]))||b.fail("Incomplete Text Node implementation");var H=function(a,b){for(var c=a.length;c--;)if(a[c]===b)return!0;return!1},I=!1;!function(){var b=document.createElement("b");b.innerHTML="1";var c=b.firstChild;b.innerHTML="<br>",I=w(c),a.features.crashyTextNodes=I}();var J;typeof window.getComputedStyle!=D?J=function(a,b){return p(a).getComputedStyle(a,null)[b]}:typeof document.documentElement.currentStyle!=D?J=function(a,b){return a.currentStyle[b]}:b.fail("No means of obtaining computed style properties found"),z.prototype={_current:null,hasNext:function(){return!!this._next},next:function(){var a,b,c=this._current=this._next;if(this._current)if(a=c.firstChild)this._next=a;else{for(b=null;c!==this.root&&!(b=c.nextSibling);)c=c.parentNode;this._next=b}return this._current},detach:function(){this._current=this._next=this.root=null}},B.prototype={equals:function(a){return!!a&&this.node===a.node&&this.offset==a.offset},inspect:function(){return"[DomPosition("+x(this.node)+":"+this.offset+")]"},toString:function(){return this.inspect()}},C.prototype={INDEX_SIZE_ERR:1,HIERARCHY_REQUEST_ERR:3,WRONG_DOCUMENT_ERR:4,NO_MODIFICATION_ALLOWED_ERR:7,NOT_FOUND_ERR:8,NOT_SUPPORTED_ERR:9,INVALID_STATE_ERR:11,INVALID_NODE_TYPE_ERR:24},C.prototype.toString=function(){return this.message},a.dom={arrayContains:H,isHtmlNamespace:c,parentElement:d,getNodeIndex:e,getNodeLength:f,getCommonAncestor:g,isAncestorOf:h,isOrIsAncestorOf:i,getClosestAncestorIn:j,isCharacterDataNode:k,isTextOrCommentNode:l,insertAfter:m,splitDataNode:n,getDocument:o,getWindow:p,getIframeWindow:r,getIframeDocument:q,getBody:E.getBody,isWindow:s,getContentDocument:t,getRootContainer:u,comparePoints:v,isBrokenNode:w,inspectNode:x,getComputedStyleProperty:J,fragmentFromNodeChildren:y,createIterator:A,DomPosition:B},a.DOMException=C}),E.createCoreModule("DomRange",["DomUtil"],function(a){function b(a,b){return 3!=a.nodeType&&(O(a,b.startContainer)||O(a,b.endContainer))}function c(a){return a.document||P(a.startContainer)}function d(a){return new K(a.parentNode,N(a))}function e(a){return new K(a.parentNode,N(a)+1)}function f(a,b,c){var d=11==a.nodeType?a.firstChild:a;return M(b)?c==b.length?I.insertAfter(a,b):b.parentNode.insertBefore(a,0==c?b:R(b,c)):c>=b.childNodes.length?b.appendChild(a):b.insertBefore(a,b.childNodes[c]),d}function g(a,b,d){if(y(a),y(b),c(b)!=c(a))throw new L("WRONG_DOCUMENT_ERR");var e=Q(a.startContainer,a.startOffset,b.endContainer,b.endOffset),f=Q(a.endContainer,a.endOffset,b.startContainer,b.startOffset);return d?0>=e&&f>=0:0>e&&f>0}function h(a){for(var b,d,e,f=c(a.range).createDocumentFragment();d=a.next();){if(b=a.isPartiallySelectedSubtree(),d=d.cloneNode(!b),b&&(e=a.getSubtreeIterator(),d.appendChild(h(e)),e.detach()),10==d.nodeType)throw new L("HIERARCHY_REQUEST_ERR");f.appendChild(d)}return f}function i(a,b,c){var d,e;c=c||{stop:!1};for(var f,g;f=a.next();)if(a.isPartiallySelectedSubtree()){if(b(f)===!1)return void(c.stop=!0);if(g=a.getSubtreeIterator(),i(g,b,c),g.detach(),c.stop)return}else for(d=I.createIterator(f);e=d.next();)if(b(e)===!1)return void(c.stop=!0)}function j(a){for(var b;a.next();)a.isPartiallySelectedSubtree()?(b=a.getSubtreeIterator(),j(b),b.detach()):a.remove()}function k(a){for(var b,d,e=c(a.range).createDocumentFragment();b=a.next();){if(a.isPartiallySelectedSubtree()?(b=b.cloneNode(!1),d=a.getSubtreeIterator(),b.appendChild(k(d)),d.detach()):a.remove(),10==b.nodeType)throw new L("HIERARCHY_REQUEST_ERR");e.appendChild(b)}return e}function l(a,b,c){var d,e=!(!b||!b.length),f=!!c;e&&(d=new RegExp("^("+b.join("|")+")$"));var g=[];return i(new n(a,!1),function(b){if(!(e&&!d.test(b.nodeType)||f&&!c(b))){var h=a.startContainer;if(b!=h||!M(h)||a.startOffset!=h.length){var i=a.endContainer;b==i&&M(i)&&0==a.endOffset||g.push(b)}}}),g}function m(a){var b="undefined"==typeof a.getName?"Range":a.getName();return"["+b+"("+I.inspectNode(a.startContainer)+":"+a.startOffset+", "+I.inspectNode(a.endContainer)+":"+a.endOffset+")]"}function n(a,b){if(this.range=a,this.clonePartiallySelectedTextNodes=b,!a.collapsed){this.sc=a.startContainer,this.so=a.startOffset,this.ec=a.endContainer,this.eo=a.endOffset;var c=a.commonAncestorContainer;this.sc===this.ec&&M(this.sc)?(this.isSingleCharacterDataNode=!0,this._first=this._last=this._next=this.sc):(this._first=this._next=this.sc!==c||M(this.sc)?S(this.sc,c,!0):this.sc.childNodes[this.so],this._last=this.ec!==c||M(this.ec)?S(this.ec,c,!0):this.ec.childNodes[this.eo-1])}}function o(a){return function(b,c){for(var d,e=c?b:b.parentNode;e;){if(d=e.nodeType,U(a,d))return e;e=e.parentNode}return null}}function p(a,b){if(cb(a,b))throw new L("INVALID_NODE_TYPE_ERR")}function q(a,b){if(!U(b,a.nodeType))throw new L("INVALID_NODE_TYPE_ERR")}function r(a,b){if(0>b||b>(M(a)?a.length:a.childNodes.length))throw new L("INDEX_SIZE_ERR")}function s(a,b){if(ab(a,!0)!==ab(b,!0))throw new L("WRONG_DOCUMENT_ERR")}function t(a){if(bb(a,!0))throw new L("NO_MODIFICATION_ALLOWED_ERR")}function u(a,b){if(!a)throw new L(b)}function v(a){return W&&I.isBrokenNode(a)||!U(Y,a.nodeType)&&!ab(a,!0)}function w(a,b){return b<=(M(a)?a.length:a.childNodes.length)}function x(a){return!!a.startContainer&&!!a.endContainer&&!v(a.startContainer)&&!v(a.endContainer)&&w(a.startContainer,a.startOffset)&&w(a.endContainer,a.endOffset)}function y(a){if(!x(a))throw new Error("Range error: Range is no longer valid after DOM mutation ("+a.inspect()+")")}function z(a,b){y(a);var c=a.startContainer,d=a.startOffset,e=a.endContainer,f=a.endOffset,g=c===e;M(e)&&f>0&&f<e.length&&R(e,f,b),M(c)&&d>0&&d<c.length&&(c=R(c,d,b),g?(f-=d,e=c):e==c.parentNode&&f>=N(c)&&f++,d=0),a.setStartAndEnd(c,d,e,f)}function A(a){y(a);var b=a.commonAncestorContainer.parentNode.cloneNode(!1);return b.appendChild(a.cloneContents()),b.innerHTML}function B(a){a.START_TO_START=ib,a.START_TO_END=jb,a.END_TO_END=kb,a.END_TO_START=lb,a.NODE_BEFORE=mb,a.NODE_AFTER=nb,a.NODE_BEFORE_AND_AFTER=ob,a.NODE_INSIDE=pb}function C(a){B(a),B(a.prototype)}function D(a,b){return function(){y(this);var c,d,f=this.startContainer,g=this.startOffset,h=this.commonAncestorContainer,j=new n(this,!0);f!==h&&(c=S(f,h,!0),d=e(c),f=d.node,g=d.offset),i(j,t),j.reset();var k=a(j);return j.detach(),b(this,f,g,f,g),k}}function E(c,f){function g(a,b){return function(c){q(c,X),q(V(c),Y);var f=(a?d:e)(c);(b?h:i)(this,f.node,f.offset)}}function h(a,b,c){var d=a.endContainer,e=a.endOffset;(b!==a.startContainer||c!==a.startOffset)&&((V(b)!=V(d)||1==Q(b,c,d,e))&&(d=b,e=c),f(a,b,c,d,e))}function i(a,b,c){var d=a.startContainer,e=a.startOffset;(b!==a.endContainer||c!==a.endOffset)&&((V(b)!=V(d)||-1==Q(b,c,d,e))&&(d=b,e=c),f(a,d,e,b,c))}var l=function(){};l.prototype=a.rangePrototype,c.prototype=new l,J.extend(c.prototype,{setStart:function(a,b){p(a,!0),r(a,b),h(this,a,b)},setEnd:function(a,b){p(a,!0),r(a,b),i(this,a,b)},setStartAndEnd:function(){var a=arguments,b=a[0],c=a[1],d=b,e=c;switch(a.length){case 3:e=a[2];break;case 4:d=a[2],e=a[3]}f(this,b,c,d,e)},setBoundary:function(a,b,c){this["set"+(c?"Start":"End")](a,b)},setStartBefore:g(!0,!0),setStartAfter:g(!1,!0),setEndBefore:g(!0,!1),setEndAfter:g(!1,!1),collapse:function(a){y(this),a?f(this,this.startContainer,this.startOffset,this.startContainer,this.startOffset):f(this,this.endContainer,this.endOffset,this.endContainer,this.endOffset)},selectNodeContents:function(a){p(a,!0),f(this,a,0,a,T(a))},selectNode:function(a){p(a,!1),q(a,X);var b=d(a),c=e(a);f(this,b.node,b.offset,c.node,c.offset)},extractContents:D(k,f),deleteContents:D(j,f),canSurroundContents:function(){y(this),t(this.startContainer),t(this.endContainer);var a=new n(this,!0),c=a._first&&b(a._first,this)||a._last&&b(a._last,this);return a.detach(),!c},splitBoundaries:function(){z(this)},splitBoundariesPreservingPositions:function(a){z(this,a)},normalizeBoundaries:function(){y(this);var a=this.startContainer,b=this.startOffset,c=this.endContainer,d=this.endOffset,e=function(a){var b=a.nextSibling;b&&b.nodeType==a.nodeType&&(c=a,d=a.length,a.appendData(b.data),b.parentNode.removeChild(b))},g=function(e){var f=e.previousSibling;if(f&&f.nodeType==e.nodeType){a=e;var g=e.length;if(b=f.length,e.insertData(0,f.data),f.parentNode.removeChild(f),a==c)d+=b,c=a;else if(c==e.parentNode){var h=N(e);d==h?(c=e,d=g):d>h&&d--}}},h=!0;if(M(c))c.length==d&&e(c);else{if(d>0){var i=c.childNodes[d-1];i&&M(i)&&e(i)}h=!this.collapsed}if(h){if(M(a))0==b&&g(a);else if(b<a.childNodes.length){var j=a.childNodes[b];j&&M(j)&&g(j)}}else a=c,b=d;f(this,a,b,c,d)},collapseToPoint:function(a,b){p(a,!0),r(a,b),this.setStartAndEnd(a,b)}}),C(c)}function F(a){a.collapsed=a.startContainer===a.endContainer&&a.startOffset===a.endOffset,a.commonAncestorContainer=a.collapsed?a.startContainer:I.getCommonAncestor(a.startContainer,a.endContainer)}function G(a,b,c,d,e){a.startContainer=b,a.startOffset=c,a.endContainer=d,a.endOffset=e,a.document=I.getDocument(b),F(a)}function H(a){this.startContainer=a,this.startOffset=0,this.endContainer=a,this.endOffset=0,this.document=a,F(this)}var I=a.dom,J=a.util,K=I.DomPosition,L=a.DOMException,M=I.isCharacterDataNode,N=I.getNodeIndex,O=I.isOrIsAncestorOf,P=I.getDocument,Q=I.comparePoints,R=I.splitDataNode,S=I.getClosestAncestorIn,T=I.getNodeLength,U=I.arrayContains,V=I.getRootContainer,W=a.features.crashyTextNodes;n.prototype={_current:null,_next:null,_first:null,_last:null,isSingleCharacterDataNode:!1,reset:function(){this._current=null,this._next=this._first},hasNext:function(){return!!this._next},next:function(){var a=this._current=this._next;return a&&(this._next=a!==this._last?a.nextSibling:null,M(a)&&this.clonePartiallySelectedTextNodes&&(a===this.ec&&(a=a.cloneNode(!0)).deleteData(this.eo,a.length-this.eo),this._current===this.sc&&(a=a.cloneNode(!0)).deleteData(0,this.so))),a},remove:function(){var a,b,c=this._current;!M(c)||c!==this.sc&&c!==this.ec?c.parentNode&&c.parentNode.removeChild(c):(a=c===this.sc?this.so:0,b=c===this.ec?this.eo:c.length,a!=b&&c.deleteData(a,b-a))},isPartiallySelectedSubtree:function(){var a=this._current;return b(a,this.range)},getSubtreeIterator:function(){var a;if(this.isSingleCharacterDataNode)a=this.range.cloneRange(),a.collapse(!1);else{a=new H(c(this.range));var b=this._current,d=b,e=0,f=b,g=T(b);O(b,this.sc)&&(d=this.sc,e=this.so),O(b,this.ec)&&(f=this.ec,g=this.eo),G(a,d,e,f,g)}return new n(a,this.clonePartiallySelectedTextNodes)},detach:function(){this.range=this._current=this._next=this._first=this._last=this.sc=this.so=this.ec=this.eo=null}};var X=[1,3,4,5,7,8,10],Y=[2,9,11],Z=[5,6,10,12],$=[1,3,4,5,7,8,10,11],_=[1,3,4,5,7,8],ab=o([9,11]),bb=o(Z),cb=o([6,10,12]),db=document.createElement("style"),eb=!1;try{db.innerHTML="<b>x</b>",eb=3==db.firstChild.nodeType}catch(fb){}a.features.htmlParsingConforms=eb;var gb=eb?function(a){var b=this.startContainer,c=P(b);if(!b)throw new L("INVALID_STATE_ERR");var d=null;return 1==b.nodeType?d=b:M(b)&&(d=I.parentElement(b)),d=null===d||"HTML"==d.nodeName&&I.isHtmlNamespace(P(d).documentElement)&&I.isHtmlNamespace(d)?c.createElement("body"):d.cloneNode(!1),d.innerHTML=a,I.fragmentFromNodeChildren(d)}:function(a){var b=c(this),d=b.createElement("body");return d.innerHTML=a,I.fragmentFromNodeChildren(d)},hb=["startContainer","startOffset","endContainer","endOffset","collapsed","commonAncestorContainer"],ib=0,jb=1,kb=2,lb=3,mb=0,nb=1,ob=2,pb=3;J.extend(a.rangePrototype,{compareBoundaryPoints:function(a,b){y(this),s(this.startContainer,b.startContainer);var c,d,e,f,g=a==lb||a==ib?"start":"end",h=a==jb||a==ib?"start":"end";return c=this[g+"Container"],d=this[g+"Offset"],e=b[h+"Container"],f=b[h+"Offset"],Q(c,d,e,f)},insertNode:function(a){if(y(this),q(a,$),t(this.startContainer),O(a,this.startContainer))throw new L("HIERARCHY_REQUEST_ERR");var b=f(a,this.startContainer,this.startOffset);this.setStartBefore(b)},cloneContents:function(){y(this);var a,b;if(this.collapsed)return c(this).createDocumentFragment();if(this.startContainer===this.endContainer&&M(this.startContainer))return a=this.startContainer.cloneNode(!0),a.data=a.data.slice(this.startOffset,this.endOffset),b=c(this).createDocumentFragment(),b.appendChild(a),b;var d=new n(this,!0);return a=h(d),d.detach(),a},canSurroundContents:function(){y(this),t(this.startContainer),t(this.endContainer);var a=new n(this,!0),c=a._first&&b(a._first,this)||a._last&&b(a._last,this);return a.detach(),!c},surroundContents:function(a){if(q(a,_),!this.canSurroundContents())throw new L("INVALID_STATE_ERR");var b=this.extractContents();if(a.hasChildNodes())for(;a.lastChild;)a.removeChild(a.lastChild);f(a,this.startContainer,this.startOffset),a.appendChild(b),this.selectNode(a)},cloneRange:function(){y(this);for(var a,b=new H(c(this)),d=hb.length;d--;)a=hb[d],b[a]=this[a];return b},toString:function(){y(this);var a=this.startContainer;if(a===this.endContainer&&M(a))return 3==a.nodeType||4==a.nodeType?a.data.slice(this.startOffset,this.endOffset):"";var b=[],c=new n(this,!0);return i(c,function(a){(3==a.nodeType||4==a.nodeType)&&b.push(a.data)}),c.detach(),b.join("")},compareNode:function(a){y(this);var b=a.parentNode,c=N(a);if(!b)throw new L("NOT_FOUND_ERR");var d=this.comparePoint(b,c),e=this.comparePoint(b,c+1);return 0>d?e>0?ob:mb:e>0?nb:pb},comparePoint:function(a,b){return y(this),u(a,"HIERARCHY_REQUEST_ERR"),s(a,this.startContainer),Q(a,b,this.startContainer,this.startOffset)<0?-1:Q(a,b,this.endContainer,this.endOffset)>0?1:0},createContextualFragment:gb,toHtml:function(){return A(this)},intersectsNode:function(a,b){if(y(this),u(a,"NOT_FOUND_ERR"),P(a)!==c(this))return!1;var d=a.parentNode,e=N(a);u(d,"NOT_FOUND_ERR");var f=Q(d,e,this.endContainer,this.endOffset),g=Q(d,e+1,this.startContainer,this.startOffset);return b?0>=f&&g>=0:0>f&&g>0},isPointInRange:function(a,b){return y(this),u(a,"HIERARCHY_REQUEST_ERR"),s(a,this.startContainer),Q(a,b,this.startContainer,this.startOffset)>=0&&Q(a,b,this.endContainer,this.endOffset)<=0},intersectsRange:function(a){return g(this,a,!1)},intersectsOrTouchesRange:function(a){return g(this,a,!0)},intersection:function(a){if(this.intersectsRange(a)){var b=Q(this.startContainer,this.startOffset,a.startContainer,a.startOffset),c=Q(this.endContainer,this.endOffset,a.endContainer,a.endOffset),d=this.cloneRange();return-1==b&&d.setStart(a.startContainer,a.startOffset),1==c&&d.setEnd(a.endContainer,a.endOffset),d}return null},union:function(a){if(this.intersectsOrTouchesRange(a)){var b=this.cloneRange();return-1==Q(a.startContainer,a.startOffset,this.startContainer,this.startOffset)&&b.setStart(a.startContainer,a.startOffset),1==Q(a.endContainer,a.endOffset,this.endContainer,this.endOffset)&&b.setEnd(a.endContainer,a.endOffset),b}throw new L("Ranges do not intersect")},containsNode:function(a,b){return b?this.intersectsNode(a,!1):this.compareNode(a)==pb},containsNodeContents:function(a){return this.comparePoint(a,0)>=0&&this.comparePoint(a,T(a))<=0},containsRange:function(a){var b=this.intersection(a);return null!==b&&a.equals(b)},containsNodeText:function(a){var b=this.cloneRange();b.selectNode(a);var c=b.getNodes([3]);if(c.length>0){b.setStart(c[0],0);var d=c.pop();return b.setEnd(d,d.length),this.containsRange(b)}return this.containsNodeContents(a)},getNodes:function(a,b){return y(this),l(this,a,b)},getDocument:function(){return c(this)},collapseBefore:function(a){this.setEndBefore(a),this.collapse(!1)},collapseAfter:function(a){this.setStartAfter(a),this.collapse(!0)},getBookmark:function(b){var d=c(this),e=a.createRange(d);b=b||I.getBody(d),e.selectNodeContents(b);var f=this.intersection(e),g=0,h=0;return f&&(e.setEnd(f.startContainer,f.startOffset),g=e.toString().length,h=g+f.toString().length),{start:g,end:h,containerNode:b}},moveToBookmark:function(a){var b=a.containerNode,c=0;this.setStart(b,0),this.collapse(!0);for(var d,e,f,g,h=[b],i=!1,j=!1;!j&&(d=h.pop());)if(3==d.nodeType)e=c+d.length,!i&&a.start>=c&&a.start<=e&&(this.setStart(d,a.start-c),i=!0),i&&a.end>=c&&a.end<=e&&(this.setEnd(d,a.end-c),j=!0),c=e;else for(g=d.childNodes,f=g.length;f--;)h.push(g[f])},getName:function(){return"DomRange"},equals:function(a){return H.rangesEqual(this,a)},isValid:function(){return x(this)},inspect:function(){return m(this)},detach:function(){}}),E(H,G),J.extend(H,{rangeProperties:hb,RangeIterator:n,copyComparisonConstants:C,createPrototypeRange:E,inspect:m,toHtml:A,getRangeDocument:c,rangesEqual:function(a,b){return a.startContainer===b.startContainer&&a.startOffset===b.startOffset&&a.endContainer===b.endContainer&&a.endOffset===b.endOffset}}),a.DomRange=H}),E.createCoreModule("WrappedRange",["DomRange"],function(a,b){var c,d,e=a.dom,f=a.util,g=e.DomPosition,h=a.DomRange,i=e.getBody,j=e.getContentDocument,k=e.isCharacterDataNode;if(a.features.implementsDomRange&&!function(){function d(a){for(var b,c=m.length;c--;)b=m[c],a[b]=a.nativeRange[b];a.collapsed=a.startContainer===a.endContainer&&a.startOffset===a.endOffset}function g(a,b,c,d,e){var f=a.startContainer!==b||a.startOffset!=c,g=a.endContainer!==d||a.endOffset!=e,h=!a.equals(a.nativeRange);(f||g||h)&&(a.setEnd(d,e),a.setStart(b,c))}var k,l,m=h.rangeProperties;c=function(a){if(!a)throw b.createError("WrappedRange: Range must be specified");this.nativeRange=a,d(this)},h.createPrototypeRange(c,g),k=c.prototype,k.selectNode=function(a){this.nativeRange.selectNode(a),d(this)},k.cloneContents=function(){return this.nativeRange.cloneContents()},k.surroundContents=function(a){this.nativeRange.surroundContents(a),d(this)},k.collapse=function(a){this.nativeRange.collapse(a),d(this)},k.cloneRange=function(){return new c(this.nativeRange.cloneRange())},k.refresh=function(){d(this)},k.toString=function(){return this.nativeRange.toString()};var n=document.createTextNode("test");i(document).appendChild(n);var o=document.createRange();o.setStart(n,0),o.setEnd(n,0);try{o.setStart(n,1),k.setStart=function(a,b){this.nativeRange.setStart(a,b),d(this)},k.setEnd=function(a,b){this.nativeRange.setEnd(a,b),d(this)},l=function(a){return function(b){this.nativeRange[a](b),d(this)}}}catch(p){k.setStart=function(a,b){try{this.nativeRange.setStart(a,b)}catch(c){this.nativeRange.setEnd(a,b),this.nativeRange.setStart(a,b)}d(this)},k.setEnd=function(a,b){try{this.nativeRange.setEnd(a,b)}catch(c){this.nativeRange.setStart(a,b),this.nativeRange.setEnd(a,b)}d(this)},l=function(a,b){return function(c){try{this.nativeRange[a](c)}catch(e){this.nativeRange[b](c),this.nativeRange[a](c)}d(this)}}}k.setStartBefore=l("setStartBefore","setEndBefore"),k.setStartAfter=l("setStartAfter","setEndAfter"),k.setEndBefore=l("setEndBefore","setStartBefore"),k.setEndAfter=l("setEndAfter","setStartAfter"),k.selectNodeContents=function(a){this.setStartAndEnd(a,0,e.getNodeLength(a))},o.selectNodeContents(n),o.setEnd(n,3);var q=document.createRange();q.selectNodeContents(n),q.setEnd(n,4),q.setStart(n,2),k.compareBoundaryPoints=-1==o.compareBoundaryPoints(o.START_TO_END,q)&&1==o.compareBoundaryPoints(o.END_TO_START,q)?function(a,b){return b=b.nativeRange||b,a==b.START_TO_END?a=b.END_TO_START:a==b.END_TO_START&&(a=b.START_TO_END),this.nativeRange.compareBoundaryPoints(a,b)}:function(a,b){return this.nativeRange.compareBoundaryPoints(a,b.nativeRange||b)};var r=document.createElement("div");r.innerHTML="123";var s=r.firstChild,t=i(document);t.appendChild(r),o.setStart(s,1),o.setEnd(s,2),o.deleteContents(),"13"==s.data&&(k.deleteContents=function(){this.nativeRange.deleteContents(),d(this)},k.extractContents=function(){var a=this.nativeRange.extractContents();return d(this),a}),t.removeChild(r),t=null,f.isHostMethod(o,"createContextualFragment")&&(k.createContextualFragment=function(a){return this.nativeRange.createContextualFragment(a)}),i(document).removeChild(n),k.getName=function(){return"WrappedRange"},a.WrappedRange=c,a.createNativeRange=function(a){return a=j(a,b,"createNativeRange"),a.createRange()}}(),a.features.implementsTextRange){var l=function(a){var b=a.parentElement(),c=a.duplicate();c.collapse(!0);var d=c.parentElement();c=a.duplicate(),c.collapse(!1);var f=c.parentElement(),g=d==f?d:e.getCommonAncestor(d,f);return g==b?g:e.getCommonAncestor(b,g)},m=function(a){return 0==a.compareEndPoints("StartToEnd",a)},n=function(a,b,c,d,f){var h=a.duplicate();h.collapse(c);var i=h.parentElement();
+if(e.isOrIsAncestorOf(b,i)||(i=b),!i.canHaveHTML){var j=new g(i.parentNode,e.getNodeIndex(i));return{boundaryPosition:j,nodeInfo:{nodeIndex:j.offset,containerElement:j.node}}}var l=e.getDocument(i).createElement("span");l.parentNode&&l.parentNode.removeChild(l);for(var m,n,o,p,q,r=c?"StartToStart":"StartToEnd",s=f&&f.containerElement==i?f.nodeIndex:0,t=i.childNodes.length,u=t,v=u;;){if(v==t?i.appendChild(l):i.insertBefore(l,i.childNodes[v]),h.moveToElementText(l),m=h.compareEndPoints(r,a),0==m||s==u)break;if(-1==m){if(u==s+1)break;s=v}else u=u==s+1?s:v;v=Math.floor((s+u)/2),i.removeChild(l)}if(q=l.nextSibling,-1==m&&q&&k(q)){h.setEndPoint(c?"EndToStart":"EndToEnd",a);var w;if(/[\r\n]/.test(q.data)){var x=h.duplicate(),y=x.text.replace(/\r\n/g,"\r").length;for(w=x.moveStart("character",y);-1==(m=x.compareEndPoints("StartToEnd",x));)w++,x.moveStart("character",1)}else w=h.text.length;p=new g(q,w)}else n=(d||!c)&&l.previousSibling,o=(d||c)&&l.nextSibling,p=o&&k(o)?new g(o,0):n&&k(n)?new g(n,n.data.length):new g(i,e.getNodeIndex(l));return l.parentNode.removeChild(l),{boundaryPosition:p,nodeInfo:{nodeIndex:v,containerElement:i}}},o=function(a,b){var c,d,f,g,h=a.offset,j=e.getDocument(a.node),l=i(j).createTextRange(),m=k(a.node);return m?(c=a.node,d=c.parentNode):(g=a.node.childNodes,c=h<g.length?g[h]:null,d=a.node),f=j.createElement("span"),f.innerHTML="&#feff;",c?d.insertBefore(f,c):d.appendChild(f),l.moveToElementText(f),l.collapse(!b),d.removeChild(f),m&&l[b?"moveStart":"moveEnd"]("character",h),l};d=function(a){this.textRange=a,this.refresh()},d.prototype=new h(document),d.prototype.refresh=function(){var a,b,c,d=l(this.textRange);m(this.textRange)?b=a=n(this.textRange,d,!0,!0).boundaryPosition:(c=n(this.textRange,d,!0,!1),a=c.boundaryPosition,b=n(this.textRange,d,!1,!1,c.nodeInfo).boundaryPosition),this.setStart(a.node,a.offset),this.setEnd(b.node,b.offset)},d.prototype.getName=function(){return"WrappedTextRange"},h.copyComparisonConstants(d);var p=function(a){if(a.collapsed)return o(new g(a.startContainer,a.startOffset),!0);var b=o(new g(a.startContainer,a.startOffset),!0),c=o(new g(a.endContainer,a.endOffset),!1),d=i(h.getRangeDocument(a)).createTextRange();return d.setEndPoint("StartToStart",b),d.setEndPoint("EndToEnd",c),d};if(d.rangeToTextRange=p,d.prototype.toTextRange=function(){return p(this)},a.WrappedTextRange=d,!a.features.implementsDomRange||a.config.preferTextRange){var q=function(a){return a("return this;")()}(Function);"undefined"==typeof q.Range&&(q.Range=d),a.createNativeRange=function(a){return a=j(a,b,"createNativeRange"),i(a).createTextRange()},a.WrappedRange=d}}a.createRange=function(c){return c=j(c,b,"createRange"),new a.WrappedRange(a.createNativeRange(c))},a.createRangyRange=function(a){return a=j(a,b,"createRangyRange"),new h(a)},a.createIframeRange=function(c){return b.deprecationNotice("createIframeRange()","createRange(iframeEl)"),a.createRange(c)},a.createIframeRangyRange=function(c){return b.deprecationNotice("createIframeRangyRange()","createRangyRange(iframeEl)"),a.createRangyRange(c)},a.addShimListener(function(b){var c=b.document;"undefined"==typeof c.createRange&&(c.createRange=function(){return a.createRange(c)}),c=b=null})}),E.createCoreModule("WrappedSelection",["DomRange","WrappedRange"],function(a,b){function c(a){return"string"==typeof a?/^backward(s)?$/i.test(a):!!a}function d(a,c){if(a){if(C.isWindow(a))return a;if(a instanceof r)return a.win;var d=C.getContentDocument(a,b,c);return C.getWindow(d)}return window}function e(a){return d(a,"getWinSelection").getSelection()}function f(a){return d(a,"getDocSelection").document.selection}function g(a){var b=!1;return a.anchorNode&&(b=1==C.comparePoints(a.anchorNode,a.anchorOffset,a.focusNode,a.focusOffset)),b}function h(a,b,c){var d=c?"end":"start",e=c?"start":"end";a.anchorNode=b[d+"Container"],a.anchorOffset=b[d+"Offset"],a.focusNode=b[e+"Container"],a.focusOffset=b[e+"Offset"]}function i(a){var b=a.nativeSelection;a.anchorNode=b.anchorNode,a.anchorOffset=b.anchorOffset,a.focusNode=b.focusNode,a.focusOffset=b.focusOffset}function j(a){a.anchorNode=a.focusNode=null,a.anchorOffset=a.focusOffset=0,a.rangeCount=0,a.isCollapsed=!0,a._ranges.length=0}function k(b){var c;return b instanceof F?(c=a.createNativeRange(b.getDocument()),c.setEnd(b.endContainer,b.endOffset),c.setStart(b.startContainer,b.startOffset)):b instanceof G?c=b.nativeRange:J.implementsDomRange&&b instanceof C.getWindow(b.startContainer).Range&&(c=b),c}function l(a){if(!a.length||1!=a[0].nodeType)return!1;for(var b=1,c=a.length;c>b;++b)if(!C.isAncestorOf(a[0],a[b]))return!1;return!0}function m(a){var c=a.getNodes();if(!l(c))throw b.createError("getSingleElementFromRange: range "+a.inspect()+" did not consist of a single element");return c[0]}function n(a){return!!a&&"undefined"!=typeof a.text}function o(a,b){var c=new G(b);a._ranges=[c],h(a,c,!1),a.rangeCount=1,a.isCollapsed=c.collapsed}function p(b){if(b._ranges.length=0,"None"==b.docSelection.type)j(b);else{var c=b.docSelection.createRange();if(n(c))o(b,c);else{b.rangeCount=c.length;for(var d,e=L(c.item(0)),f=0;f<b.rangeCount;++f)d=a.createRange(e),d.selectNode(c.item(f)),b._ranges.push(d);b.isCollapsed=1==b.rangeCount&&b._ranges[0].collapsed,h(b,b._ranges[b.rangeCount-1],!1)}}}function q(a,c){for(var d=a.docSelection.createRange(),e=m(c),f=L(d.item(0)),g=M(f).createControlRange(),h=0,i=d.length;i>h;++h)g.add(d.item(h));try{g.add(e)}catch(j){throw b.createError("addRange(): Element within the specified Range could not be added to control selection (does it have layout?)")}g.select(),p(a)}function r(a,b,c){this.nativeSelection=a,this.docSelection=b,this._ranges=[],this.win=c,this.refresh()}function s(a){a.win=a.anchorNode=a.focusNode=a._ranges=null,a.rangeCount=a.anchorOffset=a.focusOffset=0,a.detached=!0}function t(a,b){for(var c,d,e=bb.length;e--;)if(c=bb[e],d=c.selection,"deleteAll"==b)s(d);else if(c.win==a)return"delete"==b?(bb.splice(e,1),!0):d;return"deleteAll"==b&&(bb.length=0),null}function u(a,c){for(var d,e=L(c[0].startContainer),f=M(e).createControlRange(),g=0,h=c.length;h>g;++g){d=m(c[g]);try{f.add(d)}catch(i){throw b.createError("setRanges(): Element within one of the specified Ranges could not be added to control selection (does it have layout?)")}}f.select(),p(a)}function v(a,b){if(a.win.document!=L(b))throw new H("WRONG_DOCUMENT_ERR")}function w(b){return function(c,d){var e;this.rangeCount?(e=this.getRangeAt(0),e["set"+(b?"Start":"End")](c,d)):(e=a.createRange(this.win.document),e.setStartAndEnd(c,d)),this.setSingleRange(e,this.isBackward())}}function x(a){var b=[],c=new I(a.anchorNode,a.anchorOffset),d=new I(a.focusNode,a.focusOffset),e="function"==typeof a.getName?a.getName():"Selection";if("undefined"!=typeof a.rangeCount)for(var f=0,g=a.rangeCount;g>f;++f)b[f]=F.inspect(a.getRangeAt(f));return"["+e+"(Ranges: "+b.join(", ")+")(anchor: "+c.inspect()+", focus: "+d.inspect()+"]"}a.config.checkSelectionRanges=!0;var y,z,A="boolean",B="number",C=a.dom,D=a.util,E=D.isHostMethod,F=a.DomRange,G=a.WrappedRange,H=a.DOMException,I=C.DomPosition,J=a.features,K="Control",L=C.getDocument,M=C.getBody,N=F.rangesEqual,O=E(window,"getSelection"),P=D.isHostObject(document,"selection");J.implementsWinGetSelection=O,J.implementsDocSelection=P;var Q=P&&(!O||a.config.preferTextRange);Q?(y=f,a.isSelectionValid=function(a){var b=d(a,"isSelectionValid").document,c=b.selection;return"None"!=c.type||L(c.createRange().parentElement())==b}):O?(y=e,a.isSelectionValid=function(){return!0}):b.fail("Neither document.selection or window.getSelection() detected."),a.getNativeSelection=y;var R=y(),S=a.createNativeRange(document),T=M(document),U=D.areHostProperties(R,["anchorNode","focusNode","anchorOffset","focusOffset"]);J.selectionHasAnchorAndFocus=U;var V=E(R,"extend");J.selectionHasExtend=V;var W=typeof R.rangeCount==B;J.selectionHasRangeCount=W;var X=!1,Y=!0,Z=V?function(b,c){var d=F.getRangeDocument(c),e=a.createRange(d);e.collapseToPoint(c.endContainer,c.endOffset),b.addRange(k(e)),b.extend(c.startContainer,c.startOffset)}:null;D.areHostMethods(R,["addRange","getRangeAt","removeAllRanges"])&&typeof R.rangeCount==B&&J.implementsDomRange&&!function(){var b=window.getSelection();if(b){for(var c=b.rangeCount,d=c>1,e=[],f=g(b),h=0;c>h;++h)e[h]=b.getRangeAt(h);var i=M(document),j=i.appendChild(document.createElement("div"));j.contentEditable="false";var k=j.appendChild(document.createTextNode(" ")),l=document.createRange();if(l.setStart(k,1),l.collapse(!0),b.addRange(l),Y=1==b.rangeCount,b.removeAllRanges(),!d){var m=window.navigator.appVersion.match(/Chrome\/(.*?) /);if(m&&parseInt(m[1])>=36)X=!1;else{var n=l.cloneRange();l.setStart(k,0),n.setEnd(k,3),n.setStart(k,2),b.addRange(l),b.addRange(n),X=2==b.rangeCount}}for(i.removeChild(j),b.removeAllRanges(),h=0;c>h;++h)0==h&&f?Z?Z(b,e[h]):(a.warn("Rangy initialization: original selection was backwards but selection has been restored forwards because the browser does not support Selection.extend"),b.addRange(e[h])):b.addRange(e[h])}}(),J.selectionSupportsMultipleRanges=X,J.collapsedNonEditableSelectionsSupported=Y;var $,_=!1;T&&E(T,"createControlRange")&&($=T.createControlRange(),D.areHostProperties($,["item","add"])&&(_=!0)),J.implementsControlRange=_,z=U?function(a){return a.anchorNode===a.focusNode&&a.anchorOffset===a.focusOffset}:function(a){return a.rangeCount?a.getRangeAt(a.rangeCount-1).collapsed:!1};var ab;E(R,"getRangeAt")?ab=function(a,b){try{return a.getRangeAt(b)}catch(c){return null}}:U&&(ab=function(b){var c=L(b.anchorNode),d=a.createRange(c);return d.setStartAndEnd(b.anchorNode,b.anchorOffset,b.focusNode,b.focusOffset),d.collapsed!==this.isCollapsed&&d.setStartAndEnd(b.focusNode,b.focusOffset,b.anchorNode,b.anchorOffset),d}),r.prototype=a.selectionPrototype;var bb=[],cb=function(a){if(a&&a instanceof r)return a.refresh(),a;a=d(a,"getNativeSelection");var b=t(a),c=y(a),e=P?f(a):null;return b?(b.nativeSelection=c,b.docSelection=e,b.refresh()):(b=new r(c,e,a),bb.push({win:a,selection:b})),b};a.getSelection=cb,a.getIframeSelection=function(c){return b.deprecationNotice("getIframeSelection()","getSelection(iframeEl)"),a.getSelection(C.getIframeWindow(c))};var db=r.prototype;if(!Q&&U&&D.areHostMethods(R,["removeAllRanges","addRange"])){db.removeAllRanges=function(){this.nativeSelection.removeAllRanges(),j(this)};var eb=function(a,b){Z(a.nativeSelection,b),a.refresh()};db.addRange=W?function(b,d){if(_&&P&&this.docSelection.type==K)q(this,b);else if(c(d)&&V)eb(this,b);else{var e;X?e=this.rangeCount:(this.removeAllRanges(),e=0);var f=k(b).cloneRange();try{this.nativeSelection.addRange(f)}catch(g){}if(this.rangeCount=this.nativeSelection.rangeCount,this.rangeCount==e+1){if(a.config.checkSelectionRanges){var i=ab(this.nativeSelection,this.rangeCount-1);i&&!N(i,b)&&(b=new G(i))}this._ranges[this.rangeCount-1]=b,h(this,b,hb(this.nativeSelection)),this.isCollapsed=z(this)}else this.refresh()}}:function(a,b){c(b)&&V?eb(this,a):(this.nativeSelection.addRange(k(a)),this.refresh())},db.setRanges=function(a){if(_&&P&&a.length>1)u(this,a);else{this.removeAllRanges();for(var b=0,c=a.length;c>b;++b)this.addRange(a[b])}}}else{if(!(E(R,"empty")&&E(S,"select")&&_&&Q))return b.fail("No means of selecting a Range or TextRange was found"),!1;db.removeAllRanges=function(){try{if(this.docSelection.empty(),"None"!=this.docSelection.type){var a;if(this.anchorNode)a=L(this.anchorNode);else if(this.docSelection.type==K){var b=this.docSelection.createRange();b.length&&(a=L(b.item(0)))}if(a){var c=M(a).createTextRange();c.select(),this.docSelection.empty()}}}catch(d){}j(this)},db.addRange=function(b){this.docSelection.type==K?q(this,b):(a.WrappedTextRange.rangeToTextRange(b).select(),this._ranges[0]=b,this.rangeCount=1,this.isCollapsed=this._ranges[0].collapsed,h(this,b,!1))},db.setRanges=function(a){this.removeAllRanges();var b=a.length;b>1?u(this,a):b&&this.addRange(a[0])}}db.getRangeAt=function(a){if(0>a||a>=this.rangeCount)throw new H("INDEX_SIZE_ERR");return this._ranges[a].cloneRange()};var fb;if(Q)fb=function(b){var c;a.isSelectionValid(b.win)?c=b.docSelection.createRange():(c=M(b.win.document).createTextRange(),c.collapse(!0)),b.docSelection.type==K?p(b):n(c)?o(b,c):j(b)};else if(E(R,"getRangeAt")&&typeof R.rangeCount==B)fb=function(b){if(_&&P&&b.docSelection.type==K)p(b);else if(b._ranges.length=b.rangeCount=b.nativeSelection.rangeCount,b.rangeCount){for(var c=0,d=b.rangeCount;d>c;++c)b._ranges[c]=new a.WrappedRange(b.nativeSelection.getRangeAt(c));h(b,b._ranges[b.rangeCount-1],hb(b.nativeSelection)),b.isCollapsed=z(b)}else j(b)};else{if(!U||typeof R.isCollapsed!=A||typeof S.collapsed!=A||!J.implementsDomRange)return b.fail("No means of obtaining a Range or TextRange from the user's selection was found"),!1;fb=function(a){var b,c=a.nativeSelection;c.anchorNode?(b=ab(c,0),a._ranges=[b],a.rangeCount=1,i(a),a.isCollapsed=z(a)):j(a)}}db.refresh=function(a){var b=a?this._ranges.slice(0):null,c=this.anchorNode,d=this.anchorOffset;if(fb(this),a){var e=b.length;if(e!=this._ranges.length)return!0;if(this.anchorNode!=c||this.anchorOffset!=d)return!0;for(;e--;)if(!N(b[e],this._ranges[e]))return!0;return!1}};var gb=function(a,b){var c=a.getAllRanges();a.removeAllRanges();for(var d=0,e=c.length;e>d;++d)N(b,c[d])||a.addRange(c[d]);a.rangeCount||j(a)};db.removeRange=_&&P?function(a){if(this.docSelection.type==K){for(var b,c=this.docSelection.createRange(),d=m(a),e=L(c.item(0)),f=M(e).createControlRange(),g=!1,h=0,i=c.length;i>h;++h)b=c.item(h),b!==d||g?f.add(c.item(h)):g=!0;f.select(),p(this)}else gb(this,a)}:function(a){gb(this,a)};var hb;!Q&&U&&J.implementsDomRange?(hb=g,db.isBackward=function(){return hb(this)}):hb=db.isBackward=function(){return!1},db.isBackwards=db.isBackward,db.toString=function(){for(var a=[],b=0,c=this.rangeCount;c>b;++b)a[b]=""+this._ranges[b];return a.join("")},db.collapse=function(b,c){v(this,b);var d=a.createRange(b);d.collapseToPoint(b,c),this.setSingleRange(d),this.isCollapsed=!0},db.collapseToStart=function(){if(!this.rangeCount)throw new H("INVALID_STATE_ERR");var a=this._ranges[0];this.collapse(a.startContainer,a.startOffset)},db.collapseToEnd=function(){if(!this.rangeCount)throw new H("INVALID_STATE_ERR");var a=this._ranges[this.rangeCount-1];this.collapse(a.endContainer,a.endOffset)},db.selectAllChildren=function(b){v(this,b);var c=a.createRange(b);c.selectNodeContents(b),this.setSingleRange(c)},db.deleteFromDocument=function(){if(_&&P&&this.docSelection.type==K){for(var a,b=this.docSelection.createRange();b.length;)a=b.item(0),b.remove(a),a.parentNode.removeChild(a);this.refresh()}else if(this.rangeCount){var c=this.getAllRanges();if(c.length){this.removeAllRanges();for(var d=0,e=c.length;e>d;++d)c[d].deleteContents();this.addRange(c[e-1])}}},db.eachRange=function(a,b){for(var c=0,d=this._ranges.length;d>c;++c)if(a(this.getRangeAt(c)))return b},db.getAllRanges=function(){var a=[];return this.eachRange(function(b){a.push(b)}),a},db.setSingleRange=function(a,b){this.removeAllRanges(),this.addRange(a,b)},db.callMethodOnEachRange=function(a,b){var c=[];return this.eachRange(function(d){c.push(d[a].apply(d,b))}),c},db.setStart=w(!0),db.setEnd=w(!1),a.rangePrototype.select=function(a){cb(this.getDocument()).setSingleRange(this,a)},db.changeEachRange=function(a){var b=[],c=this.isBackward();this.eachRange(function(c){a(c),b.push(c)}),this.removeAllRanges(),c&&1==b.length?this.addRange(b[0],"backward"):this.setRanges(b)},db.containsNode=function(a,b){return this.eachRange(function(c){return c.containsNode(a,b)},!0)||!1},db.getBookmark=function(a){return{backward:this.isBackward(),rangeBookmarks:this.callMethodOnEachRange("getBookmark",[a])}},db.moveToBookmark=function(b){for(var c,d,e=[],f=0;c=b.rangeBookmarks[f++];)d=a.createRange(this.win),d.moveToBookmark(c),e.push(d);b.backward?this.setSingleRange(e[0],"backward"):this.setRanges(e)},db.toHtml=function(){var a=[];return this.eachRange(function(b){a.push(F.toHtml(b))}),a.join("")},J.implementsTextRange&&(db.getNativeTextRange=function(){var c;if(c=this.docSelection){var d=c.createRange();if(n(d))return d;throw b.createError("getNativeTextRange: selection is a control selection")}if(this.rangeCount>0)return a.WrappedTextRange.rangeToTextRange(this.getRangeAt(0));throw b.createError("getNativeTextRange: selection contains no range")}),db.getName=function(){return"WrappedSelection"},db.inspect=function(){return x(this)},db.detach=function(){t(this.win,"delete"),s(this)},r.detachAll=function(){t(null,"deleteAll")},r.inspect=x,r.isDirectionBackward=c,a.Selection=r,a.selectionPrototype=db,a.addShimListener(function(a){"undefined"==typeof a.getSelection&&(a.getSelection=function(){return cb(a)}),a=null})});var J=!1,K=function(){J||(J=!0,!E.initialized&&E.config.autoInitialize&&l())};return C&&("complete"==document.readyState?K():(a(document,"addEventListener")&&document.addEventListener("DOMContentLoaded",K,!1),G(window,"load",K))),E},this),function(a,b){"function"==typeof define&&define.amd?define(["./rangy-core"],a):"undefined"!=typeof module&&"object"==typeof exports?module.exports=a(require("rangy")):a(b.rangy)}(function(a){a.createModule("SaveRestore",["WrappedRange"],function(a,b){function c(a,b){return(b||document).getElementById(a)}function d(a,b){var c,d="selectionBoundary_"+ +new Date+"_"+(""+Math.random()).slice(2),e=o.getDocument(a.startContainer),f=a.cloneRange();return f.collapse(b),c=e.createElement("span"),c.id=d,c.style.lineHeight="0",c.style.display="none",c.className="rangySelectionBoundary",c.appendChild(e.createTextNode(p)),f.insertNode(c),c}function e(a,d,e,f){var g=c(e,a);g?(d[f?"setStartBefore":"setEndBefore"](g),g.parentNode.removeChild(g)):b.warn("Marker element has been removed. Cannot restore selection.")}function f(a,b){return b.compareBoundaryPoints(a.START_TO_START,a)}function g(b,c){var e,f,g=a.DomRange.getRangeDocument(b),h=b.toString();return b.collapsed?(f=d(b,!1),{document:g,markerId:f.id,collapsed:!0}):(f=d(b,!1),e=d(b,!0),{document:g,startMarkerId:e.id,endMarkerId:f.id,collapsed:!1,backward:c,toString:function(){return"original text: '"+h+"', new text: '"+b.toString()+"'"}})}function h(d,f){var g=d.document;"undefined"==typeof f&&(f=!0);var h=a.createRange(g);if(d.collapsed){var i=c(d.markerId,g);if(i){i.style.display="inline";var j=i.previousSibling;j&&3==j.nodeType?(i.parentNode.removeChild(i),h.collapseToPoint(j,j.length)):(h.collapseBefore(i),i.parentNode.removeChild(i))}else b.warn("Marker element has been removed. Cannot restore selection.")}else e(g,h,d.startMarkerId,!0),e(g,h,d.endMarkerId,!1);return f&&h.normalizeBoundaries(),h}function i(b,d){var e,h,i=[];b=b.slice(0),b.sort(f);for(var j=0,k=b.length;k>j;++j)i[j]=g(b[j],d);for(j=k-1;j>=0;--j)e=b[j],h=a.DomRange.getRangeDocument(e),e.collapsed?e.collapseAfter(c(i[j].markerId,h)):(e.setEndBefore(c(i[j].endMarkerId,h)),e.setStartAfter(c(i[j].startMarkerId,h)));return i}function j(c){if(!a.isSelectionValid(c))return b.warn("Cannot save selection. This usually happens when the selection is collapsed and the selection document has lost focus."),null;var d=a.getSelection(c),e=d.getAllRanges(),f=1==e.length&&d.isBackward(),g=i(e,f);return f?d.setSingleRange(e[0],"backward"):d.setRanges(e),{win:c,rangeInfos:g,restored:!1}}function k(a){for(var b=[],c=a.length,d=c-1;d>=0;d--)b[d]=h(a[d],!0);return b}function l(b,c){if(!b.restored){var d=b.rangeInfos,e=a.getSelection(b.win),f=k(d),g=d.length;1==g&&c&&a.features.selectionHasExtend&&d[0].backward?(e.removeAllRanges(),e.addRange(f[0],!0)):e.setRanges(f),b.restored=!0}}function m(a,b){var d=c(b,a);d&&d.parentNode.removeChild(d)}function n(a){for(var b,c=a.rangeInfos,d=0,e=c.length;e>d;++d)b=c[d],b.collapsed?m(a.doc,b.markerId):(m(a.doc,b.startMarkerId),m(a.doc,b.endMarkerId))}var o=a.dom,p="";a.util.extend(a,{saveRange:g,restoreRange:h,saveRanges:i,restoreRanges:k,saveSelection:j,restoreSelection:l,removeMarkerElement:m,removeMarkers:n})})},this);var Base=function(){};Base.extend=function(a,b){var c=Base.prototype.extend;Base._prototyping=!0;var d=new this;c.call(d,a),d.base=function(){},delete Base._prototyping;var e=d.constructor,f=d.constructor=function(){if(!Base._prototyping)if(this._constructing||this.constructor==f)this._constructing=!0,e.apply(this,arguments),delete this._constructing;else if(null!=arguments[0])return(arguments[0].extend||c).call(arguments[0],d)};return f.ancestor=this,f.extend=this.extend,f.forEach=this.forEach,f.implement=this.implement,f.prototype=d,f.toString=this.toString,f.valueOf=function(a){return"object"==a?f:e.valueOf()},c.call(f,b),"function"==typeof f.init&&f.init(),f},Base.prototype={extend:function(a,b){if(arguments.length>1){var c=this[a];if(c&&"function"==typeof b&&(!c.valueOf||c.valueOf()!=b.valueOf())&&/\bbase\b/.test(b)){var d=b.valueOf();b=function(){var a=this.base||Base.prototype.base;this.base=c;var b=d.apply(this,arguments);return this.base=a,b},b.valueOf=function(a){return"object"==a?b:d},b.toString=Base.toString}this[a]=b}else if(a){var e=Base.prototype.extend;Base._prototyping||"function"==typeof this||(e=this.extend||e);for(var f={toSource:null},g=["constructor","toString","valueOf"],h=Base._prototyping?0:1;i=g[h++];)a[i]!=f[i]&&e.call(this,i,a[i]);for(var i in a)f[i]||e.call(this,i,a[i])}return this}},Base=Base.extend({constructor:function(){this.extend(arguments[0])}},{ancestor:Object,version:"1.1",forEach:function(a,b,c){for(var d in a)void 0===this.prototype[d]&&b.call(c,a[d],d,a)},implement:function(){for(var a=0;a<arguments.length;a++)"function"==typeof arguments[a]?arguments[a](this.prototype):this.prototype.extend(arguments[a]);return this},toString:function(){return String(this.valueOf())}}),wysihtml5.browser=function(){function a(a){return+(/ipad|iphone|ipod/.test(a)&&a.match(/ os (\d+).+? like mac os x/)||[void 0,0])[1]}function b(a){return+(a.match(/android (\d+)/)||[void 0,0])[1]}function c(a,b){var c,d=-1;return"Microsoft Internet Explorer"==navigator.appName?c=new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})"):"Netscape"==navigator.appName&&(c=new RegExp("Trident/.*rv:([0-9]{1,}[.0-9]{0,})")),c&&null!=c.exec(navigator.userAgent)&&(d=parseFloat(RegExp.$1)),-1===d?!1:a?b?"<"===b?d>a:">"===b?a>d:"<="===b?d>=a:">="===b?a>=d:void 0:a===d:!0}var d=navigator.userAgent,e=document.createElement("div"),f=-1!==d.indexOf("Gecko")&&-1===d.indexOf("KHTML"),g=-1!==d.indexOf("AppleWebKit/"),h=-1!==d.indexOf("Chrome/"),i=-1!==d.indexOf("Opera/");return{USER_AGENT:d,supported:function(){var c=this.USER_AGENT.toLowerCase(),d="contentEditable"in e,f=document.execCommand&&document.queryCommandSupported&&document.queryCommandState,g=document.querySelector&&document.querySelectorAll,h=this.isIos()&&a(c)<5||this.isAndroid()&&b(c)<4||-1!==c.indexOf("opera mobi")||-1!==c.indexOf("hpwos/");return d&&f&&g&&!h},isTouchDevice:function(){return this.supportsEvent("touchmove")},isIos:function(){return/ipad|iphone|ipod/i.test(this.USER_AGENT)},isAndroid:function(){return-1!==this.USER_AGENT.indexOf("Android")},supportsSandboxedIframes:function(){return c()},throwsMixedContentWarningWhenIframeSrcIsEmpty:function(){return!("querySelector"in document)},displaysCaretInEmptyContentEditableCorrectly:function(){return c()},hasCurrentStyleProperty:function(){return"currentStyle"in e},insertsLineBreaksOnReturn:function(){return f},supportsPlaceholderAttributeOn:function(a){return"placeholder"in a},supportsEvent:function(a){return"on"+a in e||function(){return e.setAttribute("on"+a,"return;"),"function"==typeof e["on"+a]}()},supportsEventsInIframeCorrectly:function(){return!i},supportsHTML5Tags:function(a){var b=a.createElement("div"),c="<article>foo</article>";return b.innerHTML=c,b.innerHTML.toLowerCase()===c},supportsCommand:function(){var a={formatBlock:c(10,"<="),insertUnorderedList:c(),insertOrderedList:c()},b={insertHTML:f};return function(c,d){var e=a[d];if(!e){try{return c.queryCommandSupported(d)}catch(f){}try{return c.queryCommandEnabled(d)}catch(g){return!!b[d]}}return!1}}(),doesAutoLinkingInContentEditable:function(){return c()},canDisableAutoLinking:function(){return this.supportsCommand(document,"AutoUrlDetect")},clearsContentEditableCorrectly:function(){return f||i||g},supportsGetAttributeCorrectly:function(){var a=document.createElement("td");return"1"!=a.getAttribute("rowspan")},canSelectImagesInContentEditable:function(){return f||c()||i},autoScrollsToCaret:function(){return!g},autoClosesUnclosedTags:function(){var a,b,c=e.cloneNode(!1);return c.innerHTML="<p><div></div>",b=c.innerHTML.toLowerCase(),a="<p></p><div></div>"===b||"<p><div></div></p>"===b,this.autoClosesUnclosedTags=function(){return a},a},supportsNativeGetElementsByClassName:function(){return-1!==String(document.getElementsByClassName).indexOf("[native code]")},supportsSelectionModify:function(){return"getSelection"in window&&"modify"in window.getSelection()},needsSpaceAfterLineBreak:function(){return i},supportsSpeechApiOn:function(a){var b=d.match(/Chrome\/(\d+)/)||[void 0,0];return b[1]>=11&&("onwebkitspeechchange"in a||"speech"in a)},crashesWhenDefineProperty:function(a){return c(9)&&("XMLHttpRequest"===a||"XDomainRequest"===a)},doesAsyncFocus:function(){return c()},hasProblemsSettingCaretAfterImg:function(){return c()},hasUndoInContextMenu:function(){return f||h||i},hasInsertNodeIssue:function(){return i},hasIframeFocusIssue:function(){return c()},createsNestedInvalidMarkupAfterPaste:function(){return g},supportsMutationEvents:function(){return"MutationEvent"in window},supportsModenPaste:function(){return!("clipboardData"in window)}}}(),wysihtml5.lang.array=function(a){return{contains:function(b){if(Array.isArray(b)){for(var c=b.length;c--;)if(-1!==wysihtml5.lang.array(a).indexOf(b[c]))return!0;return!1}return-1!==wysihtml5.lang.array(a).indexOf(b)},indexOf:function(b){if(a.indexOf)return a.indexOf(b);for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1},without:function(b){b=wysihtml5.lang.array(b);for(var c=[],d=0,e=a.length;e>d;d++)b.contains(a[d])||c.push(a[d]);return c},get:function(){for(var b=0,c=a.length,d=[];c>b;b++)d.push(a[b]);return d},map:function(b,c){if(Array.prototype.map)return a.map(b,c);for(var d=a.length>>>0,e=new Array(d),f=0;d>f;f++)e[f]=b.call(c,a[f],f,a);return e},unique:function(){for(var b=[],c=a.length,d=0;c>d;)wysihtml5.lang.array(b).contains(a[d])||b.push(a[d]),d++;return b}}},wysihtml5.lang.Dispatcher=Base.extend({on:function(a,b){return this.events=this.events||{},this.events[a]=this.events[a]||[],this.events[a].push(b),this},off:function(a,b){this.events=this.events||{};var c,d,e=0;if(a){for(c=this.events[a]||[],d=[];e<c.length;e++)c[e]!==b&&b&&d.push(c[e]);this.events[a]=d}else this.events={};return this},fire:function(a,b){this.events=this.events||{};for(var c=this.events[a]||[],d=0;d<c.length;d++)c[d].call(this,b);return this},observe:function(){return this.on.apply(this,arguments)},stopObserving:function(){return this.off.apply(this,arguments)}}),wysihtml5.lang.object=function(a){return{merge:function(b){for(var c in b)a[c]=b[c];return this},get:function(){return a},clone:function(b){var c,d={};if(null===a||!wysihtml5.lang.object(a).isPlainObject())return a;for(c in a)a.hasOwnProperty(c)&&(d[c]=b?wysihtml5.lang.object(a[c]).clone(b):a[c]);return d},isArray:function(){return"[object Array]"===Object.prototype.toString.call(a)},isFunction:function(){return"[object Function]"===Object.prototype.toString.call(a)},isPlainObject:function(){return"[object Object]"===Object.prototype.toString.call(a)}}},function(){var a=/^\s+/,b=/\s+$/,c=/[&<>\t"]/g,d={"&":"&","<":"<",">":">",'"':"""," ":" "};wysihtml5.lang.string=function(e){return e=String(e),{trim:function(){return e.replace(a,"").replace(b,"")},interpolate:function(a){for(var b in a)e=this.replace("#{"+b+"}").by(a[b]);return e},replace:function(a){return{by:function(b){return e.split(a).join(b)}}},escapeHTML:function(a,b){var f=e.replace(c,function(a){return d[a]});return a&&(f=f.replace(/(?:\r\n|\r|\n)/g,"<br />")),b&&(f=f.replace(/ /gi," ")),f}}}}(),function(a){function b(a,b){return f(a,b)?a:(a===a.ownerDocument.documentElement&&(a=a.ownerDocument.body),g(a,b))}function c(a){return a.replace(i,function(a,b){var c=(b.match(j)||[])[1]||"",d=l[c];b=b.replace(j,""),b.split(d).length>b.split(c).length&&(b+=c,c="");var e=b,f=b;return b.length>k&&(f=f.substr(0,k)+"..."),"www."===e.substr(0,4)&&(e="http://"+e),'<a href="'+e+'">'+f+"</a>"+c})}function d(a){var b=a._wysihtml5_tempElement;return b||(b=a._wysihtml5_tempElement=a.createElement("div")),b}function e(b){var e=b.parentNode,f=a.lang.string(b.data).escapeHTML(),g=d(e.ownerDocument);for(g.innerHTML="<span></span>"+c(f),g.removeChild(g.firstChild);g.firstChild;)e.insertBefore(g.firstChild,b);e.removeChild(b)}function f(b,c){for(var d;b.parentNode;){if(b=b.parentNode,d=b.nodeName,b.className&&a.lang.array(b.className.split(" ")).contains(c))return!0;if(h.contains(d))return!0;if("body"===d)return!1}return!1}function g(b,c){if(!(h.contains(b.nodeName)||b.className&&a.lang.array(b.className.split(" ")).contains(c))){if(b.nodeType===a.TEXT_NODE&&b.data.match(i))return void e(b);for(var d=a.lang.array(b.childNodes).get(),f=d.length,j=0;f>j;j++)g(d[j],c);return b}}var h=a.lang.array(["CODE","PRE","A","SCRIPT","HEAD","TITLE","STYLE"]),i=/((https?:\/\/|www\.)[^\s<]{3,})/gi,j=/([^\w\/\-](,?))$/i,k=100,l={")":"(","]":"[","}":"{"};a.dom.autoLink=b,a.dom.autoLink.URL_REG_EXP=i}(wysihtml5),function(a){var b=a.dom;b.addClass=function(a,c){var d=a.classList;return d?d.add(c):void(b.hasClass(a,c)||(a.className+=" "+c))},b.removeClass=function(a,b){var c=a.classList;return c?c.remove(b):void(a.className=a.className.replace(new RegExp("(^|\\s+)"+b+"(\\s+|$)")," "))},b.hasClass=function(a,b){var c=a.classList;if(c)return c.contains(b);var d=a.className;return d.length>0&&(d==b||new RegExp("(^|\\s)"+b+"(\\s|$)").test(d))}}(wysihtml5),wysihtml5.dom.contains=function(){var a=document.documentElement;return a.contains?function(a,b){return b.nodeType!==wysihtml5.ELEMENT_NODE&&(b=b.parentNode),a!==b&&a.contains(b)}:a.compareDocumentPosition?function(a,b){return!!(16&a.compareDocumentPosition(b))}:void 0}(),wysihtml5.dom.convertToList=function(){function a(a,b){var c=a.createElement("li");return b.appendChild(c),c}function b(a,b){return a.createElement(b)}function c(c,d,e){if("UL"===c.nodeName||"OL"===c.nodeName||"MENU"===c.nodeName)return c;var f,g,h,i,j,k,l,m,n,o=c.ownerDocument,p=b(o,d),q=c.querySelectorAll("br"),r=q.length;for(n=0;r>n;n++)for(i=q[n];(j=i.parentNode)&&j!==c&&j.lastChild===i;){if("block"===wysihtml5.dom.getStyle("display").from(j)){j.removeChild(i);break}wysihtml5.dom.insert(i).after(i.parentNode)}for(f=wysihtml5.lang.array(c.childNodes).get(),g=f.length,n=0;g>n;n++)m=m||a(o,p),h=f[n],k="block"===wysihtml5.dom.getStyle("display").from(h),l="BR"===h.nodeName,!k||e&&wysihtml5.dom.hasClass(h,e)?l?m=m.firstChild?null:m:m.appendChild(h):(m=m.firstChild?a(o,p):m,m.appendChild(h),m=null);return 0===f.length&&a(o,p),c.parentNode.replaceChild(p,c),p}return c}(),wysihtml5.dom.copyAttributes=function(a){return{from:function(b){return{to:function(c){for(var d,e=0,f=a.length;f>e;e++)d=a[e],"undefined"!=typeof b[d]&&""!==b[d]&&(c[d]=b[d]);return{andTo:arguments.callee}}}}}},function(a){var b=["-webkit-box-sizing","-moz-box-sizing","-ms-box-sizing","box-sizing"],c=function(b){return d(b)?parseInt(a.getStyle("width").from(b),10)<b.offsetWidth:!1},d=function(c){for(var d=0,e=b.length;e>d;d++)if("border-box"===a.getStyle(b[d]).from(c))return b[d]};a.copyStyles=function(d){return{from:function(e){c(e)&&(d=wysihtml5.lang.array(d).without(b));for(var f,g="",h=d.length,i=0;h>i;i++)f=d[i],g+=f+":"+a.getStyle(f).from(e)+";";return{to:function(b){return a.setStyles(g).on(b),{andTo:arguments.callee}}}}}}}(wysihtml5.dom),function(a){a.dom.delegate=function(b,c,d,e){return a.dom.observe(b,d,function(d){for(var f=d.target,g=a.lang.array(b.querySelectorAll(c));f&&f!==b;){if(g.contains(f)){e.call(f,d);break}f=f.parentNode}})}}(wysihtml5),function(a){a.dom.domNode=function(b){var c=[a.ELEMENT_NODE,a.TEXT_NODE],d=function(b){return b.nodeType===a.TEXT_NODE&&/^\s*$/g.test(b.data)
+};return{prev:function(e){var f=b.previousSibling,g=e&&e.nodeTypes?e.nodeTypes:c;return f?!a.lang.array(g).contains(f.nodeType)||e&&e.ignoreBlankTexts&&d(f)?a.dom.domNode(f).prev(e):f:null},next:function(e){var f=b.nextSibling,g=e&&e.nodeTypes?e.nodeTypes:c;return f?!a.lang.array(g).contains(f.nodeType)||e&&e.ignoreBlankTexts&&d(f)?a.dom.domNode(f).next(e):f:null},lastLeafNode:function(c){var d;if(1!==b.nodeType)return b;if(d=b.lastChild,!d)return b;if(c&&c.leafClasses)for(var e=c.leafClasses.length;e--;)if(a.dom.hasClass(b,c.leafClasses[e]))return b;return a.dom.domNode(d).lastLeafNode(c)}}}}(wysihtml5),wysihtml5.dom.getAsDom=function(){var a=function(a,b){var c=b.createElement("div");c.style.display="none",b.body.appendChild(c);try{c.innerHTML=a}catch(d){}return b.body.removeChild(c),c},b=function(a){if(!a._wysihtml5_supportsHTML5Tags){for(var b=0,d=c.length;d>b;b++)a.createElement(c[b]);a._wysihtml5_supportsHTML5Tags=!0}},c=["abbr","article","aside","audio","bdi","canvas","command","datalist","details","figcaption","figure","footer","header","hgroup","keygen","mark","meter","nav","output","progress","rp","rt","ruby","svg","section","source","summary","time","track","video","wbr"];return function(c,d){d=d||document;var e;return"object"==typeof c&&c.nodeType?(e=d.createElement("div"),e.appendChild(c)):wysihtml5.browser.supportsHTML5Tags(d)?(e=d.createElement("div"),e.innerHTML=c):(b(d),e=a(c,d)),e}}(),wysihtml5.dom.getParentElement=function(){function a(a,b){return b&&b.length?"string"==typeof b?a===b:wysihtml5.lang.array(b).contains(a):!0}function b(a){return a.nodeType===wysihtml5.ELEMENT_NODE}function c(a,b,c){var d=(a.className||"").match(c)||[];return b?d[d.length-1]===b:!!d.length}function d(a,b,c){var d=(a.getAttribute("style")||"").match(c)||[];return b?d[d.length-1]===b:!!d.length}return function(e,f,g,h){var i=f.cssStyle||f.styleRegExp,j=f.className||f.classRegExp;for(g=g||50,j&&!f.classRegExp&&(f.classRegExp=new RegExp(f.className));g--&&e&&"BODY"!==e.nodeName&&(!h||e!==h);){if(!(!b(e)||f.nodeName&&!a(e.nodeName,f.nodeName)||i&&!d(e,f.cssStyle,f.styleRegExp)||j&&!c(e,f.className,f.classRegExp)))return e;e=e.parentNode}return null}}(),wysihtml5.dom.getStyle=function(){function a(a){return a.replace(c,function(a){return a.charAt(1).toUpperCase()})}var b={"float":"styleFloat"in document.createElement("div").style?"styleFloat":"cssFloat"},c=/\-[a-z]/g;return function(c){return{from:function(d){if(d.nodeType===wysihtml5.ELEMENT_NODE){var e=d.ownerDocument,f=b[c]||a(c),g=d.style,h=d.currentStyle,i=g[f];if(i)return i;if(h)try{return h[f]}catch(j){}var k,l,m=e.defaultView||e.parentWindow,n=("height"===c||"width"===c)&&"TEXTAREA"===d.nodeName;return m.getComputedStyle?(n&&(k=g.overflow,g.overflow="hidden"),l=m.getComputedStyle(d,null).getPropertyValue(c),n&&(g.overflow=k||""),l):void 0}}}}}(),wysihtml5.dom.getTextNodes=function(a,b){var c=[];for(a=a.firstChild;a;a=a.nextSibling)3==a.nodeType?b&&/^\s*$/.test(a.innerText||a.textContent)||c.push(a):c=c.concat(wysihtml5.dom.getTextNodes(a,b));return c},wysihtml5.dom.hasElementWithTagName=function(){function a(a){return a._wysihtml5_identifier||(a._wysihtml5_identifier=c++)}var b={},c=1;return function(c,d){var e=a(c)+":"+d,f=b[e];return f||(f=b[e]=c.getElementsByTagName(d)),f.length>0}}(),function(a){function b(a){return a._wysihtml5_identifier||(a._wysihtml5_identifier=d++)}var c={},d=1;a.dom.hasElementWithClassName=function(d,e){if(!a.browser.supportsNativeGetElementsByClassName())return!!d.querySelector("."+e);var f=b(d)+":"+e,g=c[f];return g||(g=c[f]=d.getElementsByClassName(e)),g.length>0}}(wysihtml5),wysihtml5.dom.insert=function(a){return{after:function(b){b.parentNode.insertBefore(a,b.nextSibling)},before:function(b){b.parentNode.insertBefore(a,b)},into:function(b){b.appendChild(a)}}},wysihtml5.dom.insertCSS=function(a){return a=a.join("\n"),{into:function(b){var c=b.createElement("style");c.type="text/css",c.styleSheet?c.styleSheet.cssText=a:c.appendChild(b.createTextNode(a));var d=b.querySelector("head link");if(d)return void d.parentNode.insertBefore(c,d);var e=b.querySelector("head");e&&e.appendChild(c)}}},function(a){a.dom.lineBreaks=function(b){function c(a){return"BR"===a.nodeName}function d(b){return c(b)?!0:"block"===a.dom.getStyle("display").from(b)?!0:!1}return{add:function(){var c=b.ownerDocument,e=a.dom.domNode(b).next({ignoreBlankTexts:!0}),f=a.dom.domNode(b).prev({ignoreBlankTexts:!0});e&&!d(e)&&a.dom.insert(c.createElement("br")).after(b),f&&!d(f)&&a.dom.insert(c.createElement("br")).before(b)},remove:function(){var d=a.dom.domNode(b).next({ignoreBlankTexts:!0}),e=a.dom.domNode(b).prev({ignoreBlankTexts:!0});d&&c(d)&&d.parentNode.removeChild(d),e&&c(e)&&e.parentNode.removeChild(e)}}}}(wysihtml5),wysihtml5.dom.observe=function(a,b,c){b="string"==typeof b?[b]:b;for(var d,e,f=0,g=b.length;g>f;f++)e=b[f],a.addEventListener?a.addEventListener(e,c,!1):(d=function(b){"target"in b||(b.target=b.srcElement),b.preventDefault=b.preventDefault||function(){this.returnValue=!1},b.stopPropagation=b.stopPropagation||function(){this.cancelBubble=!0},c.call(a,b)},a.attachEvent("on"+e,d));return{stop:function(){for(var e,f=0,g=b.length;g>f;f++)e=b[f],a.removeEventListener?a.removeEventListener(e,c,!1):a.detachEvent("on"+e,d)}}},wysihtml5.dom.parse=function(a,b){function c(a,b){wysihtml5.lang.object(t).merge(s).merge(b.rules).get();var c,f,g,h=b.context||a.ownerDocument||document,i=h.createDocumentFragment(),j="string"==typeof a,k=!1;for(b.clearInternals===!0&&(k=!0),c=j?wysihtml5.dom.getAsDom(a,h):a,t.selectors&&e(c,t.selectors);c.firstChild;)g=c.firstChild,f=d(g,b.cleanUp,k,b.uneditableClass),f&&i.appendChild(f),g!==f&&c.removeChild(g);if(b.unjoinNbsps)for(var l=wysihtml5.dom.getTextNodes(i),m=l.length;m--;)l[m].nodeValue=l[m].nodeValue.replace(/([\S\u00A0])\u00A0/gi,"$1 ");return c.innerHTML="",c.appendChild(i),j?wysihtml5.quirks.getCorrectInnerHTML(c):c}function d(a,b,c,e){var f,g,h,i,j=a.nodeType,k=a.childNodes,l=k.length,m=p[j],n=0;if(e&&1===j&&wysihtml5.dom.hasClass(a,e))return a;if(g=m&&m(a,c),!g){if(g===!1){for(f=a.ownerDocument.createDocumentFragment(),n=l;n--;)k[n]&&(h=d(k[n],b,c,e),h&&(k[n]===h&&n--,f.insertBefore(h,f.firstChild)));return i=wysihtml5.dom.getStyle("display").from(a),""===i&&(i=wysihtml5.lang.array(u).contains(a.tagName)?"block":""),wysihtml5.lang.array(["block","flex","table"]).contains(i)&&f.appendChild(a.ownerDocument.createElement("br")),wysihtml5.lang.array(["div","pre","p","table","td","th","ul","ol","li","dd","dl","footer","header","section","h1","h2","h3","h4","h5","h6"]).contains(a.nodeName.toLowerCase())&&a.parentNode.lastChild!==a&&(a.nextSibling&&3===a.nextSibling.nodeType&&/^\s/.test(a.nextSibling.nodeValue)||f.appendChild(a.ownerDocument.createTextNode(" "))),f.normalize&&f.normalize(),f}return null}for(n=0;l>n;n++)k[n]&&(h=d(k[n],b,c,e),h&&(k[n]===h&&n--,g.appendChild(h)));if(b&&g.nodeName.toLowerCase()===q&&(!g.childNodes.length||/^\s*$/gi.test(g.innerHTML)&&(c||"_wysihtml5-temp-placeholder"!==a.className&&"rangySelectionBoundary"!==a.className)||!g.attributes.length)){for(f=g.ownerDocument.createDocumentFragment();g.firstChild;)f.appendChild(g.firstChild);return f.normalize&&f.normalize(),f}return g.normalize&&g.normalize(),g}function e(a,b){var c,d,e;for(c in b)if(b.hasOwnProperty(c)){wysihtml5.lang.object(b[c]).isFunction()?d=b[c]:"string"==typeof b[c]&&z[b[c]]&&(d=z[b[c]]),e=a.querySelectorAll(c);for(var f=e.length;f--;)d(e[f])}}function f(a,b){var c,d,e,f=t.tags,h=a.nodeName.toLowerCase(),j=a.scopeName;if(a._wysihtml5)return null;if(a._wysihtml5=1,"wysihtml5-temp"===a.className)return null;if(j&&"HTML"!=j&&(h=j+":"+h),"outerHTML"in a&&(wysihtml5.browser.autoClosesUnclosedTags()||"P"!==a.nodeName||"</p>"===a.outerHTML.slice(-4).toLowerCase()||(h="div")),h in f){if(c=f[h],!c||c.remove)return null;if(c.unwrap)return!1;c="string"==typeof c?{rename_tag:c}:c}else{if(!a.firstChild)return null;c={rename_tag:q}}if(c.one_of_type&&!g(a,t,c.one_of_type,b)){if(!c.remove_action)return null;if("unwrap"===c.remove_action)return!1;if("rename"!==c.remove_action)return null;e=c.remove_action_rename_to||q}return d=a.ownerDocument.createElement(e||c.rename_tag||h),m(a,d,c,b),i(a,d,c),a=null,d.normalize&&d.normalize(),d}function g(a,b,c,d){var e,f;if("SPAN"===a.nodeName&&!d&&("_wysihtml5-temp-placeholder"===a.className||"rangySelectionBoundary"===a.className))return!0;for(f in c)if(c.hasOwnProperty(f)&&b.type_definitions&&b.type_definitions[f]&&(e=b.type_definitions[f],h(a,e)))return!0;return!1}function h(a,b){var c,d,e,f,g,h=a.getAttribute("class"),i=a.getAttribute("style");if(b.methods)for(var j in b.methods)if(b.methods.hasOwnProperty(j)&&y[j]&&y[j](a))return!0;if(h&&b.classes){h=h.replace(/^\s+/g,"").replace(/\s+$/g,"").split(r),c=h.length;for(var k=0;c>k;k++)if(b.classes[h[k]])return!0}if(i&&b.styles){i=i.split(";");for(d in b.styles)if(b.styles.hasOwnProperty(d))for(var l=i.length;l--;)if(g=i[l].split(":"),g[0].replace(/\s/g,"").toLowerCase()===d&&(b.styles[d]===!0||1===b.styles[d]||wysihtml5.lang.array(b.styles[d]).contains(g[1].replace(/\s/g,"").toLowerCase())))return!0}if(b.attrs)for(e in b.attrs)if(b.attrs.hasOwnProperty(e)&&(f=wysihtml5.dom.getAttribute(a,e),"string"==typeof f&&f.search(b.attrs[e])>-1))return!0;return!1}function i(a,b,c){var d,e;if(c&&c.keep_styles)for(d in c.keep_styles)if(c.keep_styles.hasOwnProperty(d)){if(e="float"===d?a.style.styleFloat||a.style.cssFloat:a.style[d],c.keep_styles[d]instanceof RegExp&&!c.keep_styles[d].test(e))continue;"float"===d?b.style[a.style.styleFloat?"styleFloat":"cssFloat"]=e:a.style[d]&&(b.style[d]=e)}}function j(a,b){var c=[];for(var d in b)b.hasOwnProperty(d)&&0===d.indexOf(a)&&c.push(d);return c}function k(a,b,c,d){var e,f=v[c];return f&&(b||"alt"===a&&"IMG"==d)&&(e=f(b),"string"==typeof e)?e:!1}function l(a,b){var c,d,e,f=wysihtml5.lang.object(t.attributes||{}).clone(),g=wysihtml5.lang.object(f).merge(wysihtml5.lang.object(b||{}).clone()).get(),h={},i=wysihtml5.dom.getAttributes(a);for(c in g)if(/\*$/.test(c)){e=j(c.slice(0,-1),i);for(var l=0,m=e.length;m>l;l++)d=k(e[l],i[e[l]],g[c],a.nodeName),d!==!1&&(h[e[l]]=d)}else d=k(c,i[c],g[c],a.nodeName),d!==!1&&(h[c]=d);return h}function m(a,b,c,d){var e,f,g,h,i,j={},k=c.set_class,m=c.add_class,n=c.add_style,o=c.set_attributes,p=t.classes,q=0,s=[],u=[],v=[],y=[];if(o&&(j=wysihtml5.lang.object(o).clone()),j=wysihtml5.lang.object(j).merge(l(a,c.check_attributes)).get(),k&&s.push(k),m)for(h in m)i=x[m[h]],i&&(g=i(wysihtml5.dom.getAttribute(a,h)),"string"==typeof g&&s.push(g));if(n)for(h in n)i=w[n[h]],i&&(newStyle=i(wysihtml5.dom.getAttribute(a,h)),"string"==typeof newStyle&&u.push(newStyle));if("string"==typeof p&&"any"===p&&a.getAttribute("class"))if(t.classes_blacklist){for(y=a.getAttribute("class"),y&&(s=s.concat(y.split(r))),e=s.length;e>q;q++)f=s[q],t.classes_blacklist[f]||v.push(f);v.length&&(j["class"]=wysihtml5.lang.array(v).unique().join(" "))}else j["class"]=a.getAttribute("class");else{for(d||(p["_wysihtml5-temp-placeholder"]=1,p._rangySelectionBoundary=1,p["wysiwyg-tmp-selected-cell"]=1),y=a.getAttribute("class"),y&&(s=s.concat(y.split(r))),e=s.length;e>q;q++)f=s[q],p[f]&&v.push(f);v.length&&(j["class"]=wysihtml5.lang.array(v).unique().join(" "))}j["class"]&&d&&(j["class"]=j["class"].replace("wysiwyg-tmp-selected-cell",""),/^\s*$/g.test(j["class"])&&delete j["class"]),u.length&&(j.style=wysihtml5.lang.array(u).unique().join(" "));for(h in j)try{b.setAttribute(h,j[h])}catch(z){}j.src&&("undefined"!=typeof j.width&&b.setAttribute("width",j.width),"undefined"!=typeof j.height&&b.setAttribute("height",j.height))}function n(a){var b=a.nextSibling;if(!b||b.nodeType!==wysihtml5.TEXT_NODE){var c=a.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP,"");return a.ownerDocument.createTextNode(c)}b.data=a.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP,"")+b.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP,"")}function o(a){return t.comments?a.ownerDocument.createComment(a.nodeValue):void 0}var p={1:f,3:n,8:o},q="span",r=/\s+/,s={tags:{},classes:{}},t={},u=["ADDRESS","BLOCKQUOTE","CENTER","DIR","DIV","DL","FIELDSET","FORM","H1","H2","H3","H4","H5","H6","ISINDEX","MENU","NOFRAMES","NOSCRIPT","OL","P","PRE","TABLE","UL"],v={url:function(){var a=/^https?:\/\//i;return function(b){return b&&b.match(a)?b.replace(a,function(a){return a.toLowerCase()}):null}}(),src:function(){var a=/^(\/|https?:\/\/)/i;return function(b){return b&&b.match(a)?b.replace(a,function(a){return a.toLowerCase()}):null}}(),href:function(){var a=/^(#|\/|https?:\/\/|mailto:)/i;return function(b){return b&&b.match(a)?b.replace(a,function(a){return a.toLowerCase()}):null}}(),alt:function(){var a=/[^ a-z0-9_\-]/gi;return function(b){return b?b.replace(a,""):""}}(),numbers:function(){var a=/\D/g;return function(b){return b=(b||"").replace(a,""),b||null}}(),any:function(){return function(a){return a}}()},w={align_text:function(){var a={left:"text-align: left;",right:"text-align: right;",center:"text-align: center;"};return function(b){return a[String(b).toLowerCase()]}}()},x={align_img:function(){var a={left:"wysiwyg-float-left",right:"wysiwyg-float-right"};return function(b){return a[String(b).toLowerCase()]}}(),align_text:function(){var a={left:"wysiwyg-text-align-left",right:"wysiwyg-text-align-right",center:"wysiwyg-text-align-center",justify:"wysiwyg-text-align-justify"};return function(b){return a[String(b).toLowerCase()]}}(),clear_br:function(){var a={left:"wysiwyg-clear-left",right:"wysiwyg-clear-right",both:"wysiwyg-clear-both",all:"wysiwyg-clear-both"};return function(b){return a[String(b).toLowerCase()]}}(),size_font:function(){var a={1:"wysiwyg-font-size-xx-small",2:"wysiwyg-font-size-small",3:"wysiwyg-font-size-medium",4:"wysiwyg-font-size-large",5:"wysiwyg-font-size-x-large",6:"wysiwyg-font-size-xx-large",7:"wysiwyg-font-size-xx-large","-":"wysiwyg-font-size-smaller","+":"wysiwyg-font-size-larger"};return function(b){return a[String(b).charAt(0)]}}()},y={has_visible_contet:function(){var a,b=["img","video","picture","br","script","noscript","style","table","iframe","object","embed","audio","svg","input","button","select","textarea","canvas"];return function(c){if(a=(c.innerText||c.textContent).replace(/\s/g,""),a&&a.length>0)return!0;for(var d=b.length;d--;)if(c.querySelector(b[d]))return!0;return c.offsetWidth&&c.offsetWidth>0&&c.offsetHeight&&c.offsetHeight>0?!0:!1}}()},z={unwrap:function(a){wysihtml5.dom.unwrap(a)},remove:function(a){a.parentNode.removeChild(a)}};return c(a,b)},wysihtml5.dom.removeEmptyTextNodes=function(a){for(var b,c=wysihtml5.lang.array(a.childNodes).get(),d=c.length,e=0;d>e;e++)b=c[e],b.nodeType===wysihtml5.TEXT_NODE&&""===b.data&&b.parentNode.removeChild(b)},wysihtml5.dom.renameElement=function(a,b){for(var c,d=a.ownerDocument.createElement(b);c=a.firstChild;)d.appendChild(c);return wysihtml5.dom.copyAttributes(["align","className"]).from(a).to(d),a.parentNode.replaceChild(d,a),d},wysihtml5.dom.replaceWithChildNodes=function(a){if(a.parentNode){if(!a.firstChild)return void a.parentNode.removeChild(a);for(var b=a.ownerDocument.createDocumentFragment();a.firstChild;)b.appendChild(a.firstChild);a.parentNode.replaceChild(b,a),a=b=null}},function(a){function b(b){return"block"===a.getStyle("display").from(b)}function c(a){return"BR"===a.nodeName}function d(a){var b=a.ownerDocument.createElement("br");a.appendChild(b)}function e(a,e){if(a.nodeName.match(/^(MENU|UL|OL)$/)){var f,g,h,i,j,k,l=a.ownerDocument,m=l.createDocumentFragment(),n=wysihtml5.dom.domNode(a).prev({ignoreBlankTexts:!0});if(e)for(!n||b(n)||c(n)||d(m);k=a.firstElementChild||a.firstChild;){for(g=k.lastChild;f=k.firstChild;)h=f===g,i=h&&!b(f)&&!c(f),m.appendChild(f),i&&d(m);k.parentNode.removeChild(k)}else for(;k=a.firstElementChild||a.firstChild;){if(k.querySelector&&k.querySelector("div, p, ul, ol, menu, blockquote, h1, h2, h3, h4, h5, h6"))for(;f=k.firstChild;)m.appendChild(f);else{for(j=l.createElement("p");f=k.firstChild;)j.appendChild(f);m.appendChild(j)}k.parentNode.removeChild(k)}a.parentNode.replaceChild(m,a)}}a.resolveList=e}(wysihtml5.dom),function(a){var b=document,c=["parent","top","opener","frameElement","frames","localStorage","globalStorage","sessionStorage","indexedDB"],d=["open","close","openDialog","showModalDialog","alert","confirm","prompt","openDatabase","postMessage","XMLHttpRequest","XDomainRequest"],e=["referrer","write","open","close"];a.dom.Sandbox=Base.extend({constructor:function(b,c){this.callback=b||a.EMPTY_FUNCTION,this.config=a.lang.object({}).merge(c).get(),this.editableArea=this._createIframe()},insertInto:function(a){"string"==typeof a&&(a=b.getElementById(a)),a.appendChild(this.editableArea)},getIframe:function(){return this.editableArea},getWindow:function(){this._readyError()},getDocument:function(){this._readyError()},destroy:function(){var a=this.getIframe();a.parentNode.removeChild(a)},_readyError:function(){throw new Error("wysihtml5.Sandbox: Sandbox iframe isn't loaded yet")},_createIframe:function(){var c=this,d=b.createElement("iframe");return d.className="wysihtml5-sandbox",a.dom.setAttributes({security:"restricted",allowtransparency:"true",frameborder:0,width:0,height:0,marginwidth:0,marginheight:0}).on(d),a.browser.throwsMixedContentWarningWhenIframeSrcIsEmpty()&&(d.src="javascript:'<html></html>'"),d.onload=function(){d.onreadystatechange=d.onload=null,c._onLoadIframe(d)},d.onreadystatechange=function(){/loaded|complete/.test(d.readyState)&&(d.onreadystatechange=d.onload=null,c._onLoadIframe(d))},d},_onLoadIframe:function(f){if(a.dom.contains(b.documentElement,f)){var g=this,h=f.contentWindow,i=f.contentWindow.document,j=b.characterSet||b.charset||"utf-8",k=this._getHtml({charset:j,stylesheets:this.config.stylesheets});if(i.open("text/html","replace"),i.write(k),i.close(),this.getWindow=function(){return f.contentWindow},this.getDocument=function(){return f.contentWindow.document},h.onerror=function(a,b,c){throw new Error("wysihtml5.Sandbox: "+a,b,c)},!a.browser.supportsSandboxedIframes()){var l,m;for(l=0,m=c.length;m>l;l++)this._unset(h,c[l]);for(l=0,m=d.length;m>l;l++)this._unset(h,d[l],a.EMPTY_FUNCTION);for(l=0,m=e.length;m>l;l++)this._unset(i,e[l]);this._unset(i,"cookie","",!0)}this.loaded=!0,setTimeout(function(){g.callback(g)},0)}},_getHtml:function(b){var c,d=b.stylesheets,e="",f=0;if(d="string"==typeof d?[d]:d)for(c=d.length;c>f;f++)e+='<link rel="stylesheet" href="'+d[f]+'">';return b.stylesheets=e,a.lang.string('<!DOCTYPE html><html><head><meta charset="#{charset}">#{stylesheets}</head><body></body></html>').interpolate(b)},_unset:function(b,c,d,e){try{b[c]=d}catch(f){}try{b.__defineGetter__(c,function(){return d})}catch(f){}if(e)try{b.__defineSetter__(c,function(){})}catch(f){}if(!a.browser.crashesWhenDefineProperty(c))try{var g={get:function(){return d}};e&&(g.set=function(){}),Object.defineProperty(b,c,g)}catch(f){}}})}(wysihtml5),function(a){var b=document;a.dom.ContentEditableArea=Base.extend({getContentEditable:function(){return this.element},getWindow:function(){return this.element.ownerDocument.defaultView},getDocument:function(){return this.element.ownerDocument},constructor:function(b,c,d){this.callback=b||a.EMPTY_FUNCTION,this.config=a.lang.object({}).merge(c).get(),this.element=d?this._bindElement(d):this._createElement()},_createElement:function(){var a=b.createElement("div");return a.className="wysihtml5-sandbox",this._loadElement(a),a},_bindElement:function(a){return a.className=a.className&&""!=a.className?a.className+" wysihtml5-sandbox":"wysihtml5-sandbox",this._loadElement(a,!0),a},_loadElement:function(a,b){var c=this;if(!b){var d=this._getHtml();a.innerHTML=d}this.getWindow=function(){return a.ownerDocument.defaultView},this.getDocument=function(){return a.ownerDocument},this.loaded=!0,setTimeout(function(){c.callback(c)},0)},_getHtml:function(){return""}})}(wysihtml5),function(){var a={className:"class"};wysihtml5.dom.setAttributes=function(b){return{on:function(c){for(var d in b)c.setAttribute(a[d]||d,b[d])}}}}(),wysihtml5.dom.setStyles=function(a){return{on:function(b){var c=b.style;if("string"==typeof a)return void(c.cssText+=";"+a);for(var d in a)"float"===d?(c.cssFloat=a[d],c.styleFloat=a[d]):c[d]=a[d]}}},function(a){a.simulatePlaceholder=function(b,c,d){var e="placeholder",f=function(){var b=c.element.offsetWidth>0&&c.element.offsetHeight>0;c.hasPlaceholderSet()&&(c.clear(),c.element.focus(),b&&setTimeout(function(){var a=c.selection.getSelection();a.focusNode&&a.anchorNode||c.selection.selectNode(c.element.firstChild||c.element)},0)),c.placeholderSet=!1,a.removeClass(c.element,e)},g=function(){c.isEmpty()&&(c.placeholderSet=!0,c.setValue(d),a.addClass(c.element,e))};b.on("set_placeholder",g).on("unset_placeholder",f).on("focus:composer",f).on("paste:composer",f).on("blur:composer",g),g()}}(wysihtml5.dom),function(a){var b=document.documentElement;"textContent"in b?(a.setTextContent=function(a,b){a.textContent=b},a.getTextContent=function(a){return a.textContent}):"innerText"in b?(a.setTextContent=function(a,b){a.innerText=b},a.getTextContent=function(a){return a.innerText}):(a.setTextContent=function(a,b){a.nodeValue=b},a.getTextContent=function(a){return a.nodeValue})}(wysihtml5.dom),wysihtml5.dom.getAttribute=function(a,b){var c=!wysihtml5.browser.supportsGetAttributeCorrectly();b=b.toLowerCase();var d=a.nodeName;if("IMG"==d&&"src"==b&&wysihtml5.dom.isLoadedImage(a)===!0)return a.src;if(c&&"outerHTML"in a){var e=a.outerHTML.toLowerCase(),f=-1!=e.indexOf(" "+b+"=");return f?a.getAttribute(b):null}return a.getAttribute(b)},wysihtml5.dom.getAttributes=function(a){var b,c=!wysihtml5.browser.supportsGetAttributeCorrectly(),d=a.nodeName,e=[];for(b in a.attributes)(a.attributes.hasOwnProperty&&a.attributes.hasOwnProperty(b)||!a.attributes.hasOwnProperty&&Object.prototype.hasOwnProperty.call(a.attributes,b))&&a.attributes[b].specified&&("IMG"==d&&"src"==a.attributes[b].name.toLowerCase()&&wysihtml5.dom.isLoadedImage(a)===!0?e.src=a.src:wysihtml5.lang.array(["rowspan","colspan"]).contains(a.attributes[b].name.toLowerCase())&&c?1!==a.attributes[b].value&&(e[a.attributes[b].name]=a.attributes[b].value):e[a.attributes[b].name]=a.attributes[b].value);return e},wysihtml5.dom.isLoadedImage=function(a){try{return a.complete&&!a.mozMatchesSelector(":-moz-broken")}catch(b){if(a.complete&&"complete"===a.readyState)return!0}},function(a){function b(a,b){for(var c,d=[],e=0,f=a.length;f>e;e++)if(c=a[e].querySelectorAll(b))for(var g=c.length;g--;d.unshift(c[g]));return d}function d(a){a.parentNode.removeChild(a)}function e(a,b){a.parentNode.insertBefore(b,a.nextSibling)}function f(a,b){for(var c=a.nextSibling;1!=c.nodeType;)if(c=c.nextSibling,!b||b==c.tagName.toLowerCase())return c;return null}var g=a.dom,h=function(a){this.el=a,this.isColspan=!1,this.isRowspan=!1,this.firstCol=!0,this.lastCol=!0,this.firstRow=!0,this.lastRow=!0,this.isReal=!0,this.spanCollection=[],this.modified=!1},i=function(a,b){a?(this.cell=a,this.table=g.getParentElement(a,{nodeName:["TABLE"]})):b&&(this.table=b,this.cell=this.table.querySelectorAll("th, td")[0])};i.prototype={addSpannedCellToMap:function(a,b,c,d,e,f){for(var g=[],i=c+(f?parseInt(f,10)-1:0),j=d+(e?parseInt(e,10)-1:0),k=c;i>=k;k++){"undefined"==typeof b[k]&&(b[k]=[]);for(var l=d;j>=l;l++)b[k][l]=new h(a),b[k][l].isColspan=e&&parseInt(e,10)>1,b[k][l].isRowspan=f&&parseInt(f,10)>1,b[k][l].firstCol=l==d,b[k][l].lastCol=l==j,b[k][l].firstRow=k==c,b[k][l].lastRow=k==i,b[k][l].isReal=l==d&&k==c,b[k][l].spanCollection=g,g.push(b[k][l])}},setCellAsModified:function(a){if(a.modified=!0,a.spanCollection.length>0)for(var b=0,c=a.spanCollection.length;c>b;b++)a.spanCollection[b].modified=!0},setTableMap:function(){var a,b,c,d,e,f,i,j,k=[],l=this.getTableRows();for(a=0;a<l.length;a++)for(b=l[a],c=this.getRowCells(b),f=0,"undefined"==typeof k[a]&&(k[a]=[]),d=0;d<c.length;d++){for(e=c[d];"undefined"!=typeof k[a][f];)f++;i=g.getAttribute(e,"colspan"),j=g.getAttribute(e,"rowspan"),i||j?(this.addSpannedCellToMap(e,k,a,f,i,j),f+=i?parseInt(i,10):1):(k[a][f]=new h(e),f++)}return this.map=k,k},getRowCells:function(c){var d=this.table.querySelectorAll("table"),e=d?b(d,"th, td"):[],f=c.querySelectorAll("th, td"),g=e.length>0?a.lang.array(f).without(e):f;return g},getTableRows:function(){var c=this.table.querySelectorAll("table"),d=c?b(c,"tr"):[],e=this.table.querySelectorAll("tr"),f=d.length>0?a.lang.array(e).without(d):e;return f},getMapIndex:function(a){for(var b=this.map.length,c=this.map&&this.map[0]?this.map[0].length:0,d=0;b>d;d++)for(var e=0;c>e;e++)if(this.map[d][e].el===a)return{row:d,col:e};return!1},getElementAtIndex:function(a){return this.setTableMap(),this.map[a.row]&&this.map[a.row][a.col]&&this.map[a.row][a.col].el?this.map[a.row][a.col].el:null},getMapElsTo:function(a){var b=[];if(this.setTableMap(),this.idx_start=this.getMapIndex(this.cell),this.idx_end=this.getMapIndex(a),this.idx_start.row>this.idx_end.row||this.idx_start.row==this.idx_end.row&&this.idx_start.col>this.idx_end.col){var c=this.idx_start;this.idx_start=this.idx_end,this.idx_end=c}if(this.idx_start.col>this.idx_end.col){var d=this.idx_start.col;this.idx_start.col=this.idx_end.col,this.idx_end.col=d}if(null!=this.idx_start&&null!=this.idx_end)for(var e=this.idx_start.row,f=this.idx_end.row;f>=e;e++)for(var g=this.idx_start.col,h=this.idx_end.col;h>=g;g++)b.push(this.map[e][g].el);return b},orderSelectionEnds:function(a){if(this.setTableMap(),this.idx_start=this.getMapIndex(this.cell),this.idx_end=this.getMapIndex(a),this.idx_start.row>this.idx_end.row||this.idx_start.row==this.idx_end.row&&this.idx_start.col>this.idx_end.col){var b=this.idx_start;this.idx_start=this.idx_end,this.idx_end=b}if(this.idx_start.col>this.idx_end.col){var c=this.idx_start.col;this.idx_start.col=this.idx_end.col,this.idx_end.col=c}return{start:this.map[this.idx_start.row][this.idx_start.col].el,end:this.map[this.idx_end.row][this.idx_end.col].el}},createCells:function(a,b,c){for(var d,e=this.table.ownerDocument,f=e.createDocumentFragment(),g=0;b>g;g++){if(d=e.createElement(a),c)for(var h in c)c.hasOwnProperty(h)&&d.setAttribute(h,c[h]);d.appendChild(document.createTextNode(" ")),f.appendChild(d)}return f},correctColIndexForUnreals:function(a,b){for(var c=this.map[b],d=-1,e=0;a>e;e++)c[e].isReal&&d++;return d},getLastNewCellOnRow:function(a,b){for(var c,d,e=this.getRowCells(a),f=0,g=e.length;g>f;f++)if(c=e[f],d=this.getMapIndex(c),d===!1||"undefined"!=typeof b&&d.row!=b)return c;return null},removeEmptyTable:function(){var a=this.table.querySelectorAll("td, th");return a&&0!=a.length?!1:(d(this.table),!0)},splitRowToCells:function(a){if(a.isColspan){var b=parseInt(g.getAttribute(a.el,"colspan")||1,10),c=a.el.tagName.toLowerCase();if(b>1){var d=this.createCells(c,b-1);e(a.el,d)}a.el.removeAttribute("colspan")}},getRealRowEl:function(a,b){var c=null,d=null;b=b||this.idx;for(var e=0,f=this.map[b.row].length;f>e;e++)if(d=this.map[b.row][e],d.isReal&&(c=g.getParentElement(d.el,{nodeName:["TR"]})))return c;return null===c&&a&&(c=g.getParentElement(this.map[b.row][b.col].el,{nodeName:["TR"]})||null),c},injectRowAt:function(a,b,c,d,f){var h=this.getRealRowEl(!1,{row:a,col:b}),i=this.createCells(d,c);if(h){var j=this.correctColIndexForUnreals(b,a);j>=0?e(this.getRowCells(h)[j],i):h.insertBefore(i,h.firstChild)}else{var k=this.table.ownerDocument.createElement("tr");k.appendChild(i),e(g.getParentElement(f.el,{nodeName:["TR"]}),k)}},canMerge:function(a){if(this.to=a,this.setTableMap(),this.idx_start=this.getMapIndex(this.cell),this.idx_end=this.getMapIndex(this.to),this.idx_start.row>this.idx_end.row||this.idx_start.row==this.idx_end.row&&this.idx_start.col>this.idx_end.col){var b=this.idx_start;this.idx_start=this.idx_end,this.idx_end=b}if(this.idx_start.col>this.idx_end.col){var c=this.idx_start.col;this.idx_start.col=this.idx_end.col,this.idx_end.col=c}for(var d=this.idx_start.row,e=this.idx_end.row;e>=d;d++)for(var f=this.idx_start.col,g=this.idx_end.col;g>=f;f++)if(this.map[d][f].isColspan||this.map[d][f].isRowspan)return!1;return!0},decreaseCellSpan:function(a,b){var c=parseInt(g.getAttribute(a.el,b),10)-1;c>=1?a.el.setAttribute(b,c):(a.el.removeAttribute(b),"colspan"==b&&(a.isColspan=!1),"rowspan"==b&&(a.isRowspan=!1),a.firstCol=!0,a.lastCol=!0,a.firstRow=!0,a.lastRow=!0,a.isReal=!0)},removeSurplusLines:function(){var a,b,c,e,f,h,i;if(this.setTableMap(),this.map){for(c=0,e=this.map.length;e>c;c++){for(a=this.map[c],i=!0,f=0,h=a.length;h>f;f++)if(b=a[f],!(g.getAttribute(b.el,"rowspan")&&parseInt(g.getAttribute(b.el,"rowspan"),10)>1&&b.firstRow!==!0)){i=!1;break}if(i)for(f=0;h>f;f++)this.decreaseCellSpan(a[f],"rowspan")}var j=this.getTableRows();for(c=0,e=j.length;e>c;c++)a=j[c],0==a.childNodes.length&&/^\s*$/.test(a.textContent||a.innerText)&&d(a)}},fillMissingCells:function(){var a=0,b=0,c=null;if(this.setTableMap(),this.map){a=this.map.length;for(var d=0;a>d;d++)this.map[d].length>b&&(b=this.map[d].length);for(var f=0;a>f;f++)for(var g=0;b>g;g++)this.map[f]&&!this.map[f][g]&&g>0&&(this.map[f][g]=new h(this.createCells("td",1)),c=this.map[f][g-1],c&&c.el&&c.el.parent&&e(this.map[f][g-1].el,this.map[f][g].el))}},rectify:function(){return this.removeEmptyTable()?!1:(this.removeSurplusLines(),this.fillMissingCells(),!0)},unmerge:function(){if(this.rectify()&&(this.setTableMap(),this.idx=this.getMapIndex(this.cell),this.idx)){var a=this.map[this.idx.row][this.idx.col],b=g.getAttribute(a.el,"colspan")?parseInt(g.getAttribute(a.el,"colspan"),10):1,c=a.el.tagName.toLowerCase();if(a.isRowspan){var d=parseInt(g.getAttribute(a.el,"rowspan"),10);if(d>1)for(var e=1,f=d-1;f>=e;e++)this.injectRowAt(this.idx.row+e,this.idx.col,b,c,a);a.el.removeAttribute("rowspan")}this.splitRowToCells(a)}},merge:function(a){if(this.rectify())if(this.canMerge(a)){for(var b=this.idx_end.row-this.idx_start.row+1,c=this.idx_end.col-this.idx_start.col+1,e=this.idx_start.row,f=this.idx_end.row;f>=e;e++)for(var g=this.idx_start.col,h=this.idx_end.col;h>=g;g++)e==this.idx_start.row&&g==this.idx_start.col?(b>1&&this.map[e][g].el.setAttribute("rowspan",b),c>1&&this.map[e][g].el.setAttribute("colspan",c)):(/^\s*<br\/?>\s*$/.test(this.map[e][g].el.innerHTML.toLowerCase())||(this.map[this.idx_start.row][this.idx_start.col].el.innerHTML+=" "+this.map[e][g].el.innerHTML),d(this.map[e][g].el));this.rectify()}else window.console&&console.log("Do not know how to merge allready merged cells.")},collapseCellToNextRow:function(a){var b=this.getMapIndex(a.el),c=b.row+1,d={row:c,col:b.col};if(c<this.map.length){var f=this.getRealRowEl(!1,d);if(null!==f){var h=this.correctColIndexForUnreals(d.col,d.row);if(h>=0)e(this.getRowCells(f)[h],a.el);else{var i=this.getLastNewCellOnRow(f,c);null!==i?e(i,a.el):f.insertBefore(a.el,f.firstChild)}parseInt(g.getAttribute(a.el,"rowspan"),10)>2?a.el.setAttribute("rowspan",parseInt(g.getAttribute(a.el,"rowspan"),10)-1):a.el.removeAttribute("rowspan")}}},removeRowCell:function(a){a.isReal?a.isRowspan?this.collapseCellToNextRow(a):d(a.el):parseInt(g.getAttribute(a.el,"rowspan"),10)>2?a.el.setAttribute("rowspan",parseInt(g.getAttribute(a.el,"rowspan"),10)-1):a.el.removeAttribute("rowspan")},getRowElementsByCell:function(){var a=[];if(this.setTableMap(),this.idx=this.getMapIndex(this.cell),this.idx!==!1)for(var b=this.map[this.idx.row],c=0,d=b.length;d>c;c++)b[c].isReal&&a.push(b[c].el);return a},getColumnElementsByCell:function(){var a=[];if(this.setTableMap(),this.idx=this.getMapIndex(this.cell),this.idx!==!1)for(var b=0,c=this.map.length;c>b;b++)this.map[b][this.idx.col]&&this.map[b][this.idx.col].isReal&&a.push(this.map[b][this.idx.col].el);return a},removeRow:function(){var a=g.getParentElement(this.cell,{nodeName:["TR"]});if(a){if(this.setTableMap(),this.idx=this.getMapIndex(this.cell),this.idx!==!1)for(var b=this.map[this.idx.row],c=0,e=b.length;e>c;c++)b[c].modified||(this.setCellAsModified(b[c]),this.removeRowCell(b[c]));d(a)}},removeColCell:function(a){a.isColspan?parseInt(g.getAttribute(a.el,"colspan"),10)>2?a.el.setAttribute("colspan",parseInt(g.getAttribute(a.el,"colspan"),10)-1):a.el.removeAttribute("colspan"):a.isReal&&d(a.el)
+},removeColumn:function(){if(this.setTableMap(),this.idx=this.getMapIndex(this.cell),this.idx!==!1)for(var a=0,b=this.map.length;b>a;a++)this.map[a][this.idx.col].modified||(this.setCellAsModified(this.map[a][this.idx.col]),this.removeColCell(this.map[a][this.idx.col]))},remove:function(a){if(this.rectify()){switch(a){case"row":this.removeRow();break;case"column":this.removeColumn()}this.rectify()}},addRow:function(a){var b=this.table.ownerDocument;if(this.setTableMap(),this.idx=this.getMapIndex(this.cell),"below"==a&&g.getAttribute(this.cell,"rowspan")&&(this.idx.row=this.idx.row+parseInt(g.getAttribute(this.cell,"rowspan"),10)-1),this.idx!==!1){for(var c=this.map[this.idx.row],d=b.createElement("tr"),f=0,h=c.length;h>f;f++)c[f].modified||(this.setCellAsModified(c[f]),this.addRowCell(c[f],d,a));switch(a){case"below":e(this.getRealRowEl(!0),d);break;case"above":var i=g.getParentElement(this.map[this.idx.row][this.idx.col].el,{nodeName:["TR"]});i&&i.parentNode.insertBefore(d,i)}}},addRowCell:function(a,b,d){var e=a.isColspan?{colspan:g.getAttribute(a.el,"colspan")}:null;a.isReal?"above"!=d&&a.isRowspan?a.el.setAttribute("rowspan",parseInt(g.getAttribute(a.el,"rowspan"),10)+1):b.appendChild(this.createCells("td",1,e)):"above"!=d&&a.isRowspan&&a.lastRow?b.appendChild(this.createCells("td",1,e)):c.isRowspan&&a.el.attr("rowspan",parseInt(g.getAttribute(a.el,"rowspan"),10)+1)},add:function(a){this.rectify()&&(("below"==a||"above"==a)&&this.addRow(a),("before"==a||"after"==a)&&this.addColumn(a))},addColCell:function(a,b,d){var f,h=a.el.tagName.toLowerCase();switch(d){case"before":f=!a.isColspan||a.firstCol;break;case"after":f=!a.isColspan||a.lastCol||a.isColspan&&c.el==this.cell}if(f){switch(d){case"before":a.el.parentNode.insertBefore(this.createCells(h,1),a.el);break;case"after":e(a.el,this.createCells(h,1))}a.isRowspan&&this.handleCellAddWithRowspan(a,b+1,d)}else a.el.setAttribute("colspan",parseInt(g.getAttribute(a.el,"colspan"),10)+1)},addColumn:function(a){var b,c;if(this.setTableMap(),this.idx=this.getMapIndex(this.cell),"after"==a&&g.getAttribute(this.cell,"colspan")&&(this.idx.col=this.idx.col+parseInt(g.getAttribute(this.cell,"colspan"),10)-1),this.idx!==!1)for(var d=0,e=this.map.length;e>d;d++)b=this.map[d],b[this.idx.col]&&(c=b[this.idx.col],c.modified||(this.setCellAsModified(c),this.addColCell(c,d,a)))},handleCellAddWithRowspan:function(a,b,c){for(var d,h,i,j=parseInt(g.getAttribute(this.cell,"rowspan"),10)-1,k=g.getParentElement(a.el,{nodeName:["TR"]}),l=a.el.tagName.toLowerCase(),m=this.table.ownerDocument,n=0;j>n;n++)if(d=this.correctColIndexForUnreals(this.idx.col,b+n),k=f(k,"tr"))if(d>0)switch(c){case"before":h=this.getRowCells(k),d>0&&this.map[b+n][this.idx.col].el!=h[d]&&d==h.length-1?e(h[d],this.createCells(l,1)):h[d].parentNode.insertBefore(this.createCells(l,1),h[d]);break;case"after":e(this.getRowCells(k)[d],this.createCells(l,1))}else k.insertBefore(this.createCells(l,1),k.firstChild);else i=m.createElement("tr"),i.appendChild(this.createCells(l,1)),this.table.appendChild(i)}},g.table={getCellsBetween:function(a,b){var c=new i(a);return c.getMapElsTo(b)},addCells:function(a,b){var c=new i(a);c.add(b)},removeCells:function(a,b){var c=new i(a);c.remove(b)},mergeCellsBetween:function(a,b){var c=new i(a);c.merge(b)},unmergeCell:function(a){var b=new i(a);b.unmerge()},orderSelectionEnds:function(a,b){var c=new i(a);return c.orderSelectionEnds(b)},indexOf:function(a){var b=new i(a);return b.setTableMap(),b.getMapIndex(a)},findCell:function(a,b){var c=new i(null,a);return c.getElementAtIndex(b)},findRowByCell:function(a){var b=new i(a);return b.getRowElementsByCell()},findColumnByCell:function(a){var b=new i(a);return b.getColumnElementsByCell()},canMerge:function(a,b){var c=new i(a);return c.canMerge(b)}}}(wysihtml5),wysihtml5.dom.query=function(a,b){var c,d=[];a.nodeType&&(a=[a]);for(var e=0,f=a.length;f>e;e++)if(c=a[e].querySelectorAll(b))for(var g=c.length;g--;d.unshift(c[g]));return d},wysihtml5.dom.compareDocumentPosition=function(){var a=document.documentElement;return a.compareDocumentPosition?function(a,b){return a.compareDocumentPosition(b)}:function(a,b){var c,d;if(c=9===a.nodeType?a:a.ownerDocument,d=9===b.nodeType?b:b.ownerDocument,a===b)return 0;if(a===b.ownerDocument)return 20;if(a.ownerDocument===b)return 10;if(c!==d)return 1;if(2===a.nodeType&&a.childNodes&&-1!==wysihtml5.lang.array(a.childNodes).indexOf(b))return 20;if(2===b.nodeType&&b.childNodes&&-1!==wysihtml5.lang.array(b.childNodes).indexOf(a))return 10;for(var e=a,f=[],g=null;e;){if(e==b)return 10;f.push(e),e=e.parentNode}for(e=b,g=null;e;){if(e==a)return 20;var h=wysihtml5.lang.array(f).indexOf(e);if(-1!==h){var i=f[h],j=wysihtml5.lang.array(i.childNodes).indexOf(f[h-1]),k=wysihtml5.lang.array(i.childNodes).indexOf(g);return j>k?2:4}g=e,e=e.parentNode}return 1}}(),wysihtml5.dom.unwrap=function(a){if(a.parentNode){for(;a.lastChild;)wysihtml5.dom.insert(a.lastChild).after(a);a.parentNode.removeChild(a)}},wysihtml5.dom.getPastedHtml=function(a){var b;return a.clipboardData&&(wysihtml5.lang.array(a.clipboardData.types).contains("text/html")?b=a.clipboardData.getData("text/html"):wysihtml5.lang.array(a.clipboardData.types).contains("text/plain")&&(b=wysihtml5.lang.string(a.clipboardData.getData("text/plain")).escapeHTML(!0,!0))),b},wysihtml5.dom.getPastedHtmlWithDiv=function(a,b){var c=a.selection.getBookmark(),d=a.element.ownerDocument,e=d.createElement("DIV");d.body.appendChild(e),e.style.width="1px",e.style.height="1px",e.style.overflow="hidden",e.setAttribute("contenteditable","true"),e.focus(),setTimeout(function(){a.selection.setBookmark(c),b(e.innerHTML),e.parentNode.removeChild(e)},0)},wysihtml5.quirks.cleanPastedHTML=function(){var a=function(a){var b=wysihtml5.lang.string(a).trim(),c=b.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&");return new RegExp("^((?!^"+c+"$).)*$","i")},b=function(b,c){var d,e,f=wysihtml5.lang.object(b).clone(!0);for(d in f.tags)if(f.tags.hasOwnProperty(d)&&f.tags[d].keep_styles)for(e in f.tags[d].keep_styles)f.tags[d].keep_styles.hasOwnProperty(e)&&c[e]&&(f.tags[d].keep_styles[e]=a(c[e]));return f},c=function(a,b){var c;if(!a)return null;for(var d=0,e=a.length;e>d;d++)if(a[d].condition||(c=a[d].set),a[d].condition&&a[d].condition.test(b))return a[d].set;return c};return function(a,d){var e,f={color:wysihtml5.dom.getStyle("color").from(d.referenceNode),fontSize:wysihtml5.dom.getStyle("font-size").from(d.referenceNode)},g=b(c(d.rules,a)||{},f);return e=wysihtml5.dom.parse(a,{rules:g,cleanUp:!0,context:d.referenceNode.ownerDocument,uneditableClass:d.uneditableClass,clearInternals:!0,unjoinNbsps:!0})}}(),wysihtml5.quirks.ensureProperClearing=function(){var a=function(){var a=this;setTimeout(function(){var b=a.innerHTML.toLowerCase();("<p> </p>"==b||"<p> </p><p> </p>"==b)&&(a.innerHTML="")},0)};return function(b){wysihtml5.dom.observe(b.element,["cut","keydown"],a)}}(),function(a){var b="%7E";a.quirks.getCorrectInnerHTML=function(c){var d=c.innerHTML;if(-1===d.indexOf(b))return d;var e,f,g,h,i=c.querySelectorAll("[href*='~'], [src*='~']");for(h=0,g=i.length;g>h;h++)e=i[h].href||i[h].src,f=a.lang.string(e).replace("~").by(b),d=a.lang.string(d).replace(f).by(e);return d}}(wysihtml5),function(a){var b="wysihtml5-quirks-redraw";a.quirks.redraw=function(c){a.dom.addClass(c,b),a.dom.removeClass(c,b);try{var d=c.ownerDocument;d.execCommand("italic",!1,null),d.execCommand("italic",!1,null)}catch(e){}}}(wysihtml5),wysihtml5.quirks.tableCellsSelection=function(a,b){function c(){return k.observe(a,"mousedown",function(a){var b=wysihtml5.dom.getParentElement(a.target,{nodeName:["TD","TH"]});b&&d(b)}),l}function d(c){l.start=c,l.end=c,l.cells=[c],l.table=k.getParentElement(l.start,{nodeName:["TABLE"]}),l.table&&(e(),k.addClass(c,m),n=k.observe(a,"mousemove",g),o=k.observe(a,"mouseup",h),b.fire("tableselectstart").fire("tableselectstart:composer"))}function e(){if(a){var b=a.querySelectorAll("."+m);if(b.length>0)for(var c=0;c<b.length;c++)k.removeClass(b[c],m)}}function f(a){for(var b=0;b<a.length;b++)k.addClass(a[b],m)}function g(a){var c,d=null,g=k.getParentElement(a.target,{nodeName:["TD","TH"]});g&&l.table&&l.start&&(d=k.getParentElement(g,{nodeName:["TABLE"]}),d&&d===l.table&&(e(),c=l.end,l.end=g,l.cells=k.table.getCellsBetween(l.start,g),l.cells.length>1&&b.composer.selection.deselect(),f(l.cells),l.end!==c&&b.fire("tableselectchange").fire("tableselectchange:composer")))}function h(){n.stop(),o.stop(),b.fire("tableselect").fire("tableselect:composer"),setTimeout(function(){i()},0)}function i(){var c=k.observe(a.ownerDocument,"click",function(a){c.stop(),k.getParentElement(a.target,{nodeName:["TABLE"]})!=l.table&&(e(),l.table=null,l.start=null,l.end=null,b.fire("tableunselect").fire("tableunselect:composer"))})}function j(a,c){l.start=a,l.end=c,l.table=k.getParentElement(l.start,{nodeName:["TABLE"]}),selectedCells=k.table.getCellsBetween(l.start,l.end),f(selectedCells),i(),b.fire("tableselect").fire("tableselect:composer")}var k=wysihtml5.dom,l={table:null,start:null,end:null,cells:null,select:j},m="wysiwyg-tmp-selected-cell",n=null,o=null;return c()},function(a){var b=/^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*([\d\.]+)\s*\)/i,c=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/i,d=/^#([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])/i,e=/^#([0-9a-f])([0-9a-f])([0-9a-f])/i,f=function(a){return new RegExp("(^|\\s|;)"+a+"\\s*:\\s*[^;$]+","gi")};a.quirks.styleParser={parseColor:function(g,h){var i,j,k=f(h),l=g.match(k),m=10;if(l){for(var n=l.length;n--;)l[n]=a.lang.string(l[n].split(":")[1]).trim();if(i=l[l.length-1],b.test(i))j=i.match(b);else if(c.test(i))j=i.match(c);else if(d.test(i))j=i.match(d),m=16;else if(e.test(i))return j=i.match(e),j.shift(),j.push(1),a.lang.array(j).map(function(a,b){return 3>b?16*parseInt(a,16)+parseInt(a,16):parseFloat(a)});if(j)return j.shift(),j[3]||j.push(1),a.lang.array(j).map(function(a,b){return 3>b?parseInt(a,m):parseFloat(a)})}return!1},unparseColor:function(a,b){if(b){if("hex"==b)return a[0].toString(16).toUpperCase()+a[1].toString(16).toUpperCase()+a[2].toString(16).toUpperCase();if("hash"==b)return"#"+a[0].toString(16).toUpperCase()+a[1].toString(16).toUpperCase()+a[2].toString(16).toUpperCase();if("rgb"==b)return"rgb("+a[0]+","+a[1]+","+a[2]+")";if("rgba"==b)return"rgba("+a[0]+","+a[1]+","+a[2]+","+a[3]+")";if("csv"==b)return a[0]+","+a[1]+","+a[2]+","+a[3]}return a[3]&&1!==a[3]?"rgba("+a[0]+","+a[1]+","+a[2]+","+a[3]+")":"rgb("+a[0]+","+a[1]+","+a[2]+")"},parseFontSize:function(b){var c=b.match(f("font-size"));return c?a.lang.string(c[c.length-1].split(":")[1]).trim():!1}}}(wysihtml5),function(a){function b(a){var b=0;if(a.parentNode)do b+=a.offsetTop||0,a=a.offsetParent;while(a);return b}function c(a,b){for(var c=0;b!==a;)if(c++,b=b.parentNode,!b)throw new Error("not a descendant of ancestor!");return c}function d(a){if(!a.canSurroundContents())for(var b=a.commonAncestorContainer,d=c(b,a.startContainer),e=c(b,a.endContainer);!a.canSurroundContents();)d>e?(a.setStartBefore(a.startContainer),d=c(b,a.startContainer)):(a.setEndAfter(a.endContainer),e=c(b,a.endContainer))}var e=a.dom;a.Selection=Base.extend({constructor:function(a,b,c){window.rangy.init(),this.editor=a,this.composer=a.composer,this.doc=this.composer.doc,this.contain=b,this.unselectableClass=c||!1},getBookmark:function(){var a=this.getRange();return a&&d(a),a&&a.cloneRange()},setBookmark:function(a){a&&this.setSelection(a)},setBefore:function(a){var b=rangy.createRange(this.doc);return b.setStartBefore(a),b.setEndBefore(a),this.setSelection(b)},creteTemporaryCaretSpaceAfter:function(b){var c=this.doc.createElement("span"),d=this.doc.createTextNode(a.INVISIBLE_SPACE),e=function(){var b;this.contain.removeEventListener("mouseup",e),this.contain.removeEventListener("keydown",g),this.contain.removeEventListener("touchstart",e),this.contain.removeEventListener("focus",e),this.contain.removeEventListener("blur",e),this.contain.removeEventListener("paste",f),this.contain.removeEventListener("drop",f),this.contain.removeEventListener("beforepaste",f),c&&c.parentNode&&(c.innerHTML=c.innerHTML.replace(a.INVISIBLE_SPACE_REG_EXP,""),/[^\s]+/.test(c.innerHTML)?(b=c.lastChild,a.dom.unwrap(c),this.setAfter(b)):c.parentNode.removeChild(c))}.bind(this),f=function(){c&&c.parentNode&&setTimeout(e,0)},g=function(a){8===a.which||91===a.which||17===a.which||86===a.which&&(a.ctrlKey||a.metaKey)||e()};return c.style.position="absolute",c.style.display="block",c.style.minWidth="1px",c.style.zIndex="99999",c.appendChild(d),b.parentNode.insertBefore(c,b.nextSibling),this.setBefore(d),this.contain.addEventListener("mouseup",e),this.contain.addEventListener("keydown",g),this.contain.addEventListener("touchstart",e),this.contain.addEventListener("focus",e),this.contain.addEventListener("blur",e),this.contain.addEventListener("paste",f),this.contain.addEventListener("drop",f),this.contain.addEventListener("beforepaste",f),c},setAfter:function(a){var b,c=rangy.createRange(this.doc),d=this.doc.documentElement.scrollTop||this.doc.body.scrollTop||this.doc.defaultView.pageYOffset,e=this.doc.documentElement.scrollLeft||this.doc.body.scrollLeft||this.doc.defaultView.pageXOffset;return c.setStartAfter(a),c.setEndAfter(a),this.composer.element.focus(),this.doc.defaultView.scrollTo(e,d),b=this.setSelection(c),b||this.creteTemporaryCaretSpaceAfter(a),b},selectNode:function(b,c){var d=rangy.createRange(this.doc),f=b.nodeType===a.ELEMENT_NODE,g="canHaveHTML"in b?b.canHaveHTML:"IMG"!==b.nodeName,h=f?b.innerHTML:b.data,i=""===h||h===a.INVISIBLE_SPACE,j=e.getStyle("display").from(b),k="block"===j||"list-item"===j;if(i&&f&&g&&!c)try{b.innerHTML=a.INVISIBLE_SPACE}catch(l){}g?d.selectNodeContents(b):d.selectNode(b),g&&i&&f?d.collapse(k):g&&i&&(d.setStartAfter(b),d.setEndAfter(b)),this.setSelection(d)},getSelectedNode:function(a){var b,c;return a&&this.doc.selection&&"Control"===this.doc.selection.type&&(c=this.doc.selection.createRange(),c&&c.length)?c.item(0):(b=this.getSelection(this.doc),b.focusNode===b.anchorNode?b.focusNode:(c=this.getRange(this.doc),c?c.commonAncestorContainer:this.doc.body))},fixSelBorders:function(){var a=this.getRange();d(a),this.setSelection(a)},getSelectedOwnNodes:function(){for(var a=this.getOwnRanges(),b=[],c=0,d=a.length;d>c;c++)b.push(a[c].commonAncestorContainer||this.doc.body);return b},findNodesInSelection:function(b){for(var c,d=this.getOwnRanges(),e=[],f=0,g=d.length;g>f;f++)c=d[f].getNodes([1],function(c){return a.lang.array(b).contains(c.nodeName)}),e=e.concat(c);return e},containsUneditable:function(){for(var a=this.getOwnUneditables(),b=this.getSelection(),c=0,d=a.length;d>c;c++)if(b.containsNode(a[c]))return!0;return!1},deleteContents:function(){var b,c,d,e,f=this.getRange();if(this.unselectableClass){(b=a.dom.getParentElement(f.startContainer,{className:this.unselectableClass},!1,this.contain))&&f.setStartBefore(b),(c=a.dom.getParentElement(f.endContainer,{className:this.unselectableClass},!1,this.contain))&&f.setEndAfter(c),d=f.getNodes([1],function(b){return a.dom.hasClass(b,this.unselectableClass)}.bind(this));for(var g=d.length;g--;)try{e=new CustomEvent("wysihtml5:uneditable:delete"),d[g].dispatchEvent(e)}catch(h){}}f.deleteContents(),this.setSelection(f)},getPreviousNode:function(b,c){var d;if(!b){var e=this.getSelection();b=e.anchorNode}if(b===this.contain)return!1;var f,g=b.previousSibling;return g===this.contain?!1:(g&&3!==g.nodeType&&1!==g.nodeType?g=this.getPreviousNode(g,c):g&&3===g.nodeType&&/^\s*$/.test(g.textContent)?g=this.getPreviousNode(g,c):c&&g&&1===g.nodeType?(d=a.dom.getStyle("display").from(g),a.lang.array(["BR","HR","IMG"]).contains(g.nodeName)||a.lang.array(["block","inline-block","flex","list-item","table"]).contains(d)||!/^[\s]*$/.test(g.innerHTML)||(g=this.getPreviousNode(g,c))):g||b===this.contain||(f=b.parentNode,f!==this.contain&&(g=this.getPreviousNode(f,c))),g!==this.contain?g:!1)},getSelectionParentsByTag:function(){for(var b,c=this.getSelectedOwnNodes(),d=[],e=0,f=c.length;f>e;e++)b=c[e].nodeName&&"LI"===c[e].nodeName?c[e]:a.dom.getParentElement(c[e],{nodeName:["LI"]},!1,this.contain),b&&d.push(b);return d.length?d:null},getRangeToNodeEnd:function(){if(this.isCollapsed()){var a=this.getRange(),b=a.startContainer,c=a.startOffset,d=rangy.createRange(this.doc);return d.selectNodeContents(b),d.setStart(b,c),d}},caretIsLastInSelection:function(){var a=(rangy.createRange(this.doc),this.getSelection(),this.getRangeToNodeEnd().cloneContents()),b=a.textContent;return/^\s*$/.test(b)},caretIsFirstInSelection:function(){var b=rangy.createRange(this.doc),c=this.getSelection(),d=this.getRange(),e=d.startContainer;return e?e.nodeType===a.TEXT_NODE?this.isCollapsed()&&e.nodeType===a.TEXT_NODE&&/^\s*$/.test(e.data.substr(0,d.startOffset)):(b.selectNodeContents(this.getRange().commonAncestorContainer),b.collapse(!0),this.isCollapsed()&&(b.startContainer===c.anchorNode||b.endContainer===c.anchorNode)&&b.startOffset===c.anchorOffset):void 0},caretIsInTheBeginnig:function(b){var c=this.getSelection(),d=c.anchorNode,e=c.anchorOffset;return b&&d?0===e&&(d.nodeName&&d.nodeName===b.toUpperCase()||a.dom.getParentElement(d.parentNode,{nodeName:b},1)):d?0===e&&!this.getPreviousNode(d,!0):void 0},caretIsBeforeUneditable:function(){var b,c,d,e=this.getSelection(),f=e.anchorNode,g=e.anchorOffset,h=[];if(f)if(0===g){var i=this.getPreviousNode(f,!0),j=i?a.dom.domNode(i).lastLeafNode(this.unselectableClass?{leafClasses:[this.unselectableClass]}:!1):null;if(j)for(var k=this.getOwnUneditables(),l=0,m=k.length;m>l;l++)if(j===k[l])return k[l]}else{if(b=e.getRangeAt(0),b.setStart(b.startContainer,b.startOffset-1),b){c=b.getNodes([1,3]);for(var n=0,o=c.length;o>n;n++)c[n].parentNode&&c[n].parentNode===f&&h.push(c[n])}if(d=h.length>0?h[h.length-1]:null,d&&1===d.nodeType&&a.dom.hasClass(d,this.unselectableClass))return d}return!1},executeAndRestoreRangy:function(a){var b=this.doc.defaultView||this.doc.parentWindow,c=rangy.saveSelection(b);if(c)try{a()}catch(d){setTimeout(function(){throw d},0)}else a();rangy.restoreSelection(c)},executeAndRestore:function(b,c){var d,f,g,h,i,j,k,l,m=this.doc.body,n=c&&m.scrollTop,o=c&&m.scrollLeft,p="_wysihtml5-temp-placeholder",q='<span class="'+p+'">'+a.INVISIBLE_SPACE+"</span>",r=this.getRange(!0);if(!r)return void b(m,m);r.collapsed||(k=r.cloneRange(),j=k.createContextualFragment(q),k.collapse(!1),k.insertNode(j),k.detach()),i=r.createContextualFragment(q),r.insertNode(i),j&&(d=this.contain.querySelectorAll("."+p),r.setStartBefore(d[0]),r.setEndAfter(d[d.length-1])),this.setSelection(r);try{b(r.startContainer,r.endContainer)}catch(s){setTimeout(function(){throw s},0)}if(d=this.contain.querySelectorAll("."+p),d&&d.length){l=rangy.createRange(this.doc),g=d[0].nextSibling,d.length>1&&(h=d[d.length-1].previousSibling),h&&g?(l.setStartBefore(g),l.setEndAfter(h)):(f=this.doc.createTextNode(a.INVISIBLE_SPACE),e.insert(f).after(d[0]),l.setStartBefore(f),l.setEndAfter(f)),this.setSelection(l);for(var t=d.length;t--;)d[t].parentNode.removeChild(d[t])}else this.contain.focus();c&&(m.scrollTop=n,m.scrollLeft=o);try{d.parentNode.removeChild(d)}catch(u){}},set:function(a,b){var c=rangy.createRange(this.doc);c.setStart(a,b||0),this.setSelection(c)},insertHTML:function(a){var b,c=(rangy.createRange(this.doc),this.doc.createElement("DIV")),d=this.doc.createDocumentFragment();for(c.innerHTML=a,b=c.lastChild;c.firstChild;)d.appendChild(c.firstChild);this.insertNode(d),b&&this.setAfter(b)},insertNode:function(a){var b=this.getRange();b&&b.insertNode(a)},surround:function(a){var b,c=this.getOwnRanges(),d=[];if(0==c.length)return d;for(var e=c.length;e--;){b=this.doc.createElement(a.nodeName),d.push(b),a.className&&(b.className=a.className),a.cssStyle&&b.setAttribute("style",a.cssStyle);try{c[e].surroundContents(b),this.selectNode(b)}catch(f){b.appendChild(c[e].extractContents()),c[e].insertNode(b)}}return d},deblockAndSurround:function(b){var c,d,e,f=this.doc.createElement("div"),g=rangy.createRange(this.doc);if(f.className=b.className,this.composer.commands.exec("formatBlock",b.nodeName,b.className),c=this.contain.querySelectorAll("."+b.className),c[0])for(c[0].parentNode.insertBefore(f,c[0]),g.setStartBefore(c[0]),g.setEndAfter(c[c.length-1]),d=g.extractContents();d.firstChild;)if(e=d.firstChild,1==e.nodeType&&a.dom.hasClass(e,b.className)){for(;e.firstChild;)f.appendChild(e.firstChild);"BR"!==e.nodeName&&f.appendChild(this.doc.createElement("br")),d.removeChild(e)}else f.appendChild(e);else f=null;return f},scrollIntoView:function(){var c,d=this.doc,e=5,f=d.documentElement.scrollHeight>d.documentElement.offsetHeight,g=d._wysihtml5ScrollIntoViewElement=d._wysihtml5ScrollIntoViewElement||function(){var b=d.createElement("span");return b.innerHTML=a.INVISIBLE_SPACE,b}();f&&(this.insertNode(g),c=b(g),g.parentNode.removeChild(g),c>=d.body.scrollTop+d.documentElement.offsetHeight-e&&(d.body.scrollTop=c))},selectLine:function(){a.browser.supportsSelectionModify()?this._selectLine_W3C():this.doc.selection&&this._selectLine_MSIE()},_selectLine_W3C:function(){var a=this.doc.defaultView,b=a.getSelection();b.modify("move","left","lineboundary"),b.modify("extend","right","lineboundary")},toLineBoundary:function(b,c){if(c="undefined"==typeof c?!1:c,a.browser.supportsSelectionModify()){var d=this.doc.defaultView,e=d.getSelection();e.modify("extend",b,"lineboundary"),c&&("left"===b?e.collapseToStart():"right"===b&&e.collapseToEnd())}},_selectLine_MSIE:function(){var a,b,c,d,e,f=this.doc.selection.createRange(),g=f.boundingTop,h=this.doc.body.scrollWidth;if(f.moveToPoint){for(0===g&&(c=this.doc.createElement("span"),this.insertNode(c),g=c.offsetTop,c.parentNode.removeChild(c)),g+=1,d=-10;h>d;d+=2)try{f.moveToPoint(d,g);break}catch(i){}for(a=g,b=this.doc.selection.createRange(),e=h;e>=0;e--)try{b.moveToPoint(e,a);break}catch(j){}f.setEndPoint("EndToEnd",b),f.select()}},getText:function(){var a=this.getSelection();return a?a.toString():""},getNodes:function(a,b){var c=this.getRange();return c?c.getNodes([a],b):[]},fixRangeOverflow:function(a){if(this.contain&&this.contain.firstChild&&a){var b=a.compareNode(this.contain);if(2!==b)1===b&&a.setStartBefore(this.contain.firstChild),0===b&&a.setEndAfter(this.contain.lastChild),3===b&&(a.setStartBefore(this.contain.firstChild),a.setEndAfter(this.contain.lastChild));else if(this._detectInlineRangeProblems(a)){var c=a.endContainer.previousElementSibling;c&&a.setEnd(c,this._endOffsetForNode(c))}}},_endOffsetForNode:function(a){var b=document.createRange();return b.selectNodeContents(a),b.endOffset},_detectInlineRangeProblems:function(a){var b=e.compareDocumentPosition(a.startContainer,a.endContainer);return 0==a.endOffset&&4&b},getRange:function(a){var b=this.getSelection(),c=b&&b.rangeCount&&b.getRangeAt(0);return a!==!0&&this.fixRangeOverflow(c),c},getOwnUneditables:function(){var b=e.query(this.contain,"."+this.unselectableClass),c=e.query(b,"."+this.unselectableClass);return a.lang.array(b).without(c)},getOwnRanges:function(){var a,b=[],c=this.getRange();if(c&&b.push(c),this.unselectableClass&&this.contain&&c){var d,e=this.getOwnUneditables();if(e.length>0)for(var f=0,g=e.length;g>f;f++){a=[];for(var h=0,i=b.length;i>h;h++){if(b[h])switch(b[h].compareNode(e[f])){case 2:break;case 3:d=b[h].cloneRange(),d.setEndBefore(e[f]),a.push(d),d=b[h].cloneRange(),d.setStartAfter(e[f]),a.push(d);break;default:a.push(b[h])}b=a}}}return b},getSelection:function(){return rangy.getSelection(this.doc.defaultView||this.doc.parentWindow)},setSelection:function(a){var b=this.doc.defaultView||this.doc.parentWindow,c=rangy.getSelection(b);return c.setSingleRange(a),c&&c.anchorNode&&c.focusNode?c:null},createRange:function(){return rangy.createRange(this.doc)},isCollapsed:function(){return this.getSelection().isCollapsed},getHtml:function(){return this.getSelection().toHtml()},getPlainText:function(){return this.getSelection().toString()},isEndToEndInNode:function(b){var c=this.getRange(),d=c.commonAncestorContainer,e=c.startContainer,f=c.endContainer;if(d.nodeType===a.TEXT_NODE&&(d=d.parentNode),e.nodeType===a.TEXT_NODE&&!/^\s*$/.test(e.data.substr(c.startOffset)))return!1;if(f.nodeType===a.TEXT_NODE&&!/^\s*$/.test(f.data.substr(c.endOffset)))return!1;for(;e&&e!==d;){if(e.nodeType!==a.TEXT_NODE&&!a.dom.contains(d,e))return!1;if(a.dom.domNode(e).prev({ignoreBlankTexts:!0}))return!1;e=e.parentNode}for(;f&&f!==d;){if(f.nodeType!==a.TEXT_NODE&&!a.dom.contains(d,f))return!1;if(a.dom.domNode(f).next({ignoreBlankTexts:!0}))return!1;f=f.parentNode}return a.lang.array(b).contains(d.nodeName)?d:!1},deselect:function(){var a=this.getSelection();a&&a.removeAllRanges()}})}(wysihtml5),function(a,b){function c(a,b,c){if(!a.className)return!1;var d=a.className.match(c)||[];return d[d.length-1]===b}function d(a,b){if(!a.getAttribute||!a.getAttribute("style"))return!1;a.getAttribute("style").match(b);return a.getAttribute("style").match(b)?!0:!1}function e(a,b,c){a.getAttribute("style")?(h(a,c),a.getAttribute("style")&&!/^\s*$/.test(a.getAttribute("style"))?a.setAttribute("style",b+";"+a.getAttribute("style")):a.setAttribute("style",b)):a.setAttribute("style",b)}function f(a,b,c){a.className?(g(a,c),a.className+=" "+b):a.className=b}function g(a,b){a.className&&(a.className=a.className.replace(b,""))}function h(a,b){var c,d=[];if(a.getAttribute("style")){c=a.getAttribute("style").split(";");for(var e=c.length;e--;)c[e].match(b)||/^\s*$/.test(c[e])||d.push(c[e]);d.length?a.setAttribute("style",d.join(";")):a.removeAttribute("style")}}function i(a,b){var c=[],d=b.split(";"),e=a.getAttribute("style");if(e){e=e.replace(/\s/gi,"").toLowerCase(),c.push(new RegExp("(^|\\s|;)"+b.replace(/\s/gi,"").replace(/([\(\)])/gi,"\\$1").toLowerCase().replace(";",";?").replace(/rgb\\\((\d+),(\d+),(\d+)\\\)/gi,"\\s?rgb\\($1,\\s?$2,\\s?$3\\)"),"gi"));for(var f=d.length;f-->0;)/^\s*$/.test(d[f])||c.push(new RegExp("(^|\\s|;)"+d[f].replace(/\s/gi,"").replace(/([\(\)])/gi,"\\$1").toLowerCase().replace(";",";?").replace(/rgb\\\((\d+),(\d+),(\d+)\\\)/gi,"\\s?rgb\\($1,\\s?$2,\\s?$3\\)"),"gi"));for(var g=0,h=c.length;h>g;g++)if(e.match(c[g]))return c[g]}return!1}function j(c,d,e,f){return e?i(c,e):f?a.dom.hasClass(c,f):b.dom.arrayContains(d,c.tagName.toLowerCase())}function k(a,b,c,d){for(var e=a.length;e--;)if(!j(a[e],b,c,d))return!1;return a.length?!0:!1}function l(a,b,c){var d=i(a,b);return d?(h(a,d),"remove"):(e(a,b,c),"change")}function m(a,b){return a.className.replace(u," ")==b.className.replace(u," ")}function n(a){for(var b=a.parentNode;a.firstChild;)b.insertBefore(a.firstChild,a);b.removeChild(a)}function o(a,b){if(a.attributes.length!=b.attributes.length)return!1;for(var c,d,e,f=0,g=a.attributes.length;g>f;++f)if(c=a.attributes[f],e=c.name,"class"!=e){if(d=b.attributes.getNamedItem(e),c.specified!=d.specified)return!1;if(c.specified&&c.nodeValue!==d.nodeValue)return!1}return!0}function p(a,c){return b.dom.isCharacterDataNode(a)?0==c?!!a.previousSibling:c==a.length?!!a.nextSibling:!0:c>0&&c<a.childNodes.length}function q(a,c,d,e){var f;if(b.dom.isCharacterDataNode(c)&&(0==d?(d=b.dom.getNodeIndex(c),c=c.parentNode):d==c.length?(d=b.dom.getNodeIndex(c)+1,c=c.parentNode):f=b.dom.splitDataNode(c,d)),!(f||e&&c===e)){f=c.cloneNode(!1),f.id&&f.removeAttribute("id");for(var g;g=c.childNodes[d];)f.appendChild(g);b.dom.insertAfter(f,c)}return c==a?f:q(a,f.parentNode,b.dom.getNodeIndex(f),e)}function r(b){this.isElementMerge=b.nodeType==a.ELEMENT_NODE,this.firstTextNode=this.isElementMerge?b.lastChild:b,this.textNodes=[this.firstTextNode]}function s(a,b,c,d,e,f,g){this.tagNames=a||[t],this.cssClass=b||(b===!1?!1:""),this.similarClassRegExp=c,this.cssStyle=e||"",this.similarStyleRegExp=f,this.normalize=d,this.applyToAnyTagName=!1,this.container=g}var t="span",u=/\s+/g;r.prototype={doMerge:function(){for(var a,b,c,d=[],e=0,f=this.textNodes.length;f>e;++e)a=this.textNodes[e],b=a.parentNode,d[e]=a.data,e&&(b.removeChild(a),b.hasChildNodes()||b.parentNode.removeChild(b));return this.firstTextNode.data=c=d.join(""),c},getLength:function(){for(var a=this.textNodes.length,b=0;a--;)b+=this.textNodes[a].length;return b},toString:function(){for(var a=[],b=0,c=this.textNodes.length;c>b;++b)a[b]="'"+this.textNodes[b].data+"'";return"[Merge("+a.join(",")+")]"}},s.prototype={getAncestorWithClass:function(d){for(var e;d;){if(e=this.cssClass?c(d,this.cssClass,this.similarClassRegExp):""!==this.cssStyle?!1:!0,d.nodeType==a.ELEMENT_NODE&&"false"!=d.getAttribute("contenteditable")&&b.dom.arrayContains(this.tagNames,d.tagName.toLowerCase())&&e)return d;d=d.parentNode}return!1},getAncestorWithStyle:function(c){for(var e;c;){if(e=this.cssStyle?d(c,this.similarStyleRegExp):!1,c.nodeType==a.ELEMENT_NODE&&"false"!=c.getAttribute("contenteditable")&&b.dom.arrayContains(this.tagNames,c.tagName.toLowerCase())&&e)return c;c=c.parentNode}return!1},getMatchingAncestor:function(a){var b=this.getAncestorWithClass(a),c=!1;return b?this.cssStyle&&(c="class"):(b=this.getAncestorWithStyle(a),b&&(c="style")),{element:b,type:c}},postApply:function(a,b){for(var c,d,e,f=a[0],g=a[a.length-1],h=[],i=f,j=g,k=0,l=g.length,m=0,n=a.length;n>m;++m)d=a[m],e=null,d&&d.parentNode&&(e=this.getAdjacentMergeableTextNode(d.parentNode,!1)),e?(c||(c=new r(e),h.push(c)),c.textNodes.push(d),d===f&&(i=c.firstTextNode,k=i.length),d===g&&(j=c.firstTextNode,l=c.getLength())):c=null;if(g&&g.parentNode){var o=this.getAdjacentMergeableTextNode(g.parentNode,!0);o&&(c||(c=new r(g),h.push(c)),c.textNodes.push(o))}if(h.length){for(m=0,n=h.length;n>m;++m)h[m].doMerge();b.setStart(i,k),b.setEnd(j,l)}},getAdjacentMergeableTextNode:function(b,c){var d,e=b.nodeType==a.TEXT_NODE,f=e?b.parentNode:b,g=c?"nextSibling":"previousSibling";if(e){if(d=b[g],d&&d.nodeType==a.TEXT_NODE)return d}else if(d=f[g],d&&this.areElementsMergeable(b,d))return d[c?"firstChild":"lastChild"];return null},areElementsMergeable:function(a,c){return b.dom.arrayContains(this.tagNames,(a.tagName||"").toLowerCase())&&b.dom.arrayContains(this.tagNames,(c.tagName||"").toLowerCase())&&m(a,c)&&o(a,c)},createContainer:function(a){var b=a.createElement(this.tagNames[0]);return this.cssClass&&(b.className=this.cssClass),this.cssStyle&&b.setAttribute("style",this.cssStyle),b},applyToTextNode:function(a){var c=a.parentNode;if(1==c.childNodes.length&&b.dom.arrayContains(this.tagNames,c.tagName.toLowerCase()))this.cssClass&&f(c,this.cssClass,this.similarClassRegExp),this.cssStyle&&e(c,this.cssStyle,this.similarStyleRegExp);else{var d=this.createContainer(b.dom.getDocument(a));a.parentNode.insertBefore(d,a),d.appendChild(a)}},isRemovable:function(c){return b.dom.arrayContains(this.tagNames,c.tagName.toLowerCase())&&""===a.lang.string(c.className).trim()&&(!c.getAttribute("style")||""===a.lang.string(c.getAttribute("style")).trim())},undoToTextNode:function(a,b,c,d){var e=c?!1:!0,f=c||d,h=!1;if(!b.containsNode(f)){var i=b.cloneRange();i.selectNode(f),i.isPointInRange(b.endContainer,b.endOffset)&&p(b.endContainer,b.endOffset)&&(q(f,b.endContainer,b.endOffset,this.container),b.setEndAfter(f)),i.isPointInRange(b.startContainer,b.startOffset)&&p(b.startContainer,b.startOffset)&&(f=q(f,b.startContainer,b.startOffset,this.container))}!e&&this.similarClassRegExp&&g(f,this.similarClassRegExp),e&&this.similarStyleRegExp&&(h="change"===l(f,this.cssStyle,this.similarStyleRegExp)),this.isRemovable(f)&&!h&&n(f)},applyToRange:function(b){for(var c,d=b.length;d--;){if(c=b[d].getNodes([a.TEXT_NODE]),!c.length)try{var e=this.createContainer(b[d].endContainer.ownerDocument);return b[d].surroundContents(e),void this.selectNode(b[d],e)}catch(f){}if(b[d].splitBoundaries(),c=b[d].getNodes([a.TEXT_NODE]),c.length){for(var g,h=0,i=c.length;i>h;++h)g=c[h],this.getMatchingAncestor(g).element||this.applyToTextNode(g);b[d].setStart(c[0],0),g=c[c.length-1],b[d].setEnd(g,g.length),this.normalize&&this.postApply(c,b[d])}}},undoToRange:function(b){for(var c,d,e,f=b.length;f--;){if(c=b[f].getNodes([a.TEXT_NODE]),c.length)b[f].splitBoundaries(),c=b[f].getNodes([a.TEXT_NODE]);
+else{var g=b[f].endContainer.ownerDocument,h=g.createTextNode(a.INVISIBLE_SPACE);b[f].insertNode(h),b[f].selectNode(h),c=[h]}for(var i=0,j=c.length;j>i;++i)b[f].isValid()&&(d=c[i],e=this.getMatchingAncestor(d),"style"===e.type?this.undoToTextNode(d,b[f],!1,e.element):e.element&&this.undoToTextNode(d,b[f],e.element));1==j?this.selectNode(b[f],c[0]):(b[f].setStart(c[0],0),d=c[c.length-1],b[f].setEnd(d,d.length),this.normalize&&this.postApply(c,b[f]))}},selectNode:function(b,c){var d=c.nodeType===a.ELEMENT_NODE,e="canHaveHTML"in c?c.canHaveHTML:!0,f=d?c.innerHTML:c.data,g=""===f||f===a.INVISIBLE_SPACE;if(g&&d&&e)try{c.innerHTML=a.INVISIBLE_SPACE}catch(h){}b.selectNodeContents(c),g&&d?b.collapse(!1):g&&(b.setStartAfter(c),b.setEndAfter(c))},getTextSelectedByRange:function(a,b){var c=b.cloneRange();c.selectNodeContents(a);var d=c.intersection(b),e=d?d.toString():"";return c.detach(),e},isAppliedToRange:function(b){for(var c,d,e=[],f="full",g=b.length;g--;){if(d=b[g].getNodes([a.TEXT_NODE]),!d.length)return c=this.getMatchingAncestor(b[g].startContainer).element,c?{elements:[c],coverage:f}:!1;for(var h,i=0,j=d.length;j>i;++i)h=this.getTextSelectedByRange(d[i],b[g]),c=this.getMatchingAncestor(d[i]).element,c&&""!=h?(e.push(c),1===a.dom.getTextNodes(c,!0).length?f="full":"full"===f&&(f="inline")):c||(f="partial")}return e.length?{elements:e,coverage:f}:!1},toggleRange:function(a){var b,c=this.isAppliedToRange(a);c?"full"===c.coverage?this.undoToRange(a):"inline"===c.coverage?(b=k(c.elements,this.tagNames,this.cssStyle,this.cssClass),this.undoToRange(a),b||this.applyToRange(a)):(k(c.elements,this.tagNames,this.cssStyle,this.cssClass)||this.undoToRange(a),this.applyToRange(a)):this.applyToRange(a)}},a.selection.HTMLApplier=s}(wysihtml5,rangy),wysihtml5.Commands=Base.extend({constructor:function(a){this.editor=a,this.composer=a.composer,this.doc=this.composer.doc},support:function(a){return wysihtml5.browser.supportsCommand(this.doc,a)},exec:function(a,b){var c=wysihtml5.commands[a],d=wysihtml5.lang.array(arguments).get(),e=c&&c.exec,f=null;if(this.composer.hasPlaceholderSet()&&!wysihtml5.lang.array(["styleWithCSS","enableObjectResizing","enableInlineTableEditing"]).contains(a)&&(this.composer.element.innerHTML="",this.composer.selection.selectNode(this.composer.element)),this.editor.fire("beforecommand:composer"),e)d.unshift(this.composer),f=e.apply(c,d);else try{f=this.doc.execCommand(a,!1,b)}catch(g){}return this.editor.fire("aftercommand:composer"),f},state:function(a){var b=wysihtml5.commands[a],c=wysihtml5.lang.array(arguments).get(),d=b&&b.state;if(d)return c.unshift(this.composer),d.apply(b,c);try{return this.doc.queryCommandState(a)}catch(e){return!1}},stateValue:function(a){var b=wysihtml5.commands[a],c=wysihtml5.lang.array(arguments).get(),d=b&&b.stateValue;return d?(c.unshift(this.composer),d.apply(b,c)):!1}}),wysihtml5.commands.bold={exec:function(a,b){wysihtml5.commands.formatInline.execWithToggle(a,b,"b")},state:function(a,b){return wysihtml5.commands.formatInline.state(a,b,"b")}},function(a){function b(b,c){var g,h,i,j,k,l,m,n,o,p=b.doc,q="_wysihtml5-temp-"+ +new Date,r=/non-matching-class/g,s=0;for(a.commands.formatInline.exec(b,d,e,q,r,d,d,!0,!0),h=p.querySelectorAll(e+"."+q),g=h.length;g>s;s++){i=h[s],i.removeAttribute("class");for(o in c)"text"!==o&&i.setAttribute(o,c[o])}l=i,1===g&&(m=f.getTextContent(i),j=!!i.querySelector("*"),k=""===m||m===a.INVISIBLE_SPACE,!j&&k&&(f.setTextContent(i,c.text||i.href),n=p.createTextNode(" "),b.selection.setAfter(i),f.insert(n).after(i),l=n)),b.selection.setAfter(l)}function c(a,b,c){for(var d,e=b.length;e--;){d=b[e].attributes;for(var f=d.length;f--;)b[e].removeAttribute(d.item(f).name);for(var g in c)c.hasOwnProperty(g)&&b[e].setAttribute(g,c[g])}}var d,e="A",f=a.dom;a.commands.createLink={exec:function(a,d,e){var f=this.state(a,d);f?a.selection.executeAndRestore(function(){c(a,f,e)}):(e="object"==typeof e?e:{href:e},b(a,e))},state:function(b,c){return a.commands.formatInline.state(b,c,"A")}}}(wysihtml5),function(a){function b(a,b){for(var d,e,f,g=b.length,h=0;g>h;h++)d=b[h],e=c.getParentElement(d,{nodeName:"code"}),f=c.getTextContent(d),f.match(c.autoLink.URL_REG_EXP)&&!e?e=c.renameElement(d,"code"):c.replaceWithChildNodes(d)}var c=a.dom;a.commands.removeLink={exec:function(a,c){var d=this.state(a,c);d&&a.selection.executeAndRestore(function(){b(a,d)})},state:function(b,c){return a.commands.formatInline.state(b,c,"A")}}}(wysihtml5),function(a){var b=/wysiwyg-font-size-[0-9a-z\-]+/g;a.commands.fontSize={exec:function(c,d,e){a.commands.formatInline.execWithToggle(c,d,"span","wysiwyg-font-size-"+e,b)},state:function(c,d,e){return a.commands.formatInline.state(c,d,"span","wysiwyg-font-size-"+e,b)}}}(wysihtml5),function(a){var b=/(\s|^)font-size\s*:\s*[^;\s]+;?/gi;a.commands.fontSizeStyle={exec:function(c,d,e){e="object"==typeof e?e.size:e,/^\s*$/.test(e)||a.commands.formatInline.execWithToggle(c,d,"span",!1,!1,"font-size:"+e,b)},state:function(c,d){return a.commands.formatInline.state(c,d,"span",!1,!1,"font-size",b)},stateValue:function(b,c){var d,e=this.state(b,c);return e&&a.lang.object(e).isArray()&&(e=e[0]),e&&(d=e.getAttribute("style"))?a.quirks.styleParser.parseFontSize(d):!1}}}(wysihtml5),function(a){var b=/wysiwyg-color-[0-9a-z]+/g;a.commands.foreColor={exec:function(c,d,e){a.commands.formatInline.execWithToggle(c,d,"span","wysiwyg-color-"+e,b)},state:function(c,d,e){return a.commands.formatInline.state(c,d,"span","wysiwyg-color-"+e,b)}}}(wysihtml5),function(a){var b=/(\s|^)color\s*:\s*[^;\s]+;?/gi;a.commands.foreColorStyle={exec:function(c,d,e){var f,g=a.quirks.styleParser.parseColor("object"==typeof e?"color:"+e.color:"color:"+e,"color");g&&(f="color: rgb("+g[0]+","+g[1]+","+g[2]+");",1!==g[3]&&(f+="color: rgba("+g[0]+","+g[1]+","+g[2]+","+g[3]+");"),a.commands.formatInline.execWithToggle(c,d,"span",!1,!1,f,b))},state:function(c,d){return a.commands.formatInline.state(c,d,"span",!1,!1,"color",b)},stateValue:function(b,c,d){var e,f=this.state(b,c);return f&&a.lang.object(f).isArray()&&(f=f[0]),f&&(e=f.getAttribute("style"),e&&e)?(val=a.quirks.styleParser.parseColor(e,"color"),a.quirks.styleParser.unparseColor(val,d)):!1}}}(wysihtml5),function(a){var b=/(\s|^)background-color\s*:\s*[^;\s]+;?/gi;a.commands.bgColorStyle={exec:function(c,d,e){var f,g=a.quirks.styleParser.parseColor("object"==typeof e?"background-color:"+e.color:"background-color:"+e,"background-color");g&&(f="background-color: rgb("+g[0]+","+g[1]+","+g[2]+");",1!==g[3]&&(f+="background-color: rgba("+g[0]+","+g[1]+","+g[2]+","+g[3]+");"),a.commands.formatInline.execWithToggle(c,d,"span",!1,!1,f,b))},state:function(c,d){return a.commands.formatInline.state(c,d,"span",!1,!1,"background-color",b)},stateValue:function(b,c,d){var e,f=this.state(b,c),g=!1;return f&&a.lang.object(f).isArray()&&(f=f[0]),f&&(e=f.getAttribute("style"))?(g=a.quirks.styleParser.parseColor(e,"background-color"),a.quirks.styleParser.unparseColor(g,d)):!1}}}(wysihtml5),function(a){function b(b,c,e){b.className?(d(b,e),b.className=a.lang.string(b.className+" "+c).trim()):b.className=c}function c(b,c,d){e(b,d),b.getAttribute("style")?b.setAttribute("style",a.lang.string(b.getAttribute("style")+" "+c).trim()):b.setAttribute("style",c)}function d(b,c){var d=c.test(b.className);return b.className=b.className.replace(c,""),""==a.lang.string(b.className).trim()&&b.removeAttribute("class"),d}function e(b,c){var d=c.test(b.getAttribute("style"));return b.setAttribute("style",(b.getAttribute("style")||"").replace(c,"")),""==a.lang.string(b.getAttribute("style")||"").trim()&&b.removeAttribute("style"),d}function f(a){var b=a.lastChild;b&&g(b)&&b.parentNode.removeChild(b)}function g(a){return"BR"===a.nodeName}function h(b,c){b.selection.isCollapsed()&&b.selection.selectLine();for(var d=b.selection.surround(c),e=0,g=d.length;g>e;e++)a.dom.lineBreaks(d[e]).remove(),f(d[e])}function i(b){return!!a.lang.string(b.className).trim()}function j(b){return!!a.lang.string(b.getAttribute("style")||"").trim()}var k=a.dom,l=["H1","H2","H3","H4","H5","H6","P","PRE","DIV"];a.commands.formatBlock={exec:function(f,g,m,n,o,p,q){var r,s,t,u,v,w=(f.doc,this.state(f,g,m,n,o,p,q)),x=f.config.useLineBreaks,y=x?"DIV":"P";return m="string"==typeof m?m.toUpperCase():m,w.length?void f.selection.executeAndRestoreRangy(function(){for(var b=w.length;b--;){if(o&&(s=d(w[b],o)),q&&(u=e(w[b],q)),(u||s)&&null===m&&w[b].nodeName!=y)return;var c=i(w[b]),f=j(w[b]);c||f||!x&&"P"!==m?k.renameElement(w[b],"P"===m?"DIV":y):(a.dom.lineBreaks(w[b]).add(),k.replaceWithChildNodes(w[b]))}}):void((null!==m&&!a.lang.array(l).contains(m)||(r=f.selection.findNodesInSelection(l).concat(f.selection.getSelectedOwnNodes()),f.selection.executeAndRestoreRangy(function(){for(var a=r.length;a--;)v=k.getParentElement(r[a],{nodeName:l}),v==f.element&&(v=null),v&&(m&&(v=k.renameElement(v,m)),n&&b(v,n,o),p&&c(v,p,q),t=!0)}),!t))&&h(f,{nodeName:m||y,className:n||null,cssStyle:p||null}))},state:function(b,c,d,e,f,g,h){var i,j=b.selection.getSelectedOwnNodes(),l=[];d="string"==typeof d?d.toUpperCase():d;for(var m=0,n=j.length;n>m;m++)i=k.getParentElement(j[m],{nodeName:d,className:e,classRegExp:f,cssStyle:g,styleRegExp:h}),i&&-1==a.lang.array(l).indexOf(i)&&l.push(i);return 0==l.length?!1:l}}}(wysihtml5),wysihtml5.commands.formatCode={exec:function(a,b,c){var d,e,f,g=this.state(a);g?a.selection.executeAndRestore(function(){d=g.querySelector("code"),wysihtml5.dom.replaceWithChildNodes(g),d&&wysihtml5.dom.replaceWithChildNodes(d)}):(e=a.selection.getRange(),f=e.extractContents(),g=a.doc.createElement("pre"),d=a.doc.createElement("code"),c&&(d.className=c),g.appendChild(d),d.appendChild(f),e.insertNode(g),a.selection.selectNode(g))},state:function(a){var b=a.selection.getSelectedNode();return b&&b.nodeName&&"PRE"==b.nodeName&&b.firstChild&&b.firstChild.nodeName&&"CODE"==b.firstChild.nodeName?b:wysihtml5.dom.getParentElement(b,{nodeName:"CODE"})&&wysihtml5.dom.getParentElement(b,{nodeName:"PRE"})}},function(a){function b(a){var b=d[a];return b?[a.toLowerCase(),b.toLowerCase()]:[a.toLowerCase()]}function c(c,d,f,g,h,i){var j=c;return d&&(j+=":"+d),g&&(j+=":"+g),e[j]||(e[j]=new a.selection.HTMLApplier(b(c),d,f,!0,g,h,i)),e[j]}var d={strong:"b",em:"i",b:"strong",i:"em"},e={};a.commands.formatInline={exec:function(a,b,d,e,f,g,h,i,j){var k=a.selection.createRange(),l=a.selection.getOwnRanges();return l&&0!=l.length?(a.selection.getSelection().removeAllRanges(),c(d,e,f,g,h,a.element).toggleRange(l),void(i?j||a.cleanUp():(k.setStart(l[0].startContainer,l[0].startOffset),k.setEnd(l[l.length-1].endContainer,l[l.length-1].endOffset),a.selection.setSelection(k),a.selection.executeAndRestore(function(){j||a.cleanUp()},!0,!0)))):!1},execWithToggle:function(b,c,d,e,f,g,h){var i=this;if(this.state(b,c,d,e,f,g,h)&&b.selection.isCollapsed()&&!b.selection.caretIsLastInSelection()&&!b.selection.caretIsFirstInSelection()){var j=i.state(b,c,d,e,f)[0];b.selection.executeAndRestoreRangy(function(){j.parentNode;b.selection.selectNode(j,!0),a.commands.formatInline.exec(b,c,d,e,f,g,h,!0,!0)})}else this.state(b,c,d,e,f,g,h)&&!b.selection.isCollapsed()?b.selection.executeAndRestoreRangy(function(){a.commands.formatInline.exec(b,c,d,e,f,g,h,!0,!0)}):a.commands.formatInline.exec(b,c,d,e,f,g,h)},state:function(b,e,f,g,h,i,j){var k,l,m=b.doc,n=d[f]||f;return a.dom.hasElementWithTagName(m,f)||a.dom.hasElementWithTagName(m,n)?g&&!a.dom.hasElementWithClassName(m,g)?!1:(k=b.selection.getOwnRanges(),k&&0!==k.length?(l=c(f,g,h,i,j,b.element).isAppliedToRange(k),l&&l.elements?l.elements:!1):!1):!1}}}(wysihtml5),function(a){a.commands.insertBlockQuote={exec:function(b,c){var d=this.state(b,c),e=b.selection.isEndToEndInNode(["H1","H2","H3","H4","H5","H6","P"]);b.selection.executeAndRestore(function(){if(d)b.config.useLineBreaks&&a.dom.lineBreaks(d).add(),a.dom.unwrap(d);else if(b.selection.isCollapsed()&&b.selection.selectLine(),e){var c=e.ownerDocument.createElement("blockquote");a.dom.insert(c).after(e),c.appendChild(e)}else b.selection.surround({nodeName:"blockquote"})})},state:function(b){var c=b.selection.getSelectedNode(),d=a.dom.getParentElement(c,{nodeName:"BLOCKQUOTE"},!1,b.element);return d?d:!1}}}(wysihtml5),wysihtml5.commands.insertHTML={exec:function(a,b,c){a.commands.support(b)?a.doc.execCommand(b,!1,c):a.selection.insertHTML(c)},state:function(){return!1}},function(a){var b="IMG";a.commands.insertImage={exec:function(c,d,e){e="object"==typeof e?e:{src:e};var f,g,h=c.doc,i=this.state(c);if(i)return c.selection.setBefore(i),g=i.parentNode,g.removeChild(i),a.dom.removeEmptyTextNodes(g),"A"!==g.nodeName||g.firstChild||(c.selection.setAfter(g),g.parentNode.removeChild(g)),void a.quirks.redraw(c.element);i=h.createElement(b);for(var j in e)i.setAttribute("className"===j?"class":j,e[j]);c.selection.insertNode(i),a.browser.hasProblemsSettingCaretAfterImg()?(f=h.createTextNode(a.INVISIBLE_SPACE),c.selection.insertNode(f),c.selection.setAfter(f)):c.selection.setAfter(i)},state:function(c){var d,e,f,g=c.doc;return a.dom.hasElementWithTagName(g,b)&&(d=c.selection.getSelectedNode())?d.nodeName===b?d:d.nodeType!==a.ELEMENT_NODE?!1:(e=c.selection.getText(),(e=a.lang.string(e).trim())?!1:(f=c.selection.getNodes(a.ELEMENT_NODE,function(a){return"IMG"===a.nodeName}),1!==f.length?!1:f[0])):!1}}}(wysihtml5),function(a){var b="<br>"+(a.browser.needsSpaceAfterLineBreak()?" ":"");a.commands.insertLineBreak={exec:function(c,d){c.commands.support(d)?(c.doc.execCommand(d,!1,null),a.browser.autoScrollsToCaret()||c.selection.scrollIntoView()):c.commands.exec("insertHTML",b)},state:function(){return!1}}}(wysihtml5),wysihtml5.commands.insertOrderedList={exec:function(a,b){wysihtml5.commands.insertList.exec(a,b,"OL")},state:function(a,b){return wysihtml5.commands.insertList.state(a,b,"OL")}},wysihtml5.commands.insertUnorderedList={exec:function(a,b){wysihtml5.commands.insertList.exec(a,b,"UL")},state:function(a,b){return wysihtml5.commands.insertList.state(a,b,"UL")}},wysihtml5.commands.insertList=function(a){var b=function(a,b){if(a&&a.nodeName){"string"==typeof b&&(b=[b]);for(var c=b.length;c--;)if(a.nodeName===b[c])return!0}return!1},c=function(c,d,e){var f={el:null,other:!1};if(c){var g=a.dom.getParentElement(c,{nodeName:"LI"}),h="UL"===d?"OL":"UL";b(c,d)?f.el=c:b(c,h)?f={el:c,other:!0}:g&&(b(g.parentNode,d)?f.el=g.parentNode:b(g.parentNode,h)&&(f={el:g.parentNode,other:!0}))}return f.el&&!e.element.contains(f.el)&&(f.el=null),f},d=function(b,c,d){var e,g="UL"===c?"OL":"UL";d.selection.executeAndRestore(function(){var h=f(g,d);if(h.length)for(var i=h.length;i--;)a.dom.renameElement(h[i],c.toLowerCase());else{e=f(["OL","UL"],d);for(var j=e.length;j--;)a.dom.resolveList(e[j],d.config.useLineBreaks);a.dom.resolveList(b,d.config.useLineBreaks)}})},e=function(b,c,d){var e="UL"===c?"OL":"UL";d.selection.executeAndRestore(function(){for(var g=[b].concat(f(e,d)),h=g.length;h--;)a.dom.renameElement(g[h],c.toLowerCase())})},f=function(a,c){for(var d=c.selection.getOwnRanges(),e=[],f=d.length;f--;)e=e.concat(d[f].getNodes([1],function(c){return b(c,a)}));return e},g=function(b,c){c.selection.executeAndRestoreRangy(function(){var d,e,f="_wysihtml5-temp-"+(new Date).getTime(),g=c.selection.deblockAndSurround({nodeName:"div",className:f});g.innerHTML=g.innerHTML.replace(a.INVISIBLE_SPACE_REG_EXP,""),g&&(d=a.lang.array(["","<br>",a.INVISIBLE_SPACE]).contains(g.innerHTML),e=a.dom.convertToList(g,b.toLowerCase(),c.parent.config.uneditableContainerClassname),d&&c.selection.selectNode(e.querySelector("li"),!0))})};return{exec:function(a,b,f){var h=a.doc,i="OL"===f?"insertOrderedList":"insertUnorderedList",j=a.selection.getSelectedNode(),k=c(j,f,a);k.el?k.other?e(k.el,f,a):d(k.el,f,a):a.commands.support(i)?h.execCommand(i,!1,null):g(f,a)},state:function(a,b,d){var e=a.selection.getSelectedNode(),f=c(e,d,a);return f.el&&!f.other?f.el:!1}}}(wysihtml5),wysihtml5.commands.italic={exec:function(a,b){wysihtml5.commands.formatInline.execWithToggle(a,b,"i")},state:function(a,b){return wysihtml5.commands.formatInline.state(a,b,"i")}},function(a){var b="wysiwyg-text-align-center",c=/wysiwyg-text-align-[0-9a-z]+/g;a.commands.justifyCenter={exec:function(d){return a.commands.formatBlock.exec(d,"formatBlock",null,b,c)},state:function(d){return a.commands.formatBlock.state(d,"formatBlock",null,b,c)}}}(wysihtml5),function(a){var b="wysiwyg-text-align-left",c=/wysiwyg-text-align-[0-9a-z]+/g;a.commands.justifyLeft={exec:function(d){return a.commands.formatBlock.exec(d,"formatBlock",null,b,c)},state:function(d){return a.commands.formatBlock.state(d,"formatBlock",null,b,c)}}}(wysihtml5),function(a){var b="wysiwyg-text-align-right",c=/wysiwyg-text-align-[0-9a-z]+/g;a.commands.justifyRight={exec:function(d){return a.commands.formatBlock.exec(d,"formatBlock",null,b,c)},state:function(d){return a.commands.formatBlock.state(d,"formatBlock",null,b,c)}}}(wysihtml5),function(a){var b="wysiwyg-text-align-justify",c=/wysiwyg-text-align-[0-9a-z]+/g;a.commands.justifyFull={exec:function(d){return a.commands.formatBlock.exec(d,"formatBlock",null,b,c)},state:function(d){return a.commands.formatBlock.state(d,"formatBlock",null,b,c)}}}(wysihtml5),function(a){var b="text-align: right;",c=/(\s|^)text-align\s*:\s*[^;\s]+;?/gi;a.commands.alignRightStyle={exec:function(d){return a.commands.formatBlock.exec(d,"formatBlock",null,null,null,b,c)},state:function(d){return a.commands.formatBlock.state(d,"formatBlock",null,null,null,b,c)}}}(wysihtml5),function(a){var b="text-align: left;",c=/(\s|^)text-align\s*:\s*[^;\s]+;?/gi;a.commands.alignLeftStyle={exec:function(d){return a.commands.formatBlock.exec(d,"formatBlock",null,null,null,b,c)},state:function(d){return a.commands.formatBlock.state(d,"formatBlock",null,null,null,b,c)}}}(wysihtml5),function(a){var b="text-align: center;",c=/(\s|^)text-align\s*:\s*[^;\s]+;?/gi;a.commands.alignCenterStyle={exec:function(d){return a.commands.formatBlock.exec(d,"formatBlock",null,null,null,b,c)},state:function(d){return a.commands.formatBlock.state(d,"formatBlock",null,null,null,b,c)}}}(wysihtml5),wysihtml5.commands.redo={exec:function(a){return a.undoManager.redo()},state:function(){return!1}},wysihtml5.commands.underline={exec:function(a,b){wysihtml5.commands.formatInline.execWithToggle(a,b,"u")},state:function(a,b){return wysihtml5.commands.formatInline.state(a,b,"u")}},wysihtml5.commands.undo={exec:function(a){return a.undoManager.undo()},state:function(){return!1}},wysihtml5.commands.createTable={exec:function(a,b,c){var d,e,f;if(c&&c.cols&&c.rows&&parseInt(c.cols,10)>0&&parseInt(c.rows,10)>0){for(f=c.tableStyle?'<table style="'+c.tableStyle+'">':"<table>",f+="<tbody>",e=0;e<c.rows;e++){for(f+="<tr>",d=0;d<c.cols;d++)f+="<td> </td>";f+="</tr>"}f+="</tbody></table>",a.commands.exec("insertHTML",f)}},state:function(){return!1}},wysihtml5.commands.mergeTableCells={exec:function(a,b){a.tableSelection&&a.tableSelection.start&&a.tableSelection.end&&(this.state(a,b)?wysihtml5.dom.table.unmergeCell(a.tableSelection.start):wysihtml5.dom.table.mergeCellsBetween(a.tableSelection.start,a.tableSelection.end))},state:function(a){if(a.tableSelection){var b=a.tableSelection.start,c=a.tableSelection.end;if(b&&c&&b==c&&(wysihtml5.dom.getAttribute(b,"colspan")&&parseInt(wysihtml5.dom.getAttribute(b,"colspan"),10)>1||wysihtml5.dom.getAttribute(b,"rowspan")&&parseInt(wysihtml5.dom.getAttribute(b,"rowspan"),10)>1))return[b]}return!1}},wysihtml5.commands.addTableCells={exec:function(a,b,c){if(a.tableSelection&&a.tableSelection.start&&a.tableSelection.end){var d=wysihtml5.dom.table.orderSelectionEnds(a.tableSelection.start,a.tableSelection.end);"before"==c||"above"==c?wysihtml5.dom.table.addCells(d.start,c):("after"==c||"below"==c)&&wysihtml5.dom.table.addCells(d.end,c),setTimeout(function(){a.tableSelection.select(d.start,d.end)},0)}},state:function(){return!1}},wysihtml5.commands.deleteTableCells={exec:function(a,b,c){if(a.tableSelection&&a.tableSelection.start&&a.tableSelection.end){var d,e=wysihtml5.dom.table.orderSelectionEnds(a.tableSelection.start,a.tableSelection.end),f=wysihtml5.dom.table.indexOf(e.start),g=a.tableSelection.table;wysihtml5.dom.table.removeCells(e.start,c),setTimeout(function(){d=wysihtml5.dom.table.findCell(g,f),d||("row"==c&&(d=wysihtml5.dom.table.findCell(g,{row:f.row-1,col:f.col})),"column"==c&&(d=wysihtml5.dom.table.findCell(g,{row:f.row,col:f.col-1}))),d&&a.tableSelection.select(d,d)},0)}},state:function(){return!1}},wysihtml5.commands.indentList={exec:function(a){var b=a.selection.getSelectionParentsByTag("LI");return b?this.tryToPushLiLevel(b,a.selection):!1},state:function(){return!1},tryToPushLiLevel:function(a,b){var c,d,e,f,g,h=!1;return b.executeAndRestoreRangy(function(){for(var b=a.length;b--;)f=a[b],c="OL"===f.parentNode.nodeName?"OL":"UL",d=f.ownerDocument.createElement(c),e=wysihtml5.dom.domNode(f).prev({nodeTypes:[wysihtml5.ELEMENT_NODE]}),g=e?e.querySelector("ul, ol"):null,e&&(g?g.appendChild(f):(d.appendChild(f),e.appendChild(d)),h=!0)}),h}},wysihtml5.commands.outdentList={exec:function(a){var b=a.selection.getSelectionParentsByTag("LI");return b?this.tryToPullLiLevel(b,a):!1},state:function(){return!1},tryToPullLiLevel:function(a,b){var c,d,e,f,g,h=!1,i=this;return b.selection.executeAndRestoreRangy(function(){for(var j=a.length;j--;)if(f=a[j],f.parentNode&&(c=f.parentNode,"OL"===c.tagName||"UL"===c.tagName)){if(h=!0,d=wysihtml5.dom.getParentElement(c.parentNode,{nodeName:["OL","UL"]},!1,b.element),e=wysihtml5.dom.getParentElement(c.parentNode,{nodeName:["LI"]},!1,b.element),d&&e)f.nextSibling&&(g=i.getAfterList(c,f),f.appendChild(g)),d.insertBefore(f,e.nextSibling);else{f.nextSibling&&(g=i.getAfterList(c,f),f.appendChild(g));for(var k=f.childNodes.length;k--;)c.parentNode.insertBefore(f.childNodes[k],c.nextSibling);c.parentNode.insertBefore(document.createElement("br"),c.nextSibling),f.parentNode.removeChild(f)}0===c.childNodes.length&&c.parentNode.removeChild(c)}}),h},getAfterList:function(a,b){for(var c=a.nodeName,d=document.createElement(c);b.nextSibling;)d.appendChild(b.nextSibling);return d}},function(a){var b=90,c=89,d=8,e=46,f=25,g="data-wysihtml5-selection-node",h="data-wysihtml5-selection-offset",i=('<span id="_wysihtml5-undo" class="_wysihtml5-temp">'+a.INVISIBLE_SPACE+"</span>",'<span id="_wysihtml5-redo" class="_wysihtml5-temp">'+a.INVISIBLE_SPACE+"</span>",a.dom);a.UndoManager=a.lang.Dispatcher.extend({constructor:function(a){this.editor=a,this.composer=a.composer,this.element=this.composer.element,this.position=0,this.historyStr=[],this.historyDom=[],this.transact(),this._observe()},_observe:function(){{var a,f=this;this.composer.sandbox.getDocument()}i.observe(this.element,"keydown",function(a){if(!a.altKey&&(a.ctrlKey||a.metaKey)){var d=a.keyCode,e=d===b&&!a.shiftKey,g=d===b&&a.shiftKey||d===c;e?(f.undo(),a.preventDefault()):g&&(f.redo(),a.preventDefault())}}),i.observe(this.element,"keydown",function(b){var c=b.keyCode;c!==a&&(a=c,(c===d||c===e)&&f.transact())}),this.editor.on("newword:composer",function(){f.transact()}).on("beforecommand:composer",function(){f.transact()})},transact:function(){var b,c,d,e,i,j=this.historyStr[this.position-1],k=this.composer.getValue(!1,!1),l=this.element.offsetWidth>0&&this.element.offsetHeight>0;if(k!==j){var m=this.historyStr.length=this.historyDom.length=this.position;m>f&&(this.historyStr.shift(),this.historyDom.shift(),this.position--),this.position++,l&&(b=this.composer.selection.getRange(),c=b&&b.startContainer?b.startContainer:this.element,d=b&&b.startOffset?b.startOffset:0,c.nodeType===a.ELEMENT_NODE?e=c:(e=c.parentNode,i=this.getChildNodeIndex(e,c)),e.setAttribute(h,d),"undefined"!=typeof i&&e.setAttribute(g,i));var n=this.element.cloneNode(!!k);this.historyDom.push(n),this.historyStr.push(k),e&&(e.removeAttribute(h),e.removeAttribute(g))}},undo:function(){this.transact(),this.undoPossible()&&(this.set(this.historyDom[--this.position-1]),this.editor.fire("undo:composer"))},redo:function(){this.redoPossible()&&(this.set(this.historyDom[++this.position-1]),this.editor.fire("redo:composer"))},undoPossible:function(){return this.position>1},redoPossible:function(){return this.position<this.historyStr.length},set:function(a){this.element.innerHTML="";for(var b=0,c=a.childNodes,d=a.childNodes.length;d>b;b++)this.element.appendChild(c[b].cloneNode(!0));var e,f,i;a.hasAttribute(h)?(e=a.getAttribute(h),i=a.getAttribute(g),f=this.element):(f=this.element.querySelector("["+h+"]")||this.element,e=f.getAttribute(h),i=f.getAttribute(g),f.removeAttribute(h),f.removeAttribute(g)),null!==i&&(f=this.getChildNodeByIndex(f,+i)),this.composer.selection.set(f,e)},getChildNodeIndex:function(a,b){for(var c=0,d=a.childNodes,e=d.length;e>c;c++)if(d[c]===b)return c},getChildNodeByIndex:function(a,b){return a.childNodes[b]}})}(wysihtml5),wysihtml5.views.View=Base.extend({constructor:function(a,b,c){this.parent=a,this.element=b,this.config=c,this.config.noTextarea||this._observeViewChange()},_observeViewChange:function(){var a=this;this.parent.on("beforeload",function(){a.parent.on("change_view",function(b){b===a.name?(a.parent.currentView=a,a.show(),setTimeout(function(){a.focus()},0)):a.hide()})})},focus:function(){if(!this.element||!this.element.ownerDocument||this.element.ownerDocument.querySelector(":focus")!==this.element)try{this.element&&this.element.focus()}catch(a){}},hide:function(){this.element.style.display="none"},show:function(){this.element.style.display=""},disable:function(){this.element.setAttribute("disabled","disabled")},enable:function(){this.element.removeAttribute("disabled")}}),function(a){var b=a.dom,c=a.browser;a.views.Composer=a.views.View.extend({name:"composer",CARET_HACK:"<br>",constructor:function(a,b,c){this.base(a,b,c),this.config.noTextarea?this.editableArea=b:this.textarea=this.parent.textarea,this.config.contentEditableMode?this._initContentEditableArea():this._initSandbox()},clear:function(){this.element.innerHTML=c.displaysCaretInEmptyContentEditableCorrectly()?"":this.CARET_HACK},getValue:function(b,c){var d=this.isEmpty()?"":a.quirks.getCorrectInnerHTML(this.element);return b!==!1&&(d=this.parent.parse(d,c===!1?!1:!0)),d},setValue:function(a,b){b&&(a=this.parent.parse(a));try{this.element.innerHTML=a}catch(c){this.element.innerText=a}},cleanUp:function(){this.parent.parse(this.element)},show:function(){this.editableArea.style.display=this._displayStyle||"",this.config.noTextarea||this.textarea.element.disabled||(this.disable(),this.enable())},hide:function(){this._displayStyle=b.getStyle("display").from(this.editableArea),"none"===this._displayStyle&&(this._displayStyle=null),this.editableArea.style.display="none"},disable:function(){this.parent.fire("disable:composer"),this.element.removeAttribute("contentEditable")},enable:function(){this.parent.fire("enable:composer"),this.element.setAttribute("contentEditable","true")},focus:function(b){a.browser.doesAsyncFocus()&&this.hasPlaceholderSet()&&this.clear(),this.base();var c=this.element.lastChild;b&&c&&this.selection&&("BR"===c.nodeName?this.selection.setBefore(this.element.lastChild):this.selection.setAfter(this.element.lastChild))},getTextContent:function(){return b.getTextContent(this.element)},hasPlaceholderSet:function(){return this.getTextContent()==(this.config.noTextarea?this.editableArea.getAttribute("data-placeholder"):this.textarea.element.getAttribute("placeholder"))&&this.placeholderSet},isEmpty:function(){var a=this.element.innerHTML.toLowerCase();return/^(\s|<br>|<\/br>|<p>|<\/p>)*$/i.test(a)||""===a||"<br>"===a||"<p></p>"===a||"<p><br></p>"===a||this.hasPlaceholderSet()},_initContentEditableArea:function(){var a=this;this.config.noTextarea?this.sandbox=new b.ContentEditableArea(function(){a._create()},{},this.editableArea):(this.sandbox=new b.ContentEditableArea(function(){a._create()}),this.editableArea=this.sandbox.getContentEditable(),b.insert(this.editableArea).after(this.textarea.element),this._createWysiwygFormField())},_initSandbox:function(){var a=this;this.sandbox=new b.Sandbox(function(){a._create()},{stylesheets:this.config.stylesheets}),this.editableArea=this.sandbox.getIframe();var c=this.textarea.element;b.insert(this.editableArea).after(c),this._createWysiwygFormField()},_createWysiwygFormField:function(){if(this.textarea.element.form){var a=document.createElement("input");a.type="hidden",a.name="_wysihtml5_mode",a.value=1,b.insert(a).after(this.textarea.element)}},_create:function(){var d=this;this.doc=this.sandbox.getDocument(),this.element=this.config.contentEditableMode?this.sandbox.getContentEditable():this.doc.body,this.config.noTextarea?this.cleanUp():(this.textarea=this.parent.textarea,this.element.innerHTML=this.textarea.getValue(!0,!1)),this.selection=new a.Selection(this.parent,this.element,this.config.uneditableContainerClassname),this.commands=new a.Commands(this.parent),this.config.noTextarea||b.copyAttributes(["className","spellcheck","title","lang","dir","accessKey"]).from(this.textarea.element).to(this.element),b.addClass(this.element,this.config.composerClassName),this.config.style&&!this.config.contentEditableMode&&this.style(),this.observe();var e=this.config.name;e&&(b.addClass(this.element,e),this.config.contentEditableMode||b.addClass(this.editableArea,e)),this.enable(),!this.config.noTextarea&&this.textarea.element.disabled&&this.disable();var f="string"==typeof this.config.placeholder?this.config.placeholder:this.config.noTextarea?this.editableArea.getAttribute("data-placeholder"):this.textarea.element.getAttribute("placeholder");f&&b.simulatePlaceholder(this.parent,this,f),this.commands.exec("styleWithCSS",!1),this._initAutoLinking(),this._initObjectResizing(),this._initUndoManager(),this._initLineBreaking(),this.config.noTextarea||!this.textarea.element.hasAttribute("autofocus")&&document.querySelector(":focus")!=this.textarea.element||c.isIos()||setTimeout(function(){d.focus(!0)},100),c.clearsContentEditableCorrectly()||a.quirks.ensureProperClearing(this),this.initSync&&this.config.sync&&this.initSync(),this.config.noTextarea||this.textarea.hide(),this.parent.fire("beforeload").fire("load")},_initAutoLinking:function(){var d=this,e=c.canDisableAutoLinking(),f=c.doesAutoLinkingInContentEditable();if(e&&this.commands.exec("autoUrlDetect",!1),this.config.autoLink){(!f||f&&e)&&(this.parent.on("newword:composer",function(){if(b.getTextContent(d.element).match(b.autoLink.URL_REG_EXP)){for(var c=d.selection.getSelectedNode(),e=d.element.querySelectorAll("."+d.config.uneditableContainerClassname),f=!1,g=e.length;g--;)a.dom.contains(e[g],c)&&(f=!0);f||b.autoLink(c,[d.config.uneditableContainerClassname])}}),b.observe(this.element,"blur",function(){b.autoLink(d.element,[d.config.uneditableContainerClassname])}));var g=this.sandbox.getDocument().getElementsByTagName("a"),h=b.autoLink.URL_REG_EXP,i=function(c){var d=a.lang.string(b.getTextContent(c)).trim();return"www."===d.substr(0,4)&&(d="http://"+d),d};b.observe(this.element,"keydown",function(a){if(g.length){var c,e=d.selection.getSelectedNode(a.target.ownerDocument),f=b.getParentElement(e,{nodeName:"A"},4);f&&(c=i(f),setTimeout(function(){var a=i(f);a!==c&&a.match(h)&&f.setAttribute("href",a)},0))}})}},_initObjectResizing:function(){if(this.commands.exec("enableObjectResizing",!0),c.supportsEvent("resizeend")){var d=["width","height"],e=d.length,f=this.element;b.observe(f,"resizeend",function(b){var c,g=b.target||b.srcElement,h=g.style,i=0;if("IMG"===g.nodeName){for(;e>i;i++)c=d[i],h[c]&&(g.setAttribute(c,parseInt(h[c],10)),h[c]="");a.quirks.redraw(f)}})}},_initUndoManager:function(){this.undoManager=new a.UndoManager(this.parent)},_initLineBreaking:function(){function d(a){var c=b.getParentElement(a,{nodeName:["P","DIV"]},2);c&&b.contains(e.element,c)&&e.selection.executeAndRestore(function(){e.config.useLineBreaks?b.replaceWithChildNodes(c):"P"!==c.nodeName&&b.renameElement(c,"p")})}var e=this,f=["LI","P","H1","H2","H3","H4","H5","H6"],g=["UL","OL","MENU"];this.config.useLineBreaks||b.observe(this.element,["focus","keydown"],function(){if(e.isEmpty()){var a=e.doc.createElement("P");
+e.element.innerHTML="",e.element.appendChild(a),c.displaysCaretInEmptyContentEditableCorrectly()?e.selection.selectNode(a,!0):(a.innerHTML="<br>",e.selection.setBefore(a.firstChild))}}),b.observe(this.element,"keydown",function(c){var h=c.keyCode;if(!c.shiftKey&&(h===a.ENTER_KEY||h===a.BACKSPACE_KEY)){var i=b.getParentElement(e.selection.getSelectedNode(),{nodeName:f},4);return i?void setTimeout(function(){var c,f=e.selection.getSelectedNode();if("LI"===i.nodeName){if(!f)return;c=b.getParentElement(f,{nodeName:g},2),c||d(f)}h===a.ENTER_KEY&&i.nodeName.match(/^H[1-6]$/)&&d(f)},0):void(e.config.useLineBreaks&&h===a.ENTER_KEY&&!a.browser.insertsLineBreaksOnReturn()&&(c.preventDefault(),e.commands.exec("insertLineBreak")))}})}})}(wysihtml5),function(a){var b=a.dom,c=document,d=window,e=c.createElement("div"),f=["background-color","color","cursor","font-family","font-size","font-style","font-variant","font-weight","line-height","letter-spacing","text-align","text-decoration","text-indent","text-rendering","word-break","word-wrap","word-spacing"],g=["background-color","border-collapse","border-bottom-color","border-bottom-style","border-bottom-width","border-left-color","border-left-style","border-left-width","border-right-color","border-right-style","border-right-width","border-top-color","border-top-style","border-top-width","clear","display","float","margin-bottom","margin-left","margin-right","margin-top","outline-color","outline-offset","outline-width","outline-style","padding-left","padding-right","padding-top","padding-bottom","position","top","left","right","bottom","z-index","vertical-align","text-align","-webkit-box-sizing","-moz-box-sizing","-ms-box-sizing","box-sizing","-webkit-box-shadow","-moz-box-shadow","-ms-box-shadow","box-shadow","-webkit-border-top-right-radius","-moz-border-radius-topright","border-top-right-radius","-webkit-border-bottom-right-radius","-moz-border-radius-bottomright","border-bottom-right-radius","-webkit-border-bottom-left-radius","-moz-border-radius-bottomleft","border-bottom-left-radius","-webkit-border-top-left-radius","-moz-border-radius-topleft","border-top-left-radius","width","height"],h=["html { height: 100%; }","body { height: 100%; padding: 1px 0 0 0; margin: -1px 0 0 0; }","body > p:first-child { margin-top: 0; }","._wysihtml5-temp { display: none; }",a.browser.isGecko?"body.placeholder { color: graytext !important; }":"body.placeholder { color: #a9a9a9 !important; }","img:-moz-broken { -moz-force-broken-image-icon: 1; height: 24px; width: 24px; }"],i=function(a){if(a.setActive)try{a.setActive()}catch(e){}else{var f=a.style,g=c.documentElement.scrollTop||c.body.scrollTop,h=c.documentElement.scrollLeft||c.body.scrollLeft,i={position:f.position,top:f.top,left:f.left,WebkitUserSelect:f.WebkitUserSelect};b.setStyles({position:"absolute",top:"-99999px",left:"-99999px",WebkitUserSelect:"none"}).on(a),a.focus(),b.setStyles(i).on(a),d.scrollTo&&d.scrollTo(h,g)}};a.views.Composer.prototype.style=function(){var d,j=this,k=c.querySelector(":focus"),l=this.textarea.element,m=l.hasAttribute("placeholder"),n=m&&l.getAttribute("placeholder"),o=l.style.display,p=l.disabled;this.focusStylesHost=e.cloneNode(!1),this.blurStylesHost=e.cloneNode(!1),this.disabledStylesHost=e.cloneNode(!1),m&&l.removeAttribute("placeholder"),l===k&&l.blur(),l.disabled=!1,l.style.display=d="none",(l.getAttribute("rows")&&"auto"===b.getStyle("height").from(l)||l.getAttribute("cols")&&"auto"===b.getStyle("width").from(l))&&(l.style.display=d=o),b.copyStyles(g).from(l).to(this.editableArea).andTo(this.blurStylesHost),b.copyStyles(f).from(l).to(this.element).andTo(this.blurStylesHost),b.insertCSS(h).into(this.element.ownerDocument),l.disabled=!0,b.copyStyles(g).from(l).to(this.disabledStylesHost),b.copyStyles(f).from(l).to(this.disabledStylesHost),l.disabled=p,l.style.display=o,i(l),l.style.display=d,b.copyStyles(g).from(l).to(this.focusStylesHost),b.copyStyles(f).from(l).to(this.focusStylesHost),l.style.display=o,b.copyStyles(["display"]).from(l).to(this.editableArea);var q=a.lang.array(g).without(["display"]);return k?k.focus():l.blur(),m&&l.setAttribute("placeholder",n),this.parent.on("focus:composer",function(){b.copyStyles(q).from(j.focusStylesHost).to(j.editableArea),b.copyStyles(f).from(j.focusStylesHost).to(j.element)}),this.parent.on("blur:composer",function(){b.copyStyles(q).from(j.blurStylesHost).to(j.editableArea),b.copyStyles(f).from(j.blurStylesHost).to(j.element)}),this.parent.observe("disable:composer",function(){b.copyStyles(q).from(j.disabledStylesHost).to(j.editableArea),b.copyStyles(f).from(j.disabledStylesHost).to(j.element)}),this.parent.observe("enable:composer",function(){b.copyStyles(q).from(j.blurStylesHost).to(j.editableArea),b.copyStyles(f).from(j.blurStylesHost).to(j.element)}),this}}(wysihtml5),function(a){var b=a.dom,c=a.browser,d={66:"bold",73:"italic",85:"underline"},e=function(a,b,c){for(var d=0,e=b.length;e>d;d++)a.addEventListener(b[d],c,!1)},f=function(a,b,c){for(var d=0,e=b.length;e>d;d++)a.removeEventListener(b[d],c,!1)},g=function(a,b){{var c=b.selection;b.element}if(c.isCollapsed())if(c.caretIsInTheBeginnig("LI"))a.preventDefault(),b.commands.exec("outdentList");else if(c.caretIsInTheBeginnig())a.preventDefault();else{if(c.caretIsFirstInSelection()&&c.getPreviousNode()&&c.getPreviousNode().nodeName&&/^H\d$/gi.test(c.getPreviousNode().nodeName)){var d=c.getPreviousNode();if(a.preventDefault(),/^\s*$/.test(d.textContent||d.innerText))d.parentNode.removeChild(d);else{var e=d.ownerDocument.createRange();e.selectNodeContents(d),e.collapse(!1),c.setSelection(e)}}var f=c.caretIsBeforeUneditable();if(f){a.preventDefault();try{var g=new CustomEvent("wysihtml5:uneditable:delete");f.dispatchEvent(g)}catch(h){}f.parentNode.removeChild(f)}}else c.containsUneditable()&&(a.preventDefault(),c.deleteContents())},h=function(a){if(a.selection.isCollapsed()){if(a.selection.caretIsInTheBeginnig("LI")&&a.commands.exec("indentList"))return}else a.selection.deleteContents();a.commands.exec("insertHTML"," ")},i=function(){this.domNodeRemovedInterval&&clearInterval(domNodeRemovedInterval),this.parent.fire("destroy:composer")},j=function(){this.parent.fire("beforeinteraction").fire("beforeinteraction:composer"),setTimeout(function(){this.parent.fire("interaction").fire("interaction:composer")}.bind(this),0)},k=function(a){this.parent.fire("focus",a).fire("focus:composer",a),setTimeout(function(){this.focusState=this.getValue(!1,!1)}.bind(this),0)},l=function(a){if(this.focusState!==this.getValue(!1,!1)){var b=a;"function"==typeof Object.create&&(b=Object.create(a,{type:{value:"change"}})),this.parent.fire("change",b).fire("change:composer",b)}this.parent.fire("blur",a).fire("blur:composer",a)},m=function(a){this.parent.fire(a.type,a).fire(a.type+":composer",a),"paste"===a.type&&setTimeout(function(){this.parent.fire("newword:composer")}.bind(this),0)},n=function(a){this.config.copyedFromMarking&&(a.clipboardData&&(a.clipboardData.setData("text/html",this.config.copyedFromMarking+this.selection.getHtml()),a.clipboardData.setData("text/plain",this.selection.getPlainText()),a.preventDefault()),this.parent.fire(a.type,a).fire(a.type+":composer",a))},o=function(b){var c=b.keyCode;(c===a.SPACE_KEY||c===a.ENTER_KEY)&&this.parent.fire("newword:composer")},p=function(b){if(!c.canSelectImagesInContentEditable()){var d=b.target,e=this.element.querySelectorAll("img"),f=this.element.querySelectorAll("."+this.config.uneditableContainerClassname+" img"),g=a.lang.array(e).without(f);"IMG"===d.nodeName&&a.lang.array(g).contains(d)&&this.selection.selectNode(d)}},q=function(a){var b,c={IMG:"Image: ",A:"Link: "},d=a.target,e=d.nodeName;("A"===e||"IMG"===e)&&(d.hasAttribute("title")||(b=c[e]+(d.getAttribute("href")||d.getAttribute("src")),d.setAttribute("title",b)))},r=function(b){if(this.config.uneditableContainerClassname){var c=a.dom.getParentElement(b.target,{className:this.config.uneditableContainerClassname},!1,this.element);c&&this.selection.setAfter(c)}},s=function(){c.canSelectImagesInContentEditable()||setTimeout(function(){this.selection.getSelection().removeAllRanges()}.bind(this),0)},t=function(b){var c,e,f=b.keyCode,i=d[f];(b.ctrlKey||b.metaKey)&&!b.altKey&&i&&(this.commands.exec(i),b.preventDefault()),f===a.BACKSPACE_KEY&&g(b,this),(f===a.BACKSPACE_KEY||f===a.DELETE_KEY)&&(c=this.selection.getSelectedNode(!0),c&&"IMG"===c.nodeName&&(b.preventDefault(),e=c.parentNode,e.removeChild(c),"A"!==e.nodeName||e.firstChild||e.parentNode.removeChild(e),setTimeout(function(){a.quirks.redraw(element)},0))),this.config.handleTabKey&&f===a.TAB_KEY&&(b.preventDefault(),h(this,element))},u=function(){setTimeout(function(){this.doc.querySelector(":focus")!==this.element&&this.focus()}.bind(this),0)},v=function(){setTimeout(function(){this.selection.getSelection().removeAllRanges()}.bind(this),0)},w=function(){var b=function(){this.doc.execCommand("enableObjectResizing",!1,"false"),this.doc.execCommand("enableInlineTableEditing",!1,"false")},c=function(){b.call(this),f(this.sandbox.getIframe(),["focus","mouseup","mouseover"],c)}.bind(this);this.doc.execCommand&&a.browser.supportsCommand(this.doc,"enableObjectResizing")&&a.browser.supportsCommand(this.doc,"enableInlineTableEditing")&&(this.sandbox.getIframe?e(this.sandbox.getIframe(),["focus","mouseup","mouseover"],c):setTimeout(function(){b.call(this)}.bind(this),0)),this.tableSelection=a.quirks.tableCellsSelection(this.element,this.parent)};a.views.Composer.prototype.observe=function(){var a=this.sandbox.getIframe?this.sandbox.getIframe():this.sandbox.getContentEditable(),d=(this.element,c.supportsEventsInIframeCorrectly()||this.sandbox.getContentEditable?this.element:this.sandbox.getWindow());this.focusState=this.getValue(!1,!1),a.addEventListener(["DOMNodeRemoved"],i.bind(this),!1),c.supportsMutationEvents()||(this.domNodeRemovedInterval=setInterval(function(){b.contains(document.documentElement,a)||i.call(this)},250)),this.config.handleTables&&w.call(this),e(d,["drop","paste","mouseup","focus","keyup"],j.bind(this)),d.addEventListener("focus",k.bind(this),!1),d.addEventListener("blur",l.bind(this),!1),e(this.element,["drop","paste","beforepaste"],m.bind(this),!1),this.element.addEventListener("copy",n.bind(this),!1),this.element.addEventListener("mousedown",p.bind(this),!1),this.element.addEventListener("mouseover",q.bind(this),!1),this.element.addEventListener("click",r.bind(this),!1),this.element.addEventListener("drop",s.bind(this),!1),this.element.addEventListener("keyup",o.bind(this),!1),this.element.addEventListener("keydown",t.bind(this),!1),this.element.addEventListener("dragenter",function(){this.parent.fire("unset_placeholder")}.bind(this),!1),!this.config.contentEditableMode&&c.hasIframeFocusIssue()&&(a.addEventListener("focus",u.bind(this),!1),a.addEventListener("blur",v.bind(this),!1))}}(wysihtml5),function(a){var b=400;a.views.Synchronizer=Base.extend({constructor:function(a,b,c){this.editor=a,this.textarea=b,this.composer=c,this._observe()},fromComposerToTextarea:function(b){this.textarea.setValue(a.lang.string(this.composer.getValue(!1,!1)).trim(),b)},fromTextareaToComposer:function(a){var b=this.textarea.getValue(!1,!1);b?this.composer.setValue(b,a):(this.composer.clear(),this.editor.fire("set_placeholder"))},sync:function(a){"textarea"===this.editor.currentView.name?this.fromTextareaToComposer(a):this.fromComposerToTextarea(a)},_observe:function(){var c,d=this,e=this.textarea.element.form,f=function(){c=setInterval(function(){d.fromComposerToTextarea()},b)},g=function(){clearInterval(c),c=null};f(),e&&(a.dom.observe(e,"submit",function(){d.sync(!0)}),a.dom.observe(e,"reset",function(){setTimeout(function(){d.fromTextareaToComposer()},0)})),this.editor.on("change_view",function(a){"composer"!==a||c?"textarea"===a&&(d.fromComposerToTextarea(!0),g()):(d.fromTextareaToComposer(!0),f())}),this.editor.on("destroy:composer",g)}})}(wysihtml5),wysihtml5.views.Textarea=wysihtml5.views.View.extend({name:"textarea",constructor:function(a,b,c){this.base(a,b,c),this._observe()},clear:function(){this.element.value=""},getValue:function(a){var b=this.isEmpty()?"":this.element.value;return a!==!1&&(b=this.parent.parse(b)),b},setValue:function(a,b){b&&(a=this.parent.parse(a)),this.element.value=a},cleanUp:function(){var a=this.parent.parse(this.element.value);this.element.value=a},hasPlaceholderSet:function(){var a=wysihtml5.browser.supportsPlaceholderAttributeOn(this.element),b=this.element.getAttribute("placeholder")||null,c=this.element.value,d=!c;return a&&d||c===b},isEmpty:function(){return!wysihtml5.lang.string(this.element.value).trim()||this.hasPlaceholderSet()},_observe:function(){var a=this.element,b=this.parent,c={focusin:"focus",focusout:"blur"},d=wysihtml5.browser.supportsEvent("focusin")?["focusin","focusout","change"]:["focus","blur","change"];b.on("beforeload",function(){wysihtml5.dom.observe(a,d,function(a){var d=c[a.type]||a.type;b.fire(d).fire(d+":textarea")}),wysihtml5.dom.observe(a,["paste","drop"],function(){setTimeout(function(){b.fire("paste").fire("paste:textarea")},0)})})}}),function(a){var b,c={name:b,style:!0,toolbar:b,showToolbarAfterInit:!0,autoLink:!0,handleTables:!0,handleTabKey:!0,parserRules:{tags:{br:{},span:{},div:{},p:{}},classes:{}},pasteParserRulesets:null,parser:a.dom.parse,composerClassName:"wysihtml5-editor",bodyClassName:"wysihtml5-supported",useLineBreaks:!0,stylesheets:[],placeholderText:b,supportTouchDevices:!0,cleanUp:!0,contentEditableMode:!1,uneditableContainerClassname:"wysihtml5-uneditable-container",copyedFromMarking:'<meta name="copied-from" content="wysihtml5">'};a.Editor=a.lang.Dispatcher.extend({constructor:function(b,d){if(this.editableElement="string"==typeof b?document.getElementById(b):b,this.config=a.lang.object({}).merge(c).merge(d).get(),this._isCompatible=a.browser.supported(),"textarea"!=this.editableElement.nodeName.toLowerCase()&&(this.config.contentEditableMode=!0,this.config.noTextarea=!0),this.config.noTextarea||(this.textarea=new a.views.Textarea(this,this.editableElement,this.config),this.currentView=this.textarea),!this._isCompatible||!this.config.supportTouchDevices&&a.browser.isTouchDevice()){var e=this;return void setTimeout(function(){e.fire("beforeload").fire("load")},0)}a.dom.addClass(document.body,this.config.bodyClassName),this.composer=new a.views.Composer(this,this.editableElement,this.config),this.currentView=this.composer,"function"==typeof this.config.parser&&this._initParser(),this.on("beforeload",this.handleBeforeLoad)},handleBeforeLoad:function(){this.config.noTextarea||(this.synchronizer=new a.views.Synchronizer(this,this.textarea,this.composer)),this.config.toolbar&&(this.toolbar=new a.toolbar.Toolbar(this,this.config.toolbar,this.config.showToolbarAfterInit))},isCompatible:function(){return this._isCompatible},clear:function(){return this.currentView.clear(),this},getValue:function(a,b){return this.currentView.getValue(a,b)},setValue:function(a,b){return this.fire("unset_placeholder"),a?(this.currentView.setValue(a,b),this):this.clear()},cleanUp:function(){this.currentView.cleanUp()},focus:function(a){return this.currentView.focus(a),this},disable:function(){return this.currentView.disable(),this},enable:function(){return this.currentView.enable(),this},isEmpty:function(){return this.currentView.isEmpty()},hasPlaceholderSet:function(){return this.currentView.hasPlaceholderSet()},parse:function(b,c){var d=this.config.contentEditableMode?document:this.composer?this.composer.sandbox.getDocument():null,e=this.config.parser(b,{rules:this.config.parserRules,cleanUp:this.config.cleanUp,context:d,uneditableClass:this.config.uneditableContainerClassname,clearInternals:c});return"object"==typeof b&&a.quirks.redraw(b),e},_initParser:function(){var b,c=this;a.browser.supportsModenPaste()?this.on("paste:composer",function(d){d.preventDefault(),b=a.dom.getPastedHtml(d),b&&c._cleanAndPaste(b)}):this.on("beforepaste:composer",function(b){b.preventDefault(),a.dom.getPastedHtmlWithDiv(c.composer,function(a){a&&c._cleanAndPaste(a)})})},_cleanAndPaste:function(b){var c=a.quirks.cleanPastedHTML(b,{referenceNode:this.composer.element,rules:this.config.pasteParserRulesets||[{set:this.config.parserRules}],uneditableClass:this.config.uneditableContainerClassname});this.composer.selection.deleteContents(),this.composer.selection.insertHTML(c)}})}(wysihtml5),function(a){var b=a.dom,c="wysihtml5-command-dialog-opened",d="input, select, textarea",e="[data-wysihtml5-dialog-field]",f="data-wysihtml5-dialog-field";a.toolbar.Dialog=a.lang.Dispatcher.extend({constructor:function(a,b){this.link=a,this.container=b},_observe:function(){if(!this._observed){var e=this,f=function(a){var b=e._serialize();b==e.elementToChange?e.fire("edit",b):e.fire("save",b),e.hide(),a.preventDefault(),a.stopPropagation()};b.observe(e.link,"click",function(){b.hasClass(e.link,c)&&setTimeout(function(){e.hide()},0)}),b.observe(this.container,"keydown",function(b){var c=b.keyCode;c===a.ENTER_KEY&&f(b),c===a.ESCAPE_KEY&&(e.fire("cancel"),e.hide())}),b.delegate(this.container,"[data-wysihtml5-dialog-action=save]","click",f),b.delegate(this.container,"[data-wysihtml5-dialog-action=cancel]","click",function(a){e.fire("cancel"),e.hide(),a.preventDefault(),a.stopPropagation()});for(var g=this.container.querySelectorAll(d),h=0,i=g.length,j=function(){clearInterval(e.interval)};i>h;h++)b.observe(g[h],"change",j);this._observed=!0}},_serialize:function(){for(var a=this.elementToChange||{},b=this.container.querySelectorAll(e),c=b.length,d=0;c>d;d++)a[b[d].getAttribute(f)]=b[d].value;return a},_interpolate:function(a){for(var b,c,d,g=document.querySelector(":focus"),h=this.container.querySelectorAll(e),i=h.length,j=0;i>j;j++)b=h[j],b!==g&&(a&&"hidden"===b.type||(c=b.getAttribute(f),d=this.elementToChange&&"boolean"!=typeof this.elementToChange?this.elementToChange.getAttribute(c)||"":b.defaultValue,b.value=d))},show:function(a){if(!b.hasClass(this.link,c)){var e=this,f=this.container.querySelector(d);if(this.elementToChange=a,this._observe(),this._interpolate(),a&&(this.interval=setInterval(function(){e._interpolate(!0)},500)),b.addClass(this.link,c),this.container.style.display="",this.fire("show"),f&&!a)try{f.focus()}catch(g){}}},hide:function(){clearInterval(this.interval),this.elementToChange=null,b.removeClass(this.link,c),this.container.style.display="none",this.fire("hide")}})}(wysihtml5),function(a){var b=a.dom,c={position:"relative"},d={left:0,margin:0,opacity:0,overflow:"hidden",padding:0,position:"absolute",top:0,zIndex:1},e={cursor:"inherit",fontSize:"50px",height:"50px",marginTop:"-25px",outline:0,padding:0,position:"absolute",right:"-4px",top:"50%"},f={"x-webkit-speech":"",speech:""};a.toolbar.Speech=function(g,h){var i=document.createElement("input");if(!a.browser.supportsSpeechApiOn(i))return void(h.style.display="none");var j=g.editor.textarea.element.getAttribute("lang");j&&(f.lang=j);var k=document.createElement("div");a.lang.object(d).merge({width:h.offsetWidth+"px",height:h.offsetHeight+"px"}),b.insert(i).into(k),b.insert(k).into(h),b.setStyles(e).on(i),b.setAttributes(f).on(i),b.setStyles(d).on(k),b.setStyles(c).on(h);var l="onwebkitspeechchange"in i?"webkitspeechchange":"speechchange";b.observe(i,l,function(){g.execCommand("insertText",i.value),i.value=""}),b.observe(i,"click",function(a){b.hasClass(h,"wysihtml5-command-disabled")&&a.preventDefault(),a.stopPropagation()})}}(wysihtml5),function(a){var b="wysihtml5-command-disabled",c="wysihtml5-commands-disabled",d="wysihtml5-command-active",e="wysihtml5-action-active",f=a.dom;a.toolbar.Toolbar=Base.extend({constructor:function(f,g,h){this.editor=f,this.container="string"==typeof g?document.getElementById(g):g,this.composer=f.composer,this._getLinks("command"),this._getLinks("action"),this._observe(),h&&this.show(),null!=f.config.classNameCommandDisabled&&(b=f.config.classNameCommandDisabled),null!=f.config.classNameCommandsDisabled&&(c=f.config.classNameCommandsDisabled),null!=f.config.classNameCommandActive&&(d=f.config.classNameCommandActive),null!=f.config.classNameActionActive&&(e=f.config.classNameActionActive);for(var i=this.container.querySelectorAll("[data-wysihtml5-command=insertSpeech]"),j=i.length,k=0;j>k;k++)new a.toolbar.Speech(this,i[k])},_getLinks:function(b){for(var c,d,e,f,g,h=this[b+"Links"]=a.lang.array(this.container.querySelectorAll("[data-wysihtml5-"+b+"]")).get(),i=h.length,j=0,k=this[b+"Mapping"]={};i>j;j++)c=h[j],e=c.getAttribute("data-wysihtml5-"+b),f=c.getAttribute("data-wysihtml5-"+b+"-value"),d=this.container.querySelector("[data-wysihtml5-"+b+"-group='"+e+"']"),g=this._getDialog(c,e),k[e+":"+f]={link:c,group:d,name:e,value:f,dialog:g,state:!1}},_getDialog:function(b,c){var d,e,f=this,g=this.container.querySelector("[data-wysihtml5-dialog='"+c+"']");return g&&(d=a.toolbar["Dialog_"+c]?new a.toolbar["Dialog_"+c](b,g):new a.toolbar.Dialog(b,g),d.on("show",function(){e=f.composer.selection.getBookmark(),f.editor.fire("show:dialog",{command:c,dialogContainer:g,commandLink:b})}),d.on("save",function(a){e&&f.composer.selection.setBookmark(e),f._execCommand(c,a),f.editor.fire("save:dialog",{command:c,dialogContainer:g,commandLink:b})}),d.on("cancel",function(){f.editor.focus(!1),f.editor.fire("cancel:dialog",{command:c,dialogContainer:g,commandLink:b})})),d},execCommand:function(a,b){if(!this.commandsDisabled){var c=this.commandMapping[a+":"+b];c&&c.dialog&&!c.state?c.dialog.show():this._execCommand(a,b)}},_execCommand:function(a,b){this.editor.focus(!1),this.composer.commands.exec(a,b),this._updateLinkStates()},execAction:function(a){var b=this.editor;"change_view"===a&&b.textarea&&(b.currentView===b.textarea?b.fire("change_view","composer"):b.fire("change_view","textarea")),"showSource"==a&&b.fire("showSource")},_observe:function(){for(var a=this,b=this.editor,d=this.container,e=this.commandLinks.concat(this.actionLinks),g=e.length,h=0;g>h;h++)"A"===e[h].nodeName?f.setAttributes({href:"javascript:;",unselectable:"on"}).on(e[h]):f.setAttributes({unselectable:"on"}).on(e[h]);f.delegate(d,"[data-wysihtml5-command], [data-wysihtml5-action]","mousedown",function(a){a.preventDefault()}),f.delegate(d,"[data-wysihtml5-command]","click",function(b){var c=this,d=c.getAttribute("data-wysihtml5-command"),e=c.getAttribute("data-wysihtml5-command-value");a.execCommand(d,e),b.preventDefault()}),f.delegate(d,"[data-wysihtml5-action]","click",function(b){var c=this.getAttribute("data-wysihtml5-action");a.execAction(c),b.preventDefault()}),b.on("interaction:composer",function(){a._updateLinkStates()}),b.on("focus:composer",function(){a.bookmark=null}),this.editor.config.handleTables&&(b.on("tableselect:composer",function(){a.container.querySelectorAll('[data-wysihtml5-hiddentools="table"]')[0].style.display=""}),b.on("tableunselect:composer",function(){a.container.querySelectorAll('[data-wysihtml5-hiddentools="table"]')[0].style.display="none"})),b.on("change_view",function(e){b.textarea&&setTimeout(function(){a.commandsDisabled="composer"!==e,a._updateLinkStates(),a.commandsDisabled?f.addClass(d,c):f.removeClass(d,c)},0)})},_updateLinkStates:function(){var c,g,h,i,j=this.commandMapping,k=this.actionMapping;for(c in j)i=j[c],this.commandsDisabled?(g=!1,f.removeClass(i.link,d),i.group&&f.removeClass(i.group,d),i.dialog&&i.dialog.hide()):(g=this.composer.commands.state(i.name,i.value),f.removeClass(i.link,b),i.group&&f.removeClass(i.group,b)),i.state!==g&&(i.state=g,g?(f.addClass(i.link,d),i.group&&f.addClass(i.group,d),i.dialog&&("object"==typeof g||a.lang.object(g).isArray()?(!i.dialog.multiselect&&a.lang.object(g).isArray()&&(g=1===g.length?g[0]:!0,i.state=g),i.dialog.show(g)):i.dialog.hide())):(f.removeClass(i.link,d),i.group&&f.removeClass(i.group,d),i.dialog&&i.dialog.hide()));for(c in k)h=k[c],"change_view"===h.name&&(h.state=this.editor.currentView===this.editor.textarea,h.state?f.addClass(h.link,e):f.removeClass(h.link,e))},show:function(){this.container.style.display=""},hide:function(){this.container.style.display="none"}})}(wysihtml5),function(a){a.toolbar.Dialog_createTable=a.toolbar.Dialog.extend({show:function(a){this.base(a)}})}(wysihtml5),function(a){var b=(a.dom,"[data-wysihtml5-dialog-field]"),c="data-wysihtml5-dialog-field";a.toolbar.Dialog_foreColorStyle=a.toolbar.Dialog.extend({multiselect:!0,_serialize:function(){for(var a={},d=this.container.querySelectorAll(b),e=d.length,f=0;e>f;f++)a[d[f].getAttribute(c)]=d[f].value;return a},_interpolate:function(d){for(var e,f=document.querySelector(":focus"),g=this.container.querySelectorAll(b),h=g.length,i=0,j=this.elementToChange?a.lang.object(this.elementToChange).isArray()?this.elementToChange[0]:this.elementToChange:null,k=j?j.getAttribute("style"):null,l=k?a.quirks.styleParser.parseColor(k,"color"):null;h>i;i++)e=g[i],e!==f&&(d&&"hidden"===e.type||"color"===e.getAttribute(c)&&(e.value=l?l[3]&&1!=l[3]?"rgba("+l[0]+","+l[1]+","+l[2]+","+l[3]+");":"rgb("+l[0]+","+l[1]+","+l[2]+");":"rgb(0,0,0);"))}})}(wysihtml5),function(a){a.dom;a.toolbar.Dialog_fontSizeStyle=a.toolbar.Dialog.extend({multiselect:!0,_serialize:function(){return{size:this.container.querySelector('[data-wysihtml5-dialog-field="size"]').value}},_interpolate:function(){var b=document.querySelector(":focus"),c=this.container.querySelector("[data-wysihtml5-dialog-field='size']"),d=this.elementToChange?a.lang.object(this.elementToChange).isArray()?this.elementToChange[0]:this.elementToChange:null,e=d?d.getAttribute("style"):null,f=e?a.quirks.styleParser.parseFontSize(e):null;c&&c!==b&&f&&!/^\s*$/.test(f)&&(c.value=f)}})}(wysihtml5);
+//# sourceMappingURL=wysihtml5x-toolbar.min.map
\ No newline at end of file
--- /dev/null
+{"version":3,"file":"wysihtml5x-toolbar.min.js","sources":["wysihtml5x-toolbar.js"],"names":["Event","prototype","preventDefault","this","returnValue","stopPropagation","cancelBubble","Element","addEventListener","eventListeners","type","listener","self","wrapper","e","target","srcElement","currentTarget","handleEvent","call","wrapper2","document","readyState","attachEvent","push","object","window","removeEventListener","counter","length","eventListener","detachEvent","splice","HTMLDocument","Window","Object","defineProperty","getOwnPropertyDescriptor","get","innerText","set","s","Array","isArray","arg","toString","Function","bind","oThis","TypeError","aArgs","slice","arguments","fToBind","fNOP","fBound","apply","concat","wysihtml5","version","commands","dom","quirks","toolbar","lang","selection","views","INVISIBLE_SPACE","INVISIBLE_SPACE_REG_EXP","EMPTY_FUNCTION","ELEMENT_NODE","TEXT_NODE","BACKSPACE_KEY","ENTER_KEY","ESCAPE_KEY","SPACE_KEY","TAB_KEY","DELETE_KEY","factory","root","define","amd","module","exports","rangy","isHostMethod","o","p","t","FUNCTION","OBJECT","isHostObject","isHostProperty","UNDEFINED","createMultiplePropertyTest","testFunc","props","i","isTextRange","range","areHostMethods","textRangeMethods","areHostProperties","textRangeProperties","getBody","doc","body","getElementsByTagName","consoleLog","msg","console","log","alertOrLog","shouldAlert","isBrowser","alert","fail","reason","api","initialized","supported","config","alertOnFail","warn","alertOnWarn","getErrorDesc","ex","message","description","String","init","testRange","implementsDomRange","implementsTextRange","createRange","domRangeMethods","domRangeProperties","nodeName","toLowerCase","createTextRange","features","errorMessage","moduleName","modules","Module","len","initListeners","shim","win","shimListeners","name","dependencies","initializer","createModule","initFunc","newModule","stack","RangePrototype","SelectionPrototype","areHostObjects","util","preferTextRange","autoInitialize","rangyAutoInitialize","extend","hasOwnProperty","obj","deep","createOptions","optionsParam","defaults","options","toArray","el","createElement","appendChild","childNodes","nodeType","arrayLike","arr","addListener","eventType","addInitListener","addShimListener","createMissingNativeApi","requiredModule","requiredModuleNames","Error","deprecationNotice","deprecated","replacement","createError","createCoreModule","rangePrototype","selectionPrototype","isHtmlNamespace","node","ns","namespaceURI","UNDEF","parentElement","parent","parentNode","getNodeIndex","previousSibling","getNodeLength","getCommonAncestor","node1","node2","n","ancestors","arrayContains","isAncestorOf","ancestor","descendant","selfIsAncestor","isOrIsAncestorOf","getClosestAncestorIn","isCharacterDataNode","isTextOrCommentNode","insertAfter","precedingNode","nextNode","nextSibling","insertBefore","splitDataNode","index","positionsToPreserve","newNode","cloneNode","deleteData","position","offset","getDocument","ownerDocument","getWindow","defaultView","parentWindow","getIframeDocument","iframeEl","contentDocument","contentWindow","getIframeWindow","isWindow","getContentDocument","methodName","tagName","getRootContainer","comparePoints","nodeA","offsetA","nodeB","offsetB","nodeC","childA","childB","firstChild","isBrokenNode","inspectNode","crashyTextNodes","data","idAttr","id","innerHTML","fragmentFromNodeChildren","child","fragment","createDocumentFragment","NodeIterator","_next","createIterator","DomPosition","DOMException","codeName","code","textNode","createTextNode","val","getComputedStyleProperty","getComputedStyle","propName","documentElement","currentStyle","_current","hasNext","next","detach","equals","pos","inspect","INDEX_SIZE_ERR","HIERARCHY_REQUEST_ERR","WRONG_DOCUMENT_ERR","NO_MODIFICATION_ALLOWED_ERR","NOT_FOUND_ERR","NOT_SUPPORTED_ERR","INVALID_STATE_ERR","INVALID_NODE_TYPE_ERR","isNonTextPartiallySelected","startContainer","endContainer","getRangeDocument","getBoundaryBeforeNode","getBoundaryAfterNode","insertNodeAtPosition","firstNodeInserted","rangesIntersect","rangeA","rangeB","touchingIsIntersecting","assertRangeValid","startComparison","startOffset","endOffset","endComparison","cloneSubtree","iterator","partiallySelected","subIterator","frag","isPartiallySelectedSubtree","getSubtreeIterator","iterateSubtree","rangeIterator","func","iteratorState","it","stop","subRangeIterator","deleteSubtree","remove","extractSubtree","getNodesInRange","nodeTypes","filter","regex","filterNodeTypes","filterExists","RegExp","join","nodes","RangeIterator","test","sc","ec","getName","clonePartiallySelectedTextNodes","collapsed","so","eo","commonAncestorContainer","isSingleCharacterDataNode","_first","_last","createAncestorFinder","assertNoDocTypeNotationEntityAncestor","allowSelf","getDocTypeNotationEntityAncestor","assertValidNodeType","invalidTypes","assertValidOffset","assertSameDocumentOrFragment","getDocumentOrFragmentContainer","assertNodeNotReadOnly","getReadonlyAncestor","assertNode","isOrphan","rootContainerNodeTypes","isValidOffset","isRangeValid","splitRangeBoundaries","startEndSame","setStartAndEnd","rangeToHtml","container","cloneContents","copyComparisonConstantsToObject","START_TO_START","s2s","START_TO_END","s2e","END_TO_END","e2e","END_TO_START","e2s","NODE_BEFORE","n_b","NODE_AFTER","n_a","NODE_BEFORE_AND_AFTER","n_b_a","NODE_INSIDE","n_i","copyComparisonConstants","constructor","createRangeContentRemover","remover","boundaryUpdater","boundary","reset","createPrototypeRange","createBeforeAfterNodeSetter","isBefore","isStart","beforeAfterNodeTypes","setRangeStart","setRangeEnd","F","setStart","setEnd","args","setBoundary","setStartBefore","setStartAfter","setEndBefore","setEndAfter","collapse","selectNodeContents","selectNode","start","end","extractContents","deleteContents","canSurroundContents","boundariesInvalid","splitBoundaries","splitBoundariesPreservingPositions","normalizeBoundaries","mergeForward","sibling","appendData","removeChild","mergeBackward","nodeLength","insertData","nodeIndex","normalizeStart","endNode","startNode","collapseToPoint","updateCollapsedAndCommonAncestor","updateBoundaries","Range","current","subRange","cloneRange","readonlyNodeTypes","insertableNodeTypes","surroundNodeTypes","styleEl","htmlParsingConforms","createContextualFragment","fragmentStr","rangeProperties","compareBoundaryPoints","how","prefixA","prefixB","insertNode","clone","surroundContents","content","hasChildNodes","lastChild","prop","textParts","compareNode","comparePoint","toHtml","intersectsNode","isPointInRange","intersectsRange","intersectsOrTouchesRange","intersection","intersectionRange","union","unionRange","containsNode","allowPartial","containsNodeContents","containsRange","containsNodeText","nodeRange","textNodes","getNodes","lastTextNode","pop","collapseBefore","collapseAfter","getBookmark","containerNode","preSelectionRange","moveToBookmark","bookmark","charIndex","nextCharIndex","nodeStack","foundStart","rangesEqual","isValid","r1","r2","DomRange","WrappedRange","WrappedTextRange","updateRangeProperties","nativeRange","updateNativeRange","startMoved","endMoved","nativeRangeDifferent","rangeProto","refresh","testTextNode","oppositeName","range2","createNativeRange","getTextRangeContainerElement","textRange","parentEl","duplicate","startEl","endEl","startEndContainer","textRangeIsCollapsed","compareEndPoints","getTextRangeBoundaryPosition","wholeRangeContainerElement","isCollapsed","startInfo","workingRange","containerElement","canHaveHTML","boundaryPosition","nodeInfo","workingNode","comparison","previousNode","boundaryNode","workingComparisonType","childNodeCount","moveToElementText","Math","floor","setEndPoint","tempRange","rangeLength","text","replace","moveStart","createBoundaryTextRange","boundaryParent","boundaryOffset","nodeIsDataNode","startBoundary","rangeContainerElement","rangeToTextRange","startRange","endRange","toTextRange","globalObj","f","createRangyRange","createIframeRange","createIframeRangyRange","isDirectionBackward","dir","WrappedSelection","getWinSelection","winParam","getSelection","getDocSelection","winSelectionIsBackward","sel","backward","anchorNode","anchorOffset","focusNode","focusOffset","updateAnchorAndFocusFromRange","anchorPrefix","focusPrefix","updateAnchorAndFocusFromNativeSelection","nativeSel","nativeSelection","updateEmptySelection","rangeCount","_ranges","getNativeRange","rangeContainsSingleElement","rangeNodes","getSingleElementFromRange","updateFromTextRange","wrappedRange","updateControlSelection","docSelection","controlRange","item","addRangeToControlSelection","rangeElement","newControlRange","createControlRange","add","select","deleteProperties","detached","actOnCachedSelection","action","cached","cachedRangySelections","createControlSelection","ranges","assertNodeInSameDocument","createStartOrEndSetter","getRangeAt","setSingleRange","isBackward","rangeInspects","anchor","focus","checkSelectionRanges","getNativeSelection","selectionIsCollapsed","BOOLEAN","NUMBER","CONTROL","implementsWinGetSelection","implementsDocSelection","useDocumentSelection","isSelectionValid","testSelection","selectionHasAnchorAndFocus","selectionHasExtend","selectionHasRangeCount","selectionSupportsMultipleRanges","collapsedNonEditableSelectionsSupported","addRangeBackwardToNative","addRange","originalSelectionRangeCount","selectionHasMultipleRanges","originalSelectionRanges","originalSelectionBackward","testEl","contentEditable","removeAllRanges","chromeMatch","navigator","appVersion","match","parseInt","testControlRange","implementsControlRange","getSelectionRangeAt","docSel","getIframeSelection","selProto","addRangeBackward","direction","previousRangeCount","clonedNativeRange","selectionIsBackward","setRanges","empty","refreshSelection","checkForChanges","oldRanges","oldAnchorNode","oldAnchorOffset","removeRangeManually","getAllRanges","removeRange","removed","isBackwards","rangeTexts","collapseToStart","collapseToEnd","selectAllChildren","deleteFromDocument","element","eachRange","callMethodOnEachRange","params","results","changeEachRange","rangeBookmarks","rangeBookmark","selRanges","rangeHtmls","getNativeTextRange","detachAll","Selection","docReady","loadHandler","require","gEBI","getElementById","insertRangeBoundaryMarker","atStart","markerEl","markerId","Date","random","boundaryRange","style","lineHeight","display","className","markerTextChar","setRangeBoundary","compareRanges","saveRange","startMarkerId","endMarkerId","restoreRange","rangeInfo","normalize","saveRanges","rangeInfos","sort","saveSelection","restored","restoreRanges","restoreSelection","savedSelection","preserveDirection","removeMarkerElement","removeMarkers","Base","_instance","_static","_prototyping","proto","base","klass","_constructing","forEach","implement","valueOf","source","value","method","previous","toSource","hidden","key","block","context","undefined","browser","iosVersion","userAgent","androidVersion","isIE","equation","re","rv","appName","exec","parseFloat","$1","testElement","isGecko","indexOf","isWebKit","isChrome","isOpera","USER_AGENT","hasContentEditableSupport","hasEditingApiSupport","execCommand","queryCommandSupported","queryCommandState","hasQuerySelectorSupport","querySelector","querySelectorAll","isIncompatibleMobileBrowser","isIos","isAndroid","isTouchDevice","supportsEvent","supportsSandboxedIframes","throwsMixedContentWarningWhenIframeSrcIsEmpty","displaysCaretInEmptyContentEditableCorrectly","hasCurrentStyleProperty","insertsLineBreaksOnReturn","supportsPlaceholderAttributeOn","eventName","setAttribute","supportsEventsInIframeCorrectly","supportsHTML5Tags","html5","supportsCommand","buggyCommands","formatBlock","insertUnorderedList","insertOrderedList","insertHTML","command","isBuggy","e1","queryCommandEnabled","e2","doesAutoLinkingInContentEditable","canDisableAutoLinking","clearsContentEditableCorrectly","supportsGetAttributeCorrectly","td","getAttribute","canSelectImagesInContentEditable","autoScrollsToCaret","autoClosesUnclosedTags","clonedTestElement","supportsNativeGetElementsByClassName","getElementsByClassName","supportsSelectionModify","needsSpaceAfterLineBreak","supportsSpeechApiOn","input","chromeVersion","crashesWhenDefineProperty","property","doesAsyncFocus","hasProblemsSettingCaretAfterImg","hasUndoInContextMenu","hasInsertNodeIssue","hasIframeFocusIssue","createsNestedInvalidMarkupAfterPaste","supportsMutationEvents","supportsModenPaste","array","contains","needle","without","arrayToSubstract","newArr","newArray","map","callback","thisArg","A","unique","vals","max","idx","Dispatcher","on","handler","events","off","handlers","newHandlers","fire","payload","observe","stopObserving","merge","otherObj","newObj","isPlainObject","isFunction","WHITE_SPACE_START","WHITE_SPACE_END","ENTITY_REG_EXP","ENTITY_MAP","&","<",">","\"","\t","string","str","trim","interpolate","vars","by","search","split","escapeHTML","linebreaks","convertSpaces","html","c","autoLink","ignoreInClasses","_hasParentThatShouldBeIgnored","_parseNode","_convertUrlsToLinks","URL_REG_EXP","url","punctuation","TRAILING_CHAR_REG_EXP","opening","BRACKETS","realUrl","displayUrl","MAX_DISPLAY_LENGTH","substr","_getTempElement","tempElement","_wysihtml5_tempElement","_wrapMatchesInNode","nodeValue","IGNORE_URLS_IN","childNodesLength",")","]","}","addClass","classList","hasClass","removeClass","elementClassName","compareDocumentPosition","convertToList","_createListItem","list","listItem","_createList","listType","uneditableClass","childNode","lineBreak","isBlockElement","isLineBreak","currentListItem","lineBreaks","lineBreaksLength","getStyle","from","insert","after","replaceChild","copyAttributes","attributesToCopy","elementToCopyFrom","to","elementToCopyTo","attribute","andTo","callee","BOX_SIZING_PROPERTIES","shouldIgnoreBoxSizingBorderBox","hasBoxSizingBorderBox","offsetWidth","copyStyles","stylesToCopy","cssText","setStyles","delegate","selector","event","domNode","defaultNodeTypes","_isBlankText","prev","prevNode","types","ignoreBlankTexts","lastLeafNode","leafClasses","getAsDom","_innerHTMLShiv","_ensureHTML5Compatibility","_wysihtml5_supportsHTML5Tags","HTML5_ELEMENTS","getParentElement","_isSameNodeName","desiredNodeNames","_isElement","_hasClassName","classRegExp","classNames","_hasStyle","cssStyle","styleRegExp","styles","matchingSet","levels","findByStyle","findByClass","camelize","REG_EXP_CAMELIZE","charAt","toUpperCase","stylePropertyMapping","float","camelizedProperty","styleValue","originalOverflow","needsOverflowReset","overflow","getPropertyValue","getTextNodes","ingoreEmpty","all","textContent","hasElementWithTagName","_getDocumentIdentifier","_wysihtml5_identifier","DOCUMENT_IDENTIFIER","LIVE_CACHE","cacheEntry","hasElementWithClassName","elementToInsert","before","into","insertCSS","rules","styleElement","styleSheet","link","head","_isLineBreak","_isLineBreakOrBlockElement","eventNames","handlerWrapper","parse","elementOrHtml_current","config_current","elementOrHtml","currentRules","defaultRules","isString","clearInternals","selectors","_applySelectorRules","_convert","cleanUp","unjoinNbsps","txtnodes","getCorrectInnerHTML","oldNode","newChild","nodeDisplay","oldNodeType","oldChilds","oldChildsLength","NODE_TYPE_MAPPING","blockElements","DEFAULT_NODE_NAME","attributes","selectorRules","els","elementHandlingMethods","_handleElement","rule","renameTag","tagRules","tags","scopeName","_wysihtml5","outerHTML","unwrap","rename_tag","one_of_type","_testTypes","remove_action","remove_action_rename_to","_handleAttributes","_handleStyles","definition","type_definitions","_testType","classesLength","a","attr","styleProp","nodeClasses","nodeStyles","methods","m","typeCeckMethods","classes","WHITE_SPACE_REG_EXP","sp","attrs","v","keep_styles","styleFloat","cssFloat","_getAttributesBeginningWith","beginning","returnAttributes","_checkAttribute","attributeName","attributeValue","newAttributeValue","attributeCheckMethods","_checkAttributes","local_attributes","newValue","matchingAttributes","globalAttributes","checkAttributes","oldAttributes","getAttributes","imax","currentClass","newClass","setClass","set_class","add_class","addStyle","add_style","setAttributes","set_attributes","allowedClasses","newClasses","oldClasses","check_attributes","addClassMethods","addStyleMethods","newStyle","classes_blacklist","src","width","height","_handleText","_handleComment","comments","createComment","1","3","8","REG_EXP","href","alt","numbers","any","align_text","mapping","left","right","center","align_img","justify","clear_br","both","size_font","2","4","5","6","7","-","+","has_visible_contet","txt","visibleElements","offsetHeight","removeEmptyTextNodes","renameElement","newNodeName","newElement","replaceWithChildNodes","_isBlockElement","_appendLineBreak","resolveList","useLineBreaks","isLastChild","shouldAppendLineBreak","paragraph","firstElementChild","windowProperties","windowProperties2","documentProperties","Sandbox","readyCallback","editableArea","_createIframe","insertInto","getIframe","_readyError","destroy","iframe","that","security","allowtransparency","frameborder","marginwidth","marginheight","onload","onreadystatechange","_onLoadIframe","iframeWindow","iframeDocument","charset","characterSet","sandboxHtml","_getHtml","stylesheets","open","write","close","onerror","fileName","lineNumber","_unset","loaded","setTimeout","templateVars","setter","__defineGetter__","__defineSetter__","ContentEditableArea","getContentEditable","_bindElement","_createElement","_loadElement","contentExists","simulatePlaceholder","editor","view","placeholderText","CLASS_NAME","unset","composerIsVisible","hasPlaceholderSet","clear","placeholderSet","isEmpty","setValue","setTextContent","getTextContent","HAS_GET_ATTRIBUTE_BUG","isLoadedImage","hasAttribute","specified","complete","mozMatchesSelector","queryInList","query","q","ret","unshift","removeElement","referenceNode","tag","MapCell","cell","isColspan","isRowspan","firstCol","lastCol","firstRow","lastRow","isReal","spanCollection","modified","TableModifyerByCell","table","addSpannedCellToMap","r","cspan","rspan","spanCollect","rmax","cmax","rr","cc","setCellAsModified","smax","setTableMap","ridx","row","cells","cidx","tableRows","getTableRows","getRowCells","inlineTables","inlineCells","allCells","tableCells","inlineRows","allRows","getMapIndex","r_length","c_length","r_idx","c_idx","col","getElementAtIndex","getMapElsTo","to_cell","idx_start","idx_end","temp_idx","temp_cidx","maxr","maxc","orderSelectionEnds","secondcell","createCells","nr","correctColIndexForUnreals","corrIdx","getLastNewCellOnRow","rowLimit","removeEmptyTable","splitRowToCells","colspan","cType","newCells","removeAttribute","getRealRowEl","force","injectRowAt","new_cells","n_cidx","canMerge","decreaseCellSpan","span","removeSurplusLines","allRowspan","fillMissingCells","r_max","c_max","prevcell","rectify","unmerge","thisCell","rowspan","collapseCellToNextRow","cellIdx","newRowIdx","newIdx","lastCell","removeRowCell","getRowElementsByCell","modRow","getColumnElementsByCell","removeRow","oldRow","removeColCell","removeColumn","what","addRow","where","newRow","addRowCell","cr","colSpanAttr","addColumn","addColCell","doAdd","handleCellAddWithRowspan","modCell","temp_r_cells","nrow","addRowsNr","crow","getCellsBetween","cell1","cell2","c1","addCells","removeCells","mergeCellsBetween","unmergeCell","findCell","findRowByCell","findColumnByCell","elements","thisOwner","otherOwner","point","parents","location_index","smallest_common_ancestor","this_index","other_index","getPastedHtml","clipboardData","getData","getPastedHtmlWithDiv","composer","selBookmark","cleanerDiv","setBookmark","cleanPastedHTML","styleToRegex","styleStr","trimmedStr","escapedStr","extendRulesWithStyleExceptions","exceptStyles","newRules","pickRuleset","ruleset","defaultSet","condition","newHtml","color","fontSize","ensureProperClearing","clearIfNecessary","TILDE_ESCAPED","urlToSearch","elementsWithTilde","redraw","tableCellsSelection","editable","handleSelectionMousedown","removeCellSelections","selection_class","moveHandler","handleMouseMove","upHandler","handleMouseUp","selectedCells","addSelections","oldEnd","curTable","deselect","bindSideclick","sideClickHandler","selectCells","RGBA_REGEX","RGB_REGEX","HEX6_REGEX","HEX3_REGEX","param_REGX","styleParser","parseColor","stylesStr","paramName","colorMatch","paramRegex","radix","shift","d","unparseColor","parseFontSize","_getCumulativeOffsetTop","top","offsetTop","offsetParent","getDepth","expandRangeToSurround","common","start_depth","end_depth","contain","unselectableClass","getRange","setSelection","setBefore","creteTemporaryCaretSpaceAfter","caretPlaceholder","caretPlaceholderText","placeholderRemover","keyDownHandler","delayedPlaceholderRemover","setAfter","which","ctrlKey","metaKey","minWidth","zIndex","originalScrollTop","scrollTop","pageYOffset","originalScrollLeft","scrollLeft","pageXOffset","scrollTo","avoidInvisibleSpace","isElement","displayStyle","getSelectedNode","fixSelBorders","getSelectedOwnNodes","getOwnRanges","ownNodes","maxi","findNodesInSelection","curNodes","containsUneditable","uneditables","getOwnUneditables","startParent","endParent","ev","CustomEvent","dispatchEvent","err","getPreviousNode","ignoreEmpty","getSelectionParentsByTag","curEl","getRangeToNodeEnd","sNode","lastR","caretIsLastInSelection","endc","endtxt","caretIsFirstInSelection","caretIsInTheBeginnig","ofNode","caretIsBeforeUneditable","contentNodes","lastNode","prevLeaf","executeAndRestoreRangy","executeAndRestore","restoreScrollPosition","newCaretPlaceholder","prevSibling","newRange","oldScrollTop","oldScrollLeft","placeholderHtml","surround","nodeOptions","deblockAndSurround","tempDivElements","tempElements","scrollIntoView","tolerance","hasScrollBars","scrollHeight","_wysihtml5ScrollIntoViewElement","selectLine","_selectLine_W3C","_selectLine_MSIE","modify","toLineBoundary","location","rangeBottom","rangeEnd","measureNode","j","rangeTop","boundingTop","scrollWidth","moveToPoint","getText","fixRangeOverflow","containment","_detectInlineRangeProblems","previousElementSibling","_endOffsetForNode","dontFix","allUneditables","deepUneditables","tmpRanges","tmpRange","jmax","getHtml","getPlainText","isEndToEndInNode","nodeNames","cssClass","regExp","matchingClassNames","hasStyleAttr","removeStyle","s2","getMatchingStyleRegexp","regexes","sSplit","elStyle","isMatchingAllready","areMatchingAllready","removeOrChangeStyle","exactRegex","hasSameClasses","el1","el2","REG_EXP_WHITE_SPACE","replaceWithOwnChildren","elementsHaveSameNonClassAttributes","attr1","attr2","getNamedItem","isSplitPoint","splitNodeAt","descendantNode","descendantOffset","Merge","firstNode","isElementMerge","firstTextNode","HTMLApplier","tagNames","similarClassRegExp","similarStyleRegExp","defaultTagName","applyToAnyTagName","doMerge","textBits","getLength","getAncestorWithClass","cssClassMatch","getAncestorWithStyle","cssStyleMatch","getMatchingAncestor","matchType","postApply","currentMerge","precedingTextNode","merges","rangeStartNode","rangeEndNode","rangeStartOffset","rangeEndOffset","getAdjacentMergeableTextNode","nextTextNode","forward","adjacentNode","isTextNode","areElementsMergeable","createContainer","applyToTextNode","isRemovable","undoToTextNode","ancestorWithClass","ancestorWithStyle","styleMode","styleChanged","ancestorRange","applyToRange","ri","undoToRange","getTextSelectedByRange","isAppliedToRange","appliedType","coverage","selectedText","toggleRange","parentsExactMatch","isApplied","Commands","support","result","state","stateValue","bold","formatInline","execWithToggle","_format","anchors","hasElementChild","elementToSetCaretAfter","whiteSpace","tempClass","tempClassRegExp","undef","NODE_NAME","_changeLinks","oldAttrs","oa","createLink","_removeFormat","codeElement","removeLink","size","fontSizeStyle","st","foreColor","foreColorStyle","colString","colorVals","colorStr","bgColorStyle","_addClass","_removeClass","_addStyle","_removeStyle","_removeLastChildIfLineBreak","_selectionWrap","surroundedNodes","_hasClasses","_hasStyles","BLOCK_ELEMENTS_GROUP","selectedNodes","classRemoveAction","blockRenameFound","styleRemoveAction","blockElement","defaultNodeName","b","hasClasses","hasStyles","formatCode","classname","pre","selectedNode","_getTagNames","alias","ALIAS_MAPPING","_getApplier","identifier","htmlApplier","strong","em","dontRestoreSelect","noCleanup","ownRanges","state_element","aliasTagName","insertBlockQuote","endToEndParent","qouteEl","insertImage","image","imagesInSelection","LINE_BREAK","insertLineBreak","insertList","isNode","findListEl","other","parentLi","otherNodeName","handleSameTypeList","innerLists","otherLists","getListsInSelection","l","handleOtherTypeList","renameLists","createListFallback","tempClassName","getTime","uneditableContainerClassname","cmd","italic","justifyCenter","justifyLeft","justifyRight","justifyFull","STYLE_STR","alignRightStyle","alignLeftStyle","alignCenterStyle","redo","undoManager","underline","undo","createTable","cols","rows","tableStyle","mergeTableCells","tableSelection","addTableCells","tableSelect","deleteTableCells","selCell","indentList","listEls","tryToPushLiLevel","liNodes","listTag","prevLi","liNode","prevLiList","found","outdentList","tryToPullLiLevel","listNode","outerListNode","outerLiNode","afterList","getAfterList","newList","Z_KEY","Y_KEY","MAX_HISTORY_ENTRIES","DATA_ATTR_NODE","DATA_ATTR_OFFSET","UndoManager","historyStr","historyDom","transact","_observe","lastKey","sandbox","altKey","keyCode","isUndo","shiftKey","isRedo","previousHtml","currentHtml","getValue","getChildNodeIndex","undoPossible","redoPossible","historyEntry","getChildNodeByIndex","View","textareaElement","noTextarea","_observeViewChange","currentView","show","hide","disable","enable","Composer","CARET_HACK","editableElement","textarea","contentEditableMode","_initContentEditableArea","_initSandbox","_displayStyle","disabled","setToEnd","_create","_createWysiwygFormField","form","hiddenField","composerClassName","placeholder","_initAutoLinking","_initObjectResizing","_initUndoManager","_initLineBreaking","initSync","sync","supportsDisablingOfAutoLinking","supportsAutoLinking","nodeWithSelection","isInUneditable","links","urlRegExp","newTextContent","properties","propertiesLength","adjust","USE_NATIVE_LINE_BREAK_INSIDE_TAGS","LIST_TAGS","HOST_TEMPLATE","TEXT_FORMATTING","BOX_FORMATTING","ADDITIONAL_CSS_RULES","focusWithoutScrolling","setActive","elementStyle","originalStyles","WebkitUserSelect","displayValueForCopying","originalActiveElement","hasPlaceholder","originalPlaceholder","originalDisplayValue","originalDisabled","focusStylesHost","blurStylesHost","disabledStylesHost","blur","boxFormattingStyles","shortcuts","66","73","85","addListeners","removeListeners","handleDeleteKeyPress","beforeUneditable","handleTabKeyDown","handleDomNodeRemoved","domNodeRemovedInterval","clearInterval","handleUserInteraction","handleFocus","focusState","handleBlur","changeevent","create","handlePaste","handleCopy","copyedFromMarking","setData","handleKeyUp","handleMouseDown","allImages","notMyImages","myImages","handleMouseOver","title","titlePrefixes","IMG","handleClick","uneditable","handleDrop","handleKeyDown","handleTabKey","handleIframeFocus","handleIframeBlur","initTableHandling","hideHandlers","iframeInitiator","focusBlurElement","setInterval","handleTables","INTERVAL","Synchronizer","fromComposerToTextarea","shouldParseHtml","fromTextareaToComposer","textareaValue","interval","startInterval","stopInterval","Textarea","supportsPlaceholder","eventMapping","focusin","focusout","defaultConfig","showToolbarAfterInit","parserRules","br","div","pasteParserRulesets","parser","bodyClassName","supportTouchDevices","Editor","_isCompatible","_initParser","handleBeforeLoad","synchronizer","Toolbar","isCompatible","htmlOrElement","parseContext","oldHtml","_cleanAndPaste","pastedHTML","cleanHtml","CLASS_NAME_OPENED","SELECTOR_FORM_ELEMENTS","SELECTOR_FIELDS","ATTRIBUTE_FIELDS","Dialog","_observed","callbackWrapper","_serialize","elementToChange","formElements","_clearInterval","fields","_interpolate","avoidHiddenFields","field","fieldName","focusedElement","defaultValue","firstField","linkStyles","wrapperStyles","margin","opacity","padding","inputStyles","cursor","marginTop","outline","inputAttributes","x-webkit-speech","speech","Speech","CLASS_NAME_COMMAND_DISABLED","CLASS_NAME_COMMANDS_DISABLED","CLASS_NAME_COMMAND_ACTIVE","CLASS_NAME_ACTION_ACTIVE","showOnInit","_getLinks","classNameCommandDisabled","classNameCommandsDisabled","classNameCommandActive","classNameActionActive","speechInputLinks","group","dialog","_getDialog","caretBookmark","dialogElement","dialogContainer","commandLink","_execCommand","commandValue","commandsDisabled","commandObj","commandMapping","_updateLinkStates","execAction","commandLinks","actionLinks","unselectable","actionMapping","multiselect","Dialog_createTable","Dialog_foreColorStyle","firstElement","Dialog_fontSizeStyle"],"mappings":";;CAOA,WAWE,GAVKA,MAAMC,UAAUC,iBACnBF,MAAMC,UAAUC,eAAe,WAC7BC,KAAKC,aAAY,IAGhBJ,MAAMC,UAAUI,kBACnBL,MA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WAAY,WACV,OAAQ9R,KAAStnD,KAAKmX,UAAU+Y,cAAc,wCAAwClC,QAGxFyrC,aAAc,WACZ,GAAII,GAAiB34D,SAASgvB,cAAc,UACxCypC,EAAiB35D,KAAKmX,UAAU+Y,cAAc,wCAC9C2sC,EAAkB78D,KAAoB,gBAAMuD,EAAUM,KAAKvC,OAAOtB,KAAKq5D,iBAAiB72D,UAAaxC,KAAKq5D,gBAAgB,GAAKr5D,KAAKq5D,gBAAmB,KACvJljB,EAAiB,EAAiB0mB,EAAazqC,aAAa,SAAW,KACvEk1B,EAAiB,EAAa/jD,EAAUI,OAAOi1C,YAAYU,cAAcnD,GAAY,IAErFwjB,IAASA,IAAUE,GAAkBvS,IAAS,QAAUnyC,KAAKmyC,KAC/DqS,EAAM3rC,MAAQs5B,OAKnB/jD"}
\ No newline at end of file
--- /dev/null
+// TODO: in future try to replace most inline compability checks with polyfills for code readability
+
+// IE8 SUPPORT BLOCK
+// You can compile wuthout all this if IE8 is not needed
+
+// addEventListener, removeEventListener
+// TODO: make usage of wysihtml5.dom.observe obsolete
+(function() {
+ if (!Event.prototype.preventDefault) {
+ Event.prototype.preventDefault=function() {
+ this.returnValue=false;
+ };
+ }
+ if (!Event.prototype.stopPropagation) {
+ Event.prototype.stopPropagation=function() {
+ this.cancelBubble=true;
+ };
+ }
+ if (!Element.prototype.addEventListener) {
+ var eventListeners=[];
+
+ var addEventListener=function(type,listener /*, useCapture (will be ignored) */) {
+ var self=this;
+ var wrapper=function(e) {
+ e.target=e.srcElement;
+ e.currentTarget=self;
+ if (listener.handleEvent) {
+ listener.handleEvent(e);
+ } else {
+ listener.call(self,e);
+ }
+ };
+ if (type=="DOMContentLoaded") {
+ var wrapper2=function(e) {
+ if (document.readyState=="complete") {
+ wrapper(e);
+ }
+ };
+ document.attachEvent("onreadystatechange",wrapper2);
+ eventListeners.push({object:this,type:type,listener:listener,wrapper:wrapper2});
+
+ if (document.readyState=="complete") {
+ var e=new Event();
+ e.srcElement=window;
+ wrapper2(e);
+ }
+ } else {
+ this.attachEvent("on"+type,wrapper);
+ eventListeners.push({object:this,type:type,listener:listener,wrapper:wrapper});
+ }
+ };
+ var removeEventListener=function(type,listener /*, useCapture (will be ignored) */) {
+ var counter=0;
+ while (counter<eventListeners.length) {
+ var eventListener=eventListeners[counter];
+ if (eventListener.object==this && eventListener.type==type && eventListener.listener==listener) {
+ if (type=="DOMContentLoaded") {
+ this.detachEvent("onreadystatechange",eventListener.wrapper);
+ } else {
+ this.detachEvent("on"+type,eventListener.wrapper);
+ }
+ eventListeners.splice(counter, 1);
+ break;
+ }
+ ++counter;
+ }
+ };
+ Element.prototype.addEventListener=addEventListener;
+ Element.prototype.removeEventListener=removeEventListener;
+ if (HTMLDocument) {
+ HTMLDocument.prototype.addEventListener=addEventListener;
+ HTMLDocument.prototype.removeEventListener=removeEventListener;
+ }
+ if (Window) {
+ Window.prototype.addEventListener=addEventListener;
+ Window.prototype.removeEventListener=removeEventListener;
+ }
+ }
+})();
+
+// element.textContent polyfill.
+if (Object.defineProperty && Object.getOwnPropertyDescriptor && Object.getOwnPropertyDescriptor(Element.prototype, "textContent") && !Object.getOwnPropertyDescriptor(Element.prototype, "textContent").get) {
+ (function() {
+ var innerText = Object.getOwnPropertyDescriptor(Element.prototype, "innerText");
+ Object.defineProperty(Element.prototype, "textContent",
+ {
+ get: function() {
+ return innerText.get.call(this);
+ },
+ set: function(s) {
+ return innerText.set.call(this, s);
+ }
+ }
+ );
+ })();
+}
+
+// isArray polyfill for ie8
+if(!Array.isArray) {
+ Array.isArray = function(arg) {
+ return Object.prototype.toString.call(arg) === '[object Array]';
+ };
+}
+
+// Function.prototype.bind()
+// TODO: clean the code from variable 'that' as it can be confusing
+if (!Function.prototype.bind) {
+ Function.prototype.bind = function(oThis) {
+ if (typeof this !== 'function') {
+ // closest thing possible to the ECMAScript 5
+ // internal IsCallable function
+ throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
+ }
+
+ var aArgs = Array.prototype.slice.call(arguments, 1),
+ fToBind = this,
+ fNOP = function() {},
+ fBound = function() {
+ return fToBind.apply(this instanceof fNOP && oThis
+ ? this
+ : oThis,
+ aArgs.concat(Array.prototype.slice.call(arguments)));
+ };
+
+ fNOP.prototype = this.prototype;
+ fBound.prototype = new fNOP();
+
+ return fBound;
+ };
+};/**
+ * @license wysihtml5x v0.4.17
+ * https://github.com/Edicy/wysihtml5
+ *
+ * Author: Christopher Blum (https://github.com/tiff)
+ * Secondary author of extended features: Oliver Pulges (https://github.com/pulges)
+ *
+ * Copyright (C) 2012 XING AG
+ * Licensed under the MIT license (MIT)
+ *
+ */
+var wysihtml5 = {
+ version: "0.4.17",
+
+ // namespaces
+ commands: {},
+ dom: {},
+ quirks: {},
+ toolbar: {},
+ lang: {},
+ selection: {},
+ views: {},
+
+ INVISIBLE_SPACE: "\uFEFF",
+ INVISIBLE_SPACE_REG_EXP: /\uFEFF/g,
+
+ EMPTY_FUNCTION: function() {},
+
+ ELEMENT_NODE: 1,
+ TEXT_NODE: 3,
+
+ BACKSPACE_KEY: 8,
+ ENTER_KEY: 13,
+ ESCAPE_KEY: 27,
+ SPACE_KEY: 32,
+ TAB_KEY: 9,
+ DELETE_KEY: 46
+};
+;/**\r
+ * Rangy, a cross-browser JavaScript range and selection library\r
+ * https://github.com/timdown/rangy\r
+ *\r
+ * Copyright 2014, Tim Down\r
+ * Licensed under the MIT license.\r
+ * Version: 1.3.0-alpha.20140921\r
+ * Build date: 21 September 2014\r
+ */\r
+\r
+(function(factory, root) {\r
+ if (typeof define == "function" && define.amd) {\r
+ // AMD. Register as an anonymous module.\r
+ define(factory);\r
+ } else if (typeof module != "undefined" && typeof exports == "object") {\r
+ // Node/CommonJS style\r
+ module.exports = factory();\r
+ } else {\r
+ // No AMD or CommonJS support so we place Rangy in (probably) the global variable\r
+ root.rangy = factory();\r
+ }\r
+})(function() {\r
+\r
+ var OBJECT = "object", FUNCTION = "function", UNDEFINED = "undefined";\r
+\r
+ // Minimal set of properties required for DOM Level 2 Range compliance. Comparison constants such as START_TO_START\r
+ // are omitted because ranges in KHTML do not have them but otherwise work perfectly well. See issue 113.\r
+ var domRangeProperties = ["startContainer", "startOffset", "endContainer", "endOffset", "collapsed",\r
+ "commonAncestorContainer"];\r
+\r
+ // Minimal set of methods required for DOM Level 2 Range compliance\r
+ var domRangeMethods = ["setStart", "setStartBefore", "setStartAfter", "setEnd", "setEndBefore",\r
+ "setEndAfter", "collapse", "selectNode", "selectNodeContents", "compareBoundaryPoints", "deleteContents",\r
+ "extractContents", "cloneContents", "insertNode", "surroundContents", "cloneRange", "toString", "detach"];\r
+\r
+ var textRangeProperties = ["boundingHeight", "boundingLeft", "boundingTop", "boundingWidth", "htmlText", "text"];\r
+\r
+ // Subset of TextRange's full set of methods that we're interested in\r
+ var textRangeMethods = ["collapse", "compareEndPoints", "duplicate", "moveToElementText", "parentElement", "select",\r
+ "setEndPoint", "getBoundingClientRect"];\r
+\r
+ /*----------------------------------------------------------------------------------------------------------------*/\r
+\r
+ // Trio of functions taken from Peter Michaux's article:\r
+ // http://peter.michaux.ca/articles/feature-detection-state-of-the-art-browser-scripting\r
+ function isHostMethod(o, p) {\r
+ var t = typeof o[p];\r
+ return t == FUNCTION || (!!(t == OBJECT && o[p])) || t == "unknown";\r
+ }\r
+\r
+ function isHostObject(o, p) {\r
+ return !!(typeof o[p] == OBJECT && o[p]);\r
+ }\r
+\r
+ function isHostProperty(o, p) {\r
+ return typeof o[p] != UNDEFINED;\r
+ }\r
+\r
+ // Creates a convenience function to save verbose repeated calls to tests functions\r
+ function createMultiplePropertyTest(testFunc) {\r
+ return function(o, props) {\r
+ var i = props.length;\r
+ while (i--) {\r
+ if (!testFunc(o, props[i])) {\r
+ return false;\r
+ }\r
+ }\r
+ return true;\r
+ };\r
+ }\r
+\r
+ // Next trio of functions are a convenience to save verbose repeated calls to previous two functions\r
+ var areHostMethods = createMultiplePropertyTest(isHostMethod);\r
+ var areHostObjects = createMultiplePropertyTest(isHostObject);\r
+ var areHostProperties = createMultiplePropertyTest(isHostProperty);\r
+\r
+ function isTextRange(range) {\r
+ return range && areHostMethods(range, textRangeMethods) && areHostProperties(range, textRangeProperties);\r
+ }\r
+\r
+ function getBody(doc) {\r
+ return isHostObject(doc, "body") ? doc.body : doc.getElementsByTagName("body")[0];\r
+ }\r
+\r
+ var modules = {};\r
+\r
+ var isBrowser = (typeof window != UNDEFINED && typeof document != UNDEFINED);\r
+\r
+ var util = {\r
+ isHostMethod: isHostMethod,\r
+ isHostObject: isHostObject,\r
+ isHostProperty: isHostProperty,\r
+ areHostMethods: areHostMethods,\r
+ areHostObjects: areHostObjects,\r
+ areHostProperties: areHostProperties,\r
+ isTextRange: isTextRange,\r
+ getBody: getBody\r
+ };\r
+\r
+ var api = {\r
+ version: "1.3.0-alpha.20140921",\r
+ initialized: false,\r
+ isBrowser: isBrowser,\r
+ supported: true,\r
+ util: util,\r
+ features: {},\r
+ modules: modules,\r
+ config: {\r
+ alertOnFail: true,\r
+ alertOnWarn: false,\r
+ preferTextRange: false,\r
+ autoInitialize: (typeof rangyAutoInitialize == UNDEFINED) ? true : rangyAutoInitialize\r
+ }\r
+ };\r
+\r
+ function consoleLog(msg) {\r
+ if (typeof console != UNDEFINED && isHostMethod(console, "log")) {\r
+ console.log(msg);\r
+ }\r
+ }\r
+\r
+ function alertOrLog(msg, shouldAlert) {\r
+ if (isBrowser && shouldAlert) {\r
+ alert(msg);\r
+ } else {\r
+ consoleLog(msg);\r
+ }\r
+ }\r
+\r
+ function fail(reason) {\r
+ api.initialized = true;\r
+ api.supported = false;\r
+ alertOrLog("Rangy is not supported in this environment. Reason: " + reason, api.config.alertOnFail);\r
+ }\r
+\r
+ api.fail = fail;\r
+\r
+ function warn(msg) {\r
+ alertOrLog("Rangy warning: " + msg, api.config.alertOnWarn);\r
+ }\r
+\r
+ api.warn = warn;\r
+\r
+ // Add utility extend() method\r
+ var extend;\r
+ if ({}.hasOwnProperty) {\r
+ util.extend = extend = function(obj, props, deep) {\r
+ var o, p;\r
+ for (var i in props) {\r
+ if (props.hasOwnProperty(i)) {\r
+ o = obj[i];\r
+ p = props[i];\r
+ if (deep && o !== null && typeof o == "object" && p !== null && typeof p == "object") {\r
+ extend(o, p, true);\r
+ }\r
+ obj[i] = p;\r
+ }\r
+ }\r
+ // Special case for toString, which does not show up in for...in loops in IE <= 8\r
+ if (props.hasOwnProperty("toString")) {\r
+ obj.toString = props.toString;\r
+ }\r
+ return obj;\r
+ };\r
+\r
+ util.createOptions = function(optionsParam, defaults) {\r
+ var options = {};\r
+ extend(options, defaults);\r
+ if (optionsParam) {\r
+ extend(options, optionsParam);\r
+ }\r
+ return options;\r
+ };\r
+ } else {\r
+ fail("hasOwnProperty not supported");\r
+ }\r
+ \r
+ // Test whether we're in a browser and bail out if not\r
+ if (!isBrowser) {\r
+ fail("Rangy can only run in a browser");\r
+ }\r
+\r
+ // Test whether Array.prototype.slice can be relied on for NodeLists and use an alternative toArray() if not\r
+ (function() {\r
+ var toArray;\r
+\r
+ if (isBrowser) {\r
+ var el = document.createElement("div");\r
+ el.appendChild(document.createElement("span"));\r
+ var slice = [].slice;\r
+ try {\r
+ if (slice.call(el.childNodes, 0)[0].nodeType == 1) {\r
+ toArray = function(arrayLike) {\r
+ return slice.call(arrayLike, 0);\r
+ };\r
+ }\r
+ } catch (e) {}\r
+ }\r
+\r
+ if (!toArray) {\r
+ toArray = function(arrayLike) {\r
+ var arr = [];\r
+ for (var i = 0, len = arrayLike.length; i < len; ++i) {\r
+ arr[i] = arrayLike[i];\r
+ }\r
+ return arr;\r
+ };\r
+ }\r
+\r
+ util.toArray = toArray;\r
+ })();\r
+\r
+ // Very simple event handler wrapper function that doesn't attempt to solve issues such as "this" handling or\r
+ // normalization of event properties\r
+ var addListener;\r
+ if (isBrowser) {\r
+ if (isHostMethod(document, "addEventListener")) {\r
+ addListener = function(obj, eventType, listener) {\r
+ obj.addEventListener(eventType, listener, false);\r
+ };\r
+ } else if (isHostMethod(document, "attachEvent")) {\r
+ addListener = function(obj, eventType, listener) {\r
+ obj.attachEvent("on" + eventType, listener);\r
+ };\r
+ } else {\r
+ fail("Document does not have required addEventListener or attachEvent method");\r
+ }\r
+\r
+ util.addListener = addListener;\r
+ }\r
+\r
+ var initListeners = [];\r
+\r
+ function getErrorDesc(ex) {\r
+ return ex.message || ex.description || String(ex);\r
+ }\r
+\r
+ // Initialization\r
+ function init() {\r
+ if (!isBrowser || api.initialized) {\r
+ return;\r
+ }\r
+ var testRange;\r
+ var implementsDomRange = false, implementsTextRange = false;\r
+\r
+ // First, perform basic feature tests\r
+\r
+ if (isHostMethod(document, "createRange")) {\r
+ testRange = document.createRange();\r
+ if (areHostMethods(testRange, domRangeMethods) && areHostProperties(testRange, domRangeProperties)) {\r
+ implementsDomRange = true;\r
+ }\r
+ }\r
+\r
+ var body = getBody(document);\r
+ if (!body || body.nodeName.toLowerCase() != "body") {\r
+ fail("No body element found");\r
+ return;\r
+ }\r
+\r
+ if (body && isHostMethod(body, "createTextRange")) {\r
+ testRange = body.createTextRange();\r
+ if (isTextRange(testRange)) {\r
+ implementsTextRange = true;\r
+ }\r
+ }\r
+\r
+ if (!implementsDomRange && !implementsTextRange) {\r
+ fail("Neither Range nor TextRange are available");\r
+ return;\r
+ }\r
+\r
+ api.initialized = true;\r
+ api.features = {\r
+ implementsDomRange: implementsDomRange,\r
+ implementsTextRange: implementsTextRange\r
+ };\r
+\r
+ // Initialize modules\r
+ var module, errorMessage;\r
+ for (var moduleName in modules) {\r
+ if ( (module = modules[moduleName]) instanceof Module ) {\r
+ module.init(module, api);\r
+ }\r
+ }\r
+\r
+ // Call init listeners\r
+ for (var i = 0, len = initListeners.length; i < len; ++i) {\r
+ try {\r
+ initListeners[i](api);\r
+ } catch (ex) {\r
+ errorMessage = "Rangy init listener threw an exception. Continuing. Detail: " + getErrorDesc(ex);\r
+ consoleLog(errorMessage);\r
+ }\r
+ }\r
+ }\r
+\r
+ // Allow external scripts to initialize this library in case it's loaded after the document has loaded\r
+ api.init = init;\r
+\r
+ // Execute listener immediately if already initialized\r
+ api.addInitListener = function(listener) {\r
+ if (api.initialized) {\r
+ listener(api);\r
+ } else {\r
+ initListeners.push(listener);\r
+ }\r
+ };\r
+\r
+ var shimListeners = [];\r
+\r
+ api.addShimListener = function(listener) {\r
+ shimListeners.push(listener);\r
+ };\r
+\r
+ function shim(win) {\r
+ win = win || window;\r
+ init();\r
+\r
+ // Notify listeners\r
+ for (var i = 0, len = shimListeners.length; i < len; ++i) {\r
+ shimListeners[i](win);\r
+ }\r
+ }\r
+\r
+ if (isBrowser) {\r
+ api.shim = api.createMissingNativeApi = shim;\r
+ }\r
+\r
+ function Module(name, dependencies, initializer) {\r
+ this.name = name;\r
+ this.dependencies = dependencies;\r
+ this.initialized = false;\r
+ this.supported = false;\r
+ this.initializer = initializer;\r
+ }\r
+\r
+ Module.prototype = {\r
+ init: function() {\r
+ var requiredModuleNames = this.dependencies || [];\r
+ for (var i = 0, len = requiredModuleNames.length, requiredModule, moduleName; i < len; ++i) {\r
+ moduleName = requiredModuleNames[i];\r
+\r
+ requiredModule = modules[moduleName];\r
+ if (!requiredModule || !(requiredModule instanceof Module)) {\r
+ throw new Error("required module '" + moduleName + "' not found");\r
+ }\r
+\r
+ requiredModule.init();\r
+\r
+ if (!requiredModule.supported) {\r
+ throw new Error("required module '" + moduleName + "' not supported");\r
+ }\r
+ }\r
+ \r
+ // Now run initializer\r
+ this.initializer(this);\r
+ },\r
+ \r
+ fail: function(reason) {\r
+ this.initialized = true;\r
+ this.supported = false;\r
+ throw new Error("Module '" + this.name + "' failed to load: " + reason);\r
+ },\r
+\r
+ warn: function(msg) {\r
+ api.warn("Module " + this.name + ": " + msg);\r
+ },\r
+\r
+ deprecationNotice: function(deprecated, replacement) {\r
+ api.warn("DEPRECATED: " + deprecated + " in module " + this.name + "is deprecated. Please use " +\r
+ replacement + " instead");\r
+ },\r
+\r
+ createError: function(msg) {\r
+ return new Error("Error in Rangy " + this.name + " module: " + msg);\r
+ }\r
+ };\r
+ \r
+ function createModule(name, dependencies, initFunc) {\r
+ var newModule = new Module(name, dependencies, function(module) {\r
+ if (!module.initialized) {\r
+ module.initialized = true;\r
+ try {\r
+ initFunc(api, module);\r
+ module.supported = true;\r
+ } catch (ex) {\r
+ var errorMessage = "Module '" + name + "' failed to load: " + getErrorDesc(ex);\r
+ consoleLog(errorMessage);\r
+ if (ex.stack) {\r
+ consoleLog(ex.stack);\r
+ }\r
+ }\r
+ }\r
+ });\r
+ modules[name] = newModule;\r
+ return newModule;\r
+ }\r
+\r
+ api.createModule = function(name) {\r
+ // Allow 2 or 3 arguments (second argument is an optional array of dependencies)\r
+ var initFunc, dependencies;\r
+ if (arguments.length == 2) {\r
+ initFunc = arguments[1];\r
+ dependencies = [];\r
+ } else {\r
+ initFunc = arguments[2];\r
+ dependencies = arguments[1];\r
+ }\r
+\r
+ var module = createModule(name, dependencies, initFunc);\r
+\r
+ // Initialize the module immediately if the core is already initialized\r
+ if (api.initialized && api.supported) {\r
+ module.init();\r
+ }\r
+ };\r
+\r
+ api.createCoreModule = function(name, dependencies, initFunc) {\r
+ createModule(name, dependencies, initFunc);\r
+ };\r
+\r
+ /*----------------------------------------------------------------------------------------------------------------*/\r
+\r
+ // Ensure rangy.rangePrototype and rangy.selectionPrototype are available immediately\r
+\r
+ function RangePrototype() {}\r
+ api.RangePrototype = RangePrototype;\r
+ api.rangePrototype = new RangePrototype();\r
+\r
+ function SelectionPrototype() {}\r
+ api.selectionPrototype = new SelectionPrototype();\r
+\r
+ /*----------------------------------------------------------------------------------------------------------------*/\r
+\r
+ // DOM utility methods used by Rangy
+ api.createCoreModule("DomUtil", [], function(api, module) {
+ var UNDEF = "undefined";
+ var util = api.util;
+
+ // Perform feature tests
+ if (!util.areHostMethods(document, ["createDocumentFragment", "createElement", "createTextNode"])) {
+ module.fail("document missing a Node creation method");
+ }
+
+ if (!util.isHostMethod(document, "getElementsByTagName")) {
+ module.fail("document missing getElementsByTagName method");
+ }
+
+ var el = document.createElement("div");
+ if (!util.areHostMethods(el, ["insertBefore", "appendChild", "cloneNode"] ||
+ !util.areHostObjects(el, ["previousSibling", "nextSibling", "childNodes", "parentNode"]))) {
+ module.fail("Incomplete Element implementation");
+ }
+
+ // innerHTML is required for Range's createContextualFragment method
+ if (!util.isHostProperty(el, "innerHTML")) {
+ module.fail("Element is missing innerHTML property");
+ }
+
+ var textNode = document.createTextNode("test");
+ if (!util.areHostMethods(textNode, ["splitText", "deleteData", "insertData", "appendData", "cloneNode"] ||
+ !util.areHostObjects(el, ["previousSibling", "nextSibling", "childNodes", "parentNode"]) ||
+ !util.areHostProperties(textNode, ["data"]))) {
+ module.fail("Incomplete Text Node implementation");
+ }
+
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ // Removed use of indexOf because of a bizarre bug in Opera that is thrown in one of the Acid3 tests. I haven't been
+ // able to replicate it outside of the test. The bug is that indexOf returns -1 when called on an Array that
+ // contains just the document as a single element and the value searched for is the document.
+ var arrayContains = /*Array.prototype.indexOf ?
+ function(arr, val) {
+ return arr.indexOf(val) > -1;
+ }:*/
+
+ function(arr, val) {
+ var i = arr.length;
+ while (i--) {
+ if (arr[i] === val) {
+ return true;
+ }
+ }
+ return false;
+ };
+
+ // Opera 11 puts HTML elements in the null namespace, it seems, and IE 7 has undefined namespaceURI
+ function isHtmlNamespace(node) {
+ var ns;
+ return typeof node.namespaceURI == UNDEF || ((ns = node.namespaceURI) === null || ns == "http://www.w3.org/1999/xhtml");
+ }
+
+ function parentElement(node) {
+ var parent = node.parentNode;
+ return (parent.nodeType == 1) ? parent : null;
+ }
+
+ function getNodeIndex(node) {
+ var i = 0;
+ while( (node = node.previousSibling) ) {
+ ++i;
+ }
+ return i;
+ }
+
+ function getNodeLength(node) {
+ switch (node.nodeType) {
+ case 7:
+ case 10:
+ return 0;
+ case 3:
+ case 8:
+ return node.length;
+ default:
+ return node.childNodes.length;
+ }
+ }
+
+ function getCommonAncestor(node1, node2) {
+ var ancestors = [], n;
+ for (n = node1; n; n = n.parentNode) {
+ ancestors.push(n);
+ }
+
+ for (n = node2; n; n = n.parentNode) {
+ if (arrayContains(ancestors, n)) {
+ return n;
+ }
+ }
+
+ return null;
+ }
+
+ function isAncestorOf(ancestor, descendant, selfIsAncestor) {
+ var n = selfIsAncestor ? descendant : descendant.parentNode;
+ while (n) {
+ if (n === ancestor) {
+ return true;
+ } else {
+ n = n.parentNode;
+ }
+ }
+ return false;
+ }
+
+ function isOrIsAncestorOf(ancestor, descendant) {
+ return isAncestorOf(ancestor, descendant, true);
+ }
+
+ function getClosestAncestorIn(node, ancestor, selfIsAncestor) {
+ var p, n = selfIsAncestor ? node : node.parentNode;
+ while (n) {
+ p = n.parentNode;
+ if (p === ancestor) {
+ return n;
+ }
+ n = p;
+ }
+ return null;
+ }
+
+ function isCharacterDataNode(node) {
+ var t = node.nodeType;
+ return t == 3 || t == 4 || t == 8 ; // Text, CDataSection or Comment
+ }
+
+ function isTextOrCommentNode(node) {
+ if (!node) {
+ return false;
+ }
+ var t = node.nodeType;
+ return t == 3 || t == 8 ; // Text or Comment
+ }
+
+ function insertAfter(node, precedingNode) {
+ var nextNode = precedingNode.nextSibling, parent = precedingNode.parentNode;
+ if (nextNode) {
+ parent.insertBefore(node, nextNode);
+ } else {
+ parent.appendChild(node);
+ }
+ return node;
+ }
+
+ // Note that we cannot use splitText() because it is bugridden in IE 9.
+ function splitDataNode(node, index, positionsToPreserve) {
+ var newNode = node.cloneNode(false);
+ newNode.deleteData(0, index);
+ node.deleteData(index, node.length - index);
+ insertAfter(newNode, node);
+
+ // Preserve positions
+ if (positionsToPreserve) {
+ for (var i = 0, position; position = positionsToPreserve[i++]; ) {
+ // Handle case where position was inside the portion of node after the split point
+ if (position.node == node && position.offset > index) {
+ position.node = newNode;
+ position.offset -= index;
+ }
+ // Handle the case where the position is a node offset within node's parent
+ else if (position.node == node.parentNode && position.offset > getNodeIndex(node)) {
+ ++position.offset;
+ }
+ }
+ }
+ return newNode;
+ }
+
+ function getDocument(node) {
+ if (node.nodeType == 9) {
+ return node;
+ } else if (typeof node.ownerDocument != UNDEF) {
+ return node.ownerDocument;
+ } else if (typeof node.document != UNDEF) {
+ return node.document;
+ } else if (node.parentNode) {
+ return getDocument(node.parentNode);
+ } else {
+ throw module.createError("getDocument: no document found for node");
+ }
+ }
+
+ function getWindow(node) {
+ var doc = getDocument(node);
+ if (typeof doc.defaultView != UNDEF) {
+ return doc.defaultView;
+ } else if (typeof doc.parentWindow != UNDEF) {
+ return doc.parentWindow;
+ } else {
+ throw module.createError("Cannot get a window object for node");
+ }
+ }
+
+ function getIframeDocument(iframeEl) {
+ if (typeof iframeEl.contentDocument != UNDEF) {
+ return iframeEl.contentDocument;
+ } else if (typeof iframeEl.contentWindow != UNDEF) {
+ return iframeEl.contentWindow.document;
+ } else {
+ throw module.createError("getIframeDocument: No Document object found for iframe element");
+ }
+ }
+
+ function getIframeWindow(iframeEl) {
+ if (typeof iframeEl.contentWindow != UNDEF) {
+ return iframeEl.contentWindow;
+ } else if (typeof iframeEl.contentDocument != UNDEF) {
+ return iframeEl.contentDocument.defaultView;
+ } else {
+ throw module.createError("getIframeWindow: No Window object found for iframe element");
+ }
+ }
+
+ // This looks bad. Is it worth it?
+ function isWindow(obj) {
+ return obj && util.isHostMethod(obj, "setTimeout") && util.isHostObject(obj, "document");
+ }
+
+ function getContentDocument(obj, module, methodName) {
+ var doc;
+
+ if (!obj) {
+ doc = document;
+ }
+
+ // Test if a DOM node has been passed and obtain a document object for it if so
+ else if (util.isHostProperty(obj, "nodeType")) {
+ doc = (obj.nodeType == 1 && obj.tagName.toLowerCase() == "iframe") ?
+ getIframeDocument(obj) : getDocument(obj);
+ }
+
+ // Test if the doc parameter appears to be a Window object
+ else if (isWindow(obj)) {
+ doc = obj.document;
+ }
+
+ if (!doc) {
+ throw module.createError(methodName + "(): Parameter must be a Window object or DOM node");
+ }
+
+ return doc;
+ }
+
+ function getRootContainer(node) {
+ var parent;
+ while ( (parent = node.parentNode) ) {
+ node = parent;
+ }
+ return node;
+ }
+
+ function comparePoints(nodeA, offsetA, nodeB, offsetB) {
+ // See http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html#Level-2-Range-Comparing
+ var nodeC, root, childA, childB, n;
+ if (nodeA == nodeB) {
+ // Case 1: nodes are the same
+ return offsetA === offsetB ? 0 : (offsetA < offsetB) ? -1 : 1;
+ } else if ( (nodeC = getClosestAncestorIn(nodeB, nodeA, true)) ) {
+ // Case 2: node C (container B or an ancestor) is a child node of A
+ return offsetA <= getNodeIndex(nodeC) ? -1 : 1;
+ } else if ( (nodeC = getClosestAncestorIn(nodeA, nodeB, true)) ) {
+ // Case 3: node C (container A or an ancestor) is a child node of B
+ return getNodeIndex(nodeC) < offsetB ? -1 : 1;
+ } else {
+ root = getCommonAncestor(nodeA, nodeB);
+ if (!root) {
+ throw new Error("comparePoints error: nodes have no common ancestor");
+ }
+
+ // Case 4: containers are siblings or descendants of siblings
+ childA = (nodeA === root) ? root : getClosestAncestorIn(nodeA, root, true);
+ childB = (nodeB === root) ? root : getClosestAncestorIn(nodeB, root, true);
+
+ if (childA === childB) {
+ // This shouldn't be possible
+ throw module.createError("comparePoints got to case 4 and childA and childB are the same!");
+ } else {
+ n = root.firstChild;
+ while (n) {
+ if (n === childA) {
+ return -1;
+ } else if (n === childB) {
+ return 1;
+ }
+ n = n.nextSibling;
+ }
+ }
+ }
+ }
+
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ // Test for IE's crash (IE 6/7) or exception (IE >= 8) when a reference to garbage-collected text node is queried
+ var crashyTextNodes = false;
+
+ function isBrokenNode(node) {
+ var n;
+ try {
+ n = node.parentNode;
+ return false;
+ } catch (e) {
+ return true;
+ }
+ }
+
+ (function() {
+ var el = document.createElement("b");
+ el.innerHTML = "1";
+ var textNode = el.firstChild;
+ el.innerHTML = "<br>";
+ crashyTextNodes = isBrokenNode(textNode);
+
+ api.features.crashyTextNodes = crashyTextNodes;
+ })();
+
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ function inspectNode(node) {
+ if (!node) {
+ return "[No node]";
+ }
+ if (crashyTextNodes && isBrokenNode(node)) {
+ return "[Broken node]";
+ }
+ if (isCharacterDataNode(node)) {
+ return '"' + node.data + '"';
+ }
+ if (node.nodeType == 1) {
+ var idAttr = node.id ? ' id="' + node.id + '"' : "";
+ return "<" + node.nodeName + idAttr + ">[index:" + getNodeIndex(node) + ",length:" + node.childNodes.length + "][" + (node.innerHTML || "[innerHTML not supported]").slice(0, 25) + "]";
+ }
+ return node.nodeName;
+ }
+
+ function fragmentFromNodeChildren(node) {
+ var fragment = getDocument(node).createDocumentFragment(), child;
+ while ( (child = node.firstChild) ) {
+ fragment.appendChild(child);
+ }
+ return fragment;
+ }
+
+ var getComputedStyleProperty;
+ if (typeof window.getComputedStyle != UNDEF) {
+ getComputedStyleProperty = function(el, propName) {
+ return getWindow(el).getComputedStyle(el, null)[propName];
+ };
+ } else if (typeof document.documentElement.currentStyle != UNDEF) {
+ getComputedStyleProperty = function(el, propName) {
+ return el.currentStyle[propName];
+ };
+ } else {
+ module.fail("No means of obtaining computed style properties found");
+ }
+
+ function NodeIterator(root) {
+ this.root = root;
+ this._next = root;
+ }
+
+ NodeIterator.prototype = {
+ _current: null,
+
+ hasNext: function() {
+ return !!this._next;
+ },
+
+ next: function() {
+ var n = this._current = this._next;
+ var child, next;
+ if (this._current) {
+ child = n.firstChild;
+ if (child) {
+ this._next = child;
+ } else {
+ next = null;
+ while ((n !== this.root) && !(next = n.nextSibling)) {
+ n = n.parentNode;
+ }
+ this._next = next;
+ }
+ }
+ return this._current;
+ },
+
+ detach: function() {
+ this._current = this._next = this.root = null;
+ }
+ };
+
+ function createIterator(root) {
+ return new NodeIterator(root);
+ }
+
+ function DomPosition(node, offset) {
+ this.node = node;
+ this.offset = offset;
+ }
+
+ DomPosition.prototype = {
+ equals: function(pos) {
+ return !!pos && this.node === pos.node && this.offset == pos.offset;
+ },
+
+ inspect: function() {
+ return "[DomPosition(" + inspectNode(this.node) + ":" + this.offset + ")]";
+ },
+
+ toString: function() {
+ return this.inspect();
+ }
+ };
+
+ function DOMException(codeName) {
+ this.code = this[codeName];
+ this.codeName = codeName;
+ this.message = "DOMException: " + this.codeName;
+ }
+
+ DOMException.prototype = {
+ INDEX_SIZE_ERR: 1,
+ HIERARCHY_REQUEST_ERR: 3,
+ WRONG_DOCUMENT_ERR: 4,
+ NO_MODIFICATION_ALLOWED_ERR: 7,
+ NOT_FOUND_ERR: 8,
+ NOT_SUPPORTED_ERR: 9,
+ INVALID_STATE_ERR: 11,
+ INVALID_NODE_TYPE_ERR: 24
+ };
+
+ DOMException.prototype.toString = function() {
+ return this.message;
+ };
+
+ api.dom = {
+ arrayContains: arrayContains,
+ isHtmlNamespace: isHtmlNamespace,
+ parentElement: parentElement,
+ getNodeIndex: getNodeIndex,
+ getNodeLength: getNodeLength,
+ getCommonAncestor: getCommonAncestor,
+ isAncestorOf: isAncestorOf,
+ isOrIsAncestorOf: isOrIsAncestorOf,
+ getClosestAncestorIn: getClosestAncestorIn,
+ isCharacterDataNode: isCharacterDataNode,
+ isTextOrCommentNode: isTextOrCommentNode,
+ insertAfter: insertAfter,
+ splitDataNode: splitDataNode,
+ getDocument: getDocument,
+ getWindow: getWindow,
+ getIframeWindow: getIframeWindow,
+ getIframeDocument: getIframeDocument,
+ getBody: util.getBody,
+ isWindow: isWindow,
+ getContentDocument: getContentDocument,
+ getRootContainer: getRootContainer,
+ comparePoints: comparePoints,
+ isBrokenNode: isBrokenNode,
+ inspectNode: inspectNode,
+ getComputedStyleProperty: getComputedStyleProperty,
+ fragmentFromNodeChildren: fragmentFromNodeChildren,
+ createIterator: createIterator,
+ DomPosition: DomPosition
+ };
+
+ api.DOMException = DOMException;
+ });\r
+\r
+ /*----------------------------------------------------------------------------------------------------------------*/\r
+\r
+ // Pure JavaScript implementation of DOM Range
+ api.createCoreModule("DomRange", ["DomUtil"], function(api, module) {
+ var dom = api.dom;
+ var util = api.util;
+ var DomPosition = dom.DomPosition;
+ var DOMException = api.DOMException;
+
+ var isCharacterDataNode = dom.isCharacterDataNode;
+ var getNodeIndex = dom.getNodeIndex;
+ var isOrIsAncestorOf = dom.isOrIsAncestorOf;
+ var getDocument = dom.getDocument;
+ var comparePoints = dom.comparePoints;
+ var splitDataNode = dom.splitDataNode;
+ var getClosestAncestorIn = dom.getClosestAncestorIn;
+ var getNodeLength = dom.getNodeLength;
+ var arrayContains = dom.arrayContains;
+ var getRootContainer = dom.getRootContainer;
+ var crashyTextNodes = api.features.crashyTextNodes;
+
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ // Utility functions
+
+ function isNonTextPartiallySelected(node, range) {
+ return (node.nodeType != 3) &&
+ (isOrIsAncestorOf(node, range.startContainer) || isOrIsAncestorOf(node, range.endContainer));
+ }
+
+ function getRangeDocument(range) {
+ return range.document || getDocument(range.startContainer);
+ }
+
+ function getBoundaryBeforeNode(node) {
+ return new DomPosition(node.parentNode, getNodeIndex(node));
+ }
+
+ function getBoundaryAfterNode(node) {
+ return new DomPosition(node.parentNode, getNodeIndex(node) + 1);
+ }
+
+ function insertNodeAtPosition(node, n, o) {
+ var firstNodeInserted = node.nodeType == 11 ? node.firstChild : node;
+ if (isCharacterDataNode(n)) {
+ if (o == n.length) {
+ dom.insertAfter(node, n);
+ } else {
+ n.parentNode.insertBefore(node, o == 0 ? n : splitDataNode(n, o));
+ }
+ } else if (o >= n.childNodes.length) {
+ n.appendChild(node);
+ } else {
+ n.insertBefore(node, n.childNodes[o]);
+ }
+ return firstNodeInserted;
+ }
+
+ function rangesIntersect(rangeA, rangeB, touchingIsIntersecting) {
+ assertRangeValid(rangeA);
+ assertRangeValid(rangeB);
+
+ if (getRangeDocument(rangeB) != getRangeDocument(rangeA)) {
+ throw new DOMException("WRONG_DOCUMENT_ERR");
+ }
+
+ var startComparison = comparePoints(rangeA.startContainer, rangeA.startOffset, rangeB.endContainer, rangeB.endOffset),
+ endComparison = comparePoints(rangeA.endContainer, rangeA.endOffset, rangeB.startContainer, rangeB.startOffset);
+
+ return touchingIsIntersecting ? startComparison <= 0 && endComparison >= 0 : startComparison < 0 && endComparison > 0;
+ }
+
+ function cloneSubtree(iterator) {
+ var partiallySelected;
+ for (var node, frag = getRangeDocument(iterator.range).createDocumentFragment(), subIterator; node = iterator.next(); ) {
+ partiallySelected = iterator.isPartiallySelectedSubtree();
+ node = node.cloneNode(!partiallySelected);
+ if (partiallySelected) {
+ subIterator = iterator.getSubtreeIterator();
+ node.appendChild(cloneSubtree(subIterator));
+ subIterator.detach();
+ }
+
+ if (node.nodeType == 10) { // DocumentType
+ throw new DOMException("HIERARCHY_REQUEST_ERR");
+ }
+ frag.appendChild(node);
+ }
+ return frag;
+ }
+
+ function iterateSubtree(rangeIterator, func, iteratorState) {
+ var it, n;
+ iteratorState = iteratorState || { stop: false };
+ for (var node, subRangeIterator; node = rangeIterator.next(); ) {
+ if (rangeIterator.isPartiallySelectedSubtree()) {
+ if (func(node) === false) {
+ iteratorState.stop = true;
+ return;
+ } else {
+ // The node is partially selected by the Range, so we can use a new RangeIterator on the portion of
+ // the node selected by the Range.
+ subRangeIterator = rangeIterator.getSubtreeIterator();
+ iterateSubtree(subRangeIterator, func, iteratorState);
+ subRangeIterator.detach();
+ if (iteratorState.stop) {
+ return;
+ }
+ }
+ } else {
+ // The whole node is selected, so we can use efficient DOM iteration to iterate over the node and its
+ // descendants
+ it = dom.createIterator(node);
+ while ( (n = it.next()) ) {
+ if (func(n) === false) {
+ iteratorState.stop = true;
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ function deleteSubtree(iterator) {
+ var subIterator;
+ while (iterator.next()) {
+ if (iterator.isPartiallySelectedSubtree()) {
+ subIterator = iterator.getSubtreeIterator();
+ deleteSubtree(subIterator);
+ subIterator.detach();
+ } else {
+ iterator.remove();
+ }
+ }
+ }
+
+ function extractSubtree(iterator) {
+ for (var node, frag = getRangeDocument(iterator.range).createDocumentFragment(), subIterator; node = iterator.next(); ) {
+
+ if (iterator.isPartiallySelectedSubtree()) {
+ node = node.cloneNode(false);
+ subIterator = iterator.getSubtreeIterator();
+ node.appendChild(extractSubtree(subIterator));
+ subIterator.detach();
+ } else {
+ iterator.remove();
+ }
+ if (node.nodeType == 10) { // DocumentType
+ throw new DOMException("HIERARCHY_REQUEST_ERR");
+ }
+ frag.appendChild(node);
+ }
+ return frag;
+ }
+
+ function getNodesInRange(range, nodeTypes, filter) {
+ var filterNodeTypes = !!(nodeTypes && nodeTypes.length), regex;
+ var filterExists = !!filter;
+ if (filterNodeTypes) {
+ regex = new RegExp("^(" + nodeTypes.join("|") + ")$");
+ }
+
+ var nodes = [];
+ iterateSubtree(new RangeIterator(range, false), function(node) {
+ if (filterNodeTypes && !regex.test(node.nodeType)) {
+ return;
+ }
+ if (filterExists && !filter(node)) {
+ return;
+ }
+ // Don't include a boundary container if it is a character data node and the range does not contain any
+ // of its character data. See issue 190.
+ var sc = range.startContainer;
+ if (node == sc && isCharacterDataNode(sc) && range.startOffset == sc.length) {
+ return;
+ }
+
+ var ec = range.endContainer;
+ if (node == ec && isCharacterDataNode(ec) && range.endOffset == 0) {
+ return;
+ }
+
+ nodes.push(node);
+ });
+ return nodes;
+ }
+
+ function inspect(range) {
+ var name = (typeof range.getName == "undefined") ? "Range" : range.getName();
+ return "[" + name + "(" + dom.inspectNode(range.startContainer) + ":" + range.startOffset + ", " +
+ dom.inspectNode(range.endContainer) + ":" + range.endOffset + ")]";
+ }
+
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ // RangeIterator code partially borrows from IERange by Tim Ryan (http://github.com/timcameronryan/IERange)
+
+ function RangeIterator(range, clonePartiallySelectedTextNodes) {
+ this.range = range;
+ this.clonePartiallySelectedTextNodes = clonePartiallySelectedTextNodes;
+
+
+ if (!range.collapsed) {
+ this.sc = range.startContainer;
+ this.so = range.startOffset;
+ this.ec = range.endContainer;
+ this.eo = range.endOffset;
+ var root = range.commonAncestorContainer;
+
+ if (this.sc === this.ec && isCharacterDataNode(this.sc)) {
+ this.isSingleCharacterDataNode = true;
+ this._first = this._last = this._next = this.sc;
+ } else {
+ this._first = this._next = (this.sc === root && !isCharacterDataNode(this.sc)) ?
+ this.sc.childNodes[this.so] : getClosestAncestorIn(this.sc, root, true);
+ this._last = (this.ec === root && !isCharacterDataNode(this.ec)) ?
+ this.ec.childNodes[this.eo - 1] : getClosestAncestorIn(this.ec, root, true);
+ }
+ }
+ }
+
+ RangeIterator.prototype = {
+ _current: null,
+ _next: null,
+ _first: null,
+ _last: null,
+ isSingleCharacterDataNode: false,
+
+ reset: function() {
+ this._current = null;
+ this._next = this._first;
+ },
+
+ hasNext: function() {
+ return !!this._next;
+ },
+
+ next: function() {
+ // Move to next node
+ var current = this._current = this._next;
+ if (current) {
+ this._next = (current !== this._last) ? current.nextSibling : null;
+
+ // Check for partially selected text nodes
+ if (isCharacterDataNode(current) && this.clonePartiallySelectedTextNodes) {
+ if (current === this.ec) {
+ (current = current.cloneNode(true)).deleteData(this.eo, current.length - this.eo);
+ }
+ if (this._current === this.sc) {
+ (current = current.cloneNode(true)).deleteData(0, this.so);
+ }
+ }
+ }
+
+ return current;
+ },
+
+ remove: function() {
+ var current = this._current, start, end;
+
+ if (isCharacterDataNode(current) && (current === this.sc || current === this.ec)) {
+ start = (current === this.sc) ? this.so : 0;
+ end = (current === this.ec) ? this.eo : current.length;
+ if (start != end) {
+ current.deleteData(start, end - start);
+ }
+ } else {
+ if (current.parentNode) {
+ current.parentNode.removeChild(current);
+ } else {
+ }
+ }
+ },
+
+ // Checks if the current node is partially selected
+ isPartiallySelectedSubtree: function() {
+ var current = this._current;
+ return isNonTextPartiallySelected(current, this.range);
+ },
+
+ getSubtreeIterator: function() {
+ var subRange;
+ if (this.isSingleCharacterDataNode) {
+ subRange = this.range.cloneRange();
+ subRange.collapse(false);
+ } else {
+ subRange = new Range(getRangeDocument(this.range));
+ var current = this._current;
+ var startContainer = current, startOffset = 0, endContainer = current, endOffset = getNodeLength(current);
+
+ if (isOrIsAncestorOf(current, this.sc)) {
+ startContainer = this.sc;
+ startOffset = this.so;
+ }
+ if (isOrIsAncestorOf(current, this.ec)) {
+ endContainer = this.ec;
+ endOffset = this.eo;
+ }
+
+ updateBoundaries(subRange, startContainer, startOffset, endContainer, endOffset);
+ }
+ return new RangeIterator(subRange, this.clonePartiallySelectedTextNodes);
+ },
+
+ detach: function() {
+ this.range = this._current = this._next = this._first = this._last = this.sc = this.so = this.ec = this.eo = null;
+ }
+ };
+
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ var beforeAfterNodeTypes = [1, 3, 4, 5, 7, 8, 10];
+ var rootContainerNodeTypes = [2, 9, 11];
+ var readonlyNodeTypes = [5, 6, 10, 12];
+ var insertableNodeTypes = [1, 3, 4, 5, 7, 8, 10, 11];
+ var surroundNodeTypes = [1, 3, 4, 5, 7, 8];
+
+ function createAncestorFinder(nodeTypes) {
+ return function(node, selfIsAncestor) {
+ var t, n = selfIsAncestor ? node : node.parentNode;
+ while (n) {
+ t = n.nodeType;
+ if (arrayContains(nodeTypes, t)) {
+ return n;
+ }
+ n = n.parentNode;
+ }
+ return null;
+ };
+ }
+
+ var getDocumentOrFragmentContainer = createAncestorFinder( [9, 11] );
+ var getReadonlyAncestor = createAncestorFinder(readonlyNodeTypes);
+ var getDocTypeNotationEntityAncestor = createAncestorFinder( [6, 10, 12] );
+
+ function assertNoDocTypeNotationEntityAncestor(node, allowSelf) {
+ if (getDocTypeNotationEntityAncestor(node, allowSelf)) {
+ throw new DOMException("INVALID_NODE_TYPE_ERR");
+ }
+ }
+
+ function assertValidNodeType(node, invalidTypes) {
+ if (!arrayContains(invalidTypes, node.nodeType)) {
+ throw new DOMException("INVALID_NODE_TYPE_ERR");
+ }
+ }
+
+ function assertValidOffset(node, offset) {
+ if (offset < 0 || offset > (isCharacterDataNode(node) ? node.length : node.childNodes.length)) {
+ throw new DOMException("INDEX_SIZE_ERR");
+ }
+ }
+
+ function assertSameDocumentOrFragment(node1, node2) {
+ if (getDocumentOrFragmentContainer(node1, true) !== getDocumentOrFragmentContainer(node2, true)) {
+ throw new DOMException("WRONG_DOCUMENT_ERR");
+ }
+ }
+
+ function assertNodeNotReadOnly(node) {
+ if (getReadonlyAncestor(node, true)) {
+ throw new DOMException("NO_MODIFICATION_ALLOWED_ERR");
+ }
+ }
+
+ function assertNode(node, codeName) {
+ if (!node) {
+ throw new DOMException(codeName);
+ }
+ }
+
+ function isOrphan(node) {
+ return (crashyTextNodes && dom.isBrokenNode(node)) ||
+ !arrayContains(rootContainerNodeTypes, node.nodeType) && !getDocumentOrFragmentContainer(node, true);
+ }
+
+ function isValidOffset(node, offset) {
+ return offset <= (isCharacterDataNode(node) ? node.length : node.childNodes.length);
+ }
+
+ function isRangeValid(range) {
+ return (!!range.startContainer && !!range.endContainer &&
+ !isOrphan(range.startContainer) &&
+ !isOrphan(range.endContainer) &&
+ isValidOffset(range.startContainer, range.startOffset) &&
+ isValidOffset(range.endContainer, range.endOffset));
+ }
+
+ function assertRangeValid(range) {
+ if (!isRangeValid(range)) {
+ throw new Error("Range error: Range is no longer valid after DOM mutation (" + range.inspect() + ")");
+ }
+ }
+
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ // Test the browser's innerHTML support to decide how to implement createContextualFragment
+ var styleEl = document.createElement("style");
+ var htmlParsingConforms = false;
+ try {
+ styleEl.innerHTML = "<b>x</b>";
+ htmlParsingConforms = (styleEl.firstChild.nodeType == 3); // Opera incorrectly creates an element node
+ } catch (e) {
+ // IE 6 and 7 throw
+ }
+
+ api.features.htmlParsingConforms = htmlParsingConforms;
+
+ var createContextualFragment = htmlParsingConforms ?
+
+ // Implementation as per HTML parsing spec, trusting in the browser's implementation of innerHTML. See
+ // discussion and base code for this implementation at issue 67.
+ // Spec: http://html5.org/specs/dom-parsing.html#extensions-to-the-range-interface
+ // Thanks to Aleks Williams.
+ function(fragmentStr) {
+ // "Let node the context object's start's node."
+ var node = this.startContainer;
+ var doc = getDocument(node);
+
+ // "If the context object's start's node is null, raise an INVALID_STATE_ERR
+ // exception and abort these steps."
+ if (!node) {
+ throw new DOMException("INVALID_STATE_ERR");
+ }
+
+ // "Let element be as follows, depending on node's interface:"
+ // Document, Document Fragment: null
+ var el = null;
+
+ // "Element: node"
+ if (node.nodeType == 1) {
+ el = node;
+
+ // "Text, Comment: node's parentElement"
+ } else if (isCharacterDataNode(node)) {
+ el = dom.parentElement(node);
+ }
+
+ // "If either element is null or element's ownerDocument is an HTML document
+ // and element's local name is "html" and element's namespace is the HTML
+ // namespace"
+ if (el === null || (
+ el.nodeName == "HTML" &&
+ dom.isHtmlNamespace(getDocument(el).documentElement) &&
+ dom.isHtmlNamespace(el)
+ )) {
+
+ // "let element be a new Element with "body" as its local name and the HTML
+ // namespace as its namespace.""
+ el = doc.createElement("body");
+ } else {
+ el = el.cloneNode(false);
+ }
+
+ // "If the node's document is an HTML document: Invoke the HTML fragment parsing algorithm."
+ // "If the node's document is an XML document: Invoke the XML fragment parsing algorithm."
+ // "In either case, the algorithm must be invoked with fragment as the input
+ // and element as the context element."
+ el.innerHTML = fragmentStr;
+
+ // "If this raises an exception, then abort these steps. Otherwise, let new
+ // children be the nodes returned."
+
+ // "Let fragment be a new DocumentFragment."
+ // "Append all new children to fragment."
+ // "Return fragment."
+ return dom.fragmentFromNodeChildren(el);
+ } :
+
+ // In this case, innerHTML cannot be trusted, so fall back to a simpler, non-conformant implementation that
+ // previous versions of Rangy used (with the exception of using a body element rather than a div)
+ function(fragmentStr) {
+ var doc = getRangeDocument(this);
+ var el = doc.createElement("body");
+ el.innerHTML = fragmentStr;
+
+ return dom.fragmentFromNodeChildren(el);
+ };
+
+ function splitRangeBoundaries(range, positionsToPreserve) {
+ assertRangeValid(range);
+
+ var sc = range.startContainer, so = range.startOffset, ec = range.endContainer, eo = range.endOffset;
+ var startEndSame = (sc === ec);
+
+ if (isCharacterDataNode(ec) && eo > 0 && eo < ec.length) {
+ splitDataNode(ec, eo, positionsToPreserve);
+ }
+
+ if (isCharacterDataNode(sc) && so > 0 && so < sc.length) {
+ sc = splitDataNode(sc, so, positionsToPreserve);
+ if (startEndSame) {
+ eo -= so;
+ ec = sc;
+ } else if (ec == sc.parentNode && eo >= getNodeIndex(sc)) {
+ eo++;
+ }
+ so = 0;
+ }
+ range.setStartAndEnd(sc, so, ec, eo);
+ }
+
+ function rangeToHtml(range) {
+ assertRangeValid(range);
+ var container = range.commonAncestorContainer.parentNode.cloneNode(false);
+ container.appendChild( range.cloneContents() );
+ return container.innerHTML;
+ }
+
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ var rangeProperties = ["startContainer", "startOffset", "endContainer", "endOffset", "collapsed",
+ "commonAncestorContainer"];
+
+ var s2s = 0, s2e = 1, e2e = 2, e2s = 3;
+ var n_b = 0, n_a = 1, n_b_a = 2, n_i = 3;
+
+ util.extend(api.rangePrototype, {
+ compareBoundaryPoints: function(how, range) {
+ assertRangeValid(this);
+ assertSameDocumentOrFragment(this.startContainer, range.startContainer);
+
+ var nodeA, offsetA, nodeB, offsetB;
+ var prefixA = (how == e2s || how == s2s) ? "start" : "end";
+ var prefixB = (how == s2e || how == s2s) ? "start" : "end";
+ nodeA = this[prefixA + "Container"];
+ offsetA = this[prefixA + "Offset"];
+ nodeB = range[prefixB + "Container"];
+ offsetB = range[prefixB + "Offset"];
+ return comparePoints(nodeA, offsetA, nodeB, offsetB);
+ },
+
+ insertNode: function(node) {
+ assertRangeValid(this);
+ assertValidNodeType(node, insertableNodeTypes);
+ assertNodeNotReadOnly(this.startContainer);
+
+ if (isOrIsAncestorOf(node, this.startContainer)) {
+ throw new DOMException("HIERARCHY_REQUEST_ERR");
+ }
+
+ // No check for whether the container of the start of the Range is of a type that does not allow
+ // children of the type of node: the browser's DOM implementation should do this for us when we attempt
+ // to add the node
+
+ var firstNodeInserted = insertNodeAtPosition(node, this.startContainer, this.startOffset);
+ this.setStartBefore(firstNodeInserted);
+ },
+
+ cloneContents: function() {
+ assertRangeValid(this);
+
+ var clone, frag;
+ if (this.collapsed) {
+ return getRangeDocument(this).createDocumentFragment();
+ } else {
+ if (this.startContainer === this.endContainer && isCharacterDataNode(this.startContainer)) {
+ clone = this.startContainer.cloneNode(true);
+ clone.data = clone.data.slice(this.startOffset, this.endOffset);
+ frag = getRangeDocument(this).createDocumentFragment();
+ frag.appendChild(clone);
+ return frag;
+ } else {
+ var iterator = new RangeIterator(this, true);
+ clone = cloneSubtree(iterator);
+ iterator.detach();
+ }
+ return clone;
+ }
+ },
+
+ canSurroundContents: function() {
+ assertRangeValid(this);
+ assertNodeNotReadOnly(this.startContainer);
+ assertNodeNotReadOnly(this.endContainer);
+
+ // Check if the contents can be surrounded. Specifically, this means whether the range partially selects
+ // no non-text nodes.
+ var iterator = new RangeIterator(this, true);
+ var boundariesInvalid = (iterator._first && (isNonTextPartiallySelected(iterator._first, this)) ||
+ (iterator._last && isNonTextPartiallySelected(iterator._last, this)));
+ iterator.detach();
+ return !boundariesInvalid;
+ },
+
+ surroundContents: function(node) {
+ assertValidNodeType(node, surroundNodeTypes);
+
+ if (!this.canSurroundContents()) {
+ throw new DOMException("INVALID_STATE_ERR");
+ }
+
+ // Extract the contents
+ var content = this.extractContents();
+
+ // Clear the children of the node
+ if (node.hasChildNodes()) {
+ while (node.lastChild) {
+ node.removeChild(node.lastChild);
+ }
+ }
+
+ // Insert the new node and add the extracted contents
+ insertNodeAtPosition(node, this.startContainer, this.startOffset);
+ node.appendChild(content);
+
+ this.selectNode(node);
+ },
+
+ cloneRange: function() {
+ assertRangeValid(this);
+ var range = new Range(getRangeDocument(this));
+ var i = rangeProperties.length, prop;
+ while (i--) {
+ prop = rangeProperties[i];
+ range[prop] = this[prop];
+ }
+ return range;
+ },
+
+ toString: function() {
+ assertRangeValid(this);
+ var sc = this.startContainer;
+ if (sc === this.endContainer && isCharacterDataNode(sc)) {
+ return (sc.nodeType == 3 || sc.nodeType == 4) ? sc.data.slice(this.startOffset, this.endOffset) : "";
+ } else {
+ var textParts = [], iterator = new RangeIterator(this, true);
+ iterateSubtree(iterator, function(node) {
+ // Accept only text or CDATA nodes, not comments
+ if (node.nodeType == 3 || node.nodeType == 4) {
+ textParts.push(node.data);
+ }
+ });
+ iterator.detach();
+ return textParts.join("");
+ }
+ },
+
+ // The methods below are all non-standard. The following batch were introduced by Mozilla but have since
+ // been removed from Mozilla.
+
+ compareNode: function(node) {
+ assertRangeValid(this);
+
+ var parent = node.parentNode;
+ var nodeIndex = getNodeIndex(node);
+
+ if (!parent) {
+ throw new DOMException("NOT_FOUND_ERR");
+ }
+
+ var startComparison = this.comparePoint(parent, nodeIndex),
+ endComparison = this.comparePoint(parent, nodeIndex + 1);
+
+ if (startComparison < 0) { // Node starts before
+ return (endComparison > 0) ? n_b_a : n_b;
+ } else {
+ return (endComparison > 0) ? n_a : n_i;
+ }
+ },
+
+ comparePoint: function(node, offset) {
+ assertRangeValid(this);
+ assertNode(node, "HIERARCHY_REQUEST_ERR");
+ assertSameDocumentOrFragment(node, this.startContainer);
+
+ if (comparePoints(node, offset, this.startContainer, this.startOffset) < 0) {
+ return -1;
+ } else if (comparePoints(node, offset, this.endContainer, this.endOffset) > 0) {
+ return 1;
+ }
+ return 0;
+ },
+
+ createContextualFragment: createContextualFragment,
+
+ toHtml: function() {
+ return rangeToHtml(this);
+ },
+
+ // touchingIsIntersecting determines whether this method considers a node that borders a range intersects
+ // with it (as in WebKit) or not (as in Gecko pre-1.9, and the default)
+ intersectsNode: function(node, touchingIsIntersecting) {
+ assertRangeValid(this);
+ assertNode(node, "NOT_FOUND_ERR");
+ if (getDocument(node) !== getRangeDocument(this)) {
+ return false;
+ }
+
+ var parent = node.parentNode, offset = getNodeIndex(node);
+ assertNode(parent, "NOT_FOUND_ERR");
+
+ var startComparison = comparePoints(parent, offset, this.endContainer, this.endOffset),
+ endComparison = comparePoints(parent, offset + 1, this.startContainer, this.startOffset);
+
+ return touchingIsIntersecting ? startComparison <= 0 && endComparison >= 0 : startComparison < 0 && endComparison > 0;
+ },
+
+ isPointInRange: function(node, offset) {
+ assertRangeValid(this);
+ assertNode(node, "HIERARCHY_REQUEST_ERR");
+ assertSameDocumentOrFragment(node, this.startContainer);
+
+ return (comparePoints(node, offset, this.startContainer, this.startOffset) >= 0) &&
+ (comparePoints(node, offset, this.endContainer, this.endOffset) <= 0);
+ },
+
+ // The methods below are non-standard and invented by me.
+
+ // Sharing a boundary start-to-end or end-to-start does not count as intersection.
+ intersectsRange: function(range) {
+ return rangesIntersect(this, range, false);
+ },
+
+ // Sharing a boundary start-to-end or end-to-start does count as intersection.
+ intersectsOrTouchesRange: function(range) {
+ return rangesIntersect(this, range, true);
+ },
+
+ intersection: function(range) {
+ if (this.intersectsRange(range)) {
+ var startComparison = comparePoints(this.startContainer, this.startOffset, range.startContainer, range.startOffset),
+ endComparison = comparePoints(this.endContainer, this.endOffset, range.endContainer, range.endOffset);
+
+ var intersectionRange = this.cloneRange();
+ if (startComparison == -1) {
+ intersectionRange.setStart(range.startContainer, range.startOffset);
+ }
+ if (endComparison == 1) {
+ intersectionRange.setEnd(range.endContainer, range.endOffset);
+ }
+ return intersectionRange;
+ }
+ return null;
+ },
+
+ union: function(range) {
+ if (this.intersectsOrTouchesRange(range)) {
+ var unionRange = this.cloneRange();
+ if (comparePoints(range.startContainer, range.startOffset, this.startContainer, this.startOffset) == -1) {
+ unionRange.setStart(range.startContainer, range.startOffset);
+ }
+ if (comparePoints(range.endContainer, range.endOffset, this.endContainer, this.endOffset) == 1) {
+ unionRange.setEnd(range.endContainer, range.endOffset);
+ }
+ return unionRange;
+ } else {
+ throw new DOMException("Ranges do not intersect");
+ }
+ },
+
+ containsNode: function(node, allowPartial) {
+ if (allowPartial) {
+ return this.intersectsNode(node, false);
+ } else {
+ return this.compareNode(node) == n_i;
+ }
+ },
+
+ containsNodeContents: function(node) {
+ return this.comparePoint(node, 0) >= 0 && this.comparePoint(node, getNodeLength(node)) <= 0;
+ },
+
+ containsRange: function(range) {
+ var intersection = this.intersection(range);
+ return intersection !== null && range.equals(intersection);
+ },
+
+ containsNodeText: function(node) {
+ var nodeRange = this.cloneRange();
+ nodeRange.selectNode(node);
+ var textNodes = nodeRange.getNodes([3]);
+ if (textNodes.length > 0) {
+ nodeRange.setStart(textNodes[0], 0);
+ var lastTextNode = textNodes.pop();
+ nodeRange.setEnd(lastTextNode, lastTextNode.length);
+ return this.containsRange(nodeRange);
+ } else {
+ return this.containsNodeContents(node);
+ }
+ },
+
+ getNodes: function(nodeTypes, filter) {
+ assertRangeValid(this);
+ return getNodesInRange(this, nodeTypes, filter);
+ },
+
+ getDocument: function() {
+ return getRangeDocument(this);
+ },
+
+ collapseBefore: function(node) {
+ this.setEndBefore(node);
+ this.collapse(false);
+ },
+
+ collapseAfter: function(node) {
+ this.setStartAfter(node);
+ this.collapse(true);
+ },
+
+ getBookmark: function(containerNode) {
+ var doc = getRangeDocument(this);
+ var preSelectionRange = api.createRange(doc);
+ containerNode = containerNode || dom.getBody(doc);
+ preSelectionRange.selectNodeContents(containerNode);
+ var range = this.intersection(preSelectionRange);
+ var start = 0, end = 0;
+ if (range) {
+ preSelectionRange.setEnd(range.startContainer, range.startOffset);
+ start = preSelectionRange.toString().length;
+ end = start + range.toString().length;
+ }
+
+ return {
+ start: start,
+ end: end,
+ containerNode: containerNode
+ };
+ },
+
+ moveToBookmark: function(bookmark) {
+ var containerNode = bookmark.containerNode;
+ var charIndex = 0;
+ this.setStart(containerNode, 0);
+ this.collapse(true);
+ var nodeStack = [containerNode], node, foundStart = false, stop = false;
+ var nextCharIndex, i, childNodes;
+
+ while (!stop && (node = nodeStack.pop())) {
+ if (node.nodeType == 3) {
+ nextCharIndex = charIndex + node.length;
+ if (!foundStart && bookmark.start >= charIndex && bookmark.start <= nextCharIndex) {
+ this.setStart(node, bookmark.start - charIndex);
+ foundStart = true;
+ }
+ if (foundStart && bookmark.end >= charIndex && bookmark.end <= nextCharIndex) {
+ this.setEnd(node, bookmark.end - charIndex);
+ stop = true;
+ }
+ charIndex = nextCharIndex;
+ } else {
+ childNodes = node.childNodes;
+ i = childNodes.length;
+ while (i--) {
+ nodeStack.push(childNodes[i]);
+ }
+ }
+ }
+ },
+
+ getName: function() {
+ return "DomRange";
+ },
+
+ equals: function(range) {
+ return Range.rangesEqual(this, range);
+ },
+
+ isValid: function() {
+ return isRangeValid(this);
+ },
+
+ inspect: function() {
+ return inspect(this);
+ },
+
+ detach: function() {
+ // In DOM4, detach() is now a no-op.
+ }
+ });
+
+ function copyComparisonConstantsToObject(obj) {
+ obj.START_TO_START = s2s;
+ obj.START_TO_END = s2e;
+ obj.END_TO_END = e2e;
+ obj.END_TO_START = e2s;
+
+ obj.NODE_BEFORE = n_b;
+ obj.NODE_AFTER = n_a;
+ obj.NODE_BEFORE_AND_AFTER = n_b_a;
+ obj.NODE_INSIDE = n_i;
+ }
+
+ function copyComparisonConstants(constructor) {
+ copyComparisonConstantsToObject(constructor);
+ copyComparisonConstantsToObject(constructor.prototype);
+ }
+
+ function createRangeContentRemover(remover, boundaryUpdater) {
+ return function() {
+ assertRangeValid(this);
+
+ var sc = this.startContainer, so = this.startOffset, root = this.commonAncestorContainer;
+
+ var iterator = new RangeIterator(this, true);
+
+ // Work out where to position the range after content removal
+ var node, boundary;
+ if (sc !== root) {
+ node = getClosestAncestorIn(sc, root, true);
+ boundary = getBoundaryAfterNode(node);
+ sc = boundary.node;
+ so = boundary.offset;
+ }
+
+ // Check none of the range is read-only
+ iterateSubtree(iterator, assertNodeNotReadOnly);
+
+ iterator.reset();
+
+ // Remove the content
+ var returnValue = remover(iterator);
+ iterator.detach();
+
+ // Move to the new position
+ boundaryUpdater(this, sc, so, sc, so);
+
+ return returnValue;
+ };
+ }
+
+ function createPrototypeRange(constructor, boundaryUpdater) {
+ function createBeforeAfterNodeSetter(isBefore, isStart) {
+ return function(node) {
+ assertValidNodeType(node, beforeAfterNodeTypes);
+ assertValidNodeType(getRootContainer(node), rootContainerNodeTypes);
+
+ var boundary = (isBefore ? getBoundaryBeforeNode : getBoundaryAfterNode)(node);
+ (isStart ? setRangeStart : setRangeEnd)(this, boundary.node, boundary.offset);
+ };
+ }
+
+ function setRangeStart(range, node, offset) {
+ var ec = range.endContainer, eo = range.endOffset;
+ if (node !== range.startContainer || offset !== range.startOffset) {
+ // Check the root containers of the range and the new boundary, and also check whether the new boundary
+ // is after the current end. In either case, collapse the range to the new position
+ if (getRootContainer(node) != getRootContainer(ec) || comparePoints(node, offset, ec, eo) == 1) {
+ ec = node;
+ eo = offset;
+ }
+ boundaryUpdater(range, node, offset, ec, eo);
+ }
+ }
+
+ function setRangeEnd(range, node, offset) {
+ var sc = range.startContainer, so = range.startOffset;
+ if (node !== range.endContainer || offset !== range.endOffset) {
+ // Check the root containers of the range and the new boundary, and also check whether the new boundary
+ // is after the current end. In either case, collapse the range to the new position
+ if (getRootContainer(node) != getRootContainer(sc) || comparePoints(node, offset, sc, so) == -1) {
+ sc = node;
+ so = offset;
+ }
+ boundaryUpdater(range, sc, so, node, offset);
+ }
+ }
+
+ // Set up inheritance
+ var F = function() {};
+ F.prototype = api.rangePrototype;
+ constructor.prototype = new F();
+
+ util.extend(constructor.prototype, {
+ setStart: function(node, offset) {
+ assertNoDocTypeNotationEntityAncestor(node, true);
+ assertValidOffset(node, offset);
+
+ setRangeStart(this, node, offset);
+ },
+
+ setEnd: function(node, offset) {
+ assertNoDocTypeNotationEntityAncestor(node, true);
+ assertValidOffset(node, offset);
+
+ setRangeEnd(this, node, offset);
+ },
+
+ /**
+ * Convenience method to set a range's start and end boundaries. Overloaded as follows:
+ * - Two parameters (node, offset) creates a collapsed range at that position
+ * - Three parameters (node, startOffset, endOffset) creates a range contained with node starting at
+ * startOffset and ending at endOffset
+ * - Four parameters (startNode, startOffset, endNode, endOffset) creates a range starting at startOffset in
+ * startNode and ending at endOffset in endNode
+ */
+ setStartAndEnd: function() {
+ var args = arguments;
+ var sc = args[0], so = args[1], ec = sc, eo = so;
+
+ switch (args.length) {
+ case 3:
+ eo = args[2];
+ break;
+ case 4:
+ ec = args[2];
+ eo = args[3];
+ break;
+ }
+
+ boundaryUpdater(this, sc, so, ec, eo);
+ },
+
+ setBoundary: function(node, offset, isStart) {
+ this["set" + (isStart ? "Start" : "End")](node, offset);
+ },
+
+ setStartBefore: createBeforeAfterNodeSetter(true, true),
+ setStartAfter: createBeforeAfterNodeSetter(false, true),
+ setEndBefore: createBeforeAfterNodeSetter(true, false),
+ setEndAfter: createBeforeAfterNodeSetter(false, false),
+
+ collapse: function(isStart) {
+ assertRangeValid(this);
+ if (isStart) {
+ boundaryUpdater(this, this.startContainer, this.startOffset, this.startContainer, this.startOffset);
+ } else {
+ boundaryUpdater(this, this.endContainer, this.endOffset, this.endContainer, this.endOffset);
+ }
+ },
+
+ selectNodeContents: function(node) {
+ assertNoDocTypeNotationEntityAncestor(node, true);
+
+ boundaryUpdater(this, node, 0, node, getNodeLength(node));
+ },
+
+ selectNode: function(node) {
+ assertNoDocTypeNotationEntityAncestor(node, false);
+ assertValidNodeType(node, beforeAfterNodeTypes);
+
+ var start = getBoundaryBeforeNode(node), end = getBoundaryAfterNode(node);
+ boundaryUpdater(this, start.node, start.offset, end.node, end.offset);
+ },
+
+ extractContents: createRangeContentRemover(extractSubtree, boundaryUpdater),
+
+ deleteContents: createRangeContentRemover(deleteSubtree, boundaryUpdater),
+
+ canSurroundContents: function() {
+ assertRangeValid(this);
+ assertNodeNotReadOnly(this.startContainer);
+ assertNodeNotReadOnly(this.endContainer);
+
+ // Check if the contents can be surrounded. Specifically, this means whether the range partially selects
+ // no non-text nodes.
+ var iterator = new RangeIterator(this, true);
+ var boundariesInvalid = (iterator._first && isNonTextPartiallySelected(iterator._first, this) ||
+ (iterator._last && isNonTextPartiallySelected(iterator._last, this)));
+ iterator.detach();
+ return !boundariesInvalid;
+ },
+
+ splitBoundaries: function() {
+ splitRangeBoundaries(this);
+ },
+
+ splitBoundariesPreservingPositions: function(positionsToPreserve) {
+ splitRangeBoundaries(this, positionsToPreserve);
+ },
+
+ normalizeBoundaries: function() {
+ assertRangeValid(this);
+
+ var sc = this.startContainer, so = this.startOffset, ec = this.endContainer, eo = this.endOffset;
+
+ var mergeForward = function(node) {
+ var sibling = node.nextSibling;
+ if (sibling && sibling.nodeType == node.nodeType) {
+ ec = node;
+ eo = node.length;
+ node.appendData(sibling.data);
+ sibling.parentNode.removeChild(sibling);
+ }
+ };
+
+ var mergeBackward = function(node) {
+ var sibling = node.previousSibling;
+ if (sibling && sibling.nodeType == node.nodeType) {
+ sc = node;
+ var nodeLength = node.length;
+ so = sibling.length;
+ node.insertData(0, sibling.data);
+ sibling.parentNode.removeChild(sibling);
+ if (sc == ec) {
+ eo += so;
+ ec = sc;
+ } else if (ec == node.parentNode) {
+ var nodeIndex = getNodeIndex(node);
+ if (eo == nodeIndex) {
+ ec = node;
+ eo = nodeLength;
+ } else if (eo > nodeIndex) {
+ eo--;
+ }
+ }
+ }
+ };
+
+ var normalizeStart = true;
+
+ if (isCharacterDataNode(ec)) {
+ if (ec.length == eo) {
+ mergeForward(ec);
+ }
+ } else {
+ if (eo > 0) {
+ var endNode = ec.childNodes[eo - 1];
+ if (endNode && isCharacterDataNode(endNode)) {
+ mergeForward(endNode);
+ }
+ }
+ normalizeStart = !this.collapsed;
+ }
+
+ if (normalizeStart) {
+ if (isCharacterDataNode(sc)) {
+ if (so == 0) {
+ mergeBackward(sc);
+ }
+ } else {
+ if (so < sc.childNodes.length) {
+ var startNode = sc.childNodes[so];
+ if (startNode && isCharacterDataNode(startNode)) {
+ mergeBackward(startNode);
+ }
+ }
+ }
+ } else {
+ sc = ec;
+ so = eo;
+ }
+
+ boundaryUpdater(this, sc, so, ec, eo);
+ },
+
+ collapseToPoint: function(node, offset) {
+ assertNoDocTypeNotationEntityAncestor(node, true);
+ assertValidOffset(node, offset);
+ this.setStartAndEnd(node, offset);
+ }
+ });
+
+ copyComparisonConstants(constructor);
+ }
+
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ // Updates commonAncestorContainer and collapsed after boundary change
+ function updateCollapsedAndCommonAncestor(range) {
+ range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
+ range.commonAncestorContainer = range.collapsed ?
+ range.startContainer : dom.getCommonAncestor(range.startContainer, range.endContainer);
+ }
+
+ function updateBoundaries(range, startContainer, startOffset, endContainer, endOffset) {
+ range.startContainer = startContainer;
+ range.startOffset = startOffset;
+ range.endContainer = endContainer;
+ range.endOffset = endOffset;
+ range.document = dom.getDocument(startContainer);
+
+ updateCollapsedAndCommonAncestor(range);
+ }
+
+ function Range(doc) {
+ this.startContainer = doc;
+ this.startOffset = 0;
+ this.endContainer = doc;
+ this.endOffset = 0;
+ this.document = doc;
+ updateCollapsedAndCommonAncestor(this);
+ }
+
+ createPrototypeRange(Range, updateBoundaries);
+
+ util.extend(Range, {
+ rangeProperties: rangeProperties,
+ RangeIterator: RangeIterator,
+ copyComparisonConstants: copyComparisonConstants,
+ createPrototypeRange: createPrototypeRange,
+ inspect: inspect,
+ toHtml: rangeToHtml,
+ getRangeDocument: getRangeDocument,
+ rangesEqual: function(r1, r2) {
+ return r1.startContainer === r2.startContainer &&
+ r1.startOffset === r2.startOffset &&
+ r1.endContainer === r2.endContainer &&
+ r1.endOffset === r2.endOffset;
+ }
+ });
+
+ api.DomRange = Range;
+ });\r
+\r
+ /*----------------------------------------------------------------------------------------------------------------*/\r
+\r
+ // Wrappers for the browser's native DOM Range and/or TextRange implementation
+ api.createCoreModule("WrappedRange", ["DomRange"], function(api, module) {
+ var WrappedRange, WrappedTextRange;
+ var dom = api.dom;
+ var util = api.util;
+ var DomPosition = dom.DomPosition;
+ var DomRange = api.DomRange;
+ var getBody = dom.getBody;
+ var getContentDocument = dom.getContentDocument;
+ var isCharacterDataNode = dom.isCharacterDataNode;
+
+
+ /*----------------------------------------------------------------------------------------------------------------*/
+
+ if (api.features.implementsDomRange) {
+ // This is a wrapper around the browser's native DOM Range. It has two aims:
+ // - Provide workarounds for specific browser bugs
+ // - provide convenient extensions, which are inherited from Rangy's DomRange
+
+ (function() {
+ var rangeProto;
+ var rangeProperties = DomRange.rangeProperties;
+
+ function updateRangeProperties(range) {
+ var i = rangeProperties.length, prop;
+ while (i--) {
+ prop = rangeProperties[i];
+ range[prop] = range.nativeRange[prop];
+ }
+ // Fix for broken collapsed property in IE 9.
+ range.collapsed = (range.startContainer === range.endContainer && range.startOffset === range.endOffset);
+ }
+
+ function updateNativeRange(range, startContainer, startOffset, endContainer, endOffset) {
+ var startMoved = (range.startContainer !== startContainer || range.startOffset != startOffset);
+ var endMoved = (range.endContainer !== endContainer || range.endOffset != endOffset);
+ var nativeRangeDifferent = !range.equals(range.nativeRange);
+
+ // Always set both boundaries for the benefit of IE9 (see issue 35)
+ if (startMoved || endMoved || nativeRangeDifferent) {
+ range.setEnd(endContainer, endOffset);
+ range.setStart(startContainer, startOffset);
+ }
+ }
+
+ var createBeforeAfterNodeSetter;
+
+ WrappedRange = function(range) {
+ if (!range) {
+ throw module.createError("WrappedRange: Range must be specified");
+ }
+ this.nativeRange = range;
+ updateRangeProperties(this);
+ };
+
+ DomRange.createPrototypeRange(WrappedRange, updateNativeRange);
+
+ rangeProto = WrappedRange.prototype;
+
+ rangeProto.selectNode = function(node) {
+ this.nativeRange.selectNode(node);
+ updateRangeProperties(this);
+ };
+
+ rangeProto.cloneContents = function() {
+ return this.nativeRange.cloneContents();
+ };
+
+ // Due to a long-standing Firefox bug that I have not been able to find a reliable way to detect,
+ // insertNode() is never delegated to the native range.
+
+ rangeProto.surroundContents = function(node) {
+ this.nativeRange.surroundContents(node);
+ updateRangeProperties(this);
+ };
+
+ rangeProto.collapse = function(isStart) {
+ this.nativeRange.collapse(isStart);
+ updateRangeProperties(this);
+ };
+
+ rangeProto.cloneRange = function() {
+ return new WrappedRange(this.nativeRange.cloneRange());
+ };
+
+ rangeProto.refresh = function() {
+ updateRangeProperties(this);
+ };
+
+ rangeProto.toString = function() {
+ return this.nativeRange.toString();
+ };
+
+ // Create test range and node for feature detection
+
+ var testTextNode = document.createTextNode("test");
+ getBody(document).appendChild(testTextNode);
+ var range = document.createRange();
+
+ /*--------------------------------------------------------------------------------------------------------*/
+
+ // Test for Firefox 2 bug that prevents moving the start of a Range to a point after its current end and
+ // correct for it
+
+ range.setStart(testTextNode, 0);
+ range.setEnd(testTextNode, 0);
+
+ try {
+ range.setStart(testTextNode, 1);
+
+ rangeProto.setStart = function(node, offset) {
+ this.nativeRange.setStart(node, offset);
+ updateRangeProperties(this);
+ };
+
+ rangeProto.setEnd = function(node, offset) {
+ this.nativeRange.setEnd(node, offset);
+ updateRangeProperties(this);
+ };
+
+ createBeforeAfterNodeSetter = function(name) {
+ return function(node) {
+ this.nativeRange[name](node);
+ updateRangeProperties(this);
+ };
+ };
+
+ } catch(ex) {
+
+ rangeProto.setStart = function(node, offset) {
+ try {
+ this.nativeRange.setStart(node, offset);
+ } catch (ex) {
+ this.nativeRange.setEnd(node, offset);
+ this.nativeRange.setStart(node, offset);
+ }
+ updateRangeProperties(this);
+ };
+
+ rangeProto.setEnd = function(node, offset) {
+ try {
+ this.nativeRange.setEnd(node, offset);
+ } catch (ex) {
+ this.nativeRange.setStart(node, offset);
+ this.nativeRange.setEnd(node, offset);
+ }
+ updateRangeProperties(this);
+ };
+
+ createBeforeAfterNodeSetter = function(name, oppositeName) {
+ return function(node) {
+ try {
+ this.nativeRange[name](node);
+ } catch (ex) {
+ this.nativeRange[oppositeName](node);
+ this.nativeRange[name](node);
+ }
+ updateRangeProperties(this);
+ };
+ };
+ }
+
+ rangeProto.setStartBefore = createBeforeAfterNodeSetter("setStartBefore", "setEndBefore");
+ rangeProto.setStartAfter = createBeforeAfterNodeSetter("setStartAfter", "setEndAfter");
+ rangeProto.setEndBefore = createBeforeAfterNodeSetter("setEndBefore", "setStartBefore");
+ rangeProto.setEndAfter = createBeforeAfterNodeSetter("setEndAfter", "setStartAfter");
+
+ /*--------------------------------------------------------------------------------------------------------*/
+
+ // Always use DOM4-compliant selectNodeContents implementation: it's simpler and less code than testing
+ // whether the native implementation can be trusted
+ rangeProto.selectNodeContents = function(node) {
+ this.setStartAndEnd(node, 0, dom.getNodeLength(node));
+ };
+
+ /*--------------------------------------------------------------------------------------------------------*/
+
+ // Test for and correct WebKit bug that has the behaviour of compareBoundaryPoints round the wrong way for
+ // constants START_TO_END and END_TO_START: https://bugs.webkit.org/show_bug.cgi?id=20738
+
+ range.selectNodeContents(testTextNode);
+ range.setEnd(testTextNode, 3);
+
+ var range2 = document.createRange();
+ range2.selectNodeContents(testTextNode);
+ range2.setEnd(testTextNode, 4);
+ range2.setStart(testTextNode, 2);
+
+ if (range.compareBoundaryPoints(range.START_TO_END, range2) == -1 &&
+ range.compareBoundaryPoints(range.END_TO_START, range2) == 1) {
+ // This is the wrong way round, so correct for it
+
+ rangeProto.compareBoundaryPoints = function(type, range) {
+ range = range.nativeRange || range;
+ if (type == range.START_TO_END) {
+ type = range.END_TO_START;
+ } else if (type == range.END_TO_START) {
+ type = range.START_TO_END;
+ }
+ return this.nativeRange.compareBoundaryPoints(type, range);
+ };
+ } else {
+ rangeProto.compareBoundaryPoints = function(type, range) {
+ return this.nativeRange.compareBoundaryPoints(type, range.nativeRange || range);
+ };
+ }
+
+ /*--------------------------------------------------------------------------------------------------------*/
+
+ // Test for IE deleteContents() and extractContents() bug and correct it. See issue 107.
+
+ var el = document.createElement("div");
+ el.innerHTML = "123";
+ var textNode = el.firstChild;
+ var body = getBody(document);
+ body.appendChild(el);
+
+ range.setStart(textNode, 1);
+ range.setEnd(textNode, 2);
+ range.deleteContents();
+
+ if (textNode.data == "13") {
+ // Behaviour is correct per DOM4 Range so wrap the browser's implementation of deleteContents() and
+ // extractContents()
+ rangeProto.deleteContents = function() {
+ this.nativeRange.deleteContents();
+ updateRangeProperties(this);
+ };
+
+ rangeProto.extractContents = function() {
+ var frag = this.nativeRange.extractContents();
+ updateRangeProperties(this);
+ return frag;
+ };
+ } else {
+ }
+
+ body.removeChild(el);
+ body = null;
+
+ /*--------------------------------------------------------------------------------------------------------*/
+
+ // Test for existence of createContextualFragment and delegate to it if it exists
+ if (util.isHostMethod(range, "createContextualFragment")) {
+ rangeProto.createContextualFragment = function(fragmentStr) {
+ return this.nativeRange.createContextualFragment(fragmentStr);
+ };
+ }
+
+ /*--------------------------------------------------------------------------------------------------------*/
+
+ // Clean up
+ getBody(document).removeChild(testTextNode);
+
+ rangeProto.getName = function() {
+ return "WrappedRange";
+ };
+
+ api.WrappedRange = WrappedRange;
+
+ api.createNativeRange = function(doc) {
+ doc = getContentDocument(doc, module, "createNativeRange");
+ return doc.createRange();
+ };
+ })();
+ }
+
+ if (api.features.implementsTextRange) {
+ /*
+ This is a workaround for a bug where IE returns the wrong container element from the TextRange's parentElement()
+ method. For example, in the following (where pipes denote the selection boundaries):
+
+ <ul id="ul"><li id="a">| a </li><li id="b"> b |</li></ul>
+
+ var range = document.selection.createRange();
+ alert(range.parentElement().id); // Should alert "ul" but alerts "b"
+
+ This method returns the common ancestor node of the following:
+ - the parentElement() of the textRange
+ - the parentElement() of the textRange after calling collapse(true)
+ - the parentElement() of the textRange after calling collapse(false)
+ */
+ var getTextRangeContainerElement = function(textRange) {
+ var parentEl = textRange.parentElement();
+ var range = textRange.duplicate();
+ range.collapse(true);
+ var startEl = range.parentElement();
+ range = textRange.duplicate();
+ range.collapse(false);
+ var endEl = range.parentElement();
+ var startEndContainer = (startEl == endEl) ? startEl : dom.getCommonAncestor(startEl, endEl);
+
+ return startEndContainer == parentEl ? startEndContainer : dom.getCommonAncestor(parentEl, startEndContainer);
+ };
+
+ var textRangeIsCollapsed = function(textRange) {
+ return textRange.compareEndPoints("StartToEnd", textRange) == 0;
+ };
+
+ // Gets the boundary of a TextRange expressed as a node and an offset within that node. This function started
+ // out as an improved version of code found in Tim Cameron Ryan's IERange (http://code.google.com/p/ierange/)
+ // but has grown, fixing problems with line breaks in preformatted text, adding workaround for IE TextRange
+ // bugs, handling for inputs and images, plus optimizations.
+ var getTextRangeBoundaryPosition = function(textRange, wholeRangeContainerElement, isStart, isCollapsed, startInfo) {
+ var workingRange = textRange.duplicate();
+ workingRange.collapse(isStart);
+ var containerElement = workingRange.parentElement();
+
+ // Sometimes collapsing a TextRange that's at the start of a text node can move it into the previous node, so
+ // check for that
+ if (!dom.isOrIsAncestorOf(wholeRangeContainerElement, containerElement)) {
+ containerElement = wholeRangeContainerElement;
+ }
+
+
+ // Deal with nodes that cannot "contain rich HTML markup". In practice, this means form inputs, images and
+ // similar. See http://msdn.microsoft.com/en-us/library/aa703950%28VS.85%29.aspx
+ if (!containerElement.canHaveHTML) {
+ var pos = new DomPosition(containerElement.parentNode, dom.getNodeIndex(containerElement));
+ return {
+ boundaryPosition: pos,
+ nodeInfo: {
+ nodeIndex: pos.offset,
+ containerElement: pos.node
+ }
+ };
+ }
+
+ var workingNode = dom.getDocument(containerElement).createElement("span");
+
+ // Workaround for HTML5 Shiv's insane violation of document.createElement(). See Rangy issue 104 and HTML5
+ // Shiv issue 64: https://github.com/aFarkas/html5shiv/issues/64
+ if (workingNode.parentNode) {
+ workingNode.parentNode.removeChild(workingNode);
+ }
+
+ var comparison, workingComparisonType = isStart ? "StartToStart" : "StartToEnd";
+ var previousNode, nextNode, boundaryPosition, boundaryNode;
+ var start = (startInfo && startInfo.containerElement == containerElement) ? startInfo.nodeIndex : 0;
+ var childNodeCount = containerElement.childNodes.length;
+ var end = childNodeCount;
+
+ // Check end first. Code within the loop assumes that the endth child node of the container is definitely
+ // after the range boundary.
+ var nodeIndex = end;
+
+ while (true) {
+ if (nodeIndex == childNodeCount) {
+ containerElement.appendChild(workingNode);
+ } else {
+ containerElement.insertBefore(workingNode, containerElement.childNodes[nodeIndex]);
+ }
+ workingRange.moveToElementText(workingNode);
+ comparison = workingRange.compareEndPoints(workingComparisonType, textRange);
+ if (comparison == 0 || start == end) {
+ break;
+ } else if (comparison == -1) {
+ if (end == start + 1) {
+ // We know the endth child node is after the range boundary, so we must be done.
+ break;
+ } else {
+ start = nodeIndex;
+ }
+ } else {
+ end = (end == start + 1) ? start : nodeIndex;
+ }
+ nodeIndex = Math.floor((start + end) / 2);
+ containerElement.removeChild(workingNode);
+ }
+
+
+ // We've now reached or gone past the boundary of the text range we're interested in
+ // so have identified the node we want
+ boundaryNode = workingNode.nextSibling;
+
+ if (comparison == -1 && boundaryNode && isCharacterDataNode(boundaryNode)) {
+ // This is a character data node (text, comment, cdata). The working range is collapsed at the start of
+ // the node containing the text range's boundary, so we move the end of the working range to the
+ // boundary point and measure the length of its text to get the boundary's offset within the node.
+ workingRange.setEndPoint(isStart ? "EndToStart" : "EndToEnd", textRange);
+
+ var offset;
+
+ if (/[\r\n]/.test(boundaryNode.data)) {
+ /*
+ For the particular case of a boundary within a text node containing rendered line breaks (within a
+ <pre> element, for example), we need a slightly complicated approach to get the boundary's offset in
+ IE. The facts:
+
+ - Each line break is represented as \r in the text node's data/nodeValue properties
+ - Each line break is represented as \r\n in the TextRange's 'text' property
+ - The 'text' property of the TextRange does not contain trailing line breaks
+
+ To get round the problem presented by the final fact above, we can use the fact that TextRange's
+ moveStart() and moveEnd() methods return the actual number of characters moved, which is not
+ necessarily the same as the number of characters it was instructed to move. The simplest approach is
+ to use this to store the characters moved when moving both the start and end of the range to the
+ start of the document body and subtracting the start offset from the end offset (the
+ "move-negative-gazillion" method). However, this is extremely slow when the document is large and
+ the range is near the end of it. Clearly doing the mirror image (i.e. moving the range boundaries to
+ the end of the document) has the same problem.
+
+ Another approach that works is to use moveStart() to move the start boundary of the range up to the
+ end boundary one character at a time and incrementing a counter with the value returned by the
+ moveStart() call. However, the check for whether the start boundary has reached the end boundary is
+ expensive, so this method is slow (although unlike "move-negative-gazillion" is largely unaffected
+ by the location of the range within the document).
+
+ The approach used below is a hybrid of the two methods above. It uses the fact that a string
+ containing the TextRange's 'text' property with each \r\n converted to a single \r character cannot
+ be longer than the text of the TextRange, so the start of the range is moved that length initially
+ and then a character at a time to make up for any trailing line breaks not contained in the 'text'
+ property. This has good performance in most situations compared to the previous two methods.
+ */
+ var tempRange = workingRange.duplicate();
+ var rangeLength = tempRange.text.replace(/\r\n/g, "\r").length;
+
+ offset = tempRange.moveStart("character", rangeLength);
+ while ( (comparison = tempRange.compareEndPoints("StartToEnd", tempRange)) == -1) {
+ offset++;
+ tempRange.moveStart("character", 1);
+ }
+ } else {
+ offset = workingRange.text.length;
+ }
+ boundaryPosition = new DomPosition(boundaryNode, offset);
+ } else {
+
+ // If the boundary immediately follows a character data node and this is the end boundary, we should favour
+ // a position within that, and likewise for a start boundary preceding a character data node
+ previousNode = (isCollapsed || !isStart) && workingNode.previousSibling;
+ nextNode = (isCollapsed || isStart) && workingNode.nextSibling;
+ if (nextNode && isCharacterDataNode(nextNode)) {
+ boundaryPosition = new DomPosition(nextNode, 0);
+ } else if (previousNode && isCharacterDataNode(previousNode)) {
+ boundaryPosition = new DomPosition(previousNode, previousNode.data.length);
+ } else {
+ boundaryPosition = new DomPosition(containerElement, dom.getNodeIndex(workingNode));
+ }
+ }
+
+ // Clean up
+ workingNode.parentNode.removeChild(workingNode);
+
+ return {
+ boundaryPosition: boundaryPosition,
+ nodeInfo: {
+ nodeIndex: nodeIndex,
+ containerElement: containerElement
+ }
+ };
+ };
+
+ // Returns a TextRange representing the boundary of a TextRange expressed as a node and an offset within that
+ // node. This function started out as an optimized version of code found in Tim Cameron Ryan's IERange
+ // (http://code.google.com/p/ierange/)
+ var createBoundaryTextRange = function(boundaryPosition, isStart) {
+ var boundaryNode, boundaryParent, boundaryOffset = boundaryPosition.offset;
+ var doc = dom.getDocument(boundaryPosition.node);
+ var workingNode, childNodes, workingRange = getBody(doc).createTextRange();
+ var nodeIsDataNode = isCharacterDataNode(boundaryPosition.node);
+
+ if (nodeIsDataNode) {
+ boundaryNode = boundaryPosition.node;
+ boundaryParent = boundaryNode.parentNode;
+ } else {
+ childNodes = boundaryPosition.node.childNodes;
+ boundaryNode = (boundaryOffset < childNodes.length) ? childNodes[boundaryOffset] : null;
+ boundaryParent = boundaryPosition.node;
+ }
+
+ // Position the range immediately before the node containing the boundary
+ workingNode = doc.createElement("span");
+
+ // Making the working element non-empty element persuades IE to consider the TextRange boundary to be within
+ // the element rather than immediately before or after it
+ workingNode.innerHTML = "&#feff;";
+
+ // insertBefore is supposed to work like appendChild if the second parameter is null. However, a bug report
+ // for IERange suggests that it can crash the browser: http://code.google.com/p/ierange/issues/detail?id=12
+ if (boundaryNode) {
+ boundaryParent.insertBefore(workingNode, boundaryNode);
+ } else {
+ boundaryParent.appendChild(workingNode);
+ }
+
+ workingRange.moveToElementText(workingNode);
+ workingRange.collapse(!isStart);
+
+ // Clean up
+ boundaryParent.removeChild(workingNode);
+
+ // Move the working range to the text offset, if required
+ if (nodeIsDataNode) {
+ workingRange[isStart ? "moveStart" : "moveEnd"]("character", boundaryOffset);
+ }
+
+ return workingRange;
+ };
+
+ /*------------------------------------------------------------------------------------------------------------*/
+
+ // This is a wrapper around a TextRange, providing full DOM Range functionality using rangy's DomRange as a
+ // prototype
+
+ WrappedTextRange = function(textRange) {
+ this.textRange = textRange;
+ this.refresh();
+ };
+
+ WrappedTextRange.prototype = new DomRange(document);
+
+ WrappedTextRange.prototype.refresh = function() {
+ var start, end, startBoundary;
+
+ // TextRange's parentElement() method cannot be trusted. getTextRangeContainerElement() works around that.
+ var rangeContainerElement = getTextRangeContainerElement(this.textRange);
+
+ if (textRangeIsCollapsed(this.textRange)) {
+ end = start = getTextRangeBoundaryPosition(this.textRange, rangeContainerElement, true,
+ true).boundaryPosition;
+ } else {
+ startBoundary = getTextRangeBoundaryPosition(this.textRange, rangeContainerElement, true, false);
+ start = startBoundary.boundaryPosition;
+
+ // An optimization used here is that if the start and end boundaries have the same parent element, the
+ // search scope for the end boundary can be limited to exclude the portion of the element that precedes
+ // the start boundary
+ end = getTextRangeBoundaryPosition(this.textRange, rangeContainerElement, false, false,
+ startBoundary.nodeInfo).boundaryPosition;
+ }
+
+ this.setStart(start.node, start.offset);
+ this.setEnd(end.node, end.offset);
+ };
+
+ WrappedTextRange.prototype.getName = function() {
+ return "WrappedTextRange";
+ };
+
+ DomRange.copyComparisonConstants(WrappedTextRange);
+
+ var rangeToTextRange = function(range) {
+ if (range.collapsed) {
+ return createBoundaryTextRange(new DomPosition(range.startContainer, range.startOffset), true);
+ } else {
+ var startRange = createBoundaryTextRange(new DomPosition(range.startContainer, range.startOffset), true);
+ var endRange = createBoundaryTextRange(new DomPosition(range.endContainer, range.endOffset), false);
+ var textRange = getBody( DomRange.getRangeDocument(range) ).createTextRange();
+ textRange.setEndPoint("StartToStart", startRange);
+ textRange.setEndPoint("EndToEnd", endRange);
+ return textRange;
+ }
+ };
+
+ WrappedTextRange.rangeToTextRange = rangeToTextRange;
+
+ WrappedTextRange.prototype.toTextRange = function() {
+ return rangeToTextRange(this);
+ };
+
+ api.WrappedTextRange = WrappedTextRange;
+
+ // IE 9 and above have both implementations and Rangy makes both available. The next few lines sets which
+ // implementation to use by default.
+ if (!api.features.implementsDomRange || api.config.preferTextRange) {
+ // Add WrappedTextRange as the Range property of the global object to allow expression like Range.END_TO_END to work
+ var globalObj = (function(f) { return f("return this;")(); })(Function);
+ if (typeof globalObj.Range == "undefined") {
+ globalObj.Range = WrappedTextRange;
+ }
+
+ api.createNativeRange = function(doc) {
+ doc = getContentDocument(doc, module, "createNativeRange");
+ return getBody(doc).createTextRange();
+ };
+
+ api.WrappedRange = WrappedTextRange;
+ }
+ }
+
+ api.createRange = function(doc) {
+ doc = getContentDocument(doc, module, "createRange");
+ return new api.WrappedRange(api.createNativeRange(doc));
+ };
+
+ api.createRangyRange = function(doc) {
+ doc = getContentDocument(doc, module, "createRangyRange");
+ return new DomRange(doc);
+ };
+
+ api.createIframeRange = function(iframeEl) {
+ module.deprecationNotice("createIframeRange()", "createRange(iframeEl)");
+ return api.createRange(iframeEl);
+ };
+
+ api.createIframeRangyRange = function(iframeEl) {
+ module.deprecationNotice("createIframeRangyRange()", "createRangyRange(iframeEl)");
+ return api.createRangyRange(iframeEl);
+ };
+
+ api.addShimListener(function(win) {
+ var doc = win.document;
+ if (typeof doc.createRange == "undefined") {
+ doc.createRange = function() {
+ return api.createRange(doc);
+ };
+ }
+ doc = win = null;
+ });
+ });\r
+\r
+ /*----------------------------------------------------------------------------------------------------------------*/\r
+\r
+ // This module creates a selection object wrapper that conforms as closely as possible to the Selection specification
+ // in the HTML Editing spec (http://dvcs.w3.org/hg/editing/raw-file/tip/editing.html#selections)
+ api.createCoreModule("WrappedSelection", ["DomRange", "WrappedRange"], function(api, module) {
+ api.config.checkSelectionRanges = true;
+
+ var BOOLEAN = "boolean";
+ var NUMBER = "number";
+ var dom = api.dom;
+ var util = api.util;
+ var isHostMethod = util.isHostMethod;
+ var DomRange = api.DomRange;
+ var WrappedRange = api.WrappedRange;
+ var DOMException = api.DOMException;
+ var DomPosition = dom.DomPosition;
+ var getNativeSelection;
+ var selectionIsCollapsed;
+ var features = api.features;
+ var CONTROL = "Control";
+ var getDocument = dom.getDocument;
+ var getBody = dom.getBody;
+ var rangesEqual = DomRange.rangesEqual;
+
+
+ // Utility function to support direction parameters in the API that may be a string ("backward" or "forward") or a
+ // Boolean (true for backwards).
+ function isDirectionBackward(dir) {
+ return (typeof dir == "string") ? /^backward(s)?$/i.test(dir) : !!dir;
+ }
+
+ function getWindow(win, methodName) {
+ if (!win) {
+ return window;
+ } else if (dom.isWindow(win)) {
+ return win;
+ } else if (win instanceof WrappedSelection) {
+ return win.win;
+ } else {
+ var doc = dom.getContentDocument(win, module, methodName);
+ return dom.getWindow(doc);
+ }
+ }
+
+ function getWinSelection(winParam) {
+ return getWindow(winParam, "getWinSelection").getSelection();
+ }
+
+ function getDocSelection(winParam) {
+ return getWindow(winParam, "getDocSelection").document.selection;
+ }
+
+ function winSelectionIsBackward(sel) {
+ var backward = false;
+ if (sel.anchorNode) {
+ backward = (dom.comparePoints(sel.anchorNode, sel.anchorOffset, sel.focusNode, sel.focusOffset) == 1);
+ }
+ return backward;
+ }
+
+ // Test for the Range/TextRange and Selection features required
+ // Test for ability to retrieve selection
+ var implementsWinGetSelection = isHostMethod(window, "getSelection"),
+ implementsDocSelection = util.isHostObject(document, "selection");
+
+ features.implementsWinGetSelection = implementsWinGetSelection;
+ features.implementsDocSelection = implementsDocSelection;
+
+ var useDocumentSelection = implementsDocSelection && (!implementsWinGetSelection || api.config.preferTextRange);
+
+ if (useDocumentSelection) {
+ getNativeSelection = getDocSelection;
+ api.isSelectionValid = function(winParam) {
+ var doc = getWindow(winParam, "isSelectionValid").document, nativeSel = doc.selection;
+
+ // Check whether the selection TextRange is actually contained within the correct document
+ return (nativeSel.type != "None" || getDocument(nativeSel.createRange().parentElement()) == doc);
+ };
+ } else if (implementsWinGetSelection) {
+ getNativeSelection = getWinSelection;
+ api.isSelectionValid = function() {
+ return true;
+ };
+ } else {
+ module.fail("Neither document.selection or window.getSelection() detected.");
+ }
+
+ api.getNativeSelection = getNativeSelection;
+
+ var testSelection = getNativeSelection();
+ var testRange = api.createNativeRange(document);
+ var body = getBody(document);
+
+ // Obtaining a range from a selection
+ var selectionHasAnchorAndFocus = util.areHostProperties(testSelection,
+ ["anchorNode", "focusNode", "anchorOffset", "focusOffset"]);
+
+ features.selectionHasAnchorAndFocus = selectionHasAnchorAndFocus;
+
+ // Test for existence of native selection extend() method
+ var selectionHasExtend = isHostMethod(testSelection, "extend");
+ features.selectionHasExtend = selectionHasExtend;
+
+ // Test if rangeCount exists
+ var selectionHasRangeCount = (typeof testSelection.rangeCount == NUMBER);
+ features.selectionHasRangeCount = selectionHasRangeCount;
+
+ var selectionSupportsMultipleRanges = false;
+ var collapsedNonEditableSelectionsSupported = true;
+
+ var addRangeBackwardToNative = selectionHasExtend ?
+ function(nativeSelection, range) {
+ var doc = DomRange.getRangeDocument(range);
+ var endRange = api.createRange(doc);
+ endRange.collapseToPoint(range.endContainer, range.endOffset);
+ nativeSelection.addRange(getNativeRange(endRange));
+ nativeSelection.extend(range.startContainer, range.startOffset);
+ } : null;
+
+ if (util.areHostMethods(testSelection, ["addRange", "getRangeAt", "removeAllRanges"]) &&
+ typeof testSelection.rangeCount == NUMBER && features.implementsDomRange) {
+
+ (function() {
+ // Previously an iframe was used but this caused problems in some circumstances in IE, so tests are
+ // performed on the current document's selection. See issue 109.
+
+ // Note also that if a selection previously existed, it is wiped by these tests. This should usually be fine
+ // because initialization usually happens when the document loads, but could be a problem for a script that
+ // loads and initializes Rangy later. If anyone complains, code could be added to save and restore the
+ // selection.
+ var sel = window.getSelection();
+ if (sel) {
+ // Store the current selection
+ var originalSelectionRangeCount = sel.rangeCount;
+ var selectionHasMultipleRanges = (originalSelectionRangeCount > 1);
+ var originalSelectionRanges = [];
+ var originalSelectionBackward = winSelectionIsBackward(sel);
+ for (var i = 0; i < originalSelectionRangeCount; ++i) {
+ originalSelectionRanges[i] = sel.getRangeAt(i);
+ }
+
+ // Create some test elements
+ var body = getBody(document);
+ var testEl = body.appendChild( document.createElement("div") );
+ testEl.contentEditable = "false";
+ var textNode = testEl.appendChild( document.createTextNode("\u00a0\u00a0\u00a0") );
+
+ // Test whether the native selection will allow a collapsed selection within a non-editable element
+ var r1 = document.createRange();
+
+ r1.setStart(textNode, 1);
+ r1.collapse(true);
+ sel.addRange(r1);
+ collapsedNonEditableSelectionsSupported = (sel.rangeCount == 1);
+ sel.removeAllRanges();
+
+ // Test whether the native selection is capable of supporting multiple ranges.
+ if (!selectionHasMultipleRanges) {
+ // Doing the original feature test here in Chrome 36 (and presumably later versions) prints a
+ // console error of "Discontiguous selection is not supported." that cannot be suppressed. There's
+ // nothing we can do about this while retaining the feature test so we have to resort to a browser
+ // sniff. I'm not happy about it. See
+ // https://code.google.com/p/chromium/issues/detail?id=399791
+ var chromeMatch = window.navigator.appVersion.match(/Chrome\/(.*?) /);
+ if (chromeMatch && parseInt(chromeMatch[1]) >= 36) {
+ selectionSupportsMultipleRanges = false;
+ } else {
+ var r2 = r1.cloneRange();
+ r1.setStart(textNode, 0);
+ r2.setEnd(textNode, 3);
+ r2.setStart(textNode, 2);
+ sel.addRange(r1);
+ sel.addRange(r2);
+ selectionSupportsMultipleRanges = (sel.rangeCount == 2);
+ }
+ }
+
+ // Clean up
+ body.removeChild(testEl);
+ sel.removeAllRanges();
+
+ for (i = 0; i < originalSelectionRangeCount; ++i) {
+ if (i == 0 && originalSelectionBackward) {
+ if (addRangeBackwardToNative) {
+ addRangeBackwardToNative(sel, originalSelectionRanges[i]);
+ } else {
+ api.warn("Rangy initialization: original selection was backwards but selection has been restored forwards because the browser does not support Selection.extend");
+ sel.addRange(originalSelectionRanges[i]);
+ }
+ } else {
+ sel.addRange(originalSelectionRanges[i]);
+ }
+ }
+ }
+ })();
+ }
+
+ features.selectionSupportsMultipleRanges = selectionSupportsMultipleRanges;
+ features.collapsedNonEditableSelectionsSupported = collapsedNonEditableSelectionsSupported;
+
+ // ControlRanges
+ var implementsControlRange = false, testControlRange;
+
+ if (body && isHostMethod(body, "createControlRange")) {
+ testControlRange = body.createControlRange();
+ if (util.areHostProperties(testControlRange, ["item", "add"])) {
+ implementsControlRange = true;
+ }
+ }
+ features.implementsControlRange = implementsControlRange;
+
+ // Selection collapsedness
+ if (selectionHasAnchorAndFocus) {
+ selectionIsCollapsed = function(sel) {
+ return sel.anchorNode === sel.focusNode && sel.anchorOffset === sel.focusOffset;
+ };
+ } else {
+ selectionIsCollapsed = function(sel) {
+ return sel.rangeCount ? sel.getRangeAt(sel.rangeCount - 1).collapsed : false;
+ };
+ }
+
+ function updateAnchorAndFocusFromRange(sel, range, backward) {
+ var anchorPrefix = backward ? "end" : "start", focusPrefix = backward ? "start" : "end";
+ sel.anchorNode = range[anchorPrefix + "Container"];
+ sel.anchorOffset = range[anchorPrefix + "Offset"];
+ sel.focusNode = range[focusPrefix + "Container"];
+ sel.focusOffset = range[focusPrefix + "Offset"];
+ }
+
+ function updateAnchorAndFocusFromNativeSelection(sel) {
+ var nativeSel = sel.nativeSelection;
+ sel.anchorNode = nativeSel.anchorNode;
+ sel.anchorOffset = nativeSel.anchorOffset;
+ sel.focusNode = nativeSel.focusNode;
+ sel.focusOffset = nativeSel.focusOffset;
+ }
+
+ function updateEmptySelection(sel) {
+ sel.anchorNode = sel.focusNode = null;
+ sel.anchorOffset = sel.focusOffset = 0;
+ sel.rangeCount = 0;
+ sel.isCollapsed = true;
+ sel._ranges.length = 0;
+ }
+
+ function getNativeRange(range) {
+ var nativeRange;
+ if (range instanceof DomRange) {
+ nativeRange = api.createNativeRange(range.getDocument());
+ nativeRange.setEnd(range.endContainer, range.endOffset);
+ nativeRange.setStart(range.startContainer, range.startOffset);
+ } else if (range instanceof WrappedRange) {
+ nativeRange = range.nativeRange;
+ } else if (features.implementsDomRange && (range instanceof dom.getWindow(range.startContainer).Range)) {
+ nativeRange = range;
+ }
+ return nativeRange;
+ }
+
+ function rangeContainsSingleElement(rangeNodes) {
+ if (!rangeNodes.length || rangeNodes[0].nodeType != 1) {
+ return false;
+ }
+ for (var i = 1, len = rangeNodes.length; i < len; ++i) {
+ if (!dom.isAncestorOf(rangeNodes[0], rangeNodes[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ function getSingleElementFromRange(range) {
+ var nodes = range.getNodes();
+ if (!rangeContainsSingleElement(nodes)) {
+ throw module.createError("getSingleElementFromRange: range " + range.inspect() + " did not consist of a single element");
+ }
+ return nodes[0];
+ }
+
+ // Simple, quick test which only needs to distinguish between a TextRange and a ControlRange
+ function isTextRange(range) {
+ return !!range && typeof range.text != "undefined";
+ }
+
+ function updateFromTextRange(sel, range) {
+ // Create a Range from the selected TextRange
+ var wrappedRange = new WrappedRange(range);
+ sel._ranges = [wrappedRange];
+
+ updateAnchorAndFocusFromRange(sel, wrappedRange, false);
+ sel.rangeCount = 1;
+ sel.isCollapsed = wrappedRange.collapsed;
+ }
+
+ function updateControlSelection(sel) {
+ // Update the wrapped selection based on what's now in the native selection
+ sel._ranges.length = 0;
+ if (sel.docSelection.type == "None") {
+ updateEmptySelection(sel);
+ } else {
+ var controlRange = sel.docSelection.createRange();
+ if (isTextRange(controlRange)) {
+ // This case (where the selection type is "Control" and calling createRange() on the selection returns
+ // a TextRange) can happen in IE 9. It happens, for example, when all elements in the selected
+ // ControlRange have been removed from the ControlRange and removed from the document.
+ updateFromTextRange(sel, controlRange);
+ } else {
+ sel.rangeCount = controlRange.length;
+ var range, doc = getDocument(controlRange.item(0));
+ for (var i = 0; i < sel.rangeCount; ++i) {
+ range = api.createRange(doc);
+ range.selectNode(controlRange.item(i));
+ sel._ranges.push(range);
+ }
+ sel.isCollapsed = sel.rangeCount == 1 && sel._ranges[0].collapsed;
+ updateAnchorAndFocusFromRange(sel, sel._ranges[sel.rangeCount - 1], false);
+ }
+ }
+ }
+
+ function addRangeToControlSelection(sel, range) {
+ var controlRange = sel.docSelection.createRange();
+ var rangeElement = getSingleElementFromRange(range);
+
+ // Create a new ControlRange containing all the elements in the selected ControlRange plus the element
+ // contained by the supplied range
+ var doc = getDocument(controlRange.item(0));
+ var newControlRange = getBody(doc).createControlRange();
+ for (var i = 0, len = controlRange.length; i < len; ++i) {
+ newControlRange.add(controlRange.item(i));
+ }
+ try {
+ newControlRange.add(rangeElement);
+ } catch (ex) {
+ throw module.createError("addRange(): Element within the specified Range could not be added to control selection (does it have layout?)");
+ }
+ newControlRange.select();
+
+ // Update the wrapped selection based on what's now in the native selection
+ updateControlSelection(sel);
+ }
+
+ var getSelectionRangeAt;
+
+ if (isHostMethod(testSelection, "getRangeAt")) {
+ // try/catch is present because getRangeAt() must have thrown an error in some browser and some situation.
+ // Unfortunately, I didn't write a comment about the specifics and am now scared to take it out. Let that be a
+ // lesson to us all, especially me.
+ getSelectionRangeAt = function(sel, index) {
+ try {
+ return sel.getRangeAt(index);
+ } catch (ex) {
+ return null;
+ }
+ };
+ } else if (selectionHasAnchorAndFocus) {
+ getSelectionRangeAt = function(sel) {
+ var doc = getDocument(sel.anchorNode);
+ var range = api.createRange(doc);
+ range.setStartAndEnd(sel.anchorNode, sel.anchorOffset, sel.focusNode, sel.focusOffset);
+
+ // Handle the case when the selection was selected backwards (from the end to the start in the
+ // document)
+ if (range.collapsed !== this.isCollapsed) {
+ range.setStartAndEnd(sel.focusNode, sel.focusOffset, sel.anchorNode, sel.anchorOffset);
+ }
+
+ return range;
+ };
+ }
+
+ function WrappedSelection(selection, docSelection, win) {
+ this.nativeSelection = selection;
+ this.docSelection = docSelection;
+ this._ranges = [];
+ this.win = win;
+ this.refresh();
+ }
+
+ WrappedSelection.prototype = api.selectionPrototype;
+
+ function deleteProperties(sel) {
+ sel.win = sel.anchorNode = sel.focusNode = sel._ranges = null;
+ sel.rangeCount = sel.anchorOffset = sel.focusOffset = 0;
+ sel.detached = true;
+ }
+
+ var cachedRangySelections = [];
+
+ function actOnCachedSelection(win, action) {
+ var i = cachedRangySelections.length, cached, sel;
+ while (i--) {
+ cached = cachedRangySelections[i];
+ sel = cached.selection;
+ if (action == "deleteAll") {
+ deleteProperties(sel);
+ } else if (cached.win == win) {
+ if (action == "delete") {
+ cachedRangySelections.splice(i, 1);
+ return true;
+ } else {
+ return sel;
+ }
+ }
+ }
+ if (action == "deleteAll") {
+ cachedRangySelections.length = 0;
+ }
+ return null;
+ }
+
+ var getSelection = function(win) {
+ // Check if the parameter is a Rangy Selection object
+ if (win && win instanceof WrappedSelection) {
+ win.refresh();
+ return win;
+ }
+
+ win = getWindow(win, "getNativeSelection");
+
+ var sel = actOnCachedSelection(win);
+ var nativeSel = getNativeSelection(win), docSel = implementsDocSelection ? getDocSelection(win) : null;
+ if (sel) {
+ sel.nativeSelection = nativeSel;
+ sel.docSelection = docSel;
+ sel.refresh();
+ } else {
+ sel = new WrappedSelection(nativeSel, docSel, win);
+ cachedRangySelections.push( { win: win, selection: sel } );
+ }
+ return sel;
+ };
+
+ api.getSelection = getSelection;
+
+ api.getIframeSelection = function(iframeEl) {
+ module.deprecationNotice("getIframeSelection()", "getSelection(iframeEl)");
+ return api.getSelection(dom.getIframeWindow(iframeEl));
+ };
+
+ var selProto = WrappedSelection.prototype;
+
+ function createControlSelection(sel, ranges) {
+ // Ensure that the selection becomes of type "Control"
+ var doc = getDocument(ranges[0].startContainer);
+ var controlRange = getBody(doc).createControlRange();
+ for (var i = 0, el, len = ranges.length; i < len; ++i) {
+ el = getSingleElementFromRange(ranges[i]);
+ try {
+ controlRange.add(el);
+ } catch (ex) {
+ throw module.createError("setRanges(): Element within one of the specified Ranges could not be added to control selection (does it have layout?)");
+ }
+ }
+ controlRange.select();
+
+ // Update the wrapped selection based on what's now in the native selection
+ updateControlSelection(sel);
+ }
+
+ // Selecting a range
+ if (!useDocumentSelection && selectionHasAnchorAndFocus && util.areHostMethods(testSelection, ["removeAllRanges", "addRange"])) {
+ selProto.removeAllRanges = function() {
+ this.nativeSelection.removeAllRanges();
+ updateEmptySelection(this);
+ };
+
+ var addRangeBackward = function(sel, range) {
+ addRangeBackwardToNative(sel.nativeSelection, range);
+ sel.refresh();
+ };
+
+ if (selectionHasRangeCount) {
+ selProto.addRange = function(range, direction) {
+ if (implementsControlRange && implementsDocSelection && this.docSelection.type == CONTROL) {
+ addRangeToControlSelection(this, range);
+ } else {
+ if (isDirectionBackward(direction) && selectionHasExtend) {
+ addRangeBackward(this, range);
+ } else {
+ var previousRangeCount;
+ if (selectionSupportsMultipleRanges) {
+ previousRangeCount = this.rangeCount;
+ } else {
+ this.removeAllRanges();
+ previousRangeCount = 0;
+ }
+ // Clone the native range so that changing the selected range does not affect the selection.
+ // This is contrary to the spec but is the only way to achieve consistency between browsers. See
+ // issue 80.
+ var clonedNativeRange = getNativeRange(range).cloneRange();
+ try {
+ this.nativeSelection.addRange(clonedNativeRange);
+ } catch (ex) {
+ }
+
+ // Check whether adding the range was successful
+ this.rangeCount = this.nativeSelection.rangeCount;
+
+ if (this.rangeCount == previousRangeCount + 1) {
+ // The range was added successfully
+
+ // Check whether the range that we added to the selection is reflected in the last range extracted from
+ // the selection
+ if (api.config.checkSelectionRanges) {
+ var nativeRange = getSelectionRangeAt(this.nativeSelection, this.rangeCount - 1);
+ if (nativeRange && !rangesEqual(nativeRange, range)) {
+ // Happens in WebKit with, for example, a selection placed at the start of a text node
+ range = new WrappedRange(nativeRange);
+ }
+ }
+ this._ranges[this.rangeCount - 1] = range;
+ updateAnchorAndFocusFromRange(this, range, selectionIsBackward(this.nativeSelection));
+ this.isCollapsed = selectionIsCollapsed(this);
+ } else {
+ // The range was not added successfully. The simplest thing is to refresh
+ this.refresh();
+ }
+ }
+ }
+ };
+ } else {
+ selProto.addRange = function(range, direction) {
+ if (isDirectionBackward(direction) && selectionHasExtend) {
+ addRangeBackward(this, range);
+ } else {
+ this.nativeSelection.addRange(getNativeRange(range));
+ this.refresh();
+ }
+ };
+ }
+
+ selProto.setRanges = function(ranges) {
+ if (implementsControlRange && implementsDocSelection && ranges.length > 1) {
+ createControlSelection(this, ranges);
+ } else {
+ this.removeAllRanges();
+ for (var i = 0, len = ranges.length; i < len; ++i) {
+ this.addRange(ranges[i]);
+ }
+ }
+ };
+ } else if (isHostMethod(testSelection, "empty") && isHostMethod(testRange, "select") &&
+ implementsControlRange && useDocumentSelection) {
+
+ selProto.removeAllRanges = function() {
+ // Added try/catch as fix for issue #21
+ try {
+ this.docSelection.empty();
+
+ // Check for empty() not working (issue #24)
+ if (this.docSelection.type != "None") {
+ // Work around failure to empty a control selection by instead selecting a TextRange and then
+ // calling empty()
+ var doc;
+ if (this.anchorNode) {
+ doc = getDocument(this.anchorNode);
+ } else if (this.docSelection.type == CONTROL) {
+ var controlRange = this.docSelection.createRange();
+ if (controlRange.length) {
+ doc = getDocument( controlRange.item(0) );
+ }
+ }
+ if (doc) {
+ var textRange = getBody(doc).createTextRange();
+ textRange.select();
+ this.docSelection.empty();
+ }
+ }
+ } catch(ex) {}
+ updateEmptySelection(this);
+ };
+
+ selProto.addRange = function(range) {
+ if (this.docSelection.type == CONTROL) {
+ addRangeToControlSelection(this, range);
+ } else {
+ api.WrappedTextRange.rangeToTextRange(range).select();
+ this._ranges[0] = range;
+ this.rangeCount = 1;
+ this.isCollapsed = this._ranges[0].collapsed;
+ updateAnchorAndFocusFromRange(this, range, false);
+ }
+ };
+
+ selProto.setRanges = function(ranges) {
+ this.removeAllRanges();
+ var rangeCount = ranges.length;
+ if (rangeCount > 1) {
+ createControlSelection(this, ranges);
+ } else if (rangeCount) {
+ this.addRange(ranges[0]);
+ }
+ };
+ } else {
+ module.fail("No means of selecting a Range or TextRange was found");
+ return false;
+ }
+
+ selProto.getRangeAt = function(index) {
+ if (index < 0 || index >= this.rangeCount) {
+ throw new DOMException("INDEX_SIZE_ERR");
+ } else {
+ // Clone the range to preserve selection-range independence. See issue 80.
+ return this._ranges[index].cloneRange();
+ }
+ };
+
+ var refreshSelection;
+
+ if (useDocumentSelection) {
+ refreshSelection = function(sel) {
+ var range;
+ if (api.isSelectionValid(sel.win)) {
+ range = sel.docSelection.createRange();
+ } else {
+ range = getBody(sel.win.document).createTextRange();
+ range.collapse(true);
+ }
+
+ if (sel.docSelection.type == CONTROL) {
+ updateControlSelection(sel);
+ } else if (isTextRange(range)) {
+ updateFromTextRange(sel, range);
+ } else {
+ updateEmptySelection(sel);
+ }
+ };
+ } else if (isHostMethod(testSelection, "getRangeAt") && typeof testSelection.rangeCount == NUMBER) {
+ refreshSelection = function(sel) {
+ if (implementsControlRange && implementsDocSelection && sel.docSelection.type == CONTROL) {
+ updateControlSelection(sel);
+ } else {
+ sel._ranges.length = sel.rangeCount = sel.nativeSelection.rangeCount;
+ if (sel.rangeCount) {
+ for (var i = 0, len = sel.rangeCount; i < len; ++i) {
+ sel._ranges[i] = new api.WrappedRange(sel.nativeSelection.getRangeAt(i));
+ }
+ updateAnchorAndFocusFromRange(sel, sel._ranges[sel.rangeCount - 1], selectionIsBackward(sel.nativeSelection));
+ sel.isCollapsed = selectionIsCollapsed(sel);
+ } else {
+ updateEmptySelection(sel);
+ }
+ }
+ };
+ } else if (selectionHasAnchorAndFocus && typeof testSelection.isCollapsed == BOOLEAN && typeof testRange.collapsed == BOOLEAN && features.implementsDomRange) {
+ refreshSelection = function(sel) {
+ var range, nativeSel = sel.nativeSelection;
+ if (nativeSel.anchorNode) {
+ range = getSelectionRangeAt(nativeSel, 0);
+ sel._ranges = [range];
+ sel.rangeCount = 1;
+ updateAnchorAndFocusFromNativeSelection(sel);
+ sel.isCollapsed = selectionIsCollapsed(sel);
+ } else {
+ updateEmptySelection(sel);
+ }
+ };
+ } else {
+ module.fail("No means of obtaining a Range or TextRange from the user's selection was found");
+ return false;
+ }
+
+ selProto.refresh = function(checkForChanges) {
+ var oldRanges = checkForChanges ? this._ranges.slice(0) : null;
+ var oldAnchorNode = this.anchorNode, oldAnchorOffset = this.anchorOffset;
+
+ refreshSelection(this);
+ if (checkForChanges) {
+ // Check the range count first
+ var i = oldRanges.length;
+ if (i != this._ranges.length) {
+ return true;
+ }
+
+ // Now check the direction. Checking the anchor position is the same is enough since we're checking all the
+ // ranges after this
+ if (this.anchorNode != oldAnchorNode || this.anchorOffset != oldAnchorOffset) {
+ return true;
+ }
+
+ // Finally, compare each range in turn
+ while (i--) {
+ if (!rangesEqual(oldRanges[i], this._ranges[i])) {
+ return true;
+ }
+ }
+ return false;
+ }
+ };
+
+ // Removal of a single range
+ var removeRangeManually = function(sel, range) {
+ var ranges = sel.getAllRanges();
+ sel.removeAllRanges();
+ for (var i = 0, len = ranges.length; i < len; ++i) {
+ if (!rangesEqual(range, ranges[i])) {
+ sel.addRange(ranges[i]);
+ }
+ }
+ if (!sel.rangeCount) {
+ updateEmptySelection(sel);
+ }
+ };
+
+ if (implementsControlRange && implementsDocSelection) {
+ selProto.removeRange = function(range) {
+ if (this.docSelection.type == CONTROL) {
+ var controlRange = this.docSelection.createRange();
+ var rangeElement = getSingleElementFromRange(range);
+
+ // Create a new ControlRange containing all the elements in the selected ControlRange minus the
+ // element contained by the supplied range
+ var doc = getDocument(controlRange.item(0));
+ var newControlRange = getBody(doc).createControlRange();
+ var el, removed = false;
+ for (var i = 0, len = controlRange.length; i < len; ++i) {
+ el = controlRange.item(i);
+ if (el !== rangeElement || removed) {
+ newControlRange.add(controlRange.item(i));
+ } else {
+ removed = true;
+ }
+ }
+ newControlRange.select();
+
+ // Update the wrapped selection based on what's now in the native selection
+ updateControlSelection(this);
+ } else {
+ removeRangeManually(this, range);
+ }
+ };
+ } else {
+ selProto.removeRange = function(range) {
+ removeRangeManually(this, range);
+ };
+ }
+
+ // Detecting if a selection is backward
+ var selectionIsBackward;
+ if (!useDocumentSelection && selectionHasAnchorAndFocus && features.implementsDomRange) {
+ selectionIsBackward = winSelectionIsBackward;
+
+ selProto.isBackward = function() {
+ return selectionIsBackward(this);
+ };
+ } else {
+ selectionIsBackward = selProto.isBackward = function() {
+ return false;
+ };
+ }
+
+ // Create an alias for backwards compatibility. From 1.3, everything is "backward" rather than "backwards"
+ selProto.isBackwards = selProto.isBackward;
+
+ // Selection stringifier
+ // This is conformant to the old HTML5 selections draft spec but differs from WebKit and Mozilla's implementation.
+ // The current spec does not yet define this method.
+ selProto.toString = function() {
+ var rangeTexts = [];
+ for (var i = 0, len = this.rangeCount; i < len; ++i) {
+ rangeTexts[i] = "" + this._ranges[i];
+ }
+ return rangeTexts.join("");
+ };
+
+ function assertNodeInSameDocument(sel, node) {
+ if (sel.win.document != getDocument(node)) {
+ throw new DOMException("WRONG_DOCUMENT_ERR");
+ }
+ }
+
+ // No current browser conforms fully to the spec for this method, so Rangy's own method is always used
+ selProto.collapse = function(node, offset) {
+ assertNodeInSameDocument(this, node);
+ var range = api.createRange(node);
+ range.collapseToPoint(node, offset);
+ this.setSingleRange(range);
+ this.isCollapsed = true;
+ };
+
+ selProto.collapseToStart = function() {
+ if (this.rangeCount) {
+ var range = this._ranges[0];
+ this.collapse(range.startContainer, range.startOffset);
+ } else {
+ throw new DOMException("INVALID_STATE_ERR");
+ }
+ };
+
+ selProto.collapseToEnd = function() {
+ if (this.rangeCount) {
+ var range = this._ranges[this.rangeCount - 1];
+ this.collapse(range.endContainer, range.endOffset);
+ } else {
+ throw new DOMException("INVALID_STATE_ERR");
+ }
+ };
+
+ // The spec is very specific on how selectAllChildren should be implemented so the native implementation is
+ // never used by Rangy.
+ selProto.selectAllChildren = function(node) {
+ assertNodeInSameDocument(this, node);
+ var range = api.createRange(node);
+ range.selectNodeContents(node);
+ this.setSingleRange(range);
+ };
+
+ selProto.deleteFromDocument = function() {
+ // Sepcial behaviour required for IE's control selections
+ if (implementsControlRange && implementsDocSelection && this.docSelection.type == CONTROL) {
+ var controlRange = this.docSelection.createRange();
+ var element;
+ while (controlRange.length) {
+ element = controlRange.item(0);
+ controlRange.remove(element);
+ element.parentNode.removeChild(element);
+ }
+ this.refresh();
+ } else if (this.rangeCount) {
+ var ranges = this.getAllRanges();
+ if (ranges.length) {
+ this.removeAllRanges();
+ for (var i = 0, len = ranges.length; i < len; ++i) {
+ ranges[i].deleteContents();
+ }
+ // The spec says nothing about what the selection should contain after calling deleteContents on each
+ // range. Firefox moves the selection to where the final selected range was, so we emulate that
+ this.addRange(ranges[len - 1]);
+ }
+ }
+ };
+
+ // The following are non-standard extensions
+ selProto.eachRange = function(func, returnValue) {
+ for (var i = 0, len = this._ranges.length; i < len; ++i) {
+ if ( func( this.getRangeAt(i) ) ) {
+ return returnValue;
+ }
+ }
+ };
+
+ selProto.getAllRanges = function() {
+ var ranges = [];
+ this.eachRange(function(range) {
+ ranges.push(range);
+ });
+ return ranges;
+ };
+
+ selProto.setSingleRange = function(range, direction) {
+ this.removeAllRanges();
+ this.addRange(range, direction);
+ };
+
+ selProto.callMethodOnEachRange = function(methodName, params) {
+ var results = [];
+ this.eachRange( function(range) {
+ results.push( range[methodName].apply(range, params) );
+ } );
+ return results;
+ };
+
+ function createStartOrEndSetter(isStart) {
+ return function(node, offset) {
+ var range;
+ if (this.rangeCount) {
+ range = this.getRangeAt(0);
+ range["set" + (isStart ? "Start" : "End")](node, offset);
+ } else {
+ range = api.createRange(this.win.document);
+ range.setStartAndEnd(node, offset);
+ }
+ this.setSingleRange(range, this.isBackward());
+ };
+ }
+
+ selProto.setStart = createStartOrEndSetter(true);
+ selProto.setEnd = createStartOrEndSetter(false);
+
+ // Add select() method to Range prototype. Any existing selection will be removed.
+ api.rangePrototype.select = function(direction) {
+ getSelection( this.getDocument() ).setSingleRange(this, direction);
+ };
+
+ selProto.changeEachRange = function(func) {
+ var ranges = [];
+ var backward = this.isBackward();
+
+ this.eachRange(function(range) {
+ func(range);
+ ranges.push(range);
+ });
+
+ this.removeAllRanges();
+ if (backward && ranges.length == 1) {
+ this.addRange(ranges[0], "backward");
+ } else {
+ this.setRanges(ranges);
+ }
+ };
+
+ selProto.containsNode = function(node, allowPartial) {
+ return this.eachRange( function(range) {
+ return range.containsNode(node, allowPartial);
+ }, true ) || false;
+ };
+
+ selProto.getBookmark = function(containerNode) {
+ return {
+ backward: this.isBackward(),
+ rangeBookmarks: this.callMethodOnEachRange("getBookmark", [containerNode])
+ };
+ };
+
+ selProto.moveToBookmark = function(bookmark) {
+ var selRanges = [];
+ for (var i = 0, rangeBookmark, range; rangeBookmark = bookmark.rangeBookmarks[i++]; ) {
+ range = api.createRange(this.win);
+ range.moveToBookmark(rangeBookmark);
+ selRanges.push(range);
+ }
+ if (bookmark.backward) {
+ this.setSingleRange(selRanges[0], "backward");
+ } else {
+ this.setRanges(selRanges);
+ }
+ };
+
+ selProto.toHtml = function() {
+ var rangeHtmls = [];
+ this.eachRange(function(range) {
+ rangeHtmls.push( DomRange.toHtml(range) );
+ });
+ return rangeHtmls.join("");
+ };
+
+ if (features.implementsTextRange) {
+ selProto.getNativeTextRange = function() {
+ var sel, textRange;
+ if ( (sel = this.docSelection) ) {
+ var range = sel.createRange();
+ if (isTextRange(range)) {
+ return range;
+ } else {
+ throw module.createError("getNativeTextRange: selection is a control selection");
+ }
+ } else if (this.rangeCount > 0) {
+ return api.WrappedTextRange.rangeToTextRange( this.getRangeAt(0) );
+ } else {
+ throw module.createError("getNativeTextRange: selection contains no range");
+ }
+ };
+ }
+
+ function inspect(sel) {
+ var rangeInspects = [];
+ var anchor = new DomPosition(sel.anchorNode, sel.anchorOffset);
+ var focus = new DomPosition(sel.focusNode, sel.focusOffset);
+ var name = (typeof sel.getName == "function") ? sel.getName() : "Selection";
+
+ if (typeof sel.rangeCount != "undefined") {
+ for (var i = 0, len = sel.rangeCount; i < len; ++i) {
+ rangeInspects[i] = DomRange.inspect(sel.getRangeAt(i));
+ }
+ }
+ return "[" + name + "(Ranges: " + rangeInspects.join(", ") +
+ ")(anchor: " + anchor.inspect() + ", focus: " + focus.inspect() + "]";
+ }
+
+ selProto.getName = function() {
+ return "WrappedSelection";
+ };
+
+ selProto.inspect = function() {
+ return inspect(this);
+ };
+
+ selProto.detach = function() {
+ actOnCachedSelection(this.win, "delete");
+ deleteProperties(this);
+ };
+
+ WrappedSelection.detachAll = function() {
+ actOnCachedSelection(null, "deleteAll");
+ };
+
+ WrappedSelection.inspect = inspect;
+ WrappedSelection.isDirectionBackward = isDirectionBackward;
+
+ api.Selection = WrappedSelection;
+
+ api.selectionPrototype = selProto;
+
+ api.addShimListener(function(win) {
+ if (typeof win.getSelection == "undefined") {
+ win.getSelection = function() {
+ return getSelection(win);
+ };
+ }
+ win = null;
+ });
+ });
+ \r
+\r
+ /*----------------------------------------------------------------------------------------------------------------*/\r
+\r
+ // Wait for document to load before initializing\r
+ var docReady = false;\r
+\r
+ var loadHandler = function(e) {\r
+ if (!docReady) {\r
+ docReady = true;\r
+ if (!api.initialized && api.config.autoInitialize) {\r
+ init();\r
+ }\r
+ }\r
+ };\r
+\r
+ if (isBrowser) {\r
+ // Test whether the document has already been loaded and initialize immediately if so\r
+ if (document.readyState == "complete") {\r
+ loadHandler();\r
+ } else {\r
+ if (isHostMethod(document, "addEventListener")) {\r
+ document.addEventListener("DOMContentLoaded", loadHandler, false);\r
+ }\r
+\r
+ // Add a fallback in case the DOMContentLoaded event isn't supported\r
+ addListener(window, "load", loadHandler);\r
+ }\r
+ }\r
+\r
+ return api;\r
+}, this);;/**\r
+ * Selection save and restore module for Rangy.\r
+ * Saves and restores user selections using marker invisible elements in the DOM.\r
+ *\r
+ * Part of Rangy, a cross-browser JavaScript range and selection library\r
+ * https://github.com/timdown/rangy\r
+ *\r
+ * Depends on Rangy core.\r
+ *\r
+ * Copyright 2014, Tim Down\r
+ * Licensed under the MIT license.\r
+ * Version: 1.3.0-alpha.20140921\r
+ * Build date: 21 September 2014\r
+ */\r
+(function(factory, root) {
+ if (typeof define == "function" && define.amd) {
+ // AMD. Register as an anonymous module with a dependency on Rangy.
+ define(["./rangy-core"], factory);
+ } else if (typeof module != "undefined" && typeof exports == "object") {
+ // Node/CommonJS style
+ module.exports = factory( require("rangy") );
+ } else {
+ // No AMD or CommonJS support so we use the rangy property of root (probably the global variable)
+ factory(root.rangy);
+ }
+})(function(rangy) {
+ rangy.createModule("SaveRestore", ["WrappedRange"], function(api, module) {
+ var dom = api.dom;
+
+ var markerTextChar = "\ufeff";
+
+ function gEBI(id, doc) {
+ return (doc || document).getElementById(id);
+ }
+
+ function insertRangeBoundaryMarker(range, atStart) {
+ var markerId = "selectionBoundary_" + (+new Date()) + "_" + ("" + Math.random()).slice(2);
+ var markerEl;
+ var doc = dom.getDocument(range.startContainer);
+
+ // Clone the Range and collapse to the appropriate boundary point
+ var boundaryRange = range.cloneRange();
+ boundaryRange.collapse(atStart);
+
+ // Create the marker element containing a single invisible character using DOM methods and insert it
+ markerEl = doc.createElement("span");
+ markerEl.id = markerId;
+ markerEl.style.lineHeight = "0";
+ markerEl.style.display = "none";
+ markerEl.className = "rangySelectionBoundary";
+ markerEl.appendChild(doc.createTextNode(markerTextChar));
+
+ boundaryRange.insertNode(markerEl);
+ return markerEl;
+ }
+
+ function setRangeBoundary(doc, range, markerId, atStart) {
+ var markerEl = gEBI(markerId, doc);
+ if (markerEl) {
+ range[atStart ? "setStartBefore" : "setEndBefore"](markerEl);
+ markerEl.parentNode.removeChild(markerEl);
+ } else {
+ module.warn("Marker element has been removed. Cannot restore selection.");
+ }
+ }
+
+ function compareRanges(r1, r2) {
+ return r2.compareBoundaryPoints(r1.START_TO_START, r1);
+ }
+
+ function saveRange(range, backward) {
+ var startEl, endEl, doc = api.DomRange.getRangeDocument(range), text = range.toString();
+
+ if (range.collapsed) {
+ endEl = insertRangeBoundaryMarker(range, false);
+ return {
+ document: doc,
+ markerId: endEl.id,
+ collapsed: true
+ };
+ } else {
+ endEl = insertRangeBoundaryMarker(range, false);
+ startEl = insertRangeBoundaryMarker(range, true);
+
+ return {
+ document: doc,
+ startMarkerId: startEl.id,
+ endMarkerId: endEl.id,
+ collapsed: false,
+ backward: backward,
+ toString: function() {
+ return "original text: '" + text + "', new text: '" + range.toString() + "'";
+ }
+ };
+ }
+ }
+
+ function restoreRange(rangeInfo, normalize) {
+ var doc = rangeInfo.document;
+ if (typeof normalize == "undefined") {
+ normalize = true;
+ }
+ var range = api.createRange(doc);
+ if (rangeInfo.collapsed) {
+ var markerEl = gEBI(rangeInfo.markerId, doc);
+ if (markerEl) {
+ markerEl.style.display = "inline";
+ var previousNode = markerEl.previousSibling;
+
+ // Workaround for issue 17
+ if (previousNode && previousNode.nodeType == 3) {
+ markerEl.parentNode.removeChild(markerEl);
+ range.collapseToPoint(previousNode, previousNode.length);
+ } else {
+ range.collapseBefore(markerEl);
+ markerEl.parentNode.removeChild(markerEl);
+ }
+ } else {
+ module.warn("Marker element has been removed. Cannot restore selection.");
+ }
+ } else {
+ setRangeBoundary(doc, range, rangeInfo.startMarkerId, true);
+ setRangeBoundary(doc, range, rangeInfo.endMarkerId, false);
+ }
+
+ if (normalize) {
+ range.normalizeBoundaries();
+ }
+
+ return range;
+ }
+
+ function saveRanges(ranges, backward) {
+ var rangeInfos = [], range, doc;
+
+ // Order the ranges by position within the DOM, latest first, cloning the array to leave the original untouched
+ ranges = ranges.slice(0);
+ ranges.sort(compareRanges);
+
+ for (var i = 0, len = ranges.length; i < len; ++i) {
+ rangeInfos[i] = saveRange(ranges[i], backward);
+ }
+
+ // Now that all the markers are in place and DOM manipulation over, adjust each range's boundaries to lie
+ // between its markers
+ for (i = len - 1; i >= 0; --i) {
+ range = ranges[i];
+ doc = api.DomRange.getRangeDocument(range);
+ if (range.collapsed) {
+ range.collapseAfter(gEBI(rangeInfos[i].markerId, doc));
+ } else {
+ range.setEndBefore(gEBI(rangeInfos[i].endMarkerId, doc));
+ range.setStartAfter(gEBI(rangeInfos[i].startMarkerId, doc));
+ }
+ }
+
+ return rangeInfos;
+ }
+
+ function saveSelection(win) {
+ if (!api.isSelectionValid(win)) {
+ module.warn("Cannot save selection. This usually happens when the selection is collapsed and the selection document has lost focus.");
+ return null;
+ }
+ var sel = api.getSelection(win);
+ var ranges = sel.getAllRanges();
+ var backward = (ranges.length == 1 && sel.isBackward());
+
+ var rangeInfos = saveRanges(ranges, backward);
+
+ // Ensure current selection is unaffected
+ if (backward) {
+ sel.setSingleRange(ranges[0], "backward");
+ } else {
+ sel.setRanges(ranges);
+ }
+
+ return {
+ win: win,
+ rangeInfos: rangeInfos,
+ restored: false
+ };
+ }
+
+ function restoreRanges(rangeInfos) {
+ var ranges = [];
+
+ // Ranges are in reverse order of appearance in the DOM. We want to restore earliest first to avoid
+ // normalization affecting previously restored ranges.
+ var rangeCount = rangeInfos.length;
+
+ for (var i = rangeCount - 1; i >= 0; i--) {
+ ranges[i] = restoreRange(rangeInfos[i], true);
+ }
+
+ return ranges;
+ }
+
+ function restoreSelection(savedSelection, preserveDirection) {
+ if (!savedSelection.restored) {
+ var rangeInfos = savedSelection.rangeInfos;
+ var sel = api.getSelection(savedSelection.win);
+ var ranges = restoreRanges(rangeInfos), rangeCount = rangeInfos.length;
+
+ if (rangeCount == 1 && preserveDirection && api.features.selectionHasExtend && rangeInfos[0].backward) {
+ sel.removeAllRanges();
+ sel.addRange(ranges[0], true);
+ } else {
+ sel.setRanges(ranges);
+ }
+
+ savedSelection.restored = true;
+ }
+ }
+
+ function removeMarkerElement(doc, markerId) {
+ var markerEl = gEBI(markerId, doc);
+ if (markerEl) {
+ markerEl.parentNode.removeChild(markerEl);
+ }
+ }
+
+ function removeMarkers(savedSelection) {
+ var rangeInfos = savedSelection.rangeInfos;
+ for (var i = 0, len = rangeInfos.length, rangeInfo; i < len; ++i) {
+ rangeInfo = rangeInfos[i];
+ if (rangeInfo.collapsed) {
+ removeMarkerElement(savedSelection.doc, rangeInfo.markerId);
+ } else {
+ removeMarkerElement(savedSelection.doc, rangeInfo.startMarkerId);
+ removeMarkerElement(savedSelection.doc, rangeInfo.endMarkerId);
+ }
+ }
+ }
+
+ api.util.extend(api, {
+ saveRange: saveRange,
+ restoreRange: restoreRange,
+ saveRanges: saveRanges,
+ restoreRanges: restoreRanges,
+ saveSelection: saveSelection,
+ restoreSelection: restoreSelection,
+ removeMarkerElement: removeMarkerElement,
+ removeMarkers: removeMarkers
+ });
+ });
+
+}, this);;/*
+ Base.js, version 1.1a
+ Copyright 2006-2010, Dean Edwards
+ License: http://www.opensource.org/licenses/mit-license.php
+*/
+
+var Base = function() {
+ // dummy
+};
+
+Base.extend = function(_instance, _static) { // subclass
+ var extend = Base.prototype.extend;
+
+ // build the prototype
+ Base._prototyping = true;
+ var proto = new this;
+ extend.call(proto, _instance);
+ proto.base = function() {
+ // call this method from any other method to invoke that method's ancestor
+ };
+ delete Base._prototyping;
+
+ // create the wrapper for the constructor function
+ //var constructor = proto.constructor.valueOf(); //-dean
+ var constructor = proto.constructor;
+ var klass = proto.constructor = function() {
+ if (!Base._prototyping) {
+ if (this._constructing || this.constructor == klass) { // instantiation
+ this._constructing = true;
+ constructor.apply(this, arguments);
+ delete this._constructing;
+ } else if (arguments[0] != null) { // casting
+ return (arguments[0].extend || extend).call(arguments[0], proto);
+ }
+ }
+ };
+
+ // build the class interface
+ klass.ancestor = this;
+ klass.extend = this.extend;
+ klass.forEach = this.forEach;
+ klass.implement = this.implement;
+ klass.prototype = proto;
+ klass.toString = this.toString;
+ klass.valueOf = function(type) {
+ //return (type == "object") ? klass : constructor; //-dean
+ return (type == "object") ? klass : constructor.valueOf();
+ };
+ extend.call(klass, _static);
+ // class initialisation
+ if (typeof klass.init == "function") klass.init();
+ return klass;
+};
+
+Base.prototype = {
+ extend: function(source, value) {
+ if (arguments.length > 1) { // extending with a name/value pair
+ var ancestor = this[source];
+ if (ancestor && (typeof value == "function") && // overriding a method?
+ // the valueOf() comparison is to avoid circular references
+ (!ancestor.valueOf || ancestor.valueOf() != value.valueOf()) &&
+ /\bbase\b/.test(value)) {
+ // get the underlying method
+ var method = value.valueOf();
+ // override
+ value = function() {
+ var previous = this.base || Base.prototype.base;
+ this.base = ancestor;
+ var returnValue = method.apply(this, arguments);
+ this.base = previous;
+ return returnValue;
+ };
+ // point to the underlying method
+ value.valueOf = function(type) {
+ return (type == "object") ? value : method;
+ };
+ value.toString = Base.toString;
+ }
+ this[source] = value;
+ } else if (source) { // extending with an object literal
+ var extend = Base.prototype.extend;
+ // if this object has a customised extend method then use it
+ if (!Base._prototyping && typeof this != "function") {
+ extend = this.extend || extend;
+ }
+ var proto = {toSource: null};
+ // do the "toString" and other methods manually
+ var hidden = ["constructor", "toString", "valueOf"];
+ // if we are prototyping then include the constructor
+ var i = Base._prototyping ? 0 : 1;
+ while (key = hidden[i++]) {
+ if (source[key] != proto[key]) {
+ extend.call(this, key, source[key]);
+
+ }
+ }
+ // copy each of the source object's properties to this object
+ for (var key in source) {
+ if (!proto[key]) extend.call(this, key, source[key]);
+ }
+ }
+ return this;
+ }
+};
+
+// initialise
+Base = Base.extend({
+ constructor: function() {
+ this.extend(arguments[0]);
+ }
+}, {
+ ancestor: Object,
+ version: "1.1",
+
+ forEach: function(object, block, context) {
+ for (var key in object) {
+ if (this.prototype[key] === undefined) {
+ block.call(context, object[key], key, object);
+ }
+ }
+ },
+
+ implement: function() {
+ for (var i = 0; i < arguments.length; i++) {
+ if (typeof arguments[i] == "function") {
+ // if it's a function, call it
+ arguments[i](this.prototype);
+ } else {
+ // add the interface using the extend method
+ this.prototype.extend(arguments[i]);
+ }
+ }
+ return this;
+ },
+
+ toString: function() {
+ return String(this.valueOf());
+ }
+});;/**
+ * Detect browser support for specific features
+ */
+wysihtml5.browser = (function() {
+ var userAgent = navigator.userAgent,
+ testElement = document.createElement("div"),
+ // Browser sniffing is unfortunately needed since some behaviors are impossible to feature detect
+ isGecko = userAgent.indexOf("Gecko") !== -1 && userAgent.indexOf("KHTML") === -1,
+ isWebKit = userAgent.indexOf("AppleWebKit/") !== -1,
+ isChrome = userAgent.indexOf("Chrome/") !== -1,
+ isOpera = userAgent.indexOf("Opera/") !== -1;
+
+ function iosVersion(userAgent) {
+ return +((/ipad|iphone|ipod/.test(userAgent) && userAgent.match(/ os (\d+).+? like mac os x/)) || [undefined, 0])[1];
+ }
+
+ function androidVersion(userAgent) {
+ return +(userAgent.match(/android (\d+)/) || [undefined, 0])[1];
+ }
+
+ function isIE(version, equation) {
+ var rv = -1,
+ re;
+
+ if (navigator.appName == 'Microsoft Internet Explorer') {
+ re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
+ } else if (navigator.appName == 'Netscape') {
+ re = new RegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})");
+ }
+
+ if (re && re.exec(navigator.userAgent) != null) {
+ rv = parseFloat(RegExp.$1);
+ }
+
+ if (rv === -1) { return false; }
+ if (!version) { return true; }
+ if (!equation) { return version === rv; }
+ if (equation === "<") { return version < rv; }
+ if (equation === ">") { return version > rv; }
+ if (equation === "<=") { return version <= rv; }
+ if (equation === ">=") { return version >= rv; }
+ }
+
+ return {
+ // Static variable needed, publicly accessible, to be able override it in unit tests
+ USER_AGENT: userAgent,
+
+ /**
+ * Exclude browsers that are not capable of displaying and handling
+ * contentEditable as desired:
+ * - iPhone, iPad (tested iOS 4.2.2) and Android (tested 2.2) refuse to make contentEditables focusable
+ * - IE < 8 create invalid markup and crash randomly from time to time
+ *
+ * @return {Boolean}
+ */
+ supported: function() {
+ var userAgent = this.USER_AGENT.toLowerCase(),
+ // Essential for making html elements editable
+ hasContentEditableSupport = "contentEditable" in testElement,
+ // Following methods are needed in order to interact with the contentEditable area
+ hasEditingApiSupport = document.execCommand && document.queryCommandSupported && document.queryCommandState,
+ // document selector apis are only supported by IE 8+, Safari 4+, Chrome and Firefox 3.5+
+ hasQuerySelectorSupport = document.querySelector && document.querySelectorAll,
+ // contentEditable is unusable in mobile browsers (tested iOS 4.2.2, Android 2.2, Opera Mobile, WebOS 3.05)
+ isIncompatibleMobileBrowser = (this.isIos() && iosVersion(userAgent) < 5) || (this.isAndroid() && androidVersion(userAgent) < 4) || userAgent.indexOf("opera mobi") !== -1 || userAgent.indexOf("hpwos/") !== -1;
+ return hasContentEditableSupport
+ && hasEditingApiSupport
+ && hasQuerySelectorSupport
+ && !isIncompatibleMobileBrowser;
+ },
+
+ isTouchDevice: function() {
+ return this.supportsEvent("touchmove");
+ },
+
+ isIos: function() {
+ return (/ipad|iphone|ipod/i).test(this.USER_AGENT);
+ },
+
+ isAndroid: function() {
+ return this.USER_AGENT.indexOf("Android") !== -1;
+ },
+
+ /**
+ * Whether the browser supports sandboxed iframes
+ * Currently only IE 6+ offers such feature <iframe security="restricted">
+ *
+ * http://msdn.microsoft.com/en-us/library/ms534622(v=vs.85).aspx
+ * http://blogs.msdn.com/b/ie/archive/2008/01/18/using-frames-more-securely.aspx
+ *
+ * HTML5 sandboxed iframes are still buggy and their DOM is not reachable from the outside (except when using postMessage)
+ */
+ supportsSandboxedIframes: function() {
+ return isIE();
+ },
+
+ /**
+ * IE6+7 throw a mixed content warning when the src of an iframe
+ * is empty/unset or about:blank
+ * window.querySelector is implemented as of IE8
+ */
+ throwsMixedContentWarningWhenIframeSrcIsEmpty: function() {
+ return !("querySelector" in document);
+ },
+
+ /**
+ * Whether the caret is correctly displayed in contentEditable elements
+ * Firefox sometimes shows a huge caret in the beginning after focusing
+ */
+ displaysCaretInEmptyContentEditableCorrectly: function() {
+ return isIE();
+ },
+
+ /**
+ * Opera and IE are the only browsers who offer the css value
+ * in the original unit, thx to the currentStyle object
+ * All other browsers provide the computed style in px via window.getComputedStyle
+ */
+ hasCurrentStyleProperty: function() {
+ return "currentStyle" in testElement;
+ },
+
+ /**
+ * Whether the browser inserts a <br> when pressing enter in a contentEditable element
+ */
+ insertsLineBreaksOnReturn: function() {
+ return isGecko;
+ },
+
+ supportsPlaceholderAttributeOn: function(element) {
+ return "placeholder" in element;
+ },
+
+ supportsEvent: function(eventName) {
+ return "on" + eventName in testElement || (function() {
+ testElement.setAttribute("on" + eventName, "return;");
+ return typeof(testElement["on" + eventName]) === "function";
+ })();
+ },
+
+ /**
+ * Opera doesn't correctly fire focus/blur events when clicking in- and outside of iframe
+ */
+ supportsEventsInIframeCorrectly: function() {
+ return !isOpera;
+ },
+
+ /**
+ * Everything below IE9 doesn't know how to treat HTML5 tags
+ *
+ * @param {Object} context The document object on which to check HTML5 support
+ *
+ * @example
+ * wysihtml5.browser.supportsHTML5Tags(document);
+ */
+ supportsHTML5Tags: function(context) {
+ var element = context.createElement("div"),
+ html5 = "<article>foo</article>";
+ element.innerHTML = html5;
+ return element.innerHTML.toLowerCase() === html5;
+ },
+
+ /**
+ * Checks whether a document supports a certain queryCommand
+ * In particular, Opera needs a reference to a document that has a contentEditable in it's dom tree
+ * in oder to report correct results
+ *
+ * @param {Object} doc Document object on which to check for a query command
+ * @param {String} command The query command to check for
+ * @return {Boolean}
+ *
+ * @example
+ * wysihtml5.browser.supportsCommand(document, "bold");
+ */
+ supportsCommand: (function() {
+ // Following commands are supported but contain bugs in some browsers
+ var buggyCommands = {
+ // formatBlock fails with some tags (eg. <blockquote>)
+ "formatBlock": isIE(10, "<="),
+ // When inserting unordered or ordered lists in Firefox, Chrome or Safari, the current selection or line gets
+ // converted into a list (<ul><li>...</li></ul>, <ol><li>...</li></ol>)
+ // IE and Opera act a bit different here as they convert the entire content of the current block element into a list
+ "insertUnorderedList": isIE(),
+ "insertOrderedList": isIE()
+ };
+
+ // Firefox throws errors for queryCommandSupported, so we have to build up our own object of supported commands
+ var supported = {
+ "insertHTML": isGecko
+ };
+
+ return function(doc, command) {
+ var isBuggy = buggyCommands[command];
+ if (!isBuggy) {
+ // Firefox throws errors when invoking queryCommandSupported or queryCommandEnabled
+ try {
+ return doc.queryCommandSupported(command);
+ } catch(e1) {}
+
+ try {
+ return doc.queryCommandEnabled(command);
+ } catch(e2) {
+ return !!supported[command];
+ }
+ }
+ return false;
+ };
+ })(),
+
+ /**
+ * IE: URLs starting with:
+ * www., http://, https://, ftp://, gopher://, mailto:, new:, snews:, telnet:, wasis:, file://,
+ * nntp://, newsrc:, ldap://, ldaps://, outlook:, mic:// and url:
+ * will automatically be auto-linked when either the user inserts them via copy&paste or presses the
+ * space bar when the caret is directly after such an url.
+ * This behavior cannot easily be avoided in IE < 9 since the logic is hardcoded in the mshtml.dll
+ * (related blog post on msdn
+ * http://blogs.msdn.com/b/ieinternals/archive/2009/09/17/prevent-automatic-hyperlinking-in-contenteditable-html.aspx).
+ */
+ doesAutoLinkingInContentEditable: function() {
+ return isIE();
+ },
+
+ /**
+ * As stated above, IE auto links urls typed into contentEditable elements
+ * Since IE9 it's possible to prevent this behavior
+ */
+ canDisableAutoLinking: function() {
+ return this.supportsCommand(document, "AutoUrlDetect");
+ },
+
+ /**
+ * IE leaves an empty paragraph in the contentEditable element after clearing it
+ * Chrome/Safari sometimes an empty <div>
+ */
+ clearsContentEditableCorrectly: function() {
+ return isGecko || isOpera || isWebKit;
+ },
+
+ /**
+ * IE gives wrong results for getAttribute
+ */
+ supportsGetAttributeCorrectly: function() {
+ var td = document.createElement("td");
+ return td.getAttribute("rowspan") != "1";
+ },
+
+ /**
+ * When clicking on images in IE, Opera and Firefox, they are selected, which makes it easy to interact with them.
+ * Chrome and Safari both don't support this
+ */
+ canSelectImagesInContentEditable: function() {
+ return isGecko || isIE() || isOpera;
+ },
+
+ /**
+ * All browsers except Safari and Chrome automatically scroll the range/caret position into view
+ */
+ autoScrollsToCaret: function() {
+ return !isWebKit;
+ },
+
+ /**
+ * Check whether the browser automatically closes tags that don't need to be opened
+ */
+ autoClosesUnclosedTags: function() {
+ var clonedTestElement = testElement.cloneNode(false),
+ returnValue,
+ innerHTML;
+
+ clonedTestElement.innerHTML = "<p><div></div>";
+ innerHTML = clonedTestElement.innerHTML.toLowerCase();
+ returnValue = innerHTML === "<p></p><div></div>" || innerHTML === "<p><div></div></p>";
+
+ // Cache result by overwriting current function
+ this.autoClosesUnclosedTags = function() { return returnValue; };
+
+ return returnValue;
+ },
+
+ /**
+ * Whether the browser supports the native document.getElementsByClassName which returns live NodeLists
+ */
+ supportsNativeGetElementsByClassName: function() {
+ return String(document.getElementsByClassName).indexOf("[native code]") !== -1;
+ },
+
+ /**
+ * As of now (19.04.2011) only supported by Firefox 4 and Chrome
+ * See https://developer.mozilla.org/en/DOM/Selection/modify
+ */
+ supportsSelectionModify: function() {
+ return "getSelection" in window && "modify" in window.getSelection();
+ },
+
+ /**
+ * Opera needs a white space after a <br> in order to position the caret correctly
+ */
+ needsSpaceAfterLineBreak: function() {
+ return isOpera;
+ },
+
+ /**
+ * Whether the browser supports the speech api on the given element
+ * See http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/
+ *
+ * @example
+ * var input = document.createElement("input");
+ * if (wysihtml5.browser.supportsSpeechApiOn(input)) {
+ * // ...
+ * }
+ */
+ supportsSpeechApiOn: function(input) {
+ var chromeVersion = userAgent.match(/Chrome\/(\d+)/) || [undefined, 0];
+ return chromeVersion[1] >= 11 && ("onwebkitspeechchange" in input || "speech" in input);
+ },
+
+ /**
+ * IE9 crashes when setting a getter via Object.defineProperty on XMLHttpRequest or XDomainRequest
+ * See https://connect.microsoft.com/ie/feedback/details/650112
+ * or try the POC http://tifftiff.de/ie9_crash/
+ */
+ crashesWhenDefineProperty: function(property) {
+ return isIE(9) && (property === "XMLHttpRequest" || property === "XDomainRequest");
+ },
+
+ /**
+ * IE is the only browser who fires the "focus" event not immediately when .focus() is called on an element
+ */
+ doesAsyncFocus: function() {
+ return isIE();
+ },
+
+ /**
+ * In IE it's impssible for the user and for the selection library to set the caret after an <img> when it's the lastChild in the document
+ */
+ hasProblemsSettingCaretAfterImg: function() {
+ return isIE();
+ },
+
+ hasUndoInContextMenu: function() {
+ return isGecko || isChrome || isOpera;
+ },
+
+ /**
+ * Opera sometimes doesn't insert the node at the right position when range.insertNode(someNode)
+ * is used (regardless if rangy or native)
+ * This especially happens when the caret is positioned right after a <br> because then
+ * insertNode() will insert the node right before the <br>
+ */
+ hasInsertNodeIssue: function() {
+ return isOpera;
+ },
+
+ /**
+ * IE 8+9 don't fire the focus event of the <body> when the iframe gets focused (even though the caret gets set into the <body>)
+ */
+ hasIframeFocusIssue: function() {
+ return isIE();
+ },
+
+ /**
+ * Chrome + Safari create invalid nested markup after paste
+ *
+ * <p>
+ * foo
+ * <p>bar</p> <!-- BOO! -->
+ * </p>
+ */
+ createsNestedInvalidMarkupAfterPaste: function() {
+ return isWebKit;
+ },
+
+ supportsMutationEvents: function() {
+ return ("MutationEvent" in window);
+ },
+
+ /**
+ IE (at least up to 11) does not support clipboardData on event.
+ It is on window but cannot return text/html
+ Should actually check for clipboardData on paste event, but cannot in firefox
+ */
+ supportsModenPaste: function () {
+ return !("clipboardData" in window);
+ }
+ };
+})();
+;wysihtml5.lang.array = function(arr) {
+ return {
+ /**
+ * Check whether a given object exists in an array
+ *
+ * @example
+ * wysihtml5.lang.array([1, 2]).contains(1);
+ * // => true
+ *
+ * Can be used to match array with array. If intersection is found true is returned
+ */
+ contains: function(needle) {
+ if (Array.isArray(needle)) {
+ for (var i = needle.length; i--;) {
+ if (wysihtml5.lang.array(arr).indexOf(needle[i]) !== -1) {
+ return true;
+ }
+ }
+ return false;
+ } else {
+ return wysihtml5.lang.array(arr).indexOf(needle) !== -1;
+ }
+ },
+
+ /**
+ * Check whether a given object exists in an array and return index
+ * If no elelemt found returns -1
+ *
+ * @example
+ * wysihtml5.lang.array([1, 2]).indexOf(2);
+ * // => 1
+ */
+ indexOf: function(needle) {
+ if (arr.indexOf) {
+ return arr.indexOf(needle);
+ } else {
+ for (var i=0, length=arr.length; i<length; i++) {
+ if (arr[i] === needle) { return i; }
+ }
+ return -1;
+ }
+ },
+
+ /**
+ * Substract one array from another
+ *
+ * @example
+ * wysihtml5.lang.array([1, 2, 3, 4]).without([3, 4]);
+ * // => [1, 2]
+ */
+ without: function(arrayToSubstract) {
+ arrayToSubstract = wysihtml5.lang.array(arrayToSubstract);
+ var newArr = [],
+ i = 0,
+ length = arr.length;
+ for (; i<length; i++) {
+ if (!arrayToSubstract.contains(arr[i])) {
+ newArr.push(arr[i]);
+ }
+ }
+ return newArr;
+ },
+
+ /**
+ * Return a clean native array
+ *
+ * Following will convert a Live NodeList to a proper Array
+ * @example
+ * var childNodes = wysihtml5.lang.array(document.body.childNodes).get();
+ */
+ get: function() {
+ var i = 0,
+ length = arr.length,
+ newArray = [];
+ for (; i<length; i++) {
+ newArray.push(arr[i]);
+ }
+ return newArray;
+ },
+
+ /**
+ * Creates a new array with the results of calling a provided function on every element in this array.
+ * optionally this can be provided as second argument
+ *
+ * @example
+ * var childNodes = wysihtml5.lang.array([1,2,3,4]).map(function (value, index, array) {
+ return value * 2;
+ * });
+ * // => [2,4,6,8]
+ */
+ map: function(callback, thisArg) {
+ if (Array.prototype.map) {
+ return arr.map(callback, thisArg);
+ } else {
+ var len = arr.length >>> 0,
+ A = new Array(len),
+ i = 0;
+ for (; i < len; i++) {
+ A[i] = callback.call(thisArg, arr[i], i, arr);
+ }
+ return A;
+ }
+ },
+
+ /* ReturnS new array without duplicate entries
+ *
+ * @example
+ * var uniq = wysihtml5.lang.array([1,2,3,2,1,4]).unique();
+ * // => [1,2,3,4]
+ */
+ unique: function() {
+ var vals = [],
+ max = arr.length,
+ idx = 0;
+
+ while (idx < max) {
+ if (!wysihtml5.lang.array(vals).contains(arr[idx])) {
+ vals.push(arr[idx]);
+ }
+ idx++;
+ }
+ return vals;
+ }
+
+ };
+};
+;wysihtml5.lang.Dispatcher = Base.extend(
+ /** @scope wysihtml5.lang.Dialog.prototype */ {
+ on: function(eventName, handler) {
+ this.events = this.events || {};
+ this.events[eventName] = this.events[eventName] || [];
+ this.events[eventName].push(handler);
+ return this;
+ },
+
+ off: function(eventName, handler) {
+ this.events = this.events || {};
+ var i = 0,
+ handlers,
+ newHandlers;
+ if (eventName) {
+ handlers = this.events[eventName] || [],
+ newHandlers = [];
+ for (; i<handlers.length; i++) {
+ if (handlers[i] !== handler && handler) {
+ newHandlers.push(handlers[i]);
+ }
+ }
+ this.events[eventName] = newHandlers;
+ } else {
+ // Clean up all events
+ this.events = {};
+ }
+ return this;
+ },
+
+ fire: function(eventName, payload) {
+ this.events = this.events || {};
+ var handlers = this.events[eventName] || [],
+ i = 0;
+ for (; i<handlers.length; i++) {
+ handlers[i].call(this, payload);
+ }
+ return this;
+ },
+
+ // deprecated, use .on()
+ observe: function() {
+ return this.on.apply(this, arguments);
+ },
+
+ // deprecated, use .off()
+ stopObserving: function() {
+ return this.off.apply(this, arguments);
+ }
+});
+;wysihtml5.lang.object = function(obj) {
+ return {
+ /**
+ * @example
+ * wysihtml5.lang.object({ foo: 1, bar: 1 }).merge({ bar: 2, baz: 3 }).get();
+ * // => { foo: 1, bar: 2, baz: 3 }
+ */
+ merge: function(otherObj) {
+ for (var i in otherObj) {
+ obj[i] = otherObj[i];
+ }
+ return this;
+ },
+
+ get: function() {
+ return obj;
+ },
+
+ /**
+ * @example
+ * wysihtml5.lang.object({ foo: 1 }).clone();
+ * // => { foo: 1 }
+ *
+ * v0.4.14 adds options for deep clone : wysihtml5.lang.object({ foo: 1 }).clone(true);
+ */
+ clone: function(deep) {
+ var newObj = {},
+ i;
+
+ if (obj === null || !wysihtml5.lang.object(obj).isPlainObject()) {
+ return obj;
+ }
+
+ for (i in obj) {
+ if(obj.hasOwnProperty(i)) {
+ if (deep) {
+ newObj[i] = wysihtml5.lang.object(obj[i]).clone(deep);
+ } else {
+ newObj[i] = obj[i];
+ }
+ }
+ }
+ return newObj;
+ },
+
+ /**
+ * @example
+ * wysihtml5.lang.object([]).isArray();
+ * // => true
+ */
+ isArray: function() {
+ return Object.prototype.toString.call(obj) === "[object Array]";
+ },
+
+ /**
+ * @example
+ * wysihtml5.lang.object(function() {}).isFunction();
+ * // => true
+ */
+ isFunction: function() {
+ return Object.prototype.toString.call(obj) === '[object Function]';
+ },
+
+ isPlainObject: function () {
+ return Object.prototype.toString.call(obj) === '[object Object]';
+ }
+ };
+};
+;(function() {
+ var WHITE_SPACE_START = /^\s+/,
+ WHITE_SPACE_END = /\s+$/,
+ ENTITY_REG_EXP = /[&<>\t"]/g,
+ ENTITY_MAP = {
+ '&': '&',
+ '<': '<',
+ '>': '>',
+ '"': """,
+ '\t':" "
+ };
+ wysihtml5.lang.string = function(str) {
+ str = String(str);
+ return {
+ /**
+ * @example
+ * wysihtml5.lang.string(" foo ").trim();
+ * // => "foo"
+ */
+ trim: function() {
+ return str.replace(WHITE_SPACE_START, "").replace(WHITE_SPACE_END, "");
+ },
+
+ /**
+ * @example
+ * wysihtml5.lang.string("Hello #{name}").interpolate({ name: "Christopher" });
+ * // => "Hello Christopher"
+ */
+ interpolate: function(vars) {
+ for (var i in vars) {
+ str = this.replace("#{" + i + "}").by(vars[i]);
+ }
+ return str;
+ },
+
+ /**
+ * @example
+ * wysihtml5.lang.string("Hello Tom").replace("Tom").with("Hans");
+ * // => "Hello Hans"
+ */
+ replace: function(search) {
+ return {
+ by: function(replace) {
+ return str.split(search).join(replace);
+ }
+ };
+ },
+
+ /**
+ * @example
+ * wysihtml5.lang.string("hello<br>").escapeHTML();
+ * // => "hello<br>"
+ */
+ escapeHTML: function(linebreaks, convertSpaces) {
+ var html = str.replace(ENTITY_REG_EXP, function(c) { return ENTITY_MAP[c]; });
+ if (linebreaks) {
+ html = html.replace(/(?:\r\n|\r|\n)/g, '<br />');
+ }
+ if (convertSpaces) {
+ html = html.replace(/ /gi, " ");
+ }
+ return html;
+ }
+ };
+ };
+})();
+;/**
+ * Find urls in descendant text nodes of an element and auto-links them
+ * Inspired by http://james.padolsey.com/javascript/find-and-replace-text-with-javascript/
+ *
+ * @param {Element} element Container element in which to search for urls
+ *
+ * @example
+ * <div id="text-container">Please click here: www.google.com</div>
+ * <script>wysihtml5.dom.autoLink(document.getElementById("text-container"));</script>
+ */
+(function(wysihtml5) {
+ var /**
+ * Don't auto-link urls that are contained in the following elements:
+ */
+ IGNORE_URLS_IN = wysihtml5.lang.array(["CODE", "PRE", "A", "SCRIPT", "HEAD", "TITLE", "STYLE"]),
+ /**
+ * revision 1:
+ * /(\S+\.{1}[^\s\,\.\!]+)/g
+ *
+ * revision 2:
+ * /(\b(((https?|ftp):\/\/)|(www\.))[-A-Z0-9+&@#\/%?=~_|!:,.;\[\]]*[-A-Z0-9+&@#\/%=~_|])/gim
+ *
+ * put this in the beginning if you don't wan't to match within a word
+ * (^|[\>\(\{\[\s\>])
+ */
+ URL_REG_EXP = /((https?:\/\/|www\.)[^\s<]{3,})/gi,
+ TRAILING_CHAR_REG_EXP = /([^\w\/\-](,?))$/i,
+ MAX_DISPLAY_LENGTH = 100,
+ BRACKETS = { ")": "(", "]": "[", "}": "{" };
+
+ function autoLink(element, ignoreInClasses) {
+ if (_hasParentThatShouldBeIgnored(element, ignoreInClasses)) {
+ return element;
+ }
+
+ if (element === element.ownerDocument.documentElement) {
+ element = element.ownerDocument.body;
+ }
+
+ return _parseNode(element, ignoreInClasses);
+ }
+
+ /**
+ * This is basically a rebuild of
+ * the rails auto_link_urls text helper
+ */
+ function _convertUrlsToLinks(str) {
+ return str.replace(URL_REG_EXP, function(match, url) {
+ var punctuation = (url.match(TRAILING_CHAR_REG_EXP) || [])[1] || "",
+ opening = BRACKETS[punctuation];
+ url = url.replace(TRAILING_CHAR_REG_EXP, "");
+
+ if (url.split(opening).length > url.split(punctuation).length) {
+ url = url + punctuation;
+ punctuation = "";
+ }
+ var realUrl = url,
+ displayUrl = url;
+ if (url.length > MAX_DISPLAY_LENGTH) {
+ displayUrl = displayUrl.substr(0, MAX_DISPLAY_LENGTH) + "...";
+ }
+ // Add http prefix if necessary
+ if (realUrl.substr(0, 4) === "www.") {
+ realUrl = "http://" + realUrl;
+ }
+
+ return '<a href="' + realUrl + '">' + displayUrl + '</a>' + punctuation;
+ });
+ }
+
+ /**
+ * Creates or (if already cached) returns a temp element
+ * for the given document object
+ */
+ function _getTempElement(context) {
+ var tempElement = context._wysihtml5_tempElement;
+ if (!tempElement) {
+ tempElement = context._wysihtml5_tempElement = context.createElement("div");
+ }
+ return tempElement;
+ }
+
+ /**
+ * Replaces the original text nodes with the newly auto-linked dom tree
+ */
+ function _wrapMatchesInNode(textNode) {
+ var parentNode = textNode.parentNode,
+ nodeValue = wysihtml5.lang.string(textNode.data).escapeHTML(),
+ tempElement = _getTempElement(parentNode.ownerDocument);
+
+ // We need to insert an empty/temporary <span /> to fix IE quirks
+ // Elsewise IE would strip white space in the beginning
+ tempElement.innerHTML = "<span></span>" + _convertUrlsToLinks(nodeValue);
+ tempElement.removeChild(tempElement.firstChild);
+
+ while (tempElement.firstChild) {
+ // inserts tempElement.firstChild before textNode
+ parentNode.insertBefore(tempElement.firstChild, textNode);
+ }
+ parentNode.removeChild(textNode);
+ }
+
+ function _hasParentThatShouldBeIgnored(node, ignoreInClasses) {
+ var nodeName;
+ while (node.parentNode) {
+ node = node.parentNode;
+ nodeName = node.nodeName;
+ if (node.className && wysihtml5.lang.array(node.className.split(' ')).contains(ignoreInClasses)) {
+ return true;
+ }
+ if (IGNORE_URLS_IN.contains(nodeName)) {
+ return true;
+ } else if (nodeName === "body") {
+ return false;
+ }
+ }
+ return false;
+ }
+
+ function _parseNode(element, ignoreInClasses) {
+ if (IGNORE_URLS_IN.contains(element.nodeName)) {
+ return;
+ }
+
+ if (element.className && wysihtml5.lang.array(element.className.split(' ')).contains(ignoreInClasses)) {
+ return;
+ }
+
+ if (element.nodeType === wysihtml5.TEXT_NODE && element.data.match(URL_REG_EXP)) {
+ _wrapMatchesInNode(element);
+ return;
+ }
+
+ var childNodes = wysihtml5.lang.array(element.childNodes).get(),
+ childNodesLength = childNodes.length,
+ i = 0;
+
+ for (; i<childNodesLength; i++) {
+ _parseNode(childNodes[i], ignoreInClasses);
+ }
+
+ return element;
+ }
+
+ wysihtml5.dom.autoLink = autoLink;
+
+ // Reveal url reg exp to the outside
+ wysihtml5.dom.autoLink.URL_REG_EXP = URL_REG_EXP;
+})(wysihtml5);
+;(function(wysihtml5) {
+ var api = wysihtml5.dom;
+
+ api.addClass = function(element, className) {
+ var classList = element.classList;
+ if (classList) {
+ return classList.add(className);
+ }
+ if (api.hasClass(element, className)) {
+ return;
+ }
+ element.className += " " + className;
+ };
+
+ api.removeClass = function(element, className) {
+ var classList = element.classList;
+ if (classList) {
+ return classList.remove(className);
+ }
+
+ element.className = element.className.replace(new RegExp("(^|\\s+)" + className + "(\\s+|$)"), " ");
+ };
+
+ api.hasClass = function(element, className) {
+ var classList = element.classList;
+ if (classList) {
+ return classList.contains(className);
+ }
+
+ var elementClassName = element.className;
+ return (elementClassName.length > 0 && (elementClassName == className || new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName)));
+ };
+})(wysihtml5);
+;wysihtml5.dom.contains = (function() {
+ var documentElement = document.documentElement;
+ if (documentElement.contains) {
+ return function(container, element) {
+ if (element.nodeType !== wysihtml5.ELEMENT_NODE) {
+ element = element.parentNode;
+ }
+ return container !== element && container.contains(element);
+ };
+ } else if (documentElement.compareDocumentPosition) {
+ return function(container, element) {
+ // https://developer.mozilla.org/en/DOM/Node.compareDocumentPosition
+ return !!(container.compareDocumentPosition(element) & 16);
+ };
+ }
+})();
+;/**
+ * Converts an HTML fragment/element into a unordered/ordered list
+ *
+ * @param {Element} element The element which should be turned into a list
+ * @param {String} listType The list type in which to convert the tree (either "ul" or "ol")
+ * @return {Element} The created list
+ *
+ * @example
+ * <!-- Assume the following dom: -->
+ * <span id="pseudo-list">
+ * eminem<br>
+ * dr. dre
+ * <div>50 Cent</div>
+ * </span>
+ *
+ * <script>
+ * wysihtml5.dom.convertToList(document.getElementById("pseudo-list"), "ul");
+ * </script>
+ *
+ * <!-- Will result in: -->
+ * <ul>
+ * <li>eminem</li>
+ * <li>dr. dre</li>
+ * <li>50 Cent</li>
+ * </ul>
+ */
+wysihtml5.dom.convertToList = (function() {
+ function _createListItem(doc, list) {
+ var listItem = doc.createElement("li");
+ list.appendChild(listItem);
+ return listItem;
+ }
+
+ function _createList(doc, type) {
+ return doc.createElement(type);
+ }
+
+ function convertToList(element, listType, uneditableClass) {
+ if (element.nodeName === "UL" || element.nodeName === "OL" || element.nodeName === "MENU") {
+ // Already a list
+ return element;
+ }
+
+ var doc = element.ownerDocument,
+ list = _createList(doc, listType),
+ lineBreaks = element.querySelectorAll("br"),
+ lineBreaksLength = lineBreaks.length,
+ childNodes,
+ childNodesLength,
+ childNode,
+ lineBreak,
+ parentNode,
+ isBlockElement,
+ isLineBreak,
+ currentListItem,
+ i;
+
+ // First find <br> at the end of inline elements and move them behind them
+ for (i=0; i<lineBreaksLength; i++) {
+ lineBreak = lineBreaks[i];
+ while ((parentNode = lineBreak.parentNode) && parentNode !== element && parentNode.lastChild === lineBreak) {
+ if (wysihtml5.dom.getStyle("display").from(parentNode) === "block") {
+ parentNode.removeChild(lineBreak);
+ break;
+ }
+ wysihtml5.dom.insert(lineBreak).after(lineBreak.parentNode);
+ }
+ }
+
+ childNodes = wysihtml5.lang.array(element.childNodes).get();
+ childNodesLength = childNodes.length;
+
+ for (i=0; i<childNodesLength; i++) {
+ currentListItem = currentListItem || _createListItem(doc, list);
+ childNode = childNodes[i];
+ isBlockElement = wysihtml5.dom.getStyle("display").from(childNode) === "block";
+ isLineBreak = childNode.nodeName === "BR";
+
+ // consider uneditable as an inline element
+ if (isBlockElement && (!uneditableClass || !wysihtml5.dom.hasClass(childNode, uneditableClass))) {
+ // Append blockElement to current <li> if empty, otherwise create a new one
+ currentListItem = currentListItem.firstChild ? _createListItem(doc, list) : currentListItem;
+ currentListItem.appendChild(childNode);
+ currentListItem = null;
+ continue;
+ }
+
+ if (isLineBreak) {
+ // Only create a new list item in the next iteration when the current one has already content
+ currentListItem = currentListItem.firstChild ? null : currentListItem;
+ continue;
+ }
+
+ currentListItem.appendChild(childNode);
+ }
+
+ if (childNodes.length === 0) {
+ _createListItem(doc, list);
+ }
+
+ element.parentNode.replaceChild(list, element);
+ return list;
+ }
+
+ return convertToList;
+})();
+;/**
+ * Copy a set of attributes from one element to another
+ *
+ * @param {Array} attributesToCopy List of attributes which should be copied
+ * @return {Object} Returns an object which offers the "from" method which can be invoked with the element where to
+ * copy the attributes from., this again returns an object which provides a method named "to" which can be invoked
+ * with the element where to copy the attributes to (see example)
+ *
+ * @example
+ * var textarea = document.querySelector("textarea"),
+ * div = document.querySelector("div[contenteditable=true]"),
+ * anotherDiv = document.querySelector("div.preview");
+ * wysihtml5.dom.copyAttributes(["spellcheck", "value", "placeholder"]).from(textarea).to(div).andTo(anotherDiv);
+ *
+ */
+wysihtml5.dom.copyAttributes = function(attributesToCopy) {
+ return {
+ from: function(elementToCopyFrom) {
+ return {
+ to: function(elementToCopyTo) {
+ var attribute,
+ i = 0,
+ length = attributesToCopy.length;
+ for (; i<length; i++) {
+ attribute = attributesToCopy[i];
+ if (typeof(elementToCopyFrom[attribute]) !== "undefined" && elementToCopyFrom[attribute] !== "") {
+ elementToCopyTo[attribute] = elementToCopyFrom[attribute];
+ }
+ }
+ return { andTo: arguments.callee };
+ }
+ };
+ }
+ };
+};
+;/**
+ * Copy a set of styles from one element to another
+ * Please note that this only works properly across browsers when the element from which to copy the styles
+ * is in the dom
+ *
+ * Interesting article on how to copy styles
+ *
+ * @param {Array} stylesToCopy List of styles which should be copied
+ * @return {Object} Returns an object which offers the "from" method which can be invoked with the element where to
+ * copy the styles from., this again returns an object which provides a method named "to" which can be invoked
+ * with the element where to copy the styles to (see example)
+ *
+ * @example
+ * var textarea = document.querySelector("textarea"),
+ * div = document.querySelector("div[contenteditable=true]"),
+ * anotherDiv = document.querySelector("div.preview");
+ * wysihtml5.dom.copyStyles(["overflow-y", "width", "height"]).from(textarea).to(div).andTo(anotherDiv);
+ *
+ */
+(function(dom) {
+
+ /**
+ * Mozilla, WebKit and Opera recalculate the computed width when box-sizing: boder-box; is set
+ * So if an element has "width: 200px; -moz-box-sizing: border-box; border: 1px;" then
+ * its computed css width will be 198px
+ *
+ * See https://bugzilla.mozilla.org/show_bug.cgi?id=520992
+ */
+ var BOX_SIZING_PROPERTIES = ["-webkit-box-sizing", "-moz-box-sizing", "-ms-box-sizing", "box-sizing"];
+
+ var shouldIgnoreBoxSizingBorderBox = function(element) {
+ if (hasBoxSizingBorderBox(element)) {
+ return parseInt(dom.getStyle("width").from(element), 10) < element.offsetWidth;
+ }
+ return false;
+ };
+
+ var hasBoxSizingBorderBox = function(element) {
+ var i = 0,
+ length = BOX_SIZING_PROPERTIES.length;
+ for (; i<length; i++) {
+ if (dom.getStyle(BOX_SIZING_PROPERTIES[i]).from(element) === "border-box") {
+ return BOX_SIZING_PROPERTIES[i];
+ }
+ }
+ };
+
+ dom.copyStyles = function(stylesToCopy) {
+ return {
+ from: function(element) {
+ if (shouldIgnoreBoxSizingBorderBox(element)) {
+ stylesToCopy = wysihtml5.lang.array(stylesToCopy).without(BOX_SIZING_PROPERTIES);
+ }
+
+ var cssText = "",
+ length = stylesToCopy.length,
+ i = 0,
+ property;
+ for (; i<length; i++) {
+ property = stylesToCopy[i];
+ cssText += property + ":" + dom.getStyle(property).from(element) + ";";
+ }
+
+ return {
+ to: function(element) {
+ dom.setStyles(cssText).on(element);
+ return { andTo: arguments.callee };
+ }
+ };
+ }
+ };
+ };
+})(wysihtml5.dom);
+;/**
+ * Event Delegation
+ *
+ * @example
+ * wysihtml5.dom.delegate(document.body, "a", "click", function() {
+ * // foo
+ * });
+ */
+(function(wysihtml5) {
+
+ wysihtml5.dom.delegate = function(container, selector, eventName, handler) {
+ return wysihtml5.dom.observe(container, eventName, function(event) {
+ var target = event.target,
+ match = wysihtml5.lang.array(container.querySelectorAll(selector));
+
+ while (target && target !== container) {
+ if (match.contains(target)) {
+ handler.call(target, event);
+ break;
+ }
+ target = target.parentNode;
+ }
+ });
+ };
+
+})(wysihtml5);
+;// TODO: Refactor dom tree traversing here
+(function(wysihtml5) {
+ wysihtml5.dom.domNode = function(node) {
+ var defaultNodeTypes = [wysihtml5.ELEMENT_NODE, wysihtml5.TEXT_NODE];
+
+ var _isBlankText = function(node) {
+ return node.nodeType === wysihtml5.TEXT_NODE && (/^\s*$/g).test(node.data);
+ };
+
+ return {
+
+ // var node = wysihtml5.dom.domNode(element).prev({nodeTypes: [1,3], ignoreBlankTexts: true});
+ prev: function(options) {
+ var prevNode = node.previousSibling,
+ types = (options && options.nodeTypes) ? options.nodeTypes : defaultNodeTypes;
+
+ if (!prevNode) {
+ return null;
+ }
+
+ if (
+ (!wysihtml5.lang.array(types).contains(prevNode.nodeType)) || // nodeTypes check.
+ (options && options.ignoreBlankTexts && _isBlankText(prevNode)) // Blank text nodes bypassed if set
+ ) {
+ return wysihtml5.dom.domNode(prevNode).prev(options);
+ }
+
+ return prevNode;
+ },
+
+ // var node = wysihtml5.dom.domNode(element).next({nodeTypes: [1,3], ignoreBlankTexts: true});
+ next: function(options) {
+ var nextNode = node.nextSibling,
+ types = (options && options.nodeTypes) ? options.nodeTypes : defaultNodeTypes;
+
+ if (!nextNode) {
+ return null;
+ }
+
+ if (
+ (!wysihtml5.lang.array(types).contains(nextNode.nodeType)) || // nodeTypes check.
+ (options && options.ignoreBlankTexts && _isBlankText(nextNode)) // blank text nodes bypassed if set
+ ) {
+ return wysihtml5.dom.domNode(nextNode).next(options);
+ }
+
+ return nextNode;
+ },
+
+ // Traverses a node for last children and their chidren (including itself), and finds the last node that has no children.
+ // Array of classes for forced last-leaves (ex: uneditable-container) can be defined (options = {leafClasses: [...]})
+ // Useful for finding the actually visible element before cursor
+ lastLeafNode: function(options) {
+ var lastChild;
+
+ // Returns non-element nodes
+ if (node.nodeType !== 1) {
+ return node;
+ }
+
+ // Returns if element is leaf
+ lastChild = node.lastChild;
+ if (!lastChild) {
+ return node;
+ }
+
+ // Returns if element is of of options.leafClasses leaf
+ if (options && options.leafClasses) {
+ for (var i = options.leafClasses.length; i--;) {
+ if (wysihtml5.dom.hasClass(node, options.leafClasses[i])) {
+ return node;
+ }
+ }
+ }
+
+ return wysihtml5.dom.domNode(lastChild).lastLeafNode(options);
+ }
+
+ };
+ };
+})(wysihtml5);;/**
+ * Returns the given html wrapped in a div element
+ *
+ * Fixing IE's inability to treat unknown elements (HTML5 section, article, ...) correctly
+ * when inserted via innerHTML
+ *
+ * @param {String} html The html which should be wrapped in a dom element
+ * @param {Obejct} [context] Document object of the context the html belongs to
+ *
+ * @example
+ * wysihtml5.dom.getAsDom("<article>foo</article>");
+ */
+wysihtml5.dom.getAsDom = (function() {
+
+ var _innerHTMLShiv = function(html, context) {
+ var tempElement = context.createElement("div");
+ tempElement.style.display = "none";
+ context.body.appendChild(tempElement);
+ // IE throws an exception when trying to insert <frameset></frameset> via innerHTML
+ try { tempElement.innerHTML = html; } catch(e) {}
+ context.body.removeChild(tempElement);
+ return tempElement;
+ };
+
+ /**
+ * Make sure IE supports HTML5 tags, which is accomplished by simply creating one instance of each element
+ */
+ var _ensureHTML5Compatibility = function(context) {
+ if (context._wysihtml5_supportsHTML5Tags) {
+ return;
+ }
+ for (var i=0, length=HTML5_ELEMENTS.length; i<length; i++) {
+ context.createElement(HTML5_ELEMENTS[i]);
+ }
+ context._wysihtml5_supportsHTML5Tags = true;
+ };
+
+
+ /**
+ * List of html5 tags
+ * taken from http://simon.html5.org/html5-elements
+ */
+ var HTML5_ELEMENTS = [
+ "abbr", "article", "aside", "audio", "bdi", "canvas", "command", "datalist", "details", "figcaption",
+ "figure", "footer", "header", "hgroup", "keygen", "mark", "meter", "nav", "output", "progress",
+ "rp", "rt", "ruby", "svg", "section", "source", "summary", "time", "track", "video", "wbr"
+ ];
+
+ return function(html, context) {
+ context = context || document;
+ var tempElement;
+ if (typeof(html) === "object" && html.nodeType) {
+ tempElement = context.createElement("div");
+ tempElement.appendChild(html);
+ } else if (wysihtml5.browser.supportsHTML5Tags(context)) {
+ tempElement = context.createElement("div");
+ tempElement.innerHTML = html;
+ } else {
+ _ensureHTML5Compatibility(context);
+ tempElement = _innerHTMLShiv(html, context);
+ }
+ return tempElement;
+ };
+})();
+;/**
+ * Walks the dom tree from the given node up until it finds a match
+ * Designed for optimal performance.
+ *
+ * @param {Element} node The from which to check the parent nodes
+ * @param {Object} matchingSet Object to match against (possible properties: nodeName, className, classRegExp)
+ * @param {Number} [levels] How many parents should the function check up from the current node (defaults to 50)
+ * @return {null|Element} Returns the first element that matched the desiredNodeName(s)
+ * @example
+ * var listElement = wysihtml5.dom.getParentElement(document.querySelector("li"), { nodeName: ["MENU", "UL", "OL"] });
+ * // ... or ...
+ * var unorderedListElement = wysihtml5.dom.getParentElement(document.querySelector("li"), { nodeName: "UL" });
+ * // ... or ...
+ * var coloredElement = wysihtml5.dom.getParentElement(myTextNode, { nodeName: "SPAN", className: "wysiwyg-color-red", classRegExp: /wysiwyg-color-[a-z]/g });
+ */
+wysihtml5.dom.getParentElement = (function() {
+
+ function _isSameNodeName(nodeName, desiredNodeNames) {
+ if (!desiredNodeNames || !desiredNodeNames.length) {
+ return true;
+ }
+
+ if (typeof(desiredNodeNames) === "string") {
+ return nodeName === desiredNodeNames;
+ } else {
+ return wysihtml5.lang.array(desiredNodeNames).contains(nodeName);
+ }
+ }
+
+ function _isElement(node) {
+ return node.nodeType === wysihtml5.ELEMENT_NODE;
+ }
+
+ function _hasClassName(element, className, classRegExp) {
+ var classNames = (element.className || "").match(classRegExp) || [];
+ if (!className) {
+ return !!classNames.length;
+ }
+ return classNames[classNames.length - 1] === className;
+ }
+
+ function _hasStyle(element, cssStyle, styleRegExp) {
+ var styles = (element.getAttribute('style') || "").match(styleRegExp) || [];
+ if (!cssStyle) {
+ return !!styles.length;
+ }
+ return styles[styles.length - 1] === cssStyle;
+ }
+
+ return function(node, matchingSet, levels, container) {
+ var findByStyle = (matchingSet.cssStyle || matchingSet.styleRegExp),
+ findByClass = (matchingSet.className || matchingSet.classRegExp);
+
+ levels = levels || 50; // Go max 50 nodes upwards from current node
+
+ // make the matching class regex from class name if omitted
+ if (findByClass && !matchingSet.classRegExp) {
+ matchingSet.classRegExp = new RegExp(matchingSet.className);
+ }
+
+ while (levels-- && node && node.nodeName !== "BODY" && (!container || node !== container)) {
+ if (_isElement(node) && (!matchingSet.nodeName || _isSameNodeName(node.nodeName, matchingSet.nodeName)) &&
+ (!findByStyle || _hasStyle(node, matchingSet.cssStyle, matchingSet.styleRegExp)) &&
+ (!findByClass || _hasClassName(node, matchingSet.className, matchingSet.classRegExp))
+ ) {
+ return node;
+ }
+ node = node.parentNode;
+ }
+ return null;
+ };
+})();
+;/**
+ * Get element's style for a specific css property
+ *
+ * @param {Element} element The element on which to retrieve the style
+ * @param {String} property The CSS property to retrieve ("float", "display", "text-align", ...)
+ *
+ * @example
+ * wysihtml5.dom.getStyle("display").from(document.body);
+ * // => "block"
+ */
+wysihtml5.dom.getStyle = (function() {
+ var stylePropertyMapping = {
+ "float": ("styleFloat" in document.createElement("div").style) ? "styleFloat" : "cssFloat"
+ },
+ REG_EXP_CAMELIZE = /\-[a-z]/g;
+
+ function camelize(str) {
+ return str.replace(REG_EXP_CAMELIZE, function(match) {
+ return match.charAt(1).toUpperCase();
+ });
+ }
+
+ return function(property) {
+ return {
+ from: function(element) {
+ if (element.nodeType !== wysihtml5.ELEMENT_NODE) {
+ return;
+ }
+
+ var doc = element.ownerDocument,
+ camelizedProperty = stylePropertyMapping[property] || camelize(property),
+ style = element.style,
+ currentStyle = element.currentStyle,
+ styleValue = style[camelizedProperty];
+ if (styleValue) {
+ return styleValue;
+ }
+
+ // currentStyle is no standard and only supported by Opera and IE but it has one important advantage over the standard-compliant
+ // window.getComputedStyle, since it returns css property values in their original unit:
+ // If you set an elements width to "50%", window.getComputedStyle will give you it's current width in px while currentStyle
+ // gives you the original "50%".
+ // Opera supports both, currentStyle and window.getComputedStyle, that's why checking for currentStyle should have higher prio
+ if (currentStyle) {
+ try {
+ return currentStyle[camelizedProperty];
+ } catch(e) {
+ //ie will occasionally fail for unknown reasons. swallowing exception
+ }
+ }
+
+ var win = doc.defaultView || doc.parentWindow,
+ needsOverflowReset = (property === "height" || property === "width") && element.nodeName === "TEXTAREA",
+ originalOverflow,
+ returnValue;
+
+ if (win.getComputedStyle) {
+ // Chrome and Safari both calculate a wrong width and height for textareas when they have scroll bars
+ // therfore we remove and restore the scrollbar and calculate the value in between
+ if (needsOverflowReset) {
+ originalOverflow = style.overflow;
+ style.overflow = "hidden";
+ }
+ returnValue = win.getComputedStyle(element, null).getPropertyValue(property);
+ if (needsOverflowReset) {
+ style.overflow = originalOverflow || "";
+ }
+ return returnValue;
+ }
+ }
+ };
+ };
+})();
+;wysihtml5.dom.getTextNodes = function(node, ingoreEmpty){
+ var all = [];
+ for (node=node.firstChild;node;node=node.nextSibling){
+ if (node.nodeType == 3) {
+ if (!ingoreEmpty || !(/^\s*$/).test(node.innerText || node.textContent)) {
+ all.push(node);
+ }
+ } else {
+ all = all.concat(wysihtml5.dom.getTextNodes(node, ingoreEmpty));
+ }
+ }
+ return all;
+};;/**
+ * High performant way to check whether an element with a specific tag name is in the given document
+ * Optimized for being heavily executed
+ * Unleashes the power of live node lists
+ *
+ * @param {Object} doc The document object of the context where to check
+ * @param {String} tagName Upper cased tag name
+ * @example
+ * wysihtml5.dom.hasElementWithTagName(document, "IMG");
+ */
+wysihtml5.dom.hasElementWithTagName = (function() {
+ var LIVE_CACHE = {},
+ DOCUMENT_IDENTIFIER = 1;
+
+ function _getDocumentIdentifier(doc) {
+ return doc._wysihtml5_identifier || (doc._wysihtml5_identifier = DOCUMENT_IDENTIFIER++);
+ }
+
+ return function(doc, tagName) {
+ var key = _getDocumentIdentifier(doc) + ":" + tagName,
+ cacheEntry = LIVE_CACHE[key];
+ if (!cacheEntry) {
+ cacheEntry = LIVE_CACHE[key] = doc.getElementsByTagName(tagName);
+ }
+
+ return cacheEntry.length > 0;
+ };
+})();
+;/**
+ * High performant way to check whether an element with a specific class name is in the given document
+ * Optimized for being heavily executed
+ * Unleashes the power of live node lists
+ *
+ * @param {Object} doc The document object of the context where to check
+ * @param {String} tagName Upper cased tag name
+ * @example
+ * wysihtml5.dom.hasElementWithClassName(document, "foobar");
+ */
+(function(wysihtml5) {
+ var LIVE_CACHE = {},
+ DOCUMENT_IDENTIFIER = 1;
+
+ function _getDocumentIdentifier(doc) {
+ return doc._wysihtml5_identifier || (doc._wysihtml5_identifier = DOCUMENT_IDENTIFIER++);
+ }
+
+ wysihtml5.dom.hasElementWithClassName = function(doc, className) {
+ // getElementsByClassName is not supported by IE<9
+ // but is sometimes mocked via library code (which then doesn't return live node lists)
+ if (!wysihtml5.browser.supportsNativeGetElementsByClassName()) {
+ return !!doc.querySelector("." + className);
+ }
+
+ var key = _getDocumentIdentifier(doc) + ":" + className,
+ cacheEntry = LIVE_CACHE[key];
+ if (!cacheEntry) {
+ cacheEntry = LIVE_CACHE[key] = doc.getElementsByClassName(className);
+ }
+
+ return cacheEntry.length > 0;
+ };
+})(wysihtml5);
+;wysihtml5.dom.insert = function(elementToInsert) {
+ return {
+ after: function(element) {
+ element.parentNode.insertBefore(elementToInsert, element.nextSibling);
+ },
+
+ before: function(element) {
+ element.parentNode.insertBefore(elementToInsert, element);
+ },
+
+ into: function(element) {
+ element.appendChild(elementToInsert);
+ }
+ };
+};
+;wysihtml5.dom.insertCSS = function(rules) {
+ rules = rules.join("\n");
+
+ return {
+ into: function(doc) {
+ var styleElement = doc.createElement("style");
+ styleElement.type = "text/css";
+
+ if (styleElement.styleSheet) {
+ styleElement.styleSheet.cssText = rules;
+ } else {
+ styleElement.appendChild(doc.createTextNode(rules));
+ }
+
+ var link = doc.querySelector("head link");
+ if (link) {
+ link.parentNode.insertBefore(styleElement, link);
+ return;
+ } else {
+ var head = doc.querySelector("head");
+ if (head) {
+ head.appendChild(styleElement);
+ }
+ }
+ }
+ };
+};
+;// TODO: Refactor dom tree traversing here
+(function(wysihtml5) {
+ wysihtml5.dom.lineBreaks = function(node) {
+
+ function _isLineBreak(n) {
+ return n.nodeName === "BR";
+ }
+
+ /**
+ * Checks whether the elment causes a visual line break
+ * (<br> or block elements)
+ */
+ function _isLineBreakOrBlockElement(element) {
+ if (_isLineBreak(element)) {
+ return true;
+ }
+
+ if (wysihtml5.dom.getStyle("display").from(element) === "block") {
+ return true;
+ }
+
+ return false;
+ }
+
+ return {
+
+ /* wysihtml5.dom.lineBreaks(element).add();
+ *
+ * Adds line breaks before and after the given node if the previous and next siblings
+ * aren't already causing a visual line break (block element or <br>)
+ */
+ add: function(options) {
+ var doc = node.ownerDocument,
+ nextSibling = wysihtml5.dom.domNode(node).next({ignoreBlankTexts: true}),
+ previousSibling = wysihtml5.dom.domNode(node).prev({ignoreBlankTexts: true});
+
+ if (nextSibling && !_isLineBreakOrBlockElement(nextSibling)) {
+ wysihtml5.dom.insert(doc.createElement("br")).after(node);
+ }
+ if (previousSibling && !_isLineBreakOrBlockElement(previousSibling)) {
+ wysihtml5.dom.insert(doc.createElement("br")).before(node);
+ }
+ },
+
+ /* wysihtml5.dom.lineBreaks(element).remove();
+ *
+ * Removes line breaks before and after the given node
+ */
+ remove: function(options) {
+ var nextSibling = wysihtml5.dom.domNode(node).next({ignoreBlankTexts: true}),
+ previousSibling = wysihtml5.dom.domNode(node).prev({ignoreBlankTexts: true});
+
+ if (nextSibling && _isLineBreak(nextSibling)) {
+ nextSibling.parentNode.removeChild(nextSibling);
+ }
+ if (previousSibling && _isLineBreak(previousSibling)) {
+ previousSibling.parentNode.removeChild(previousSibling);
+ }
+ }
+ };
+ };
+})(wysihtml5);;/**
+ * Method to set dom events
+ *
+ * @example
+ * wysihtml5.dom.observe(iframe.contentWindow.document.body, ["focus", "blur"], function() { ... });
+ */
+wysihtml5.dom.observe = function(element, eventNames, handler) {
+ eventNames = typeof(eventNames) === "string" ? [eventNames] : eventNames;
+
+ var handlerWrapper,
+ eventName,
+ i = 0,
+ length = eventNames.length;
+
+ for (; i<length; i++) {
+ eventName = eventNames[i];
+ if (element.addEventListener) {
+ element.addEventListener(eventName, handler, false);
+ } else {
+ handlerWrapper = function(event) {
+ if (!("target" in event)) {
+ event.target = event.srcElement;
+ }
+ event.preventDefault = event.preventDefault || function() {
+ this.returnValue = false;
+ };
+ event.stopPropagation = event.stopPropagation || function() {
+ this.cancelBubble = true;
+ };
+ handler.call(element, event);
+ };
+ element.attachEvent("on" + eventName, handlerWrapper);
+ }
+ }
+
+ return {
+ stop: function() {
+ var eventName,
+ i = 0,
+ length = eventNames.length;
+ for (; i<length; i++) {
+ eventName = eventNames[i];
+ if (element.removeEventListener) {
+ element.removeEventListener(eventName, handler, false);
+ } else {
+ element.detachEvent("on" + eventName, handlerWrapper);
+ }
+ }
+ }
+ };
+};
+;/**
+ * HTML Sanitizer
+ * Rewrites the HTML based on given rules
+ *
+ * @param {Element|String} elementOrHtml HTML String to be sanitized OR element whose content should be sanitized
+ * @param {Object} [rules] List of rules for rewriting the HTML, if there's no rule for an element it will
+ * be converted to a "span". Each rule is a key/value pair where key is the tag to convert, and value the
+ * desired substitution.
+ * @param {Object} context Document object in which to parse the html, needed to sandbox the parsing
+ *
+ * @return {Element|String} Depends on the elementOrHtml parameter. When html then the sanitized html as string elsewise the element.
+ *
+ * @example
+ * var userHTML = '<div id="foo" onclick="alert(1);"><p><font color="red">foo</font><script>alert(1);</script></p></div>';
+ * wysihtml5.dom.parse(userHTML, {
+ * tags {
+ * p: "div", // Rename p tags to div tags
+ * font: "span" // Rename font tags to span tags
+ * div: true, // Keep them, also possible (same result when passing: "div" or true)
+ * script: undefined // Remove script elements
+ * }
+ * });
+ * // => <div><div><span>foo bar</span></div></div>
+ *
+ * var userHTML = '<table><tbody><tr><td>I'm a table!</td></tr></tbody></table>';
+ * wysihtml5.dom.parse(userHTML);
+ * // => '<span><span><span><span>I'm a table!</span></span></span></span>'
+ *
+ * var userHTML = '<div>foobar<br>foobar</div>';
+ * wysihtml5.dom.parse(userHTML, {
+ * tags: {
+ * div: undefined,
+ * br: true
+ * }
+ * });
+ * // => ''
+ *
+ * var userHTML = '<div class="red">foo</div><div class="pink">bar</div>';
+ * wysihtml5.dom.parse(userHTML, {
+ * classes: {
+ * red: 1,
+ * green: 1
+ * },
+ * tags: {
+ * div: {
+ * rename_tag: "p"
+ * }
+ * }
+ * });
+ * // => '<p class="red">foo</p><p>bar</p>'
+ */
+
+wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
+ /* TODO: Currently escaped module pattern as otherwise folloowing default swill be shared among multiple editors.
+ * Refactor whole code as this method while workind is kind of awkward too */
+
+ /**
+ * It's not possible to use a XMLParser/DOMParser as HTML5 is not always well-formed XML
+ * new DOMParser().parseFromString('<img src="foo.gif">') will cause a parseError since the
+ * node isn't closed
+ *
+ * Therefore we've to use the browser's ordinary HTML parser invoked by setting innerHTML.
+ */
+ var NODE_TYPE_MAPPING = {
+ "1": _handleElement,
+ "3": _handleText,
+ "8": _handleComment
+ },
+ // Rename unknown tags to this
+ DEFAULT_NODE_NAME = "span",
+ WHITE_SPACE_REG_EXP = /\s+/,
+ defaultRules = { tags: {}, classes: {} },
+ currentRules = {},
+ blockElements = ["ADDRESS" ,"BLOCKQUOTE" ,"CENTER" ,"DIR" ,"DIV" ,"DL" ,"FIELDSET" ,
+ "FORM", "H1" ,"H2" ,"H3" ,"H4" ,"H5" ,"H6" ,"ISINDEX" ,"MENU",
+ "NOFRAMES", "NOSCRIPT" ,"OL" ,"P" ,"PRE","TABLE", "UL"];
+
+ /**
+ * Iterates over all childs of the element, recreates them, appends them into a document fragment
+ * which later replaces the entire body content
+ */
+ function parse(elementOrHtml, config) {
+ wysihtml5.lang.object(currentRules).merge(defaultRules).merge(config.rules).get();
+
+ var context = config.context || elementOrHtml.ownerDocument || document,
+ fragment = context.createDocumentFragment(),
+ isString = typeof(elementOrHtml) === "string",
+ clearInternals = false,
+ element,
+ newNode,
+ firstChild;
+
+ if (config.clearInternals === true) {
+ clearInternals = true;
+ }
+
+ if (isString) {
+ element = wysihtml5.dom.getAsDom(elementOrHtml, context);
+ } else {
+ element = elementOrHtml;
+ }
+
+ if (currentRules.selectors) {
+ _applySelectorRules(element, currentRules.selectors);
+ }
+
+ while (element.firstChild) {
+ firstChild = element.firstChild;
+ newNode = _convert(firstChild, config.cleanUp, clearInternals, config.uneditableClass);
+ if (newNode) {
+ fragment.appendChild(newNode);
+ }
+ if (firstChild !== newNode) {
+ element.removeChild(firstChild);
+ }
+ }
+
+ if (config.unjoinNbsps) {
+ // replace joined non-breakable spaces with unjoined
+ var txtnodes = wysihtml5.dom.getTextNodes(fragment);
+ for (var n = txtnodes.length; n--;) {
+ txtnodes[n].nodeValue = txtnodes[n].nodeValue.replace(/([\S\u00A0])\u00A0/gi, "$1 ");
+ }
+ }
+
+ // Clear element contents
+ element.innerHTML = "";
+
+ // Insert new DOM tree
+ element.appendChild(fragment);
+
+ return isString ? wysihtml5.quirks.getCorrectInnerHTML(element) : element;
+ }
+
+ function _convert(oldNode, cleanUp, clearInternals, uneditableClass) {
+ var oldNodeType = oldNode.nodeType,
+ oldChilds = oldNode.childNodes,
+ oldChildsLength = oldChilds.length,
+ method = NODE_TYPE_MAPPING[oldNodeType],
+ i = 0,
+ fragment,
+ newNode,
+ newChild,
+ nodeDisplay;
+
+ // Passes directly elemets with uneditable class
+ if (uneditableClass && oldNodeType === 1 && wysihtml5.dom.hasClass(oldNode, uneditableClass)) {
+ return oldNode;
+ }
+
+ newNode = method && method(oldNode, clearInternals);
+
+ // Remove or unwrap node in case of return value null or false
+ if (!newNode) {
+ if (newNode === false) {
+ // false defines that tag should be removed but contents should remain (unwrap)
+ fragment = oldNode.ownerDocument.createDocumentFragment();
+
+ for (i = oldChildsLength; i--;) {
+ if (oldChilds[i]) {
+ newChild = _convert(oldChilds[i], cleanUp, clearInternals, uneditableClass);
+ if (newChild) {
+ if (oldChilds[i] === newChild) {
+ i--;
+ }
+ fragment.insertBefore(newChild, fragment.firstChild);
+ }
+ }
+ }
+
+ nodeDisplay = wysihtml5.dom.getStyle("display").from(oldNode);
+
+ if (nodeDisplay === '') {
+ // Handle display style when element not in dom
+ nodeDisplay = wysihtml5.lang.array(blockElements).contains(oldNode.tagName) ? "block" : "";
+ }
+ if (wysihtml5.lang.array(["block", "flex", "table"]).contains(nodeDisplay)) {
+ fragment.appendChild(oldNode.ownerDocument.createElement("br"));
+ }
+
+ // TODO: try to minimize surplus spaces
+ if (wysihtml5.lang.array([
+ "div", "pre", "p",
+ "table", "td", "th",
+ "ul", "ol", "li",
+ "dd", "dl",
+ "footer", "header", "section",
+ "h1", "h2", "h3", "h4", "h5", "h6"
+ ]).contains(oldNode.nodeName.toLowerCase()) && oldNode.parentNode.lastChild !== oldNode) {
+ // add space at first when unwraping non-textflow elements
+ if (!oldNode.nextSibling || oldNode.nextSibling.nodeType !== 3 || !(/^\s/).test(oldNode.nextSibling.nodeValue)) {
+ fragment.appendChild(oldNode.ownerDocument.createTextNode(" "));
+ }
+ }
+
+ if (fragment.normalize) {
+ fragment.normalize();
+ }
+ return fragment;
+ } else {
+ // Remove
+ return null;
+ }
+ }
+
+ // Converts all childnodes
+ for (i=0; i<oldChildsLength; i++) {
+ if (oldChilds[i]) {
+ newChild = _convert(oldChilds[i], cleanUp, clearInternals, uneditableClass);
+ if (newChild) {
+ if (oldChilds[i] === newChild) {
+ i--;
+ }
+ newNode.appendChild(newChild);
+ }
+ }
+ }
+
+ // Cleanup senseless <span> elements
+ if (cleanUp &&
+ newNode.nodeName.toLowerCase() === DEFAULT_NODE_NAME &&
+ (!newNode.childNodes.length ||
+ ((/^\s*$/gi).test(newNode.innerHTML) && (clearInternals || (oldNode.className !== "_wysihtml5-temp-placeholder" && oldNode.className !== "rangySelectionBoundary"))) ||
+ !newNode.attributes.length)
+ ) {
+ fragment = newNode.ownerDocument.createDocumentFragment();
+ while (newNode.firstChild) {
+ fragment.appendChild(newNode.firstChild);
+ }
+ if (fragment.normalize) {
+ fragment.normalize();
+ }
+ return fragment;
+ }
+
+ if (newNode.normalize) {
+ newNode.normalize();
+ }
+ return newNode;
+ }
+
+ function _applySelectorRules (element, selectorRules) {
+ var sel, method, els;
+
+ for (sel in selectorRules) {
+ if (selectorRules.hasOwnProperty(sel)) {
+ if (wysihtml5.lang.object(selectorRules[sel]).isFunction()) {
+ method = selectorRules[sel];
+ } else if (typeof(selectorRules[sel]) === "string" && elementHandlingMethods[selectorRules[sel]]) {
+ method = elementHandlingMethods[selectorRules[sel]];
+ }
+ els = element.querySelectorAll(sel);
+ for (var i = els.length; i--;) {
+ method(els[i]);
+ }
+ }
+ }
+ }
+
+ function _handleElement(oldNode, clearInternals) {
+ var rule,
+ newNode,
+ tagRules = currentRules.tags,
+ nodeName = oldNode.nodeName.toLowerCase(),
+ scopeName = oldNode.scopeName,
+ renameTag;
+
+ /**
+ * We already parsed that element
+ * ignore it! (yes, this sometimes happens in IE8 when the html is invalid)
+ */
+ if (oldNode._wysihtml5) {
+ return null;
+ }
+ oldNode._wysihtml5 = 1;
+
+ if (oldNode.className === "wysihtml5-temp") {
+ return null;
+ }
+
+ /**
+ * IE is the only browser who doesn't include the namespace in the
+ * nodeName, that's why we have to prepend it by ourselves
+ * scopeName is a proprietary IE feature
+ * read more here http://msdn.microsoft.com/en-us/library/ms534388(v=vs.85).aspx
+ */
+ if (scopeName && scopeName != "HTML") {
+ nodeName = scopeName + ":" + nodeName;
+ }
+ /**
+ * Repair node
+ * IE is a bit bitchy when it comes to invalid nested markup which includes unclosed tags
+ * A <p> doesn't need to be closed according HTML4-5 spec, we simply replace it with a <div> to preserve its content and layout
+ */
+ if ("outerHTML" in oldNode) {
+ if (!wysihtml5.browser.autoClosesUnclosedTags() &&
+ oldNode.nodeName === "P" &&
+ oldNode.outerHTML.slice(-4).toLowerCase() !== "</p>") {
+ nodeName = "div";
+ }
+ }
+
+ if (nodeName in tagRules) {
+ rule = tagRules[nodeName];
+ if (!rule || rule.remove) {
+ return null;
+ } else if (rule.unwrap) {
+ return false;
+ }
+ rule = typeof(rule) === "string" ? { rename_tag: rule } : rule;
+ } else if (oldNode.firstChild) {
+ rule = { rename_tag: DEFAULT_NODE_NAME };
+ } else {
+ // Remove empty unknown elements
+ return null;
+ }
+
+ // tests if type condition is met or node should be removed/unwrapped/renamed
+ if (rule.one_of_type && !_testTypes(oldNode, currentRules, rule.one_of_type, clearInternals)) {
+ if (rule.remove_action) {
+ if (rule.remove_action === "unwrap") {
+ return false;
+ } else if (rule.remove_action === "rename") {
+ renameTag = rule.remove_action_rename_to || DEFAULT_NODE_NAME;
+ } else {
+ return null;
+ }
+ } else {
+ return null;
+ }
+ }
+
+ newNode = oldNode.ownerDocument.createElement(renameTag || rule.rename_tag || nodeName);
+ _handleAttributes(oldNode, newNode, rule, clearInternals);
+ _handleStyles(oldNode, newNode, rule);
+
+ oldNode = null;
+
+ if (newNode.normalize) { newNode.normalize(); }
+ return newNode;
+ }
+
+ function _testTypes(oldNode, rules, types, clearInternals) {
+ var definition, type;
+
+ // do not interfere with placeholder span or pasting caret position is not maintained
+ if (oldNode.nodeName === "SPAN" && !clearInternals && (oldNode.className === "_wysihtml5-temp-placeholder" || oldNode.className === "rangySelectionBoundary")) {
+ return true;
+ }
+
+ for (type in types) {
+ if (types.hasOwnProperty(type) && rules.type_definitions && rules.type_definitions[type]) {
+ definition = rules.type_definitions[type];
+ if (_testType(oldNode, definition)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ function array_contains(a, obj) {
+ var i = a.length;
+ while (i--) {
+ if (a[i] === obj) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ function _testType(oldNode, definition) {
+
+ var nodeClasses = oldNode.getAttribute("class"),
+ nodeStyles = oldNode.getAttribute("style"),
+ classesLength, s, s_corrected, a, attr, currentClass, styleProp;
+
+ // test for methods
+ if (definition.methods) {
+ for (var m in definition.methods) {
+ if (definition.methods.hasOwnProperty(m) && typeCeckMethods[m]) {
+
+ if (typeCeckMethods[m](oldNode)) {
+ return true;
+ }
+ }
+ }
+ }
+
+ // test for classes, if one found return true
+ if (nodeClasses && definition.classes) {
+ nodeClasses = nodeClasses.replace(/^\s+/g, '').replace(/\s+$/g, '').split(WHITE_SPACE_REG_EXP);
+ classesLength = nodeClasses.length;
+ for (var i = 0; i < classesLength; i++) {
+ if (definition.classes[nodeClasses[i]]) {
+ return true;
+ }
+ }
+ }
+
+ // test for styles, if one found return true
+ if (nodeStyles && definition.styles) {
+
+ nodeStyles = nodeStyles.split(';');
+ for (s in definition.styles) {
+ if (definition.styles.hasOwnProperty(s)) {
+ for (var sp = nodeStyles.length; sp--;) {
+ styleProp = nodeStyles[sp].split(':');
+
+ if (styleProp[0].replace(/\s/g, '').toLowerCase() === s) {
+ if (definition.styles[s] === true || definition.styles[s] === 1 || wysihtml5.lang.array(definition.styles[s]).contains(styleProp[1].replace(/\s/g, '').toLowerCase()) ) {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // test for attributes in general against regex match
+ if (definition.attrs) {
+ for (a in definition.attrs) {
+ if (definition.attrs.hasOwnProperty(a)) {
+ attr = wysihtml5.dom.getAttribute(oldNode, a);
+ if (typeof(attr) === "string") {
+ if (attr.search(definition.attrs[a]) > -1) {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ function _handleStyles(oldNode, newNode, rule) {
+ var s, v;
+ if(rule && rule.keep_styles) {
+ for (s in rule.keep_styles) {
+ if (rule.keep_styles.hasOwnProperty(s)) {
+ v = (s === "float") ? oldNode.style.styleFloat || oldNode.style.cssFloat : oldNode.style[s];
+ // value can be regex and if so should match or style skipped
+ if (rule.keep_styles[s] instanceof RegExp && !(rule.keep_styles[s].test(v))) {
+ continue;
+ }
+ if (s === "float") {
+ // IE compability
+ newNode.style[(oldNode.style.styleFloat) ? 'styleFloat': 'cssFloat'] = v;
+ } else if (oldNode.style[s]) {
+ newNode.style[s] = v;
+ }
+ }
+ }
+ }
+ };
+
+ function _getAttributesBeginningWith(beginning, attributes) {
+ var returnAttributes = [];
+ for (var attr in attributes) {
+ if (attributes.hasOwnProperty(attr) && attr.indexOf(beginning) === 0) {
+ returnAttributes.push(attr);
+ }
+ }
+ return returnAttributes;
+ }
+
+ function _checkAttribute(attributeName, attributeValue, methodName, nodeName) {
+ var method = attributeCheckMethods[methodName],
+ newAttributeValue;
+
+ if (method) {
+ if (attributeValue || (attributeName === "alt" && nodeName == "IMG")) {
+ newAttributeValue = method(attributeValue);
+ if (typeof(newAttributeValue) === "string") {
+ return newAttributeValue;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ function _checkAttributes(oldNode, local_attributes) {
+ var globalAttributes = wysihtml5.lang.object(currentRules.attributes || {}).clone(), // global values for check/convert values of attributes
+ checkAttributes = wysihtml5.lang.object(globalAttributes).merge( wysihtml5.lang.object(local_attributes || {}).clone()).get(),
+ attributes = {},
+ oldAttributes = wysihtml5.dom.getAttributes(oldNode),
+ attributeName, newValue, matchingAttributes;
+
+ for (attributeName in checkAttributes) {
+ if ((/\*$/).test(attributeName)) {
+
+ matchingAttributes = _getAttributesBeginningWith(attributeName.slice(0,-1), oldAttributes);
+ for (var i = 0, imax = matchingAttributes.length; i < imax; i++) {
+
+ newValue = _checkAttribute(matchingAttributes[i], oldAttributes[matchingAttributes[i]], checkAttributes[attributeName], oldNode.nodeName);
+ if (newValue !== false) {
+ attributes[matchingAttributes[i]] = newValue;
+ }
+ }
+ } else {
+ newValue = _checkAttribute(attributeName, oldAttributes[attributeName], checkAttributes[attributeName], oldNode.nodeName);
+ if (newValue !== false) {
+ attributes[attributeName] = newValue;
+ }
+ }
+ }
+
+ return attributes;
+ }
+
+ // TODO: refactor. Too long to read
+ function _handleAttributes(oldNode, newNode, rule, clearInternals) {
+ var attributes = {}, // fresh new set of attributes to set on newNode
+ setClass = rule.set_class, // classes to set
+ addClass = rule.add_class, // add classes based on existing attributes
+ addStyle = rule.add_style, // add styles based on existing attributes
+ setAttributes = rule.set_attributes, // attributes to set on the current node
+ allowedClasses = currentRules.classes,
+ i = 0,
+ classes = [],
+ styles = [],
+ newClasses = [],
+ oldClasses = [],
+ classesLength,
+ newClassesLength,
+ currentClass,
+ newClass,
+ attributeName,
+ method;
+
+ if (setAttributes) {
+ attributes = wysihtml5.lang.object(setAttributes).clone();
+ }
+
+ // check/convert values of attributes
+ attributes = wysihtml5.lang.object(attributes).merge(_checkAttributes(oldNode, rule.check_attributes)).get();
+
+ if (setClass) {
+ classes.push(setClass);
+ }
+
+ if (addClass) {
+ for (attributeName in addClass) {
+ method = addClassMethods[addClass[attributeName]];
+ if (!method) {
+ continue;
+ }
+ newClass = method(wysihtml5.dom.getAttribute(oldNode, attributeName));
+ if (typeof(newClass) === "string") {
+ classes.push(newClass);
+ }
+ }
+ }
+
+ if (addStyle) {
+ for (attributeName in addStyle) {
+ method = addStyleMethods[addStyle[attributeName]];
+ if (!method) {
+ continue;
+ }
+
+ newStyle = method(wysihtml5.dom.getAttribute(oldNode, attributeName));
+ if (typeof(newStyle) === "string") {
+ styles.push(newStyle);
+ }
+ }
+ }
+
+
+ if (typeof(allowedClasses) === "string" && allowedClasses === "any" && oldNode.getAttribute("class")) {
+ if (currentRules.classes_blacklist) {
+ oldClasses = oldNode.getAttribute("class");
+ if (oldClasses) {
+ classes = classes.concat(oldClasses.split(WHITE_SPACE_REG_EXP));
+ }
+
+ classesLength = classes.length;
+ for (; i<classesLength; i++) {
+ currentClass = classes[i];
+ if (!currentRules.classes_blacklist[currentClass]) {
+ newClasses.push(currentClass);
+ }
+ }
+
+ if (newClasses.length) {
+ attributes["class"] = wysihtml5.lang.array(newClasses).unique().join(" ");
+ }
+
+ } else {
+ attributes["class"] = oldNode.getAttribute("class");
+ }
+ } else {
+ // make sure that wysihtml5 temp class doesn't get stripped out
+ if (!clearInternals) {
+ allowedClasses["_wysihtml5-temp-placeholder"] = 1;
+ allowedClasses["_rangySelectionBoundary"] = 1;
+ allowedClasses["wysiwyg-tmp-selected-cell"] = 1;
+ }
+
+ // add old classes last
+ oldClasses = oldNode.getAttribute("class");
+ if (oldClasses) {
+ classes = classes.concat(oldClasses.split(WHITE_SPACE_REG_EXP));
+ }
+ classesLength = classes.length;
+ for (; i<classesLength; i++) {
+ currentClass = classes[i];
+ if (allowedClasses[currentClass]) {
+ newClasses.push(currentClass);
+ }
+ }
+
+ if (newClasses.length) {
+ attributes["class"] = wysihtml5.lang.array(newClasses).unique().join(" ");
+ }
+ }
+
+ // remove table selection class if present
+ if (attributes["class"] && clearInternals) {
+ attributes["class"] = attributes["class"].replace("wysiwyg-tmp-selected-cell", "");
+ if ((/^\s*$/g).test(attributes["class"])) {
+ delete attributes["class"];
+ }
+ }
+
+ if (styles.length) {
+ attributes["style"] = wysihtml5.lang.array(styles).unique().join(" ");
+ }
+
+ // set attributes on newNode
+ for (attributeName in attributes) {
+ // Setting attributes can cause a js error in IE under certain circumstances
+ // eg. on a <img> under https when it's new attribute value is non-https
+ // TODO: Investigate this further and check for smarter handling
+ try {
+ newNode.setAttribute(attributeName, attributes[attributeName]);
+ } catch(e) {}
+ }
+
+ // IE8 sometimes loses the width/height attributes when those are set before the "src"
+ // so we make sure to set them again
+ if (attributes.src) {
+ if (typeof(attributes.width) !== "undefined") {
+ newNode.setAttribute("width", attributes.width);
+ }
+ if (typeof(attributes.height) !== "undefined") {
+ newNode.setAttribute("height", attributes.height);
+ }
+ }
+ }
+
+ function _handleText(oldNode) {
+ var nextSibling = oldNode.nextSibling;
+ if (nextSibling && nextSibling.nodeType === wysihtml5.TEXT_NODE) {
+ // Concatenate text nodes
+ nextSibling.data = oldNode.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "") + nextSibling.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "");
+ } else {
+ // \uFEFF = wysihtml5.INVISIBLE_SPACE (used as a hack in certain rich text editing situations)
+ var data = oldNode.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "");
+ return oldNode.ownerDocument.createTextNode(data);
+ }
+ }
+
+ function _handleComment(oldNode) {
+ if (currentRules.comments) {
+ return oldNode.ownerDocument.createComment(oldNode.nodeValue);
+ }
+ }
+
+ // ------------ attribute checks ------------ \\
+ var attributeCheckMethods = {
+ url: (function() {
+ var REG_EXP = /^https?:\/\//i;
+ return function(attributeValue) {
+ if (!attributeValue || !attributeValue.match(REG_EXP)) {
+ return null;
+ }
+ return attributeValue.replace(REG_EXP, function(match) {
+ return match.toLowerCase();
+ });
+ };
+ })(),
+
+ src: (function() {
+ var REG_EXP = /^(\/|https?:\/\/)/i;
+ return function(attributeValue) {
+ if (!attributeValue || !attributeValue.match(REG_EXP)) {
+ return null;
+ }
+ return attributeValue.replace(REG_EXP, function(match) {
+ return match.toLowerCase();
+ });
+ };
+ })(),
+
+ href: (function() {
+ var REG_EXP = /^(#|\/|https?:\/\/|mailto:)/i;
+ return function(attributeValue) {
+ if (!attributeValue || !attributeValue.match(REG_EXP)) {
+ return null;
+ }
+ return attributeValue.replace(REG_EXP, function(match) {
+ return match.toLowerCase();
+ });
+ };
+ })(),
+
+ alt: (function() {
+ var REG_EXP = /[^ a-z0-9_\-]/gi;
+ return function(attributeValue) {
+ if (!attributeValue) {
+ return "";
+ }
+ return attributeValue.replace(REG_EXP, "");
+ };
+ })(),
+
+ numbers: (function() {
+ var REG_EXP = /\D/g;
+ return function(attributeValue) {
+ attributeValue = (attributeValue || "").replace(REG_EXP, "");
+ return attributeValue || null;
+ };
+ })(),
+
+ any: (function() {
+ return function(attributeValue) {
+ return attributeValue;
+ };
+ })()
+ };
+
+ // ------------ style converter (converts an html attribute to a style) ------------ \\
+ var addStyleMethods = {
+ align_text: (function() {
+ var mapping = {
+ left: "text-align: left;",
+ right: "text-align: right;",
+ center: "text-align: center;"
+ };
+ return function(attributeValue) {
+ return mapping[String(attributeValue).toLowerCase()];
+ };
+ })(),
+ };
+
+ // ------------ class converter (converts an html attribute to a class name) ------------ \\
+ var addClassMethods = {
+ align_img: (function() {
+ var mapping = {
+ left: "wysiwyg-float-left",
+ right: "wysiwyg-float-right"
+ };
+ return function(attributeValue) {
+ return mapping[String(attributeValue).toLowerCase()];
+ };
+ })(),
+
+ align_text: (function() {
+ var mapping = {
+ left: "wysiwyg-text-align-left",
+ right: "wysiwyg-text-align-right",
+ center: "wysiwyg-text-align-center",
+ justify: "wysiwyg-text-align-justify"
+ };
+ return function(attributeValue) {
+ return mapping[String(attributeValue).toLowerCase()];
+ };
+ })(),
+
+ clear_br: (function() {
+ var mapping = {
+ left: "wysiwyg-clear-left",
+ right: "wysiwyg-clear-right",
+ both: "wysiwyg-clear-both",
+ all: "wysiwyg-clear-both"
+ };
+ return function(attributeValue) {
+ return mapping[String(attributeValue).toLowerCase()];
+ };
+ })(),
+
+ size_font: (function() {
+ var mapping = {
+ "1": "wysiwyg-font-size-xx-small",
+ "2": "wysiwyg-font-size-small",
+ "3": "wysiwyg-font-size-medium",
+ "4": "wysiwyg-font-size-large",
+ "5": "wysiwyg-font-size-x-large",
+ "6": "wysiwyg-font-size-xx-large",
+ "7": "wysiwyg-font-size-xx-large",
+ "-": "wysiwyg-font-size-smaller",
+ "+": "wysiwyg-font-size-larger"
+ };
+ return function(attributeValue) {
+ return mapping[String(attributeValue).charAt(0)];
+ };
+ })()
+ };
+
+ // checks if element is possibly visible
+ var typeCeckMethods = {
+ has_visible_contet: (function() {
+ var txt,
+ isVisible = false,
+ visibleElements = ['img', 'video', 'picture', 'br', 'script', 'noscript',
+ 'style', 'table', 'iframe', 'object', 'embed', 'audio',
+ 'svg', 'input', 'button', 'select','textarea', 'canvas'];
+
+ return function(el) {
+
+ // has visible innertext. so is visible
+ txt = (el.innerText || el.textContent).replace(/\s/g, '');
+ if (txt && txt.length > 0) {
+ return true;
+ }
+
+ // matches list of visible dimensioned elements
+ for (var i = visibleElements.length; i--;) {
+ if (el.querySelector(visibleElements[i])) {
+ return true;
+ }
+ }
+
+ // try to measure dimesions in last resort. (can find only of elements in dom)
+ if (el.offsetWidth && el.offsetWidth > 0 && el.offsetHeight && el.offsetHeight > 0) {
+ return true;
+ }
+
+ return false;
+ };
+ })()
+ };
+
+ var elementHandlingMethods = {
+ unwrap: function (element) {
+ wysihtml5.dom.unwrap(element);
+ },
+
+ remove: function (element) {
+ element.parentNode.removeChild(element);
+ }
+ };
+
+ return parse(elementOrHtml_current, config_current);
+};
+;/**
+ * Checks for empty text node childs and removes them
+ *
+ * @param {Element} node The element in which to cleanup
+ * @example
+ * wysihtml5.dom.removeEmptyTextNodes(element);
+ */
+wysihtml5.dom.removeEmptyTextNodes = function(node) {
+ var childNode,
+ childNodes = wysihtml5.lang.array(node.childNodes).get(),
+ childNodesLength = childNodes.length,
+ i = 0;
+ for (; i<childNodesLength; i++) {
+ childNode = childNodes[i];
+ if (childNode.nodeType === wysihtml5.TEXT_NODE && childNode.data === "") {
+ childNode.parentNode.removeChild(childNode);
+ }
+ }
+};
+;/**
+ * Renames an element (eg. a <div> to a <p>) and keeps its childs
+ *
+ * @param {Element} element The list element which should be renamed
+ * @param {Element} newNodeName The desired tag name
+ *
+ * @example
+ * <!-- Assume the following dom: -->
+ * <ul id="list">
+ * <li>eminem</li>
+ * <li>dr. dre</li>
+ * <li>50 Cent</li>
+ * </ul>
+ *
+ * <script>
+ * wysihtml5.dom.renameElement(document.getElementById("list"), "ol");
+ * </script>
+ *
+ * <!-- Will result in: -->
+ * <ol>
+ * <li>eminem</li>
+ * <li>dr. dre</li>
+ * <li>50 Cent</li>
+ * </ol>
+ */
+wysihtml5.dom.renameElement = function(element, newNodeName) {
+ var newElement = element.ownerDocument.createElement(newNodeName),
+ firstChild;
+ while (firstChild = element.firstChild) {
+ newElement.appendChild(firstChild);
+ }
+ wysihtml5.dom.copyAttributes(["align", "className"]).from(element).to(newElement);
+ element.parentNode.replaceChild(newElement, element);
+ return newElement;
+};
+;/**
+ * Takes an element, removes it and replaces it with it's childs
+ *
+ * @param {Object} node The node which to replace with it's child nodes
+ * @example
+ * <div id="foo">
+ * <span>hello</span>
+ * </div>
+ * <script>
+ * // Remove #foo and replace with it's children
+ * wysihtml5.dom.replaceWithChildNodes(document.getElementById("foo"));
+ * </script>
+ */
+wysihtml5.dom.replaceWithChildNodes = function(node) {
+ if (!node.parentNode) {
+ return;
+ }
+
+ if (!node.firstChild) {
+ node.parentNode.removeChild(node);
+ return;
+ }
+
+ var fragment = node.ownerDocument.createDocumentFragment();
+ while (node.firstChild) {
+ fragment.appendChild(node.firstChild);
+ }
+ node.parentNode.replaceChild(fragment, node);
+ node = fragment = null;
+};
+;/**
+ * Unwraps an unordered/ordered list
+ *
+ * @param {Element} element The list element which should be unwrapped
+ *
+ * @example
+ * <!-- Assume the following dom: -->
+ * <ul id="list">
+ * <li>eminem</li>
+ * <li>dr. dre</li>
+ * <li>50 Cent</li>
+ * </ul>
+ *
+ * <script>
+ * wysihtml5.dom.resolveList(document.getElementById("list"));
+ * </script>
+ *
+ * <!-- Will result in: -->
+ * eminem<br>
+ * dr. dre<br>
+ * 50 Cent<br>
+ */
+(function(dom) {
+ function _isBlockElement(node) {
+ return dom.getStyle("display").from(node) === "block";
+ }
+
+ function _isLineBreak(node) {
+ return node.nodeName === "BR";
+ }
+
+ function _appendLineBreak(element) {
+ var lineBreak = element.ownerDocument.createElement("br");
+ element.appendChild(lineBreak);
+ }
+
+ function resolveList(list, useLineBreaks) {
+ if (!list.nodeName.match(/^(MENU|UL|OL)$/)) {
+ return;
+ }
+
+ var doc = list.ownerDocument,
+ fragment = doc.createDocumentFragment(),
+ previousSibling = wysihtml5.dom.domNode(list).prev({ignoreBlankTexts: true}),
+ firstChild,
+ lastChild,
+ isLastChild,
+ shouldAppendLineBreak,
+ paragraph,
+ listItem;
+
+ if (useLineBreaks) {
+ // Insert line break if list is after a non-block element
+ if (previousSibling && !_isBlockElement(previousSibling) && !_isLineBreak(previousSibling)) {
+ _appendLineBreak(fragment);
+ }
+
+ while (listItem = (list.firstElementChild || list.firstChild)) {
+ lastChild = listItem.lastChild;
+ while (firstChild = listItem.firstChild) {
+ isLastChild = firstChild === lastChild;
+ // This needs to be done before appending it to the fragment, as it otherwise will lose style information
+ shouldAppendLineBreak = isLastChild && !_isBlockElement(firstChild) && !_isLineBreak(firstChild);
+ fragment.appendChild(firstChild);
+ if (shouldAppendLineBreak) {
+ _appendLineBreak(fragment);
+ }
+ }
+
+ listItem.parentNode.removeChild(listItem);
+ }
+ } else {
+ while (listItem = (list.firstElementChild || list.firstChild)) {
+ if (listItem.querySelector && listItem.querySelector("div, p, ul, ol, menu, blockquote, h1, h2, h3, h4, h5, h6")) {
+ while (firstChild = listItem.firstChild) {
+ fragment.appendChild(firstChild);
+ }
+ } else {
+ paragraph = doc.createElement("p");
+ while (firstChild = listItem.firstChild) {
+ paragraph.appendChild(firstChild);
+ }
+ fragment.appendChild(paragraph);
+ }
+ listItem.parentNode.removeChild(listItem);
+ }
+ }
+
+ list.parentNode.replaceChild(fragment, list);
+ }
+
+ dom.resolveList = resolveList;
+})(wysihtml5.dom);
+;/**
+ * Sandbox for executing javascript, parsing css styles and doing dom operations in a secure way
+ *
+ * Browser Compatibility:
+ * - Secure in MSIE 6+, but only when the user hasn't made changes to his security level "restricted"
+ * - Partially secure in other browsers (Firefox, Opera, Safari, Chrome, ...)
+ *
+ * Please note that this class can't benefit from the HTML5 sandbox attribute for the following reasons:
+ * - sandboxing doesn't work correctly with inlined content (src="javascript:'<html>...</html>'")
+ * - sandboxing of physical documents causes that the dom isn't accessible anymore from the outside (iframe.contentWindow, ...)
+ * - setting the "allow-same-origin" flag would fix that, but then still javascript and dom events refuse to fire
+ * - therefore the "allow-scripts" flag is needed, which then would deactivate any security, as the js executed inside the iframe
+ * can do anything as if the sandbox attribute wasn't set
+ *
+ * @param {Function} [readyCallback] Method that gets invoked when the sandbox is ready
+ * @param {Object} [config] Optional parameters
+ *
+ * @example
+ * new wysihtml5.dom.Sandbox(function(sandbox) {
+ * sandbox.getWindow().document.body.innerHTML = '<img src=foo.gif onerror="alert(document.cookie)">';
+ * });
+ */
+(function(wysihtml5) {
+ var /**
+ * Default configuration
+ */
+ doc = document,
+ /**
+ * Properties to unset/protect on the window object
+ */
+ windowProperties = [
+ "parent", "top", "opener", "frameElement", "frames",
+ "localStorage", "globalStorage", "sessionStorage", "indexedDB"
+ ],
+ /**
+ * Properties on the window object which are set to an empty function
+ */
+ windowProperties2 = [
+ "open", "close", "openDialog", "showModalDialog",
+ "alert", "confirm", "prompt",
+ "openDatabase", "postMessage",
+ "XMLHttpRequest", "XDomainRequest"
+ ],
+ /**
+ * Properties to unset/protect on the document object
+ */
+ documentProperties = [
+ "referrer",
+ "write", "open", "close"
+ ];
+
+ wysihtml5.dom.Sandbox = Base.extend(
+ /** @scope wysihtml5.dom.Sandbox.prototype */ {
+
+ constructor: function(readyCallback, config) {
+ this.callback = readyCallback || wysihtml5.EMPTY_FUNCTION;
+ this.config = wysihtml5.lang.object({}).merge(config).get();
+ this.editableArea = this._createIframe();
+ },
+
+ insertInto: function(element) {
+ if (typeof(element) === "string") {
+ element = doc.getElementById(element);
+ }
+
+ element.appendChild(this.editableArea);
+ },
+
+ getIframe: function() {
+ return this.editableArea;
+ },
+
+ getWindow: function() {
+ this._readyError();
+ },
+
+ getDocument: function() {
+ this._readyError();
+ },
+
+ destroy: function() {
+ var iframe = this.getIframe();
+ iframe.parentNode.removeChild(iframe);
+ },
+
+ _readyError: function() {
+ throw new Error("wysihtml5.Sandbox: Sandbox iframe isn't loaded yet");
+ },
+
+ /**
+ * Creates the sandbox iframe
+ *
+ * Some important notes:
+ * - We can't use HTML5 sandbox for now:
+ * setting it causes that the iframe's dom can't be accessed from the outside
+ * Therefore we need to set the "allow-same-origin" flag which enables accessing the iframe's dom
+ * But then there's another problem, DOM events (focus, blur, change, keypress, ...) aren't fired.
+ * In order to make this happen we need to set the "allow-scripts" flag.
+ * A combination of allow-scripts and allow-same-origin is almost the same as setting no sandbox attribute at all.
+ * - Chrome & Safari, doesn't seem to support sandboxing correctly when the iframe's html is inlined (no physical document)
+ * - IE needs to have the security="restricted" attribute set before the iframe is
+ * inserted into the dom tree
+ * - Believe it or not but in IE "security" in document.createElement("iframe") is false, even
+ * though it supports it
+ * - When an iframe has security="restricted", in IE eval() & execScript() don't work anymore
+ * - IE doesn't fire the onload event when the content is inlined in the src attribute, therefore we rely
+ * on the onreadystatechange event
+ */
+ _createIframe: function() {
+ var that = this,
+ iframe = doc.createElement("iframe");
+ iframe.className = "wysihtml5-sandbox";
+ wysihtml5.dom.setAttributes({
+ "security": "restricted",
+ "allowtransparency": "true",
+ "frameborder": 0,
+ "width": 0,
+ "height": 0,
+ "marginwidth": 0,
+ "marginheight": 0
+ }).on(iframe);
+
+ // Setting the src like this prevents ssl warnings in IE6
+ if (wysihtml5.browser.throwsMixedContentWarningWhenIframeSrcIsEmpty()) {
+ iframe.src = "javascript:'<html></html>'";
+ }
+
+ iframe.onload = function() {
+ iframe.onreadystatechange = iframe.onload = null;
+ that._onLoadIframe(iframe);
+ };
+
+ iframe.onreadystatechange = function() {
+ if (/loaded|complete/.test(iframe.readyState)) {
+ iframe.onreadystatechange = iframe.onload = null;
+ that._onLoadIframe(iframe);
+ }
+ };
+
+ return iframe;
+ },
+
+ /**
+ * Callback for when the iframe has finished loading
+ */
+ _onLoadIframe: function(iframe) {
+ // don't resume when the iframe got unloaded (eg. by removing it from the dom)
+ if (!wysihtml5.dom.contains(doc.documentElement, iframe)) {
+ return;
+ }
+
+ var that = this,
+ iframeWindow = iframe.contentWindow,
+ iframeDocument = iframe.contentWindow.document,
+ charset = doc.characterSet || doc.charset || "utf-8",
+ sandboxHtml = this._getHtml({
+ charset: charset,
+ stylesheets: this.config.stylesheets
+ });
+
+ // Create the basic dom tree including proper DOCTYPE and charset
+ iframeDocument.open("text/html", "replace");
+ iframeDocument.write(sandboxHtml);
+ iframeDocument.close();
+
+ this.getWindow = function() { return iframe.contentWindow; };
+ this.getDocument = function() { return iframe.contentWindow.document; };
+
+ // Catch js errors and pass them to the parent's onerror event
+ // addEventListener("error") doesn't work properly in some browsers
+ // TODO: apparently this doesn't work in IE9!
+ iframeWindow.onerror = function(errorMessage, fileName, lineNumber) {
+ throw new Error("wysihtml5.Sandbox: " + errorMessage, fileName, lineNumber);
+ };
+
+ if (!wysihtml5.browser.supportsSandboxedIframes()) {
+ // Unset a bunch of sensitive variables
+ // Please note: This isn't hack safe!
+ // It more or less just takes care of basic attacks and prevents accidental theft of sensitive information
+ // IE is secure though, which is the most important thing, since IE is the only browser, who
+ // takes over scripts & styles into contentEditable elements when copied from external websites
+ // or applications (Microsoft Word, ...)
+ var i, length;
+ for (i=0, length=windowProperties.length; i<length; i++) {
+ this._unset(iframeWindow, windowProperties[i]);
+ }
+ for (i=0, length=windowProperties2.length; i<length; i++) {
+ this._unset(iframeWindow, windowProperties2[i], wysihtml5.EMPTY_FUNCTION);
+ }
+ for (i=0, length=documentProperties.length; i<length; i++) {
+ this._unset(iframeDocument, documentProperties[i]);
+ }
+ // This doesn't work in Safari 5
+ // See http://stackoverflow.com/questions/992461/is-it-possible-to-override-document-cookie-in-webkit
+ this._unset(iframeDocument, "cookie", "", true);
+ }
+
+ this.loaded = true;
+
+ // Trigger the callback
+ setTimeout(function() { that.callback(that); }, 0);
+ },
+
+ _getHtml: function(templateVars) {
+ var stylesheets = templateVars.stylesheets,
+ html = "",
+ i = 0,
+ length;
+ stylesheets = typeof(stylesheets) === "string" ? [stylesheets] : stylesheets;
+ if (stylesheets) {
+ length = stylesheets.length;
+ for (; i<length; i++) {
+ html += '<link rel="stylesheet" href="' + stylesheets[i] + '">';
+ }
+ }
+ templateVars.stylesheets = html;
+
+ return wysihtml5.lang.string(
+ '<!DOCTYPE html><html><head>'
+ + '<meta charset="#{charset}">#{stylesheets}</head>'
+ + '<body></body></html>'
+ ).interpolate(templateVars);
+ },
+
+ /**
+ * Method to unset/override existing variables
+ * @example
+ * // Make cookie unreadable and unwritable
+ * this._unset(document, "cookie", "", true);
+ */
+ _unset: function(object, property, value, setter) {
+ try { object[property] = value; } catch(e) {}
+
+ try { object.__defineGetter__(property, function() { return value; }); } catch(e) {}
+ if (setter) {
+ try { object.__defineSetter__(property, function() {}); } catch(e) {}
+ }
+
+ if (!wysihtml5.browser.crashesWhenDefineProperty(property)) {
+ try {
+ var config = {
+ get: function() { return value; }
+ };
+ if (setter) {
+ config.set = function() {};
+ }
+ Object.defineProperty(object, property, config);
+ } catch(e) {}
+ }
+ }
+ });
+})(wysihtml5);
+;(function(wysihtml5) {
+ var doc = document;
+ wysihtml5.dom.ContentEditableArea = Base.extend({
+ getContentEditable: function() {
+ return this.element;
+ },
+
+ getWindow: function() {
+ return this.element.ownerDocument.defaultView;
+ },
+
+ getDocument: function() {
+ return this.element.ownerDocument;
+ },
+
+ constructor: function(readyCallback, config, contentEditable) {
+ this.callback = readyCallback || wysihtml5.EMPTY_FUNCTION;
+ this.config = wysihtml5.lang.object({}).merge(config).get();
+ if (contentEditable) {
+ this.element = this._bindElement(contentEditable);
+ } else {
+ this.element = this._createElement();
+ }
+ },
+
+ // creates a new contenteditable and initiates it
+ _createElement: function() {
+ var element = doc.createElement("div");
+ element.className = "wysihtml5-sandbox";
+ this._loadElement(element);
+ return element;
+ },
+
+ // initiates an allready existent contenteditable
+ _bindElement: function(contentEditable) {
+ contentEditable.className = (contentEditable.className && contentEditable.className != '') ? contentEditable.className + " wysihtml5-sandbox" : "wysihtml5-sandbox";
+ this._loadElement(contentEditable, true);
+ return contentEditable;
+ },
+
+ _loadElement: function(element, contentExists) {
+ var that = this;
+ if (!contentExists) {
+ var sandboxHtml = this._getHtml();
+ element.innerHTML = sandboxHtml;
+ }
+
+ this.getWindow = function() { return element.ownerDocument.defaultView; };
+ this.getDocument = function() { return element.ownerDocument; };
+
+ // Catch js errors and pass them to the parent's onerror event
+ // addEventListener("error") doesn't work properly in some browsers
+ // TODO: apparently this doesn't work in IE9!
+ // TODO: figure out and bind the errors logic for contenteditble mode
+ /*iframeWindow.onerror = function(errorMessage, fileName, lineNumber) {
+ throw new Error("wysihtml5.Sandbox: " + errorMessage, fileName, lineNumber);
+ }
+ */
+ this.loaded = true;
+ // Trigger the callback
+ setTimeout(function() { that.callback(that); }, 0);
+ },
+
+ _getHtml: function(templateVars) {
+ return '';
+ }
+
+ });
+})(wysihtml5);
+;(function() {
+ var mapping = {
+ "className": "class"
+ };
+ wysihtml5.dom.setAttributes = function(attributes) {
+ return {
+ on: function(element) {
+ for (var i in attributes) {
+ element.setAttribute(mapping[i] || i, attributes[i]);
+ }
+ }
+ };
+ };
+})();
+;wysihtml5.dom.setStyles = function(styles) {
+ return {
+ on: function(element) {
+ var style = element.style;
+ if (typeof(styles) === "string") {
+ style.cssText += ";" + styles;
+ return;
+ }
+ for (var i in styles) {
+ if (i === "float") {
+ style.cssFloat = styles[i];
+ style.styleFloat = styles[i];
+ } else {
+ style[i] = styles[i];
+ }
+ }
+ }
+ };
+};
+;/**
+ * Simulate HTML5 placeholder attribute
+ *
+ * Needed since
+ * - div[contentEditable] elements don't support it
+ * - older browsers (such as IE8 and Firefox 3.6) don't support it at all
+ *
+ * @param {Object} parent Instance of main wysihtml5.Editor class
+ * @param {Element} view Instance of wysihtml5.views.* class
+ * @param {String} placeholderText
+ *
+ * @example
+ * wysihtml.dom.simulatePlaceholder(this, composer, "Foobar");
+ */
+(function(dom) {
+ dom.simulatePlaceholder = function(editor, view, placeholderText) {
+ var CLASS_NAME = "placeholder",
+ unset = function() {
+ var composerIsVisible = view.element.offsetWidth > 0 && view.element.offsetHeight > 0;
+ if (view.hasPlaceholderSet()) {
+ view.clear();
+ view.element.focus();
+ if (composerIsVisible ) {
+ setTimeout(function() {
+ var sel = view.selection.getSelection();
+ if (!sel.focusNode || !sel.anchorNode) {
+ view.selection.selectNode(view.element.firstChild || view.element);
+ }
+ }, 0);
+ }
+ }
+ view.placeholderSet = false;
+ dom.removeClass(view.element, CLASS_NAME);
+ },
+ set = function() {
+ if (view.isEmpty()) {
+ view.placeholderSet = true;
+ view.setValue(placeholderText);
+ dom.addClass(view.element, CLASS_NAME);
+ }
+ };
+
+ editor
+ .on("set_placeholder", set)
+ .on("unset_placeholder", unset)
+ .on("focus:composer", unset)
+ .on("paste:composer", unset)
+ .on("blur:composer", set);
+
+ set();
+ };
+})(wysihtml5.dom);
+;(function(dom) {
+ var documentElement = document.documentElement;
+ if ("textContent" in documentElement) {
+ dom.setTextContent = function(element, text) {
+ element.textContent = text;
+ };
+
+ dom.getTextContent = function(element) {
+ return element.textContent;
+ };
+ } else if ("innerText" in documentElement) {
+ dom.setTextContent = function(element, text) {
+ element.innerText = text;
+ };
+
+ dom.getTextContent = function(element) {
+ return element.innerText;
+ };
+ } else {
+ dom.setTextContent = function(element, text) {
+ element.nodeValue = text;
+ };
+
+ dom.getTextContent = function(element) {
+ return element.nodeValue;
+ };
+ }
+})(wysihtml5.dom);
+
+;/**
+ * Get a set of attribute from one element
+ *
+ * IE gives wrong results for hasAttribute/getAttribute, for example:
+ * var td = document.createElement("td");
+ * td.getAttribute("rowspan"); // => "1" in IE
+ *
+ * Therefore we have to check the element's outerHTML for the attribute
+*/
+
+wysihtml5.dom.getAttribute = function(node, attributeName) {
+ var HAS_GET_ATTRIBUTE_BUG = !wysihtml5.browser.supportsGetAttributeCorrectly();
+ attributeName = attributeName.toLowerCase();
+ var nodeName = node.nodeName;
+ if (nodeName == "IMG" && attributeName == "src" && wysihtml5.dom.isLoadedImage(node) === true) {
+ // Get 'src' attribute value via object property since this will always contain the
+ // full absolute url (http://...)
+ // this fixes a very annoying bug in firefox (ver 3.6 & 4) and IE 8 where images copied from the same host
+ // will have relative paths, which the sanitizer strips out (see attributeCheckMethods.url)
+ return node.src;
+ } else if (HAS_GET_ATTRIBUTE_BUG && "outerHTML" in node) {
+ // Don't trust getAttribute/hasAttribute in IE 6-8, instead check the element's outerHTML
+ var outerHTML = node.outerHTML.toLowerCase(),
+ // TODO: This might not work for attributes without value: <input disabled>
+ hasAttribute = outerHTML.indexOf(" " + attributeName + "=") != -1;
+
+ return hasAttribute ? node.getAttribute(attributeName) : null;
+ } else{
+ return node.getAttribute(attributeName);
+ }
+};
+;/**
+ * Get all attributes of an element
+ *
+ * IE gives wrong results for hasAttribute/getAttribute, for example:
+ * var td = document.createElement("td");
+ * td.getAttribute("rowspan"); // => "1" in IE
+ *
+ * Therefore we have to check the element's outerHTML for the attribute
+*/
+
+wysihtml5.dom.getAttributes = function(node) {
+ var HAS_GET_ATTRIBUTE_BUG = !wysihtml5.browser.supportsGetAttributeCorrectly(),
+ nodeName = node.nodeName,
+ attributes = [],
+ attr;
+
+ for (attr in node.attributes) {
+ if ((node.attributes.hasOwnProperty && node.attributes.hasOwnProperty(attr)) || (!node.attributes.hasOwnProperty && Object.prototype.hasOwnProperty.call(node.attributes, attr))) {
+ if (node.attributes[attr].specified) {
+ if (nodeName == "IMG" && node.attributes[attr].name.toLowerCase() == "src" && wysihtml5.dom.isLoadedImage(node) === true) {
+ attributes['src'] = node.src;
+ } else if (wysihtml5.lang.array(['rowspan', 'colspan']).contains(node.attributes[attr].name.toLowerCase()) && HAS_GET_ATTRIBUTE_BUG) {
+ if (node.attributes[attr].value !== 1) {
+ attributes[node.attributes[attr].name] = node.attributes[attr].value;
+ }
+ } else {
+ attributes[node.attributes[attr].name] = node.attributes[attr].value;
+ }
+ }
+ }
+ }
+ return attributes;
+};;/**
+ * Check whether the given node is a proper loaded image
+ * FIXME: Returns undefined when unknown (Chrome, Safari)
+*/
+
+wysihtml5.dom.isLoadedImage = function (node) {
+ try {
+ return node.complete && !node.mozMatchesSelector(":-moz-broken");
+ } catch(e) {
+ if (node.complete && node.readyState === "complete") {
+ return true;
+ }
+ }
+};
+;(function(wysihtml5) {
+
+ var api = wysihtml5.dom;
+
+ var MapCell = function(cell) {
+ this.el = cell;
+ this.isColspan= false;
+ this.isRowspan= false;
+ this.firstCol= true;
+ this.lastCol= true;
+ this.firstRow= true;
+ this.lastRow= true;
+ this.isReal= true;
+ this.spanCollection= [];
+ this.modified = false;
+ };
+
+ var TableModifyerByCell = function (cell, table) {
+ if (cell) {
+ this.cell = cell;
+ this.table = api.getParentElement(cell, { nodeName: ["TABLE"] });
+ } else if (table) {
+ this.table = table;
+ this.cell = this.table.querySelectorAll('th, td')[0];
+ }
+ };
+
+ function queryInList(list, query) {
+ var ret = [],
+ q;
+ for (var e = 0, len = list.length; e < len; e++) {
+ q = list[e].querySelectorAll(query);
+ if (q) {
+ for(var i = q.length; i--; ret.unshift(q[i]));
+ }
+ }
+ return ret;
+ }
+
+ function removeElement(el) {
+ el.parentNode.removeChild(el);
+ }
+
+ function insertAfter(referenceNode, newNode) {
+ referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
+ }
+
+ function nextNode(node, tag) {
+ var element = node.nextSibling;
+ while (element.nodeType !=1) {
+ element = element.nextSibling;
+ if (!tag || tag == element.tagName.toLowerCase()) {
+ return element;
+ }
+ }
+ return null;
+ }
+
+ TableModifyerByCell.prototype = {
+
+ addSpannedCellToMap: function(cell, map, r, c, cspan, rspan) {
+ var spanCollect = [],
+ rmax = r + ((rspan) ? parseInt(rspan, 10) - 1 : 0),
+ cmax = c + ((cspan) ? parseInt(cspan, 10) - 1 : 0);
+
+ for (var rr = r; rr <= rmax; rr++) {
+ if (typeof map[rr] == "undefined") { map[rr] = []; }
+ for (var cc = c; cc <= cmax; cc++) {
+ map[rr][cc] = new MapCell(cell);
+ map[rr][cc].isColspan = (cspan && parseInt(cspan, 10) > 1);
+ map[rr][cc].isRowspan = (rspan && parseInt(rspan, 10) > 1);
+ map[rr][cc].firstCol = cc == c;
+ map[rr][cc].lastCol = cc == cmax;
+ map[rr][cc].firstRow = rr == r;
+ map[rr][cc].lastRow = rr == rmax;
+ map[rr][cc].isReal = cc == c && rr == r;
+ map[rr][cc].spanCollection = spanCollect;
+
+ spanCollect.push(map[rr][cc]);
+ }
+ }
+ },
+
+ setCellAsModified: function(cell) {
+ cell.modified = true;
+ if (cell.spanCollection.length > 0) {
+ for (var s = 0, smax = cell.spanCollection.length; s < smax; s++) {
+ cell.spanCollection[s].modified = true;
+ }
+ }
+ },
+
+ setTableMap: function() {
+ var map = [];
+ var tableRows = this.getTableRows(),
+ ridx, row, cells, cidx, cell,
+ c,
+ cspan, rspan;
+
+ for (ridx = 0; ridx < tableRows.length; ridx++) {
+ row = tableRows[ridx];
+ cells = this.getRowCells(row);
+ c = 0;
+ if (typeof map[ridx] == "undefined") { map[ridx] = []; }
+ for (cidx = 0; cidx < cells.length; cidx++) {
+ cell = cells[cidx];
+
+ // If cell allready set means it is set by col or rowspan,
+ // so increase cols index until free col is found
+ while (typeof map[ridx][c] != "undefined") { c++; }
+
+ cspan = api.getAttribute(cell, 'colspan');
+ rspan = api.getAttribute(cell, 'rowspan');
+
+ if (cspan || rspan) {
+ this.addSpannedCellToMap(cell, map, ridx, c, cspan, rspan);
+ c = c + ((cspan) ? parseInt(cspan, 10) : 1);
+ } else {
+ map[ridx][c] = new MapCell(cell);
+ c++;
+ }
+ }
+ }
+ this.map = map;
+ return map;
+ },
+
+ getRowCells: function(row) {
+ var inlineTables = this.table.querySelectorAll('table'),
+ inlineCells = (inlineTables) ? queryInList(inlineTables, 'th, td') : [],
+ allCells = row.querySelectorAll('th, td'),
+ tableCells = (inlineCells.length > 0) ? wysihtml5.lang.array(allCells).without(inlineCells) : allCells;
+
+ return tableCells;
+ },
+
+ getTableRows: function() {
+ var inlineTables = this.table.querySelectorAll('table'),
+ inlineRows = (inlineTables) ? queryInList(inlineTables, 'tr') : [],
+ allRows = this.table.querySelectorAll('tr'),
+ tableRows = (inlineRows.length > 0) ? wysihtml5.lang.array(allRows).without(inlineRows) : allRows;
+
+ return tableRows;
+ },
+
+ getMapIndex: function(cell) {
+ var r_length = this.map.length,
+ c_length = (this.map && this.map[0]) ? this.map[0].length : 0;
+
+ for (var r_idx = 0;r_idx < r_length; r_idx++) {
+ for (var c_idx = 0;c_idx < c_length; c_idx++) {
+ if (this.map[r_idx][c_idx].el === cell) {
+ return {'row': r_idx, 'col': c_idx};
+ }
+ }
+ }
+ return false;
+ },
+
+ getElementAtIndex: function(idx) {
+ this.setTableMap();
+ if (this.map[idx.row] && this.map[idx.row][idx.col] && this.map[idx.row][idx.col].el) {
+ return this.map[idx.row][idx.col].el;
+ }
+ return null;
+ },
+
+ getMapElsTo: function(to_cell) {
+ var els = [];
+ this.setTableMap();
+ this.idx_start = this.getMapIndex(this.cell);
+ this.idx_end = this.getMapIndex(to_cell);
+
+ // switch indexes if start is bigger than end
+ if (this.idx_start.row > this.idx_end.row || (this.idx_start.row == this.idx_end.row && this.idx_start.col > this.idx_end.col)) {
+ var temp_idx = this.idx_start;
+ this.idx_start = this.idx_end;
+ this.idx_end = temp_idx;
+ }
+ if (this.idx_start.col > this.idx_end.col) {
+ var temp_cidx = this.idx_start.col;
+ this.idx_start.col = this.idx_end.col;
+ this.idx_end.col = temp_cidx;
+ }
+
+ if (this.idx_start != null && this.idx_end != null) {
+ for (var row = this.idx_start.row, maxr = this.idx_end.row; row <= maxr; row++) {
+ for (var col = this.idx_start.col, maxc = this.idx_end.col; col <= maxc; col++) {
+ els.push(this.map[row][col].el);
+ }
+ }
+ }
+ return els;
+ },
+
+ orderSelectionEnds: function(secondcell) {
+ this.setTableMap();
+ this.idx_start = this.getMapIndex(this.cell);
+ this.idx_end = this.getMapIndex(secondcell);
+
+ // switch indexes if start is bigger than end
+ if (this.idx_start.row > this.idx_end.row || (this.idx_start.row == this.idx_end.row && this.idx_start.col > this.idx_end.col)) {
+ var temp_idx = this.idx_start;
+ this.idx_start = this.idx_end;
+ this.idx_end = temp_idx;
+ }
+ if (this.idx_start.col > this.idx_end.col) {
+ var temp_cidx = this.idx_start.col;
+ this.idx_start.col = this.idx_end.col;
+ this.idx_end.col = temp_cidx;
+ }
+
+ return {
+ "start": this.map[this.idx_start.row][this.idx_start.col].el,
+ "end": this.map[this.idx_end.row][this.idx_end.col].el
+ };
+ },
+
+ createCells: function(tag, nr, attrs) {
+ var doc = this.table.ownerDocument,
+ frag = doc.createDocumentFragment(),
+ cell;
+ for (var i = 0; i < nr; i++) {
+ cell = doc.createElement(tag);
+
+ if (attrs) {
+ for (var attr in attrs) {
+ if (attrs.hasOwnProperty(attr)) {
+ cell.setAttribute(attr, attrs[attr]);
+ }
+ }
+ }
+
+ // add non breaking space
+ cell.appendChild(document.createTextNode("\u00a0"));
+
+ frag.appendChild(cell);
+ }
+ return frag;
+ },
+
+ // Returns next real cell (not part of spanned cell unless first) on row if selected index is not real. I no real cells -1 will be returned
+ correctColIndexForUnreals: function(col, row) {
+ var r = this.map[row],
+ corrIdx = -1;
+ for (var i = 0, max = col; i < col; i++) {
+ if (r[i].isReal){
+ corrIdx++;
+ }
+ }
+ return corrIdx;
+ },
+
+ getLastNewCellOnRow: function(row, rowLimit) {
+ var cells = this.getRowCells(row),
+ cell, idx;
+
+ for (var cidx = 0, cmax = cells.length; cidx < cmax; cidx++) {
+ cell = cells[cidx];
+ idx = this.getMapIndex(cell);
+ if (idx === false || (typeof rowLimit != "undefined" && idx.row != rowLimit)) {
+ return cell;
+ }
+ }
+ return null;
+ },
+
+ removeEmptyTable: function() {
+ var cells = this.table.querySelectorAll('td, th');
+ if (!cells || cells.length == 0) {
+ removeElement(this.table);
+ return true;
+ } else {
+ return false;
+ }
+ },
+
+ // Splits merged cell on row to unique cells
+ splitRowToCells: function(cell) {
+ if (cell.isColspan) {
+ var colspan = parseInt(api.getAttribute(cell.el, 'colspan') || 1, 10),
+ cType = cell.el.tagName.toLowerCase();
+ if (colspan > 1) {
+ var newCells = this.createCells(cType, colspan -1);
+ insertAfter(cell.el, newCells);
+ }
+ cell.el.removeAttribute('colspan');
+ }
+ },
+
+ getRealRowEl: function(force, idx) {
+ var r = null,
+ c = null;
+
+ idx = idx || this.idx;
+
+ for (var cidx = 0, cmax = this.map[idx.row].length; cidx < cmax; cidx++) {
+ c = this.map[idx.row][cidx];
+ if (c.isReal) {
+ r = api.getParentElement(c.el, { nodeName: ["TR"] });
+ if (r) {
+ return r;
+ }
+ }
+ }
+
+ if (r === null && force) {
+ r = api.getParentElement(this.map[idx.row][idx.col].el, { nodeName: ["TR"] }) || null;
+ }
+
+ return r;
+ },
+
+ injectRowAt: function(row, col, colspan, cType, c) {
+ var r = this.getRealRowEl(false, {'row': row, 'col': col}),
+ new_cells = this.createCells(cType, colspan);
+
+ if (r) {
+ var n_cidx = this.correctColIndexForUnreals(col, row);
+ if (n_cidx >= 0) {
+ insertAfter(this.getRowCells(r)[n_cidx], new_cells);
+ } else {
+ r.insertBefore(new_cells, r.firstChild);
+ }
+ } else {
+ var rr = this.table.ownerDocument.createElement('tr');
+ rr.appendChild(new_cells);
+ insertAfter(api.getParentElement(c.el, { nodeName: ["TR"] }), rr);
+ }
+ },
+
+ canMerge: function(to) {
+ this.to = to;
+ this.setTableMap();
+ this.idx_start = this.getMapIndex(this.cell);
+ this.idx_end = this.getMapIndex(this.to);
+
+ // switch indexes if start is bigger than end
+ if (this.idx_start.row > this.idx_end.row || (this.idx_start.row == this.idx_end.row && this.idx_start.col > this.idx_end.col)) {
+ var temp_idx = this.idx_start;
+ this.idx_start = this.idx_end;
+ this.idx_end = temp_idx;
+ }
+ if (this.idx_start.col > this.idx_end.col) {
+ var temp_cidx = this.idx_start.col;
+ this.idx_start.col = this.idx_end.col;
+ this.idx_end.col = temp_cidx;
+ }
+
+ for (var row = this.idx_start.row, maxr = this.idx_end.row; row <= maxr; row++) {
+ for (var col = this.idx_start.col, maxc = this.idx_end.col; col <= maxc; col++) {
+ if (this.map[row][col].isColspan || this.map[row][col].isRowspan) {
+ return false;
+ }
+ }
+ }
+ return true;
+ },
+
+ decreaseCellSpan: function(cell, span) {
+ var nr = parseInt(api.getAttribute(cell.el, span), 10) - 1;
+ if (nr >= 1) {
+ cell.el.setAttribute(span, nr);
+ } else {
+ cell.el.removeAttribute(span);
+ if (span == 'colspan') {
+ cell.isColspan = false;
+ }
+ if (span == 'rowspan') {
+ cell.isRowspan = false;
+ }
+ cell.firstCol = true;
+ cell.lastCol = true;
+ cell.firstRow = true;
+ cell.lastRow = true;
+ cell.isReal = true;
+ }
+ },
+
+ removeSurplusLines: function() {
+ var row, cell, ridx, rmax, cidx, cmax, allRowspan;
+
+ this.setTableMap();
+ if (this.map) {
+ ridx = 0;
+ rmax = this.map.length;
+ for (;ridx < rmax; ridx++) {
+ row = this.map[ridx];
+ allRowspan = true;
+ cidx = 0;
+ cmax = row.length;
+ for (; cidx < cmax; cidx++) {
+ cell = row[cidx];
+ if (!(api.getAttribute(cell.el, "rowspan") && parseInt(api.getAttribute(cell.el, "rowspan"), 10) > 1 && cell.firstRow !== true)) {
+ allRowspan = false;
+ break;
+ }
+ }
+ if (allRowspan) {
+ cidx = 0;
+ for (; cidx < cmax; cidx++) {
+ this.decreaseCellSpan(row[cidx], 'rowspan');
+ }
+ }
+ }
+
+ // remove rows without cells
+ var tableRows = this.getTableRows();
+ ridx = 0;
+ rmax = tableRows.length;
+ for (;ridx < rmax; ridx++) {
+ row = tableRows[ridx];
+ if (row.childNodes.length == 0 && (/^\s*$/.test(row.textContent || row.innerText))) {
+ removeElement(row);
+ }
+ }
+ }
+ },
+
+ fillMissingCells: function() {
+ var r_max = 0,
+ c_max = 0,
+ prevcell = null;
+
+ this.setTableMap();
+ if (this.map) {
+
+ // find maximal dimensions of broken table
+ r_max = this.map.length;
+ for (var ridx = 0; ridx < r_max; ridx++) {
+ if (this.map[ridx].length > c_max) { c_max = this.map[ridx].length; }
+ }
+
+ for (var row = 0; row < r_max; row++) {
+ for (var col = 0; col < c_max; col++) {
+ if (this.map[row] && !this.map[row][col]) {
+ if (col > 0) {
+ this.map[row][col] = new MapCell(this.createCells('td', 1));
+ prevcell = this.map[row][col-1];
+ if (prevcell && prevcell.el && prevcell.el.parent) { // if parent does not exist element is removed from dom
+ insertAfter(this.map[row][col-1].el, this.map[row][col].el);
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+
+ rectify: function() {
+ if (!this.removeEmptyTable()) {
+ this.removeSurplusLines();
+ this.fillMissingCells();
+ return true;
+ } else {
+ return false;
+ }
+ },
+
+ unmerge: function() {
+ if (this.rectify()) {
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+
+ if (this.idx) {
+ var thisCell = this.map[this.idx.row][this.idx.col],
+ colspan = (api.getAttribute(thisCell.el, "colspan")) ? parseInt(api.getAttribute(thisCell.el, "colspan"), 10) : 1,
+ cType = thisCell.el.tagName.toLowerCase();
+
+ if (thisCell.isRowspan) {
+ var rowspan = parseInt(api.getAttribute(thisCell.el, "rowspan"), 10);
+ if (rowspan > 1) {
+ for (var nr = 1, maxr = rowspan - 1; nr <= maxr; nr++){
+ this.injectRowAt(this.idx.row + nr, this.idx.col, colspan, cType, thisCell);
+ }
+ }
+ thisCell.el.removeAttribute('rowspan');
+ }
+ this.splitRowToCells(thisCell);
+ }
+ }
+ },
+
+ // merges cells from start cell (defined in creating obj) to "to" cell
+ merge: function(to) {
+ if (this.rectify()) {
+ if (this.canMerge(to)) {
+ var rowspan = this.idx_end.row - this.idx_start.row + 1,
+ colspan = this.idx_end.col - this.idx_start.col + 1;
+
+ for (var row = this.idx_start.row, maxr = this.idx_end.row; row <= maxr; row++) {
+ for (var col = this.idx_start.col, maxc = this.idx_end.col; col <= maxc; col++) {
+
+ if (row == this.idx_start.row && col == this.idx_start.col) {
+ if (rowspan > 1) {
+ this.map[row][col].el.setAttribute('rowspan', rowspan);
+ }
+ if (colspan > 1) {
+ this.map[row][col].el.setAttribute('colspan', colspan);
+ }
+ } else {
+ // transfer content
+ if (!(/^\s*<br\/?>\s*$/.test(this.map[row][col].el.innerHTML.toLowerCase()))) {
+ this.map[this.idx_start.row][this.idx_start.col].el.innerHTML += ' ' + this.map[row][col].el.innerHTML;
+ }
+ removeElement(this.map[row][col].el);
+ }
+ }
+ }
+ this.rectify();
+ } else {
+ if (window.console) {
+ console.log('Do not know how to merge allready merged cells.');
+ }
+ }
+ }
+ },
+
+ // Decreases rowspan of a cell if it is done on first cell of rowspan row (real cell)
+ // Cell is moved to next row (if it is real)
+ collapseCellToNextRow: function(cell) {
+ var cellIdx = this.getMapIndex(cell.el),
+ newRowIdx = cellIdx.row + 1,
+ newIdx = {'row': newRowIdx, 'col': cellIdx.col};
+
+ if (newRowIdx < this.map.length) {
+
+ var row = this.getRealRowEl(false, newIdx);
+ if (row !== null) {
+ var n_cidx = this.correctColIndexForUnreals(newIdx.col, newIdx.row);
+ if (n_cidx >= 0) {
+ insertAfter(this.getRowCells(row)[n_cidx], cell.el);
+ } else {
+ var lastCell = this.getLastNewCellOnRow(row, newRowIdx);
+ if (lastCell !== null) {
+ insertAfter(lastCell, cell.el);
+ } else {
+ row.insertBefore(cell.el, row.firstChild);
+ }
+ }
+ if (parseInt(api.getAttribute(cell.el, 'rowspan'), 10) > 2) {
+ cell.el.setAttribute('rowspan', parseInt(api.getAttribute(cell.el, 'rowspan'), 10) - 1);
+ } else {
+ cell.el.removeAttribute('rowspan');
+ }
+ }
+ }
+ },
+
+ // Removes a cell when removing a row
+ // If is rowspan cell then decreases the rowspan
+ // and moves cell to next row if needed (is first cell of rowspan)
+ removeRowCell: function(cell) {
+ if (cell.isReal) {
+ if (cell.isRowspan) {
+ this.collapseCellToNextRow(cell);
+ } else {
+ removeElement(cell.el);
+ }
+ } else {
+ if (parseInt(api.getAttribute(cell.el, 'rowspan'), 10) > 2) {
+ cell.el.setAttribute('rowspan', parseInt(api.getAttribute(cell.el, 'rowspan'), 10) - 1);
+ } else {
+ cell.el.removeAttribute('rowspan');
+ }
+ }
+ },
+
+ getRowElementsByCell: function() {
+ var cells = [];
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+ if (this.idx !== false) {
+ var modRow = this.map[this.idx.row];
+ for (var cidx = 0, cmax = modRow.length; cidx < cmax; cidx++) {
+ if (modRow[cidx].isReal) {
+ cells.push(modRow[cidx].el);
+ }
+ }
+ }
+ return cells;
+ },
+
+ getColumnElementsByCell: function() {
+ var cells = [];
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+ if (this.idx !== false) {
+ for (var ridx = 0, rmax = this.map.length; ridx < rmax; ridx++) {
+ if (this.map[ridx][this.idx.col] && this.map[ridx][this.idx.col].isReal) {
+ cells.push(this.map[ridx][this.idx.col].el);
+ }
+ }
+ }
+ return cells;
+ },
+
+ // Removes the row of selected cell
+ removeRow: function() {
+ var oldRow = api.getParentElement(this.cell, { nodeName: ["TR"] });
+ if (oldRow) {
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+ if (this.idx !== false) {
+ var modRow = this.map[this.idx.row];
+ for (var cidx = 0, cmax = modRow.length; cidx < cmax; cidx++) {
+ if (!modRow[cidx].modified) {
+ this.setCellAsModified(modRow[cidx]);
+ this.removeRowCell(modRow[cidx]);
+ }
+ }
+ }
+ removeElement(oldRow);
+ }
+ },
+
+ removeColCell: function(cell) {
+ if (cell.isColspan) {
+ if (parseInt(api.getAttribute(cell.el, 'colspan'), 10) > 2) {
+ cell.el.setAttribute('colspan', parseInt(api.getAttribute(cell.el, 'colspan'), 10) - 1);
+ } else {
+ cell.el.removeAttribute('colspan');
+ }
+ } else if (cell.isReal) {
+ removeElement(cell.el);
+ }
+ },
+
+ removeColumn: function() {
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+ if (this.idx !== false) {
+ for (var ridx = 0, rmax = this.map.length; ridx < rmax; ridx++) {
+ if (!this.map[ridx][this.idx.col].modified) {
+ this.setCellAsModified(this.map[ridx][this.idx.col]);
+ this.removeColCell(this.map[ridx][this.idx.col]);
+ }
+ }
+ }
+ },
+
+ // removes row or column by selected cell element
+ remove: function(what) {
+ if (this.rectify()) {
+ switch (what) {
+ case 'row':
+ this.removeRow();
+ break;
+ case 'column':
+ this.removeColumn();
+ break;
+ }
+ this.rectify();
+ }
+ },
+
+ addRow: function(where) {
+ var doc = this.table.ownerDocument;
+
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+ if (where == "below" && api.getAttribute(this.cell, 'rowspan')) {
+ this.idx.row = this.idx.row + parseInt(api.getAttribute(this.cell, 'rowspan'), 10) - 1;
+ }
+
+ if (this.idx !== false) {
+ var modRow = this.map[this.idx.row],
+ newRow = doc.createElement('tr');
+
+ for (var ridx = 0, rmax = modRow.length; ridx < rmax; ridx++) {
+ if (!modRow[ridx].modified) {
+ this.setCellAsModified(modRow[ridx]);
+ this.addRowCell(modRow[ridx], newRow, where);
+ }
+ }
+
+ switch (where) {
+ case 'below':
+ insertAfter(this.getRealRowEl(true), newRow);
+ break;
+ case 'above':
+ var cr = api.getParentElement(this.map[this.idx.row][this.idx.col].el, { nodeName: ["TR"] });
+ if (cr) {
+ cr.parentNode.insertBefore(newRow, cr);
+ }
+ break;
+ }
+ }
+ },
+
+ addRowCell: function(cell, row, where) {
+ var colSpanAttr = (cell.isColspan) ? {"colspan" : api.getAttribute(cell.el, 'colspan')} : null;
+ if (cell.isReal) {
+ if (where != 'above' && cell.isRowspan) {
+ cell.el.setAttribute('rowspan', parseInt(api.getAttribute(cell.el,'rowspan'), 10) + 1);
+ } else {
+ row.appendChild(this.createCells('td', 1, colSpanAttr));
+ }
+ } else {
+ if (where != 'above' && cell.isRowspan && cell.lastRow) {
+ row.appendChild(this.createCells('td', 1, colSpanAttr));
+ } else if (c.isRowspan) {
+ cell.el.attr('rowspan', parseInt(api.getAttribute(cell.el, 'rowspan'), 10) + 1);
+ }
+ }
+ },
+
+ add: function(where) {
+ if (this.rectify()) {
+ if (where == 'below' || where == 'above') {
+ this.addRow(where);
+ }
+ if (where == 'before' || where == 'after') {
+ this.addColumn(where);
+ }
+ }
+ },
+
+ addColCell: function (cell, ridx, where) {
+ var doAdd,
+ cType = cell.el.tagName.toLowerCase();
+
+ // defines add cell vs expand cell conditions
+ // true means add
+ switch (where) {
+ case "before":
+ doAdd = (!cell.isColspan || cell.firstCol);
+ break;
+ case "after":
+ doAdd = (!cell.isColspan || cell.lastCol || (cell.isColspan && c.el == this.cell));
+ break;
+ }
+
+ if (doAdd){
+ // adds a cell before or after current cell element
+ switch (where) {
+ case "before":
+ cell.el.parentNode.insertBefore(this.createCells(cType, 1), cell.el);
+ break;
+ case "after":
+ insertAfter(cell.el, this.createCells(cType, 1));
+ break;
+ }
+
+ // handles if cell has rowspan
+ if (cell.isRowspan) {
+ this.handleCellAddWithRowspan(cell, ridx+1, where);
+ }
+
+ } else {
+ // expands cell
+ cell.el.setAttribute('colspan', parseInt(api.getAttribute(cell.el, 'colspan'), 10) + 1);
+ }
+ },
+
+ addColumn: function(where) {
+ var row, modCell;
+
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+ if (where == "after" && api.getAttribute(this.cell, 'colspan')) {
+ this.idx.col = this.idx.col + parseInt(api.getAttribute(this.cell, 'colspan'), 10) - 1;
+ }
+
+ if (this.idx !== false) {
+ for (var ridx = 0, rmax = this.map.length; ridx < rmax; ridx++ ) {
+ row = this.map[ridx];
+ if (row[this.idx.col]) {
+ modCell = row[this.idx.col];
+ if (!modCell.modified) {
+ this.setCellAsModified(modCell);
+ this.addColCell(modCell, ridx , where);
+ }
+ }
+ }
+ }
+ },
+
+ handleCellAddWithRowspan: function (cell, ridx, where) {
+ var addRowsNr = parseInt(api.getAttribute(this.cell, 'rowspan'), 10) - 1,
+ crow = api.getParentElement(cell.el, { nodeName: ["TR"] }),
+ cType = cell.el.tagName.toLowerCase(),
+ cidx, temp_r_cells,
+ doc = this.table.ownerDocument,
+ nrow;
+
+ for (var i = 0; i < addRowsNr; i++) {
+ cidx = this.correctColIndexForUnreals(this.idx.col, (ridx + i));
+ crow = nextNode(crow, 'tr');
+ if (crow) {
+ if (cidx > 0) {
+ switch (where) {
+ case "before":
+ temp_r_cells = this.getRowCells(crow);
+ if (cidx > 0 && this.map[ridx + i][this.idx.col].el != temp_r_cells[cidx] && cidx == temp_r_cells.length - 1) {
+ insertAfter(temp_r_cells[cidx], this.createCells(cType, 1));
+ } else {
+ temp_r_cells[cidx].parentNode.insertBefore(this.createCells(cType, 1), temp_r_cells[cidx]);
+ }
+
+ break;
+ case "after":
+ insertAfter(this.getRowCells(crow)[cidx], this.createCells(cType, 1));
+ break;
+ }
+ } else {
+ crow.insertBefore(this.createCells(cType, 1), crow.firstChild);
+ }
+ } else {
+ nrow = doc.createElement('tr');
+ nrow.appendChild(this.createCells(cType, 1));
+ this.table.appendChild(nrow);
+ }
+ }
+ }
+ };
+
+ api.table = {
+ getCellsBetween: function(cell1, cell2) {
+ var c1 = new TableModifyerByCell(cell1);
+ return c1.getMapElsTo(cell2);
+ },
+
+ addCells: function(cell, where) {
+ var c = new TableModifyerByCell(cell);
+ c.add(where);
+ },
+
+ removeCells: function(cell, what) {
+ var c = new TableModifyerByCell(cell);
+ c.remove(what);
+ },
+
+ mergeCellsBetween: function(cell1, cell2) {
+ var c1 = new TableModifyerByCell(cell1);
+ c1.merge(cell2);
+ },
+
+ unmergeCell: function(cell) {
+ var c = new TableModifyerByCell(cell);
+ c.unmerge();
+ },
+
+ orderSelectionEnds: function(cell, cell2) {
+ var c = new TableModifyerByCell(cell);
+ return c.orderSelectionEnds(cell2);
+ },
+
+ indexOf: function(cell) {
+ var c = new TableModifyerByCell(cell);
+ c.setTableMap();
+ return c.getMapIndex(cell);
+ },
+
+ findCell: function(table, idx) {
+ var c = new TableModifyerByCell(null, table);
+ return c.getElementAtIndex(idx);
+ },
+
+ findRowByCell: function(cell) {
+ var c = new TableModifyerByCell(cell);
+ return c.getRowElementsByCell();
+ },
+
+ findColumnByCell: function(cell) {
+ var c = new TableModifyerByCell(cell);
+ return c.getColumnElementsByCell();
+ },
+
+ canMerge: function(cell1, cell2) {
+ var c = new TableModifyerByCell(cell1);
+ return c.canMerge(cell2);
+ }
+ };
+
+
+
+})(wysihtml5);
+;// does a selector query on element or array of elements
+
+wysihtml5.dom.query = function(elements, query) {
+ var ret = [],
+ q;
+
+ if (elements.nodeType) {
+ elements = [elements];
+ }
+
+ for (var e = 0, len = elements.length; e < len; e++) {
+ q = elements[e].querySelectorAll(query);
+ if (q) {
+ for(var i = q.length; i--; ret.unshift(q[i]));
+ }
+ }
+ return ret;
+};
+;wysihtml5.dom.compareDocumentPosition = (function() {
+ var documentElement = document.documentElement;
+ if (documentElement.compareDocumentPosition) {
+ return function(container, element) {
+ return container.compareDocumentPosition(element);
+ };
+ } else {
+ return function( container, element ) {
+ // implementation borrowed from https://github.com/tmpvar/jsdom/blob/681a8524b663281a0f58348c6129c8c184efc62c/lib/jsdom/level3/core.js // MIT license
+ var thisOwner, otherOwner;
+
+ if( container.nodeType === 9) // Node.DOCUMENT_NODE
+ thisOwner = container;
+ else
+ thisOwner = container.ownerDocument;
+
+ if( element.nodeType === 9) // Node.DOCUMENT_NODE
+ otherOwner = element;
+ else
+ otherOwner = element.ownerDocument;
+
+ if( container === element ) return 0;
+ if( container === element.ownerDocument ) return 4 + 16; //Node.DOCUMENT_POSITION_FOLLOWING + Node.DOCUMENT_POSITION_CONTAINED_BY;
+ if( container.ownerDocument === element ) return 2 + 8; //Node.DOCUMENT_POSITION_PRECEDING + Node.DOCUMENT_POSITION_CONTAINS;
+ if( thisOwner !== otherOwner ) return 1; // Node.DOCUMENT_POSITION_DISCONNECTED;
+
+ // Text nodes for attributes does not have a _parentNode. So we need to find them as attribute child.
+ if( container.nodeType === 2 /*Node.ATTRIBUTE_NODE*/ && container.childNodes && wysihtml5.lang.array(container.childNodes).indexOf( element ) !== -1)
+ return 4 + 16; //Node.DOCUMENT_POSITION_FOLLOWING + Node.DOCUMENT_POSITION_CONTAINED_BY;
+
+ if( element.nodeType === 2 /*Node.ATTRIBUTE_NODE*/ && element.childNodes && wysihtml5.lang.array(element.childNodes).indexOf( container ) !== -1)
+ return 2 + 8; //Node.DOCUMENT_POSITION_PRECEDING + Node.DOCUMENT_POSITION_CONTAINS;
+
+ var point = container;
+ var parents = [ ];
+ var previous = null;
+ while( point ) {
+ if( point == element ) return 2 + 8; //Node.DOCUMENT_POSITION_PRECEDING + Node.DOCUMENT_POSITION_CONTAINS;
+ parents.push( point );
+ point = point.parentNode;
+ }
+ point = element;
+ previous = null;
+ while( point ) {
+ if( point == container ) return 4 + 16; //Node.DOCUMENT_POSITION_FOLLOWING + Node.DOCUMENT_POSITION_CONTAINED_BY;
+ var location_index = wysihtml5.lang.array(parents).indexOf( point );
+ if( location_index !== -1) {
+ var smallest_common_ancestor = parents[ location_index ];
+ var this_index = wysihtml5.lang.array(smallest_common_ancestor.childNodes).indexOf( parents[location_index - 1]);//smallest_common_ancestor.childNodes.toArray().indexOf( parents[location_index - 1] );
+ var other_index = wysihtml5.lang.array(smallest_common_ancestor.childNodes).indexOf( previous ); //smallest_common_ancestor.childNodes.toArray().indexOf( previous );
+ if( this_index > other_index ) {
+ return 2; //Node.DOCUMENT_POSITION_PRECEDING;
+ }
+ else {
+ return 4; //Node.DOCUMENT_POSITION_FOLLOWING;
+ }
+ }
+ previous = point;
+ point = point.parentNode;
+ }
+ return 1; //Node.DOCUMENT_POSITION_DISCONNECTED;
+ };
+ }
+})();
+;wysihtml5.dom.unwrap = function(node) {
+ if (node.parentNode) {
+ while (node.lastChild) {
+ wysihtml5.dom.insert(node.lastChild).after(node);
+ }
+ node.parentNode.removeChild(node);
+ }
+};;/*
+ * Methods for fetching pasted html before it gets inserted into content
+**/
+
+/* Modern event.clipboardData driven approach.
+ * Advantage is that it does not have to loose selection or modify dom to catch the data.
+ * IE does not support though.
+**/
+wysihtml5.dom.getPastedHtml = function(event) {
+ var html;
+ if (event.clipboardData) {
+ if (wysihtml5.lang.array(event.clipboardData.types).contains('text/html')) {
+ html = event.clipboardData.getData('text/html');
+ } else if (wysihtml5.lang.array(event.clipboardData.types).contains('text/plain')) {
+ html = wysihtml5.lang.string(event.clipboardData.getData('text/plain')).escapeHTML(true, true);
+ }
+ }
+ return html;
+};
+
+/* Older temprorary contenteditable as paste source catcher method for fallbacks */
+wysihtml5.dom.getPastedHtmlWithDiv = function (composer, f) {
+ var selBookmark = composer.selection.getBookmark(),
+ doc = composer.element.ownerDocument,
+ cleanerDiv = doc.createElement('DIV');
+
+ doc.body.appendChild(cleanerDiv);
+
+ cleanerDiv.style.width = "1px";
+ cleanerDiv.style.height = "1px";
+ cleanerDiv.style.overflow = "hidden";
+
+ cleanerDiv.setAttribute('contenteditable', 'true');
+ cleanerDiv.focus();
+
+ setTimeout(function () {
+ composer.selection.setBookmark(selBookmark);
+ f(cleanerDiv.innerHTML);
+ cleanerDiv.parentNode.removeChild(cleanerDiv);
+ }, 0);
+};;/**
+ * Fix most common html formatting misbehaviors of browsers implementation when inserting
+ * content via copy & paste contentEditable
+ *
+ * @author Christopher Blum
+ */
+wysihtml5.quirks.cleanPastedHTML = (function() {
+
+ var styleToRegex = function (styleStr) {
+ var trimmedStr = wysihtml5.lang.string(styleStr).trim(),
+ escapedStr = trimmedStr.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
+
+ return new RegExp("^((?!^" + escapedStr + "$).)*$", "i");
+ };
+
+ var extendRulesWithStyleExceptions = function (rules, exceptStyles) {
+ var newRules = wysihtml5.lang.object(rules).clone(true),
+ tag, style;
+
+ for (tag in newRules.tags) {
+
+ if (newRules.tags.hasOwnProperty(tag)) {
+ if (newRules.tags[tag].keep_styles) {
+ for (style in newRules.tags[tag].keep_styles) {
+ if (newRules.tags[tag].keep_styles.hasOwnProperty(style)) {
+ if (exceptStyles[style]) {
+ newRules.tags[tag].keep_styles[style] = styleToRegex(exceptStyles[style]);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return newRules;
+ };
+
+ var pickRuleset = function(ruleset, html) {
+ var pickedSet, defaultSet;
+
+ if (!ruleset) {
+ return null;
+ }
+
+ for (var i = 0, max = ruleset.length; i < max; i++) {
+ if (!ruleset[i].condition) {
+ defaultSet = ruleset[i].set;
+ }
+ if (ruleset[i].condition && ruleset[i].condition.test(html)) {
+ return ruleset[i].set;
+ }
+ }
+
+ return defaultSet;
+ };
+
+ return function(html, options) {
+ var exceptStyles = {
+ 'color': wysihtml5.dom.getStyle("color").from(options.referenceNode),
+ 'fontSize': wysihtml5.dom.getStyle("font-size").from(options.referenceNode)
+ },
+ rules = extendRulesWithStyleExceptions(pickRuleset(options.rules, html) || {}, exceptStyles),
+ newHtml;
+
+ newHtml = wysihtml5.dom.parse(html, {
+ "rules": rules,
+ "cleanUp": true, // <span> elements, empty or without attributes, should be removed/replaced with their content
+ "context": options.referenceNode.ownerDocument,
+ "uneditableClass": options.uneditableClass,
+ "clearInternals" : true, // don't paste temprorary selection and other markings
+ "unjoinNbsps" : true
+ });
+
+ return newHtml;
+ };
+
+})();;/**
+ * IE and Opera leave an empty paragraph in the contentEditable element after clearing it
+ *
+ * @param {Object} contentEditableElement The contentEditable element to observe for clearing events
+ * @exaple
+ * wysihtml5.quirks.ensureProperClearing(myContentEditableElement);
+ */
+wysihtml5.quirks.ensureProperClearing = (function() {
+ var clearIfNecessary = function() {
+ var element = this;
+ setTimeout(function() {
+ var innerHTML = element.innerHTML.toLowerCase();
+ if (innerHTML == "<p> </p>" ||
+ innerHTML == "<p> </p><p> </p>") {
+ element.innerHTML = "";
+ }
+ }, 0);
+ };
+
+ return function(composer) {
+ wysihtml5.dom.observe(composer.element, ["cut", "keydown"], clearIfNecessary);
+ };
+})();
+;// See https://bugzilla.mozilla.org/show_bug.cgi?id=664398
+//
+// In Firefox this:
+// var d = document.createElement("div");
+// d.innerHTML ='<a href="~"></a>';
+// d.innerHTML;
+// will result in:
+// <a href="%7E"></a>
+// which is wrong
+(function(wysihtml5) {
+ var TILDE_ESCAPED = "%7E";
+ wysihtml5.quirks.getCorrectInnerHTML = function(element) {
+ var innerHTML = element.innerHTML;
+ if (innerHTML.indexOf(TILDE_ESCAPED) === -1) {
+ return innerHTML;
+ }
+
+ var elementsWithTilde = element.querySelectorAll("[href*='~'], [src*='~']"),
+ url,
+ urlToSearch,
+ length,
+ i;
+ for (i=0, length=elementsWithTilde.length; i<length; i++) {
+ url = elementsWithTilde[i].href || elementsWithTilde[i].src;
+ urlToSearch = wysihtml5.lang.string(url).replace("~").by(TILDE_ESCAPED);
+ innerHTML = wysihtml5.lang.string(innerHTML).replace(urlToSearch).by(url);
+ }
+ return innerHTML;
+ };
+})(wysihtml5);
+;/**
+ * Force rerendering of a given element
+ * Needed to fix display misbehaviors of IE
+ *
+ * @param {Element} element The element object which needs to be rerendered
+ * @example
+ * wysihtml5.quirks.redraw(document.body);
+ */
+(function(wysihtml5) {
+ var CLASS_NAME = "wysihtml5-quirks-redraw";
+
+ wysihtml5.quirks.redraw = function(element) {
+ wysihtml5.dom.addClass(element, CLASS_NAME);
+ wysihtml5.dom.removeClass(element, CLASS_NAME);
+
+ // Following hack is needed for firefox to make sure that image resize handles are properly removed
+ try {
+ var doc = element.ownerDocument;
+ doc.execCommand("italic", false, null);
+ doc.execCommand("italic", false, null);
+ } catch(e) {}
+ };
+})(wysihtml5);
+;wysihtml5.quirks.tableCellsSelection = function(editable, editor) {
+
+ var dom = wysihtml5.dom,
+ select = {
+ table: null,
+ start: null,
+ end: null,
+ cells: null,
+ select: selectCells
+ },
+ selection_class = "wysiwyg-tmp-selected-cell",
+ moveHandler = null,
+ upHandler = null;
+
+ function init () {
+
+ dom.observe(editable, "mousedown", function(event) {
+ var target = wysihtml5.dom.getParentElement(event.target, { nodeName: ["TD", "TH"] });
+ if (target) {
+ handleSelectionMousedown(target);
+ }
+ });
+
+ return select;
+ }
+
+ function handleSelectionMousedown (target) {
+ select.start = target;
+ select.end = target;
+ select.cells = [target];
+ select.table = dom.getParentElement(select.start, { nodeName: ["TABLE"] });
+
+ if (select.table) {
+ removeCellSelections();
+ dom.addClass(target, selection_class);
+ moveHandler = dom.observe(editable, "mousemove", handleMouseMove);
+ upHandler = dom.observe(editable, "mouseup", handleMouseUp);
+ editor.fire("tableselectstart").fire("tableselectstart:composer");
+ }
+ }
+
+ // remove all selection classes
+ function removeCellSelections () {
+ if (editable) {
+ var selectedCells = editable.querySelectorAll('.' + selection_class);
+ if (selectedCells.length > 0) {
+ for (var i = 0; i < selectedCells.length; i++) {
+ dom.removeClass(selectedCells[i], selection_class);
+ }
+ }
+ }
+ }
+
+ function addSelections (cells) {
+ for (var i = 0; i < cells.length; i++) {
+ dom.addClass(cells[i], selection_class);
+ }
+ }
+
+ function handleMouseMove (event) {
+ var curTable = null,
+ cell = dom.getParentElement(event.target, { nodeName: ["TD","TH"] }),
+ oldEnd;
+
+ if (cell && select.table && select.start) {
+ curTable = dom.getParentElement(cell, { nodeName: ["TABLE"] });
+ if (curTable && curTable === select.table) {
+ removeCellSelections();
+ oldEnd = select.end;
+ select.end = cell;
+ select.cells = dom.table.getCellsBetween(select.start, cell);
+ if (select.cells.length > 1) {
+ editor.composer.selection.deselect();
+ }
+ addSelections(select.cells);
+ if (select.end !== oldEnd) {
+ editor.fire("tableselectchange").fire("tableselectchange:composer");
+ }
+ }
+ }
+ }
+
+ function handleMouseUp (event) {
+ moveHandler.stop();
+ upHandler.stop();
+ editor.fire("tableselect").fire("tableselect:composer");
+ setTimeout(function() {
+ bindSideclick();
+ },0);
+ }
+
+ function bindSideclick () {
+ var sideClickHandler = dom.observe(editable.ownerDocument, "click", function(event) {
+ sideClickHandler.stop();
+ if (dom.getParentElement(event.target, { nodeName: ["TABLE"] }) != select.table) {
+ removeCellSelections();
+ select.table = null;
+ select.start = null;
+ select.end = null;
+ editor.fire("tableunselect").fire("tableunselect:composer");
+ }
+ });
+ }
+
+ function selectCells (start, end) {
+ select.start = start;
+ select.end = end;
+ select.table = dom.getParentElement(select.start, { nodeName: ["TABLE"] });
+ selectedCells = dom.table.getCellsBetween(select.start, select.end);
+ addSelections(selectedCells);
+ bindSideclick();
+ editor.fire("tableselect").fire("tableselect:composer");
+ }
+
+ return init();
+
+};
+;(function(wysihtml5) {
+ var RGBA_REGEX = /^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*([\d\.]+)\s*\)/i,
+ RGB_REGEX = /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/i,
+ HEX6_REGEX = /^#([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])/i,
+ HEX3_REGEX = /^#([0-9a-f])([0-9a-f])([0-9a-f])/i;
+
+ var param_REGX = function (p) {
+ return new RegExp("(^|\\s|;)" + p + "\\s*:\\s*[^;$]+" , "gi");
+ };
+
+ wysihtml5.quirks.styleParser = {
+
+ parseColor: function(stylesStr, paramName) {
+ var paramRegex = param_REGX(paramName),
+ params = stylesStr.match(paramRegex),
+ radix = 10,
+ str, colorMatch;
+
+ if (params) {
+ for (var i = params.length; i--;) {
+ params[i] = wysihtml5.lang.string(params[i].split(':')[1]).trim();
+ }
+ str = params[params.length-1];
+
+ if (RGBA_REGEX.test(str)) {
+ colorMatch = str.match(RGBA_REGEX);
+ } else if (RGB_REGEX.test(str)) {
+ colorMatch = str.match(RGB_REGEX);
+ } else if (HEX6_REGEX.test(str)) {
+ colorMatch = str.match(HEX6_REGEX);
+ radix = 16;
+ } else if (HEX3_REGEX.test(str)) {
+ colorMatch = str.match(HEX3_REGEX);
+ colorMatch.shift();
+ colorMatch.push(1);
+ return wysihtml5.lang.array(colorMatch).map(function(d, idx) {
+ return (idx < 3) ? (parseInt(d, 16) * 16) + parseInt(d, 16): parseFloat(d);
+ });
+ }
+
+ if (colorMatch) {
+ colorMatch.shift();
+ if (!colorMatch[3]) {
+ colorMatch.push(1);
+ }
+ return wysihtml5.lang.array(colorMatch).map(function(d, idx) {
+ return (idx < 3) ? parseInt(d, radix): parseFloat(d);
+ });
+ }
+ }
+ return false;
+ },
+
+ unparseColor: function(val, props) {
+ if (props) {
+ if (props == "hex") {
+ return (val[0].toString(16).toUpperCase()) + (val[1].toString(16).toUpperCase()) + (val[2].toString(16).toUpperCase());
+ } else if (props == "hash") {
+ return "#" + (val[0].toString(16).toUpperCase()) + (val[1].toString(16).toUpperCase()) + (val[2].toString(16).toUpperCase());
+ } else if (props == "rgb") {
+ return "rgb(" + val[0] + "," + val[1] + "," + val[2] + ")";
+ } else if (props == "rgba") {
+ return "rgba(" + val[0] + "," + val[1] + "," + val[2] + "," + val[3] + ")";
+ } else if (props == "csv") {
+ return val[0] + "," + val[1] + "," + val[2] + "," + val[3];
+ }
+ }
+
+ if (val[3] && val[3] !== 1) {
+ return "rgba(" + val[0] + "," + val[1] + "," + val[2] + "," + val[3] + ")";
+ } else {
+ return "rgb(" + val[0] + "," + val[1] + "," + val[2] + ")";
+ }
+ },
+
+ parseFontSize: function(stylesStr) {
+ var params = stylesStr.match(param_REGX('font-size'));
+ if (params) {
+ return wysihtml5.lang.string(params[params.length - 1].split(':')[1]).trim();
+ }
+ return false;
+ }
+ };
+
+})(wysihtml5);
+;/**
+ * Selection API
+ *
+ * @example
+ * var selection = new wysihtml5.Selection(editor);
+ */
+(function(wysihtml5) {
+ var dom = wysihtml5.dom;
+
+ function _getCumulativeOffsetTop(element) {
+ var top = 0;
+ if (element.parentNode) {
+ do {
+ top += element.offsetTop || 0;
+ element = element.offsetParent;
+ } while (element);
+ }
+ return top;
+ }
+
+ // Provides the depth of ``descendant`` relative to ``ancestor``
+ function getDepth(ancestor, descendant) {
+ var ret = 0;
+ while (descendant !== ancestor) {
+ ret++;
+ descendant = descendant.parentNode;
+ if (!descendant)
+ throw new Error("not a descendant of ancestor!");
+ }
+ return ret;
+ }
+
+ // Should fix the obtained ranges that cannot surrond contents normally to apply changes upon
+ // Being considerate to firefox that sets range start start out of span and end inside on doubleclick initiated selection
+ function expandRangeToSurround(range) {
+ if (range.canSurroundContents()) return;
+
+ var common = range.commonAncestorContainer,
+ start_depth = getDepth(common, range.startContainer),
+ end_depth = getDepth(common, range.endContainer);
+
+ while(!range.canSurroundContents()) {
+ // In the following branches, we cannot just decrement the depth variables because the setStartBefore/setEndAfter may move the start or end of the range more than one level relative to ``common``. So we need to recompute the depth.
+ if (start_depth > end_depth) {
+ range.setStartBefore(range.startContainer);
+ start_depth = getDepth(common, range.startContainer);
+ }
+ else {
+ range.setEndAfter(range.endContainer);
+ end_depth = getDepth(common, range.endContainer);
+ }
+ }
+ }
+
+ wysihtml5.Selection = Base.extend(
+ /** @scope wysihtml5.Selection.prototype */ {
+ constructor: function(editor, contain, unselectableClass) {
+ // Make sure that our external range library is initialized
+ window.rangy.init();
+
+ this.editor = editor;
+ this.composer = editor.composer;
+ this.doc = this.composer.doc;
+ this.contain = contain;
+ this.unselectableClass = unselectableClass || false;
+ },
+
+ /**
+ * Get the current selection as a bookmark to be able to later restore it
+ *
+ * @return {Object} An object that represents the current selection
+ */
+ getBookmark: function() {
+ var range = this.getRange();
+ if (range) expandRangeToSurround(range);
+ return range && range.cloneRange();
+ },
+
+ /**
+ * Restore a selection retrieved via wysihtml5.Selection.prototype.getBookmark
+ *
+ * @param {Object} bookmark An object that represents the current selection
+ */
+ setBookmark: function(bookmark) {
+ if (!bookmark) {
+ return;
+ }
+
+ this.setSelection(bookmark);
+ },
+
+ /**
+ * Set the caret in front of the given node
+ *
+ * @param {Object} node The element or text node where to position the caret in front of
+ * @example
+ * selection.setBefore(myElement);
+ */
+ setBefore: function(node) {
+ var range = rangy.createRange(this.doc);
+ range.setStartBefore(node);
+ range.setEndBefore(node);
+ return this.setSelection(range);
+ },
+
+ // Constructs a self removing whitespace (ain absolute positioned span) for placing selection caret when normal methods fail.
+ // Webkit has an issue with placing caret into places where there are no textnodes near by.
+ creteTemporaryCaretSpaceAfter: function (node) {
+ var caretPlaceholder = this.doc.createElement('span'),
+ caretPlaceholderText = this.doc.createTextNode(wysihtml5.INVISIBLE_SPACE),
+ placeholderRemover = (function(event) {
+ // Self-destructs the caret and keeps the text inserted into it by user
+ var lastChild;
+
+ this.contain.removeEventListener('mouseup', placeholderRemover);
+ this.contain.removeEventListener('keydown', keyDownHandler);
+ this.contain.removeEventListener('touchstart', placeholderRemover);
+ this.contain.removeEventListener('focus', placeholderRemover);
+ this.contain.removeEventListener('blur', placeholderRemover);
+ this.contain.removeEventListener('paste', delayedPlaceholderRemover);
+ this.contain.removeEventListener('drop', delayedPlaceholderRemover);
+ this.contain.removeEventListener('beforepaste', delayedPlaceholderRemover);
+
+ // If user inserted sth it is in the placeholder and sgould be unwrapped and stripped of invisible whitespace hack
+ // Otherwise the wrapper can just be removed
+ if (caretPlaceholder && caretPlaceholder.parentNode) {
+ caretPlaceholder.innerHTML = caretPlaceholder.innerHTML.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "");
+ if ((/[^\s]+/).test(caretPlaceholder.innerHTML)) {
+ lastChild = caretPlaceholder.lastChild;
+ wysihtml5.dom.unwrap(caretPlaceholder);
+ this.setAfter(lastChild);
+ } else {
+ caretPlaceholder.parentNode.removeChild(caretPlaceholder);
+ }
+
+ }
+ }).bind(this),
+ delayedPlaceholderRemover = function (event) {
+ if (caretPlaceholder && caretPlaceholder.parentNode) {
+ setTimeout(placeholderRemover, 0);
+ }
+ },
+ keyDownHandler = function(event) {
+ if (event.which !== 8 && event.which !== 91 && event.which !== 17 && (event.which !== 86 || (!event.ctrlKey && !event.metaKey))) {
+ placeholderRemover();
+ }
+ };
+
+ caretPlaceholder.style.position = 'absolute';
+ caretPlaceholder.style.display = 'block';
+ caretPlaceholder.style.minWidth = '1px';
+ caretPlaceholder.style.zIndex = '99999';
+ caretPlaceholder.appendChild(caretPlaceholderText);
+
+ node.parentNode.insertBefore(caretPlaceholder, node.nextSibling);
+ this.setBefore(caretPlaceholderText);
+
+ // Remove the caret fix on any of the following events (some are delayed as content change happens after event)
+ this.contain.addEventListener('mouseup', placeholderRemover);
+ this.contain.addEventListener('keydown', keyDownHandler);
+ this.contain.addEventListener('touchstart', placeholderRemover);
+ this.contain.addEventListener('focus', placeholderRemover);
+ this.contain.addEventListener('blur', placeholderRemover);
+ this.contain.addEventListener('paste', delayedPlaceholderRemover);
+ this.contain.addEventListener('drop', delayedPlaceholderRemover);
+ this.contain.addEventListener('beforepaste', delayedPlaceholderRemover);
+
+ return caretPlaceholder;
+ },
+
+ /**
+ * Set the caret after the given node
+ *
+ * @param {Object} node The element or text node where to position the caret in front of
+ * @example
+ * selection.setBefore(myElement);
+ */
+ setAfter: function(node) {
+ var range = rangy.createRange(this.doc),
+ originalScrollTop = this.doc.documentElement.scrollTop || this.doc.body.scrollTop || this.doc.defaultView.pageYOffset,
+ originalScrollLeft = this.doc.documentElement.scrollLeft || this.doc.body.scrollLeft || this.doc.defaultView.pageXOffset,
+ sel;
+
+ range.setStartAfter(node);
+ range.setEndAfter(node);
+ this.composer.element.focus();
+ this.doc.defaultView.scrollTo(originalScrollLeft, originalScrollTop);
+ sel = this.setSelection(range);
+
+ // Webkit fails to add selection if there are no textnodes in that region
+ // (like an uneditable container at the end of content).
+ if (!sel) {
+ this.creteTemporaryCaretSpaceAfter(node);
+ }
+ return sel;
+ },
+
+ /**
+ * Ability to select/mark nodes
+ *
+ * @param {Element} node The node/element to select
+ * @example
+ * selection.selectNode(document.getElementById("my-image"));
+ */
+ selectNode: function(node, avoidInvisibleSpace) {
+ var range = rangy.createRange(this.doc),
+ isElement = node.nodeType === wysihtml5.ELEMENT_NODE,
+ canHaveHTML = "canHaveHTML" in node ? node.canHaveHTML : (node.nodeName !== "IMG"),
+ content = isElement ? node.innerHTML : node.data,
+ isEmpty = (content === "" || content === wysihtml5.INVISIBLE_SPACE),
+ displayStyle = dom.getStyle("display").from(node),
+ isBlockElement = (displayStyle === "block" || displayStyle === "list-item");
+
+ if (isEmpty && isElement && canHaveHTML && !avoidInvisibleSpace) {
+ // Make sure that caret is visible in node by inserting a zero width no breaking space
+ try { node.innerHTML = wysihtml5.INVISIBLE_SPACE; } catch(e) {}
+ }
+
+ if (canHaveHTML) {
+ range.selectNodeContents(node);
+ } else {
+ range.selectNode(node);
+ }
+
+ if (canHaveHTML && isEmpty && isElement) {
+ range.collapse(isBlockElement);
+ } else if (canHaveHTML && isEmpty) {
+ range.setStartAfter(node);
+ range.setEndAfter(node);
+ }
+
+ this.setSelection(range);
+ },
+
+ /**
+ * Get the node which contains the selection
+ *
+ * @param {Boolean} [controlRange] (only IE) Whether it should return the selected ControlRange element when the selection type is a "ControlRange"
+ * @return {Object} The node that contains the caret
+ * @example
+ * var nodeThatContainsCaret = selection.getSelectedNode();
+ */
+ getSelectedNode: function(controlRange) {
+ var selection,
+ range;
+
+ if (controlRange && this.doc.selection && this.doc.selection.type === "Control") {
+ range = this.doc.selection.createRange();
+ if (range && range.length) {
+ return range.item(0);
+ }
+ }
+
+ selection = this.getSelection(this.doc);
+ if (selection.focusNode === selection.anchorNode) {
+ return selection.focusNode;
+ } else {
+ range = this.getRange(this.doc);
+ return range ? range.commonAncestorContainer : this.doc.body;
+ }
+ },
+
+ fixSelBorders: function() {
+ var range = this.getRange();
+ expandRangeToSurround(range);
+ this.setSelection(range);
+ },
+
+ getSelectedOwnNodes: function(controlRange) {
+ var selection,
+ ranges = this.getOwnRanges(),
+ ownNodes = [];
+
+ for (var i = 0, maxi = ranges.length; i < maxi; i++) {
+ ownNodes.push(ranges[i].commonAncestorContainer || this.doc.body);
+ }
+ return ownNodes;
+ },
+
+ findNodesInSelection: function(nodeTypes) {
+ var ranges = this.getOwnRanges(),
+ nodes = [], curNodes;
+ for (var i = 0, maxi = ranges.length; i < maxi; i++) {
+ curNodes = ranges[i].getNodes([1], function(node) {
+ return wysihtml5.lang.array(nodeTypes).contains(node.nodeName);
+ });
+ nodes = nodes.concat(curNodes);
+ }
+ return nodes;
+ },
+
+ containsUneditable: function() {
+ var uneditables = this.getOwnUneditables(),
+ selection = this.getSelection();
+
+ for (var i = 0, maxi = uneditables.length; i < maxi; i++) {
+ if (selection.containsNode(uneditables[i])) {
+ return true;
+ }
+ }
+
+ return false;
+ },
+
+ // Deletes selection contents making sure uneditables/unselectables are not partially deleted
+ // Triggers wysihtml5:uneditable:delete custom event on all deleted uneditables if customevents suppoorted
+ deleteContents: function() {
+ var range = this.getRange(),
+ startParent, endParent, uneditables, ev;
+
+ if (this.unselectableClass) {
+ if ((startParent = wysihtml5.dom.getParentElement(range.startContainer, { className: this.unselectableClass }, false, this.contain))) {
+ range.setStartBefore(startParent);
+ }
+ if ((endParent = wysihtml5.dom.getParentElement(range.endContainer, { className: this.unselectableClass }, false, this.contain))) {
+ range.setEndAfter(endParent);
+ }
+
+ // If customevents present notify uneditable elements of being deleted
+ uneditables = range.getNodes([1], (function (node) {
+ return wysihtml5.dom.hasClass(node, this.unselectableClass);
+ }).bind(this));
+ for (var i = uneditables.length; i--;) {
+ try {
+ ev = new CustomEvent("wysihtml5:uneditable:delete");
+ uneditables[i].dispatchEvent(ev);
+ } catch (err) {}
+ }
+
+ }
+ range.deleteContents();
+ this.setSelection(range);
+ },
+
+ getPreviousNode: function(node, ignoreEmpty) {
+ var displayStyle;
+ if (!node) {
+ var selection = this.getSelection();
+ node = selection.anchorNode;
+ }
+
+ if (node === this.contain) {
+ return false;
+ }
+
+ var ret = node.previousSibling,
+ parent;
+
+ if (ret === this.contain) {
+ return false;
+ }
+
+ if (ret && ret.nodeType !== 3 && ret.nodeType !== 1) {
+ // do not count comments and other node types
+ ret = this.getPreviousNode(ret, ignoreEmpty);
+ } else if (ret && ret.nodeType === 3 && (/^\s*$/).test(ret.textContent)) {
+ // do not count empty textnodes as previous nodes
+ ret = this.getPreviousNode(ret, ignoreEmpty);
+ } else if (ignoreEmpty && ret && ret.nodeType === 1) {
+ // Do not count empty nodes if param set.
+ // Contenteditable tends to bypass and delete these silently when deleting with caret when element is inline-like
+ displayStyle = wysihtml5.dom.getStyle("display").from(ret);
+ if (
+ !wysihtml5.lang.array(["BR", "HR", "IMG"]).contains(ret.nodeName) &&
+ !wysihtml5.lang.array(["block", "inline-block", "flex", "list-item", "table"]).contains(displayStyle) &&
+ (/^[\s]*$/).test(ret.innerHTML)
+ ) {
+ ret = this.getPreviousNode(ret, ignoreEmpty);
+ }
+ } else if (!ret && node !== this.contain) {
+ parent = node.parentNode;
+ if (parent !== this.contain) {
+ ret = this.getPreviousNode(parent, ignoreEmpty);
+ }
+ }
+
+ return (ret !== this.contain) ? ret : false;
+ },
+
+ getSelectionParentsByTag: function(tagName) {
+ var nodes = this.getSelectedOwnNodes(),
+ curEl, parents = [];
+
+ for (var i = 0, maxi = nodes.length; i < maxi; i++) {
+ curEl = (nodes[i].nodeName && nodes[i].nodeName === 'LI') ? nodes[i] : wysihtml5.dom.getParentElement(nodes[i], { nodeName: ['LI']}, false, this.contain);
+ if (curEl) {
+ parents.push(curEl);
+ }
+ }
+ return (parents.length) ? parents : null;
+ },
+
+ getRangeToNodeEnd: function() {
+ if (this.isCollapsed()) {
+ var range = this.getRange(),
+ sNode = range.startContainer,
+ pos = range.startOffset,
+ lastR = rangy.createRange(this.doc);
+
+ lastR.selectNodeContents(sNode);
+ lastR.setStart(sNode, pos);
+ return lastR;
+ }
+ },
+
+ caretIsLastInSelection: function() {
+ var r = rangy.createRange(this.doc),
+ s = this.getSelection(),
+ endc = this.getRangeToNodeEnd().cloneContents(),
+ endtxt = endc.textContent;
+
+ return (/^\s*$/).test(endtxt);
+ },
+
+ caretIsFirstInSelection: function() {
+ var r = rangy.createRange(this.doc),
+ s = this.getSelection(),
+ range = this.getRange(),
+ startNode = range.startContainer;
+
+ if (startNode) {
+ if (startNode.nodeType === wysihtml5.TEXT_NODE) {
+ return this.isCollapsed() && (startNode.nodeType === wysihtml5.TEXT_NODE && (/^\s*$/).test(startNode.data.substr(0,range.startOffset)));
+ } else {
+ r.selectNodeContents(this.getRange().commonAncestorContainer);
+ r.collapse(true);
+ return (this.isCollapsed() && (r.startContainer === s.anchorNode || r.endContainer === s.anchorNode) && r.startOffset === s.anchorOffset);
+ }
+ }
+ },
+
+ caretIsInTheBeginnig: function(ofNode) {
+ var selection = this.getSelection(),
+ node = selection.anchorNode,
+ offset = selection.anchorOffset;
+ if (ofNode && node) {
+ return (offset === 0 && (node.nodeName && node.nodeName === ofNode.toUpperCase() || wysihtml5.dom.getParentElement(node.parentNode, { nodeName: ofNode }, 1)));
+ } else if (node) {
+ return (offset === 0 && !this.getPreviousNode(node, true));
+ }
+ },
+
+ caretIsBeforeUneditable: function() {
+ var selection = this.getSelection(),
+ node = selection.anchorNode,
+ offset = selection.anchorOffset,
+ childNodes = [],
+ range, contentNodes, lastNode;
+
+ if (node) {
+ if (offset === 0) {
+ var prevNode = this.getPreviousNode(node, true),
+ prevLeaf = prevNode ? wysihtml5.dom.domNode(prevNode).lastLeafNode((this.unselectableClass) ? {leafClasses: [this.unselectableClass]} : false) : null;
+ if (prevLeaf) {
+ var uneditables = this.getOwnUneditables();
+ for (var i = 0, maxi = uneditables.length; i < maxi; i++) {
+ if (prevLeaf === uneditables[i]) {
+ return uneditables[i];
+ }
+ }
+ }
+ } else {
+ range = selection.getRangeAt(0);
+ range.setStart(range.startContainer, range.startOffset - 1);
+ // TODO: make getting children on range a separate funtion
+ if (range) {
+ contentNodes = range.getNodes([1,3]);
+ for (var n = 0, max = contentNodes.length; n < max; n++) {
+ if (contentNodes[n].parentNode && contentNodes[n].parentNode === node) {
+ childNodes.push(contentNodes[n]);
+ }
+ }
+ }
+ lastNode = childNodes.length > 0 ? childNodes[childNodes.length -1] : null;
+ if (lastNode && lastNode.nodeType === 1 && wysihtml5.dom.hasClass(lastNode, this.unselectableClass)) {
+ return lastNode;
+ }
+
+ }
+ }
+ return false;
+ },
+
+ // TODO: Figure out a method from following 2 that would work universally
+ executeAndRestoreRangy: function(method, restoreScrollPosition) {
+ var win = this.doc.defaultView || this.doc.parentWindow,
+ sel = rangy.saveSelection(win);
+
+ if (!sel) {
+ method();
+ } else {
+ try {
+ method();
+ } catch(e) {
+ setTimeout(function() { throw e; }, 0);
+ }
+ }
+ rangy.restoreSelection(sel);
+ },
+
+ // TODO: has problems in chrome 12. investigate block level and uneditable area inbetween
+ executeAndRestore: function(method, restoreScrollPosition) {
+ var body = this.doc.body,
+ oldScrollTop = restoreScrollPosition && body.scrollTop,
+ oldScrollLeft = restoreScrollPosition && body.scrollLeft,
+ className = "_wysihtml5-temp-placeholder",
+ placeholderHtml = '<span class="' + className + '">' + wysihtml5.INVISIBLE_SPACE + '</span>',
+ range = this.getRange(true),
+ caretPlaceholder,
+ newCaretPlaceholder,
+ nextSibling, prevSibling,
+ node, node2, range2,
+ newRange;
+
+ // Nothing selected, execute and say goodbye
+ if (!range) {
+ method(body, body);
+ return;
+ }
+
+ if (!range.collapsed) {
+ range2 = range.cloneRange();
+ node2 = range2.createContextualFragment(placeholderHtml);
+ range2.collapse(false);
+ range2.insertNode(node2);
+ range2.detach();
+ }
+
+ node = range.createContextualFragment(placeholderHtml);
+ range.insertNode(node);
+
+ if (node2) {
+ caretPlaceholder = this.contain.querySelectorAll("." + className);
+ range.setStartBefore(caretPlaceholder[0]);
+ range.setEndAfter(caretPlaceholder[caretPlaceholder.length -1]);
+ }
+ this.setSelection(range);
+
+ // Make sure that a potential error doesn't cause our placeholder element to be left as a placeholder
+ try {
+ method(range.startContainer, range.endContainer);
+ } catch(e) {
+ setTimeout(function() { throw e; }, 0);
+ }
+ caretPlaceholder = this.contain.querySelectorAll("." + className);
+ if (caretPlaceholder && caretPlaceholder.length) {
+ newRange = rangy.createRange(this.doc);
+ nextSibling = caretPlaceholder[0].nextSibling;
+ if (caretPlaceholder.length > 1) {
+ prevSibling = caretPlaceholder[caretPlaceholder.length -1].previousSibling;
+ }
+ if (prevSibling && nextSibling) {
+ newRange.setStartBefore(nextSibling);
+ newRange.setEndAfter(prevSibling);
+ } else {
+ newCaretPlaceholder = this.doc.createTextNode(wysihtml5.INVISIBLE_SPACE);
+ dom.insert(newCaretPlaceholder).after(caretPlaceholder[0]);
+ newRange.setStartBefore(newCaretPlaceholder);
+ newRange.setEndAfter(newCaretPlaceholder);
+ }
+ this.setSelection(newRange);
+ for (var i = caretPlaceholder.length; i--;) {
+ caretPlaceholder[i].parentNode.removeChild(caretPlaceholder[i]);
+ }
+
+ } else {
+ // fallback for when all hell breaks loose
+ this.contain.focus();
+ }
+
+ if (restoreScrollPosition) {
+ body.scrollTop = oldScrollTop;
+ body.scrollLeft = oldScrollLeft;
+ }
+
+ // Remove it again, just to make sure that the placeholder is definitely out of the dom tree
+ try {
+ caretPlaceholder.parentNode.removeChild(caretPlaceholder);
+ } catch(e2) {}
+ },
+
+ set: function(node, offset) {
+ var newRange = rangy.createRange(this.doc);
+ newRange.setStart(node, offset || 0);
+ this.setSelection(newRange);
+ },
+
+ /**
+ * Insert html at the caret position and move the cursor after the inserted html
+ *
+ * @param {String} html HTML string to insert
+ * @example
+ * selection.insertHTML("<p>foobar</p>");
+ */
+ insertHTML: function(html) {
+ var range = rangy.createRange(this.doc),
+ node = this.doc.createElement('DIV'),
+ fragment = this.doc.createDocumentFragment(),
+ lastChild;
+
+ node.innerHTML = html;
+ lastChild = node.lastChild;
+
+ while (node.firstChild) {
+ fragment.appendChild(node.firstChild);
+ }
+ this.insertNode(fragment);
+
+ if (lastChild) {
+ this.setAfter(lastChild);
+ }
+ },
+
+ /**
+ * Insert a node at the caret position and move the cursor behind it
+ *
+ * @param {Object} node HTML string to insert
+ * @example
+ * selection.insertNode(document.createTextNode("foobar"));
+ */
+ insertNode: function(node) {
+ var range = this.getRange();
+ if (range) {
+ range.insertNode(node);
+ }
+ },
+
+ /**
+ * Wraps current selection with the given node
+ *
+ * @param {Object} node The node to surround the selected elements with
+ */
+ surround: function(nodeOptions) {
+ var ranges = this.getOwnRanges(),
+ node, nodes = [];
+ if (ranges.length == 0) {
+ return nodes;
+ }
+
+ for (var i = ranges.length; i--;) {
+ node = this.doc.createElement(nodeOptions.nodeName);
+ nodes.push(node);
+ if (nodeOptions.className) {
+ node.className = nodeOptions.className;
+ }
+ if (nodeOptions.cssStyle) {
+ node.setAttribute('style', nodeOptions.cssStyle);
+ }
+ try {
+ // This only works when the range boundaries are not overlapping other elements
+ ranges[i].surroundContents(node);
+ this.selectNode(node);
+ } catch(e) {
+ // fallback
+ node.appendChild(ranges[i].extractContents());
+ ranges[i].insertNode(node);
+ }
+ }
+ return nodes;
+ },
+
+ deblockAndSurround: function(nodeOptions) {
+ var tempElement = this.doc.createElement('div'),
+ range = rangy.createRange(this.doc),
+ tempDivElements,
+ tempElements,
+ firstChild;
+
+ tempElement.className = nodeOptions.className;
+
+ this.composer.commands.exec("formatBlock", nodeOptions.nodeName, nodeOptions.className);
+ tempDivElements = this.contain.querySelectorAll("." + nodeOptions.className);
+ if (tempDivElements[0]) {
+ tempDivElements[0].parentNode.insertBefore(tempElement, tempDivElements[0]);
+
+ range.setStartBefore(tempDivElements[0]);
+ range.setEndAfter(tempDivElements[tempDivElements.length - 1]);
+ tempElements = range.extractContents();
+
+ while (tempElements.firstChild) {
+ firstChild = tempElements.firstChild;
+ if (firstChild.nodeType == 1 && wysihtml5.dom.hasClass(firstChild, nodeOptions.className)) {
+ while (firstChild.firstChild) {
+ tempElement.appendChild(firstChild.firstChild);
+ }
+ if (firstChild.nodeName !== "BR") { tempElement.appendChild(this.doc.createElement('br')); }
+ tempElements.removeChild(firstChild);
+ } else {
+ tempElement.appendChild(firstChild);
+ }
+ }
+ } else {
+ tempElement = null;
+ }
+
+ return tempElement;
+ },
+
+ /**
+ * Scroll the current caret position into the view
+ * FIXME: This is a bit hacky, there might be a smarter way of doing this
+ *
+ * @example
+ * selection.scrollIntoView();
+ */
+ scrollIntoView: function() {
+ var doc = this.doc,
+ tolerance = 5, // px
+ hasScrollBars = doc.documentElement.scrollHeight > doc.documentElement.offsetHeight,
+ tempElement = doc._wysihtml5ScrollIntoViewElement = doc._wysihtml5ScrollIntoViewElement || (function() {
+ var element = doc.createElement("span");
+ // The element needs content in order to be able to calculate it's position properly
+ element.innerHTML = wysihtml5.INVISIBLE_SPACE;
+ return element;
+ })(),
+ offsetTop;
+
+ if (hasScrollBars) {
+ this.insertNode(tempElement);
+ offsetTop = _getCumulativeOffsetTop(tempElement);
+ tempElement.parentNode.removeChild(tempElement);
+ if (offsetTop >= (doc.body.scrollTop + doc.documentElement.offsetHeight - tolerance)) {
+ doc.body.scrollTop = offsetTop;
+ }
+ }
+ },
+
+ /**
+ * Select line where the caret is in
+ */
+ selectLine: function() {
+ if (wysihtml5.browser.supportsSelectionModify()) {
+ this._selectLine_W3C();
+ } else if (this.doc.selection) {
+ this._selectLine_MSIE();
+ }
+ },
+
+ /**
+ * See https://developer.mozilla.org/en/DOM/Selection/modify
+ */
+ _selectLine_W3C: function() {
+ var win = this.doc.defaultView,
+ selection = win.getSelection();
+ selection.modify("move", "left", "lineboundary");
+ selection.modify("extend", "right", "lineboundary");
+ },
+
+ // collapses selection to current line beginning or end
+ toLineBoundary: function (location, collapse) {
+ collapse = (typeof collapse === 'undefined') ? false : collapse;
+ if (wysihtml5.browser.supportsSelectionModify()) {
+ var win = this.doc.defaultView,
+ selection = win.getSelection();
+
+ selection.modify("extend", location, "lineboundary");
+ if (collapse) {
+ if (location === "left") {
+ selection.collapseToStart();
+ } else if (location === "right") {
+ selection.collapseToEnd();
+ }
+ }
+ }
+ },
+
+ _selectLine_MSIE: function() {
+ var range = this.doc.selection.createRange(),
+ rangeTop = range.boundingTop,
+ scrollWidth = this.doc.body.scrollWidth,
+ rangeBottom,
+ rangeEnd,
+ measureNode,
+ i,
+ j;
+
+ if (!range.moveToPoint) {
+ return;
+ }
+
+ if (rangeTop === 0) {
+ // Don't know why, but when the selection ends at the end of a line
+ // range.boundingTop is 0
+ measureNode = this.doc.createElement("span");
+ this.insertNode(measureNode);
+ rangeTop = measureNode.offsetTop;
+ measureNode.parentNode.removeChild(measureNode);
+ }
+
+ rangeTop += 1;
+
+ for (i=-10; i<scrollWidth; i+=2) {
+ try {
+ range.moveToPoint(i, rangeTop);
+ break;
+ } catch(e1) {}
+ }
+
+ // Investigate the following in order to handle multi line selections
+ // rangeBottom = rangeTop + (rangeHeight ? (rangeHeight - 1) : 0);
+ rangeBottom = rangeTop;
+ rangeEnd = this.doc.selection.createRange();
+ for (j=scrollWidth; j>=0; j--) {
+ try {
+ rangeEnd.moveToPoint(j, rangeBottom);
+ break;
+ } catch(e2) {}
+ }
+
+ range.setEndPoint("EndToEnd", rangeEnd);
+ range.select();
+ },
+
+ getText: function() {
+ var selection = this.getSelection();
+ return selection ? selection.toString() : "";
+ },
+
+ getNodes: function(nodeType, filter) {
+ var range = this.getRange();
+ if (range) {
+ return range.getNodes([nodeType], filter);
+ } else {
+ return [];
+ }
+ },
+
+ fixRangeOverflow: function(range) {
+ if (this.contain && this.contain.firstChild && range) {
+ var containment = range.compareNode(this.contain);
+ if (containment !== 2) {
+ if (containment === 1) {
+ range.setStartBefore(this.contain.firstChild);
+ }
+ if (containment === 0) {
+ range.setEndAfter(this.contain.lastChild);
+ }
+ if (containment === 3) {
+ range.setStartBefore(this.contain.firstChild);
+ range.setEndAfter(this.contain.lastChild);
+ }
+ } else if (this._detectInlineRangeProblems(range)) {
+ var previousElementSibling = range.endContainer.previousElementSibling;
+ if (previousElementSibling) {
+ range.setEnd(previousElementSibling, this._endOffsetForNode(previousElementSibling));
+ }
+ }
+ }
+ },
+
+ _endOffsetForNode: function(node) {
+ var range = document.createRange();
+ range.selectNodeContents(node);
+ return range.endOffset;
+ },
+
+ _detectInlineRangeProblems: function(range) {
+ var position = dom.compareDocumentPosition(range.startContainer, range.endContainer);
+ return (
+ range.endOffset == 0 &&
+ position & 4 //Node.DOCUMENT_POSITION_FOLLOWING
+ );
+ },
+
+ getRange: function(dontFix) {
+ var selection = this.getSelection(),
+ range = selection && selection.rangeCount && selection.getRangeAt(0);
+
+ if (dontFix !== true) {
+ this.fixRangeOverflow(range);
+ }
+
+ return range;
+ },
+
+ getOwnUneditables: function() {
+ var allUneditables = dom.query(this.contain, '.' + this.unselectableClass),
+ deepUneditables = dom.query(allUneditables, '.' + this.unselectableClass);
+
+ return wysihtml5.lang.array(allUneditables).without(deepUneditables);
+ },
+
+ // Returns an array of ranges that belong only to this editable
+ // Needed as uneditable block in contenteditabel can split range into pieces
+ // If manipulating content reverse loop is usually needed as manipulation can shift subsequent ranges
+ getOwnRanges: function() {
+ var ranges = [],
+ r = this.getRange(),
+ tmpRanges;
+
+ if (r) { ranges.push(r); }
+
+ if (this.unselectableClass && this.contain && r) {
+ var uneditables = this.getOwnUneditables(),
+ tmpRange;
+ if (uneditables.length > 0) {
+ for (var i = 0, imax = uneditables.length; i < imax; i++) {
+ tmpRanges = [];
+ for (var j = 0, jmax = ranges.length; j < jmax; j++) {
+ if (ranges[j]) {
+ switch (ranges[j].compareNode(uneditables[i])) {
+ case 2:
+ // all selection inside uneditable. remove
+ break;
+ case 3:
+ //section begins before and ends after uneditable. spilt
+ tmpRange = ranges[j].cloneRange();
+ tmpRange.setEndBefore(uneditables[i]);
+ tmpRanges.push(tmpRange);
+
+ tmpRange = ranges[j].cloneRange();
+ tmpRange.setStartAfter(uneditables[i]);
+ tmpRanges.push(tmpRange);
+ break;
+ default:
+ // in all other cases uneditable does not touch selection. dont modify
+ tmpRanges.push(ranges[j]);
+ }
+ }
+ ranges = tmpRanges;
+ }
+ }
+ }
+ }
+ return ranges;
+ },
+
+ getSelection: function() {
+ return rangy.getSelection(this.doc.defaultView || this.doc.parentWindow);
+ },
+
+ // Sets selection in document to a given range
+ // Set selection method detects if it fails to set any selection in document and returns null on fail
+ // (especially needed in webkit where some ranges just can not create selection for no reason)
+ setSelection: function(range) {
+ var win = this.doc.defaultView || this.doc.parentWindow,
+ selection = rangy.getSelection(win);
+ selection.setSingleRange(range);
+ return (selection && selection.anchorNode && selection.focusNode) ? selection : null;
+ },
+
+ createRange: function() {
+ return rangy.createRange(this.doc);
+ },
+
+ isCollapsed: function() {
+ return this.getSelection().isCollapsed;
+ },
+
+ getHtml: function() {
+ return this.getSelection().toHtml();
+ },
+
+ getPlainText: function () {
+ return this.getSelection().toString();
+ },
+
+ isEndToEndInNode: function(nodeNames) {
+ var range = this.getRange(),
+ parentElement = range.commonAncestorContainer,
+ startNode = range.startContainer,
+ endNode = range.endContainer;
+
+
+ if (parentElement.nodeType === wysihtml5.TEXT_NODE) {
+ parentElement = parentElement.parentNode;
+ }
+
+ if (startNode.nodeType === wysihtml5.TEXT_NODE && !(/^\s*$/).test(startNode.data.substr(range.startOffset))) {
+ return false;
+ }
+
+ if (endNode.nodeType === wysihtml5.TEXT_NODE && !(/^\s*$/).test(endNode.data.substr(range.endOffset))) {
+ return false;
+ }
+
+ while (startNode && startNode !== parentElement) {
+ if (startNode.nodeType !== wysihtml5.TEXT_NODE && !wysihtml5.dom.contains(parentElement, startNode)) {
+ return false;
+ }
+ if (wysihtml5.dom.domNode(startNode).prev({ignoreBlankTexts: true})) {
+ return false;
+ }
+ startNode = startNode.parentNode;
+ }
+
+ while (endNode && endNode !== parentElement) {
+ if (endNode.nodeType !== wysihtml5.TEXT_NODE && !wysihtml5.dom.contains(parentElement, endNode)) {
+ return false;
+ }
+ if (wysihtml5.dom.domNode(endNode).next({ignoreBlankTexts: true})) {
+ return false;
+ }
+ endNode = endNode.parentNode;
+ }
+
+ return (wysihtml5.lang.array(nodeNames).contains(parentElement.nodeName)) ? parentElement : false;
+ },
+
+ deselect: function() {
+ var sel = this.getSelection();
+ sel && sel.removeAllRanges();
+ }
+ });
+
+})(wysihtml5);
+;/**
+ * Inspired by the rangy CSS Applier module written by Tim Down and licensed under the MIT license.
+ * http://code.google.com/p/rangy/
+ *
+ * changed in order to be able ...
+ * - to use custom tags
+ * - to detect and replace similar css classes via reg exp
+ */
+(function(wysihtml5, rangy) {
+ var defaultTagName = "span";
+
+ var REG_EXP_WHITE_SPACE = /\s+/g;
+
+ function hasClass(el, cssClass, regExp) {
+ if (!el.className) {
+ return false;
+ }
+
+ var matchingClassNames = el.className.match(regExp) || [];
+ return matchingClassNames[matchingClassNames.length - 1] === cssClass;
+ }
+
+ function hasStyleAttr(el, regExp) {
+ if (!el.getAttribute || !el.getAttribute('style')) {
+ return false;
+ }
+ var matchingStyles = el.getAttribute('style').match(regExp);
+ return (el.getAttribute('style').match(regExp)) ? true : false;
+ }
+
+ function addStyle(el, cssStyle, regExp) {
+ if (el.getAttribute('style')) {
+ removeStyle(el, regExp);
+ if (el.getAttribute('style') && !(/^\s*$/).test(el.getAttribute('style'))) {
+ el.setAttribute('style', cssStyle + ";" + el.getAttribute('style'));
+ } else {
+ el.setAttribute('style', cssStyle);
+ }
+ } else {
+ el.setAttribute('style', cssStyle);
+ }
+ }
+
+ function addClass(el, cssClass, regExp) {
+ if (el.className) {
+ removeClass(el, regExp);
+ el.className += " " + cssClass;
+ } else {
+ el.className = cssClass;
+ }
+ }
+
+ function removeClass(el, regExp) {
+ if (el.className) {
+ el.className = el.className.replace(regExp, "");
+ }
+ }
+
+ function removeStyle(el, regExp) {
+ var s,
+ s2 = [];
+ if (el.getAttribute('style')) {
+ s = el.getAttribute('style').split(';');
+ for (var i = s.length; i--;) {
+ if (!s[i].match(regExp) && !(/^\s*$/).test(s[i])) {
+ s2.push(s[i]);
+ }
+ }
+ if (s2.length) {
+ el.setAttribute('style', s2.join(';'));
+ } else {
+ el.removeAttribute('style');
+ }
+ }
+ }
+
+ function getMatchingStyleRegexp(el, style) {
+ var regexes = [],
+ sSplit = style.split(';'),
+ elStyle = el.getAttribute('style');
+
+ if (elStyle) {
+ elStyle = elStyle.replace(/\s/gi, '').toLowerCase();
+ regexes.push(new RegExp("(^|\\s|;)" + style.replace(/\s/gi, '').replace(/([\(\)])/gi, "\\$1").toLowerCase().replace(";", ";?").replace(/rgb\\\((\d+),(\d+),(\d+)\\\)/gi, "\\s?rgb\\($1,\\s?$2,\\s?$3\\)"), "gi"));
+
+ for (var i = sSplit.length; i-- > 0;) {
+ if (!(/^\s*$/).test(sSplit[i])) {
+ regexes.push(new RegExp("(^|\\s|;)" + sSplit[i].replace(/\s/gi, '').replace(/([\(\)])/gi, "\\$1").toLowerCase().replace(";", ";?").replace(/rgb\\\((\d+),(\d+),(\d+)\\\)/gi, "\\s?rgb\\($1,\\s?$2,\\s?$3\\)"), "gi"));
+ }
+ }
+ for (var j = 0, jmax = regexes.length; j < jmax; j++) {
+ if (elStyle.match(regexes[j])) {
+ return regexes[j];
+ }
+ }
+ }
+
+ return false;
+ }
+
+ function isMatchingAllready(node, tags, style, className) {
+ if (style) {
+ return getMatchingStyleRegexp(node, style);
+ } else if (className) {
+ return wysihtml5.dom.hasClass(node, className);
+ } else {
+ return rangy.dom.arrayContains(tags, node.tagName.toLowerCase());
+ }
+ }
+
+ function areMatchingAllready(nodes, tags, style, className) {
+ for (var i = nodes.length; i--;) {
+ if (!isMatchingAllready(nodes[i], tags, style, className)) {
+ return false;
+ }
+ }
+ return nodes.length ? true : false;
+ }
+
+ function removeOrChangeStyle(el, style, regExp) {
+
+ var exactRegex = getMatchingStyleRegexp(el, style);
+ if (exactRegex) {
+ // adding same style value on property again removes style
+ removeStyle(el, exactRegex);
+ return "remove";
+ } else {
+ // adding new style value changes value
+ addStyle(el, style, regExp);
+ return "change";
+ }
+ }
+
+ function hasSameClasses(el1, el2) {
+ return el1.className.replace(REG_EXP_WHITE_SPACE, " ") == el2.className.replace(REG_EXP_WHITE_SPACE, " ");
+ }
+
+ function replaceWithOwnChildren(el) {
+ var parent = el.parentNode;
+ while (el.firstChild) {
+ parent.insertBefore(el.firstChild, el);
+ }
+ parent.removeChild(el);
+ }
+
+ function elementsHaveSameNonClassAttributes(el1, el2) {
+ if (el1.attributes.length != el2.attributes.length) {
+ return false;
+ }
+ for (var i = 0, len = el1.attributes.length, attr1, attr2, name; i < len; ++i) {
+ attr1 = el1.attributes[i];
+ name = attr1.name;
+ if (name != "class") {
+ attr2 = el2.attributes.getNamedItem(name);
+ if (attr1.specified != attr2.specified) {
+ return false;
+ }
+ if (attr1.specified && attr1.nodeValue !== attr2.nodeValue) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ function isSplitPoint(node, offset) {
+ if (rangy.dom.isCharacterDataNode(node)) {
+ if (offset == 0) {
+ return !!node.previousSibling;
+ } else if (offset == node.length) {
+ return !!node.nextSibling;
+ } else {
+ return true;
+ }
+ }
+
+ return offset > 0 && offset < node.childNodes.length;
+ }
+
+ function splitNodeAt(node, descendantNode, descendantOffset, container) {
+ var newNode;
+ if (rangy.dom.isCharacterDataNode(descendantNode)) {
+ if (descendantOffset == 0) {
+ descendantOffset = rangy.dom.getNodeIndex(descendantNode);
+ descendantNode = descendantNode.parentNode;
+ } else if (descendantOffset == descendantNode.length) {
+ descendantOffset = rangy.dom.getNodeIndex(descendantNode) + 1;
+ descendantNode = descendantNode.parentNode;
+ } else {
+ newNode = rangy.dom.splitDataNode(descendantNode, descendantOffset);
+ }
+ }
+ if (!newNode) {
+ if (!container || descendantNode !== container) {
+
+ newNode = descendantNode.cloneNode(false);
+ if (newNode.id) {
+ newNode.removeAttribute("id");
+ }
+ var child;
+ while ((child = descendantNode.childNodes[descendantOffset])) {
+ newNode.appendChild(child);
+ }
+ rangy.dom.insertAfter(newNode, descendantNode);
+
+ }
+ }
+ return (descendantNode == node) ? newNode : splitNodeAt(node, newNode.parentNode, rangy.dom.getNodeIndex(newNode), container);
+ }
+
+ function Merge(firstNode) {
+ this.isElementMerge = (firstNode.nodeType == wysihtml5.ELEMENT_NODE);
+ this.firstTextNode = this.isElementMerge ? firstNode.lastChild : firstNode;
+ this.textNodes = [this.firstTextNode];
+ }
+
+ Merge.prototype = {
+ doMerge: function() {
+ var textBits = [], textNode, parent, text;
+ for (var i = 0, len = this.textNodes.length; i < len; ++i) {
+ textNode = this.textNodes[i];
+ parent = textNode.parentNode;
+ textBits[i] = textNode.data;
+ if (i) {
+ parent.removeChild(textNode);
+ if (!parent.hasChildNodes()) {
+ parent.parentNode.removeChild(parent);
+ }
+ }
+ }
+ this.firstTextNode.data = text = textBits.join("");
+ return text;
+ },
+
+ getLength: function() {
+ var i = this.textNodes.length, len = 0;
+ while (i--) {
+ len += this.textNodes[i].length;
+ }
+ return len;
+ },
+
+ toString: function() {
+ var textBits = [];
+ for (var i = 0, len = this.textNodes.length; i < len; ++i) {
+ textBits[i] = "'" + this.textNodes[i].data + "'";
+ }
+ return "[Merge(" + textBits.join(",") + ")]";
+ }
+ };
+
+ function HTMLApplier(tagNames, cssClass, similarClassRegExp, normalize, cssStyle, similarStyleRegExp, container) {
+ this.tagNames = tagNames || [defaultTagName];
+ this.cssClass = cssClass || ((cssClass === false) ? false : "");
+ this.similarClassRegExp = similarClassRegExp;
+ this.cssStyle = cssStyle || "";
+ this.similarStyleRegExp = similarStyleRegExp;
+ this.normalize = normalize;
+ this.applyToAnyTagName = false;
+ this.container = container;
+ }
+
+ HTMLApplier.prototype = {
+ getAncestorWithClass: function(node) {
+ var cssClassMatch;
+ while (node) {
+ cssClassMatch = this.cssClass ? hasClass(node, this.cssClass, this.similarClassRegExp) : (this.cssStyle !== "") ? false : true;
+ if (node.nodeType == wysihtml5.ELEMENT_NODE && node.getAttribute("contenteditable") != "false" && rangy.dom.arrayContains(this.tagNames, node.tagName.toLowerCase()) && cssClassMatch) {
+ return node;
+ }
+ node = node.parentNode;
+ }
+ return false;
+ },
+
+ // returns parents of node with given style attribute
+ getAncestorWithStyle: function(node) {
+ var cssStyleMatch;
+ while (node) {
+ cssStyleMatch = this.cssStyle ? hasStyleAttr(node, this.similarStyleRegExp) : false;
+
+ if (node.nodeType == wysihtml5.ELEMENT_NODE && node.getAttribute("contenteditable") != "false" && rangy.dom.arrayContains(this.tagNames, node.tagName.toLowerCase()) && cssStyleMatch) {
+ return node;
+ }
+ node = node.parentNode;
+ }
+ return false;
+ },
+
+ getMatchingAncestor: function(node) {
+ var ancestor = this.getAncestorWithClass(node),
+ matchType = false;
+
+ if (!ancestor) {
+ ancestor = this.getAncestorWithStyle(node);
+ if (ancestor) {
+ matchType = "style";
+ }
+ } else {
+ if (this.cssStyle) {
+ matchType = "class";
+ }
+ }
+
+ return {
+ "element": ancestor,
+ "type": matchType
+ };
+ },
+
+ // Normalizes nodes after applying a CSS class to a Range.
+ postApply: function(textNodes, range) {
+ var firstNode = textNodes[0], lastNode = textNodes[textNodes.length - 1];
+
+ var merges = [], currentMerge;
+
+ var rangeStartNode = firstNode, rangeEndNode = lastNode;
+ var rangeStartOffset = 0, rangeEndOffset = lastNode.length;
+
+ var textNode, precedingTextNode;
+
+ for (var i = 0, len = textNodes.length; i < len; ++i) {
+ textNode = textNodes[i];
+ precedingTextNode = null;
+ if (textNode && textNode.parentNode) {
+ precedingTextNode = this.getAdjacentMergeableTextNode(textNode.parentNode, false);
+ }
+ if (precedingTextNode) {
+ if (!currentMerge) {
+ currentMerge = new Merge(precedingTextNode);
+ merges.push(currentMerge);
+ }
+ currentMerge.textNodes.push(textNode);
+ if (textNode === firstNode) {
+ rangeStartNode = currentMerge.firstTextNode;
+ rangeStartOffset = rangeStartNode.length;
+ }
+ if (textNode === lastNode) {
+ rangeEndNode = currentMerge.firstTextNode;
+ rangeEndOffset = currentMerge.getLength();
+ }
+ } else {
+ currentMerge = null;
+ }
+ }
+ // Test whether the first node after the range needs merging
+ if(lastNode && lastNode.parentNode) {
+ var nextTextNode = this.getAdjacentMergeableTextNode(lastNode.parentNode, true);
+ if (nextTextNode) {
+ if (!currentMerge) {
+ currentMerge = new Merge(lastNode);
+ merges.push(currentMerge);
+ }
+ currentMerge.textNodes.push(nextTextNode);
+ }
+ }
+ // Do the merges
+ if (merges.length) {
+ for (i = 0, len = merges.length; i < len; ++i) {
+ merges[i].doMerge();
+ }
+ // Set the range boundaries
+ range.setStart(rangeStartNode, rangeStartOffset);
+ range.setEnd(rangeEndNode, rangeEndOffset);
+ }
+ },
+
+ getAdjacentMergeableTextNode: function(node, forward) {
+ var isTextNode = (node.nodeType == wysihtml5.TEXT_NODE);
+ var el = isTextNode ? node.parentNode : node;
+ var adjacentNode;
+ var propName = forward ? "nextSibling" : "previousSibling";
+ if (isTextNode) {
+ // Can merge if the node's previous/next sibling is a text node
+ adjacentNode = node[propName];
+ if (adjacentNode && adjacentNode.nodeType == wysihtml5.TEXT_NODE) {
+ return adjacentNode;
+ }
+ } else {
+ // Compare element with its sibling
+ adjacentNode = el[propName];
+ if (adjacentNode && this.areElementsMergeable(node, adjacentNode)) {
+ return adjacentNode[forward ? "firstChild" : "lastChild"];
+ }
+ }
+ return null;
+ },
+
+ areElementsMergeable: function(el1, el2) {
+ return rangy.dom.arrayContains(this.tagNames, (el1.tagName || "").toLowerCase())
+ && rangy.dom.arrayContains(this.tagNames, (el2.tagName || "").toLowerCase())
+ && hasSameClasses(el1, el2)
+ && elementsHaveSameNonClassAttributes(el1, el2);
+ },
+
+ createContainer: function(doc) {
+ var el = doc.createElement(this.tagNames[0]);
+ if (this.cssClass) {
+ el.className = this.cssClass;
+ }
+ if (this.cssStyle) {
+ el.setAttribute('style', this.cssStyle);
+ }
+ return el;
+ },
+
+ applyToTextNode: function(textNode) {
+ var parent = textNode.parentNode;
+ if (parent.childNodes.length == 1 && rangy.dom.arrayContains(this.tagNames, parent.tagName.toLowerCase())) {
+
+ if (this.cssClass) {
+ addClass(parent, this.cssClass, this.similarClassRegExp);
+ }
+ if (this.cssStyle) {
+ addStyle(parent, this.cssStyle, this.similarStyleRegExp);
+ }
+ } else {
+ var el = this.createContainer(rangy.dom.getDocument(textNode));
+ textNode.parentNode.insertBefore(el, textNode);
+ el.appendChild(textNode);
+ }
+ },
+
+ isRemovable: function(el) {
+ return rangy.dom.arrayContains(this.tagNames, el.tagName.toLowerCase()) &&
+ wysihtml5.lang.string(el.className).trim() === "" &&
+ (
+ !el.getAttribute('style') ||
+ wysihtml5.lang.string(el.getAttribute('style')).trim() === ""
+ );
+ },
+
+ undoToTextNode: function(textNode, range, ancestorWithClass, ancestorWithStyle) {
+ var styleMode = (ancestorWithClass) ? false : true,
+ ancestor = ancestorWithClass || ancestorWithStyle,
+ styleChanged = false;
+ if (!range.containsNode(ancestor)) {
+ // Split out the portion of the ancestor from which we can remove the CSS class
+ var ancestorRange = range.cloneRange();
+ ancestorRange.selectNode(ancestor);
+
+ if (ancestorRange.isPointInRange(range.endContainer, range.endOffset) && isSplitPoint(range.endContainer, range.endOffset)) {
+ splitNodeAt(ancestor, range.endContainer, range.endOffset, this.container);
+ range.setEndAfter(ancestor);
+ }
+ if (ancestorRange.isPointInRange(range.startContainer, range.startOffset) && isSplitPoint(range.startContainer, range.startOffset)) {
+ ancestor = splitNodeAt(ancestor, range.startContainer, range.startOffset, this.container);
+ }
+ }
+
+ if (!styleMode && this.similarClassRegExp) {
+ removeClass(ancestor, this.similarClassRegExp);
+ }
+
+ if (styleMode && this.similarStyleRegExp) {
+ styleChanged = (removeOrChangeStyle(ancestor, this.cssStyle, this.similarStyleRegExp) === "change");
+ }
+ if (this.isRemovable(ancestor) && !styleChanged) {
+ replaceWithOwnChildren(ancestor);
+ }
+ },
+
+ applyToRange: function(range) {
+ var textNodes;
+ for (var ri = range.length; ri--;) {
+ textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
+
+ if (!textNodes.length) {
+ try {
+ var node = this.createContainer(range[ri].endContainer.ownerDocument);
+ range[ri].surroundContents(node);
+ this.selectNode(range[ri], node);
+ return;
+ } catch(e) {}
+ }
+
+ range[ri].splitBoundaries();
+ textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
+ if (textNodes.length) {
+ var textNode;
+
+ for (var i = 0, len = textNodes.length; i < len; ++i) {
+ textNode = textNodes[i];
+ if (!this.getMatchingAncestor(textNode).element) {
+ this.applyToTextNode(textNode);
+ }
+ }
+
+ range[ri].setStart(textNodes[0], 0);
+ textNode = textNodes[textNodes.length - 1];
+ range[ri].setEnd(textNode, textNode.length);
+
+ if (this.normalize) {
+ this.postApply(textNodes, range[ri]);
+ }
+ }
+
+ }
+ },
+
+ undoToRange: function(range) {
+ var textNodes, textNode, ancestorWithClass, ancestorWithStyle, ancestor;
+ for (var ri = range.length; ri--;) {
+
+ textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
+ if (textNodes.length) {
+ range[ri].splitBoundaries();
+ textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
+ } else {
+ var doc = range[ri].endContainer.ownerDocument,
+ node = doc.createTextNode(wysihtml5.INVISIBLE_SPACE);
+ range[ri].insertNode(node);
+ range[ri].selectNode(node);
+ textNodes = [node];
+ }
+
+ for (var i = 0, len = textNodes.length; i < len; ++i) {
+ if (range[ri].isValid()) {
+ textNode = textNodes[i];
+
+ ancestor = this.getMatchingAncestor(textNode);
+ if (ancestor.type === "style") {
+ this.undoToTextNode(textNode, range[ri], false, ancestor.element);
+ } else if (ancestor.element) {
+ this.undoToTextNode(textNode, range[ri], ancestor.element);
+ }
+ }
+ }
+
+ if (len == 1) {
+ this.selectNode(range[ri], textNodes[0]);
+ } else {
+ range[ri].setStart(textNodes[0], 0);
+ textNode = textNodes[textNodes.length - 1];
+ range[ri].setEnd(textNode, textNode.length);
+
+ if (this.normalize) {
+ this.postApply(textNodes, range[ri]);
+ }
+ }
+
+ }
+ },
+
+ selectNode: function(range, node) {
+ var isElement = node.nodeType === wysihtml5.ELEMENT_NODE,
+ canHaveHTML = "canHaveHTML" in node ? node.canHaveHTML : true,
+ content = isElement ? node.innerHTML : node.data,
+ isEmpty = (content === "" || content === wysihtml5.INVISIBLE_SPACE);
+
+ if (isEmpty && isElement && canHaveHTML) {
+ // Make sure that caret is visible in node by inserting a zero width no breaking space
+ try { node.innerHTML = wysihtml5.INVISIBLE_SPACE; } catch(e) {}
+ }
+ range.selectNodeContents(node);
+ if (isEmpty && isElement) {
+ range.collapse(false);
+ } else if (isEmpty) {
+ range.setStartAfter(node);
+ range.setEndAfter(node);
+ }
+ },
+
+ getTextSelectedByRange: function(textNode, range) {
+ var textRange = range.cloneRange();
+ textRange.selectNodeContents(textNode);
+
+ var intersectionRange = textRange.intersection(range);
+ var text = intersectionRange ? intersectionRange.toString() : "";
+ textRange.detach();
+
+ return text;
+ },
+
+ isAppliedToRange: function(range) {
+ var ancestors = [],
+ appliedType = "full",
+ ancestor, styleAncestor, textNodes;
+
+ for (var ri = range.length; ri--;) {
+
+ textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
+ if (!textNodes.length) {
+ ancestor = this.getMatchingAncestor(range[ri].startContainer).element;
+
+ return (ancestor) ? {
+ "elements": [ancestor],
+ "coverage": appliedType
+ } : false;
+ }
+
+ for (var i = 0, len = textNodes.length, selectedText; i < len; ++i) {
+ selectedText = this.getTextSelectedByRange(textNodes[i], range[ri]);
+ ancestor = this.getMatchingAncestor(textNodes[i]).element;
+ if (ancestor && selectedText != "") {
+ ancestors.push(ancestor);
+
+ if (wysihtml5.dom.getTextNodes(ancestor, true).length === 1) {
+ appliedType = "full";
+ } else if (appliedType === "full") {
+ appliedType = "inline";
+ }
+ } else if (!ancestor) {
+ appliedType = "partial";
+ }
+ }
+
+ }
+
+ return (ancestors.length) ? {
+ "elements": ancestors,
+ "coverage": appliedType
+ } : false;
+ },
+
+ toggleRange: function(range) {
+ var isApplied = this.isAppliedToRange(range),
+ parentsExactMatch;
+
+ if (isApplied) {
+ if (isApplied.coverage === "full") {
+ this.undoToRange(range);
+ } else if (isApplied.coverage === "inline") {
+ parentsExactMatch = areMatchingAllready(isApplied.elements, this.tagNames, this.cssStyle, this.cssClass);
+ this.undoToRange(range);
+ if (!parentsExactMatch) {
+ this.applyToRange(range);
+ }
+ } else {
+ // partial
+ if (!areMatchingAllready(isApplied.elements, this.tagNames, this.cssStyle, this.cssClass)) {
+ this.undoToRange(range);
+ }
+ this.applyToRange(range);
+ }
+ } else {
+ this.applyToRange(range);
+ }
+ }
+ };
+
+ wysihtml5.selection.HTMLApplier = HTMLApplier;
+
+})(wysihtml5, rangy);
+;/**
+ * Rich Text Query/Formatting Commands
+ *
+ * @example
+ * var commands = new wysihtml5.Commands(editor);
+ */
+wysihtml5.Commands = Base.extend(
+ /** @scope wysihtml5.Commands.prototype */ {
+ constructor: function(editor) {
+ this.editor = editor;
+ this.composer = editor.composer;
+ this.doc = this.composer.doc;
+ },
+
+ /**
+ * Check whether the browser supports the given command
+ *
+ * @param {String} command The command string which to check (eg. "bold", "italic", "insertUnorderedList")
+ * @example
+ * commands.supports("createLink");
+ */
+ support: function(command) {
+ return wysihtml5.browser.supportsCommand(this.doc, command);
+ },
+
+ /**
+ * Check whether the browser supports the given command
+ *
+ * @param {String} command The command string which to execute (eg. "bold", "italic", "insertUnorderedList")
+ * @param {String} [value] The command value parameter, needed for some commands ("createLink", "insertImage", ...), optional for commands that don't require one ("bold", "underline", ...)
+ * @example
+ * commands.exec("insertImage", "http://a1.twimg.com/profile_images/113868655/schrei_twitter_reasonably_small.jpg");
+ */
+ exec: function(command, value) {
+ var obj = wysihtml5.commands[command],
+ args = wysihtml5.lang.array(arguments).get(),
+ method = obj && obj.exec,
+ result = null;
+
+ // If composer ahs placeholder unset it before command
+ // Do not apply on commands that are behavioral
+ if (this.composer.hasPlaceholderSet() && !wysihtml5.lang.array(['styleWithCSS', 'enableObjectResizing', 'enableInlineTableEditing']).contains(command)) {
+ this.composer.element.innerHTML = "";
+ this.composer.selection.selectNode(this.composer.element);
+ }
+
+ this.editor.fire("beforecommand:composer");
+
+ if (method) {
+ args.unshift(this.composer);
+ result = method.apply(obj, args);
+ } else {
+ try {
+ // try/catch for buggy firefox
+ result = this.doc.execCommand(command, false, value);
+ } catch(e) {}
+ }
+
+ this.editor.fire("aftercommand:composer");
+ return result;
+ },
+
+ /**
+ * Check whether the current command is active
+ * If the caret is within a bold text, then calling this with command "bold" should return true
+ *
+ * @param {String} command The command string which to check (eg. "bold", "italic", "insertUnorderedList")
+ * @param {String} [commandValue] The command value parameter (eg. for "insertImage" the image src)
+ * @return {Boolean} Whether the command is active
+ * @example
+ * var isCurrentSelectionBold = commands.state("bold");
+ */
+ state: function(command, commandValue) {
+ var obj = wysihtml5.commands[command],
+ args = wysihtml5.lang.array(arguments).get(),
+ method = obj && obj.state;
+ if (method) {
+ args.unshift(this.composer);
+ return method.apply(obj, args);
+ } else {
+ try {
+ // try/catch for buggy firefox
+ return this.doc.queryCommandState(command);
+ } catch(e) {
+ return false;
+ }
+ }
+ },
+
+ /* Get command state parsed value if command has stateValue parsing function */
+ stateValue: function(command) {
+ var obj = wysihtml5.commands[command],
+ args = wysihtml5.lang.array(arguments).get(),
+ method = obj && obj.stateValue;
+ if (method) {
+ args.unshift(this.composer);
+ return method.apply(obj, args);
+ } else {
+ return false;
+ }
+ }
+});
+;wysihtml5.commands.bold = {
+ exec: function(composer, command) {
+ wysihtml5.commands.formatInline.execWithToggle(composer, command, "b");
+ },
+
+ state: function(composer, command) {
+ // element.ownerDocument.queryCommandState("bold") results:
+ // firefox: only <b>
+ // chrome: <b>, <strong>, <h1>, <h2>, ...
+ // ie: <b>, <strong>
+ // opera: <b>, <strong>
+ return wysihtml5.commands.formatInline.state(composer, command, "b");
+ }
+};
+
+;(function(wysihtml5) {
+ var undef,
+ NODE_NAME = "A",
+ dom = wysihtml5.dom;
+
+ function _format(composer, attributes) {
+ var doc = composer.doc,
+ tempClass = "_wysihtml5-temp-" + (+new Date()),
+ tempClassRegExp = /non-matching-class/g,
+ i = 0,
+ length,
+ anchors,
+ anchor,
+ hasElementChild,
+ isEmpty,
+ elementToSetCaretAfter,
+ textContent,
+ whiteSpace,
+ j;
+ wysihtml5.commands.formatInline.exec(composer, undef, NODE_NAME, tempClass, tempClassRegExp, undef, undef, true, true);
+ anchors = doc.querySelectorAll(NODE_NAME + "." + tempClass);
+ length = anchors.length;
+ for (; i<length; i++) {
+ anchor = anchors[i];
+ anchor.removeAttribute("class");
+ for (j in attributes) {
+ // Do not set attribute "text" as it is meant for setting string value if created link has no textual data
+ if (j !== "text") {
+ anchor.setAttribute(j, attributes[j]);
+ }
+ }
+ }
+
+ elementToSetCaretAfter = anchor;
+ if (length === 1) {
+ textContent = dom.getTextContent(anchor);
+ hasElementChild = !!anchor.querySelector("*");
+ isEmpty = textContent === "" || textContent === wysihtml5.INVISIBLE_SPACE;
+ if (!hasElementChild && isEmpty) {
+ dom.setTextContent(anchor, attributes.text || anchor.href);
+ whiteSpace = doc.createTextNode(" ");
+ composer.selection.setAfter(anchor);
+ dom.insert(whiteSpace).after(anchor);
+ elementToSetCaretAfter = whiteSpace;
+ }
+ }
+ composer.selection.setAfter(elementToSetCaretAfter);
+ }
+
+ // Changes attributes of links
+ function _changeLinks(composer, anchors, attributes) {
+ var oldAttrs;
+ for (var a = anchors.length; a--;) {
+
+ // Remove all old attributes
+ oldAttrs = anchors[a].attributes;
+ for (var oa = oldAttrs.length; oa--;) {
+ anchors[a].removeAttribute(oldAttrs.item(oa).name);
+ }
+
+ // Set new attributes
+ for (var j in attributes) {
+ if (attributes.hasOwnProperty(j)) {
+ anchors[a].setAttribute(j, attributes[j]);
+ }
+ }
+
+ }
+ }
+
+ wysihtml5.commands.createLink = {
+ /**
+ * TODO: Use HTMLApplier or formatInline here
+ *
+ * Turns selection into a link
+ * If selection is already a link, it just changes the attributes
+ *
+ * @example
+ * // either ...
+ * wysihtml5.commands.createLink.exec(composer, "createLink", "http://www.google.de");
+ * // ... or ...
+ * wysihtml5.commands.createLink.exec(composer, "createLink", { href: "http://www.google.de", target: "_blank" });
+ */
+ exec: function(composer, command, value) {
+ var anchors = this.state(composer, command);
+ if (anchors) {
+ // Selection contains links then change attributes of these links
+ composer.selection.executeAndRestore(function() {
+ _changeLinks(composer, anchors, value);
+ });
+ } else {
+ // Create links
+ value = typeof(value) === "object" ? value : { href: value };
+ _format(composer, value);
+ }
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatInline.state(composer, command, "A");
+ }
+ };
+})(wysihtml5);
+;(function(wysihtml5) {
+ var dom = wysihtml5.dom;
+
+ function _removeFormat(composer, anchors) {
+ var length = anchors.length,
+ i = 0,
+ anchor,
+ codeElement,
+ textContent;
+ for (; i<length; i++) {
+ anchor = anchors[i];
+ codeElement = dom.getParentElement(anchor, { nodeName: "code" });
+ textContent = dom.getTextContent(anchor);
+
+ // if <a> contains url-like text content, rename it to <code> to prevent re-autolinking
+ // else replace <a> with its childNodes
+ if (textContent.match(dom.autoLink.URL_REG_EXP) && !codeElement) {
+ // <code> element is used to prevent later auto-linking of the content
+ codeElement = dom.renameElement(anchor, "code");
+ } else {
+ dom.replaceWithChildNodes(anchor);
+ }
+ }
+ }
+
+ wysihtml5.commands.removeLink = {
+ /*
+ * If selection is a link, it removes the link and wraps it with a <code> element
+ * The <code> element is needed to avoid auto linking
+ *
+ * @example
+ * wysihtml5.commands.createLink.exec(composer, "removeLink");
+ */
+
+ exec: function(composer, command) {
+ var anchors = this.state(composer, command);
+ if (anchors) {
+ composer.selection.executeAndRestore(function() {
+ _removeFormat(composer, anchors);
+ });
+ }
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatInline.state(composer, command, "A");
+ }
+ };
+})(wysihtml5);
+;/**
+ * document.execCommand("fontSize") will create either inline styles (firefox, chrome) or use font tags
+ * which we don't want
+ * Instead we set a css class
+ */
+(function(wysihtml5) {
+ var REG_EXP = /wysiwyg-font-size-[0-9a-z\-]+/g;
+
+ wysihtml5.commands.fontSize = {
+ exec: function(composer, command, size) {
+ wysihtml5.commands.formatInline.execWithToggle(composer, command, "span", "wysiwyg-font-size-" + size, REG_EXP);
+ },
+
+ state: function(composer, command, size) {
+ return wysihtml5.commands.formatInline.state(composer, command, "span", "wysiwyg-font-size-" + size, REG_EXP);
+ }
+ };
+})(wysihtml5);
+;/* In case font size adjustment to any number defined by user is preferred, we cannot use classes and must use inline styles. */
+(function(wysihtml5) {
+ var REG_EXP = /(\s|^)font-size\s*:\s*[^;\s]+;?/gi;
+
+ wysihtml5.commands.fontSizeStyle = {
+ exec: function(composer, command, size) {
+ size = (typeof(size) == "object") ? size.size : size;
+ if (!(/^\s*$/).test(size)) {
+ wysihtml5.commands.formatInline.execWithToggle(composer, command, "span", false, false, "font-size:" + size, REG_EXP);
+ }
+ },
+
+ state: function(composer, command, size) {
+ return wysihtml5.commands.formatInline.state(composer, command, "span", false, false, "font-size", REG_EXP);
+ },
+
+ stateValue: function(composer, command) {
+ var st = this.state(composer, command),
+ styleStr, fontsizeMatches,
+ val = false;
+
+ if (st && wysihtml5.lang.object(st).isArray()) {
+ st = st[0];
+ }
+ if (st) {
+ styleStr = st.getAttribute('style');
+ if (styleStr) {
+ return wysihtml5.quirks.styleParser.parseFontSize(styleStr);
+ }
+ }
+ return false;
+ }
+ };
+})(wysihtml5);
+;/**
+ * document.execCommand("foreColor") will create either inline styles (firefox, chrome) or use font tags
+ * which we don't want
+ * Instead we set a css class
+ */
+(function(wysihtml5) {
+ var REG_EXP = /wysiwyg-color-[0-9a-z]+/g;
+
+ wysihtml5.commands.foreColor = {
+ exec: function(composer, command, color) {
+ wysihtml5.commands.formatInline.execWithToggle(composer, command, "span", "wysiwyg-color-" + color, REG_EXP);
+ },
+
+ state: function(composer, command, color) {
+ return wysihtml5.commands.formatInline.state(composer, command, "span", "wysiwyg-color-" + color, REG_EXP);
+ }
+ };
+})(wysihtml5);
+;/**
+ * document.execCommand("foreColor") will create either inline styles (firefox, chrome) or use font tags
+ * which we don't want
+ * Instead we set a css class
+ */
+(function(wysihtml5) {
+ var REG_EXP = /(\s|^)color\s*:\s*[^;\s]+;?/gi;
+
+ wysihtml5.commands.foreColorStyle = {
+ exec: function(composer, command, color) {
+ var colorVals = wysihtml5.quirks.styleParser.parseColor((typeof(color) == "object") ? "color:" + color.color : "color:" + color, "color"),
+ colString;
+
+ if (colorVals) {
+ colString = "color: rgb(" + colorVals[0] + ',' + colorVals[1] + ',' + colorVals[2] + ');';
+ if (colorVals[3] !== 1) {
+ colString += "color: rgba(" + colorVals[0] + ',' + colorVals[1] + ',' + colorVals[2] + ',' + colorVals[3] + ');';
+ }
+ wysihtml5.commands.formatInline.execWithToggle(composer, command, "span", false, false, colString, REG_EXP);
+ }
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatInline.state(composer, command, "span", false, false, "color", REG_EXP);
+ },
+
+ stateValue: function(composer, command, props) {
+ var st = this.state(composer, command),
+ colorStr;
+
+ if (st && wysihtml5.lang.object(st).isArray()) {
+ st = st[0];
+ }
+
+ if (st) {
+ colorStr = st.getAttribute('style');
+ if (colorStr) {
+ if (colorStr) {
+ val = wysihtml5.quirks.styleParser.parseColor(colorStr, "color");
+ return wysihtml5.quirks.styleParser.unparseColor(val, props);
+ }
+ }
+ }
+ return false;
+ }
+
+ };
+})(wysihtml5);
+;/* In case background adjustment to any color defined by user is preferred, we cannot use classes and must use inline styles. */
+(function(wysihtml5) {
+ var REG_EXP = /(\s|^)background-color\s*:\s*[^;\s]+;?/gi;
+
+ wysihtml5.commands.bgColorStyle = {
+ exec: function(composer, command, color) {
+ var colorVals = wysihtml5.quirks.styleParser.parseColor((typeof(color) == "object") ? "background-color:" + color.color : "background-color:" + color, "background-color"),
+ colString;
+
+ if (colorVals) {
+ colString = "background-color: rgb(" + colorVals[0] + ',' + colorVals[1] + ',' + colorVals[2] + ');';
+ if (colorVals[3] !== 1) {
+ colString += "background-color: rgba(" + colorVals[0] + ',' + colorVals[1] + ',' + colorVals[2] + ',' + colorVals[3] + ');';
+ }
+ wysihtml5.commands.formatInline.execWithToggle(composer, command, "span", false, false, colString, REG_EXP);
+ }
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatInline.state(composer, command, "span", false, false, "background-color", REG_EXP);
+ },
+
+ stateValue: function(composer, command, props) {
+ var st = this.state(composer, command),
+ colorStr,
+ val = false;
+
+ if (st && wysihtml5.lang.object(st).isArray()) {
+ st = st[0];
+ }
+
+ if (st) {
+ colorStr = st.getAttribute('style');
+ if (colorStr) {
+ val = wysihtml5.quirks.styleParser.parseColor(colorStr, "background-color");
+ return wysihtml5.quirks.styleParser.unparseColor(val, props);
+ }
+ }
+ return false;
+ }
+
+ };
+})(wysihtml5);
+;(function(wysihtml5) {
+ var dom = wysihtml5.dom,
+ // Following elements are grouped
+ // when the caret is within a H1 and the H4 is invoked, the H1 should turn into H4
+ // instead of creating a H4 within a H1 which would result in semantically invalid html
+ BLOCK_ELEMENTS_GROUP = ["H1", "H2", "H3", "H4", "H5", "H6", "P", "PRE", "DIV"];
+
+ /**
+ * Remove similiar classes (based on classRegExp)
+ * and add the desired class name
+ */
+ function _addClass(element, className, classRegExp) {
+ if (element.className) {
+ _removeClass(element, classRegExp);
+ element.className = wysihtml5.lang.string(element.className + " " + className).trim();
+ } else {
+ element.className = className;
+ }
+ }
+
+ function _addStyle(element, cssStyle, styleRegExp) {
+ _removeStyle(element, styleRegExp);
+ if (element.getAttribute('style')) {
+ element.setAttribute('style', wysihtml5.lang.string(element.getAttribute('style') + " " + cssStyle).trim());
+ } else {
+ element.setAttribute('style', cssStyle);
+ }
+ }
+
+ function _removeClass(element, classRegExp) {
+ var ret = classRegExp.test(element.className);
+ element.className = element.className.replace(classRegExp, "");
+ if (wysihtml5.lang.string(element.className).trim() == '') {
+ element.removeAttribute('class');
+ }
+ return ret;
+ }
+
+ function _removeStyle(element, styleRegExp) {
+ var ret = styleRegExp.test(element.getAttribute('style'));
+ element.setAttribute('style', (element.getAttribute('style') || "").replace(styleRegExp, ""));
+ if (wysihtml5.lang.string(element.getAttribute('style') || "").trim() == '') {
+ element.removeAttribute('style');
+ }
+ return ret;
+ }
+
+ function _removeLastChildIfLineBreak(node) {
+ var lastChild = node.lastChild;
+ if (lastChild && _isLineBreak(lastChild)) {
+ lastChild.parentNode.removeChild(lastChild);
+ }
+ }
+
+ function _isLineBreak(node) {
+ return node.nodeName === "BR";
+ }
+
+ /**
+ * Execute native query command
+ * and if necessary modify the inserted node's className
+ */
+ function _execCommand(doc, composer, command, nodeName, className) {
+ var ranges = composer.selection.getOwnRanges();
+ for (var i = ranges.length; i--;){
+ composer.selection.getSelection().removeAllRanges();
+ composer.selection.setSelection(ranges[i]);
+ if (className) {
+ var eventListener = dom.observe(doc, "DOMNodeInserted", function(event) {
+ var target = event.target,
+ displayStyle;
+ if (target.nodeType !== wysihtml5.ELEMENT_NODE) {
+ return;
+ }
+ displayStyle = dom.getStyle("display").from(target);
+ if (displayStyle.substr(0, 6) !== "inline") {
+ // Make sure that only block elements receive the given class
+ target.className += " " + className;
+ }
+ });
+ }
+ doc.execCommand(command, false, nodeName);
+
+ if (eventListener) {
+ eventListener.stop();
+ }
+ }
+ }
+
+ function _selectionWrap(composer, options) {
+ if (composer.selection.isCollapsed()) {
+ composer.selection.selectLine();
+ }
+
+ var surroundedNodes = composer.selection.surround(options);
+ for (var i = 0, imax = surroundedNodes.length; i < imax; i++) {
+ wysihtml5.dom.lineBreaks(surroundedNodes[i]).remove();
+ _removeLastChildIfLineBreak(surroundedNodes[i]);
+ }
+
+ // rethink restoring selection
+ // composer.selection.selectNode(element, wysihtml5.browser.displaysCaretInEmptyContentEditableCorrectly());
+ }
+
+ function _hasClasses(element) {
+ return !!wysihtml5.lang.string(element.className).trim();
+ }
+
+ function _hasStyles(element) {
+ return !!wysihtml5.lang.string(element.getAttribute('style') || '').trim();
+ }
+
+ wysihtml5.commands.formatBlock = {
+ exec: function(composer, command, nodeName, className, classRegExp, cssStyle, styleRegExp) {
+ var doc = composer.doc,
+ blockElements = this.state(composer, command, nodeName, className, classRegExp, cssStyle, styleRegExp),
+ useLineBreaks = composer.config.useLineBreaks,
+ defaultNodeName = useLineBreaks ? "DIV" : "P",
+ selectedNodes, classRemoveAction, blockRenameFound, styleRemoveAction, blockElement;
+ nodeName = typeof(nodeName) === "string" ? nodeName.toUpperCase() : nodeName;
+
+ if (blockElements.length) {
+ composer.selection.executeAndRestoreRangy(function() {
+ for (var b = blockElements.length; b--;) {
+ if (classRegExp) {
+ classRemoveAction = _removeClass(blockElements[b], classRegExp);
+ }
+ if (styleRegExp) {
+ styleRemoveAction = _removeStyle(blockElements[b], styleRegExp);
+ }
+
+ if ((styleRemoveAction || classRemoveAction) && nodeName === null && blockElements[b].nodeName != defaultNodeName) {
+ // dont rename or remove element when just setting block formating class or style
+ return;
+ }
+
+ var hasClasses = _hasClasses(blockElements[b]),
+ hasStyles = _hasStyles(blockElements[b]);
+
+ if (!hasClasses && !hasStyles && (useLineBreaks || nodeName === "P")) {
+ // Insert a line break afterwards and beforewards when there are siblings
+ // that are not of type line break or block element
+ wysihtml5.dom.lineBreaks(blockElements[b]).add();
+ dom.replaceWithChildNodes(blockElements[b]);
+ } else {
+ // Make sure that styling is kept by renaming the element to a <div> or <p> and copying over the class name
+ dom.renameElement(blockElements[b], nodeName === "P" ? "DIV" : defaultNodeName);
+ }
+ }
+ });
+
+ return;
+ }
+
+ // Find similiar block element and rename it (<h2 class="foo"></h2> => <h1 class="foo"></h1>)
+ if (nodeName === null || wysihtml5.lang.array(BLOCK_ELEMENTS_GROUP).contains(nodeName)) {
+ selectedNodes = composer.selection.findNodesInSelection(BLOCK_ELEMENTS_GROUP).concat(composer.selection.getSelectedOwnNodes());
+ composer.selection.executeAndRestoreRangy(function() {
+ for (var n = selectedNodes.length; n--;) {
+ blockElement = dom.getParentElement(selectedNodes[n], {
+ nodeName: BLOCK_ELEMENTS_GROUP
+ });
+ if (blockElement == composer.element) {
+ blockElement = null;
+ }
+ if (blockElement) {
+ // Rename current block element to new block element and add class
+ if (nodeName) {
+ blockElement = dom.renameElement(blockElement, nodeName);
+ }
+ if (className) {
+ _addClass(blockElement, className, classRegExp);
+ }
+ if (cssStyle) {
+ _addStyle(blockElement, cssStyle, styleRegExp);
+ }
+ blockRenameFound = true;
+ }
+ }
+
+ });
+
+ if (blockRenameFound) {
+ return;
+ }
+ }
+
+ _selectionWrap(composer, {
+ "nodeName": (nodeName || defaultNodeName),
+ "className": className || null,
+ "cssStyle": cssStyle || null
+ });
+ },
+
+ state: function(composer, command, nodeName, className, classRegExp, cssStyle, styleRegExp) {
+ var nodes = composer.selection.getSelectedOwnNodes(),
+ parents = [],
+ parent;
+
+ nodeName = typeof(nodeName) === "string" ? nodeName.toUpperCase() : nodeName;
+
+ //var selectedNode = composer.selection.getSelectedNode();
+ for (var i = 0, maxi = nodes.length; i < maxi; i++) {
+ parent = dom.getParentElement(nodes[i], {
+ nodeName: nodeName,
+ className: className,
+ classRegExp: classRegExp,
+ cssStyle: cssStyle,
+ styleRegExp: styleRegExp
+ });
+ if (parent && wysihtml5.lang.array(parents).indexOf(parent) == -1) {
+ parents.push(parent);
+ }
+ }
+ if (parents.length == 0) {
+ return false;
+ }
+ return parents;
+ }
+
+
+ };
+})(wysihtml5);
+;/* Formats block for as a <pre><code class="classname"></code></pre> block
+ * Useful in conjuction for sytax highlight utility: highlight.js
+ *
+ * Usage:
+ *
+ * editorInstance.composer.commands.exec("formatCode", "language-html");
+*/
+
+wysihtml5.commands.formatCode = {
+
+ exec: function(composer, command, classname) {
+ var pre = this.state(composer),
+ code, range, selectedNodes;
+ if (pre) {
+ // caret is already within a <pre><code>...</code></pre>
+ composer.selection.executeAndRestore(function() {
+ code = pre.querySelector("code");
+ wysihtml5.dom.replaceWithChildNodes(pre);
+ if (code) {
+ wysihtml5.dom.replaceWithChildNodes(code);
+ }
+ });
+ } else {
+ // Wrap in <pre><code>...</code></pre>
+ range = composer.selection.getRange();
+ selectedNodes = range.extractContents();
+ pre = composer.doc.createElement("pre");
+ code = composer.doc.createElement("code");
+
+ if (classname) {
+ code.className = classname;
+ }
+
+ pre.appendChild(code);
+ code.appendChild(selectedNodes);
+ range.insertNode(pre);
+ composer.selection.selectNode(pre);
+ }
+ },
+
+ state: function(composer) {
+ var selectedNode = composer.selection.getSelectedNode();
+ if (selectedNode && selectedNode.nodeName && selectedNode.nodeName == "PRE"&&
+ selectedNode.firstChild && selectedNode.firstChild.nodeName && selectedNode.firstChild.nodeName == "CODE") {
+ return selectedNode;
+ } else {
+ return wysihtml5.dom.getParentElement(selectedNode, { nodeName: "CODE" }) && wysihtml5.dom.getParentElement(selectedNode, { nodeName: "PRE" });
+ }
+ }
+};;/**
+ * formatInline scenarios for tag "B" (| = caret, |foo| = selected text)
+ *
+ * #1 caret in unformatted text:
+ * abcdefg|
+ * output:
+ * abcdefg<b>|</b>
+ *
+ * #2 unformatted text selected:
+ * abc|deg|h
+ * output:
+ * abc<b>|deg|</b>h
+ *
+ * #3 unformatted text selected across boundaries:
+ * ab|c <span>defg|h</span>
+ * output:
+ * ab<b>|c </b><span><b>defg</b>|h</span>
+ *
+ * #4 formatted text entirely selected
+ * <b>|abc|</b>
+ * output:
+ * |abc|
+ *
+ * #5 formatted text partially selected
+ * <b>ab|c|</b>
+ * output:
+ * <b>ab</b>|c|
+ *
+ * #6 formatted text selected across boundaries
+ * <span>ab|c</span> <b>de|fgh</b>
+ * output:
+ * <span>ab|c</span> de|<b>fgh</b>
+ */
+(function(wysihtml5) {
+ var // Treat <b> as <strong> and vice versa
+ ALIAS_MAPPING = {
+ "strong": "b",
+ "em": "i",
+ "b": "strong",
+ "i": "em"
+ },
+ htmlApplier = {};
+
+ function _getTagNames(tagName) {
+ var alias = ALIAS_MAPPING[tagName];
+ return alias ? [tagName.toLowerCase(), alias.toLowerCase()] : [tagName.toLowerCase()];
+ }
+
+ function _getApplier(tagName, className, classRegExp, cssStyle, styleRegExp, container) {
+ var identifier = tagName;
+
+ if (className) {
+ identifier += ":" + className;
+ }
+ if (cssStyle) {
+ identifier += ":" + cssStyle;
+ }
+
+ if (!htmlApplier[identifier]) {
+ htmlApplier[identifier] = new wysihtml5.selection.HTMLApplier(_getTagNames(tagName), className, classRegExp, true, cssStyle, styleRegExp, container);
+ }
+
+ return htmlApplier[identifier];
+ }
+
+ wysihtml5.commands.formatInline = {
+ exec: function(composer, command, tagName, className, classRegExp, cssStyle, styleRegExp, dontRestoreSelect, noCleanup) {
+ var range = composer.selection.createRange(),
+ ownRanges = composer.selection.getOwnRanges();
+
+ if (!ownRanges || ownRanges.length == 0) {
+ return false;
+ }
+ composer.selection.getSelection().removeAllRanges();
+
+ _getApplier(tagName, className, classRegExp, cssStyle, styleRegExp, composer.element).toggleRange(ownRanges);
+
+ if (!dontRestoreSelect) {
+ range.setStart(ownRanges[0].startContainer, ownRanges[0].startOffset);
+ range.setEnd(
+ ownRanges[ownRanges.length - 1].endContainer,
+ ownRanges[ownRanges.length - 1].endOffset
+ );
+ composer.selection.setSelection(range);
+ composer.selection.executeAndRestore(function() {
+ if (!noCleanup) {
+ composer.cleanUp();
+ }
+ }, true, true);
+ } else if (!noCleanup) {
+ composer.cleanUp();
+ }
+ },
+
+ // Executes so that if collapsed caret is in a state and executing that state it should unformat that state
+ // It is achieved by selecting the entire state element before executing.
+ // This works on built in contenteditable inline format commands
+ execWithToggle: function(composer, command, tagName, className, classRegExp, cssStyle, styleRegExp) {
+ var that = this;
+
+ if (this.state(composer, command, tagName, className, classRegExp, cssStyle, styleRegExp) &&
+ composer.selection.isCollapsed() &&
+ !composer.selection.caretIsLastInSelection() &&
+ !composer.selection.caretIsFirstInSelection()
+ ) {
+ var state_element = that.state(composer, command, tagName, className, classRegExp)[0];
+ composer.selection.executeAndRestoreRangy(function() {
+ var parent = state_element.parentNode;
+ composer.selection.selectNode(state_element, true);
+ wysihtml5.commands.formatInline.exec(composer, command, tagName, className, classRegExp, cssStyle, styleRegExp, true, true);
+ });
+ } else {
+ if (this.state(composer, command, tagName, className, classRegExp, cssStyle, styleRegExp) && !composer.selection.isCollapsed()) {
+ composer.selection.executeAndRestoreRangy(function() {
+ wysihtml5.commands.formatInline.exec(composer, command, tagName, className, classRegExp, cssStyle, styleRegExp, true, true);
+ });
+ } else {
+ wysihtml5.commands.formatInline.exec(composer, command, tagName, className, classRegExp, cssStyle, styleRegExp);
+ }
+ }
+ },
+
+ state: function(composer, command, tagName, className, classRegExp, cssStyle, styleRegExp) {
+ var doc = composer.doc,
+ aliasTagName = ALIAS_MAPPING[tagName] || tagName,
+ ownRanges, isApplied;
+
+ // Check whether the document contains a node with the desired tagName
+ if (!wysihtml5.dom.hasElementWithTagName(doc, tagName) &&
+ !wysihtml5.dom.hasElementWithTagName(doc, aliasTagName)) {
+ return false;
+ }
+
+ // Check whether the document contains a node with the desired className
+ if (className && !wysihtml5.dom.hasElementWithClassName(doc, className)) {
+ return false;
+ }
+
+ ownRanges = composer.selection.getOwnRanges();
+
+ if (!ownRanges || ownRanges.length === 0) {
+ return false;
+ }
+
+ isApplied = _getApplier(tagName, className, classRegExp, cssStyle, styleRegExp, composer.element).isAppliedToRange(ownRanges);
+
+ return (isApplied && isApplied.elements) ? isApplied.elements : false;
+ }
+ };
+})(wysihtml5);
+;(function(wysihtml5) {
+
+ wysihtml5.commands.insertBlockQuote = {
+ exec: function(composer, command) {
+ var state = this.state(composer, command),
+ endToEndParent = composer.selection.isEndToEndInNode(['H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'P']),
+ prevNode, nextNode;
+
+ composer.selection.executeAndRestore(function() {
+ if (state) {
+ if (composer.config.useLineBreaks) {
+ wysihtml5.dom.lineBreaks(state).add();
+ }
+ wysihtml5.dom.unwrap(state);
+ } else {
+ if (composer.selection.isCollapsed()) {
+ composer.selection.selectLine();
+ }
+
+ if (endToEndParent) {
+ var qouteEl = endToEndParent.ownerDocument.createElement('blockquote');
+ wysihtml5.dom.insert(qouteEl).after(endToEndParent);
+ qouteEl.appendChild(endToEndParent);
+ } else {
+ composer.selection.surround({nodeName: "blockquote"});
+ }
+ }
+ });
+ },
+ state: function(composer, command) {
+ var selectedNode = composer.selection.getSelectedNode(),
+ node = wysihtml5.dom.getParentElement(selectedNode, { nodeName: "BLOCKQUOTE" }, false, composer.element);
+
+ return (node) ? node : false;
+ }
+ };
+
+})(wysihtml5);;wysihtml5.commands.insertHTML = {
+ exec: function(composer, command, html) {
+ if (composer.commands.support(command)) {
+ composer.doc.execCommand(command, false, html);
+ } else {
+ composer.selection.insertHTML(html);
+ }
+ },
+
+ state: function() {
+ return false;
+ }
+};
+;(function(wysihtml5) {
+ var NODE_NAME = "IMG";
+
+ wysihtml5.commands.insertImage = {
+ /**
+ * Inserts an <img>
+ * If selection is already an image link, it removes it
+ *
+ * @example
+ * // either ...
+ * wysihtml5.commands.insertImage.exec(composer, "insertImage", "http://www.google.de/logo.jpg");
+ * // ... or ...
+ * wysihtml5.commands.insertImage.exec(composer, "insertImage", { src: "http://www.google.de/logo.jpg", title: "foo" });
+ */
+ exec: function(composer, command, value) {
+ value = typeof(value) === "object" ? value : { src: value };
+
+ var doc = composer.doc,
+ image = this.state(composer),
+ textNode,
+ parent;
+
+ if (image) {
+ // Image already selected, set the caret before it and delete it
+ composer.selection.setBefore(image);
+ parent = image.parentNode;
+ parent.removeChild(image);
+
+ // and it's parent <a> too if it hasn't got any other relevant child nodes
+ wysihtml5.dom.removeEmptyTextNodes(parent);
+ if (parent.nodeName === "A" && !parent.firstChild) {
+ composer.selection.setAfter(parent);
+ parent.parentNode.removeChild(parent);
+ }
+
+ // firefox and ie sometimes don't remove the image handles, even though the image got removed
+ wysihtml5.quirks.redraw(composer.element);
+ return;
+ }
+
+ image = doc.createElement(NODE_NAME);
+
+ for (var i in value) {
+ image.setAttribute(i === "className" ? "class" : i, value[i]);
+ }
+
+ composer.selection.insertNode(image);
+ if (wysihtml5.browser.hasProblemsSettingCaretAfterImg()) {
+ textNode = doc.createTextNode(wysihtml5.INVISIBLE_SPACE);
+ composer.selection.insertNode(textNode);
+ composer.selection.setAfter(textNode);
+ } else {
+ composer.selection.setAfter(image);
+ }
+ },
+
+ state: function(composer) {
+ var doc = composer.doc,
+ selectedNode,
+ text,
+ imagesInSelection;
+
+ if (!wysihtml5.dom.hasElementWithTagName(doc, NODE_NAME)) {
+ return false;
+ }
+
+ selectedNode = composer.selection.getSelectedNode();
+ if (!selectedNode) {
+ return false;
+ }
+
+ if (selectedNode.nodeName === NODE_NAME) {
+ // This works perfectly in IE
+ return selectedNode;
+ }
+
+ if (selectedNode.nodeType !== wysihtml5.ELEMENT_NODE) {
+ return false;
+ }
+
+ text = composer.selection.getText();
+ text = wysihtml5.lang.string(text).trim();
+ if (text) {
+ return false;
+ }
+
+ imagesInSelection = composer.selection.getNodes(wysihtml5.ELEMENT_NODE, function(node) {
+ return node.nodeName === "IMG";
+ });
+
+ if (imagesInSelection.length !== 1) {
+ return false;
+ }
+
+ return imagesInSelection[0];
+ }
+ };
+})(wysihtml5);
+;(function(wysihtml5) {
+ var LINE_BREAK = "<br>" + (wysihtml5.browser.needsSpaceAfterLineBreak() ? " " : "");
+
+ wysihtml5.commands.insertLineBreak = {
+ exec: function(composer, command) {
+ if (composer.commands.support(command)) {
+ composer.doc.execCommand(command, false, null);
+ if (!wysihtml5.browser.autoScrollsToCaret()) {
+ composer.selection.scrollIntoView();
+ }
+ } else {
+ composer.commands.exec("insertHTML", LINE_BREAK);
+ }
+ },
+
+ state: function() {
+ return false;
+ }
+ };
+})(wysihtml5);
+;wysihtml5.commands.insertOrderedList = {
+ exec: function(composer, command) {
+ wysihtml5.commands.insertList.exec(composer, command, "OL");
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.insertList.state(composer, command, "OL");
+ }
+};
+;wysihtml5.commands.insertUnorderedList = {
+ exec: function(composer, command) {
+ wysihtml5.commands.insertList.exec(composer, command, "UL");
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.insertList.state(composer, command, "UL");
+ }
+};
+;wysihtml5.commands.insertList = (function(wysihtml5) {
+
+ var isNode = function(node, name) {
+ if (node && node.nodeName) {
+ if (typeof name === 'string') {
+ name = [name];
+ }
+ for (var n = name.length; n--;) {
+ if (node.nodeName === name[n]) {
+ return true;
+ }
+ }
+ }
+ return false;
+ };
+
+ var findListEl = function(node, nodeName, composer) {
+ var ret = {
+ el: null,
+ other: false
+ };
+
+ if (node) {
+ var parentLi = wysihtml5.dom.getParentElement(node, { nodeName: "LI" }),
+ otherNodeName = (nodeName === "UL") ? "OL" : "UL";
+
+ if (isNode(node, nodeName)) {
+ ret.el = node;
+ } else if (isNode(node, otherNodeName)) {
+ ret = {
+ el: node,
+ other: true
+ };
+ } else if (parentLi) {
+ if (isNode(parentLi.parentNode, nodeName)) {
+ ret.el = parentLi.parentNode;
+ } else if (isNode(parentLi.parentNode, otherNodeName)) {
+ ret = {
+ el : parentLi.parentNode,
+ other: true
+ };
+ }
+ }
+ }
+
+ // do not count list elements outside of composer
+ if (ret.el && !composer.element.contains(ret.el)) {
+ ret.el = null;
+ }
+
+ return ret;
+ };
+
+ var handleSameTypeList = function(el, nodeName, composer) {
+ var otherNodeName = (nodeName === "UL") ? "OL" : "UL",
+ otherLists, innerLists;
+ // Unwrap list
+ // <ul><li>foo</li><li>bar</li></ul>
+ // becomes:
+ // foo<br>bar<br>
+ composer.selection.executeAndRestore(function() {
+ var otherLists = getListsInSelection(otherNodeName, composer);
+ if (otherLists.length) {
+ for (var l = otherLists.length; l--;) {
+ wysihtml5.dom.renameElement(otherLists[l], nodeName.toLowerCase());
+ }
+ } else {
+ innerLists = getListsInSelection(['OL', 'UL'], composer);
+ for (var i = innerLists.length; i--;) {
+ wysihtml5.dom.resolveList(innerLists[i], composer.config.useLineBreaks);
+ }
+ wysihtml5.dom.resolveList(el, composer.config.useLineBreaks);
+ }
+ });
+ };
+
+ var handleOtherTypeList = function(el, nodeName, composer) {
+ var otherNodeName = (nodeName === "UL") ? "OL" : "UL";
+ // Turn an ordered list into an unordered list
+ // <ol><li>foo</li><li>bar</li></ol>
+ // becomes:
+ // <ul><li>foo</li><li>bar</li></ul>
+ // Also rename other lists in selection
+ composer.selection.executeAndRestore(function() {
+ var renameLists = [el].concat(getListsInSelection(otherNodeName, composer));
+
+ // All selection inner lists get renamed too
+ for (var l = renameLists.length; l--;) {
+ wysihtml5.dom.renameElement(renameLists[l], nodeName.toLowerCase());
+ }
+ });
+ };
+
+ var getListsInSelection = function(nodeName, composer) {
+ var ranges = composer.selection.getOwnRanges(),
+ renameLists = [];
+
+ for (var r = ranges.length; r--;) {
+ renameLists = renameLists.concat(ranges[r].getNodes([1], function(node) {
+ return isNode(node, nodeName);
+ }));
+ }
+
+ return renameLists;
+ };
+
+ var createListFallback = function(nodeName, composer) {
+ // Fallback for Create list
+ composer.selection.executeAndRestoreRangy(function() {
+ var tempClassName = "_wysihtml5-temp-" + new Date().getTime(),
+ tempElement = composer.selection.deblockAndSurround({
+ "nodeName": "div",
+ "className": tempClassName
+ }),
+ isEmpty, list;
+
+ // This space causes new lists to never break on enter
+ var INVISIBLE_SPACE_REG_EXP = /\uFEFF/g;
+ tempElement.innerHTML = tempElement.innerHTML.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "");
+
+ if (tempElement) {
+ isEmpty = wysihtml5.lang.array(["", "<br>", wysihtml5.INVISIBLE_SPACE]).contains(tempElement.innerHTML);
+ list = wysihtml5.dom.convertToList(tempElement, nodeName.toLowerCase(), composer.parent.config.uneditableContainerClassname);
+ if (isEmpty) {
+ composer.selection.selectNode(list.querySelector("li"), true);
+ }
+ }
+ });
+ };
+
+ return {
+ exec: function(composer, command, nodeName) {
+ var doc = composer.doc,
+ cmd = (nodeName === "OL") ? "insertOrderedList" : "insertUnorderedList",
+ selectedNode = composer.selection.getSelectedNode(),
+ list = findListEl(selectedNode, nodeName, composer);
+
+ if (!list.el) {
+ if (composer.commands.support(cmd)) {
+ doc.execCommand(cmd, false, null);
+ } else {
+ createListFallback(nodeName, composer);
+ }
+ } else if (list.other) {
+ handleOtherTypeList(list.el, nodeName, composer);
+ } else {
+ handleSameTypeList(list.el, nodeName, composer);
+ }
+ },
+
+ state: function(composer, command, nodeName) {
+ var selectedNode = composer.selection.getSelectedNode(),
+ list = findListEl(selectedNode, nodeName, composer);
+
+ return (list.el && !list.other) ? list.el : false;
+ }
+ };
+
+})(wysihtml5);;wysihtml5.commands.italic = {
+ exec: function(composer, command) {
+ wysihtml5.commands.formatInline.execWithToggle(composer, command, "i");
+ },
+
+ state: function(composer, command) {
+ // element.ownerDocument.queryCommandState("italic") results:
+ // firefox: only <i>
+ // chrome: <i>, <em>, <blockquote>, ...
+ // ie: <i>, <em>
+ // opera: only <i>
+ return wysihtml5.commands.formatInline.state(composer, command, "i");
+ }
+};
+;(function(wysihtml5) {
+ var CLASS_NAME = "wysiwyg-text-align-center",
+ REG_EXP = /wysiwyg-text-align-[0-9a-z]+/g;
+
+ wysihtml5.commands.justifyCenter = {
+ exec: function(composer, command) {
+ return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", null, CLASS_NAME, REG_EXP);
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatBlock.state(composer, "formatBlock", null, CLASS_NAME, REG_EXP);
+ }
+ };
+})(wysihtml5);
+;(function(wysihtml5) {
+ var CLASS_NAME = "wysiwyg-text-align-left",
+ REG_EXP = /wysiwyg-text-align-[0-9a-z]+/g;
+
+ wysihtml5.commands.justifyLeft = {
+ exec: function(composer, command) {
+ return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", null, CLASS_NAME, REG_EXP);
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatBlock.state(composer, "formatBlock", null, CLASS_NAME, REG_EXP);
+ }
+ };
+})(wysihtml5);
+;(function(wysihtml5) {
+ var CLASS_NAME = "wysiwyg-text-align-right",
+ REG_EXP = /wysiwyg-text-align-[0-9a-z]+/g;
+
+ wysihtml5.commands.justifyRight = {
+ exec: function(composer, command) {
+ return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", null, CLASS_NAME, REG_EXP);
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatBlock.state(composer, "formatBlock", null, CLASS_NAME, REG_EXP);
+ }
+ };
+})(wysihtml5);
+;(function(wysihtml5) {
+ var CLASS_NAME = "wysiwyg-text-align-justify",
+ REG_EXP = /wysiwyg-text-align-[0-9a-z]+/g;
+
+ wysihtml5.commands.justifyFull = {
+ exec: function(composer, command) {
+ return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", null, CLASS_NAME, REG_EXP);
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatBlock.state(composer, "formatBlock", null, CLASS_NAME, REG_EXP);
+ }
+ };
+})(wysihtml5);
+;(function(wysihtml5) {
+ var STYLE_STR = "text-align: right;",
+ REG_EXP = /(\s|^)text-align\s*:\s*[^;\s]+;?/gi;
+
+ wysihtml5.commands.alignRightStyle = {
+ exec: function(composer, command) {
+ return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", null, null, null, STYLE_STR, REG_EXP);
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatBlock.state(composer, "formatBlock", null, null, null, STYLE_STR, REG_EXP);
+ }
+ };
+})(wysihtml5);
+;(function(wysihtml5) {
+ var STYLE_STR = "text-align: left;",
+ REG_EXP = /(\s|^)text-align\s*:\s*[^;\s]+;?/gi;
+
+ wysihtml5.commands.alignLeftStyle = {
+ exec: function(composer, command) {
+ return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", null, null, null, STYLE_STR, REG_EXP);
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatBlock.state(composer, "formatBlock", null, null, null, STYLE_STR, REG_EXP);
+ }
+ };
+})(wysihtml5);
+;(function(wysihtml5) {
+ var STYLE_STR = "text-align: center;",
+ REG_EXP = /(\s|^)text-align\s*:\s*[^;\s]+;?/gi;
+
+ wysihtml5.commands.alignCenterStyle = {
+ exec: function(composer, command) {
+ return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", null, null, null, STYLE_STR, REG_EXP);
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatBlock.state(composer, "formatBlock", null, null, null, STYLE_STR, REG_EXP);
+ }
+ };
+})(wysihtml5);
+;wysihtml5.commands.redo = {
+ exec: function(composer) {
+ return composer.undoManager.redo();
+ },
+
+ state: function(composer) {
+ return false;
+ }
+};
+;wysihtml5.commands.underline = {
+ exec: function(composer, command) {
+ wysihtml5.commands.formatInline.execWithToggle(composer, command, "u");
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatInline.state(composer, command, "u");
+ }
+};
+;wysihtml5.commands.undo = {
+ exec: function(composer) {
+ return composer.undoManager.undo();
+ },
+
+ state: function(composer) {
+ return false;
+ }
+};
+;wysihtml5.commands.createTable = {
+ exec: function(composer, command, value) {
+ var col, row, html;
+ if (value && value.cols && value.rows && parseInt(value.cols, 10) > 0 && parseInt(value.rows, 10) > 0) {
+ if (value.tableStyle) {
+ html = "<table style=\"" + value.tableStyle + "\">";
+ } else {
+ html = "<table>";
+ }
+ html += "<tbody>";
+ for (row = 0; row < value.rows; row ++) {
+ html += '<tr>';
+ for (col = 0; col < value.cols; col ++) {
+ html += "<td> </td>";
+ }
+ html += '</tr>';
+ }
+ html += "</tbody></table>";
+ composer.commands.exec("insertHTML", html);
+ //composer.selection.insertHTML(html);
+ }
+
+
+ },
+
+ state: function(composer, command) {
+ return false;
+ }
+};
+;wysihtml5.commands.mergeTableCells = {
+ exec: function(composer, command) {
+ if (composer.tableSelection && composer.tableSelection.start && composer.tableSelection.end) {
+ if (this.state(composer, command)) {
+ wysihtml5.dom.table.unmergeCell(composer.tableSelection.start);
+ } else {
+ wysihtml5.dom.table.mergeCellsBetween(composer.tableSelection.start, composer.tableSelection.end);
+ }
+ }
+ },
+
+ state: function(composer, command) {
+ if (composer.tableSelection) {
+ var start = composer.tableSelection.start,
+ end = composer.tableSelection.end;
+ if (start && end && start == end &&
+ ((
+ wysihtml5.dom.getAttribute(start, "colspan") &&
+ parseInt(wysihtml5.dom.getAttribute(start, "colspan"), 10) > 1
+ ) || (
+ wysihtml5.dom.getAttribute(start, "rowspan") &&
+ parseInt(wysihtml5.dom.getAttribute(start, "rowspan"), 10) > 1
+ ))
+ ) {
+ return [start];
+ }
+ }
+ return false;
+ }
+};
+;wysihtml5.commands.addTableCells = {
+ exec: function(composer, command, value) {
+ if (composer.tableSelection && composer.tableSelection.start && composer.tableSelection.end) {
+
+ // switches start and end if start is bigger than end (reverse selection)
+ var tableSelect = wysihtml5.dom.table.orderSelectionEnds(composer.tableSelection.start, composer.tableSelection.end);
+ if (value == "before" || value == "above") {
+ wysihtml5.dom.table.addCells(tableSelect.start, value);
+ } else if (value == "after" || value == "below") {
+ wysihtml5.dom.table.addCells(tableSelect.end, value);
+ }
+ setTimeout(function() {
+ composer.tableSelection.select(tableSelect.start, tableSelect.end);
+ },0);
+ }
+ },
+
+ state: function(composer, command) {
+ return false;
+ }
+};
+;wysihtml5.commands.deleteTableCells = {
+ exec: function(composer, command, value) {
+ if (composer.tableSelection && composer.tableSelection.start && composer.tableSelection.end) {
+ var tableSelect = wysihtml5.dom.table.orderSelectionEnds(composer.tableSelection.start, composer.tableSelection.end),
+ idx = wysihtml5.dom.table.indexOf(tableSelect.start),
+ selCell,
+ table = composer.tableSelection.table;
+
+ wysihtml5.dom.table.removeCells(tableSelect.start, value);
+ setTimeout(function() {
+ // move selection to next or previous if not present
+ selCell = wysihtml5.dom.table.findCell(table, idx);
+
+ if (!selCell){
+ if (value == "row") {
+ selCell = wysihtml5.dom.table.findCell(table, {
+ "row": idx.row - 1,
+ "col": idx.col
+ });
+ }
+
+ if (value == "column") {
+ selCell = wysihtml5.dom.table.findCell(table, {
+ "row": idx.row,
+ "col": idx.col - 1
+ });
+ }
+ }
+ if (selCell) {
+ composer.tableSelection.select(selCell, selCell);
+ }
+ }, 0);
+
+ }
+ },
+
+ state: function(composer, command) {
+ return false;
+ }
+};
+;wysihtml5.commands.indentList = {
+ exec: function(composer, command, value) {
+ var listEls = composer.selection.getSelectionParentsByTag('LI');
+ if (listEls) {
+ return this.tryToPushLiLevel(listEls, composer.selection);
+ }
+ return false;
+ },
+
+ state: function(composer, command) {
+ return false;
+ },
+
+ tryToPushLiLevel: function(liNodes, selection) {
+ var listTag, list, prevLi, liNode, prevLiList,
+ found = false;
+
+ selection.executeAndRestoreRangy(function() {
+
+ for (var i = liNodes.length; i--;) {
+ liNode = liNodes[i];
+ listTag = (liNode.parentNode.nodeName === 'OL') ? 'OL' : 'UL';
+ list = liNode.ownerDocument.createElement(listTag);
+ prevLi = wysihtml5.dom.domNode(liNode).prev({nodeTypes: [wysihtml5.ELEMENT_NODE]});
+ prevLiList = (prevLi) ? prevLi.querySelector('ul, ol') : null;
+
+ if (prevLi) {
+ if (prevLiList) {
+ prevLiList.appendChild(liNode);
+ } else {
+ list.appendChild(liNode);
+ prevLi.appendChild(list);
+ }
+ found = true;
+ }
+ }
+
+ });
+ return found;
+ }
+};
+;wysihtml5.commands.outdentList = {
+ exec: function(composer, command, value) {
+ var listEls = composer.selection.getSelectionParentsByTag('LI');
+ if (listEls) {
+ return this.tryToPullLiLevel(listEls, composer);
+ }
+ return false;
+ },
+
+ state: function(composer, command) {
+ return false;
+ },
+
+ tryToPullLiLevel: function(liNodes, composer) {
+ var listNode, outerListNode, outerLiNode, list, prevLi, liNode, afterList,
+ found = false,
+ that = this;
+
+ composer.selection.executeAndRestoreRangy(function() {
+
+ for (var i = liNodes.length; i--;) {
+ liNode = liNodes[i];
+ if (liNode.parentNode) {
+ listNode = liNode.parentNode;
+
+ if (listNode.tagName === 'OL' || listNode.tagName === 'UL') {
+ found = true;
+
+ outerListNode = wysihtml5.dom.getParentElement(listNode.parentNode, { nodeName: ['OL', 'UL']}, false, composer.element);
+ outerLiNode = wysihtml5.dom.getParentElement(listNode.parentNode, { nodeName: ['LI']}, false, composer.element);
+
+ if (outerListNode && outerLiNode) {
+
+ if (liNode.nextSibling) {
+ afterList = that.getAfterList(listNode, liNode);
+ liNode.appendChild(afterList);
+ }
+ outerListNode.insertBefore(liNode, outerLiNode.nextSibling);
+
+ } else {
+
+ if (liNode.nextSibling) {
+ afterList = that.getAfterList(listNode, liNode);
+ liNode.appendChild(afterList);
+ }
+
+ for (var j = liNode.childNodes.length; j--;) {
+ listNode.parentNode.insertBefore(liNode.childNodes[j], listNode.nextSibling);
+ }
+
+ listNode.parentNode.insertBefore(document.createElement('br'), listNode.nextSibling);
+ liNode.parentNode.removeChild(liNode);
+
+ }
+
+ // cleanup
+ if (listNode.childNodes.length === 0) {
+ listNode.parentNode.removeChild(listNode);
+ }
+ }
+ }
+ }
+
+ });
+ return found;
+ },
+
+ getAfterList: function(listNode, liNode) {
+ var nodeName = listNode.nodeName,
+ newList = document.createElement(nodeName);
+
+ while (liNode.nextSibling) {
+ newList.appendChild(liNode.nextSibling);
+ }
+ return newList;
+ }
+
+};;/**
+ * Undo Manager for wysihtml5
+ * slightly inspired by http://rniwa.com/editing/undomanager.html#the-undomanager-interface
+ */
+(function(wysihtml5) {
+ var Z_KEY = 90,
+ Y_KEY = 89,
+ BACKSPACE_KEY = 8,
+ DELETE_KEY = 46,
+ MAX_HISTORY_ENTRIES = 25,
+ DATA_ATTR_NODE = "data-wysihtml5-selection-node",
+ DATA_ATTR_OFFSET = "data-wysihtml5-selection-offset",
+ UNDO_HTML = '<span id="_wysihtml5-undo" class="_wysihtml5-temp">' + wysihtml5.INVISIBLE_SPACE + '</span>',
+ REDO_HTML = '<span id="_wysihtml5-redo" class="_wysihtml5-temp">' + wysihtml5.INVISIBLE_SPACE + '</span>',
+ dom = wysihtml5.dom;
+
+ function cleanTempElements(doc) {
+ var tempElement;
+ while (tempElement = doc.querySelector("._wysihtml5-temp")) {
+ tempElement.parentNode.removeChild(tempElement);
+ }
+ }
+
+ wysihtml5.UndoManager = wysihtml5.lang.Dispatcher.extend(
+ /** @scope wysihtml5.UndoManager.prototype */ {
+ constructor: function(editor) {
+ this.editor = editor;
+ this.composer = editor.composer;
+ this.element = this.composer.element;
+
+ this.position = 0;
+ this.historyStr = [];
+ this.historyDom = [];
+
+ this.transact();
+
+ this._observe();
+ },
+
+ _observe: function() {
+ var that = this,
+ doc = this.composer.sandbox.getDocument(),
+ lastKey;
+
+ // Catch CTRL+Z and CTRL+Y
+ dom.observe(this.element, "keydown", function(event) {
+ if (event.altKey || (!event.ctrlKey && !event.metaKey)) {
+ return;
+ }
+
+ var keyCode = event.keyCode,
+ isUndo = keyCode === Z_KEY && !event.shiftKey,
+ isRedo = (keyCode === Z_KEY && event.shiftKey) || (keyCode === Y_KEY);
+
+ if (isUndo) {
+ that.undo();
+ event.preventDefault();
+ } else if (isRedo) {
+ that.redo();
+ event.preventDefault();
+ }
+ });
+
+ // Catch delete and backspace
+ dom.observe(this.element, "keydown", function(event) {
+ var keyCode = event.keyCode;
+ if (keyCode === lastKey) {
+ return;
+ }
+
+ lastKey = keyCode;
+
+ if (keyCode === BACKSPACE_KEY || keyCode === DELETE_KEY) {
+ that.transact();
+ }
+ });
+
+ this.editor
+ .on("newword:composer", function() {
+ that.transact();
+ })
+
+ .on("beforecommand:composer", function() {
+ that.transact();
+ });
+ },
+
+ transact: function() {
+ var previousHtml = this.historyStr[this.position - 1],
+ currentHtml = this.composer.getValue(false, false),
+ composerIsVisible = this.element.offsetWidth > 0 && this.element.offsetHeight > 0,
+ range, node, offset, element, position;
+
+ if (currentHtml === previousHtml) {
+ return;
+ }
+
+ var length = this.historyStr.length = this.historyDom.length = this.position;
+ if (length > MAX_HISTORY_ENTRIES) {
+ this.historyStr.shift();
+ this.historyDom.shift();
+ this.position--;
+ }
+
+ this.position++;
+
+ if (composerIsVisible) {
+ // Do not start saving selection if composer is not visible
+ range = this.composer.selection.getRange();
+ node = (range && range.startContainer) ? range.startContainer : this.element;
+ offset = (range && range.startOffset) ? range.startOffset : 0;
+
+ if (node.nodeType === wysihtml5.ELEMENT_NODE) {
+ element = node;
+ } else {
+ element = node.parentNode;
+ position = this.getChildNodeIndex(element, node);
+ }
+
+ element.setAttribute(DATA_ATTR_OFFSET, offset);
+ if (typeof(position) !== "undefined") {
+ element.setAttribute(DATA_ATTR_NODE, position);
+ }
+ }
+
+ var clone = this.element.cloneNode(!!currentHtml);
+ this.historyDom.push(clone);
+ this.historyStr.push(currentHtml);
+
+ if (element) {
+ element.removeAttribute(DATA_ATTR_OFFSET);
+ element.removeAttribute(DATA_ATTR_NODE);
+ }
+
+ },
+
+ undo: function() {
+ this.transact();
+
+ if (!this.undoPossible()) {
+ return;
+ }
+
+ this.set(this.historyDom[--this.position - 1]);
+ this.editor.fire("undo:composer");
+ },
+
+ redo: function() {
+ if (!this.redoPossible()) {
+ return;
+ }
+
+ this.set(this.historyDom[++this.position - 1]);
+ this.editor.fire("redo:composer");
+ },
+
+ undoPossible: function() {
+ return this.position > 1;
+ },
+
+ redoPossible: function() {
+ return this.position < this.historyStr.length;
+ },
+
+ set: function(historyEntry) {
+ this.element.innerHTML = "";
+
+ var i = 0,
+ childNodes = historyEntry.childNodes,
+ length = historyEntry.childNodes.length;
+
+ for (; i<length; i++) {
+ this.element.appendChild(childNodes[i].cloneNode(true));
+ }
+
+ // Restore selection
+ var offset,
+ node,
+ position;
+
+ if (historyEntry.hasAttribute(DATA_ATTR_OFFSET)) {
+ offset = historyEntry.getAttribute(DATA_ATTR_OFFSET);
+ position = historyEntry.getAttribute(DATA_ATTR_NODE);
+ node = this.element;
+ } else {
+ node = this.element.querySelector("[" + DATA_ATTR_OFFSET + "]") || this.element;
+ offset = node.getAttribute(DATA_ATTR_OFFSET);
+ position = node.getAttribute(DATA_ATTR_NODE);
+ node.removeAttribute(DATA_ATTR_OFFSET);
+ node.removeAttribute(DATA_ATTR_NODE);
+ }
+
+ if (position !== null) {
+ node = this.getChildNodeByIndex(node, +position);
+ }
+
+ this.composer.selection.set(node, offset);
+ },
+
+ getChildNodeIndex: function(parent, child) {
+ var i = 0,
+ childNodes = parent.childNodes,
+ length = childNodes.length;
+ for (; i<length; i++) {
+ if (childNodes[i] === child) {
+ return i;
+ }
+ }
+ },
+
+ getChildNodeByIndex: function(parent, index) {
+ return parent.childNodes[index];
+ }
+ });
+})(wysihtml5);
+;/**
+ * TODO: the following methods still need unit test coverage
+ */
+wysihtml5.views.View = Base.extend(
+ /** @scope wysihtml5.views.View.prototype */ {
+ constructor: function(parent, textareaElement, config) {
+ this.parent = parent;
+ this.element = textareaElement;
+ this.config = config;
+ if (!this.config.noTextarea) {
+ this._observeViewChange();
+ }
+ },
+
+ _observeViewChange: function() {
+ var that = this;
+ this.parent.on("beforeload", function() {
+ that.parent.on("change_view", function(view) {
+ if (view === that.name) {
+ that.parent.currentView = that;
+ that.show();
+ // Using tiny delay here to make sure that the placeholder is set before focusing
+ setTimeout(function() { that.focus(); }, 0);
+ } else {
+ that.hide();
+ }
+ });
+ });
+ },
+
+ focus: function() {
+ if (this.element && this.element.ownerDocument && this.element.ownerDocument.querySelector(":focus") === this.element) {
+ return;
+ }
+
+ try { if(this.element) { this.element.focus(); } } catch(e) {}
+ },
+
+ hide: function() {
+ this.element.style.display = "none";
+ },
+
+ show: function() {
+ this.element.style.display = "";
+ },
+
+ disable: function() {
+ this.element.setAttribute("disabled", "disabled");
+ },
+
+ enable: function() {
+ this.element.removeAttribute("disabled");
+ }
+});
+;(function(wysihtml5) {
+ var dom = wysihtml5.dom,
+ browser = wysihtml5.browser;
+
+ wysihtml5.views.Composer = wysihtml5.views.View.extend(
+ /** @scope wysihtml5.views.Composer.prototype */ {
+ name: "composer",
+
+ // Needed for firefox in order to display a proper caret in an empty contentEditable
+ CARET_HACK: "<br>",
+
+ constructor: function(parent, editableElement, config) {
+ this.base(parent, editableElement, config);
+ if (!this.config.noTextarea) {
+ this.textarea = this.parent.textarea;
+ } else {
+ this.editableArea = editableElement;
+ }
+ if (this.config.contentEditableMode) {
+ this._initContentEditableArea();
+ } else {
+ this._initSandbox();
+ }
+ },
+
+ clear: function() {
+ this.element.innerHTML = browser.displaysCaretInEmptyContentEditableCorrectly() ? "" : this.CARET_HACK;
+ },
+
+ getValue: function(parse, clearInternals) {
+ var value = this.isEmpty() ? "" : wysihtml5.quirks.getCorrectInnerHTML(this.element);
+ if (parse !== false) {
+ value = this.parent.parse(value, (clearInternals === false) ? false : true);
+ }
+
+ return value;
+ },
+
+ setValue: function(html, parse) {
+ if (parse) {
+ html = this.parent.parse(html);
+ }
+
+ try {
+ this.element.innerHTML = html;
+ } catch (e) {
+ this.element.innerText = html;
+ }
+ },
+
+ cleanUp: function() {
+ this.parent.parse(this.element);
+ },
+
+ show: function() {
+ this.editableArea.style.display = this._displayStyle || "";
+
+ if (!this.config.noTextarea && !this.textarea.element.disabled) {
+ // Firefox needs this, otherwise contentEditable becomes uneditable
+ this.disable();
+ this.enable();
+ }
+ },
+
+ hide: function() {
+ this._displayStyle = dom.getStyle("display").from(this.editableArea);
+ if (this._displayStyle === "none") {
+ this._displayStyle = null;
+ }
+ this.editableArea.style.display = "none";
+ },
+
+ disable: function() {
+ this.parent.fire("disable:composer");
+ this.element.removeAttribute("contentEditable");
+ },
+
+ enable: function() {
+ this.parent.fire("enable:composer");
+ this.element.setAttribute("contentEditable", "true");
+ },
+
+ focus: function(setToEnd) {
+ // IE 8 fires the focus event after .focus()
+ // This is needed by our simulate_placeholder.js to work
+ // therefore we clear it ourselves this time
+ if (wysihtml5.browser.doesAsyncFocus() && this.hasPlaceholderSet()) {
+ this.clear();
+ }
+
+ this.base();
+
+ var lastChild = this.element.lastChild;
+ if (setToEnd && lastChild && this.selection) {
+ if (lastChild.nodeName === "BR") {
+ this.selection.setBefore(this.element.lastChild);
+ } else {
+ this.selection.setAfter(this.element.lastChild);
+ }
+ }
+ },
+
+ getTextContent: function() {
+ return dom.getTextContent(this.element);
+ },
+
+ hasPlaceholderSet: function() {
+ return this.getTextContent() == ((this.config.noTextarea) ? this.editableArea.getAttribute("data-placeholder") : this.textarea.element.getAttribute("placeholder")) && this.placeholderSet;
+ },
+
+ isEmpty: function() {
+ var innerHTML = this.element.innerHTML.toLowerCase();
+ return (/^(\s|<br>|<\/br>|<p>|<\/p>)*$/i).test(innerHTML) ||
+ innerHTML === "" ||
+ innerHTML === "<br>" ||
+ innerHTML === "<p></p>" ||
+ innerHTML === "<p><br></p>" ||
+ this.hasPlaceholderSet();
+ },
+
+ _initContentEditableArea: function() {
+ var that = this;
+
+ if (this.config.noTextarea) {
+ this.sandbox = new dom.ContentEditableArea(function() {
+ that._create();
+ }, {}, this.editableArea);
+ } else {
+ this.sandbox = new dom.ContentEditableArea(function() {
+ that._create();
+ });
+ this.editableArea = this.sandbox.getContentEditable();
+ dom.insert(this.editableArea).after(this.textarea.element);
+ this._createWysiwygFormField();
+ }
+ },
+
+ _initSandbox: function() {
+ var that = this;
+
+ this.sandbox = new dom.Sandbox(function() {
+ that._create();
+ }, {
+ stylesheets: this.config.stylesheets
+ });
+ this.editableArea = this.sandbox.getIframe();
+
+ var textareaElement = this.textarea.element;
+ dom.insert(this.editableArea).after(textareaElement);
+
+ this._createWysiwygFormField();
+ },
+
+ // Creates hidden field which tells the server after submit, that the user used an wysiwyg editor
+ _createWysiwygFormField: function() {
+ if (this.textarea.element.form) {
+ var hiddenField = document.createElement("input");
+ hiddenField.type = "hidden";
+ hiddenField.name = "_wysihtml5_mode";
+ hiddenField.value = 1;
+ dom.insert(hiddenField).after(this.textarea.element);
+ }
+ },
+
+ _create: function() {
+ var that = this;
+ this.doc = this.sandbox.getDocument();
+ this.element = (this.config.contentEditableMode) ? this.sandbox.getContentEditable() : this.doc.body;
+ if (!this.config.noTextarea) {
+ this.textarea = this.parent.textarea;
+ this.element.innerHTML = this.textarea.getValue(true, false);
+ } else {
+ this.cleanUp(); // cleans contenteditable on initiation as it may contain html
+ }
+
+ // Make sure our selection handler is ready
+ this.selection = new wysihtml5.Selection(this.parent, this.element, this.config.uneditableContainerClassname);
+
+ // Make sure commands dispatcher is ready
+ this.commands = new wysihtml5.Commands(this.parent);
+
+ if (!this.config.noTextarea) {
+ dom.copyAttributes([
+ "className", "spellcheck", "title", "lang", "dir", "accessKey"
+ ]).from(this.textarea.element).to(this.element);
+ }
+
+ dom.addClass(this.element, this.config.composerClassName);
+ //
+ // Make the editor look like the original textarea, by syncing styles
+ if (this.config.style && !this.config.contentEditableMode) {
+ this.style();
+ }
+
+ this.observe();
+
+ var name = this.config.name;
+ if (name) {
+ dom.addClass(this.element, name);
+ if (!this.config.contentEditableMode) { dom.addClass(this.editableArea, name); }
+ }
+
+ this.enable();
+
+ if (!this.config.noTextarea && this.textarea.element.disabled) {
+ this.disable();
+ }
+
+ // Simulate html5 placeholder attribute on contentEditable element
+ var placeholderText = typeof(this.config.placeholder) === "string"
+ ? this.config.placeholder
+ : ((this.config.noTextarea) ? this.editableArea.getAttribute("data-placeholder") : this.textarea.element.getAttribute("placeholder"));
+ if (placeholderText) {
+ dom.simulatePlaceholder(this.parent, this, placeholderText);
+ }
+
+ // Make sure that the browser avoids using inline styles whenever possible
+ this.commands.exec("styleWithCSS", false);
+
+ this._initAutoLinking();
+ this._initObjectResizing();
+ this._initUndoManager();
+ this._initLineBreaking();
+
+ // Simulate html5 autofocus on contentEditable element
+ // This doesn't work on IOS (5.1.1)
+ if (!this.config.noTextarea && (this.textarea.element.hasAttribute("autofocus") || document.querySelector(":focus") == this.textarea.element) && !browser.isIos()) {
+ setTimeout(function() { that.focus(true); }, 100);
+ }
+
+ // IE sometimes leaves a single paragraph, which can't be removed by the user
+ if (!browser.clearsContentEditableCorrectly()) {
+ wysihtml5.quirks.ensureProperClearing(this);
+ }
+
+ // Set up a sync that makes sure that textarea and editor have the same content
+ if (this.initSync && this.config.sync) {
+ this.initSync();
+ }
+
+ // Okay hide the textarea, we are ready to go
+ if (!this.config.noTextarea) { this.textarea.hide(); }
+
+ // Fire global (before-)load event
+ this.parent.fire("beforeload").fire("load");
+ },
+
+ _initAutoLinking: function() {
+ var that = this,
+ supportsDisablingOfAutoLinking = browser.canDisableAutoLinking(),
+ supportsAutoLinking = browser.doesAutoLinkingInContentEditable();
+ if (supportsDisablingOfAutoLinking) {
+ this.commands.exec("autoUrlDetect", false);
+ }
+
+ if (!this.config.autoLink) {
+ return;
+ }
+
+ // Only do the auto linking by ourselves when the browser doesn't support auto linking
+ // OR when he supports auto linking but we were able to turn it off (IE9+)
+ if (!supportsAutoLinking || (supportsAutoLinking && supportsDisablingOfAutoLinking)) {
+ this.parent.on("newword:composer", function() {
+ if (dom.getTextContent(that.element).match(dom.autoLink.URL_REG_EXP)) {
+ var nodeWithSelection = that.selection.getSelectedNode(),
+ uneditables = that.element.querySelectorAll("." + that.config.uneditableContainerClassname),
+ isInUneditable = false;
+
+ for (var i = uneditables.length; i--;) {
+ if (wysihtml5.dom.contains(uneditables[i], nodeWithSelection)) {
+ isInUneditable = true;
+ }
+ }
+
+ if (!isInUneditable) dom.autoLink(nodeWithSelection, [that.config.uneditableContainerClassname]);
+ }
+ });
+
+ dom.observe(this.element, "blur", function() {
+ dom.autoLink(that.element, [that.config.uneditableContainerClassname]);
+ });
+ }
+
+ // Assuming we have the following:
+ // <a href="http://www.google.de">http://www.google.de</a>
+ // If a user now changes the url in the innerHTML we want to make sure that
+ // it's synchronized with the href attribute (as long as the innerHTML is still a url)
+ var // Use a live NodeList to check whether there are any links in the document
+ links = this.sandbox.getDocument().getElementsByTagName("a"),
+ // The autoLink helper method reveals a reg exp to detect correct urls
+ urlRegExp = dom.autoLink.URL_REG_EXP,
+ getTextContent = function(element) {
+ var textContent = wysihtml5.lang.string(dom.getTextContent(element)).trim();
+ if (textContent.substr(0, 4) === "www.") {
+ textContent = "http://" + textContent;
+ }
+ return textContent;
+ };
+
+ dom.observe(this.element, "keydown", function(event) {
+ if (!links.length) {
+ return;
+ }
+
+ var selectedNode = that.selection.getSelectedNode(event.target.ownerDocument),
+ link = dom.getParentElement(selectedNode, { nodeName: "A" }, 4),
+ textContent;
+
+ if (!link) {
+ return;
+ }
+
+ textContent = getTextContent(link);
+ // keydown is fired before the actual content is changed
+ // therefore we set a timeout to change the href
+ setTimeout(function() {
+ var newTextContent = getTextContent(link);
+ if (newTextContent === textContent) {
+ return;
+ }
+
+ // Only set href when new href looks like a valid url
+ if (newTextContent.match(urlRegExp)) {
+ link.setAttribute("href", newTextContent);
+ }
+ }, 0);
+ });
+ },
+
+ _initObjectResizing: function() {
+ this.commands.exec("enableObjectResizing", true);
+
+ // IE sets inline styles after resizing objects
+ // The following lines make sure that the width/height css properties
+ // are copied over to the width/height attributes
+ if (browser.supportsEvent("resizeend")) {
+ var properties = ["width", "height"],
+ propertiesLength = properties.length,
+ element = this.element;
+
+ dom.observe(element, "resizeend", function(event) {
+ var target = event.target || event.srcElement,
+ style = target.style,
+ i = 0,
+ property;
+
+ if (target.nodeName !== "IMG") {
+ return;
+ }
+
+ for (; i<propertiesLength; i++) {
+ property = properties[i];
+ if (style[property]) {
+ target.setAttribute(property, parseInt(style[property], 10));
+ style[property] = "";
+ }
+ }
+
+ // After resizing IE sometimes forgets to remove the old resize handles
+ wysihtml5.quirks.redraw(element);
+ });
+ }
+ },
+
+ _initUndoManager: function() {
+ this.undoManager = new wysihtml5.UndoManager(this.parent);
+ },
+
+ _initLineBreaking: function() {
+ var that = this,
+ USE_NATIVE_LINE_BREAK_INSIDE_TAGS = ["LI", "P", "H1", "H2", "H3", "H4", "H5", "H6"],
+ LIST_TAGS = ["UL", "OL", "MENU"];
+
+ function adjust(selectedNode) {
+ var parentElement = dom.getParentElement(selectedNode, { nodeName: ["P", "DIV"] }, 2);
+ if (parentElement && dom.contains(that.element, parentElement)) {
+ that.selection.executeAndRestore(function() {
+ if (that.config.useLineBreaks) {
+ dom.replaceWithChildNodes(parentElement);
+ } else if (parentElement.nodeName !== "P") {
+ dom.renameElement(parentElement, "p");
+ }
+ });
+ }
+ }
+
+ if (!this.config.useLineBreaks) {
+ dom.observe(this.element, ["focus", "keydown"], function() {
+ if (that.isEmpty()) {
+ var paragraph = that.doc.createElement("P");
+ that.element.innerHTML = "";
+ that.element.appendChild(paragraph);
+ if (!browser.displaysCaretInEmptyContentEditableCorrectly()) {
+ paragraph.innerHTML = "<br>";
+ that.selection.setBefore(paragraph.firstChild);
+ } else {
+ that.selection.selectNode(paragraph, true);
+ }
+ }
+ });
+ }
+
+ // Under certain circumstances Chrome + Safari create nested <p> or <hX> tags after paste
+ // Inserting an invisible white space in front of it fixes the issue
+ // This is too hacky and causes selection not to replace content on paste in chrome
+ /* if (browser.createsNestedInvalidMarkupAfterPaste()) {
+ dom.observe(this.element, "paste", function(event) {
+ var invisibleSpace = that.doc.createTextNode(wysihtml5.INVISIBLE_SPACE);
+ that.selection.insertNode(invisibleSpace);
+ });
+ }*/
+
+
+ dom.observe(this.element, "keydown", function(event) {
+ var keyCode = event.keyCode;
+
+ if (event.shiftKey) {
+ return;
+ }
+
+ if (keyCode !== wysihtml5.ENTER_KEY && keyCode !== wysihtml5.BACKSPACE_KEY) {
+ return;
+ }
+ var blockElement = dom.getParentElement(that.selection.getSelectedNode(), { nodeName: USE_NATIVE_LINE_BREAK_INSIDE_TAGS }, 4);
+ if (blockElement) {
+ setTimeout(function() {
+ // Unwrap paragraph after leaving a list or a H1-6
+ var selectedNode = that.selection.getSelectedNode(),
+ list;
+
+ if (blockElement.nodeName === "LI") {
+ if (!selectedNode) {
+ return;
+ }
+
+ list = dom.getParentElement(selectedNode, { nodeName: LIST_TAGS }, 2);
+
+ if (!list) {
+ adjust(selectedNode);
+ }
+ }
+
+ if (keyCode === wysihtml5.ENTER_KEY && blockElement.nodeName.match(/^H[1-6]$/)) {
+ adjust(selectedNode);
+ }
+ }, 0);
+ return;
+ }
+
+ if (that.config.useLineBreaks && keyCode === wysihtml5.ENTER_KEY && !wysihtml5.browser.insertsLineBreaksOnReturn()) {
+ event.preventDefault();
+ that.commands.exec("insertLineBreak");
+
+ }
+ });
+ }
+ });
+})(wysihtml5);
+;(function(wysihtml5) {
+ var dom = wysihtml5.dom,
+ doc = document,
+ win = window,
+ HOST_TEMPLATE = doc.createElement("div"),
+ /**
+ * Styles to copy from textarea to the composer element
+ */
+ TEXT_FORMATTING = [
+ "background-color",
+ "color", "cursor",
+ "font-family", "font-size", "font-style", "font-variant", "font-weight",
+ "line-height", "letter-spacing",
+ "text-align", "text-decoration", "text-indent", "text-rendering",
+ "word-break", "word-wrap", "word-spacing"
+ ],
+ /**
+ * Styles to copy from textarea to the iframe
+ */
+ BOX_FORMATTING = [
+ "background-color",
+ "border-collapse",
+ "border-bottom-color", "border-bottom-style", "border-bottom-width",
+ "border-left-color", "border-left-style", "border-left-width",
+ "border-right-color", "border-right-style", "border-right-width",
+ "border-top-color", "border-top-style", "border-top-width",
+ "clear", "display", "float",
+ "margin-bottom", "margin-left", "margin-right", "margin-top",
+ "outline-color", "outline-offset", "outline-width", "outline-style",
+ "padding-left", "padding-right", "padding-top", "padding-bottom",
+ "position", "top", "left", "right", "bottom", "z-index",
+ "vertical-align", "text-align",
+ "-webkit-box-sizing", "-moz-box-sizing", "-ms-box-sizing", "box-sizing",
+ "-webkit-box-shadow", "-moz-box-shadow", "-ms-box-shadow","box-shadow",
+ "-webkit-border-top-right-radius", "-moz-border-radius-topright", "border-top-right-radius",
+ "-webkit-border-bottom-right-radius", "-moz-border-radius-bottomright", "border-bottom-right-radius",
+ "-webkit-border-bottom-left-radius", "-moz-border-radius-bottomleft", "border-bottom-left-radius",
+ "-webkit-border-top-left-radius", "-moz-border-radius-topleft", "border-top-left-radius",
+ "width", "height"
+ ],
+ ADDITIONAL_CSS_RULES = [
+ "html { height: 100%; }",
+ "body { height: 100%; padding: 1px 0 0 0; margin: -1px 0 0 0; }",
+ "body > p:first-child { margin-top: 0; }",
+ "._wysihtml5-temp { display: none; }",
+ wysihtml5.browser.isGecko ?
+ "body.placeholder { color: graytext !important; }" :
+ "body.placeholder { color: #a9a9a9 !important; }",
+ // Ensure that user see's broken images and can delete them
+ "img:-moz-broken { -moz-force-broken-image-icon: 1; height: 24px; width: 24px; }"
+ ];
+
+ /**
+ * With "setActive" IE offers a smart way of focusing elements without scrolling them into view:
+ * http://msdn.microsoft.com/en-us/library/ms536738(v=vs.85).aspx
+ *
+ * Other browsers need a more hacky way: (pssst don't tell my mama)
+ * In order to prevent the element being scrolled into view when focusing it, we simply
+ * move it out of the scrollable area, focus it, and reset it's position
+ */
+ var focusWithoutScrolling = function(element) {
+ if (element.setActive) {
+ // Following line could cause a js error when the textarea is invisible
+ // See https://github.com/xing/wysihtml5/issues/9
+ try { element.setActive(); } catch(e) {}
+ } else {
+ var elementStyle = element.style,
+ originalScrollTop = doc.documentElement.scrollTop || doc.body.scrollTop,
+ originalScrollLeft = doc.documentElement.scrollLeft || doc.body.scrollLeft,
+ originalStyles = {
+ position: elementStyle.position,
+ top: elementStyle.top,
+ left: elementStyle.left,
+ WebkitUserSelect: elementStyle.WebkitUserSelect
+ };
+
+ dom.setStyles({
+ position: "absolute",
+ top: "-99999px",
+ left: "-99999px",
+ // Don't ask why but temporarily setting -webkit-user-select to none makes the whole thing performing smoother
+ WebkitUserSelect: "none"
+ }).on(element);
+
+ element.focus();
+
+ dom.setStyles(originalStyles).on(element);
+
+ if (win.scrollTo) {
+ // Some browser extensions unset this method to prevent annoyances
+ // "Better PopUp Blocker" for Chrome http://code.google.com/p/betterpopupblocker/source/browse/trunk/blockStart.js#100
+ // Issue: http://code.google.com/p/betterpopupblocker/issues/detail?id=1
+ win.scrollTo(originalScrollLeft, originalScrollTop);
+ }
+ }
+ };
+
+
+ wysihtml5.views.Composer.prototype.style = function() {
+ var that = this,
+ originalActiveElement = doc.querySelector(":focus"),
+ textareaElement = this.textarea.element,
+ hasPlaceholder = textareaElement.hasAttribute("placeholder"),
+ originalPlaceholder = hasPlaceholder && textareaElement.getAttribute("placeholder"),
+ originalDisplayValue = textareaElement.style.display,
+ originalDisabled = textareaElement.disabled,
+ displayValueForCopying;
+
+ this.focusStylesHost = HOST_TEMPLATE.cloneNode(false);
+ this.blurStylesHost = HOST_TEMPLATE.cloneNode(false);
+ this.disabledStylesHost = HOST_TEMPLATE.cloneNode(false);
+
+ // Remove placeholder before copying (as the placeholder has an affect on the computed style)
+ if (hasPlaceholder) {
+ textareaElement.removeAttribute("placeholder");
+ }
+
+ if (textareaElement === originalActiveElement) {
+ textareaElement.blur();
+ }
+
+ // enable for copying styles
+ textareaElement.disabled = false;
+
+ // set textarea to display="none" to get cascaded styles via getComputedStyle
+ textareaElement.style.display = displayValueForCopying = "none";
+
+ if ((textareaElement.getAttribute("rows") && dom.getStyle("height").from(textareaElement) === "auto") ||
+ (textareaElement.getAttribute("cols") && dom.getStyle("width").from(textareaElement) === "auto")) {
+ textareaElement.style.display = displayValueForCopying = originalDisplayValue;
+ }
+
+ // --------- iframe styles (has to be set before editor styles, otherwise IE9 sets wrong fontFamily on blurStylesHost) ---------
+ dom.copyStyles(BOX_FORMATTING).from(textareaElement).to(this.editableArea).andTo(this.blurStylesHost);
+
+ // --------- editor styles ---------
+ dom.copyStyles(TEXT_FORMATTING).from(textareaElement).to(this.element).andTo(this.blurStylesHost);
+
+ // --------- apply standard rules ---------
+ dom.insertCSS(ADDITIONAL_CSS_RULES).into(this.element.ownerDocument);
+
+ // --------- :disabled styles ---------
+ textareaElement.disabled = true;
+ dom.copyStyles(BOX_FORMATTING).from(textareaElement).to(this.disabledStylesHost);
+ dom.copyStyles(TEXT_FORMATTING).from(textareaElement).to(this.disabledStylesHost);
+ textareaElement.disabled = originalDisabled;
+
+ // --------- :focus styles ---------
+ textareaElement.style.display = originalDisplayValue;
+ focusWithoutScrolling(textareaElement);
+ textareaElement.style.display = displayValueForCopying;
+
+ dom.copyStyles(BOX_FORMATTING).from(textareaElement).to(this.focusStylesHost);
+ dom.copyStyles(TEXT_FORMATTING).from(textareaElement).to(this.focusStylesHost);
+
+ // reset textarea
+ textareaElement.style.display = originalDisplayValue;
+
+ dom.copyStyles(["display"]).from(textareaElement).to(this.editableArea);
+
+ // Make sure that we don't change the display style of the iframe when copying styles oblur/onfocus
+ // this is needed for when the change_view event is fired where the iframe is hidden and then
+ // the blur event fires and re-displays it
+ var boxFormattingStyles = wysihtml5.lang.array(BOX_FORMATTING).without(["display"]);
+
+ // --------- restore focus ---------
+ if (originalActiveElement) {
+ originalActiveElement.focus();
+ } else {
+ textareaElement.blur();
+ }
+
+ // --------- restore placeholder ---------
+ if (hasPlaceholder) {
+ textareaElement.setAttribute("placeholder", originalPlaceholder);
+ }
+
+ // --------- Sync focus/blur styles ---------
+ this.parent.on("focus:composer", function() {
+ dom.copyStyles(boxFormattingStyles) .from(that.focusStylesHost).to(that.editableArea);
+ dom.copyStyles(TEXT_FORMATTING) .from(that.focusStylesHost).to(that.element);
+ });
+
+ this.parent.on("blur:composer", function() {
+ dom.copyStyles(boxFormattingStyles) .from(that.blurStylesHost).to(that.editableArea);
+ dom.copyStyles(TEXT_FORMATTING) .from(that.blurStylesHost).to(that.element);
+ });
+
+ this.parent.observe("disable:composer", function() {
+ dom.copyStyles(boxFormattingStyles) .from(that.disabledStylesHost).to(that.editableArea);
+ dom.copyStyles(TEXT_FORMATTING) .from(that.disabledStylesHost).to(that.element);
+ });
+
+ this.parent.observe("enable:composer", function() {
+ dom.copyStyles(boxFormattingStyles) .from(that.blurStylesHost).to(that.editableArea);
+ dom.copyStyles(TEXT_FORMATTING) .from(that.blurStylesHost).to(that.element);
+ });
+
+ return this;
+ };
+})(wysihtml5);
+;/**
+ * Taking care of events
+ * - Simulating 'change' event on contentEditable element
+ * - Handling drag & drop logic
+ * - Catch paste events
+ * - Dispatch proprietary newword:composer event
+ * - Keyboard shortcuts
+ */
+(function(wysihtml5) {
+ var dom = wysihtml5.dom,
+ browser = wysihtml5.browser,
+ /**
+ * Map keyCodes to query commands
+ */
+ shortcuts = {
+ "66": "bold", // B
+ "73": "italic", // I
+ "85": "underline" // U
+ };
+
+ // Adds multiple eventlisteners to target, bound to one callback
+ // TODO: If needed elsewhere make it part of wysihtml5.dom or sth
+ var addListeners = function (target, events, callback) {
+ for(var i = 0, max = events.length; i < max; i++) {
+ target.addEventListener(events[i], callback, false);
+ }
+ };
+
+ // Removes multiple eventlisteners from target, bound to one callback
+ // TODO: If needed elsewhere make it part of wysihtml5.dom or sth
+ var removeListeners = function (target, events, callback) {
+ for(var i = 0, max = events.length; i < max; i++) {
+ target.removeEventListener(events[i], callback, false);
+ }
+ };
+
+ var deleteAroundEditable = function(selection, uneditable, element) {
+ // merge node with previous node from uneditable
+ var prevNode = selection.getPreviousNode(uneditable, true),
+ curNode = selection.getSelectedNode();
+
+ if (curNode.nodeType !== 1 && curNode.parentNode !== element) { curNode = curNode.parentNode; }
+ if (prevNode) {
+ if (curNode.nodeType == 1) {
+ var first = curNode.firstChild;
+
+ if (prevNode.nodeType == 1) {
+ while (curNode.firstChild) {
+ prevNode.appendChild(curNode.firstChild);
+ }
+ } else {
+ while (curNode.firstChild) {
+ uneditable.parentNode.insertBefore(curNode.firstChild, uneditable);
+ }
+ }
+ if (curNode.parentNode) {
+ curNode.parentNode.removeChild(curNode);
+ }
+ selection.setBefore(first);
+ } else {
+ if (prevNode.nodeType == 1) {
+ prevNode.appendChild(curNode);
+ } else {
+ uneditable.parentNode.insertBefore(curNode, uneditable);
+ }
+ selection.setBefore(curNode);
+ }
+ }
+ };
+
+ var handleDeleteKeyPress = function(event, composer) {
+ var selection = composer.selection,
+ element = composer.element;
+
+ if (selection.isCollapsed()) {
+ if (selection.caretIsInTheBeginnig('LI')) {
+ event.preventDefault();
+ composer.commands.exec('outdentList');
+ } else if (selection.caretIsInTheBeginnig()) {
+ event.preventDefault();
+ } else {
+
+ if (selection.caretIsFirstInSelection() &&
+ selection.getPreviousNode() &&
+ selection.getPreviousNode().nodeName &&
+ (/^H\d$/gi).test(selection.getPreviousNode().nodeName)
+ ) {
+ var prevNode = selection.getPreviousNode();
+ event.preventDefault();
+ if ((/^\s*$/).test(prevNode.textContent || prevNode.innerText)) {
+ // heading is empty
+ prevNode.parentNode.removeChild(prevNode);
+ } else {
+ var range = prevNode.ownerDocument.createRange();
+ range.selectNodeContents(prevNode);
+ range.collapse(false);
+ selection.setSelection(range);
+ }
+ }
+
+ var beforeUneditable = selection.caretIsBeforeUneditable();
+ // Do a special delete if caret would delete uneditable
+ if (beforeUneditable) {
+ event.preventDefault();
+ // If customevents present notify element of being deleted
+ // TODO: Investigate if browser support can be extended
+ try {
+ var ev = new CustomEvent("wysihtml5:uneditable:delete");
+ beforeUneditable.dispatchEvent(ev);
+ } catch (err) {}
+ beforeUneditable.parentNode.removeChild(beforeUneditable);
+ }
+ }
+ } else {
+ if (selection.containsUneditable()) {
+ event.preventDefault();
+ selection.deleteContents();
+ }
+ }
+ };
+
+ var handleTabKeyDown = function(composer, element) {
+ if (!composer.selection.isCollapsed()) {
+ composer.selection.deleteContents();
+ } else if (composer.selection.caretIsInTheBeginnig('LI')) {
+ if (composer.commands.exec('indentList')) return;
+ }
+
+ // Is   close enough to tab. Could not find enough counter arguments for now.
+ composer.commands.exec("insertHTML", " ");
+ };
+
+ var handleDomNodeRemoved = function(event) {
+ if (this.domNodeRemovedInterval) {
+ clearInterval(domNodeRemovedInterval);
+ }
+ this.parent.fire("destroy:composer");
+ };
+
+ // Listens to "drop", "paste", "mouseup", "focus", "keyup" events and fires
+ var handleUserInteraction = function (event) {
+ this.parent.fire("beforeinteraction").fire("beforeinteraction:composer");
+ setTimeout((function() {
+ this.parent.fire("interaction").fire("interaction:composer");
+ }).bind(this), 0);
+ };
+
+ var handleFocus = function(event) {
+ this.parent.fire("focus", event).fire("focus:composer", event);
+
+ // Delay storing of state until all focus handler are fired
+ // especially the one which resets the placeholder
+ setTimeout((function() {
+ this.focusState = this.getValue(false, false);
+ }).bind(this), 0);
+ };
+
+ var handleBlur = function(event) {
+ if (this.focusState !== this.getValue(false, false)) {
+ //create change event if supported (all except IE8)
+ var changeevent = event;
+ if(typeof Object.create == 'function') {
+ changeevent = Object.create(event, { type: { value: 'change' } });
+ }
+ this.parent.fire("change", changeevent).fire("change:composer", changeevent);
+ }
+ this.parent.fire("blur", event).fire("blur:composer", event);
+ };
+
+ var handlePaste = function(event) {
+ this.parent.fire(event.type, event).fire(event.type + ":composer", event);
+ if (event.type === "paste") {
+ setTimeout((function() {
+ this.parent.fire("newword:composer");
+ }).bind(this), 0);
+ }
+ };
+
+ var handleCopy = function(event) {
+ if (this.config.copyedFromMarking) {
+ // If supported the copied source can be based directly on selection
+ // Very useful for webkit based browsers where copy will otherwise contain a lot of code and styles based on whatever and not actually in selection.
+ if (event.clipboardData) {
+ event.clipboardData.setData("text/html", this.config.copyedFromMarking + this.selection.getHtml());
+ event.clipboardData.setData("text/plain", this.selection.getPlainText());
+ event.preventDefault();
+ }
+ this.parent.fire(event.type, event).fire(event.type + ":composer", event);
+ }
+ };
+
+ var handleKeyUp = function(event) {
+ var keyCode = event.keyCode;
+ if (keyCode === wysihtml5.SPACE_KEY || keyCode === wysihtml5.ENTER_KEY) {
+ this.parent.fire("newword:composer");
+ }
+ };
+
+ var handleMouseDown = function(event) {
+ if (!browser.canSelectImagesInContentEditable()) {
+ // Make sure that images are selected when clicking on them
+ var target = event.target,
+ allImages = this.element.querySelectorAll('img'),
+ notMyImages = this.element.querySelectorAll('.' + this.config.uneditableContainerClassname + ' img'),
+ myImages = wysihtml5.lang.array(allImages).without(notMyImages);
+
+ if (target.nodeName === "IMG" && wysihtml5.lang.array(myImages).contains(target)) {
+ this.selection.selectNode(target);
+ }
+ }
+ };
+
+ // TODO: mouseover is not actually a foolproof and obvious place for this, must be changed as it modifies dom on random basis
+ // Shows url in tooltip when hovering links or images
+ var handleMouseOver = function(event) {
+ var titlePrefixes = {
+ IMG: "Image: ",
+ A: "Link: "
+ },
+ target = event.target,
+ nodeName = target.nodeName,
+ title;
+
+ if (nodeName !== "A" && nodeName !== "IMG") {
+ return;
+ }
+ if(!target.hasAttribute("title")){
+ title = titlePrefixes[nodeName] + (target.getAttribute("href") || target.getAttribute("src"));
+ target.setAttribute("title", title);
+ }
+ };
+
+ var handleClick = function(event) {
+ if (this.config.uneditableContainerClassname) {
+ // If uneditables is configured, makes clicking on uneditable move caret after clicked element (so it can be deleted like text)
+ // If uneditable needs text selection itself event.stopPropagation can be used to prevent this behaviour
+ var uneditable = wysihtml5.dom.getParentElement(event.target, { className: this.config.uneditableContainerClassname }, false, this.element);
+ if (uneditable) {
+ this.selection.setAfter(uneditable);
+ }
+ }
+ };
+
+ var handleDrop = function(event) {
+ if (!browser.canSelectImagesInContentEditable()) {
+ // TODO: if I knew how to get dropped elements list from event I could limit it to only IMG element case
+ setTimeout((function() {
+ this.selection.getSelection().removeAllRanges();
+ }).bind(this), 0);
+ }
+ };
+
+ var handleKeyDown = function(event) {
+ var keyCode = event.keyCode,
+ command = shortcuts[keyCode],
+ target, parent;
+
+ // Shortcut logic
+ if ((event.ctrlKey || event.metaKey) && !event.altKey && command) {
+ this.commands.exec(command);
+ event.preventDefault();
+ }
+
+ if (keyCode === wysihtml5.BACKSPACE_KEY) {
+ // Delete key override for special cases
+ handleDeleteKeyPress(event, this);
+ }
+
+ // Make sure that when pressing backspace/delete on selected images deletes the image and it's anchor
+ if (keyCode === wysihtml5.BACKSPACE_KEY || keyCode === wysihtml5.DELETE_KEY) {
+ target = this.selection.getSelectedNode(true);
+ if (target && target.nodeName === "IMG") {
+ event.preventDefault();
+ parent = target.parentNode;
+ parent.removeChild(target);// delete the <img>
+ // And it's parent <a> too if it hasn't got any other child nodes
+ if (parent.nodeName === "A" && !parent.firstChild) {
+ parent.parentNode.removeChild(parent);
+ }
+ setTimeout(function() {
+ wysihtml5.quirks.redraw(element);
+ }, 0);
+ }
+ }
+
+ if (this.config.handleTabKey && keyCode === wysihtml5.TAB_KEY) {
+ // TAB key handling
+ event.preventDefault();
+ handleTabKeyDown(this, element);
+ }
+
+ };
+
+ var handleIframeFocus = function(event) {
+ setTimeout((function() {
+ if (this.doc.querySelector(":focus") !== this.element) {
+ this.focus();
+ }
+ }).bind(this), 0);
+ };
+
+ var handleIframeBlur = function(event) {
+ setTimeout((function() {
+ this.selection.getSelection().removeAllRanges();
+ }).bind(this), 0);
+ };
+
+ // Table management
+ // If present enableObjectResizing and enableInlineTableEditing command should be called with false to prevent native table handlers
+ var initTableHandling = function () {
+ var hideHandlers = function () {
+ this.doc.execCommand("enableObjectResizing", false, "false");
+ this.doc.execCommand("enableInlineTableEditing", false, "false");
+ },
+ iframeInitiator = (function() {
+ hideHandlers.call(this);
+ removeListeners(this.sandbox.getIframe(), ["focus", "mouseup", "mouseover"], iframeInitiator);
+ }).bind(this);
+
+ if( this.doc.execCommand &&
+ wysihtml5.browser.supportsCommand(this.doc, "enableObjectResizing") &&
+ wysihtml5.browser.supportsCommand(this.doc, "enableInlineTableEditing"))
+ {
+ if (this.sandbox.getIframe) {
+ addListeners(this.sandbox.getIframe(), ["focus", "mouseup", "mouseover"], iframeInitiator);
+ } else {
+ setTimeout((function() {
+ hideHandlers.call(this);
+ }).bind(this), 0);
+ }
+ }
+ this.tableSelection = wysihtml5.quirks.tableCellsSelection(this.element, this.parent);
+ };
+
+ wysihtml5.views.Composer.prototype.observe = function() {
+ var that = this,
+ container = (this.sandbox.getIframe) ? this.sandbox.getIframe() : this.sandbox.getContentEditable(),
+ element = this.element,
+ focusBlurElement = (browser.supportsEventsInIframeCorrectly() || this.sandbox.getContentEditable) ? this.element : this.sandbox.getWindow();
+
+ this.focusState = this.getValue(false, false);
+
+ // --------- destroy:composer event ---------
+ container.addEventListener(["DOMNodeRemoved"], handleDomNodeRemoved.bind(this), false);
+
+ // DOMNodeRemoved event is not supported in IE 8
+ // TODO: try to figure out a polyfill style fix, so it could be transferred to polyfills and removed if ie8 is not needed
+ if (!browser.supportsMutationEvents()) {
+ this.domNodeRemovedInterval = setInterval(function() {
+ if (!dom.contains(document.documentElement, container)) {
+ handleDomNodeRemoved.call(this);
+ }
+ }, 250);
+ }
+
+ // --------- User interactions --
+ if (this.config.handleTables) {
+ // If handleTables option is true, table handling functions are bound
+ initTableHandling.call(this);
+ }
+
+ addListeners(focusBlurElement, ["drop", "paste", "mouseup", "focus", "keyup"], handleUserInteraction.bind(this));
+ focusBlurElement.addEventListener("focus", handleFocus.bind(this), false);
+ focusBlurElement.addEventListener("blur", handleBlur.bind(this), false);
+
+ addListeners(this.element, ["drop", "paste", "beforepaste"], handlePaste.bind(this), false);
+ this.element.addEventListener("copy", handleCopy.bind(this), false);
+ this.element.addEventListener("mousedown", handleMouseDown.bind(this), false);
+ this.element.addEventListener("mouseover", handleMouseOver.bind(this), false);
+ this.element.addEventListener("click", handleClick.bind(this), false);
+ this.element.addEventListener("drop", handleDrop.bind(this), false);
+ this.element.addEventListener("keyup", handleKeyUp.bind(this), false);
+ this.element.addEventListener("keydown", handleKeyDown.bind(this), false);
+
+ this.element.addEventListener("dragenter", (function() {
+ this.parent.fire("unset_placeholder");
+ }).bind(this), false);
+
+ // --------- IE 8+9 focus the editor when the iframe is clicked (without actually firing the 'focus' event on the <body>) ---------
+ if (!this.config.contentEditableMode && browser.hasIframeFocusIssue()) {
+ container.addEventListener("focus", handleIframeFocus.bind(this), false);
+ container.addEventListener("blur", handleIframeBlur.bind(this), false);
+ }
+
+ };
+})(wysihtml5);
+;/**
+ * Class that takes care that the value of the composer and the textarea is always in sync
+ */
+(function(wysihtml5) {
+ var INTERVAL = 400;
+
+ wysihtml5.views.Synchronizer = Base.extend(
+ /** @scope wysihtml5.views.Synchronizer.prototype */ {
+
+ constructor: function(editor, textarea, composer) {
+ this.editor = editor;
+ this.textarea = textarea;
+ this.composer = composer;
+
+ this._observe();
+ },
+
+ /**
+ * Sync html from composer to textarea
+ * Takes care of placeholders
+ * @param {Boolean} shouldParseHtml Whether the html should be sanitized before inserting it into the textarea
+ */
+ fromComposerToTextarea: function(shouldParseHtml) {
+ this.textarea.setValue(wysihtml5.lang.string(this.composer.getValue(false, false)).trim(), shouldParseHtml);
+ },
+
+ /**
+ * Sync value of textarea to composer
+ * Takes care of placeholders
+ * @param {Boolean} shouldParseHtml Whether the html should be sanitized before inserting it into the composer
+ */
+ fromTextareaToComposer: function(shouldParseHtml) {
+ var textareaValue = this.textarea.getValue(false, false);
+ if (textareaValue) {
+ this.composer.setValue(textareaValue, shouldParseHtml);
+ } else {
+ this.composer.clear();
+ this.editor.fire("set_placeholder");
+ }
+ },
+
+ /**
+ * Invoke syncing based on view state
+ * @param {Boolean} shouldParseHtml Whether the html should be sanitized before inserting it into the composer/textarea
+ */
+ sync: function(shouldParseHtml) {
+ if (this.editor.currentView.name === "textarea") {
+ this.fromTextareaToComposer(shouldParseHtml);
+ } else {
+ this.fromComposerToTextarea(shouldParseHtml);
+ }
+ },
+
+ /**
+ * Initializes interval-based syncing
+ * also makes sure that on-submit the composer's content is synced with the textarea
+ * immediately when the form gets submitted
+ */
+ _observe: function() {
+ var interval,
+ that = this,
+ form = this.textarea.element.form,
+ startInterval = function() {
+ interval = setInterval(function() { that.fromComposerToTextarea(); }, INTERVAL);
+ },
+ stopInterval = function() {
+ clearInterval(interval);
+ interval = null;
+ };
+
+ startInterval();
+
+ if (form) {
+ // If the textarea is in a form make sure that after onreset and onsubmit the composer
+ // has the correct state
+ wysihtml5.dom.observe(form, "submit", function() {
+ that.sync(true);
+ });
+ wysihtml5.dom.observe(form, "reset", function() {
+ setTimeout(function() { that.fromTextareaToComposer(); }, 0);
+ });
+ }
+
+ this.editor.on("change_view", function(view) {
+ if (view === "composer" && !interval) {
+ that.fromTextareaToComposer(true);
+ startInterval();
+ } else if (view === "textarea") {
+ that.fromComposerToTextarea(true);
+ stopInterval();
+ }
+ });
+
+ this.editor.on("destroy:composer", stopInterval);
+ }
+ });
+})(wysihtml5);
+;wysihtml5.views.Textarea = wysihtml5.views.View.extend(
+ /** @scope wysihtml5.views.Textarea.prototype */ {
+ name: "textarea",
+
+ constructor: function(parent, textareaElement, config) {
+ this.base(parent, textareaElement, config);
+
+ this._observe();
+ },
+
+ clear: function() {
+ this.element.value = "";
+ },
+
+ getValue: function(parse) {
+ var value = this.isEmpty() ? "" : this.element.value;
+ if (parse !== false) {
+ value = this.parent.parse(value);
+ }
+ return value;
+ },
+
+ setValue: function(html, parse) {
+ if (parse) {
+ html = this.parent.parse(html);
+ }
+ this.element.value = html;
+ },
+
+ cleanUp: function() {
+ var html = this.parent.parse(this.element.value);
+ this.element.value = html;
+ },
+
+ hasPlaceholderSet: function() {
+ var supportsPlaceholder = wysihtml5.browser.supportsPlaceholderAttributeOn(this.element),
+ placeholderText = this.element.getAttribute("placeholder") || null,
+ value = this.element.value,
+ isEmpty = !value;
+ return (supportsPlaceholder && isEmpty) || (value === placeholderText);
+ },
+
+ isEmpty: function() {
+ return !wysihtml5.lang.string(this.element.value).trim() || this.hasPlaceholderSet();
+ },
+
+ _observe: function() {
+ var element = this.element,
+ parent = this.parent,
+ eventMapping = {
+ focusin: "focus",
+ focusout: "blur"
+ },
+ /**
+ * Calling focus() or blur() on an element doesn't synchronously trigger the attached focus/blur events
+ * This is the case for focusin and focusout, so let's use them whenever possible, kkthxbai
+ */
+ events = wysihtml5.browser.supportsEvent("focusin") ? ["focusin", "focusout", "change"] : ["focus", "blur", "change"];
+
+ parent.on("beforeload", function() {
+ wysihtml5.dom.observe(element, events, function(event) {
+ var eventName = eventMapping[event.type] || event.type;
+ parent.fire(eventName).fire(eventName + ":textarea");
+ });
+
+ wysihtml5.dom.observe(element, ["paste", "drop"], function() {
+ setTimeout(function() { parent.fire("paste").fire("paste:textarea"); }, 0);
+ });
+ });
+ }
+});
+;/**
+ * WYSIHTML5 Editor
+ *
+ * @param {Element} editableElement Reference to the textarea which should be turned into a rich text interface
+ * @param {Object} [config] See defaultConfig object below for explanation of each individual config option
+ *
+ * @events
+ * load
+ * beforeload (for internal use only)
+ * focus
+ * focus:composer
+ * focus:textarea
+ * blur
+ * blur:composer
+ * blur:textarea
+ * change
+ * change:composer
+ * change:textarea
+ * paste
+ * paste:composer
+ * paste:textarea
+ * newword:composer
+ * destroy:composer
+ * undo:composer
+ * redo:composer
+ * beforecommand:composer
+ * aftercommand:composer
+ * enable:composer
+ * disable:composer
+ * change_view
+ */
+(function(wysihtml5) {
+ var undef;
+
+ var defaultConfig = {
+ // Give the editor a name, the name will also be set as class name on the iframe and on the iframe's body
+ name: undef,
+ // Whether the editor should look like the textarea (by adopting styles)
+ style: true,
+ // Id of the toolbar element, pass falsey value if you don't want any toolbar logic
+ toolbar: undef,
+ // Whether toolbar is displayed after init by script automatically.
+ // Can be set to false if toolobar is set to display only on editable area focus
+ showToolbarAfterInit: true,
+ // Whether urls, entered by the user should automatically become clickable-links
+ autoLink: true,
+ // Includes table editing events and cell selection tracking
+ handleTables: true,
+ // Tab key inserts tab into text as default behaviour. It can be disabled to regain keyboard navigation
+ handleTabKey: true,
+ // Object which includes parser rules to apply when html gets cleaned
+ // See parser_rules/*.js for examples
+ parserRules: { tags: { br: {}, span: {}, div: {}, p: {} }, classes: {} },
+ // Object which includes parser when the user inserts content via copy & paste. If null parserRules will be used instead
+ pasteParserRulesets: null,
+ // Parser method to use when the user inserts content
+ parser: wysihtml5.dom.parse,
+ // Class name which should be set on the contentEditable element in the created sandbox iframe, can be styled via the 'stylesheets' option
+ composerClassName: "wysihtml5-editor",
+ // Class name to add to the body when the wysihtml5 editor is supported
+ bodyClassName: "wysihtml5-supported",
+ // By default wysihtml5 will insert a <br> for line breaks, set this to false to use <p>
+ useLineBreaks: true,
+ // Array (or single string) of stylesheet urls to be loaded in the editor's iframe
+ stylesheets: [],
+ // Placeholder text to use, defaults to the placeholder attribute on the textarea element
+ placeholderText: undef,
+ // Whether the rich text editor should be rendered on touch devices (wysihtml5 >= 0.3.0 comes with basic support for iOS 5)
+ supportTouchDevices: true,
+ // Whether senseless <span> elements (empty or without attributes) should be removed/replaced with their content
+ cleanUp: true,
+ // Whether to use div instead of secure iframe
+ contentEditableMode: false,
+ // Classname of container that editor should not touch and pass through
+ // Pass false to disable
+ uneditableContainerClassname: "wysihtml5-uneditable-container",
+ // Browsers that support copied source handling will get a marking of the origin of the copied source (for determinig code cleanup rules on paste)
+ // Also copied source is based directly on selection -
+ // (very useful for webkit based browsers where copy will otherwise contain a lot of code and styles based on whatever and not actually in selection).
+ // If falsy value is passed source override is also disabled
+ copyedFromMarking: '<meta name="copied-from" content="wysihtml5">'
+ };
+
+ wysihtml5.Editor = wysihtml5.lang.Dispatcher.extend(
+ /** @scope wysihtml5.Editor.prototype */ {
+ constructor: function(editableElement, config) {
+ this.editableElement = typeof(editableElement) === "string" ? document.getElementById(editableElement) : editableElement;
+ this.config = wysihtml5.lang.object({}).merge(defaultConfig).merge(config).get();
+ this._isCompatible = wysihtml5.browser.supported();
+
+ if (this.editableElement.nodeName.toLowerCase() != "textarea") {
+ this.config.contentEditableMode = true;
+ this.config.noTextarea = true;
+ }
+ if (!this.config.noTextarea) {
+ this.textarea = new wysihtml5.views.Textarea(this, this.editableElement, this.config);
+ this.currentView = this.textarea;
+ }
+
+ // Sort out unsupported/unwanted browsers here
+ if (!this._isCompatible || (!this.config.supportTouchDevices && wysihtml5.browser.isTouchDevice())) {
+ var that = this;
+ setTimeout(function() { that.fire("beforeload").fire("load"); }, 0);
+ return;
+ }
+
+ // Add class name to body, to indicate that the editor is supported
+ wysihtml5.dom.addClass(document.body, this.config.bodyClassName);
+
+ this.composer = new wysihtml5.views.Composer(this, this.editableElement, this.config);
+ this.currentView = this.composer;
+
+ if (typeof(this.config.parser) === "function") {
+ this._initParser();
+ }
+
+ this.on("beforeload", this.handleBeforeLoad);
+ },
+
+ handleBeforeLoad: function() {
+ if (!this.config.noTextarea) {
+ this.synchronizer = new wysihtml5.views.Synchronizer(this, this.textarea, this.composer);
+ }
+ if (this.config.toolbar) {
+ this.toolbar = new wysihtml5.toolbar.Toolbar(this, this.config.toolbar, this.config.showToolbarAfterInit);
+ }
+ },
+
+ isCompatible: function() {
+ return this._isCompatible;
+ },
+
+ clear: function() {
+ this.currentView.clear();
+ return this;
+ },
+
+ getValue: function(parse, clearInternals) {
+ return this.currentView.getValue(parse, clearInternals);
+ },
+
+ setValue: function(html, parse) {
+ this.fire("unset_placeholder");
+
+ if (!html) {
+ return this.clear();
+ }
+
+ this.currentView.setValue(html, parse);
+ return this;
+ },
+
+ cleanUp: function() {
+ this.currentView.cleanUp();
+ },
+
+ focus: function(setToEnd) {
+ this.currentView.focus(setToEnd);
+ return this;
+ },
+
+ /**
+ * Deactivate editor (make it readonly)
+ */
+ disable: function() {
+ this.currentView.disable();
+ return this;
+ },
+
+ /**
+ * Activate editor
+ */
+ enable: function() {
+ this.currentView.enable();
+ return this;
+ },
+
+ isEmpty: function() {
+ return this.currentView.isEmpty();
+ },
+
+ hasPlaceholderSet: function() {
+ return this.currentView.hasPlaceholderSet();
+ },
+
+ parse: function(htmlOrElement, clearInternals) {
+ var parseContext = (this.config.contentEditableMode) ? document : ((this.composer) ? this.composer.sandbox.getDocument() : null);
+ var returnValue = this.config.parser(htmlOrElement, {
+ "rules": this.config.parserRules,
+ "cleanUp": this.config.cleanUp,
+ "context": parseContext,
+ "uneditableClass": this.config.uneditableContainerClassname,
+ "clearInternals" : clearInternals
+ });
+ if (typeof(htmlOrElement) === "object") {
+ wysihtml5.quirks.redraw(htmlOrElement);
+ }
+ return returnValue;
+ },
+
+ /**
+ * Prepare html parser logic
+ * - Observes for paste and drop
+ */
+ _initParser: function() {
+ var that = this,
+ oldHtml,
+ cleanHtml;
+
+ if (wysihtml5.browser.supportsModenPaste()) {
+ this.on("paste:composer", function(event) {
+ event.preventDefault();
+ oldHtml = wysihtml5.dom.getPastedHtml(event);
+ if (oldHtml) {
+ that._cleanAndPaste(oldHtml);
+ }
+ });
+
+ } else {
+ this.on("beforepaste:composer", function(event) {
+ event.preventDefault();
+ wysihtml5.dom.getPastedHtmlWithDiv(that.composer, function(pastedHTML) {
+ if (pastedHTML) {
+ that._cleanAndPaste(pastedHTML);
+ }
+ });
+ });
+
+ }
+ },
+
+ _cleanAndPaste: function (oldHtml) {
+ var cleanHtml = wysihtml5.quirks.cleanPastedHTML(oldHtml, {
+ "referenceNode": this.composer.element,
+ "rules": this.config.pasteParserRulesets || [{"set": this.config.parserRules}],
+ "uneditableClass": this.config.uneditableContainerClassname
+ });
+ this.composer.selection.deleteContents();
+ this.composer.selection.insertHTML(cleanHtml);
+ }
+ });
+})(wysihtml5);
--- /dev/null
+/*! wysihtml5x - v0.4.17 (2014-11-06) */
+
+!function(){if(Event.prototype.preventDefault||(Event.prototype.preventDefault=function(){this.returnValue=!1}),Event.prototype.stopPropagation||(Event.prototype.stopPropagation=function(){this.cancelBubble=!0}),!Element.prototype.addEventListener){var a=[],b=function(b,c){var d=this,e=function(a){a.target=a.srcElement,a.currentTarget=d,c.handleEvent?c.handleEvent(a):c.call(d,a)};if("DOMContentLoaded"==b){var f=function(a){"complete"==document.readyState&&e(a)};if(document.attachEvent("onreadystatechange",f),a.push({object:this,type:b,listener:c,wrapper:f}),"complete"==document.readyState){var g=new Event;g.srcElement=window,f(g)}}else this.attachEvent("on"+b,e),a.push({object:this,type:b,listener:c,wrapper:e})},c=function(b,c){for(var d=0;d<a.length;){var e=a[d];if(e.object==this&&e.type==b&&e.listener==c){"DOMContentLoaded"==b?this.detachEvent("onreadystatechange",e.wrapper):this.detachEvent("on"+b,e.wrapper),a.splice(d,1);break}++d}};Element.prototype.addEventListener=b,Element.prototype.removeEventListener=c,HTMLDocument&&(HTMLDocument.prototype.addEventListener=b,HTMLDocument.prototype.removeEventListener=c),Window&&(Window.prototype.addEventListener=b,Window.prototype.removeEventListener=c)}}(),Object.defineProperty&&Object.getOwnPropertyDescriptor&&Object.getOwnPropertyDescriptor(Element.prototype,"textContent")&&!Object.getOwnPropertyDescriptor(Element.prototype,"textContent").get&&!function(){var a=Object.getOwnPropertyDescriptor(Element.prototype,"innerText");Object.defineProperty(Element.prototype,"textContent",{get:function(){return a.get.call(this)},set:function(b){return a.set.call(this,b)}})}(),Array.isArray||(Array.isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)}),Function.prototype.bind||(Function.prototype.bind=function(a){if("function"!=typeof this)throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");var b=Array.prototype.slice.call(arguments,1),c=this,d=function(){},e=function(){return c.apply(this instanceof d&&a?this:a,b.concat(Array.prototype.slice.call(arguments)))};return d.prototype=this.prototype,e.prototype=new d,e});var wysihtml5={version:"0.4.17",commands:{},dom:{},quirks:{},toolbar:{},lang:{},selection:{},views:{},INVISIBLE_SPACE:"",INVISIBLE_SPACE_REG_EXP:/\uFEFF/g,EMPTY_FUNCTION:function(){},ELEMENT_NODE:1,TEXT_NODE:3,BACKSPACE_KEY:8,ENTER_KEY:13,ESCAPE_KEY:27,SPACE_KEY:32,TAB_KEY:9,DELETE_KEY:46};!function(a,b){"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"object"==typeof exports?module.exports=a():b.rangy=a()}(function(){function a(a,b){var c=typeof a[b];return c==s||!(c!=r||!a[b])||"unknown"==c}function b(a,b){return!(typeof a[b]!=r||!a[b])}function c(a,b){return typeof a[b]!=t}function d(a){return function(b,c){for(var d=c.length;d--;)if(!a(b,c[d]))return!1;return!0}}function e(a){return a&&y(a,x)&&A(a,w)}function f(a){return b(a,"body")?a.body:a.getElementsByTagName("body")[0]}function g(b){typeof console!=t&&a(console,"log")&&console.log(b)}function h(a,b){C&&b?alert(a):g(a)}function i(a){E.initialized=!0,E.supported=!1,h("Rangy is not supported in this environment. Reason: "+a,E.config.alertOnFail)}function j(a){h("Rangy warning: "+a,E.config.alertOnWarn)}function k(a){return a.message||a.description||String(a)}function l(){if(C&&!E.initialized){var b,c=!1,d=!1;a(document,"createRange")&&(b=document.createRange(),y(b,v)&&A(b,u)&&(c=!0));var h=f(document);if(!h||"body"!=h.nodeName.toLowerCase())return void i("No body element found");if(h&&a(h,"createTextRange")&&(b=h.createTextRange(),e(b)&&(d=!0)),!c&&!d)return void i("Neither Range nor TextRange are available");E.initialized=!0,E.features={implementsDomRange:c,implementsTextRange:d};var j,l;for(var m in B)(j=B[m])instanceof n&&j.init(j,E);for(var o=0,p=H.length;p>o;++o)try{H[o](E)}catch(q){l="Rangy init listener threw an exception. Continuing. Detail: "+k(q),g(l)}}}function m(a){a=a||window,l();for(var b=0,c=I.length;c>b;++b)I[b](a)}function n(a,b,c){this.name=a,this.dependencies=b,this.initialized=!1,this.supported=!1,this.initializer=c}function o(a,b,c){var d=new n(a,b,function(b){if(!b.initialized){b.initialized=!0;try{c(E,b),b.supported=!0}catch(d){var e="Module '"+a+"' failed to load: "+k(d);g(e),d.stack&&g(d.stack)}}});return B[a]=d,d}function p(){}function q(){}var r="object",s="function",t="undefined",u=["startContainer","startOffset","endContainer","endOffset","collapsed","commonAncestorContainer"],v=["setStart","setStartBefore","setStartAfter","setEnd","setEndBefore","setEndAfter","collapse","selectNode","selectNodeContents","compareBoundaryPoints","deleteContents","extractContents","cloneContents","insertNode","surroundContents","cloneRange","toString","detach"],w=["boundingHeight","boundingLeft","boundingTop","boundingWidth","htmlText","text"],x=["collapse","compareEndPoints","duplicate","moveToElementText","parentElement","select","setEndPoint","getBoundingClientRect"],y=d(a),z=d(b),A=d(c),B={},C=typeof window!=t&&typeof document!=t,D={isHostMethod:a,isHostObject:b,isHostProperty:c,areHostMethods:y,areHostObjects:z,areHostProperties:A,isTextRange:e,getBody:f},E={version:"1.3.0-alpha.20140921",initialized:!1,isBrowser:C,supported:!0,util:D,features:{},modules:B,config:{alertOnFail:!0,alertOnWarn:!1,preferTextRange:!1,autoInitialize:typeof rangyAutoInitialize==t?!0:rangyAutoInitialize}};E.fail=i,E.warn=j;var F;({}).hasOwnProperty?(D.extend=F=function(a,b,c){var d,e;for(var f in b)b.hasOwnProperty(f)&&(d=a[f],e=b[f],c&&null!==d&&"object"==typeof d&&null!==e&&"object"==typeof e&&F(d,e,!0),a[f]=e);return b.hasOwnProperty("toString")&&(a.toString=b.toString),a},D.createOptions=function(a,b){var c={};return F(c,b),a&&F(c,a),c}):i("hasOwnProperty not supported"),C||i("Rangy can only run in a browser"),function(){var a;if(C){var b=document.createElement("div");b.appendChild(document.createElement("span"));var c=[].slice;try{1==c.call(b.childNodes,0)[0].nodeType&&(a=function(a){return c.call(a,0)})}catch(d){}}a||(a=function(a){for(var b=[],c=0,d=a.length;d>c;++c)b[c]=a[c];return b}),D.toArray=a}();var G;C&&(a(document,"addEventListener")?G=function(a,b,c){a.addEventListener(b,c,!1)}:a(document,"attachEvent")?G=function(a,b,c){a.attachEvent("on"+b,c)}:i("Document does not have required addEventListener or attachEvent method"),D.addListener=G);var H=[];E.init=l,E.addInitListener=function(a){E.initialized?a(E):H.push(a)};var I=[];E.addShimListener=function(a){I.push(a)},C&&(E.shim=E.createMissingNativeApi=m),n.prototype={init:function(){for(var a,b,c=this.dependencies||[],d=0,e=c.length;e>d;++d){if(b=c[d],a=B[b],!(a&&a instanceof n))throw new Error("required module '"+b+"' not found");if(a.init(),!a.supported)throw new Error("required module '"+b+"' not supported")}this.initializer(this)},fail:function(a){throw this.initialized=!0,this.supported=!1,new Error("Module '"+this.name+"' failed to load: "+a)},warn:function(a){E.warn("Module "+this.name+": "+a)},deprecationNotice:function(a,b){E.warn("DEPRECATED: "+a+" in module "+this.name+"is deprecated. Please use "+b+" instead")},createError:function(a){return new Error("Error in Rangy "+this.name+" module: "+a)}},E.createModule=function(a){var b,c;2==arguments.length?(b=arguments[1],c=[]):(b=arguments[2],c=arguments[1]);var d=o(a,c,b);E.initialized&&E.supported&&d.init()},E.createCoreModule=function(a,b,c){o(a,b,c)},E.RangePrototype=p,E.rangePrototype=new p,E.selectionPrototype=new q,E.createCoreModule("DomUtil",[],function(a,b){function c(a){var b;return typeof a.namespaceURI==D||null===(b=a.namespaceURI)||"http://www.w3.org/1999/xhtml"==b}function d(a){var b=a.parentNode;return 1==b.nodeType?b:null}function e(a){for(var b=0;a=a.previousSibling;)++b;return b}function f(a){switch(a.nodeType){case 7:case 10:return 0;case 3:case 8:return a.length;default:return a.childNodes.length}}function g(a,b){var c,d=[];for(c=a;c;c=c.parentNode)d.push(c);for(c=b;c;c=c.parentNode)if(H(d,c))return c;return null}function h(a,b,c){for(var d=c?b:b.parentNode;d;){if(d===a)return!0;d=d.parentNode}return!1}function i(a,b){return h(a,b,!0)}function j(a,b,c){for(var d,e=c?a:a.parentNode;e;){if(d=e.parentNode,d===b)return e;e=d}return null}function k(a){var b=a.nodeType;return 3==b||4==b||8==b}function l(a){if(!a)return!1;var b=a.nodeType;return 3==b||8==b}function m(a,b){var c=b.nextSibling,d=b.parentNode;return c?d.insertBefore(a,c):d.appendChild(a),a}function n(a,b,c){var d=a.cloneNode(!1);if(d.deleteData(0,b),a.deleteData(b,a.length-b),m(d,a),c)for(var f,g=0;f=c[g++];)f.node==a&&f.offset>b?(f.node=d,f.offset-=b):f.node==a.parentNode&&f.offset>e(a)&&++f.offset;return d}function o(a){if(9==a.nodeType)return a;if(typeof a.ownerDocument!=D)return a.ownerDocument;if(typeof a.document!=D)return a.document;if(a.parentNode)return o(a.parentNode);throw b.createError("getDocument: no document found for node")}function p(a){var c=o(a);if(typeof c.defaultView!=D)return c.defaultView;if(typeof c.parentWindow!=D)return c.parentWindow;throw b.createError("Cannot get a window object for node")}function q(a){if(typeof a.contentDocument!=D)return a.contentDocument;if(typeof a.contentWindow!=D)return a.contentWindow.document;throw b.createError("getIframeDocument: No Document object found for iframe element")}function r(a){if(typeof a.contentWindow!=D)return a.contentWindow;if(typeof a.contentDocument!=D)return a.contentDocument.defaultView;throw b.createError("getIframeWindow: No Window object found for iframe element")}function s(a){return a&&E.isHostMethod(a,"setTimeout")&&E.isHostObject(a,"document")}function t(a,b,c){var d;if(a?E.isHostProperty(a,"nodeType")?d=1==a.nodeType&&"iframe"==a.tagName.toLowerCase()?q(a):o(a):s(a)&&(d=a.document):d=document,!d)throw b.createError(c+"(): Parameter must be a Window object or DOM node");return d}function u(a){for(var b;b=a.parentNode;)a=b;return a}function v(a,c,d,f){var h,i,k,l,m;if(a==d)return c===f?0:f>c?-1:1;if(h=j(d,a,!0))return c<=e(h)?-1:1;if(h=j(a,d,!0))return e(h)<f?-1:1;if(i=g(a,d),!i)throw new Error("comparePoints error: nodes have no common ancestor");if(k=a===i?i:j(a,i,!0),l=d===i?i:j(d,i,!0),k===l)throw b.createError("comparePoints got to case 4 and childA and childB are the same!");for(m=i.firstChild;m;){if(m===k)return-1;if(m===l)return 1;m=m.nextSibling}}function w(a){var b;try{return b=a.parentNode,!1}catch(c){return!0}}function x(a){if(!a)return"[No node]";if(I&&w(a))return"[Broken node]";if(k(a))return'"'+a.data+'"';if(1==a.nodeType){var b=a.id?' id="'+a.id+'"':"";return"<"+a.nodeName+b+">[index:"+e(a)+",length:"+a.childNodes.length+"]["+(a.innerHTML||"[innerHTML not supported]").slice(0,25)+"]"}return a.nodeName}function y(a){for(var b,c=o(a).createDocumentFragment();b=a.firstChild;)c.appendChild(b);return c}function z(a){this.root=a,this._next=a}function A(a){return new z(a)}function B(a,b){this.node=a,this.offset=b}function C(a){this.code=this[a],this.codeName=a,this.message="DOMException: "+this.codeName}var D="undefined",E=a.util;E.areHostMethods(document,["createDocumentFragment","createElement","createTextNode"])||b.fail("document missing a Node creation method"),E.isHostMethod(document,"getElementsByTagName")||b.fail("document missing getElementsByTagName method");var F=document.createElement("div");E.areHostMethods(F,["insertBefore","appendChild","cloneNode"]||!E.areHostObjects(F,["previousSibling","nextSibling","childNodes","parentNode"]))||b.fail("Incomplete Element implementation"),E.isHostProperty(F,"innerHTML")||b.fail("Element is missing innerHTML property");var G=document.createTextNode("test");E.areHostMethods(G,["splitText","deleteData","insertData","appendData","cloneNode"]||!E.areHostObjects(F,["previousSibling","nextSibling","childNodes","parentNode"])||!E.areHostProperties(G,["data"]))||b.fail("Incomplete Text Node implementation");var H=function(a,b){for(var c=a.length;c--;)if(a[c]===b)return!0;return!1},I=!1;!function(){var b=document.createElement("b");b.innerHTML="1";var c=b.firstChild;b.innerHTML="<br>",I=w(c),a.features.crashyTextNodes=I}();var J;typeof window.getComputedStyle!=D?J=function(a,b){return p(a).getComputedStyle(a,null)[b]}:typeof document.documentElement.currentStyle!=D?J=function(a,b){return a.currentStyle[b]}:b.fail("No means of obtaining computed style properties found"),z.prototype={_current:null,hasNext:function(){return!!this._next},next:function(){var a,b,c=this._current=this._next;if(this._current)if(a=c.firstChild)this._next=a;else{for(b=null;c!==this.root&&!(b=c.nextSibling);)c=c.parentNode;this._next=b}return this._current},detach:function(){this._current=this._next=this.root=null}},B.prototype={equals:function(a){return!!a&&this.node===a.node&&this.offset==a.offset},inspect:function(){return"[DomPosition("+x(this.node)+":"+this.offset+")]"},toString:function(){return this.inspect()}},C.prototype={INDEX_SIZE_ERR:1,HIERARCHY_REQUEST_ERR:3,WRONG_DOCUMENT_ERR:4,NO_MODIFICATION_ALLOWED_ERR:7,NOT_FOUND_ERR:8,NOT_SUPPORTED_ERR:9,INVALID_STATE_ERR:11,INVALID_NODE_TYPE_ERR:24},C.prototype.toString=function(){return this.message},a.dom={arrayContains:H,isHtmlNamespace:c,parentElement:d,getNodeIndex:e,getNodeLength:f,getCommonAncestor:g,isAncestorOf:h,isOrIsAncestorOf:i,getClosestAncestorIn:j,isCharacterDataNode:k,isTextOrCommentNode:l,insertAfter:m,splitDataNode:n,getDocument:o,getWindow:p,getIframeWindow:r,getIframeDocument:q,getBody:E.getBody,isWindow:s,getContentDocument:t,getRootContainer:u,comparePoints:v,isBrokenNode:w,inspectNode:x,getComputedStyleProperty:J,fragmentFromNodeChildren:y,createIterator:A,DomPosition:B},a.DOMException=C}),E.createCoreModule("DomRange",["DomUtil"],function(a){function b(a,b){return 3!=a.nodeType&&(O(a,b.startContainer)||O(a,b.endContainer))}function c(a){return a.document||P(a.startContainer)}function d(a){return new K(a.parentNode,N(a))}function e(a){return new K(a.parentNode,N(a)+1)}function f(a,b,c){var d=11==a.nodeType?a.firstChild:a;return M(b)?c==b.length?I.insertAfter(a,b):b.parentNode.insertBefore(a,0==c?b:R(b,c)):c>=b.childNodes.length?b.appendChild(a):b.insertBefore(a,b.childNodes[c]),d}function g(a,b,d){if(y(a),y(b),c(b)!=c(a))throw new L("WRONG_DOCUMENT_ERR");var e=Q(a.startContainer,a.startOffset,b.endContainer,b.endOffset),f=Q(a.endContainer,a.endOffset,b.startContainer,b.startOffset);return d?0>=e&&f>=0:0>e&&f>0}function h(a){for(var b,d,e,f=c(a.range).createDocumentFragment();d=a.next();){if(b=a.isPartiallySelectedSubtree(),d=d.cloneNode(!b),b&&(e=a.getSubtreeIterator(),d.appendChild(h(e)),e.detach()),10==d.nodeType)throw new L("HIERARCHY_REQUEST_ERR");f.appendChild(d)}return f}function i(a,b,c){var d,e;c=c||{stop:!1};for(var f,g;f=a.next();)if(a.isPartiallySelectedSubtree()){if(b(f)===!1)return void(c.stop=!0);if(g=a.getSubtreeIterator(),i(g,b,c),g.detach(),c.stop)return}else for(d=I.createIterator(f);e=d.next();)if(b(e)===!1)return void(c.stop=!0)}function j(a){for(var b;a.next();)a.isPartiallySelectedSubtree()?(b=a.getSubtreeIterator(),j(b),b.detach()):a.remove()}function k(a){for(var b,d,e=c(a.range).createDocumentFragment();b=a.next();){if(a.isPartiallySelectedSubtree()?(b=b.cloneNode(!1),d=a.getSubtreeIterator(),b.appendChild(k(d)),d.detach()):a.remove(),10==b.nodeType)throw new L("HIERARCHY_REQUEST_ERR");e.appendChild(b)}return e}function l(a,b,c){var d,e=!(!b||!b.length),f=!!c;e&&(d=new RegExp("^("+b.join("|")+")$"));var g=[];return i(new n(a,!1),function(b){if(!(e&&!d.test(b.nodeType)||f&&!c(b))){var h=a.startContainer;if(b!=h||!M(h)||a.startOffset!=h.length){var i=a.endContainer;b==i&&M(i)&&0==a.endOffset||g.push(b)}}}),g}function m(a){var b="undefined"==typeof a.getName?"Range":a.getName();return"["+b+"("+I.inspectNode(a.startContainer)+":"+a.startOffset+", "+I.inspectNode(a.endContainer)+":"+a.endOffset+")]"}function n(a,b){if(this.range=a,this.clonePartiallySelectedTextNodes=b,!a.collapsed){this.sc=a.startContainer,this.so=a.startOffset,this.ec=a.endContainer,this.eo=a.endOffset;var c=a.commonAncestorContainer;this.sc===this.ec&&M(this.sc)?(this.isSingleCharacterDataNode=!0,this._first=this._last=this._next=this.sc):(this._first=this._next=this.sc!==c||M(this.sc)?S(this.sc,c,!0):this.sc.childNodes[this.so],this._last=this.ec!==c||M(this.ec)?S(this.ec,c,!0):this.ec.childNodes[this.eo-1])}}function o(a){return function(b,c){for(var d,e=c?b:b.parentNode;e;){if(d=e.nodeType,U(a,d))return e;e=e.parentNode}return null}}function p(a,b){if(cb(a,b))throw new L("INVALID_NODE_TYPE_ERR")}function q(a,b){if(!U(b,a.nodeType))throw new L("INVALID_NODE_TYPE_ERR")}function r(a,b){if(0>b||b>(M(a)?a.length:a.childNodes.length))throw new L("INDEX_SIZE_ERR")}function s(a,b){if(ab(a,!0)!==ab(b,!0))throw new L("WRONG_DOCUMENT_ERR")}function t(a){if(bb(a,!0))throw new L("NO_MODIFICATION_ALLOWED_ERR")}function u(a,b){if(!a)throw new L(b)}function v(a){return W&&I.isBrokenNode(a)||!U(Y,a.nodeType)&&!ab(a,!0)}function w(a,b){return b<=(M(a)?a.length:a.childNodes.length)}function x(a){return!!a.startContainer&&!!a.endContainer&&!v(a.startContainer)&&!v(a.endContainer)&&w(a.startContainer,a.startOffset)&&w(a.endContainer,a.endOffset)}function y(a){if(!x(a))throw new Error("Range error: Range is no longer valid after DOM mutation ("+a.inspect()+")")}function z(a,b){y(a);var c=a.startContainer,d=a.startOffset,e=a.endContainer,f=a.endOffset,g=c===e;M(e)&&f>0&&f<e.length&&R(e,f,b),M(c)&&d>0&&d<c.length&&(c=R(c,d,b),g?(f-=d,e=c):e==c.parentNode&&f>=N(c)&&f++,d=0),a.setStartAndEnd(c,d,e,f)}function A(a){y(a);var b=a.commonAncestorContainer.parentNode.cloneNode(!1);return b.appendChild(a.cloneContents()),b.innerHTML}function B(a){a.START_TO_START=ib,a.START_TO_END=jb,a.END_TO_END=kb,a.END_TO_START=lb,a.NODE_BEFORE=mb,a.NODE_AFTER=nb,a.NODE_BEFORE_AND_AFTER=ob,a.NODE_INSIDE=pb}function C(a){B(a),B(a.prototype)}function D(a,b){return function(){y(this);var c,d,f=this.startContainer,g=this.startOffset,h=this.commonAncestorContainer,j=new n(this,!0);f!==h&&(c=S(f,h,!0),d=e(c),f=d.node,g=d.offset),i(j,t),j.reset();var k=a(j);return j.detach(),b(this,f,g,f,g),k}}function E(c,f){function g(a,b){return function(c){q(c,X),q(V(c),Y);var f=(a?d:e)(c);(b?h:i)(this,f.node,f.offset)}}function h(a,b,c){var d=a.endContainer,e=a.endOffset;(b!==a.startContainer||c!==a.startOffset)&&((V(b)!=V(d)||1==Q(b,c,d,e))&&(d=b,e=c),f(a,b,c,d,e))}function i(a,b,c){var d=a.startContainer,e=a.startOffset;(b!==a.endContainer||c!==a.endOffset)&&((V(b)!=V(d)||-1==Q(b,c,d,e))&&(d=b,e=c),f(a,d,e,b,c))}var l=function(){};l.prototype=a.rangePrototype,c.prototype=new l,J.extend(c.prototype,{setStart:function(a,b){p(a,!0),r(a,b),h(this,a,b)},setEnd:function(a,b){p(a,!0),r(a,b),i(this,a,b)},setStartAndEnd:function(){var a=arguments,b=a[0],c=a[1],d=b,e=c;switch(a.length){case 3:e=a[2];break;case 4:d=a[2],e=a[3]}f(this,b,c,d,e)},setBoundary:function(a,b,c){this["set"+(c?"Start":"End")](a,b)},setStartBefore:g(!0,!0),setStartAfter:g(!1,!0),setEndBefore:g(!0,!1),setEndAfter:g(!1,!1),collapse:function(a){y(this),a?f(this,this.startContainer,this.startOffset,this.startContainer,this.startOffset):f(this,this.endContainer,this.endOffset,this.endContainer,this.endOffset)},selectNodeContents:function(a){p(a,!0),f(this,a,0,a,T(a))},selectNode:function(a){p(a,!1),q(a,X);var b=d(a),c=e(a);f(this,b.node,b.offset,c.node,c.offset)},extractContents:D(k,f),deleteContents:D(j,f),canSurroundContents:function(){y(this),t(this.startContainer),t(this.endContainer);var a=new n(this,!0),c=a._first&&b(a._first,this)||a._last&&b(a._last,this);return a.detach(),!c},splitBoundaries:function(){z(this)},splitBoundariesPreservingPositions:function(a){z(this,a)},normalizeBoundaries:function(){y(this);var a=this.startContainer,b=this.startOffset,c=this.endContainer,d=this.endOffset,e=function(a){var b=a.nextSibling;b&&b.nodeType==a.nodeType&&(c=a,d=a.length,a.appendData(b.data),b.parentNode.removeChild(b))},g=function(e){var f=e.previousSibling;if(f&&f.nodeType==e.nodeType){a=e;var g=e.length;if(b=f.length,e.insertData(0,f.data),f.parentNode.removeChild(f),a==c)d+=b,c=a;else if(c==e.parentNode){var h=N(e);d==h?(c=e,d=g):d>h&&d--}}},h=!0;if(M(c))c.length==d&&e(c);else{if(d>0){var i=c.childNodes[d-1];i&&M(i)&&e(i)}h=!this.collapsed}if(h){if(M(a))0==b&&g(a);else if(b<a.childNodes.length){var j=a.childNodes[b];j&&M(j)&&g(j)}}else a=c,b=d;f(this,a,b,c,d)},collapseToPoint:function(a,b){p(a,!0),r(a,b),this.setStartAndEnd(a,b)}}),C(c)}function F(a){a.collapsed=a.startContainer===a.endContainer&&a.startOffset===a.endOffset,a.commonAncestorContainer=a.collapsed?a.startContainer:I.getCommonAncestor(a.startContainer,a.endContainer)}function G(a,b,c,d,e){a.startContainer=b,a.startOffset=c,a.endContainer=d,a.endOffset=e,a.document=I.getDocument(b),F(a)}function H(a){this.startContainer=a,this.startOffset=0,this.endContainer=a,this.endOffset=0,this.document=a,F(this)}var I=a.dom,J=a.util,K=I.DomPosition,L=a.DOMException,M=I.isCharacterDataNode,N=I.getNodeIndex,O=I.isOrIsAncestorOf,P=I.getDocument,Q=I.comparePoints,R=I.splitDataNode,S=I.getClosestAncestorIn,T=I.getNodeLength,U=I.arrayContains,V=I.getRootContainer,W=a.features.crashyTextNodes;n.prototype={_current:null,_next:null,_first:null,_last:null,isSingleCharacterDataNode:!1,reset:function(){this._current=null,this._next=this._first},hasNext:function(){return!!this._next},next:function(){var a=this._current=this._next;return a&&(this._next=a!==this._last?a.nextSibling:null,M(a)&&this.clonePartiallySelectedTextNodes&&(a===this.ec&&(a=a.cloneNode(!0)).deleteData(this.eo,a.length-this.eo),this._current===this.sc&&(a=a.cloneNode(!0)).deleteData(0,this.so))),a},remove:function(){var a,b,c=this._current;!M(c)||c!==this.sc&&c!==this.ec?c.parentNode&&c.parentNode.removeChild(c):(a=c===this.sc?this.so:0,b=c===this.ec?this.eo:c.length,a!=b&&c.deleteData(a,b-a))},isPartiallySelectedSubtree:function(){var a=this._current;return b(a,this.range)},getSubtreeIterator:function(){var a;if(this.isSingleCharacterDataNode)a=this.range.cloneRange(),a.collapse(!1);else{a=new H(c(this.range));var b=this._current,d=b,e=0,f=b,g=T(b);O(b,this.sc)&&(d=this.sc,e=this.so),O(b,this.ec)&&(f=this.ec,g=this.eo),G(a,d,e,f,g)}return new n(a,this.clonePartiallySelectedTextNodes)},detach:function(){this.range=this._current=this._next=this._first=this._last=this.sc=this.so=this.ec=this.eo=null}};var X=[1,3,4,5,7,8,10],Y=[2,9,11],Z=[5,6,10,12],$=[1,3,4,5,7,8,10,11],_=[1,3,4,5,7,8],ab=o([9,11]),bb=o(Z),cb=o([6,10,12]),db=document.createElement("style"),eb=!1;try{db.innerHTML="<b>x</b>",eb=3==db.firstChild.nodeType}catch(fb){}a.features.htmlParsingConforms=eb;var gb=eb?function(a){var b=this.startContainer,c=P(b);if(!b)throw new L("INVALID_STATE_ERR");var d=null;return 1==b.nodeType?d=b:M(b)&&(d=I.parentElement(b)),d=null===d||"HTML"==d.nodeName&&I.isHtmlNamespace(P(d).documentElement)&&I.isHtmlNamespace(d)?c.createElement("body"):d.cloneNode(!1),d.innerHTML=a,I.fragmentFromNodeChildren(d)}:function(a){var b=c(this),d=b.createElement("body");return d.innerHTML=a,I.fragmentFromNodeChildren(d)},hb=["startContainer","startOffset","endContainer","endOffset","collapsed","commonAncestorContainer"],ib=0,jb=1,kb=2,lb=3,mb=0,nb=1,ob=2,pb=3;J.extend(a.rangePrototype,{compareBoundaryPoints:function(a,b){y(this),s(this.startContainer,b.startContainer);var c,d,e,f,g=a==lb||a==ib?"start":"end",h=a==jb||a==ib?"start":"end";return c=this[g+"Container"],d=this[g+"Offset"],e=b[h+"Container"],f=b[h+"Offset"],Q(c,d,e,f)},insertNode:function(a){if(y(this),q(a,$),t(this.startContainer),O(a,this.startContainer))throw new L("HIERARCHY_REQUEST_ERR");var b=f(a,this.startContainer,this.startOffset);this.setStartBefore(b)},cloneContents:function(){y(this);var a,b;if(this.collapsed)return c(this).createDocumentFragment();if(this.startContainer===this.endContainer&&M(this.startContainer))return a=this.startContainer.cloneNode(!0),a.data=a.data.slice(this.startOffset,this.endOffset),b=c(this).createDocumentFragment(),b.appendChild(a),b;var d=new n(this,!0);return a=h(d),d.detach(),a},canSurroundContents:function(){y(this),t(this.startContainer),t(this.endContainer);var a=new n(this,!0),c=a._first&&b(a._first,this)||a._last&&b(a._last,this);return a.detach(),!c},surroundContents:function(a){if(q(a,_),!this.canSurroundContents())throw new L("INVALID_STATE_ERR");var b=this.extractContents();if(a.hasChildNodes())for(;a.lastChild;)a.removeChild(a.lastChild);f(a,this.startContainer,this.startOffset),a.appendChild(b),this.selectNode(a)},cloneRange:function(){y(this);for(var a,b=new H(c(this)),d=hb.length;d--;)a=hb[d],b[a]=this[a];return b},toString:function(){y(this);var a=this.startContainer;if(a===this.endContainer&&M(a))return 3==a.nodeType||4==a.nodeType?a.data.slice(this.startOffset,this.endOffset):"";var b=[],c=new n(this,!0);return i(c,function(a){(3==a.nodeType||4==a.nodeType)&&b.push(a.data)}),c.detach(),b.join("")},compareNode:function(a){y(this);var b=a.parentNode,c=N(a);if(!b)throw new L("NOT_FOUND_ERR");var d=this.comparePoint(b,c),e=this.comparePoint(b,c+1);return 0>d?e>0?ob:mb:e>0?nb:pb},comparePoint:function(a,b){return y(this),u(a,"HIERARCHY_REQUEST_ERR"),s(a,this.startContainer),Q(a,b,this.startContainer,this.startOffset)<0?-1:Q(a,b,this.endContainer,this.endOffset)>0?1:0},createContextualFragment:gb,toHtml:function(){return A(this)},intersectsNode:function(a,b){if(y(this),u(a,"NOT_FOUND_ERR"),P(a)!==c(this))return!1;var d=a.parentNode,e=N(a);u(d,"NOT_FOUND_ERR");var f=Q(d,e,this.endContainer,this.endOffset),g=Q(d,e+1,this.startContainer,this.startOffset);return b?0>=f&&g>=0:0>f&&g>0},isPointInRange:function(a,b){return y(this),u(a,"HIERARCHY_REQUEST_ERR"),s(a,this.startContainer),Q(a,b,this.startContainer,this.startOffset)>=0&&Q(a,b,this.endContainer,this.endOffset)<=0},intersectsRange:function(a){return g(this,a,!1)},intersectsOrTouchesRange:function(a){return g(this,a,!0)},intersection:function(a){if(this.intersectsRange(a)){var b=Q(this.startContainer,this.startOffset,a.startContainer,a.startOffset),c=Q(this.endContainer,this.endOffset,a.endContainer,a.endOffset),d=this.cloneRange();return-1==b&&d.setStart(a.startContainer,a.startOffset),1==c&&d.setEnd(a.endContainer,a.endOffset),d}return null},union:function(a){if(this.intersectsOrTouchesRange(a)){var b=this.cloneRange();return-1==Q(a.startContainer,a.startOffset,this.startContainer,this.startOffset)&&b.setStart(a.startContainer,a.startOffset),1==Q(a.endContainer,a.endOffset,this.endContainer,this.endOffset)&&b.setEnd(a.endContainer,a.endOffset),b}throw new L("Ranges do not intersect")},containsNode:function(a,b){return b?this.intersectsNode(a,!1):this.compareNode(a)==pb},containsNodeContents:function(a){return this.comparePoint(a,0)>=0&&this.comparePoint(a,T(a))<=0},containsRange:function(a){var b=this.intersection(a);return null!==b&&a.equals(b)},containsNodeText:function(a){var b=this.cloneRange();b.selectNode(a);var c=b.getNodes([3]);if(c.length>0){b.setStart(c[0],0);var d=c.pop();return b.setEnd(d,d.length),this.containsRange(b)}return this.containsNodeContents(a)},getNodes:function(a,b){return y(this),l(this,a,b)},getDocument:function(){return c(this)},collapseBefore:function(a){this.setEndBefore(a),this.collapse(!1)},collapseAfter:function(a){this.setStartAfter(a),this.collapse(!0)},getBookmark:function(b){var d=c(this),e=a.createRange(d);b=b||I.getBody(d),e.selectNodeContents(b);var f=this.intersection(e),g=0,h=0;return f&&(e.setEnd(f.startContainer,f.startOffset),g=e.toString().length,h=g+f.toString().length),{start:g,end:h,containerNode:b}},moveToBookmark:function(a){var b=a.containerNode,c=0;this.setStart(b,0),this.collapse(!0);for(var d,e,f,g,h=[b],i=!1,j=!1;!j&&(d=h.pop());)if(3==d.nodeType)e=c+d.length,!i&&a.start>=c&&a.start<=e&&(this.setStart(d,a.start-c),i=!0),i&&a.end>=c&&a.end<=e&&(this.setEnd(d,a.end-c),j=!0),c=e;else for(g=d.childNodes,f=g.length;f--;)h.push(g[f])},getName:function(){return"DomRange"},equals:function(a){return H.rangesEqual(this,a)},isValid:function(){return x(this)},inspect:function(){return m(this)},detach:function(){}}),E(H,G),J.extend(H,{rangeProperties:hb,RangeIterator:n,copyComparisonConstants:C,createPrototypeRange:E,inspect:m,toHtml:A,getRangeDocument:c,rangesEqual:function(a,b){return a.startContainer===b.startContainer&&a.startOffset===b.startOffset&&a.endContainer===b.endContainer&&a.endOffset===b.endOffset}}),a.DomRange=H}),E.createCoreModule("WrappedRange",["DomRange"],function(a,b){var c,d,e=a.dom,f=a.util,g=e.DomPosition,h=a.DomRange,i=e.getBody,j=e.getContentDocument,k=e.isCharacterDataNode;if(a.features.implementsDomRange&&!function(){function d(a){for(var b,c=m.length;c--;)b=m[c],a[b]=a.nativeRange[b];a.collapsed=a.startContainer===a.endContainer&&a.startOffset===a.endOffset}function g(a,b,c,d,e){var f=a.startContainer!==b||a.startOffset!=c,g=a.endContainer!==d||a.endOffset!=e,h=!a.equals(a.nativeRange);(f||g||h)&&(a.setEnd(d,e),a.setStart(b,c))}var k,l,m=h.rangeProperties;c=function(a){if(!a)throw b.createError("WrappedRange: Range must be specified");this.nativeRange=a,d(this)},h.createPrototypeRange(c,g),k=c.prototype,k.selectNode=function(a){this.nativeRange.selectNode(a),d(this)},k.cloneContents=function(){return this.nativeRange.cloneContents()},k.surroundContents=function(a){this.nativeRange.surroundContents(a),d(this)},k.collapse=function(a){this.nativeRange.collapse(a),d(this)},k.cloneRange=function(){return new c(this.nativeRange.cloneRange())},k.refresh=function(){d(this)},k.toString=function(){return this.nativeRange.toString()};var n=document.createTextNode("test");i(document).appendChild(n);var o=document.createRange();o.setStart(n,0),o.setEnd(n,0);try{o.setStart(n,1),k.setStart=function(a,b){this.nativeRange.setStart(a,b),d(this)},k.setEnd=function(a,b){this.nativeRange.setEnd(a,b),d(this)},l=function(a){return function(b){this.nativeRange[a](b),d(this)}}}catch(p){k.setStart=function(a,b){try{this.nativeRange.setStart(a,b)}catch(c){this.nativeRange.setEnd(a,b),this.nativeRange.setStart(a,b)}d(this)},k.setEnd=function(a,b){try{this.nativeRange.setEnd(a,b)}catch(c){this.nativeRange.setStart(a,b),this.nativeRange.setEnd(a,b)}d(this)},l=function(a,b){return function(c){try{this.nativeRange[a](c)}catch(e){this.nativeRange[b](c),this.nativeRange[a](c)}d(this)}}}k.setStartBefore=l("setStartBefore","setEndBefore"),k.setStartAfter=l("setStartAfter","setEndAfter"),k.setEndBefore=l("setEndBefore","setStartBefore"),k.setEndAfter=l("setEndAfter","setStartAfter"),k.selectNodeContents=function(a){this.setStartAndEnd(a,0,e.getNodeLength(a))},o.selectNodeContents(n),o.setEnd(n,3);var q=document.createRange();q.selectNodeContents(n),q.setEnd(n,4),q.setStart(n,2),k.compareBoundaryPoints=-1==o.compareBoundaryPoints(o.START_TO_END,q)&&1==o.compareBoundaryPoints(o.END_TO_START,q)?function(a,b){return b=b.nativeRange||b,a==b.START_TO_END?a=b.END_TO_START:a==b.END_TO_START&&(a=b.START_TO_END),this.nativeRange.compareBoundaryPoints(a,b)}:function(a,b){return this.nativeRange.compareBoundaryPoints(a,b.nativeRange||b)};var r=document.createElement("div");r.innerHTML="123";var s=r.firstChild,t=i(document);t.appendChild(r),o.setStart(s,1),o.setEnd(s,2),o.deleteContents(),"13"==s.data&&(k.deleteContents=function(){this.nativeRange.deleteContents(),d(this)},k.extractContents=function(){var a=this.nativeRange.extractContents();return d(this),a}),t.removeChild(r),t=null,f.isHostMethod(o,"createContextualFragment")&&(k.createContextualFragment=function(a){return this.nativeRange.createContextualFragment(a)}),i(document).removeChild(n),k.getName=function(){return"WrappedRange"},a.WrappedRange=c,a.createNativeRange=function(a){return a=j(a,b,"createNativeRange"),a.createRange()}}(),a.features.implementsTextRange){var l=function(a){var b=a.parentElement(),c=a.duplicate();c.collapse(!0);var d=c.parentElement();c=a.duplicate(),c.collapse(!1);var f=c.parentElement(),g=d==f?d:e.getCommonAncestor(d,f);return g==b?g:e.getCommonAncestor(b,g)},m=function(a){return 0==a.compareEndPoints("StartToEnd",a)},n=function(a,b,c,d,f){var h=a.duplicate();h.collapse(c);var i=h.parentElement();
+if(e.isOrIsAncestorOf(b,i)||(i=b),!i.canHaveHTML){var j=new g(i.parentNode,e.getNodeIndex(i));return{boundaryPosition:j,nodeInfo:{nodeIndex:j.offset,containerElement:j.node}}}var l=e.getDocument(i).createElement("span");l.parentNode&&l.parentNode.removeChild(l);for(var m,n,o,p,q,r=c?"StartToStart":"StartToEnd",s=f&&f.containerElement==i?f.nodeIndex:0,t=i.childNodes.length,u=t,v=u;;){if(v==t?i.appendChild(l):i.insertBefore(l,i.childNodes[v]),h.moveToElementText(l),m=h.compareEndPoints(r,a),0==m||s==u)break;if(-1==m){if(u==s+1)break;s=v}else u=u==s+1?s:v;v=Math.floor((s+u)/2),i.removeChild(l)}if(q=l.nextSibling,-1==m&&q&&k(q)){h.setEndPoint(c?"EndToStart":"EndToEnd",a);var w;if(/[\r\n]/.test(q.data)){var x=h.duplicate(),y=x.text.replace(/\r\n/g,"\r").length;for(w=x.moveStart("character",y);-1==(m=x.compareEndPoints("StartToEnd",x));)w++,x.moveStart("character",1)}else w=h.text.length;p=new g(q,w)}else n=(d||!c)&&l.previousSibling,o=(d||c)&&l.nextSibling,p=o&&k(o)?new g(o,0):n&&k(n)?new g(n,n.data.length):new g(i,e.getNodeIndex(l));return l.parentNode.removeChild(l),{boundaryPosition:p,nodeInfo:{nodeIndex:v,containerElement:i}}},o=function(a,b){var c,d,f,g,h=a.offset,j=e.getDocument(a.node),l=i(j).createTextRange(),m=k(a.node);return m?(c=a.node,d=c.parentNode):(g=a.node.childNodes,c=h<g.length?g[h]:null,d=a.node),f=j.createElement("span"),f.innerHTML="&#feff;",c?d.insertBefore(f,c):d.appendChild(f),l.moveToElementText(f),l.collapse(!b),d.removeChild(f),m&&l[b?"moveStart":"moveEnd"]("character",h),l};d=function(a){this.textRange=a,this.refresh()},d.prototype=new h(document),d.prototype.refresh=function(){var a,b,c,d=l(this.textRange);m(this.textRange)?b=a=n(this.textRange,d,!0,!0).boundaryPosition:(c=n(this.textRange,d,!0,!1),a=c.boundaryPosition,b=n(this.textRange,d,!1,!1,c.nodeInfo).boundaryPosition),this.setStart(a.node,a.offset),this.setEnd(b.node,b.offset)},d.prototype.getName=function(){return"WrappedTextRange"},h.copyComparisonConstants(d);var p=function(a){if(a.collapsed)return o(new g(a.startContainer,a.startOffset),!0);var b=o(new g(a.startContainer,a.startOffset),!0),c=o(new g(a.endContainer,a.endOffset),!1),d=i(h.getRangeDocument(a)).createTextRange();return d.setEndPoint("StartToStart",b),d.setEndPoint("EndToEnd",c),d};if(d.rangeToTextRange=p,d.prototype.toTextRange=function(){return p(this)},a.WrappedTextRange=d,!a.features.implementsDomRange||a.config.preferTextRange){var q=function(a){return a("return this;")()}(Function);"undefined"==typeof q.Range&&(q.Range=d),a.createNativeRange=function(a){return a=j(a,b,"createNativeRange"),i(a).createTextRange()},a.WrappedRange=d}}a.createRange=function(c){return c=j(c,b,"createRange"),new a.WrappedRange(a.createNativeRange(c))},a.createRangyRange=function(a){return a=j(a,b,"createRangyRange"),new h(a)},a.createIframeRange=function(c){return b.deprecationNotice("createIframeRange()","createRange(iframeEl)"),a.createRange(c)},a.createIframeRangyRange=function(c){return b.deprecationNotice("createIframeRangyRange()","createRangyRange(iframeEl)"),a.createRangyRange(c)},a.addShimListener(function(b){var c=b.document;"undefined"==typeof c.createRange&&(c.createRange=function(){return a.createRange(c)}),c=b=null})}),E.createCoreModule("WrappedSelection",["DomRange","WrappedRange"],function(a,b){function c(a){return"string"==typeof a?/^backward(s)?$/i.test(a):!!a}function d(a,c){if(a){if(C.isWindow(a))return a;if(a instanceof r)return a.win;var d=C.getContentDocument(a,b,c);return C.getWindow(d)}return window}function e(a){return d(a,"getWinSelection").getSelection()}function f(a){return d(a,"getDocSelection").document.selection}function g(a){var b=!1;return a.anchorNode&&(b=1==C.comparePoints(a.anchorNode,a.anchorOffset,a.focusNode,a.focusOffset)),b}function h(a,b,c){var d=c?"end":"start",e=c?"start":"end";a.anchorNode=b[d+"Container"],a.anchorOffset=b[d+"Offset"],a.focusNode=b[e+"Container"],a.focusOffset=b[e+"Offset"]}function i(a){var b=a.nativeSelection;a.anchorNode=b.anchorNode,a.anchorOffset=b.anchorOffset,a.focusNode=b.focusNode,a.focusOffset=b.focusOffset}function j(a){a.anchorNode=a.focusNode=null,a.anchorOffset=a.focusOffset=0,a.rangeCount=0,a.isCollapsed=!0,a._ranges.length=0}function k(b){var c;return b instanceof F?(c=a.createNativeRange(b.getDocument()),c.setEnd(b.endContainer,b.endOffset),c.setStart(b.startContainer,b.startOffset)):b instanceof G?c=b.nativeRange:J.implementsDomRange&&b instanceof C.getWindow(b.startContainer).Range&&(c=b),c}function l(a){if(!a.length||1!=a[0].nodeType)return!1;for(var b=1,c=a.length;c>b;++b)if(!C.isAncestorOf(a[0],a[b]))return!1;return!0}function m(a){var c=a.getNodes();if(!l(c))throw b.createError("getSingleElementFromRange: range "+a.inspect()+" did not consist of a single element");return c[0]}function n(a){return!!a&&"undefined"!=typeof a.text}function o(a,b){var c=new G(b);a._ranges=[c],h(a,c,!1),a.rangeCount=1,a.isCollapsed=c.collapsed}function p(b){if(b._ranges.length=0,"None"==b.docSelection.type)j(b);else{var c=b.docSelection.createRange();if(n(c))o(b,c);else{b.rangeCount=c.length;for(var d,e=L(c.item(0)),f=0;f<b.rangeCount;++f)d=a.createRange(e),d.selectNode(c.item(f)),b._ranges.push(d);b.isCollapsed=1==b.rangeCount&&b._ranges[0].collapsed,h(b,b._ranges[b.rangeCount-1],!1)}}}function q(a,c){for(var d=a.docSelection.createRange(),e=m(c),f=L(d.item(0)),g=M(f).createControlRange(),h=0,i=d.length;i>h;++h)g.add(d.item(h));try{g.add(e)}catch(j){throw b.createError("addRange(): Element within the specified Range could not be added to control selection (does it have layout?)")}g.select(),p(a)}function r(a,b,c){this.nativeSelection=a,this.docSelection=b,this._ranges=[],this.win=c,this.refresh()}function s(a){a.win=a.anchorNode=a.focusNode=a._ranges=null,a.rangeCount=a.anchorOffset=a.focusOffset=0,a.detached=!0}function t(a,b){for(var c,d,e=bb.length;e--;)if(c=bb[e],d=c.selection,"deleteAll"==b)s(d);else if(c.win==a)return"delete"==b?(bb.splice(e,1),!0):d;return"deleteAll"==b&&(bb.length=0),null}function u(a,c){for(var d,e=L(c[0].startContainer),f=M(e).createControlRange(),g=0,h=c.length;h>g;++g){d=m(c[g]);try{f.add(d)}catch(i){throw b.createError("setRanges(): Element within one of the specified Ranges could not be added to control selection (does it have layout?)")}}f.select(),p(a)}function v(a,b){if(a.win.document!=L(b))throw new H("WRONG_DOCUMENT_ERR")}function w(b){return function(c,d){var e;this.rangeCount?(e=this.getRangeAt(0),e["set"+(b?"Start":"End")](c,d)):(e=a.createRange(this.win.document),e.setStartAndEnd(c,d)),this.setSingleRange(e,this.isBackward())}}function x(a){var b=[],c=new I(a.anchorNode,a.anchorOffset),d=new I(a.focusNode,a.focusOffset),e="function"==typeof a.getName?a.getName():"Selection";if("undefined"!=typeof a.rangeCount)for(var f=0,g=a.rangeCount;g>f;++f)b[f]=F.inspect(a.getRangeAt(f));return"["+e+"(Ranges: "+b.join(", ")+")(anchor: "+c.inspect()+", focus: "+d.inspect()+"]"}a.config.checkSelectionRanges=!0;var y,z,A="boolean",B="number",C=a.dom,D=a.util,E=D.isHostMethod,F=a.DomRange,G=a.WrappedRange,H=a.DOMException,I=C.DomPosition,J=a.features,K="Control",L=C.getDocument,M=C.getBody,N=F.rangesEqual,O=E(window,"getSelection"),P=D.isHostObject(document,"selection");J.implementsWinGetSelection=O,J.implementsDocSelection=P;var Q=P&&(!O||a.config.preferTextRange);Q?(y=f,a.isSelectionValid=function(a){var b=d(a,"isSelectionValid").document,c=b.selection;return"None"!=c.type||L(c.createRange().parentElement())==b}):O?(y=e,a.isSelectionValid=function(){return!0}):b.fail("Neither document.selection or window.getSelection() detected."),a.getNativeSelection=y;var R=y(),S=a.createNativeRange(document),T=M(document),U=D.areHostProperties(R,["anchorNode","focusNode","anchorOffset","focusOffset"]);J.selectionHasAnchorAndFocus=U;var V=E(R,"extend");J.selectionHasExtend=V;var W=typeof R.rangeCount==B;J.selectionHasRangeCount=W;var X=!1,Y=!0,Z=V?function(b,c){var d=F.getRangeDocument(c),e=a.createRange(d);e.collapseToPoint(c.endContainer,c.endOffset),b.addRange(k(e)),b.extend(c.startContainer,c.startOffset)}:null;D.areHostMethods(R,["addRange","getRangeAt","removeAllRanges"])&&typeof R.rangeCount==B&&J.implementsDomRange&&!function(){var b=window.getSelection();if(b){for(var c=b.rangeCount,d=c>1,e=[],f=g(b),h=0;c>h;++h)e[h]=b.getRangeAt(h);var i=M(document),j=i.appendChild(document.createElement("div"));j.contentEditable="false";var k=j.appendChild(document.createTextNode(" ")),l=document.createRange();if(l.setStart(k,1),l.collapse(!0),b.addRange(l),Y=1==b.rangeCount,b.removeAllRanges(),!d){var m=window.navigator.appVersion.match(/Chrome\/(.*?) /);if(m&&parseInt(m[1])>=36)X=!1;else{var n=l.cloneRange();l.setStart(k,0),n.setEnd(k,3),n.setStart(k,2),b.addRange(l),b.addRange(n),X=2==b.rangeCount}}for(i.removeChild(j),b.removeAllRanges(),h=0;c>h;++h)0==h&&f?Z?Z(b,e[h]):(a.warn("Rangy initialization: original selection was backwards but selection has been restored forwards because the browser does not support Selection.extend"),b.addRange(e[h])):b.addRange(e[h])}}(),J.selectionSupportsMultipleRanges=X,J.collapsedNonEditableSelectionsSupported=Y;var $,_=!1;T&&E(T,"createControlRange")&&($=T.createControlRange(),D.areHostProperties($,["item","add"])&&(_=!0)),J.implementsControlRange=_,z=U?function(a){return a.anchorNode===a.focusNode&&a.anchorOffset===a.focusOffset}:function(a){return a.rangeCount?a.getRangeAt(a.rangeCount-1).collapsed:!1};var ab;E(R,"getRangeAt")?ab=function(a,b){try{return a.getRangeAt(b)}catch(c){return null}}:U&&(ab=function(b){var c=L(b.anchorNode),d=a.createRange(c);return d.setStartAndEnd(b.anchorNode,b.anchorOffset,b.focusNode,b.focusOffset),d.collapsed!==this.isCollapsed&&d.setStartAndEnd(b.focusNode,b.focusOffset,b.anchorNode,b.anchorOffset),d}),r.prototype=a.selectionPrototype;var bb=[],cb=function(a){if(a&&a instanceof r)return a.refresh(),a;a=d(a,"getNativeSelection");var b=t(a),c=y(a),e=P?f(a):null;return b?(b.nativeSelection=c,b.docSelection=e,b.refresh()):(b=new r(c,e,a),bb.push({win:a,selection:b})),b};a.getSelection=cb,a.getIframeSelection=function(c){return b.deprecationNotice("getIframeSelection()","getSelection(iframeEl)"),a.getSelection(C.getIframeWindow(c))};var db=r.prototype;if(!Q&&U&&D.areHostMethods(R,["removeAllRanges","addRange"])){db.removeAllRanges=function(){this.nativeSelection.removeAllRanges(),j(this)};var eb=function(a,b){Z(a.nativeSelection,b),a.refresh()};db.addRange=W?function(b,d){if(_&&P&&this.docSelection.type==K)q(this,b);else if(c(d)&&V)eb(this,b);else{var e;X?e=this.rangeCount:(this.removeAllRanges(),e=0);var f=k(b).cloneRange();try{this.nativeSelection.addRange(f)}catch(g){}if(this.rangeCount=this.nativeSelection.rangeCount,this.rangeCount==e+1){if(a.config.checkSelectionRanges){var i=ab(this.nativeSelection,this.rangeCount-1);i&&!N(i,b)&&(b=new G(i))}this._ranges[this.rangeCount-1]=b,h(this,b,hb(this.nativeSelection)),this.isCollapsed=z(this)}else this.refresh()}}:function(a,b){c(b)&&V?eb(this,a):(this.nativeSelection.addRange(k(a)),this.refresh())},db.setRanges=function(a){if(_&&P&&a.length>1)u(this,a);else{this.removeAllRanges();for(var b=0,c=a.length;c>b;++b)this.addRange(a[b])}}}else{if(!(E(R,"empty")&&E(S,"select")&&_&&Q))return b.fail("No means of selecting a Range or TextRange was found"),!1;db.removeAllRanges=function(){try{if(this.docSelection.empty(),"None"!=this.docSelection.type){var a;if(this.anchorNode)a=L(this.anchorNode);else if(this.docSelection.type==K){var b=this.docSelection.createRange();b.length&&(a=L(b.item(0)))}if(a){var c=M(a).createTextRange();c.select(),this.docSelection.empty()}}}catch(d){}j(this)},db.addRange=function(b){this.docSelection.type==K?q(this,b):(a.WrappedTextRange.rangeToTextRange(b).select(),this._ranges[0]=b,this.rangeCount=1,this.isCollapsed=this._ranges[0].collapsed,h(this,b,!1))},db.setRanges=function(a){this.removeAllRanges();var b=a.length;b>1?u(this,a):b&&this.addRange(a[0])}}db.getRangeAt=function(a){if(0>a||a>=this.rangeCount)throw new H("INDEX_SIZE_ERR");return this._ranges[a].cloneRange()};var fb;if(Q)fb=function(b){var c;a.isSelectionValid(b.win)?c=b.docSelection.createRange():(c=M(b.win.document).createTextRange(),c.collapse(!0)),b.docSelection.type==K?p(b):n(c)?o(b,c):j(b)};else if(E(R,"getRangeAt")&&typeof R.rangeCount==B)fb=function(b){if(_&&P&&b.docSelection.type==K)p(b);else if(b._ranges.length=b.rangeCount=b.nativeSelection.rangeCount,b.rangeCount){for(var c=0,d=b.rangeCount;d>c;++c)b._ranges[c]=new a.WrappedRange(b.nativeSelection.getRangeAt(c));h(b,b._ranges[b.rangeCount-1],hb(b.nativeSelection)),b.isCollapsed=z(b)}else j(b)};else{if(!U||typeof R.isCollapsed!=A||typeof S.collapsed!=A||!J.implementsDomRange)return b.fail("No means of obtaining a Range or TextRange from the user's selection was found"),!1;fb=function(a){var b,c=a.nativeSelection;c.anchorNode?(b=ab(c,0),a._ranges=[b],a.rangeCount=1,i(a),a.isCollapsed=z(a)):j(a)}}db.refresh=function(a){var b=a?this._ranges.slice(0):null,c=this.anchorNode,d=this.anchorOffset;if(fb(this),a){var e=b.length;if(e!=this._ranges.length)return!0;if(this.anchorNode!=c||this.anchorOffset!=d)return!0;for(;e--;)if(!N(b[e],this._ranges[e]))return!0;return!1}};var gb=function(a,b){var c=a.getAllRanges();a.removeAllRanges();for(var d=0,e=c.length;e>d;++d)N(b,c[d])||a.addRange(c[d]);a.rangeCount||j(a)};db.removeRange=_&&P?function(a){if(this.docSelection.type==K){for(var b,c=this.docSelection.createRange(),d=m(a),e=L(c.item(0)),f=M(e).createControlRange(),g=!1,h=0,i=c.length;i>h;++h)b=c.item(h),b!==d||g?f.add(c.item(h)):g=!0;f.select(),p(this)}else gb(this,a)}:function(a){gb(this,a)};var hb;!Q&&U&&J.implementsDomRange?(hb=g,db.isBackward=function(){return hb(this)}):hb=db.isBackward=function(){return!1},db.isBackwards=db.isBackward,db.toString=function(){for(var a=[],b=0,c=this.rangeCount;c>b;++b)a[b]=""+this._ranges[b];return a.join("")},db.collapse=function(b,c){v(this,b);var d=a.createRange(b);d.collapseToPoint(b,c),this.setSingleRange(d),this.isCollapsed=!0},db.collapseToStart=function(){if(!this.rangeCount)throw new H("INVALID_STATE_ERR");var a=this._ranges[0];this.collapse(a.startContainer,a.startOffset)},db.collapseToEnd=function(){if(!this.rangeCount)throw new H("INVALID_STATE_ERR");var a=this._ranges[this.rangeCount-1];this.collapse(a.endContainer,a.endOffset)},db.selectAllChildren=function(b){v(this,b);var c=a.createRange(b);c.selectNodeContents(b),this.setSingleRange(c)},db.deleteFromDocument=function(){if(_&&P&&this.docSelection.type==K){for(var a,b=this.docSelection.createRange();b.length;)a=b.item(0),b.remove(a),a.parentNode.removeChild(a);this.refresh()}else if(this.rangeCount){var c=this.getAllRanges();if(c.length){this.removeAllRanges();for(var d=0,e=c.length;e>d;++d)c[d].deleteContents();this.addRange(c[e-1])}}},db.eachRange=function(a,b){for(var c=0,d=this._ranges.length;d>c;++c)if(a(this.getRangeAt(c)))return b},db.getAllRanges=function(){var a=[];return this.eachRange(function(b){a.push(b)}),a},db.setSingleRange=function(a,b){this.removeAllRanges(),this.addRange(a,b)},db.callMethodOnEachRange=function(a,b){var c=[];return this.eachRange(function(d){c.push(d[a].apply(d,b))}),c},db.setStart=w(!0),db.setEnd=w(!1),a.rangePrototype.select=function(a){cb(this.getDocument()).setSingleRange(this,a)},db.changeEachRange=function(a){var b=[],c=this.isBackward();this.eachRange(function(c){a(c),b.push(c)}),this.removeAllRanges(),c&&1==b.length?this.addRange(b[0],"backward"):this.setRanges(b)},db.containsNode=function(a,b){return this.eachRange(function(c){return c.containsNode(a,b)},!0)||!1},db.getBookmark=function(a){return{backward:this.isBackward(),rangeBookmarks:this.callMethodOnEachRange("getBookmark",[a])}},db.moveToBookmark=function(b){for(var c,d,e=[],f=0;c=b.rangeBookmarks[f++];)d=a.createRange(this.win),d.moveToBookmark(c),e.push(d);b.backward?this.setSingleRange(e[0],"backward"):this.setRanges(e)},db.toHtml=function(){var a=[];return this.eachRange(function(b){a.push(F.toHtml(b))}),a.join("")},J.implementsTextRange&&(db.getNativeTextRange=function(){var c;if(c=this.docSelection){var d=c.createRange();if(n(d))return d;throw b.createError("getNativeTextRange: selection is a control selection")}if(this.rangeCount>0)return a.WrappedTextRange.rangeToTextRange(this.getRangeAt(0));throw b.createError("getNativeTextRange: selection contains no range")}),db.getName=function(){return"WrappedSelection"},db.inspect=function(){return x(this)},db.detach=function(){t(this.win,"delete"),s(this)},r.detachAll=function(){t(null,"deleteAll")},r.inspect=x,r.isDirectionBackward=c,a.Selection=r,a.selectionPrototype=db,a.addShimListener(function(a){"undefined"==typeof a.getSelection&&(a.getSelection=function(){return cb(a)}),a=null})});var J=!1,K=function(){J||(J=!0,!E.initialized&&E.config.autoInitialize&&l())};return C&&("complete"==document.readyState?K():(a(document,"addEventListener")&&document.addEventListener("DOMContentLoaded",K,!1),G(window,"load",K))),E},this),function(a,b){"function"==typeof define&&define.amd?define(["./rangy-core"],a):"undefined"!=typeof module&&"object"==typeof exports?module.exports=a(require("rangy")):a(b.rangy)}(function(a){a.createModule("SaveRestore",["WrappedRange"],function(a,b){function c(a,b){return(b||document).getElementById(a)}function d(a,b){var c,d="selectionBoundary_"+ +new Date+"_"+(""+Math.random()).slice(2),e=o.getDocument(a.startContainer),f=a.cloneRange();return f.collapse(b),c=e.createElement("span"),c.id=d,c.style.lineHeight="0",c.style.display="none",c.className="rangySelectionBoundary",c.appendChild(e.createTextNode(p)),f.insertNode(c),c}function e(a,d,e,f){var g=c(e,a);g?(d[f?"setStartBefore":"setEndBefore"](g),g.parentNode.removeChild(g)):b.warn("Marker element has been removed. Cannot restore selection.")}function f(a,b){return b.compareBoundaryPoints(a.START_TO_START,a)}function g(b,c){var e,f,g=a.DomRange.getRangeDocument(b),h=b.toString();return b.collapsed?(f=d(b,!1),{document:g,markerId:f.id,collapsed:!0}):(f=d(b,!1),e=d(b,!0),{document:g,startMarkerId:e.id,endMarkerId:f.id,collapsed:!1,backward:c,toString:function(){return"original text: '"+h+"', new text: '"+b.toString()+"'"}})}function h(d,f){var g=d.document;"undefined"==typeof f&&(f=!0);var h=a.createRange(g);if(d.collapsed){var i=c(d.markerId,g);if(i){i.style.display="inline";var j=i.previousSibling;j&&3==j.nodeType?(i.parentNode.removeChild(i),h.collapseToPoint(j,j.length)):(h.collapseBefore(i),i.parentNode.removeChild(i))}else b.warn("Marker element has been removed. Cannot restore selection.")}else e(g,h,d.startMarkerId,!0),e(g,h,d.endMarkerId,!1);return f&&h.normalizeBoundaries(),h}function i(b,d){var e,h,i=[];b=b.slice(0),b.sort(f);for(var j=0,k=b.length;k>j;++j)i[j]=g(b[j],d);for(j=k-1;j>=0;--j)e=b[j],h=a.DomRange.getRangeDocument(e),e.collapsed?e.collapseAfter(c(i[j].markerId,h)):(e.setEndBefore(c(i[j].endMarkerId,h)),e.setStartAfter(c(i[j].startMarkerId,h)));return i}function j(c){if(!a.isSelectionValid(c))return b.warn("Cannot save selection. This usually happens when the selection is collapsed and the selection document has lost focus."),null;var d=a.getSelection(c),e=d.getAllRanges(),f=1==e.length&&d.isBackward(),g=i(e,f);return f?d.setSingleRange(e[0],"backward"):d.setRanges(e),{win:c,rangeInfos:g,restored:!1}}function k(a){for(var b=[],c=a.length,d=c-1;d>=0;d--)b[d]=h(a[d],!0);return b}function l(b,c){if(!b.restored){var d=b.rangeInfos,e=a.getSelection(b.win),f=k(d),g=d.length;1==g&&c&&a.features.selectionHasExtend&&d[0].backward?(e.removeAllRanges(),e.addRange(f[0],!0)):e.setRanges(f),b.restored=!0}}function m(a,b){var d=c(b,a);d&&d.parentNode.removeChild(d)}function n(a){for(var b,c=a.rangeInfos,d=0,e=c.length;e>d;++d)b=c[d],b.collapsed?m(a.doc,b.markerId):(m(a.doc,b.startMarkerId),m(a.doc,b.endMarkerId))}var o=a.dom,p="";a.util.extend(a,{saveRange:g,restoreRange:h,saveRanges:i,restoreRanges:k,saveSelection:j,restoreSelection:l,removeMarkerElement:m,removeMarkers:n})})},this);var Base=function(){};Base.extend=function(a,b){var c=Base.prototype.extend;Base._prototyping=!0;var d=new this;c.call(d,a),d.base=function(){},delete Base._prototyping;var e=d.constructor,f=d.constructor=function(){if(!Base._prototyping)if(this._constructing||this.constructor==f)this._constructing=!0,e.apply(this,arguments),delete this._constructing;else if(null!=arguments[0])return(arguments[0].extend||c).call(arguments[0],d)};return f.ancestor=this,f.extend=this.extend,f.forEach=this.forEach,f.implement=this.implement,f.prototype=d,f.toString=this.toString,f.valueOf=function(a){return"object"==a?f:e.valueOf()},c.call(f,b),"function"==typeof f.init&&f.init(),f},Base.prototype={extend:function(a,b){if(arguments.length>1){var c=this[a];if(c&&"function"==typeof b&&(!c.valueOf||c.valueOf()!=b.valueOf())&&/\bbase\b/.test(b)){var d=b.valueOf();b=function(){var a=this.base||Base.prototype.base;this.base=c;var b=d.apply(this,arguments);return this.base=a,b},b.valueOf=function(a){return"object"==a?b:d},b.toString=Base.toString}this[a]=b}else if(a){var e=Base.prototype.extend;Base._prototyping||"function"==typeof this||(e=this.extend||e);for(var f={toSource:null},g=["constructor","toString","valueOf"],h=Base._prototyping?0:1;i=g[h++];)a[i]!=f[i]&&e.call(this,i,a[i]);for(var i in a)f[i]||e.call(this,i,a[i])}return this}},Base=Base.extend({constructor:function(){this.extend(arguments[0])}},{ancestor:Object,version:"1.1",forEach:function(a,b,c){for(var d in a)void 0===this.prototype[d]&&b.call(c,a[d],d,a)},implement:function(){for(var a=0;a<arguments.length;a++)"function"==typeof arguments[a]?arguments[a](this.prototype):this.prototype.extend(arguments[a]);return this},toString:function(){return String(this.valueOf())}}),wysihtml5.browser=function(){function a(a){return+(/ipad|iphone|ipod/.test(a)&&a.match(/ os (\d+).+? like mac os x/)||[void 0,0])[1]}function b(a){return+(a.match(/android (\d+)/)||[void 0,0])[1]}function c(a,b){var c,d=-1;return"Microsoft Internet Explorer"==navigator.appName?c=new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})"):"Netscape"==navigator.appName&&(c=new RegExp("Trident/.*rv:([0-9]{1,}[.0-9]{0,})")),c&&null!=c.exec(navigator.userAgent)&&(d=parseFloat(RegExp.$1)),-1===d?!1:a?b?"<"===b?d>a:">"===b?a>d:"<="===b?d>=a:">="===b?a>=d:void 0:a===d:!0}var d=navigator.userAgent,e=document.createElement("div"),f=-1!==d.indexOf("Gecko")&&-1===d.indexOf("KHTML"),g=-1!==d.indexOf("AppleWebKit/"),h=-1!==d.indexOf("Chrome/"),i=-1!==d.indexOf("Opera/");return{USER_AGENT:d,supported:function(){var c=this.USER_AGENT.toLowerCase(),d="contentEditable"in e,f=document.execCommand&&document.queryCommandSupported&&document.queryCommandState,g=document.querySelector&&document.querySelectorAll,h=this.isIos()&&a(c)<5||this.isAndroid()&&b(c)<4||-1!==c.indexOf("opera mobi")||-1!==c.indexOf("hpwos/");return d&&f&&g&&!h},isTouchDevice:function(){return this.supportsEvent("touchmove")},isIos:function(){return/ipad|iphone|ipod/i.test(this.USER_AGENT)},isAndroid:function(){return-1!==this.USER_AGENT.indexOf("Android")},supportsSandboxedIframes:function(){return c()},throwsMixedContentWarningWhenIframeSrcIsEmpty:function(){return!("querySelector"in document)},displaysCaretInEmptyContentEditableCorrectly:function(){return c()},hasCurrentStyleProperty:function(){return"currentStyle"in e},insertsLineBreaksOnReturn:function(){return f},supportsPlaceholderAttributeOn:function(a){return"placeholder"in a},supportsEvent:function(a){return"on"+a in e||function(){return e.setAttribute("on"+a,"return;"),"function"==typeof e["on"+a]}()},supportsEventsInIframeCorrectly:function(){return!i},supportsHTML5Tags:function(a){var b=a.createElement("div"),c="<article>foo</article>";return b.innerHTML=c,b.innerHTML.toLowerCase()===c},supportsCommand:function(){var a={formatBlock:c(10,"<="),insertUnorderedList:c(),insertOrderedList:c()},b={insertHTML:f};return function(c,d){var e=a[d];if(!e){try{return c.queryCommandSupported(d)}catch(f){}try{return c.queryCommandEnabled(d)}catch(g){return!!b[d]}}return!1}}(),doesAutoLinkingInContentEditable:function(){return c()},canDisableAutoLinking:function(){return this.supportsCommand(document,"AutoUrlDetect")},clearsContentEditableCorrectly:function(){return f||i||g},supportsGetAttributeCorrectly:function(){var a=document.createElement("td");return"1"!=a.getAttribute("rowspan")},canSelectImagesInContentEditable:function(){return f||c()||i},autoScrollsToCaret:function(){return!g},autoClosesUnclosedTags:function(){var a,b,c=e.cloneNode(!1);return c.innerHTML="<p><div></div>",b=c.innerHTML.toLowerCase(),a="<p></p><div></div>"===b||"<p><div></div></p>"===b,this.autoClosesUnclosedTags=function(){return a},a},supportsNativeGetElementsByClassName:function(){return-1!==String(document.getElementsByClassName).indexOf("[native code]")},supportsSelectionModify:function(){return"getSelection"in window&&"modify"in window.getSelection()},needsSpaceAfterLineBreak:function(){return i},supportsSpeechApiOn:function(a){var b=d.match(/Chrome\/(\d+)/)||[void 0,0];return b[1]>=11&&("onwebkitspeechchange"in a||"speech"in a)},crashesWhenDefineProperty:function(a){return c(9)&&("XMLHttpRequest"===a||"XDomainRequest"===a)},doesAsyncFocus:function(){return c()},hasProblemsSettingCaretAfterImg:function(){return c()},hasUndoInContextMenu:function(){return f||h||i},hasInsertNodeIssue:function(){return i},hasIframeFocusIssue:function(){return c()},createsNestedInvalidMarkupAfterPaste:function(){return g},supportsMutationEvents:function(){return"MutationEvent"in window},supportsModenPaste:function(){return!("clipboardData"in window)}}}(),wysihtml5.lang.array=function(a){return{contains:function(b){if(Array.isArray(b)){for(var c=b.length;c--;)if(-1!==wysihtml5.lang.array(a).indexOf(b[c]))return!0;return!1}return-1!==wysihtml5.lang.array(a).indexOf(b)},indexOf:function(b){if(a.indexOf)return a.indexOf(b);for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1},without:function(b){b=wysihtml5.lang.array(b);for(var c=[],d=0,e=a.length;e>d;d++)b.contains(a[d])||c.push(a[d]);return c},get:function(){for(var b=0,c=a.length,d=[];c>b;b++)d.push(a[b]);return d},map:function(b,c){if(Array.prototype.map)return a.map(b,c);for(var d=a.length>>>0,e=new Array(d),f=0;d>f;f++)e[f]=b.call(c,a[f],f,a);return e},unique:function(){for(var b=[],c=a.length,d=0;c>d;)wysihtml5.lang.array(b).contains(a[d])||b.push(a[d]),d++;return b}}},wysihtml5.lang.Dispatcher=Base.extend({on:function(a,b){return this.events=this.events||{},this.events[a]=this.events[a]||[],this.events[a].push(b),this},off:function(a,b){this.events=this.events||{};var c,d,e=0;if(a){for(c=this.events[a]||[],d=[];e<c.length;e++)c[e]!==b&&b&&d.push(c[e]);this.events[a]=d}else this.events={};return this},fire:function(a,b){this.events=this.events||{};for(var c=this.events[a]||[],d=0;d<c.length;d++)c[d].call(this,b);return this},observe:function(){return this.on.apply(this,arguments)},stopObserving:function(){return this.off.apply(this,arguments)}}),wysihtml5.lang.object=function(a){return{merge:function(b){for(var c in b)a[c]=b[c];return this},get:function(){return a},clone:function(b){var c,d={};if(null===a||!wysihtml5.lang.object(a).isPlainObject())return a;for(c in a)a.hasOwnProperty(c)&&(d[c]=b?wysihtml5.lang.object(a[c]).clone(b):a[c]);return d},isArray:function(){return"[object Array]"===Object.prototype.toString.call(a)},isFunction:function(){return"[object Function]"===Object.prototype.toString.call(a)},isPlainObject:function(){return"[object Object]"===Object.prototype.toString.call(a)}}},function(){var a=/^\s+/,b=/\s+$/,c=/[&<>\t"]/g,d={"&":"&","<":"<",">":">",'"':"""," ":" "};wysihtml5.lang.string=function(e){return e=String(e),{trim:function(){return e.replace(a,"").replace(b,"")},interpolate:function(a){for(var b in a)e=this.replace("#{"+b+"}").by(a[b]);return e},replace:function(a){return{by:function(b){return e.split(a).join(b)}}},escapeHTML:function(a,b){var f=e.replace(c,function(a){return d[a]});return a&&(f=f.replace(/(?:\r\n|\r|\n)/g,"<br />")),b&&(f=f.replace(/ /gi," ")),f}}}}(),function(a){function b(a,b){return f(a,b)?a:(a===a.ownerDocument.documentElement&&(a=a.ownerDocument.body),g(a,b))}function c(a){return a.replace(i,function(a,b){var c=(b.match(j)||[])[1]||"",d=l[c];b=b.replace(j,""),b.split(d).length>b.split(c).length&&(b+=c,c="");var e=b,f=b;return b.length>k&&(f=f.substr(0,k)+"..."),"www."===e.substr(0,4)&&(e="http://"+e),'<a href="'+e+'">'+f+"</a>"+c})}function d(a){var b=a._wysihtml5_tempElement;return b||(b=a._wysihtml5_tempElement=a.createElement("div")),b}function e(b){var e=b.parentNode,f=a.lang.string(b.data).escapeHTML(),g=d(e.ownerDocument);for(g.innerHTML="<span></span>"+c(f),g.removeChild(g.firstChild);g.firstChild;)e.insertBefore(g.firstChild,b);e.removeChild(b)}function f(b,c){for(var d;b.parentNode;){if(b=b.parentNode,d=b.nodeName,b.className&&a.lang.array(b.className.split(" ")).contains(c))return!0;if(h.contains(d))return!0;if("body"===d)return!1}return!1}function g(b,c){if(!(h.contains(b.nodeName)||b.className&&a.lang.array(b.className.split(" ")).contains(c))){if(b.nodeType===a.TEXT_NODE&&b.data.match(i))return void e(b);for(var d=a.lang.array(b.childNodes).get(),f=d.length,j=0;f>j;j++)g(d[j],c);return b}}var h=a.lang.array(["CODE","PRE","A","SCRIPT","HEAD","TITLE","STYLE"]),i=/((https?:\/\/|www\.)[^\s<]{3,})/gi,j=/([^\w\/\-](,?))$/i,k=100,l={")":"(","]":"[","}":"{"};a.dom.autoLink=b,a.dom.autoLink.URL_REG_EXP=i}(wysihtml5),function(a){var b=a.dom;b.addClass=function(a,c){var d=a.classList;return d?d.add(c):void(b.hasClass(a,c)||(a.className+=" "+c))},b.removeClass=function(a,b){var c=a.classList;return c?c.remove(b):void(a.className=a.className.replace(new RegExp("(^|\\s+)"+b+"(\\s+|$)")," "))},b.hasClass=function(a,b){var c=a.classList;if(c)return c.contains(b);var d=a.className;return d.length>0&&(d==b||new RegExp("(^|\\s)"+b+"(\\s|$)").test(d))}}(wysihtml5),wysihtml5.dom.contains=function(){var a=document.documentElement;return a.contains?function(a,b){return b.nodeType!==wysihtml5.ELEMENT_NODE&&(b=b.parentNode),a!==b&&a.contains(b)}:a.compareDocumentPosition?function(a,b){return!!(16&a.compareDocumentPosition(b))}:void 0}(),wysihtml5.dom.convertToList=function(){function a(a,b){var c=a.createElement("li");return b.appendChild(c),c}function b(a,b){return a.createElement(b)}function c(c,d,e){if("UL"===c.nodeName||"OL"===c.nodeName||"MENU"===c.nodeName)return c;var f,g,h,i,j,k,l,m,n,o=c.ownerDocument,p=b(o,d),q=c.querySelectorAll("br"),r=q.length;for(n=0;r>n;n++)for(i=q[n];(j=i.parentNode)&&j!==c&&j.lastChild===i;){if("block"===wysihtml5.dom.getStyle("display").from(j)){j.removeChild(i);break}wysihtml5.dom.insert(i).after(i.parentNode)}for(f=wysihtml5.lang.array(c.childNodes).get(),g=f.length,n=0;g>n;n++)m=m||a(o,p),h=f[n],k="block"===wysihtml5.dom.getStyle("display").from(h),l="BR"===h.nodeName,!k||e&&wysihtml5.dom.hasClass(h,e)?l?m=m.firstChild?null:m:m.appendChild(h):(m=m.firstChild?a(o,p):m,m.appendChild(h),m=null);return 0===f.length&&a(o,p),c.parentNode.replaceChild(p,c),p}return c}(),wysihtml5.dom.copyAttributes=function(a){return{from:function(b){return{to:function(c){for(var d,e=0,f=a.length;f>e;e++)d=a[e],"undefined"!=typeof b[d]&&""!==b[d]&&(c[d]=b[d]);return{andTo:arguments.callee}}}}}},function(a){var b=["-webkit-box-sizing","-moz-box-sizing","-ms-box-sizing","box-sizing"],c=function(b){return d(b)?parseInt(a.getStyle("width").from(b),10)<b.offsetWidth:!1},d=function(c){for(var d=0,e=b.length;e>d;d++)if("border-box"===a.getStyle(b[d]).from(c))return b[d]};a.copyStyles=function(d){return{from:function(e){c(e)&&(d=wysihtml5.lang.array(d).without(b));for(var f,g="",h=d.length,i=0;h>i;i++)f=d[i],g+=f+":"+a.getStyle(f).from(e)+";";return{to:function(b){return a.setStyles(g).on(b),{andTo:arguments.callee}}}}}}}(wysihtml5.dom),function(a){a.dom.delegate=function(b,c,d,e){return a.dom.observe(b,d,function(d){for(var f=d.target,g=a.lang.array(b.querySelectorAll(c));f&&f!==b;){if(g.contains(f)){e.call(f,d);break}f=f.parentNode}})}}(wysihtml5),function(a){a.dom.domNode=function(b){var c=[a.ELEMENT_NODE,a.TEXT_NODE],d=function(b){return b.nodeType===a.TEXT_NODE&&/^\s*$/g.test(b.data)
+};return{prev:function(e){var f=b.previousSibling,g=e&&e.nodeTypes?e.nodeTypes:c;return f?!a.lang.array(g).contains(f.nodeType)||e&&e.ignoreBlankTexts&&d(f)?a.dom.domNode(f).prev(e):f:null},next:function(e){var f=b.nextSibling,g=e&&e.nodeTypes?e.nodeTypes:c;return f?!a.lang.array(g).contains(f.nodeType)||e&&e.ignoreBlankTexts&&d(f)?a.dom.domNode(f).next(e):f:null},lastLeafNode:function(c){var d;if(1!==b.nodeType)return b;if(d=b.lastChild,!d)return b;if(c&&c.leafClasses)for(var e=c.leafClasses.length;e--;)if(a.dom.hasClass(b,c.leafClasses[e]))return b;return a.dom.domNode(d).lastLeafNode(c)}}}}(wysihtml5),wysihtml5.dom.getAsDom=function(){var a=function(a,b){var c=b.createElement("div");c.style.display="none",b.body.appendChild(c);try{c.innerHTML=a}catch(d){}return b.body.removeChild(c),c},b=function(a){if(!a._wysihtml5_supportsHTML5Tags){for(var b=0,d=c.length;d>b;b++)a.createElement(c[b]);a._wysihtml5_supportsHTML5Tags=!0}},c=["abbr","article","aside","audio","bdi","canvas","command","datalist","details","figcaption","figure","footer","header","hgroup","keygen","mark","meter","nav","output","progress","rp","rt","ruby","svg","section","source","summary","time","track","video","wbr"];return function(c,d){d=d||document;var e;return"object"==typeof c&&c.nodeType?(e=d.createElement("div"),e.appendChild(c)):wysihtml5.browser.supportsHTML5Tags(d)?(e=d.createElement("div"),e.innerHTML=c):(b(d),e=a(c,d)),e}}(),wysihtml5.dom.getParentElement=function(){function a(a,b){return b&&b.length?"string"==typeof b?a===b:wysihtml5.lang.array(b).contains(a):!0}function b(a){return a.nodeType===wysihtml5.ELEMENT_NODE}function c(a,b,c){var d=(a.className||"").match(c)||[];return b?d[d.length-1]===b:!!d.length}function d(a,b,c){var d=(a.getAttribute("style")||"").match(c)||[];return b?d[d.length-1]===b:!!d.length}return function(e,f,g,h){var i=f.cssStyle||f.styleRegExp,j=f.className||f.classRegExp;for(g=g||50,j&&!f.classRegExp&&(f.classRegExp=new RegExp(f.className));g--&&e&&"BODY"!==e.nodeName&&(!h||e!==h);){if(!(!b(e)||f.nodeName&&!a(e.nodeName,f.nodeName)||i&&!d(e,f.cssStyle,f.styleRegExp)||j&&!c(e,f.className,f.classRegExp)))return e;e=e.parentNode}return null}}(),wysihtml5.dom.getStyle=function(){function a(a){return a.replace(c,function(a){return a.charAt(1).toUpperCase()})}var b={"float":"styleFloat"in document.createElement("div").style?"styleFloat":"cssFloat"},c=/\-[a-z]/g;return function(c){return{from:function(d){if(d.nodeType===wysihtml5.ELEMENT_NODE){var e=d.ownerDocument,f=b[c]||a(c),g=d.style,h=d.currentStyle,i=g[f];if(i)return i;if(h)try{return h[f]}catch(j){}var k,l,m=e.defaultView||e.parentWindow,n=("height"===c||"width"===c)&&"TEXTAREA"===d.nodeName;return m.getComputedStyle?(n&&(k=g.overflow,g.overflow="hidden"),l=m.getComputedStyle(d,null).getPropertyValue(c),n&&(g.overflow=k||""),l):void 0}}}}}(),wysihtml5.dom.getTextNodes=function(a,b){var c=[];for(a=a.firstChild;a;a=a.nextSibling)3==a.nodeType?b&&/^\s*$/.test(a.innerText||a.textContent)||c.push(a):c=c.concat(wysihtml5.dom.getTextNodes(a,b));return c},wysihtml5.dom.hasElementWithTagName=function(){function a(a){return a._wysihtml5_identifier||(a._wysihtml5_identifier=c++)}var b={},c=1;return function(c,d){var e=a(c)+":"+d,f=b[e];return f||(f=b[e]=c.getElementsByTagName(d)),f.length>0}}(),function(a){function b(a){return a._wysihtml5_identifier||(a._wysihtml5_identifier=d++)}var c={},d=1;a.dom.hasElementWithClassName=function(d,e){if(!a.browser.supportsNativeGetElementsByClassName())return!!d.querySelector("."+e);var f=b(d)+":"+e,g=c[f];return g||(g=c[f]=d.getElementsByClassName(e)),g.length>0}}(wysihtml5),wysihtml5.dom.insert=function(a){return{after:function(b){b.parentNode.insertBefore(a,b.nextSibling)},before:function(b){b.parentNode.insertBefore(a,b)},into:function(b){b.appendChild(a)}}},wysihtml5.dom.insertCSS=function(a){return a=a.join("\n"),{into:function(b){var c=b.createElement("style");c.type="text/css",c.styleSheet?c.styleSheet.cssText=a:c.appendChild(b.createTextNode(a));var d=b.querySelector("head link");if(d)return void d.parentNode.insertBefore(c,d);var e=b.querySelector("head");e&&e.appendChild(c)}}},function(a){a.dom.lineBreaks=function(b){function c(a){return"BR"===a.nodeName}function d(b){return c(b)?!0:"block"===a.dom.getStyle("display").from(b)?!0:!1}return{add:function(){var c=b.ownerDocument,e=a.dom.domNode(b).next({ignoreBlankTexts:!0}),f=a.dom.domNode(b).prev({ignoreBlankTexts:!0});e&&!d(e)&&a.dom.insert(c.createElement("br")).after(b),f&&!d(f)&&a.dom.insert(c.createElement("br")).before(b)},remove:function(){var d=a.dom.domNode(b).next({ignoreBlankTexts:!0}),e=a.dom.domNode(b).prev({ignoreBlankTexts:!0});d&&c(d)&&d.parentNode.removeChild(d),e&&c(e)&&e.parentNode.removeChild(e)}}}}(wysihtml5),wysihtml5.dom.observe=function(a,b,c){b="string"==typeof b?[b]:b;for(var d,e,f=0,g=b.length;g>f;f++)e=b[f],a.addEventListener?a.addEventListener(e,c,!1):(d=function(b){"target"in b||(b.target=b.srcElement),b.preventDefault=b.preventDefault||function(){this.returnValue=!1},b.stopPropagation=b.stopPropagation||function(){this.cancelBubble=!0},c.call(a,b)},a.attachEvent("on"+e,d));return{stop:function(){for(var e,f=0,g=b.length;g>f;f++)e=b[f],a.removeEventListener?a.removeEventListener(e,c,!1):a.detachEvent("on"+e,d)}}},wysihtml5.dom.parse=function(a,b){function c(a,b){wysihtml5.lang.object(t).merge(s).merge(b.rules).get();var c,f,g,h=b.context||a.ownerDocument||document,i=h.createDocumentFragment(),j="string"==typeof a,k=!1;for(b.clearInternals===!0&&(k=!0),c=j?wysihtml5.dom.getAsDom(a,h):a,t.selectors&&e(c,t.selectors);c.firstChild;)g=c.firstChild,f=d(g,b.cleanUp,k,b.uneditableClass),f&&i.appendChild(f),g!==f&&c.removeChild(g);if(b.unjoinNbsps)for(var l=wysihtml5.dom.getTextNodes(i),m=l.length;m--;)l[m].nodeValue=l[m].nodeValue.replace(/([\S\u00A0])\u00A0/gi,"$1 ");return c.innerHTML="",c.appendChild(i),j?wysihtml5.quirks.getCorrectInnerHTML(c):c}function d(a,b,c,e){var f,g,h,i,j=a.nodeType,k=a.childNodes,l=k.length,m=p[j],n=0;if(e&&1===j&&wysihtml5.dom.hasClass(a,e))return a;if(g=m&&m(a,c),!g){if(g===!1){for(f=a.ownerDocument.createDocumentFragment(),n=l;n--;)k[n]&&(h=d(k[n],b,c,e),h&&(k[n]===h&&n--,f.insertBefore(h,f.firstChild)));return i=wysihtml5.dom.getStyle("display").from(a),""===i&&(i=wysihtml5.lang.array(u).contains(a.tagName)?"block":""),wysihtml5.lang.array(["block","flex","table"]).contains(i)&&f.appendChild(a.ownerDocument.createElement("br")),wysihtml5.lang.array(["div","pre","p","table","td","th","ul","ol","li","dd","dl","footer","header","section","h1","h2","h3","h4","h5","h6"]).contains(a.nodeName.toLowerCase())&&a.parentNode.lastChild!==a&&(a.nextSibling&&3===a.nextSibling.nodeType&&/^\s/.test(a.nextSibling.nodeValue)||f.appendChild(a.ownerDocument.createTextNode(" "))),f.normalize&&f.normalize(),f}return null}for(n=0;l>n;n++)k[n]&&(h=d(k[n],b,c,e),h&&(k[n]===h&&n--,g.appendChild(h)));if(b&&g.nodeName.toLowerCase()===q&&(!g.childNodes.length||/^\s*$/gi.test(g.innerHTML)&&(c||"_wysihtml5-temp-placeholder"!==a.className&&"rangySelectionBoundary"!==a.className)||!g.attributes.length)){for(f=g.ownerDocument.createDocumentFragment();g.firstChild;)f.appendChild(g.firstChild);return f.normalize&&f.normalize(),f}return g.normalize&&g.normalize(),g}function e(a,b){var c,d,e;for(c in b)if(b.hasOwnProperty(c)){wysihtml5.lang.object(b[c]).isFunction()?d=b[c]:"string"==typeof b[c]&&z[b[c]]&&(d=z[b[c]]),e=a.querySelectorAll(c);for(var f=e.length;f--;)d(e[f])}}function f(a,b){var c,d,e,f=t.tags,h=a.nodeName.toLowerCase(),j=a.scopeName;if(a._wysihtml5)return null;if(a._wysihtml5=1,"wysihtml5-temp"===a.className)return null;if(j&&"HTML"!=j&&(h=j+":"+h),"outerHTML"in a&&(wysihtml5.browser.autoClosesUnclosedTags()||"P"!==a.nodeName||"</p>"===a.outerHTML.slice(-4).toLowerCase()||(h="div")),h in f){if(c=f[h],!c||c.remove)return null;if(c.unwrap)return!1;c="string"==typeof c?{rename_tag:c}:c}else{if(!a.firstChild)return null;c={rename_tag:q}}if(c.one_of_type&&!g(a,t,c.one_of_type,b)){if(!c.remove_action)return null;if("unwrap"===c.remove_action)return!1;if("rename"!==c.remove_action)return null;e=c.remove_action_rename_to||q}return d=a.ownerDocument.createElement(e||c.rename_tag||h),m(a,d,c,b),i(a,d,c),a=null,d.normalize&&d.normalize(),d}function g(a,b,c,d){var e,f;if("SPAN"===a.nodeName&&!d&&("_wysihtml5-temp-placeholder"===a.className||"rangySelectionBoundary"===a.className))return!0;for(f in c)if(c.hasOwnProperty(f)&&b.type_definitions&&b.type_definitions[f]&&(e=b.type_definitions[f],h(a,e)))return!0;return!1}function h(a,b){var c,d,e,f,g,h=a.getAttribute("class"),i=a.getAttribute("style");if(b.methods)for(var j in b.methods)if(b.methods.hasOwnProperty(j)&&y[j]&&y[j](a))return!0;if(h&&b.classes){h=h.replace(/^\s+/g,"").replace(/\s+$/g,"").split(r),c=h.length;for(var k=0;c>k;k++)if(b.classes[h[k]])return!0}if(i&&b.styles){i=i.split(";");for(d in b.styles)if(b.styles.hasOwnProperty(d))for(var l=i.length;l--;)if(g=i[l].split(":"),g[0].replace(/\s/g,"").toLowerCase()===d&&(b.styles[d]===!0||1===b.styles[d]||wysihtml5.lang.array(b.styles[d]).contains(g[1].replace(/\s/g,"").toLowerCase())))return!0}if(b.attrs)for(e in b.attrs)if(b.attrs.hasOwnProperty(e)&&(f=wysihtml5.dom.getAttribute(a,e),"string"==typeof f&&f.search(b.attrs[e])>-1))return!0;return!1}function i(a,b,c){var d,e;if(c&&c.keep_styles)for(d in c.keep_styles)if(c.keep_styles.hasOwnProperty(d)){if(e="float"===d?a.style.styleFloat||a.style.cssFloat:a.style[d],c.keep_styles[d]instanceof RegExp&&!c.keep_styles[d].test(e))continue;"float"===d?b.style[a.style.styleFloat?"styleFloat":"cssFloat"]=e:a.style[d]&&(b.style[d]=e)}}function j(a,b){var c=[];for(var d in b)b.hasOwnProperty(d)&&0===d.indexOf(a)&&c.push(d);return c}function k(a,b,c,d){var e,f=v[c];return f&&(b||"alt"===a&&"IMG"==d)&&(e=f(b),"string"==typeof e)?e:!1}function l(a,b){var c,d,e,f=wysihtml5.lang.object(t.attributes||{}).clone(),g=wysihtml5.lang.object(f).merge(wysihtml5.lang.object(b||{}).clone()).get(),h={},i=wysihtml5.dom.getAttributes(a);for(c in g)if(/\*$/.test(c)){e=j(c.slice(0,-1),i);for(var l=0,m=e.length;m>l;l++)d=k(e[l],i[e[l]],g[c],a.nodeName),d!==!1&&(h[e[l]]=d)}else d=k(c,i[c],g[c],a.nodeName),d!==!1&&(h[c]=d);return h}function m(a,b,c,d){var e,f,g,h,i,j={},k=c.set_class,m=c.add_class,n=c.add_style,o=c.set_attributes,p=t.classes,q=0,s=[],u=[],v=[],y=[];if(o&&(j=wysihtml5.lang.object(o).clone()),j=wysihtml5.lang.object(j).merge(l(a,c.check_attributes)).get(),k&&s.push(k),m)for(h in m)i=x[m[h]],i&&(g=i(wysihtml5.dom.getAttribute(a,h)),"string"==typeof g&&s.push(g));if(n)for(h in n)i=w[n[h]],i&&(newStyle=i(wysihtml5.dom.getAttribute(a,h)),"string"==typeof newStyle&&u.push(newStyle));if("string"==typeof p&&"any"===p&&a.getAttribute("class"))if(t.classes_blacklist){for(y=a.getAttribute("class"),y&&(s=s.concat(y.split(r))),e=s.length;e>q;q++)f=s[q],t.classes_blacklist[f]||v.push(f);v.length&&(j["class"]=wysihtml5.lang.array(v).unique().join(" "))}else j["class"]=a.getAttribute("class");else{for(d||(p["_wysihtml5-temp-placeholder"]=1,p._rangySelectionBoundary=1,p["wysiwyg-tmp-selected-cell"]=1),y=a.getAttribute("class"),y&&(s=s.concat(y.split(r))),e=s.length;e>q;q++)f=s[q],p[f]&&v.push(f);v.length&&(j["class"]=wysihtml5.lang.array(v).unique().join(" "))}j["class"]&&d&&(j["class"]=j["class"].replace("wysiwyg-tmp-selected-cell",""),/^\s*$/g.test(j["class"])&&delete j["class"]),u.length&&(j.style=wysihtml5.lang.array(u).unique().join(" "));for(h in j)try{b.setAttribute(h,j[h])}catch(z){}j.src&&("undefined"!=typeof j.width&&b.setAttribute("width",j.width),"undefined"!=typeof j.height&&b.setAttribute("height",j.height))}function n(a){var b=a.nextSibling;if(!b||b.nodeType!==wysihtml5.TEXT_NODE){var c=a.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP,"");return a.ownerDocument.createTextNode(c)}b.data=a.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP,"")+b.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP,"")}function o(a){return t.comments?a.ownerDocument.createComment(a.nodeValue):void 0}var p={1:f,3:n,8:o},q="span",r=/\s+/,s={tags:{},classes:{}},t={},u=["ADDRESS","BLOCKQUOTE","CENTER","DIR","DIV","DL","FIELDSET","FORM","H1","H2","H3","H4","H5","H6","ISINDEX","MENU","NOFRAMES","NOSCRIPT","OL","P","PRE","TABLE","UL"],v={url:function(){var a=/^https?:\/\//i;return function(b){return b&&b.match(a)?b.replace(a,function(a){return a.toLowerCase()}):null}}(),src:function(){var a=/^(\/|https?:\/\/)/i;return function(b){return b&&b.match(a)?b.replace(a,function(a){return a.toLowerCase()}):null}}(),href:function(){var a=/^(#|\/|https?:\/\/|mailto:)/i;return function(b){return b&&b.match(a)?b.replace(a,function(a){return a.toLowerCase()}):null}}(),alt:function(){var a=/[^ a-z0-9_\-]/gi;return function(b){return b?b.replace(a,""):""}}(),numbers:function(){var a=/\D/g;return function(b){return b=(b||"").replace(a,""),b||null}}(),any:function(){return function(a){return a}}()},w={align_text:function(){var a={left:"text-align: left;",right:"text-align: right;",center:"text-align: center;"};return function(b){return a[String(b).toLowerCase()]}}()},x={align_img:function(){var a={left:"wysiwyg-float-left",right:"wysiwyg-float-right"};return function(b){return a[String(b).toLowerCase()]}}(),align_text:function(){var a={left:"wysiwyg-text-align-left",right:"wysiwyg-text-align-right",center:"wysiwyg-text-align-center",justify:"wysiwyg-text-align-justify"};return function(b){return a[String(b).toLowerCase()]}}(),clear_br:function(){var a={left:"wysiwyg-clear-left",right:"wysiwyg-clear-right",both:"wysiwyg-clear-both",all:"wysiwyg-clear-both"};return function(b){return a[String(b).toLowerCase()]}}(),size_font:function(){var a={1:"wysiwyg-font-size-xx-small",2:"wysiwyg-font-size-small",3:"wysiwyg-font-size-medium",4:"wysiwyg-font-size-large",5:"wysiwyg-font-size-x-large",6:"wysiwyg-font-size-xx-large",7:"wysiwyg-font-size-xx-large","-":"wysiwyg-font-size-smaller","+":"wysiwyg-font-size-larger"};return function(b){return a[String(b).charAt(0)]}}()},y={has_visible_contet:function(){var a,b=["img","video","picture","br","script","noscript","style","table","iframe","object","embed","audio","svg","input","button","select","textarea","canvas"];return function(c){if(a=(c.innerText||c.textContent).replace(/\s/g,""),a&&a.length>0)return!0;for(var d=b.length;d--;)if(c.querySelector(b[d]))return!0;return c.offsetWidth&&c.offsetWidth>0&&c.offsetHeight&&c.offsetHeight>0?!0:!1}}()},z={unwrap:function(a){wysihtml5.dom.unwrap(a)},remove:function(a){a.parentNode.removeChild(a)}};return c(a,b)},wysihtml5.dom.removeEmptyTextNodes=function(a){for(var b,c=wysihtml5.lang.array(a.childNodes).get(),d=c.length,e=0;d>e;e++)b=c[e],b.nodeType===wysihtml5.TEXT_NODE&&""===b.data&&b.parentNode.removeChild(b)},wysihtml5.dom.renameElement=function(a,b){for(var c,d=a.ownerDocument.createElement(b);c=a.firstChild;)d.appendChild(c);return wysihtml5.dom.copyAttributes(["align","className"]).from(a).to(d),a.parentNode.replaceChild(d,a),d},wysihtml5.dom.replaceWithChildNodes=function(a){if(a.parentNode){if(!a.firstChild)return void a.parentNode.removeChild(a);for(var b=a.ownerDocument.createDocumentFragment();a.firstChild;)b.appendChild(a.firstChild);a.parentNode.replaceChild(b,a),a=b=null}},function(a){function b(b){return"block"===a.getStyle("display").from(b)}function c(a){return"BR"===a.nodeName}function d(a){var b=a.ownerDocument.createElement("br");a.appendChild(b)}function e(a,e){if(a.nodeName.match(/^(MENU|UL|OL)$/)){var f,g,h,i,j,k,l=a.ownerDocument,m=l.createDocumentFragment(),n=wysihtml5.dom.domNode(a).prev({ignoreBlankTexts:!0});if(e)for(!n||b(n)||c(n)||d(m);k=a.firstElementChild||a.firstChild;){for(g=k.lastChild;f=k.firstChild;)h=f===g,i=h&&!b(f)&&!c(f),m.appendChild(f),i&&d(m);k.parentNode.removeChild(k)}else for(;k=a.firstElementChild||a.firstChild;){if(k.querySelector&&k.querySelector("div, p, ul, ol, menu, blockquote, h1, h2, h3, h4, h5, h6"))for(;f=k.firstChild;)m.appendChild(f);else{for(j=l.createElement("p");f=k.firstChild;)j.appendChild(f);m.appendChild(j)}k.parentNode.removeChild(k)}a.parentNode.replaceChild(m,a)}}a.resolveList=e}(wysihtml5.dom),function(a){var b=document,c=["parent","top","opener","frameElement","frames","localStorage","globalStorage","sessionStorage","indexedDB"],d=["open","close","openDialog","showModalDialog","alert","confirm","prompt","openDatabase","postMessage","XMLHttpRequest","XDomainRequest"],e=["referrer","write","open","close"];a.dom.Sandbox=Base.extend({constructor:function(b,c){this.callback=b||a.EMPTY_FUNCTION,this.config=a.lang.object({}).merge(c).get(),this.editableArea=this._createIframe()},insertInto:function(a){"string"==typeof a&&(a=b.getElementById(a)),a.appendChild(this.editableArea)},getIframe:function(){return this.editableArea},getWindow:function(){this._readyError()},getDocument:function(){this._readyError()},destroy:function(){var a=this.getIframe();a.parentNode.removeChild(a)},_readyError:function(){throw new Error("wysihtml5.Sandbox: Sandbox iframe isn't loaded yet")},_createIframe:function(){var c=this,d=b.createElement("iframe");return d.className="wysihtml5-sandbox",a.dom.setAttributes({security:"restricted",allowtransparency:"true",frameborder:0,width:0,height:0,marginwidth:0,marginheight:0}).on(d),a.browser.throwsMixedContentWarningWhenIframeSrcIsEmpty()&&(d.src="javascript:'<html></html>'"),d.onload=function(){d.onreadystatechange=d.onload=null,c._onLoadIframe(d)},d.onreadystatechange=function(){/loaded|complete/.test(d.readyState)&&(d.onreadystatechange=d.onload=null,c._onLoadIframe(d))},d},_onLoadIframe:function(f){if(a.dom.contains(b.documentElement,f)){var g=this,h=f.contentWindow,i=f.contentWindow.document,j=b.characterSet||b.charset||"utf-8",k=this._getHtml({charset:j,stylesheets:this.config.stylesheets});if(i.open("text/html","replace"),i.write(k),i.close(),this.getWindow=function(){return f.contentWindow},this.getDocument=function(){return f.contentWindow.document},h.onerror=function(a,b,c){throw new Error("wysihtml5.Sandbox: "+a,b,c)},!a.browser.supportsSandboxedIframes()){var l,m;for(l=0,m=c.length;m>l;l++)this._unset(h,c[l]);for(l=0,m=d.length;m>l;l++)this._unset(h,d[l],a.EMPTY_FUNCTION);for(l=0,m=e.length;m>l;l++)this._unset(i,e[l]);this._unset(i,"cookie","",!0)}this.loaded=!0,setTimeout(function(){g.callback(g)},0)}},_getHtml:function(b){var c,d=b.stylesheets,e="",f=0;if(d="string"==typeof d?[d]:d)for(c=d.length;c>f;f++)e+='<link rel="stylesheet" href="'+d[f]+'">';return b.stylesheets=e,a.lang.string('<!DOCTYPE html><html><head><meta charset="#{charset}">#{stylesheets}</head><body></body></html>').interpolate(b)},_unset:function(b,c,d,e){try{b[c]=d}catch(f){}try{b.__defineGetter__(c,function(){return d})}catch(f){}if(e)try{b.__defineSetter__(c,function(){})}catch(f){}if(!a.browser.crashesWhenDefineProperty(c))try{var g={get:function(){return d}};e&&(g.set=function(){}),Object.defineProperty(b,c,g)}catch(f){}}})}(wysihtml5),function(a){var b=document;a.dom.ContentEditableArea=Base.extend({getContentEditable:function(){return this.element},getWindow:function(){return this.element.ownerDocument.defaultView},getDocument:function(){return this.element.ownerDocument},constructor:function(b,c,d){this.callback=b||a.EMPTY_FUNCTION,this.config=a.lang.object({}).merge(c).get(),this.element=d?this._bindElement(d):this._createElement()},_createElement:function(){var a=b.createElement("div");return a.className="wysihtml5-sandbox",this._loadElement(a),a},_bindElement:function(a){return a.className=a.className&&""!=a.className?a.className+" wysihtml5-sandbox":"wysihtml5-sandbox",this._loadElement(a,!0),a},_loadElement:function(a,b){var c=this;if(!b){var d=this._getHtml();a.innerHTML=d}this.getWindow=function(){return a.ownerDocument.defaultView},this.getDocument=function(){return a.ownerDocument},this.loaded=!0,setTimeout(function(){c.callback(c)},0)},_getHtml:function(){return""}})}(wysihtml5),function(){var a={className:"class"};wysihtml5.dom.setAttributes=function(b){return{on:function(c){for(var d in b)c.setAttribute(a[d]||d,b[d])}}}}(),wysihtml5.dom.setStyles=function(a){return{on:function(b){var c=b.style;if("string"==typeof a)return void(c.cssText+=";"+a);for(var d in a)"float"===d?(c.cssFloat=a[d],c.styleFloat=a[d]):c[d]=a[d]}}},function(a){a.simulatePlaceholder=function(b,c,d){var e="placeholder",f=function(){var b=c.element.offsetWidth>0&&c.element.offsetHeight>0;c.hasPlaceholderSet()&&(c.clear(),c.element.focus(),b&&setTimeout(function(){var a=c.selection.getSelection();a.focusNode&&a.anchorNode||c.selection.selectNode(c.element.firstChild||c.element)},0)),c.placeholderSet=!1,a.removeClass(c.element,e)},g=function(){c.isEmpty()&&(c.placeholderSet=!0,c.setValue(d),a.addClass(c.element,e))};b.on("set_placeholder",g).on("unset_placeholder",f).on("focus:composer",f).on("paste:composer",f).on("blur:composer",g),g()}}(wysihtml5.dom),function(a){var b=document.documentElement;"textContent"in b?(a.setTextContent=function(a,b){a.textContent=b},a.getTextContent=function(a){return a.textContent}):"innerText"in b?(a.setTextContent=function(a,b){a.innerText=b},a.getTextContent=function(a){return a.innerText}):(a.setTextContent=function(a,b){a.nodeValue=b},a.getTextContent=function(a){return a.nodeValue})}(wysihtml5.dom),wysihtml5.dom.getAttribute=function(a,b){var c=!wysihtml5.browser.supportsGetAttributeCorrectly();b=b.toLowerCase();var d=a.nodeName;if("IMG"==d&&"src"==b&&wysihtml5.dom.isLoadedImage(a)===!0)return a.src;if(c&&"outerHTML"in a){var e=a.outerHTML.toLowerCase(),f=-1!=e.indexOf(" "+b+"=");return f?a.getAttribute(b):null}return a.getAttribute(b)},wysihtml5.dom.getAttributes=function(a){var b,c=!wysihtml5.browser.supportsGetAttributeCorrectly(),d=a.nodeName,e=[];for(b in a.attributes)(a.attributes.hasOwnProperty&&a.attributes.hasOwnProperty(b)||!a.attributes.hasOwnProperty&&Object.prototype.hasOwnProperty.call(a.attributes,b))&&a.attributes[b].specified&&("IMG"==d&&"src"==a.attributes[b].name.toLowerCase()&&wysihtml5.dom.isLoadedImage(a)===!0?e.src=a.src:wysihtml5.lang.array(["rowspan","colspan"]).contains(a.attributes[b].name.toLowerCase())&&c?1!==a.attributes[b].value&&(e[a.attributes[b].name]=a.attributes[b].value):e[a.attributes[b].name]=a.attributes[b].value);return e},wysihtml5.dom.isLoadedImage=function(a){try{return a.complete&&!a.mozMatchesSelector(":-moz-broken")}catch(b){if(a.complete&&"complete"===a.readyState)return!0}},function(a){function b(a,b){for(var c,d=[],e=0,f=a.length;f>e;e++)if(c=a[e].querySelectorAll(b))for(var g=c.length;g--;d.unshift(c[g]));return d}function d(a){a.parentNode.removeChild(a)}function e(a,b){a.parentNode.insertBefore(b,a.nextSibling)}function f(a,b){for(var c=a.nextSibling;1!=c.nodeType;)if(c=c.nextSibling,!b||b==c.tagName.toLowerCase())return c;return null}var g=a.dom,h=function(a){this.el=a,this.isColspan=!1,this.isRowspan=!1,this.firstCol=!0,this.lastCol=!0,this.firstRow=!0,this.lastRow=!0,this.isReal=!0,this.spanCollection=[],this.modified=!1},i=function(a,b){a?(this.cell=a,this.table=g.getParentElement(a,{nodeName:["TABLE"]})):b&&(this.table=b,this.cell=this.table.querySelectorAll("th, td")[0])};i.prototype={addSpannedCellToMap:function(a,b,c,d,e,f){for(var g=[],i=c+(f?parseInt(f,10)-1:0),j=d+(e?parseInt(e,10)-1:0),k=c;i>=k;k++){"undefined"==typeof b[k]&&(b[k]=[]);for(var l=d;j>=l;l++)b[k][l]=new h(a),b[k][l].isColspan=e&&parseInt(e,10)>1,b[k][l].isRowspan=f&&parseInt(f,10)>1,b[k][l].firstCol=l==d,b[k][l].lastCol=l==j,b[k][l].firstRow=k==c,b[k][l].lastRow=k==i,b[k][l].isReal=l==d&&k==c,b[k][l].spanCollection=g,g.push(b[k][l])}},setCellAsModified:function(a){if(a.modified=!0,a.spanCollection.length>0)for(var b=0,c=a.spanCollection.length;c>b;b++)a.spanCollection[b].modified=!0},setTableMap:function(){var a,b,c,d,e,f,i,j,k=[],l=this.getTableRows();for(a=0;a<l.length;a++)for(b=l[a],c=this.getRowCells(b),f=0,"undefined"==typeof k[a]&&(k[a]=[]),d=0;d<c.length;d++){for(e=c[d];"undefined"!=typeof k[a][f];)f++;i=g.getAttribute(e,"colspan"),j=g.getAttribute(e,"rowspan"),i||j?(this.addSpannedCellToMap(e,k,a,f,i,j),f+=i?parseInt(i,10):1):(k[a][f]=new h(e),f++)}return this.map=k,k},getRowCells:function(c){var d=this.table.querySelectorAll("table"),e=d?b(d,"th, td"):[],f=c.querySelectorAll("th, td"),g=e.length>0?a.lang.array(f).without(e):f;return g},getTableRows:function(){var c=this.table.querySelectorAll("table"),d=c?b(c,"tr"):[],e=this.table.querySelectorAll("tr"),f=d.length>0?a.lang.array(e).without(d):e;return f},getMapIndex:function(a){for(var b=this.map.length,c=this.map&&this.map[0]?this.map[0].length:0,d=0;b>d;d++)for(var e=0;c>e;e++)if(this.map[d][e].el===a)return{row:d,col:e};return!1},getElementAtIndex:function(a){return this.setTableMap(),this.map[a.row]&&this.map[a.row][a.col]&&this.map[a.row][a.col].el?this.map[a.row][a.col].el:null},getMapElsTo:function(a){var b=[];if(this.setTableMap(),this.idx_start=this.getMapIndex(this.cell),this.idx_end=this.getMapIndex(a),this.idx_start.row>this.idx_end.row||this.idx_start.row==this.idx_end.row&&this.idx_start.col>this.idx_end.col){var c=this.idx_start;this.idx_start=this.idx_end,this.idx_end=c}if(this.idx_start.col>this.idx_end.col){var d=this.idx_start.col;this.idx_start.col=this.idx_end.col,this.idx_end.col=d}if(null!=this.idx_start&&null!=this.idx_end)for(var e=this.idx_start.row,f=this.idx_end.row;f>=e;e++)for(var g=this.idx_start.col,h=this.idx_end.col;h>=g;g++)b.push(this.map[e][g].el);return b},orderSelectionEnds:function(a){if(this.setTableMap(),this.idx_start=this.getMapIndex(this.cell),this.idx_end=this.getMapIndex(a),this.idx_start.row>this.idx_end.row||this.idx_start.row==this.idx_end.row&&this.idx_start.col>this.idx_end.col){var b=this.idx_start;this.idx_start=this.idx_end,this.idx_end=b}if(this.idx_start.col>this.idx_end.col){var c=this.idx_start.col;this.idx_start.col=this.idx_end.col,this.idx_end.col=c}return{start:this.map[this.idx_start.row][this.idx_start.col].el,end:this.map[this.idx_end.row][this.idx_end.col].el}},createCells:function(a,b,c){for(var d,e=this.table.ownerDocument,f=e.createDocumentFragment(),g=0;b>g;g++){if(d=e.createElement(a),c)for(var h in c)c.hasOwnProperty(h)&&d.setAttribute(h,c[h]);d.appendChild(document.createTextNode(" ")),f.appendChild(d)}return f},correctColIndexForUnreals:function(a,b){for(var c=this.map[b],d=-1,e=0;a>e;e++)c[e].isReal&&d++;return d},getLastNewCellOnRow:function(a,b){for(var c,d,e=this.getRowCells(a),f=0,g=e.length;g>f;f++)if(c=e[f],d=this.getMapIndex(c),d===!1||"undefined"!=typeof b&&d.row!=b)return c;return null},removeEmptyTable:function(){var a=this.table.querySelectorAll("td, th");return a&&0!=a.length?!1:(d(this.table),!0)},splitRowToCells:function(a){if(a.isColspan){var b=parseInt(g.getAttribute(a.el,"colspan")||1,10),c=a.el.tagName.toLowerCase();if(b>1){var d=this.createCells(c,b-1);e(a.el,d)}a.el.removeAttribute("colspan")}},getRealRowEl:function(a,b){var c=null,d=null;b=b||this.idx;for(var e=0,f=this.map[b.row].length;f>e;e++)if(d=this.map[b.row][e],d.isReal&&(c=g.getParentElement(d.el,{nodeName:["TR"]})))return c;return null===c&&a&&(c=g.getParentElement(this.map[b.row][b.col].el,{nodeName:["TR"]})||null),c},injectRowAt:function(a,b,c,d,f){var h=this.getRealRowEl(!1,{row:a,col:b}),i=this.createCells(d,c);if(h){var j=this.correctColIndexForUnreals(b,a);j>=0?e(this.getRowCells(h)[j],i):h.insertBefore(i,h.firstChild)}else{var k=this.table.ownerDocument.createElement("tr");k.appendChild(i),e(g.getParentElement(f.el,{nodeName:["TR"]}),k)}},canMerge:function(a){if(this.to=a,this.setTableMap(),this.idx_start=this.getMapIndex(this.cell),this.idx_end=this.getMapIndex(this.to),this.idx_start.row>this.idx_end.row||this.idx_start.row==this.idx_end.row&&this.idx_start.col>this.idx_end.col){var b=this.idx_start;this.idx_start=this.idx_end,this.idx_end=b}if(this.idx_start.col>this.idx_end.col){var c=this.idx_start.col;this.idx_start.col=this.idx_end.col,this.idx_end.col=c}for(var d=this.idx_start.row,e=this.idx_end.row;e>=d;d++)for(var f=this.idx_start.col,g=this.idx_end.col;g>=f;f++)if(this.map[d][f].isColspan||this.map[d][f].isRowspan)return!1;return!0},decreaseCellSpan:function(a,b){var c=parseInt(g.getAttribute(a.el,b),10)-1;c>=1?a.el.setAttribute(b,c):(a.el.removeAttribute(b),"colspan"==b&&(a.isColspan=!1),"rowspan"==b&&(a.isRowspan=!1),a.firstCol=!0,a.lastCol=!0,a.firstRow=!0,a.lastRow=!0,a.isReal=!0)},removeSurplusLines:function(){var a,b,c,e,f,h,i;if(this.setTableMap(),this.map){for(c=0,e=this.map.length;e>c;c++){for(a=this.map[c],i=!0,f=0,h=a.length;h>f;f++)if(b=a[f],!(g.getAttribute(b.el,"rowspan")&&parseInt(g.getAttribute(b.el,"rowspan"),10)>1&&b.firstRow!==!0)){i=!1;break}if(i)for(f=0;h>f;f++)this.decreaseCellSpan(a[f],"rowspan")}var j=this.getTableRows();for(c=0,e=j.length;e>c;c++)a=j[c],0==a.childNodes.length&&/^\s*$/.test(a.textContent||a.innerText)&&d(a)}},fillMissingCells:function(){var a=0,b=0,c=null;if(this.setTableMap(),this.map){a=this.map.length;for(var d=0;a>d;d++)this.map[d].length>b&&(b=this.map[d].length);for(var f=0;a>f;f++)for(var g=0;b>g;g++)this.map[f]&&!this.map[f][g]&&g>0&&(this.map[f][g]=new h(this.createCells("td",1)),c=this.map[f][g-1],c&&c.el&&c.el.parent&&e(this.map[f][g-1].el,this.map[f][g].el))}},rectify:function(){return this.removeEmptyTable()?!1:(this.removeSurplusLines(),this.fillMissingCells(),!0)},unmerge:function(){if(this.rectify()&&(this.setTableMap(),this.idx=this.getMapIndex(this.cell),this.idx)){var a=this.map[this.idx.row][this.idx.col],b=g.getAttribute(a.el,"colspan")?parseInt(g.getAttribute(a.el,"colspan"),10):1,c=a.el.tagName.toLowerCase();if(a.isRowspan){var d=parseInt(g.getAttribute(a.el,"rowspan"),10);if(d>1)for(var e=1,f=d-1;f>=e;e++)this.injectRowAt(this.idx.row+e,this.idx.col,b,c,a);a.el.removeAttribute("rowspan")}this.splitRowToCells(a)}},merge:function(a){if(this.rectify())if(this.canMerge(a)){for(var b=this.idx_end.row-this.idx_start.row+1,c=this.idx_end.col-this.idx_start.col+1,e=this.idx_start.row,f=this.idx_end.row;f>=e;e++)for(var g=this.idx_start.col,h=this.idx_end.col;h>=g;g++)e==this.idx_start.row&&g==this.idx_start.col?(b>1&&this.map[e][g].el.setAttribute("rowspan",b),c>1&&this.map[e][g].el.setAttribute("colspan",c)):(/^\s*<br\/?>\s*$/.test(this.map[e][g].el.innerHTML.toLowerCase())||(this.map[this.idx_start.row][this.idx_start.col].el.innerHTML+=" "+this.map[e][g].el.innerHTML),d(this.map[e][g].el));this.rectify()}else window.console&&console.log("Do not know how to merge allready merged cells.")},collapseCellToNextRow:function(a){var b=this.getMapIndex(a.el),c=b.row+1,d={row:c,col:b.col};if(c<this.map.length){var f=this.getRealRowEl(!1,d);if(null!==f){var h=this.correctColIndexForUnreals(d.col,d.row);if(h>=0)e(this.getRowCells(f)[h],a.el);else{var i=this.getLastNewCellOnRow(f,c);null!==i?e(i,a.el):f.insertBefore(a.el,f.firstChild)}parseInt(g.getAttribute(a.el,"rowspan"),10)>2?a.el.setAttribute("rowspan",parseInt(g.getAttribute(a.el,"rowspan"),10)-1):a.el.removeAttribute("rowspan")}}},removeRowCell:function(a){a.isReal?a.isRowspan?this.collapseCellToNextRow(a):d(a.el):parseInt(g.getAttribute(a.el,"rowspan"),10)>2?a.el.setAttribute("rowspan",parseInt(g.getAttribute(a.el,"rowspan"),10)-1):a.el.removeAttribute("rowspan")},getRowElementsByCell:function(){var a=[];if(this.setTableMap(),this.idx=this.getMapIndex(this.cell),this.idx!==!1)for(var b=this.map[this.idx.row],c=0,d=b.length;d>c;c++)b[c].isReal&&a.push(b[c].el);return a},getColumnElementsByCell:function(){var a=[];if(this.setTableMap(),this.idx=this.getMapIndex(this.cell),this.idx!==!1)for(var b=0,c=this.map.length;c>b;b++)this.map[b][this.idx.col]&&this.map[b][this.idx.col].isReal&&a.push(this.map[b][this.idx.col].el);return a},removeRow:function(){var a=g.getParentElement(this.cell,{nodeName:["TR"]});if(a){if(this.setTableMap(),this.idx=this.getMapIndex(this.cell),this.idx!==!1)for(var b=this.map[this.idx.row],c=0,e=b.length;e>c;c++)b[c].modified||(this.setCellAsModified(b[c]),this.removeRowCell(b[c]));d(a)}},removeColCell:function(a){a.isColspan?parseInt(g.getAttribute(a.el,"colspan"),10)>2?a.el.setAttribute("colspan",parseInt(g.getAttribute(a.el,"colspan"),10)-1):a.el.removeAttribute("colspan"):a.isReal&&d(a.el)
+},removeColumn:function(){if(this.setTableMap(),this.idx=this.getMapIndex(this.cell),this.idx!==!1)for(var a=0,b=this.map.length;b>a;a++)this.map[a][this.idx.col].modified||(this.setCellAsModified(this.map[a][this.idx.col]),this.removeColCell(this.map[a][this.idx.col]))},remove:function(a){if(this.rectify()){switch(a){case"row":this.removeRow();break;case"column":this.removeColumn()}this.rectify()}},addRow:function(a){var b=this.table.ownerDocument;if(this.setTableMap(),this.idx=this.getMapIndex(this.cell),"below"==a&&g.getAttribute(this.cell,"rowspan")&&(this.idx.row=this.idx.row+parseInt(g.getAttribute(this.cell,"rowspan"),10)-1),this.idx!==!1){for(var c=this.map[this.idx.row],d=b.createElement("tr"),f=0,h=c.length;h>f;f++)c[f].modified||(this.setCellAsModified(c[f]),this.addRowCell(c[f],d,a));switch(a){case"below":e(this.getRealRowEl(!0),d);break;case"above":var i=g.getParentElement(this.map[this.idx.row][this.idx.col].el,{nodeName:["TR"]});i&&i.parentNode.insertBefore(d,i)}}},addRowCell:function(a,b,d){var e=a.isColspan?{colspan:g.getAttribute(a.el,"colspan")}:null;a.isReal?"above"!=d&&a.isRowspan?a.el.setAttribute("rowspan",parseInt(g.getAttribute(a.el,"rowspan"),10)+1):b.appendChild(this.createCells("td",1,e)):"above"!=d&&a.isRowspan&&a.lastRow?b.appendChild(this.createCells("td",1,e)):c.isRowspan&&a.el.attr("rowspan",parseInt(g.getAttribute(a.el,"rowspan"),10)+1)},add:function(a){this.rectify()&&(("below"==a||"above"==a)&&this.addRow(a),("before"==a||"after"==a)&&this.addColumn(a))},addColCell:function(a,b,d){var f,h=a.el.tagName.toLowerCase();switch(d){case"before":f=!a.isColspan||a.firstCol;break;case"after":f=!a.isColspan||a.lastCol||a.isColspan&&c.el==this.cell}if(f){switch(d){case"before":a.el.parentNode.insertBefore(this.createCells(h,1),a.el);break;case"after":e(a.el,this.createCells(h,1))}a.isRowspan&&this.handleCellAddWithRowspan(a,b+1,d)}else a.el.setAttribute("colspan",parseInt(g.getAttribute(a.el,"colspan"),10)+1)},addColumn:function(a){var b,c;if(this.setTableMap(),this.idx=this.getMapIndex(this.cell),"after"==a&&g.getAttribute(this.cell,"colspan")&&(this.idx.col=this.idx.col+parseInt(g.getAttribute(this.cell,"colspan"),10)-1),this.idx!==!1)for(var d=0,e=this.map.length;e>d;d++)b=this.map[d],b[this.idx.col]&&(c=b[this.idx.col],c.modified||(this.setCellAsModified(c),this.addColCell(c,d,a)))},handleCellAddWithRowspan:function(a,b,c){for(var d,h,i,j=parseInt(g.getAttribute(this.cell,"rowspan"),10)-1,k=g.getParentElement(a.el,{nodeName:["TR"]}),l=a.el.tagName.toLowerCase(),m=this.table.ownerDocument,n=0;j>n;n++)if(d=this.correctColIndexForUnreals(this.idx.col,b+n),k=f(k,"tr"))if(d>0)switch(c){case"before":h=this.getRowCells(k),d>0&&this.map[b+n][this.idx.col].el!=h[d]&&d==h.length-1?e(h[d],this.createCells(l,1)):h[d].parentNode.insertBefore(this.createCells(l,1),h[d]);break;case"after":e(this.getRowCells(k)[d],this.createCells(l,1))}else k.insertBefore(this.createCells(l,1),k.firstChild);else i=m.createElement("tr"),i.appendChild(this.createCells(l,1)),this.table.appendChild(i)}},g.table={getCellsBetween:function(a,b){var c=new i(a);return c.getMapElsTo(b)},addCells:function(a,b){var c=new i(a);c.add(b)},removeCells:function(a,b){var c=new i(a);c.remove(b)},mergeCellsBetween:function(a,b){var c=new i(a);c.merge(b)},unmergeCell:function(a){var b=new i(a);b.unmerge()},orderSelectionEnds:function(a,b){var c=new i(a);return c.orderSelectionEnds(b)},indexOf:function(a){var b=new i(a);return b.setTableMap(),b.getMapIndex(a)},findCell:function(a,b){var c=new i(null,a);return c.getElementAtIndex(b)},findRowByCell:function(a){var b=new i(a);return b.getRowElementsByCell()},findColumnByCell:function(a){var b=new i(a);return b.getColumnElementsByCell()},canMerge:function(a,b){var c=new i(a);return c.canMerge(b)}}}(wysihtml5),wysihtml5.dom.query=function(a,b){var c,d=[];a.nodeType&&(a=[a]);for(var e=0,f=a.length;f>e;e++)if(c=a[e].querySelectorAll(b))for(var g=c.length;g--;d.unshift(c[g]));return d},wysihtml5.dom.compareDocumentPosition=function(){var a=document.documentElement;return a.compareDocumentPosition?function(a,b){return a.compareDocumentPosition(b)}:function(a,b){var c,d;if(c=9===a.nodeType?a:a.ownerDocument,d=9===b.nodeType?b:b.ownerDocument,a===b)return 0;if(a===b.ownerDocument)return 20;if(a.ownerDocument===b)return 10;if(c!==d)return 1;if(2===a.nodeType&&a.childNodes&&-1!==wysihtml5.lang.array(a.childNodes).indexOf(b))return 20;if(2===b.nodeType&&b.childNodes&&-1!==wysihtml5.lang.array(b.childNodes).indexOf(a))return 10;for(var e=a,f=[],g=null;e;){if(e==b)return 10;f.push(e),e=e.parentNode}for(e=b,g=null;e;){if(e==a)return 20;var h=wysihtml5.lang.array(f).indexOf(e);if(-1!==h){var i=f[h],j=wysihtml5.lang.array(i.childNodes).indexOf(f[h-1]),k=wysihtml5.lang.array(i.childNodes).indexOf(g);return j>k?2:4}g=e,e=e.parentNode}return 1}}(),wysihtml5.dom.unwrap=function(a){if(a.parentNode){for(;a.lastChild;)wysihtml5.dom.insert(a.lastChild).after(a);a.parentNode.removeChild(a)}},wysihtml5.dom.getPastedHtml=function(a){var b;return a.clipboardData&&(wysihtml5.lang.array(a.clipboardData.types).contains("text/html")?b=a.clipboardData.getData("text/html"):wysihtml5.lang.array(a.clipboardData.types).contains("text/plain")&&(b=wysihtml5.lang.string(a.clipboardData.getData("text/plain")).escapeHTML(!0,!0))),b},wysihtml5.dom.getPastedHtmlWithDiv=function(a,b){var c=a.selection.getBookmark(),d=a.element.ownerDocument,e=d.createElement("DIV");d.body.appendChild(e),e.style.width="1px",e.style.height="1px",e.style.overflow="hidden",e.setAttribute("contenteditable","true"),e.focus(),setTimeout(function(){a.selection.setBookmark(c),b(e.innerHTML),e.parentNode.removeChild(e)},0)},wysihtml5.quirks.cleanPastedHTML=function(){var a=function(a){var b=wysihtml5.lang.string(a).trim(),c=b.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&");return new RegExp("^((?!^"+c+"$).)*$","i")},b=function(b,c){var d,e,f=wysihtml5.lang.object(b).clone(!0);for(d in f.tags)if(f.tags.hasOwnProperty(d)&&f.tags[d].keep_styles)for(e in f.tags[d].keep_styles)f.tags[d].keep_styles.hasOwnProperty(e)&&c[e]&&(f.tags[d].keep_styles[e]=a(c[e]));return f},c=function(a,b){var c;if(!a)return null;for(var d=0,e=a.length;e>d;d++)if(a[d].condition||(c=a[d].set),a[d].condition&&a[d].condition.test(b))return a[d].set;return c};return function(a,d){var e,f={color:wysihtml5.dom.getStyle("color").from(d.referenceNode),fontSize:wysihtml5.dom.getStyle("font-size").from(d.referenceNode)},g=b(c(d.rules,a)||{},f);return e=wysihtml5.dom.parse(a,{rules:g,cleanUp:!0,context:d.referenceNode.ownerDocument,uneditableClass:d.uneditableClass,clearInternals:!0,unjoinNbsps:!0})}}(),wysihtml5.quirks.ensureProperClearing=function(){var a=function(){var a=this;setTimeout(function(){var b=a.innerHTML.toLowerCase();("<p> </p>"==b||"<p> </p><p> </p>"==b)&&(a.innerHTML="")},0)};return function(b){wysihtml5.dom.observe(b.element,["cut","keydown"],a)}}(),function(a){var b="%7E";a.quirks.getCorrectInnerHTML=function(c){var d=c.innerHTML;if(-1===d.indexOf(b))return d;var e,f,g,h,i=c.querySelectorAll("[href*='~'], [src*='~']");for(h=0,g=i.length;g>h;h++)e=i[h].href||i[h].src,f=a.lang.string(e).replace("~").by(b),d=a.lang.string(d).replace(f).by(e);return d}}(wysihtml5),function(a){var b="wysihtml5-quirks-redraw";a.quirks.redraw=function(c){a.dom.addClass(c,b),a.dom.removeClass(c,b);try{var d=c.ownerDocument;d.execCommand("italic",!1,null),d.execCommand("italic",!1,null)}catch(e){}}}(wysihtml5),wysihtml5.quirks.tableCellsSelection=function(a,b){function c(){return k.observe(a,"mousedown",function(a){var b=wysihtml5.dom.getParentElement(a.target,{nodeName:["TD","TH"]});b&&d(b)}),l}function d(c){l.start=c,l.end=c,l.cells=[c],l.table=k.getParentElement(l.start,{nodeName:["TABLE"]}),l.table&&(e(),k.addClass(c,m),n=k.observe(a,"mousemove",g),o=k.observe(a,"mouseup",h),b.fire("tableselectstart").fire("tableselectstart:composer"))}function e(){if(a){var b=a.querySelectorAll("."+m);if(b.length>0)for(var c=0;c<b.length;c++)k.removeClass(b[c],m)}}function f(a){for(var b=0;b<a.length;b++)k.addClass(a[b],m)}function g(a){var c,d=null,g=k.getParentElement(a.target,{nodeName:["TD","TH"]});g&&l.table&&l.start&&(d=k.getParentElement(g,{nodeName:["TABLE"]}),d&&d===l.table&&(e(),c=l.end,l.end=g,l.cells=k.table.getCellsBetween(l.start,g),l.cells.length>1&&b.composer.selection.deselect(),f(l.cells),l.end!==c&&b.fire("tableselectchange").fire("tableselectchange:composer")))}function h(){n.stop(),o.stop(),b.fire("tableselect").fire("tableselect:composer"),setTimeout(function(){i()},0)}function i(){var c=k.observe(a.ownerDocument,"click",function(a){c.stop(),k.getParentElement(a.target,{nodeName:["TABLE"]})!=l.table&&(e(),l.table=null,l.start=null,l.end=null,b.fire("tableunselect").fire("tableunselect:composer"))})}function j(a,c){l.start=a,l.end=c,l.table=k.getParentElement(l.start,{nodeName:["TABLE"]}),selectedCells=k.table.getCellsBetween(l.start,l.end),f(selectedCells),i(),b.fire("tableselect").fire("tableselect:composer")}var k=wysihtml5.dom,l={table:null,start:null,end:null,cells:null,select:j},m="wysiwyg-tmp-selected-cell",n=null,o=null;return c()},function(a){var b=/^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*([\d\.]+)\s*\)/i,c=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/i,d=/^#([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])/i,e=/^#([0-9a-f])([0-9a-f])([0-9a-f])/i,f=function(a){return new RegExp("(^|\\s|;)"+a+"\\s*:\\s*[^;$]+","gi")};a.quirks.styleParser={parseColor:function(g,h){var i,j,k=f(h),l=g.match(k),m=10;if(l){for(var n=l.length;n--;)l[n]=a.lang.string(l[n].split(":")[1]).trim();if(i=l[l.length-1],b.test(i))j=i.match(b);else if(c.test(i))j=i.match(c);else if(d.test(i))j=i.match(d),m=16;else if(e.test(i))return j=i.match(e),j.shift(),j.push(1),a.lang.array(j).map(function(a,b){return 3>b?16*parseInt(a,16)+parseInt(a,16):parseFloat(a)});if(j)return j.shift(),j[3]||j.push(1),a.lang.array(j).map(function(a,b){return 3>b?parseInt(a,m):parseFloat(a)})}return!1},unparseColor:function(a,b){if(b){if("hex"==b)return a[0].toString(16).toUpperCase()+a[1].toString(16).toUpperCase()+a[2].toString(16).toUpperCase();if("hash"==b)return"#"+a[0].toString(16).toUpperCase()+a[1].toString(16).toUpperCase()+a[2].toString(16).toUpperCase();if("rgb"==b)return"rgb("+a[0]+","+a[1]+","+a[2]+")";if("rgba"==b)return"rgba("+a[0]+","+a[1]+","+a[2]+","+a[3]+")";if("csv"==b)return a[0]+","+a[1]+","+a[2]+","+a[3]}return a[3]&&1!==a[3]?"rgba("+a[0]+","+a[1]+","+a[2]+","+a[3]+")":"rgb("+a[0]+","+a[1]+","+a[2]+")"},parseFontSize:function(b){var c=b.match(f("font-size"));return c?a.lang.string(c[c.length-1].split(":")[1]).trim():!1}}}(wysihtml5),function(a){function b(a){var b=0;if(a.parentNode)do b+=a.offsetTop||0,a=a.offsetParent;while(a);return b}function c(a,b){for(var c=0;b!==a;)if(c++,b=b.parentNode,!b)throw new Error("not a descendant of ancestor!");return c}function d(a){if(!a.canSurroundContents())for(var b=a.commonAncestorContainer,d=c(b,a.startContainer),e=c(b,a.endContainer);!a.canSurroundContents();)d>e?(a.setStartBefore(a.startContainer),d=c(b,a.startContainer)):(a.setEndAfter(a.endContainer),e=c(b,a.endContainer))}var e=a.dom;a.Selection=Base.extend({constructor:function(a,b,c){window.rangy.init(),this.editor=a,this.composer=a.composer,this.doc=this.composer.doc,this.contain=b,this.unselectableClass=c||!1},getBookmark:function(){var a=this.getRange();return a&&d(a),a&&a.cloneRange()},setBookmark:function(a){a&&this.setSelection(a)},setBefore:function(a){var b=rangy.createRange(this.doc);return b.setStartBefore(a),b.setEndBefore(a),this.setSelection(b)},creteTemporaryCaretSpaceAfter:function(b){var c=this.doc.createElement("span"),d=this.doc.createTextNode(a.INVISIBLE_SPACE),e=function(){var b;this.contain.removeEventListener("mouseup",e),this.contain.removeEventListener("keydown",g),this.contain.removeEventListener("touchstart",e),this.contain.removeEventListener("focus",e),this.contain.removeEventListener("blur",e),this.contain.removeEventListener("paste",f),this.contain.removeEventListener("drop",f),this.contain.removeEventListener("beforepaste",f),c&&c.parentNode&&(c.innerHTML=c.innerHTML.replace(a.INVISIBLE_SPACE_REG_EXP,""),/[^\s]+/.test(c.innerHTML)?(b=c.lastChild,a.dom.unwrap(c),this.setAfter(b)):c.parentNode.removeChild(c))}.bind(this),f=function(){c&&c.parentNode&&setTimeout(e,0)},g=function(a){8===a.which||91===a.which||17===a.which||86===a.which&&(a.ctrlKey||a.metaKey)||e()};return c.style.position="absolute",c.style.display="block",c.style.minWidth="1px",c.style.zIndex="99999",c.appendChild(d),b.parentNode.insertBefore(c,b.nextSibling),this.setBefore(d),this.contain.addEventListener("mouseup",e),this.contain.addEventListener("keydown",g),this.contain.addEventListener("touchstart",e),this.contain.addEventListener("focus",e),this.contain.addEventListener("blur",e),this.contain.addEventListener("paste",f),this.contain.addEventListener("drop",f),this.contain.addEventListener("beforepaste",f),c},setAfter:function(a){var b,c=rangy.createRange(this.doc),d=this.doc.documentElement.scrollTop||this.doc.body.scrollTop||this.doc.defaultView.pageYOffset,e=this.doc.documentElement.scrollLeft||this.doc.body.scrollLeft||this.doc.defaultView.pageXOffset;return c.setStartAfter(a),c.setEndAfter(a),this.composer.element.focus(),this.doc.defaultView.scrollTo(e,d),b=this.setSelection(c),b||this.creteTemporaryCaretSpaceAfter(a),b},selectNode:function(b,c){var d=rangy.createRange(this.doc),f=b.nodeType===a.ELEMENT_NODE,g="canHaveHTML"in b?b.canHaveHTML:"IMG"!==b.nodeName,h=f?b.innerHTML:b.data,i=""===h||h===a.INVISIBLE_SPACE,j=e.getStyle("display").from(b),k="block"===j||"list-item"===j;if(i&&f&&g&&!c)try{b.innerHTML=a.INVISIBLE_SPACE}catch(l){}g?d.selectNodeContents(b):d.selectNode(b),g&&i&&f?d.collapse(k):g&&i&&(d.setStartAfter(b),d.setEndAfter(b)),this.setSelection(d)},getSelectedNode:function(a){var b,c;return a&&this.doc.selection&&"Control"===this.doc.selection.type&&(c=this.doc.selection.createRange(),c&&c.length)?c.item(0):(b=this.getSelection(this.doc),b.focusNode===b.anchorNode?b.focusNode:(c=this.getRange(this.doc),c?c.commonAncestorContainer:this.doc.body))},fixSelBorders:function(){var a=this.getRange();d(a),this.setSelection(a)},getSelectedOwnNodes:function(){for(var a=this.getOwnRanges(),b=[],c=0,d=a.length;d>c;c++)b.push(a[c].commonAncestorContainer||this.doc.body);return b},findNodesInSelection:function(b){for(var c,d=this.getOwnRanges(),e=[],f=0,g=d.length;g>f;f++)c=d[f].getNodes([1],function(c){return a.lang.array(b).contains(c.nodeName)}),e=e.concat(c);return e},containsUneditable:function(){for(var a=this.getOwnUneditables(),b=this.getSelection(),c=0,d=a.length;d>c;c++)if(b.containsNode(a[c]))return!0;return!1},deleteContents:function(){var b,c,d,e,f=this.getRange();if(this.unselectableClass){(b=a.dom.getParentElement(f.startContainer,{className:this.unselectableClass},!1,this.contain))&&f.setStartBefore(b),(c=a.dom.getParentElement(f.endContainer,{className:this.unselectableClass},!1,this.contain))&&f.setEndAfter(c),d=f.getNodes([1],function(b){return a.dom.hasClass(b,this.unselectableClass)}.bind(this));for(var g=d.length;g--;)try{e=new CustomEvent("wysihtml5:uneditable:delete"),d[g].dispatchEvent(e)}catch(h){}}f.deleteContents(),this.setSelection(f)},getPreviousNode:function(b,c){var d;if(!b){var e=this.getSelection();b=e.anchorNode}if(b===this.contain)return!1;var f,g=b.previousSibling;return g===this.contain?!1:(g&&3!==g.nodeType&&1!==g.nodeType?g=this.getPreviousNode(g,c):g&&3===g.nodeType&&/^\s*$/.test(g.textContent)?g=this.getPreviousNode(g,c):c&&g&&1===g.nodeType?(d=a.dom.getStyle("display").from(g),a.lang.array(["BR","HR","IMG"]).contains(g.nodeName)||a.lang.array(["block","inline-block","flex","list-item","table"]).contains(d)||!/^[\s]*$/.test(g.innerHTML)||(g=this.getPreviousNode(g,c))):g||b===this.contain||(f=b.parentNode,f!==this.contain&&(g=this.getPreviousNode(f,c))),g!==this.contain?g:!1)},getSelectionParentsByTag:function(){for(var b,c=this.getSelectedOwnNodes(),d=[],e=0,f=c.length;f>e;e++)b=c[e].nodeName&&"LI"===c[e].nodeName?c[e]:a.dom.getParentElement(c[e],{nodeName:["LI"]},!1,this.contain),b&&d.push(b);return d.length?d:null},getRangeToNodeEnd:function(){if(this.isCollapsed()){var a=this.getRange(),b=a.startContainer,c=a.startOffset,d=rangy.createRange(this.doc);return d.selectNodeContents(b),d.setStart(b,c),d}},caretIsLastInSelection:function(){var a=(rangy.createRange(this.doc),this.getSelection(),this.getRangeToNodeEnd().cloneContents()),b=a.textContent;return/^\s*$/.test(b)},caretIsFirstInSelection:function(){var b=rangy.createRange(this.doc),c=this.getSelection(),d=this.getRange(),e=d.startContainer;return e?e.nodeType===a.TEXT_NODE?this.isCollapsed()&&e.nodeType===a.TEXT_NODE&&/^\s*$/.test(e.data.substr(0,d.startOffset)):(b.selectNodeContents(this.getRange().commonAncestorContainer),b.collapse(!0),this.isCollapsed()&&(b.startContainer===c.anchorNode||b.endContainer===c.anchorNode)&&b.startOffset===c.anchorOffset):void 0},caretIsInTheBeginnig:function(b){var c=this.getSelection(),d=c.anchorNode,e=c.anchorOffset;return b&&d?0===e&&(d.nodeName&&d.nodeName===b.toUpperCase()||a.dom.getParentElement(d.parentNode,{nodeName:b},1)):d?0===e&&!this.getPreviousNode(d,!0):void 0},caretIsBeforeUneditable:function(){var b,c,d,e=this.getSelection(),f=e.anchorNode,g=e.anchorOffset,h=[];if(f)if(0===g){var i=this.getPreviousNode(f,!0),j=i?a.dom.domNode(i).lastLeafNode(this.unselectableClass?{leafClasses:[this.unselectableClass]}:!1):null;if(j)for(var k=this.getOwnUneditables(),l=0,m=k.length;m>l;l++)if(j===k[l])return k[l]}else{if(b=e.getRangeAt(0),b.setStart(b.startContainer,b.startOffset-1),b){c=b.getNodes([1,3]);for(var n=0,o=c.length;o>n;n++)c[n].parentNode&&c[n].parentNode===f&&h.push(c[n])}if(d=h.length>0?h[h.length-1]:null,d&&1===d.nodeType&&a.dom.hasClass(d,this.unselectableClass))return d}return!1},executeAndRestoreRangy:function(a){var b=this.doc.defaultView||this.doc.parentWindow,c=rangy.saveSelection(b);if(c)try{a()}catch(d){setTimeout(function(){throw d},0)}else a();rangy.restoreSelection(c)},executeAndRestore:function(b,c){var d,f,g,h,i,j,k,l,m=this.doc.body,n=c&&m.scrollTop,o=c&&m.scrollLeft,p="_wysihtml5-temp-placeholder",q='<span class="'+p+'">'+a.INVISIBLE_SPACE+"</span>",r=this.getRange(!0);if(!r)return void b(m,m);r.collapsed||(k=r.cloneRange(),j=k.createContextualFragment(q),k.collapse(!1),k.insertNode(j),k.detach()),i=r.createContextualFragment(q),r.insertNode(i),j&&(d=this.contain.querySelectorAll("."+p),r.setStartBefore(d[0]),r.setEndAfter(d[d.length-1])),this.setSelection(r);try{b(r.startContainer,r.endContainer)}catch(s){setTimeout(function(){throw s},0)}if(d=this.contain.querySelectorAll("."+p),d&&d.length){l=rangy.createRange(this.doc),g=d[0].nextSibling,d.length>1&&(h=d[d.length-1].previousSibling),h&&g?(l.setStartBefore(g),l.setEndAfter(h)):(f=this.doc.createTextNode(a.INVISIBLE_SPACE),e.insert(f).after(d[0]),l.setStartBefore(f),l.setEndAfter(f)),this.setSelection(l);for(var t=d.length;t--;)d[t].parentNode.removeChild(d[t])}else this.contain.focus();c&&(m.scrollTop=n,m.scrollLeft=o);try{d.parentNode.removeChild(d)}catch(u){}},set:function(a,b){var c=rangy.createRange(this.doc);c.setStart(a,b||0),this.setSelection(c)},insertHTML:function(a){var b,c=(rangy.createRange(this.doc),this.doc.createElement("DIV")),d=this.doc.createDocumentFragment();for(c.innerHTML=a,b=c.lastChild;c.firstChild;)d.appendChild(c.firstChild);this.insertNode(d),b&&this.setAfter(b)},insertNode:function(a){var b=this.getRange();b&&b.insertNode(a)},surround:function(a){var b,c=this.getOwnRanges(),d=[];if(0==c.length)return d;for(var e=c.length;e--;){b=this.doc.createElement(a.nodeName),d.push(b),a.className&&(b.className=a.className),a.cssStyle&&b.setAttribute("style",a.cssStyle);try{c[e].surroundContents(b),this.selectNode(b)}catch(f){b.appendChild(c[e].extractContents()),c[e].insertNode(b)}}return d},deblockAndSurround:function(b){var c,d,e,f=this.doc.createElement("div"),g=rangy.createRange(this.doc);if(f.className=b.className,this.composer.commands.exec("formatBlock",b.nodeName,b.className),c=this.contain.querySelectorAll("."+b.className),c[0])for(c[0].parentNode.insertBefore(f,c[0]),g.setStartBefore(c[0]),g.setEndAfter(c[c.length-1]),d=g.extractContents();d.firstChild;)if(e=d.firstChild,1==e.nodeType&&a.dom.hasClass(e,b.className)){for(;e.firstChild;)f.appendChild(e.firstChild);"BR"!==e.nodeName&&f.appendChild(this.doc.createElement("br")),d.removeChild(e)}else f.appendChild(e);else f=null;return f},scrollIntoView:function(){var c,d=this.doc,e=5,f=d.documentElement.scrollHeight>d.documentElement.offsetHeight,g=d._wysihtml5ScrollIntoViewElement=d._wysihtml5ScrollIntoViewElement||function(){var b=d.createElement("span");return b.innerHTML=a.INVISIBLE_SPACE,b}();f&&(this.insertNode(g),c=b(g),g.parentNode.removeChild(g),c>=d.body.scrollTop+d.documentElement.offsetHeight-e&&(d.body.scrollTop=c))},selectLine:function(){a.browser.supportsSelectionModify()?this._selectLine_W3C():this.doc.selection&&this._selectLine_MSIE()},_selectLine_W3C:function(){var a=this.doc.defaultView,b=a.getSelection();b.modify("move","left","lineboundary"),b.modify("extend","right","lineboundary")},toLineBoundary:function(b,c){if(c="undefined"==typeof c?!1:c,a.browser.supportsSelectionModify()){var d=this.doc.defaultView,e=d.getSelection();e.modify("extend",b,"lineboundary"),c&&("left"===b?e.collapseToStart():"right"===b&&e.collapseToEnd())}},_selectLine_MSIE:function(){var a,b,c,d,e,f=this.doc.selection.createRange(),g=f.boundingTop,h=this.doc.body.scrollWidth;if(f.moveToPoint){for(0===g&&(c=this.doc.createElement("span"),this.insertNode(c),g=c.offsetTop,c.parentNode.removeChild(c)),g+=1,d=-10;h>d;d+=2)try{f.moveToPoint(d,g);break}catch(i){}for(a=g,b=this.doc.selection.createRange(),e=h;e>=0;e--)try{b.moveToPoint(e,a);break}catch(j){}f.setEndPoint("EndToEnd",b),f.select()}},getText:function(){var a=this.getSelection();return a?a.toString():""},getNodes:function(a,b){var c=this.getRange();return c?c.getNodes([a],b):[]},fixRangeOverflow:function(a){if(this.contain&&this.contain.firstChild&&a){var b=a.compareNode(this.contain);if(2!==b)1===b&&a.setStartBefore(this.contain.firstChild),0===b&&a.setEndAfter(this.contain.lastChild),3===b&&(a.setStartBefore(this.contain.firstChild),a.setEndAfter(this.contain.lastChild));else if(this._detectInlineRangeProblems(a)){var c=a.endContainer.previousElementSibling;c&&a.setEnd(c,this._endOffsetForNode(c))}}},_endOffsetForNode:function(a){var b=document.createRange();return b.selectNodeContents(a),b.endOffset},_detectInlineRangeProblems:function(a){var b=e.compareDocumentPosition(a.startContainer,a.endContainer);return 0==a.endOffset&&4&b},getRange:function(a){var b=this.getSelection(),c=b&&b.rangeCount&&b.getRangeAt(0);return a!==!0&&this.fixRangeOverflow(c),c},getOwnUneditables:function(){var b=e.query(this.contain,"."+this.unselectableClass),c=e.query(b,"."+this.unselectableClass);return a.lang.array(b).without(c)},getOwnRanges:function(){var a,b=[],c=this.getRange();if(c&&b.push(c),this.unselectableClass&&this.contain&&c){var d,e=this.getOwnUneditables();if(e.length>0)for(var f=0,g=e.length;g>f;f++){a=[];for(var h=0,i=b.length;i>h;h++){if(b[h])switch(b[h].compareNode(e[f])){case 2:break;case 3:d=b[h].cloneRange(),d.setEndBefore(e[f]),a.push(d),d=b[h].cloneRange(),d.setStartAfter(e[f]),a.push(d);break;default:a.push(b[h])}b=a}}}return b},getSelection:function(){return rangy.getSelection(this.doc.defaultView||this.doc.parentWindow)},setSelection:function(a){var b=this.doc.defaultView||this.doc.parentWindow,c=rangy.getSelection(b);return c.setSingleRange(a),c&&c.anchorNode&&c.focusNode?c:null},createRange:function(){return rangy.createRange(this.doc)},isCollapsed:function(){return this.getSelection().isCollapsed},getHtml:function(){return this.getSelection().toHtml()},getPlainText:function(){return this.getSelection().toString()},isEndToEndInNode:function(b){var c=this.getRange(),d=c.commonAncestorContainer,e=c.startContainer,f=c.endContainer;if(d.nodeType===a.TEXT_NODE&&(d=d.parentNode),e.nodeType===a.TEXT_NODE&&!/^\s*$/.test(e.data.substr(c.startOffset)))return!1;if(f.nodeType===a.TEXT_NODE&&!/^\s*$/.test(f.data.substr(c.endOffset)))return!1;for(;e&&e!==d;){if(e.nodeType!==a.TEXT_NODE&&!a.dom.contains(d,e))return!1;if(a.dom.domNode(e).prev({ignoreBlankTexts:!0}))return!1;e=e.parentNode}for(;f&&f!==d;){if(f.nodeType!==a.TEXT_NODE&&!a.dom.contains(d,f))return!1;if(a.dom.domNode(f).next({ignoreBlankTexts:!0}))return!1;f=f.parentNode}return a.lang.array(b).contains(d.nodeName)?d:!1},deselect:function(){var a=this.getSelection();a&&a.removeAllRanges()}})}(wysihtml5),function(a,b){function c(a,b,c){if(!a.className)return!1;var d=a.className.match(c)||[];return d[d.length-1]===b}function d(a,b){if(!a.getAttribute||!a.getAttribute("style"))return!1;a.getAttribute("style").match(b);return a.getAttribute("style").match(b)?!0:!1}function e(a,b,c){a.getAttribute("style")?(h(a,c),a.getAttribute("style")&&!/^\s*$/.test(a.getAttribute("style"))?a.setAttribute("style",b+";"+a.getAttribute("style")):a.setAttribute("style",b)):a.setAttribute("style",b)}function f(a,b,c){a.className?(g(a,c),a.className+=" "+b):a.className=b}function g(a,b){a.className&&(a.className=a.className.replace(b,""))}function h(a,b){var c,d=[];if(a.getAttribute("style")){c=a.getAttribute("style").split(";");for(var e=c.length;e--;)c[e].match(b)||/^\s*$/.test(c[e])||d.push(c[e]);d.length?a.setAttribute("style",d.join(";")):a.removeAttribute("style")}}function i(a,b){var c=[],d=b.split(";"),e=a.getAttribute("style");if(e){e=e.replace(/\s/gi,"").toLowerCase(),c.push(new RegExp("(^|\\s|;)"+b.replace(/\s/gi,"").replace(/([\(\)])/gi,"\\$1").toLowerCase().replace(";",";?").replace(/rgb\\\((\d+),(\d+),(\d+)\\\)/gi,"\\s?rgb\\($1,\\s?$2,\\s?$3\\)"),"gi"));for(var f=d.length;f-->0;)/^\s*$/.test(d[f])||c.push(new RegExp("(^|\\s|;)"+d[f].replace(/\s/gi,"").replace(/([\(\)])/gi,"\\$1").toLowerCase().replace(";",";?").replace(/rgb\\\((\d+),(\d+),(\d+)\\\)/gi,"\\s?rgb\\($1,\\s?$2,\\s?$3\\)"),"gi"));for(var g=0,h=c.length;h>g;g++)if(e.match(c[g]))return c[g]}return!1}function j(c,d,e,f){return e?i(c,e):f?a.dom.hasClass(c,f):b.dom.arrayContains(d,c.tagName.toLowerCase())}function k(a,b,c,d){for(var e=a.length;e--;)if(!j(a[e],b,c,d))return!1;return a.length?!0:!1}function l(a,b,c){var d=i(a,b);return d?(h(a,d),"remove"):(e(a,b,c),"change")}function m(a,b){return a.className.replace(u," ")==b.className.replace(u," ")}function n(a){for(var b=a.parentNode;a.firstChild;)b.insertBefore(a.firstChild,a);b.removeChild(a)}function o(a,b){if(a.attributes.length!=b.attributes.length)return!1;for(var c,d,e,f=0,g=a.attributes.length;g>f;++f)if(c=a.attributes[f],e=c.name,"class"!=e){if(d=b.attributes.getNamedItem(e),c.specified!=d.specified)return!1;if(c.specified&&c.nodeValue!==d.nodeValue)return!1}return!0}function p(a,c){return b.dom.isCharacterDataNode(a)?0==c?!!a.previousSibling:c==a.length?!!a.nextSibling:!0:c>0&&c<a.childNodes.length}function q(a,c,d,e){var f;if(b.dom.isCharacterDataNode(c)&&(0==d?(d=b.dom.getNodeIndex(c),c=c.parentNode):d==c.length?(d=b.dom.getNodeIndex(c)+1,c=c.parentNode):f=b.dom.splitDataNode(c,d)),!(f||e&&c===e)){f=c.cloneNode(!1),f.id&&f.removeAttribute("id");for(var g;g=c.childNodes[d];)f.appendChild(g);b.dom.insertAfter(f,c)}return c==a?f:q(a,f.parentNode,b.dom.getNodeIndex(f),e)}function r(b){this.isElementMerge=b.nodeType==a.ELEMENT_NODE,this.firstTextNode=this.isElementMerge?b.lastChild:b,this.textNodes=[this.firstTextNode]}function s(a,b,c,d,e,f,g){this.tagNames=a||[t],this.cssClass=b||(b===!1?!1:""),this.similarClassRegExp=c,this.cssStyle=e||"",this.similarStyleRegExp=f,this.normalize=d,this.applyToAnyTagName=!1,this.container=g}var t="span",u=/\s+/g;r.prototype={doMerge:function(){for(var a,b,c,d=[],e=0,f=this.textNodes.length;f>e;++e)a=this.textNodes[e],b=a.parentNode,d[e]=a.data,e&&(b.removeChild(a),b.hasChildNodes()||b.parentNode.removeChild(b));return this.firstTextNode.data=c=d.join(""),c},getLength:function(){for(var a=this.textNodes.length,b=0;a--;)b+=this.textNodes[a].length;return b},toString:function(){for(var a=[],b=0,c=this.textNodes.length;c>b;++b)a[b]="'"+this.textNodes[b].data+"'";return"[Merge("+a.join(",")+")]"}},s.prototype={getAncestorWithClass:function(d){for(var e;d;){if(e=this.cssClass?c(d,this.cssClass,this.similarClassRegExp):""!==this.cssStyle?!1:!0,d.nodeType==a.ELEMENT_NODE&&"false"!=d.getAttribute("contenteditable")&&b.dom.arrayContains(this.tagNames,d.tagName.toLowerCase())&&e)return d;d=d.parentNode}return!1},getAncestorWithStyle:function(c){for(var e;c;){if(e=this.cssStyle?d(c,this.similarStyleRegExp):!1,c.nodeType==a.ELEMENT_NODE&&"false"!=c.getAttribute("contenteditable")&&b.dom.arrayContains(this.tagNames,c.tagName.toLowerCase())&&e)return c;c=c.parentNode}return!1},getMatchingAncestor:function(a){var b=this.getAncestorWithClass(a),c=!1;return b?this.cssStyle&&(c="class"):(b=this.getAncestorWithStyle(a),b&&(c="style")),{element:b,type:c}},postApply:function(a,b){for(var c,d,e,f=a[0],g=a[a.length-1],h=[],i=f,j=g,k=0,l=g.length,m=0,n=a.length;n>m;++m)d=a[m],e=null,d&&d.parentNode&&(e=this.getAdjacentMergeableTextNode(d.parentNode,!1)),e?(c||(c=new r(e),h.push(c)),c.textNodes.push(d),d===f&&(i=c.firstTextNode,k=i.length),d===g&&(j=c.firstTextNode,l=c.getLength())):c=null;if(g&&g.parentNode){var o=this.getAdjacentMergeableTextNode(g.parentNode,!0);o&&(c||(c=new r(g),h.push(c)),c.textNodes.push(o))}if(h.length){for(m=0,n=h.length;n>m;++m)h[m].doMerge();b.setStart(i,k),b.setEnd(j,l)}},getAdjacentMergeableTextNode:function(b,c){var d,e=b.nodeType==a.TEXT_NODE,f=e?b.parentNode:b,g=c?"nextSibling":"previousSibling";if(e){if(d=b[g],d&&d.nodeType==a.TEXT_NODE)return d}else if(d=f[g],d&&this.areElementsMergeable(b,d))return d[c?"firstChild":"lastChild"];return null},areElementsMergeable:function(a,c){return b.dom.arrayContains(this.tagNames,(a.tagName||"").toLowerCase())&&b.dom.arrayContains(this.tagNames,(c.tagName||"").toLowerCase())&&m(a,c)&&o(a,c)},createContainer:function(a){var b=a.createElement(this.tagNames[0]);return this.cssClass&&(b.className=this.cssClass),this.cssStyle&&b.setAttribute("style",this.cssStyle),b},applyToTextNode:function(a){var c=a.parentNode;if(1==c.childNodes.length&&b.dom.arrayContains(this.tagNames,c.tagName.toLowerCase()))this.cssClass&&f(c,this.cssClass,this.similarClassRegExp),this.cssStyle&&e(c,this.cssStyle,this.similarStyleRegExp);else{var d=this.createContainer(b.dom.getDocument(a));a.parentNode.insertBefore(d,a),d.appendChild(a)}},isRemovable:function(c){return b.dom.arrayContains(this.tagNames,c.tagName.toLowerCase())&&""===a.lang.string(c.className).trim()&&(!c.getAttribute("style")||""===a.lang.string(c.getAttribute("style")).trim())},undoToTextNode:function(a,b,c,d){var e=c?!1:!0,f=c||d,h=!1;if(!b.containsNode(f)){var i=b.cloneRange();i.selectNode(f),i.isPointInRange(b.endContainer,b.endOffset)&&p(b.endContainer,b.endOffset)&&(q(f,b.endContainer,b.endOffset,this.container),b.setEndAfter(f)),i.isPointInRange(b.startContainer,b.startOffset)&&p(b.startContainer,b.startOffset)&&(f=q(f,b.startContainer,b.startOffset,this.container))}!e&&this.similarClassRegExp&&g(f,this.similarClassRegExp),e&&this.similarStyleRegExp&&(h="change"===l(f,this.cssStyle,this.similarStyleRegExp)),this.isRemovable(f)&&!h&&n(f)},applyToRange:function(b){for(var c,d=b.length;d--;){if(c=b[d].getNodes([a.TEXT_NODE]),!c.length)try{var e=this.createContainer(b[d].endContainer.ownerDocument);return b[d].surroundContents(e),void this.selectNode(b[d],e)}catch(f){}if(b[d].splitBoundaries(),c=b[d].getNodes([a.TEXT_NODE]),c.length){for(var g,h=0,i=c.length;i>h;++h)g=c[h],this.getMatchingAncestor(g).element||this.applyToTextNode(g);b[d].setStart(c[0],0),g=c[c.length-1],b[d].setEnd(g,g.length),this.normalize&&this.postApply(c,b[d])}}},undoToRange:function(b){for(var c,d,e,f=b.length;f--;){if(c=b[f].getNodes([a.TEXT_NODE]),c.length)b[f].splitBoundaries(),c=b[f].getNodes([a.TEXT_NODE]);
+else{var g=b[f].endContainer.ownerDocument,h=g.createTextNode(a.INVISIBLE_SPACE);b[f].insertNode(h),b[f].selectNode(h),c=[h]}for(var i=0,j=c.length;j>i;++i)b[f].isValid()&&(d=c[i],e=this.getMatchingAncestor(d),"style"===e.type?this.undoToTextNode(d,b[f],!1,e.element):e.element&&this.undoToTextNode(d,b[f],e.element));1==j?this.selectNode(b[f],c[0]):(b[f].setStart(c[0],0),d=c[c.length-1],b[f].setEnd(d,d.length),this.normalize&&this.postApply(c,b[f]))}},selectNode:function(b,c){var d=c.nodeType===a.ELEMENT_NODE,e="canHaveHTML"in c?c.canHaveHTML:!0,f=d?c.innerHTML:c.data,g=""===f||f===a.INVISIBLE_SPACE;if(g&&d&&e)try{c.innerHTML=a.INVISIBLE_SPACE}catch(h){}b.selectNodeContents(c),g&&d?b.collapse(!1):g&&(b.setStartAfter(c),b.setEndAfter(c))},getTextSelectedByRange:function(a,b){var c=b.cloneRange();c.selectNodeContents(a);var d=c.intersection(b),e=d?d.toString():"";return c.detach(),e},isAppliedToRange:function(b){for(var c,d,e=[],f="full",g=b.length;g--;){if(d=b[g].getNodes([a.TEXT_NODE]),!d.length)return c=this.getMatchingAncestor(b[g].startContainer).element,c?{elements:[c],coverage:f}:!1;for(var h,i=0,j=d.length;j>i;++i)h=this.getTextSelectedByRange(d[i],b[g]),c=this.getMatchingAncestor(d[i]).element,c&&""!=h?(e.push(c),1===a.dom.getTextNodes(c,!0).length?f="full":"full"===f&&(f="inline")):c||(f="partial")}return e.length?{elements:e,coverage:f}:!1},toggleRange:function(a){var b,c=this.isAppliedToRange(a);c?"full"===c.coverage?this.undoToRange(a):"inline"===c.coverage?(b=k(c.elements,this.tagNames,this.cssStyle,this.cssClass),this.undoToRange(a),b||this.applyToRange(a)):(k(c.elements,this.tagNames,this.cssStyle,this.cssClass)||this.undoToRange(a),this.applyToRange(a)):this.applyToRange(a)}},a.selection.HTMLApplier=s}(wysihtml5,rangy),wysihtml5.Commands=Base.extend({constructor:function(a){this.editor=a,this.composer=a.composer,this.doc=this.composer.doc},support:function(a){return wysihtml5.browser.supportsCommand(this.doc,a)},exec:function(a,b){var c=wysihtml5.commands[a],d=wysihtml5.lang.array(arguments).get(),e=c&&c.exec,f=null;if(this.composer.hasPlaceholderSet()&&!wysihtml5.lang.array(["styleWithCSS","enableObjectResizing","enableInlineTableEditing"]).contains(a)&&(this.composer.element.innerHTML="",this.composer.selection.selectNode(this.composer.element)),this.editor.fire("beforecommand:composer"),e)d.unshift(this.composer),f=e.apply(c,d);else try{f=this.doc.execCommand(a,!1,b)}catch(g){}return this.editor.fire("aftercommand:composer"),f},state:function(a){var b=wysihtml5.commands[a],c=wysihtml5.lang.array(arguments).get(),d=b&&b.state;if(d)return c.unshift(this.composer),d.apply(b,c);try{return this.doc.queryCommandState(a)}catch(e){return!1}},stateValue:function(a){var b=wysihtml5.commands[a],c=wysihtml5.lang.array(arguments).get(),d=b&&b.stateValue;return d?(c.unshift(this.composer),d.apply(b,c)):!1}}),wysihtml5.commands.bold={exec:function(a,b){wysihtml5.commands.formatInline.execWithToggle(a,b,"b")},state:function(a,b){return wysihtml5.commands.formatInline.state(a,b,"b")}},function(a){function b(b,c){var g,h,i,j,k,l,m,n,o,p=b.doc,q="_wysihtml5-temp-"+ +new Date,r=/non-matching-class/g,s=0;for(a.commands.formatInline.exec(b,d,e,q,r,d,d,!0,!0),h=p.querySelectorAll(e+"."+q),g=h.length;g>s;s++){i=h[s],i.removeAttribute("class");for(o in c)"text"!==o&&i.setAttribute(o,c[o])}l=i,1===g&&(m=f.getTextContent(i),j=!!i.querySelector("*"),k=""===m||m===a.INVISIBLE_SPACE,!j&&k&&(f.setTextContent(i,c.text||i.href),n=p.createTextNode(" "),b.selection.setAfter(i),f.insert(n).after(i),l=n)),b.selection.setAfter(l)}function c(a,b,c){for(var d,e=b.length;e--;){d=b[e].attributes;for(var f=d.length;f--;)b[e].removeAttribute(d.item(f).name);for(var g in c)c.hasOwnProperty(g)&&b[e].setAttribute(g,c[g])}}var d,e="A",f=a.dom;a.commands.createLink={exec:function(a,d,e){var f=this.state(a,d);f?a.selection.executeAndRestore(function(){c(a,f,e)}):(e="object"==typeof e?e:{href:e},b(a,e))},state:function(b,c){return a.commands.formatInline.state(b,c,"A")}}}(wysihtml5),function(a){function b(a,b){for(var d,e,f,g=b.length,h=0;g>h;h++)d=b[h],e=c.getParentElement(d,{nodeName:"code"}),f=c.getTextContent(d),f.match(c.autoLink.URL_REG_EXP)&&!e?e=c.renameElement(d,"code"):c.replaceWithChildNodes(d)}var c=a.dom;a.commands.removeLink={exec:function(a,c){var d=this.state(a,c);d&&a.selection.executeAndRestore(function(){b(a,d)})},state:function(b,c){return a.commands.formatInline.state(b,c,"A")}}}(wysihtml5),function(a){var b=/wysiwyg-font-size-[0-9a-z\-]+/g;a.commands.fontSize={exec:function(c,d,e){a.commands.formatInline.execWithToggle(c,d,"span","wysiwyg-font-size-"+e,b)},state:function(c,d,e){return a.commands.formatInline.state(c,d,"span","wysiwyg-font-size-"+e,b)}}}(wysihtml5),function(a){var b=/(\s|^)font-size\s*:\s*[^;\s]+;?/gi;a.commands.fontSizeStyle={exec:function(c,d,e){e="object"==typeof e?e.size:e,/^\s*$/.test(e)||a.commands.formatInline.execWithToggle(c,d,"span",!1,!1,"font-size:"+e,b)},state:function(c,d){return a.commands.formatInline.state(c,d,"span",!1,!1,"font-size",b)},stateValue:function(b,c){var d,e=this.state(b,c);return e&&a.lang.object(e).isArray()&&(e=e[0]),e&&(d=e.getAttribute("style"))?a.quirks.styleParser.parseFontSize(d):!1}}}(wysihtml5),function(a){var b=/wysiwyg-color-[0-9a-z]+/g;a.commands.foreColor={exec:function(c,d,e){a.commands.formatInline.execWithToggle(c,d,"span","wysiwyg-color-"+e,b)},state:function(c,d,e){return a.commands.formatInline.state(c,d,"span","wysiwyg-color-"+e,b)}}}(wysihtml5),function(a){var b=/(\s|^)color\s*:\s*[^;\s]+;?/gi;a.commands.foreColorStyle={exec:function(c,d,e){var f,g=a.quirks.styleParser.parseColor("object"==typeof e?"color:"+e.color:"color:"+e,"color");g&&(f="color: rgb("+g[0]+","+g[1]+","+g[2]+");",1!==g[3]&&(f+="color: rgba("+g[0]+","+g[1]+","+g[2]+","+g[3]+");"),a.commands.formatInline.execWithToggle(c,d,"span",!1,!1,f,b))},state:function(c,d){return a.commands.formatInline.state(c,d,"span",!1,!1,"color",b)},stateValue:function(b,c,d){var e,f=this.state(b,c);return f&&a.lang.object(f).isArray()&&(f=f[0]),f&&(e=f.getAttribute("style"),e&&e)?(val=a.quirks.styleParser.parseColor(e,"color"),a.quirks.styleParser.unparseColor(val,d)):!1}}}(wysihtml5),function(a){var b=/(\s|^)background-color\s*:\s*[^;\s]+;?/gi;a.commands.bgColorStyle={exec:function(c,d,e){var f,g=a.quirks.styleParser.parseColor("object"==typeof e?"background-color:"+e.color:"background-color:"+e,"background-color");g&&(f="background-color: rgb("+g[0]+","+g[1]+","+g[2]+");",1!==g[3]&&(f+="background-color: rgba("+g[0]+","+g[1]+","+g[2]+","+g[3]+");"),a.commands.formatInline.execWithToggle(c,d,"span",!1,!1,f,b))},state:function(c,d){return a.commands.formatInline.state(c,d,"span",!1,!1,"background-color",b)},stateValue:function(b,c,d){var e,f=this.state(b,c),g=!1;return f&&a.lang.object(f).isArray()&&(f=f[0]),f&&(e=f.getAttribute("style"))?(g=a.quirks.styleParser.parseColor(e,"background-color"),a.quirks.styleParser.unparseColor(g,d)):!1}}}(wysihtml5),function(a){function b(b,c,e){b.className?(d(b,e),b.className=a.lang.string(b.className+" "+c).trim()):b.className=c}function c(b,c,d){e(b,d),b.getAttribute("style")?b.setAttribute("style",a.lang.string(b.getAttribute("style")+" "+c).trim()):b.setAttribute("style",c)}function d(b,c){var d=c.test(b.className);return b.className=b.className.replace(c,""),""==a.lang.string(b.className).trim()&&b.removeAttribute("class"),d}function e(b,c){var d=c.test(b.getAttribute("style"));return b.setAttribute("style",(b.getAttribute("style")||"").replace(c,"")),""==a.lang.string(b.getAttribute("style")||"").trim()&&b.removeAttribute("style"),d}function f(a){var b=a.lastChild;b&&g(b)&&b.parentNode.removeChild(b)}function g(a){return"BR"===a.nodeName}function h(b,c){b.selection.isCollapsed()&&b.selection.selectLine();for(var d=b.selection.surround(c),e=0,g=d.length;g>e;e++)a.dom.lineBreaks(d[e]).remove(),f(d[e])}function i(b){return!!a.lang.string(b.className).trim()}function j(b){return!!a.lang.string(b.getAttribute("style")||"").trim()}var k=a.dom,l=["H1","H2","H3","H4","H5","H6","P","PRE","DIV"];a.commands.formatBlock={exec:function(f,g,m,n,o,p,q){var r,s,t,u,v,w=(f.doc,this.state(f,g,m,n,o,p,q)),x=f.config.useLineBreaks,y=x?"DIV":"P";return m="string"==typeof m?m.toUpperCase():m,w.length?void f.selection.executeAndRestoreRangy(function(){for(var b=w.length;b--;){if(o&&(s=d(w[b],o)),q&&(u=e(w[b],q)),(u||s)&&null===m&&w[b].nodeName!=y)return;var c=i(w[b]),f=j(w[b]);c||f||!x&&"P"!==m?k.renameElement(w[b],"P"===m?"DIV":y):(a.dom.lineBreaks(w[b]).add(),k.replaceWithChildNodes(w[b]))}}):void((null!==m&&!a.lang.array(l).contains(m)||(r=f.selection.findNodesInSelection(l).concat(f.selection.getSelectedOwnNodes()),f.selection.executeAndRestoreRangy(function(){for(var a=r.length;a--;)v=k.getParentElement(r[a],{nodeName:l}),v==f.element&&(v=null),v&&(m&&(v=k.renameElement(v,m)),n&&b(v,n,o),p&&c(v,p,q),t=!0)}),!t))&&h(f,{nodeName:m||y,className:n||null,cssStyle:p||null}))},state:function(b,c,d,e,f,g,h){var i,j=b.selection.getSelectedOwnNodes(),l=[];d="string"==typeof d?d.toUpperCase():d;for(var m=0,n=j.length;n>m;m++)i=k.getParentElement(j[m],{nodeName:d,className:e,classRegExp:f,cssStyle:g,styleRegExp:h}),i&&-1==a.lang.array(l).indexOf(i)&&l.push(i);return 0==l.length?!1:l}}}(wysihtml5),wysihtml5.commands.formatCode={exec:function(a,b,c){var d,e,f,g=this.state(a);g?a.selection.executeAndRestore(function(){d=g.querySelector("code"),wysihtml5.dom.replaceWithChildNodes(g),d&&wysihtml5.dom.replaceWithChildNodes(d)}):(e=a.selection.getRange(),f=e.extractContents(),g=a.doc.createElement("pre"),d=a.doc.createElement("code"),c&&(d.className=c),g.appendChild(d),d.appendChild(f),e.insertNode(g),a.selection.selectNode(g))},state:function(a){var b=a.selection.getSelectedNode();return b&&b.nodeName&&"PRE"==b.nodeName&&b.firstChild&&b.firstChild.nodeName&&"CODE"==b.firstChild.nodeName?b:wysihtml5.dom.getParentElement(b,{nodeName:"CODE"})&&wysihtml5.dom.getParentElement(b,{nodeName:"PRE"})}},function(a){function b(a){var b=d[a];return b?[a.toLowerCase(),b.toLowerCase()]:[a.toLowerCase()]}function c(c,d,f,g,h,i){var j=c;return d&&(j+=":"+d),g&&(j+=":"+g),e[j]||(e[j]=new a.selection.HTMLApplier(b(c),d,f,!0,g,h,i)),e[j]}var d={strong:"b",em:"i",b:"strong",i:"em"},e={};a.commands.formatInline={exec:function(a,b,d,e,f,g,h,i,j){var k=a.selection.createRange(),l=a.selection.getOwnRanges();return l&&0!=l.length?(a.selection.getSelection().removeAllRanges(),c(d,e,f,g,h,a.element).toggleRange(l),void(i?j||a.cleanUp():(k.setStart(l[0].startContainer,l[0].startOffset),k.setEnd(l[l.length-1].endContainer,l[l.length-1].endOffset),a.selection.setSelection(k),a.selection.executeAndRestore(function(){j||a.cleanUp()},!0,!0)))):!1},execWithToggle:function(b,c,d,e,f,g,h){var i=this;if(this.state(b,c,d,e,f,g,h)&&b.selection.isCollapsed()&&!b.selection.caretIsLastInSelection()&&!b.selection.caretIsFirstInSelection()){var j=i.state(b,c,d,e,f)[0];b.selection.executeAndRestoreRangy(function(){j.parentNode;b.selection.selectNode(j,!0),a.commands.formatInline.exec(b,c,d,e,f,g,h,!0,!0)})}else this.state(b,c,d,e,f,g,h)&&!b.selection.isCollapsed()?b.selection.executeAndRestoreRangy(function(){a.commands.formatInline.exec(b,c,d,e,f,g,h,!0,!0)}):a.commands.formatInline.exec(b,c,d,e,f,g,h)},state:function(b,e,f,g,h,i,j){var k,l,m=b.doc,n=d[f]||f;return a.dom.hasElementWithTagName(m,f)||a.dom.hasElementWithTagName(m,n)?g&&!a.dom.hasElementWithClassName(m,g)?!1:(k=b.selection.getOwnRanges(),k&&0!==k.length?(l=c(f,g,h,i,j,b.element).isAppliedToRange(k),l&&l.elements?l.elements:!1):!1):!1}}}(wysihtml5),function(a){a.commands.insertBlockQuote={exec:function(b,c){var d=this.state(b,c),e=b.selection.isEndToEndInNode(["H1","H2","H3","H4","H5","H6","P"]);b.selection.executeAndRestore(function(){if(d)b.config.useLineBreaks&&a.dom.lineBreaks(d).add(),a.dom.unwrap(d);else if(b.selection.isCollapsed()&&b.selection.selectLine(),e){var c=e.ownerDocument.createElement("blockquote");a.dom.insert(c).after(e),c.appendChild(e)}else b.selection.surround({nodeName:"blockquote"})})},state:function(b){var c=b.selection.getSelectedNode(),d=a.dom.getParentElement(c,{nodeName:"BLOCKQUOTE"},!1,b.element);return d?d:!1}}}(wysihtml5),wysihtml5.commands.insertHTML={exec:function(a,b,c){a.commands.support(b)?a.doc.execCommand(b,!1,c):a.selection.insertHTML(c)},state:function(){return!1}},function(a){var b="IMG";a.commands.insertImage={exec:function(c,d,e){e="object"==typeof e?e:{src:e};var f,g,h=c.doc,i=this.state(c);if(i)return c.selection.setBefore(i),g=i.parentNode,g.removeChild(i),a.dom.removeEmptyTextNodes(g),"A"!==g.nodeName||g.firstChild||(c.selection.setAfter(g),g.parentNode.removeChild(g)),void a.quirks.redraw(c.element);i=h.createElement(b);for(var j in e)i.setAttribute("className"===j?"class":j,e[j]);c.selection.insertNode(i),a.browser.hasProblemsSettingCaretAfterImg()?(f=h.createTextNode(a.INVISIBLE_SPACE),c.selection.insertNode(f),c.selection.setAfter(f)):c.selection.setAfter(i)},state:function(c){var d,e,f,g=c.doc;return a.dom.hasElementWithTagName(g,b)&&(d=c.selection.getSelectedNode())?d.nodeName===b?d:d.nodeType!==a.ELEMENT_NODE?!1:(e=c.selection.getText(),(e=a.lang.string(e).trim())?!1:(f=c.selection.getNodes(a.ELEMENT_NODE,function(a){return"IMG"===a.nodeName}),1!==f.length?!1:f[0])):!1}}}(wysihtml5),function(a){var b="<br>"+(a.browser.needsSpaceAfterLineBreak()?" ":"");a.commands.insertLineBreak={exec:function(c,d){c.commands.support(d)?(c.doc.execCommand(d,!1,null),a.browser.autoScrollsToCaret()||c.selection.scrollIntoView()):c.commands.exec("insertHTML",b)},state:function(){return!1}}}(wysihtml5),wysihtml5.commands.insertOrderedList={exec:function(a,b){wysihtml5.commands.insertList.exec(a,b,"OL")},state:function(a,b){return wysihtml5.commands.insertList.state(a,b,"OL")}},wysihtml5.commands.insertUnorderedList={exec:function(a,b){wysihtml5.commands.insertList.exec(a,b,"UL")},state:function(a,b){return wysihtml5.commands.insertList.state(a,b,"UL")}},wysihtml5.commands.insertList=function(a){var b=function(a,b){if(a&&a.nodeName){"string"==typeof b&&(b=[b]);for(var c=b.length;c--;)if(a.nodeName===b[c])return!0}return!1},c=function(c,d,e){var f={el:null,other:!1};if(c){var g=a.dom.getParentElement(c,{nodeName:"LI"}),h="UL"===d?"OL":"UL";b(c,d)?f.el=c:b(c,h)?f={el:c,other:!0}:g&&(b(g.parentNode,d)?f.el=g.parentNode:b(g.parentNode,h)&&(f={el:g.parentNode,other:!0}))}return f.el&&!e.element.contains(f.el)&&(f.el=null),f},d=function(b,c,d){var e,g="UL"===c?"OL":"UL";d.selection.executeAndRestore(function(){var h=f(g,d);if(h.length)for(var i=h.length;i--;)a.dom.renameElement(h[i],c.toLowerCase());else{e=f(["OL","UL"],d);for(var j=e.length;j--;)a.dom.resolveList(e[j],d.config.useLineBreaks);a.dom.resolveList(b,d.config.useLineBreaks)}})},e=function(b,c,d){var e="UL"===c?"OL":"UL";d.selection.executeAndRestore(function(){for(var g=[b].concat(f(e,d)),h=g.length;h--;)a.dom.renameElement(g[h],c.toLowerCase())})},f=function(a,c){for(var d=c.selection.getOwnRanges(),e=[],f=d.length;f--;)e=e.concat(d[f].getNodes([1],function(c){return b(c,a)}));return e},g=function(b,c){c.selection.executeAndRestoreRangy(function(){var d,e,f="_wysihtml5-temp-"+(new Date).getTime(),g=c.selection.deblockAndSurround({nodeName:"div",className:f});g.innerHTML=g.innerHTML.replace(a.INVISIBLE_SPACE_REG_EXP,""),g&&(d=a.lang.array(["","<br>",a.INVISIBLE_SPACE]).contains(g.innerHTML),e=a.dom.convertToList(g,b.toLowerCase(),c.parent.config.uneditableContainerClassname),d&&c.selection.selectNode(e.querySelector("li"),!0))})};return{exec:function(a,b,f){var h=a.doc,i="OL"===f?"insertOrderedList":"insertUnorderedList",j=a.selection.getSelectedNode(),k=c(j,f,a);k.el?k.other?e(k.el,f,a):d(k.el,f,a):a.commands.support(i)?h.execCommand(i,!1,null):g(f,a)},state:function(a,b,d){var e=a.selection.getSelectedNode(),f=c(e,d,a);return f.el&&!f.other?f.el:!1}}}(wysihtml5),wysihtml5.commands.italic={exec:function(a,b){wysihtml5.commands.formatInline.execWithToggle(a,b,"i")},state:function(a,b){return wysihtml5.commands.formatInline.state(a,b,"i")}},function(a){var b="wysiwyg-text-align-center",c=/wysiwyg-text-align-[0-9a-z]+/g;a.commands.justifyCenter={exec:function(d){return a.commands.formatBlock.exec(d,"formatBlock",null,b,c)},state:function(d){return a.commands.formatBlock.state(d,"formatBlock",null,b,c)}}}(wysihtml5),function(a){var b="wysiwyg-text-align-left",c=/wysiwyg-text-align-[0-9a-z]+/g;a.commands.justifyLeft={exec:function(d){return a.commands.formatBlock.exec(d,"formatBlock",null,b,c)},state:function(d){return a.commands.formatBlock.state(d,"formatBlock",null,b,c)}}}(wysihtml5),function(a){var b="wysiwyg-text-align-right",c=/wysiwyg-text-align-[0-9a-z]+/g;a.commands.justifyRight={exec:function(d){return a.commands.formatBlock.exec(d,"formatBlock",null,b,c)},state:function(d){return a.commands.formatBlock.state(d,"formatBlock",null,b,c)}}}(wysihtml5),function(a){var b="wysiwyg-text-align-justify",c=/wysiwyg-text-align-[0-9a-z]+/g;a.commands.justifyFull={exec:function(d){return a.commands.formatBlock.exec(d,"formatBlock",null,b,c)},state:function(d){return a.commands.formatBlock.state(d,"formatBlock",null,b,c)}}}(wysihtml5),function(a){var b="text-align: right;",c=/(\s|^)text-align\s*:\s*[^;\s]+;?/gi;a.commands.alignRightStyle={exec:function(d){return a.commands.formatBlock.exec(d,"formatBlock",null,null,null,b,c)},state:function(d){return a.commands.formatBlock.state(d,"formatBlock",null,null,null,b,c)}}}(wysihtml5),function(a){var b="text-align: left;",c=/(\s|^)text-align\s*:\s*[^;\s]+;?/gi;a.commands.alignLeftStyle={exec:function(d){return a.commands.formatBlock.exec(d,"formatBlock",null,null,null,b,c)},state:function(d){return a.commands.formatBlock.state(d,"formatBlock",null,null,null,b,c)}}}(wysihtml5),function(a){var b="text-align: center;",c=/(\s|^)text-align\s*:\s*[^;\s]+;?/gi;a.commands.alignCenterStyle={exec:function(d){return a.commands.formatBlock.exec(d,"formatBlock",null,null,null,b,c)},state:function(d){return a.commands.formatBlock.state(d,"formatBlock",null,null,null,b,c)}}}(wysihtml5),wysihtml5.commands.redo={exec:function(a){return a.undoManager.redo()},state:function(){return!1}},wysihtml5.commands.underline={exec:function(a,b){wysihtml5.commands.formatInline.execWithToggle(a,b,"u")},state:function(a,b){return wysihtml5.commands.formatInline.state(a,b,"u")}},wysihtml5.commands.undo={exec:function(a){return a.undoManager.undo()},state:function(){return!1}},wysihtml5.commands.createTable={exec:function(a,b,c){var d,e,f;if(c&&c.cols&&c.rows&&parseInt(c.cols,10)>0&&parseInt(c.rows,10)>0){for(f=c.tableStyle?'<table style="'+c.tableStyle+'">':"<table>",f+="<tbody>",e=0;e<c.rows;e++){for(f+="<tr>",d=0;d<c.cols;d++)f+="<td> </td>";f+="</tr>"}f+="</tbody></table>",a.commands.exec("insertHTML",f)}},state:function(){return!1}},wysihtml5.commands.mergeTableCells={exec:function(a,b){a.tableSelection&&a.tableSelection.start&&a.tableSelection.end&&(this.state(a,b)?wysihtml5.dom.table.unmergeCell(a.tableSelection.start):wysihtml5.dom.table.mergeCellsBetween(a.tableSelection.start,a.tableSelection.end))},state:function(a){if(a.tableSelection){var b=a.tableSelection.start,c=a.tableSelection.end;if(b&&c&&b==c&&(wysihtml5.dom.getAttribute(b,"colspan")&&parseInt(wysihtml5.dom.getAttribute(b,"colspan"),10)>1||wysihtml5.dom.getAttribute(b,"rowspan")&&parseInt(wysihtml5.dom.getAttribute(b,"rowspan"),10)>1))return[b]}return!1}},wysihtml5.commands.addTableCells={exec:function(a,b,c){if(a.tableSelection&&a.tableSelection.start&&a.tableSelection.end){var d=wysihtml5.dom.table.orderSelectionEnds(a.tableSelection.start,a.tableSelection.end);"before"==c||"above"==c?wysihtml5.dom.table.addCells(d.start,c):("after"==c||"below"==c)&&wysihtml5.dom.table.addCells(d.end,c),setTimeout(function(){a.tableSelection.select(d.start,d.end)},0)}},state:function(){return!1}},wysihtml5.commands.deleteTableCells={exec:function(a,b,c){if(a.tableSelection&&a.tableSelection.start&&a.tableSelection.end){var d,e=wysihtml5.dom.table.orderSelectionEnds(a.tableSelection.start,a.tableSelection.end),f=wysihtml5.dom.table.indexOf(e.start),g=a.tableSelection.table;wysihtml5.dom.table.removeCells(e.start,c),setTimeout(function(){d=wysihtml5.dom.table.findCell(g,f),d||("row"==c&&(d=wysihtml5.dom.table.findCell(g,{row:f.row-1,col:f.col})),"column"==c&&(d=wysihtml5.dom.table.findCell(g,{row:f.row,col:f.col-1}))),d&&a.tableSelection.select(d,d)},0)}},state:function(){return!1}},wysihtml5.commands.indentList={exec:function(a){var b=a.selection.getSelectionParentsByTag("LI");return b?this.tryToPushLiLevel(b,a.selection):!1},state:function(){return!1},tryToPushLiLevel:function(a,b){var c,d,e,f,g,h=!1;return b.executeAndRestoreRangy(function(){for(var b=a.length;b--;)f=a[b],c="OL"===f.parentNode.nodeName?"OL":"UL",d=f.ownerDocument.createElement(c),e=wysihtml5.dom.domNode(f).prev({nodeTypes:[wysihtml5.ELEMENT_NODE]}),g=e?e.querySelector("ul, ol"):null,e&&(g?g.appendChild(f):(d.appendChild(f),e.appendChild(d)),h=!0)}),h}},wysihtml5.commands.outdentList={exec:function(a){var b=a.selection.getSelectionParentsByTag("LI");return b?this.tryToPullLiLevel(b,a):!1},state:function(){return!1},tryToPullLiLevel:function(a,b){var c,d,e,f,g,h=!1,i=this;return b.selection.executeAndRestoreRangy(function(){for(var j=a.length;j--;)if(f=a[j],f.parentNode&&(c=f.parentNode,"OL"===c.tagName||"UL"===c.tagName)){if(h=!0,d=wysihtml5.dom.getParentElement(c.parentNode,{nodeName:["OL","UL"]},!1,b.element),e=wysihtml5.dom.getParentElement(c.parentNode,{nodeName:["LI"]},!1,b.element),d&&e)f.nextSibling&&(g=i.getAfterList(c,f),f.appendChild(g)),d.insertBefore(f,e.nextSibling);else{f.nextSibling&&(g=i.getAfterList(c,f),f.appendChild(g));for(var k=f.childNodes.length;k--;)c.parentNode.insertBefore(f.childNodes[k],c.nextSibling);c.parentNode.insertBefore(document.createElement("br"),c.nextSibling),f.parentNode.removeChild(f)}0===c.childNodes.length&&c.parentNode.removeChild(c)}}),h},getAfterList:function(a,b){for(var c=a.nodeName,d=document.createElement(c);b.nextSibling;)d.appendChild(b.nextSibling);return d}},function(a){var b=90,c=89,d=8,e=46,f=25,g="data-wysihtml5-selection-node",h="data-wysihtml5-selection-offset",i=('<span id="_wysihtml5-undo" class="_wysihtml5-temp">'+a.INVISIBLE_SPACE+"</span>",'<span id="_wysihtml5-redo" class="_wysihtml5-temp">'+a.INVISIBLE_SPACE+"</span>",a.dom);a.UndoManager=a.lang.Dispatcher.extend({constructor:function(a){this.editor=a,this.composer=a.composer,this.element=this.composer.element,this.position=0,this.historyStr=[],this.historyDom=[],this.transact(),this._observe()},_observe:function(){{var a,f=this;this.composer.sandbox.getDocument()}i.observe(this.element,"keydown",function(a){if(!a.altKey&&(a.ctrlKey||a.metaKey)){var d=a.keyCode,e=d===b&&!a.shiftKey,g=d===b&&a.shiftKey||d===c;e?(f.undo(),a.preventDefault()):g&&(f.redo(),a.preventDefault())}}),i.observe(this.element,"keydown",function(b){var c=b.keyCode;c!==a&&(a=c,(c===d||c===e)&&f.transact())}),this.editor.on("newword:composer",function(){f.transact()}).on("beforecommand:composer",function(){f.transact()})},transact:function(){var b,c,d,e,i,j=this.historyStr[this.position-1],k=this.composer.getValue(!1,!1),l=this.element.offsetWidth>0&&this.element.offsetHeight>0;if(k!==j){var m=this.historyStr.length=this.historyDom.length=this.position;m>f&&(this.historyStr.shift(),this.historyDom.shift(),this.position--),this.position++,l&&(b=this.composer.selection.getRange(),c=b&&b.startContainer?b.startContainer:this.element,d=b&&b.startOffset?b.startOffset:0,c.nodeType===a.ELEMENT_NODE?e=c:(e=c.parentNode,i=this.getChildNodeIndex(e,c)),e.setAttribute(h,d),"undefined"!=typeof i&&e.setAttribute(g,i));var n=this.element.cloneNode(!!k);this.historyDom.push(n),this.historyStr.push(k),e&&(e.removeAttribute(h),e.removeAttribute(g))}},undo:function(){this.transact(),this.undoPossible()&&(this.set(this.historyDom[--this.position-1]),this.editor.fire("undo:composer"))},redo:function(){this.redoPossible()&&(this.set(this.historyDom[++this.position-1]),this.editor.fire("redo:composer"))},undoPossible:function(){return this.position>1},redoPossible:function(){return this.position<this.historyStr.length},set:function(a){this.element.innerHTML="";for(var b=0,c=a.childNodes,d=a.childNodes.length;d>b;b++)this.element.appendChild(c[b].cloneNode(!0));var e,f,i;a.hasAttribute(h)?(e=a.getAttribute(h),i=a.getAttribute(g),f=this.element):(f=this.element.querySelector("["+h+"]")||this.element,e=f.getAttribute(h),i=f.getAttribute(g),f.removeAttribute(h),f.removeAttribute(g)),null!==i&&(f=this.getChildNodeByIndex(f,+i)),this.composer.selection.set(f,e)},getChildNodeIndex:function(a,b){for(var c=0,d=a.childNodes,e=d.length;e>c;c++)if(d[c]===b)return c},getChildNodeByIndex:function(a,b){return a.childNodes[b]}})}(wysihtml5),wysihtml5.views.View=Base.extend({constructor:function(a,b,c){this.parent=a,this.element=b,this.config=c,this.config.noTextarea||this._observeViewChange()},_observeViewChange:function(){var a=this;this.parent.on("beforeload",function(){a.parent.on("change_view",function(b){b===a.name?(a.parent.currentView=a,a.show(),setTimeout(function(){a.focus()},0)):a.hide()})})},focus:function(){if(!this.element||!this.element.ownerDocument||this.element.ownerDocument.querySelector(":focus")!==this.element)try{this.element&&this.element.focus()}catch(a){}},hide:function(){this.element.style.display="none"},show:function(){this.element.style.display=""},disable:function(){this.element.setAttribute("disabled","disabled")},enable:function(){this.element.removeAttribute("disabled")}}),function(a){var b=a.dom,c=a.browser;a.views.Composer=a.views.View.extend({name:"composer",CARET_HACK:"<br>",constructor:function(a,b,c){this.base(a,b,c),this.config.noTextarea?this.editableArea=b:this.textarea=this.parent.textarea,this.config.contentEditableMode?this._initContentEditableArea():this._initSandbox()},clear:function(){this.element.innerHTML=c.displaysCaretInEmptyContentEditableCorrectly()?"":this.CARET_HACK},getValue:function(b,c){var d=this.isEmpty()?"":a.quirks.getCorrectInnerHTML(this.element);return b!==!1&&(d=this.parent.parse(d,c===!1?!1:!0)),d},setValue:function(a,b){b&&(a=this.parent.parse(a));try{this.element.innerHTML=a}catch(c){this.element.innerText=a}},cleanUp:function(){this.parent.parse(this.element)},show:function(){this.editableArea.style.display=this._displayStyle||"",this.config.noTextarea||this.textarea.element.disabled||(this.disable(),this.enable())},hide:function(){this._displayStyle=b.getStyle("display").from(this.editableArea),"none"===this._displayStyle&&(this._displayStyle=null),this.editableArea.style.display="none"},disable:function(){this.parent.fire("disable:composer"),this.element.removeAttribute("contentEditable")},enable:function(){this.parent.fire("enable:composer"),this.element.setAttribute("contentEditable","true")},focus:function(b){a.browser.doesAsyncFocus()&&this.hasPlaceholderSet()&&this.clear(),this.base();var c=this.element.lastChild;b&&c&&this.selection&&("BR"===c.nodeName?this.selection.setBefore(this.element.lastChild):this.selection.setAfter(this.element.lastChild))},getTextContent:function(){return b.getTextContent(this.element)},hasPlaceholderSet:function(){return this.getTextContent()==(this.config.noTextarea?this.editableArea.getAttribute("data-placeholder"):this.textarea.element.getAttribute("placeholder"))&&this.placeholderSet},isEmpty:function(){var a=this.element.innerHTML.toLowerCase();return/^(\s|<br>|<\/br>|<p>|<\/p>)*$/i.test(a)||""===a||"<br>"===a||"<p></p>"===a||"<p><br></p>"===a||this.hasPlaceholderSet()},_initContentEditableArea:function(){var a=this;this.config.noTextarea?this.sandbox=new b.ContentEditableArea(function(){a._create()},{},this.editableArea):(this.sandbox=new b.ContentEditableArea(function(){a._create()}),this.editableArea=this.sandbox.getContentEditable(),b.insert(this.editableArea).after(this.textarea.element),this._createWysiwygFormField())},_initSandbox:function(){var a=this;this.sandbox=new b.Sandbox(function(){a._create()},{stylesheets:this.config.stylesheets}),this.editableArea=this.sandbox.getIframe();var c=this.textarea.element;b.insert(this.editableArea).after(c),this._createWysiwygFormField()},_createWysiwygFormField:function(){if(this.textarea.element.form){var a=document.createElement("input");a.type="hidden",a.name="_wysihtml5_mode",a.value=1,b.insert(a).after(this.textarea.element)}},_create:function(){var d=this;this.doc=this.sandbox.getDocument(),this.element=this.config.contentEditableMode?this.sandbox.getContentEditable():this.doc.body,this.config.noTextarea?this.cleanUp():(this.textarea=this.parent.textarea,this.element.innerHTML=this.textarea.getValue(!0,!1)),this.selection=new a.Selection(this.parent,this.element,this.config.uneditableContainerClassname),this.commands=new a.Commands(this.parent),this.config.noTextarea||b.copyAttributes(["className","spellcheck","title","lang","dir","accessKey"]).from(this.textarea.element).to(this.element),b.addClass(this.element,this.config.composerClassName),this.config.style&&!this.config.contentEditableMode&&this.style(),this.observe();var e=this.config.name;e&&(b.addClass(this.element,e),this.config.contentEditableMode||b.addClass(this.editableArea,e)),this.enable(),!this.config.noTextarea&&this.textarea.element.disabled&&this.disable();var f="string"==typeof this.config.placeholder?this.config.placeholder:this.config.noTextarea?this.editableArea.getAttribute("data-placeholder"):this.textarea.element.getAttribute("placeholder");f&&b.simulatePlaceholder(this.parent,this,f),this.commands.exec("styleWithCSS",!1),this._initAutoLinking(),this._initObjectResizing(),this._initUndoManager(),this._initLineBreaking(),this.config.noTextarea||!this.textarea.element.hasAttribute("autofocus")&&document.querySelector(":focus")!=this.textarea.element||c.isIos()||setTimeout(function(){d.focus(!0)},100),c.clearsContentEditableCorrectly()||a.quirks.ensureProperClearing(this),this.initSync&&this.config.sync&&this.initSync(),this.config.noTextarea||this.textarea.hide(),this.parent.fire("beforeload").fire("load")},_initAutoLinking:function(){var d=this,e=c.canDisableAutoLinking(),f=c.doesAutoLinkingInContentEditable();if(e&&this.commands.exec("autoUrlDetect",!1),this.config.autoLink){(!f||f&&e)&&(this.parent.on("newword:composer",function(){if(b.getTextContent(d.element).match(b.autoLink.URL_REG_EXP)){for(var c=d.selection.getSelectedNode(),e=d.element.querySelectorAll("."+d.config.uneditableContainerClassname),f=!1,g=e.length;g--;)a.dom.contains(e[g],c)&&(f=!0);f||b.autoLink(c,[d.config.uneditableContainerClassname])}}),b.observe(this.element,"blur",function(){b.autoLink(d.element,[d.config.uneditableContainerClassname])}));var g=this.sandbox.getDocument().getElementsByTagName("a"),h=b.autoLink.URL_REG_EXP,i=function(c){var d=a.lang.string(b.getTextContent(c)).trim();return"www."===d.substr(0,4)&&(d="http://"+d),d};b.observe(this.element,"keydown",function(a){if(g.length){var c,e=d.selection.getSelectedNode(a.target.ownerDocument),f=b.getParentElement(e,{nodeName:"A"},4);f&&(c=i(f),setTimeout(function(){var a=i(f);a!==c&&a.match(h)&&f.setAttribute("href",a)},0))}})}},_initObjectResizing:function(){if(this.commands.exec("enableObjectResizing",!0),c.supportsEvent("resizeend")){var d=["width","height"],e=d.length,f=this.element;b.observe(f,"resizeend",function(b){var c,g=b.target||b.srcElement,h=g.style,i=0;if("IMG"===g.nodeName){for(;e>i;i++)c=d[i],h[c]&&(g.setAttribute(c,parseInt(h[c],10)),h[c]="");a.quirks.redraw(f)}})}},_initUndoManager:function(){this.undoManager=new a.UndoManager(this.parent)},_initLineBreaking:function(){function d(a){var c=b.getParentElement(a,{nodeName:["P","DIV"]},2);c&&b.contains(e.element,c)&&e.selection.executeAndRestore(function(){e.config.useLineBreaks?b.replaceWithChildNodes(c):"P"!==c.nodeName&&b.renameElement(c,"p")})}var e=this,f=["LI","P","H1","H2","H3","H4","H5","H6"],g=["UL","OL","MENU"];this.config.useLineBreaks||b.observe(this.element,["focus","keydown"],function(){if(e.isEmpty()){var a=e.doc.createElement("P");
+e.element.innerHTML="",e.element.appendChild(a),c.displaysCaretInEmptyContentEditableCorrectly()?e.selection.selectNode(a,!0):(a.innerHTML="<br>",e.selection.setBefore(a.firstChild))}}),b.observe(this.element,"keydown",function(c){var h=c.keyCode;if(!c.shiftKey&&(h===a.ENTER_KEY||h===a.BACKSPACE_KEY)){var i=b.getParentElement(e.selection.getSelectedNode(),{nodeName:f},4);return i?void setTimeout(function(){var c,f=e.selection.getSelectedNode();if("LI"===i.nodeName){if(!f)return;c=b.getParentElement(f,{nodeName:g},2),c||d(f)}h===a.ENTER_KEY&&i.nodeName.match(/^H[1-6]$/)&&d(f)},0):void(e.config.useLineBreaks&&h===a.ENTER_KEY&&!a.browser.insertsLineBreaksOnReturn()&&(c.preventDefault(),e.commands.exec("insertLineBreak")))}})}})}(wysihtml5),function(a){var b=a.dom,c=document,d=window,e=c.createElement("div"),f=["background-color","color","cursor","font-family","font-size","font-style","font-variant","font-weight","line-height","letter-spacing","text-align","text-decoration","text-indent","text-rendering","word-break","word-wrap","word-spacing"],g=["background-color","border-collapse","border-bottom-color","border-bottom-style","border-bottom-width","border-left-color","border-left-style","border-left-width","border-right-color","border-right-style","border-right-width","border-top-color","border-top-style","border-top-width","clear","display","float","margin-bottom","margin-left","margin-right","margin-top","outline-color","outline-offset","outline-width","outline-style","padding-left","padding-right","padding-top","padding-bottom","position","top","left","right","bottom","z-index","vertical-align","text-align","-webkit-box-sizing","-moz-box-sizing","-ms-box-sizing","box-sizing","-webkit-box-shadow","-moz-box-shadow","-ms-box-shadow","box-shadow","-webkit-border-top-right-radius","-moz-border-radius-topright","border-top-right-radius","-webkit-border-bottom-right-radius","-moz-border-radius-bottomright","border-bottom-right-radius","-webkit-border-bottom-left-radius","-moz-border-radius-bottomleft","border-bottom-left-radius","-webkit-border-top-left-radius","-moz-border-radius-topleft","border-top-left-radius","width","height"],h=["html { height: 100%; }","body { height: 100%; padding: 1px 0 0 0; margin: -1px 0 0 0; }","body > p:first-child { margin-top: 0; }","._wysihtml5-temp { display: none; }",a.browser.isGecko?"body.placeholder { color: graytext !important; }":"body.placeholder { color: #a9a9a9 !important; }","img:-moz-broken { -moz-force-broken-image-icon: 1; height: 24px; width: 24px; }"],i=function(a){if(a.setActive)try{a.setActive()}catch(e){}else{var f=a.style,g=c.documentElement.scrollTop||c.body.scrollTop,h=c.documentElement.scrollLeft||c.body.scrollLeft,i={position:f.position,top:f.top,left:f.left,WebkitUserSelect:f.WebkitUserSelect};b.setStyles({position:"absolute",top:"-99999px",left:"-99999px",WebkitUserSelect:"none"}).on(a),a.focus(),b.setStyles(i).on(a),d.scrollTo&&d.scrollTo(h,g)}};a.views.Composer.prototype.style=function(){var d,j=this,k=c.querySelector(":focus"),l=this.textarea.element,m=l.hasAttribute("placeholder"),n=m&&l.getAttribute("placeholder"),o=l.style.display,p=l.disabled;this.focusStylesHost=e.cloneNode(!1),this.blurStylesHost=e.cloneNode(!1),this.disabledStylesHost=e.cloneNode(!1),m&&l.removeAttribute("placeholder"),l===k&&l.blur(),l.disabled=!1,l.style.display=d="none",(l.getAttribute("rows")&&"auto"===b.getStyle("height").from(l)||l.getAttribute("cols")&&"auto"===b.getStyle("width").from(l))&&(l.style.display=d=o),b.copyStyles(g).from(l).to(this.editableArea).andTo(this.blurStylesHost),b.copyStyles(f).from(l).to(this.element).andTo(this.blurStylesHost),b.insertCSS(h).into(this.element.ownerDocument),l.disabled=!0,b.copyStyles(g).from(l).to(this.disabledStylesHost),b.copyStyles(f).from(l).to(this.disabledStylesHost),l.disabled=p,l.style.display=o,i(l),l.style.display=d,b.copyStyles(g).from(l).to(this.focusStylesHost),b.copyStyles(f).from(l).to(this.focusStylesHost),l.style.display=o,b.copyStyles(["display"]).from(l).to(this.editableArea);var q=a.lang.array(g).without(["display"]);return k?k.focus():l.blur(),m&&l.setAttribute("placeholder",n),this.parent.on("focus:composer",function(){b.copyStyles(q).from(j.focusStylesHost).to(j.editableArea),b.copyStyles(f).from(j.focusStylesHost).to(j.element)}),this.parent.on("blur:composer",function(){b.copyStyles(q).from(j.blurStylesHost).to(j.editableArea),b.copyStyles(f).from(j.blurStylesHost).to(j.element)}),this.parent.observe("disable:composer",function(){b.copyStyles(q).from(j.disabledStylesHost).to(j.editableArea),b.copyStyles(f).from(j.disabledStylesHost).to(j.element)}),this.parent.observe("enable:composer",function(){b.copyStyles(q).from(j.blurStylesHost).to(j.editableArea),b.copyStyles(f).from(j.blurStylesHost).to(j.element)}),this}}(wysihtml5),function(a){var b=a.dom,c=a.browser,d={66:"bold",73:"italic",85:"underline"},e=function(a,b,c){for(var d=0,e=b.length;e>d;d++)a.addEventListener(b[d],c,!1)},f=function(a,b,c){for(var d=0,e=b.length;e>d;d++)a.removeEventListener(b[d],c,!1)},g=function(a,b){{var c=b.selection;b.element}if(c.isCollapsed())if(c.caretIsInTheBeginnig("LI"))a.preventDefault(),b.commands.exec("outdentList");else if(c.caretIsInTheBeginnig())a.preventDefault();else{if(c.caretIsFirstInSelection()&&c.getPreviousNode()&&c.getPreviousNode().nodeName&&/^H\d$/gi.test(c.getPreviousNode().nodeName)){var d=c.getPreviousNode();if(a.preventDefault(),/^\s*$/.test(d.textContent||d.innerText))d.parentNode.removeChild(d);else{var e=d.ownerDocument.createRange();e.selectNodeContents(d),e.collapse(!1),c.setSelection(e)}}var f=c.caretIsBeforeUneditable();if(f){a.preventDefault();try{var g=new CustomEvent("wysihtml5:uneditable:delete");f.dispatchEvent(g)}catch(h){}f.parentNode.removeChild(f)}}else c.containsUneditable()&&(a.preventDefault(),c.deleteContents())},h=function(a){if(a.selection.isCollapsed()){if(a.selection.caretIsInTheBeginnig("LI")&&a.commands.exec("indentList"))return}else a.selection.deleteContents();a.commands.exec("insertHTML"," ")},i=function(){this.domNodeRemovedInterval&&clearInterval(domNodeRemovedInterval),this.parent.fire("destroy:composer")},j=function(){this.parent.fire("beforeinteraction").fire("beforeinteraction:composer"),setTimeout(function(){this.parent.fire("interaction").fire("interaction:composer")}.bind(this),0)},k=function(a){this.parent.fire("focus",a).fire("focus:composer",a),setTimeout(function(){this.focusState=this.getValue(!1,!1)}.bind(this),0)},l=function(a){if(this.focusState!==this.getValue(!1,!1)){var b=a;"function"==typeof Object.create&&(b=Object.create(a,{type:{value:"change"}})),this.parent.fire("change",b).fire("change:composer",b)}this.parent.fire("blur",a).fire("blur:composer",a)},m=function(a){this.parent.fire(a.type,a).fire(a.type+":composer",a),"paste"===a.type&&setTimeout(function(){this.parent.fire("newword:composer")}.bind(this),0)},n=function(a){this.config.copyedFromMarking&&(a.clipboardData&&(a.clipboardData.setData("text/html",this.config.copyedFromMarking+this.selection.getHtml()),a.clipboardData.setData("text/plain",this.selection.getPlainText()),a.preventDefault()),this.parent.fire(a.type,a).fire(a.type+":composer",a))},o=function(b){var c=b.keyCode;(c===a.SPACE_KEY||c===a.ENTER_KEY)&&this.parent.fire("newword:composer")},p=function(b){if(!c.canSelectImagesInContentEditable()){var d=b.target,e=this.element.querySelectorAll("img"),f=this.element.querySelectorAll("."+this.config.uneditableContainerClassname+" img"),g=a.lang.array(e).without(f);"IMG"===d.nodeName&&a.lang.array(g).contains(d)&&this.selection.selectNode(d)}},q=function(a){var b,c={IMG:"Image: ",A:"Link: "},d=a.target,e=d.nodeName;("A"===e||"IMG"===e)&&(d.hasAttribute("title")||(b=c[e]+(d.getAttribute("href")||d.getAttribute("src")),d.setAttribute("title",b)))},r=function(b){if(this.config.uneditableContainerClassname){var c=a.dom.getParentElement(b.target,{className:this.config.uneditableContainerClassname},!1,this.element);c&&this.selection.setAfter(c)}},s=function(){c.canSelectImagesInContentEditable()||setTimeout(function(){this.selection.getSelection().removeAllRanges()}.bind(this),0)},t=function(b){var c,e,f=b.keyCode,i=d[f];(b.ctrlKey||b.metaKey)&&!b.altKey&&i&&(this.commands.exec(i),b.preventDefault()),f===a.BACKSPACE_KEY&&g(b,this),(f===a.BACKSPACE_KEY||f===a.DELETE_KEY)&&(c=this.selection.getSelectedNode(!0),c&&"IMG"===c.nodeName&&(b.preventDefault(),e=c.parentNode,e.removeChild(c),"A"!==e.nodeName||e.firstChild||e.parentNode.removeChild(e),setTimeout(function(){a.quirks.redraw(element)},0))),this.config.handleTabKey&&f===a.TAB_KEY&&(b.preventDefault(),h(this,element))},u=function(){setTimeout(function(){this.doc.querySelector(":focus")!==this.element&&this.focus()}.bind(this),0)},v=function(){setTimeout(function(){this.selection.getSelection().removeAllRanges()}.bind(this),0)},w=function(){var b=function(){this.doc.execCommand("enableObjectResizing",!1,"false"),this.doc.execCommand("enableInlineTableEditing",!1,"false")},c=function(){b.call(this),f(this.sandbox.getIframe(),["focus","mouseup","mouseover"],c)}.bind(this);this.doc.execCommand&&a.browser.supportsCommand(this.doc,"enableObjectResizing")&&a.browser.supportsCommand(this.doc,"enableInlineTableEditing")&&(this.sandbox.getIframe?e(this.sandbox.getIframe(),["focus","mouseup","mouseover"],c):setTimeout(function(){b.call(this)}.bind(this),0)),this.tableSelection=a.quirks.tableCellsSelection(this.element,this.parent)};a.views.Composer.prototype.observe=function(){var a=this.sandbox.getIframe?this.sandbox.getIframe():this.sandbox.getContentEditable(),d=(this.element,c.supportsEventsInIframeCorrectly()||this.sandbox.getContentEditable?this.element:this.sandbox.getWindow());this.focusState=this.getValue(!1,!1),a.addEventListener(["DOMNodeRemoved"],i.bind(this),!1),c.supportsMutationEvents()||(this.domNodeRemovedInterval=setInterval(function(){b.contains(document.documentElement,a)||i.call(this)},250)),this.config.handleTables&&w.call(this),e(d,["drop","paste","mouseup","focus","keyup"],j.bind(this)),d.addEventListener("focus",k.bind(this),!1),d.addEventListener("blur",l.bind(this),!1),e(this.element,["drop","paste","beforepaste"],m.bind(this),!1),this.element.addEventListener("copy",n.bind(this),!1),this.element.addEventListener("mousedown",p.bind(this),!1),this.element.addEventListener("mouseover",q.bind(this),!1),this.element.addEventListener("click",r.bind(this),!1),this.element.addEventListener("drop",s.bind(this),!1),this.element.addEventListener("keyup",o.bind(this),!1),this.element.addEventListener("keydown",t.bind(this),!1),this.element.addEventListener("dragenter",function(){this.parent.fire("unset_placeholder")}.bind(this),!1),!this.config.contentEditableMode&&c.hasIframeFocusIssue()&&(a.addEventListener("focus",u.bind(this),!1),a.addEventListener("blur",v.bind(this),!1))}}(wysihtml5),function(a){var b=400;a.views.Synchronizer=Base.extend({constructor:function(a,b,c){this.editor=a,this.textarea=b,this.composer=c,this._observe()},fromComposerToTextarea:function(b){this.textarea.setValue(a.lang.string(this.composer.getValue(!1,!1)).trim(),b)},fromTextareaToComposer:function(a){var b=this.textarea.getValue(!1,!1);b?this.composer.setValue(b,a):(this.composer.clear(),this.editor.fire("set_placeholder"))},sync:function(a){"textarea"===this.editor.currentView.name?this.fromTextareaToComposer(a):this.fromComposerToTextarea(a)},_observe:function(){var c,d=this,e=this.textarea.element.form,f=function(){c=setInterval(function(){d.fromComposerToTextarea()},b)},g=function(){clearInterval(c),c=null};f(),e&&(a.dom.observe(e,"submit",function(){d.sync(!0)}),a.dom.observe(e,"reset",function(){setTimeout(function(){d.fromTextareaToComposer()},0)})),this.editor.on("change_view",function(a){"composer"!==a||c?"textarea"===a&&(d.fromComposerToTextarea(!0),g()):(d.fromTextareaToComposer(!0),f())}),this.editor.on("destroy:composer",g)}})}(wysihtml5),wysihtml5.views.Textarea=wysihtml5.views.View.extend({name:"textarea",constructor:function(a,b,c){this.base(a,b,c),this._observe()},clear:function(){this.element.value=""},getValue:function(a){var b=this.isEmpty()?"":this.element.value;return a!==!1&&(b=this.parent.parse(b)),b},setValue:function(a,b){b&&(a=this.parent.parse(a)),this.element.value=a},cleanUp:function(){var a=this.parent.parse(this.element.value);this.element.value=a},hasPlaceholderSet:function(){var a=wysihtml5.browser.supportsPlaceholderAttributeOn(this.element),b=this.element.getAttribute("placeholder")||null,c=this.element.value,d=!c;return a&&d||c===b},isEmpty:function(){return!wysihtml5.lang.string(this.element.value).trim()||this.hasPlaceholderSet()},_observe:function(){var a=this.element,b=this.parent,c={focusin:"focus",focusout:"blur"},d=wysihtml5.browser.supportsEvent("focusin")?["focusin","focusout","change"]:["focus","blur","change"];b.on("beforeload",function(){wysihtml5.dom.observe(a,d,function(a){var d=c[a.type]||a.type;b.fire(d).fire(d+":textarea")}),wysihtml5.dom.observe(a,["paste","drop"],function(){setTimeout(function(){b.fire("paste").fire("paste:textarea")},0)})})}}),function(a){var b,c={name:b,style:!0,toolbar:b,showToolbarAfterInit:!0,autoLink:!0,handleTables:!0,handleTabKey:!0,parserRules:{tags:{br:{},span:{},div:{},p:{}},classes:{}},pasteParserRulesets:null,parser:a.dom.parse,composerClassName:"wysihtml5-editor",bodyClassName:"wysihtml5-supported",useLineBreaks:!0,stylesheets:[],placeholderText:b,supportTouchDevices:!0,cleanUp:!0,contentEditableMode:!1,uneditableContainerClassname:"wysihtml5-uneditable-container",copyedFromMarking:'<meta name="copied-from" content="wysihtml5">'};a.Editor=a.lang.Dispatcher.extend({constructor:function(b,d){if(this.editableElement="string"==typeof b?document.getElementById(b):b,this.config=a.lang.object({}).merge(c).merge(d).get(),this._isCompatible=a.browser.supported(),"textarea"!=this.editableElement.nodeName.toLowerCase()&&(this.config.contentEditableMode=!0,this.config.noTextarea=!0),this.config.noTextarea||(this.textarea=new a.views.Textarea(this,this.editableElement,this.config),this.currentView=this.textarea),!this._isCompatible||!this.config.supportTouchDevices&&a.browser.isTouchDevice()){var e=this;return void setTimeout(function(){e.fire("beforeload").fire("load")},0)}a.dom.addClass(document.body,this.config.bodyClassName),this.composer=new a.views.Composer(this,this.editableElement,this.config),this.currentView=this.composer,"function"==typeof this.config.parser&&this._initParser(),this.on("beforeload",this.handleBeforeLoad)},handleBeforeLoad:function(){this.config.noTextarea||(this.synchronizer=new a.views.Synchronizer(this,this.textarea,this.composer)),this.config.toolbar&&(this.toolbar=new a.toolbar.Toolbar(this,this.config.toolbar,this.config.showToolbarAfterInit))},isCompatible:function(){return this._isCompatible},clear:function(){return this.currentView.clear(),this},getValue:function(a,b){return this.currentView.getValue(a,b)},setValue:function(a,b){return this.fire("unset_placeholder"),a?(this.currentView.setValue(a,b),this):this.clear()},cleanUp:function(){this.currentView.cleanUp()},focus:function(a){return this.currentView.focus(a),this},disable:function(){return this.currentView.disable(),this},enable:function(){return this.currentView.enable(),this},isEmpty:function(){return this.currentView.isEmpty()},hasPlaceholderSet:function(){return this.currentView.hasPlaceholderSet()},parse:function(b,c){var d=this.config.contentEditableMode?document:this.composer?this.composer.sandbox.getDocument():null,e=this.config.parser(b,{rules:this.config.parserRules,cleanUp:this.config.cleanUp,context:d,uneditableClass:this.config.uneditableContainerClassname,clearInternals:c});return"object"==typeof b&&a.quirks.redraw(b),e},_initParser:function(){var b,c=this;a.browser.supportsModenPaste()?this.on("paste:composer",function(d){d.preventDefault(),b=a.dom.getPastedHtml(d),b&&c._cleanAndPaste(b)}):this.on("beforepaste:composer",function(b){b.preventDefault(),a.dom.getPastedHtmlWithDiv(c.composer,function(a){a&&c._cleanAndPaste(a)})})},_cleanAndPaste:function(b){var c=a.quirks.cleanPastedHTML(b,{referenceNode:this.composer.element,rules:this.config.pasteParserRulesets||[{set:this.config.parserRules}],uneditableClass:this.config.uneditableContainerClassname});this.composer.selection.deleteContents(),this.composer.selection.insertHTML(c)}})}(wysihtml5);
+//# sourceMappingURL=wysihtml5x.min.map
\ No newline at end of file
--- /dev/null
+{"version":3,"file":"wysihtml5x.min.js","sources":["wysihtml5x.js"],"names":["Event","prototype","preventDefault","this","returnValue","stopPropagation","cancelBubble","Element","addEventListener","eventListeners","type","listener","self","wrapper","e","target","srcElement","currentTarget","handleEvent","call","wrapper2","document","readyState","attachEvent","push","object","window","removeEventListener","counter","length","eventListener","detachEvent","splice","HTMLDocument","Window","Object","defineProperty","getOwnPropertyDescriptor","get","innerText","set","s","Array","isArray","arg","toString","Function","bind","oThis","TypeError","aArgs","slice","arguments","fToBind","fNOP","fBound","apply","concat","wysihtml5","version","commands","dom","quirks","toolbar","lang","selection","views","INVISIBLE_SPACE","INVISIBLE_SPACE_REG_EXP","EMPTY_FUNCTION","ELEMENT_NODE","TEXT_NODE","BACKSPACE_KEY","ENTER_KEY","ESCAPE_KEY","SPACE_KEY","TAB_KEY","DELETE_KEY","factory","root","define","amd","module","exports","rangy","isHostMethod","o","p","t","FUNCTION","OBJECT","isHostObject","isHostProperty","UNDEFINED","createMultiplePropertyTest","testFunc","props","i","isTextRange","range","areHostMethods","textRangeMethods","areHostProperties","textRangeProperties","getBody","doc","body","getElementsByTagName","consoleLog","msg","console","log","alertOrLog","shouldAlert","isBrowser","alert","fail","reason","api","initialized","supported","config","alertOnFail","warn","alertOnWarn","getErrorDesc","ex","message","description","String","init","testRange","implementsDomRange","implementsTextRange","createRange","domRangeMethods","domRangeProperties","nodeName","toLowerCase","createTextRange","features","errorMessage","moduleName","modules","Module","len","initListeners","shim","win","shimListeners","name","dependencies","initializer","createModule","initFunc","newModule","stack","RangePrototype","SelectionPrototype","areHostObjects","util","preferTextRange","autoInitialize","rangyAutoInitialize","extend","hasOwnProperty","obj","deep","createOptions","optionsParam","defaults","options","toArray","el","createElement","appendChild","childNodes","nodeType","arrayLike","arr","addListener","eventType","addInitListener","addShimListener","createMissingNativeApi","requiredModule","requiredModuleNames","Error","deprecationNotice","deprecated","replacement","createError","createCoreModule","rangePrototype","selectionPrototype","isHtmlNamespace","node","ns","namespaceURI","UNDEF","parentElement","parent","parentNode","getNodeIndex","previousSibling","getNodeLength","getCommonAncestor","node1","node2","n","ancestors","arrayContains","isAncestorOf","ancestor","descendant","selfIsAncestor","isOrIsAncestorOf","getClosestAncestorIn","isCharacterDataNode","isTextOrCommentNode","insertAfter","precedingNode","nextNode","nextSibling","insertBefore","splitDataNode","index","positionsToPreserve","newNode","cloneNode","deleteData","position","offset","getDocument","ownerDocument","getWindow","defaultView","parentWindow","getIframeDocument","iframeEl","contentDocument","contentWindow","getIframeWindow","isWindow","getContentDocument","methodName","tagName","getRootContainer","comparePoints","nodeA","offsetA","nodeB","offsetB","nodeC","childA","childB","firstChild","isBrokenNode","inspectNode","crashyTextNodes","data","idAttr","id","innerHTML","fragmentFromNodeChildren","child","fragment","createDocumentFragment","NodeIterator","_next","createIterator","DomPosition","DOMException","codeName","code","textNode","createTextNode","val","getComputedStyleProperty","getComputedStyle","propName","documentElement","currentStyle","_current","hasNext","next","detach","equals","pos","inspect","INDEX_SIZE_ERR","HIERARCHY_REQUEST_ERR","WRONG_DOCUMENT_ERR","NO_MODIFICATION_ALLOWED_ERR","NOT_FOUND_ERR","NOT_SUPPORTED_ERR","INVALID_STATE_ERR","INVALID_NODE_TYPE_ERR","isNonTextPartiallySelected","startContainer","endContainer","getRangeDocument","getBoundaryBeforeNode","getBoundaryAfterNode","insertNodeAtPosition","firstNodeInserted","rangesIntersect","rangeA","rangeB","touchingIsIntersecting","assertRangeValid","startComparison","startOffset","endOffset","endComparison","cloneSubtree","iterator","partiallySelected","subIterator","frag","isPartiallySelectedSubtree","getSubtreeIterator","iterateSubtree","rangeIterator","func","iteratorState","it","stop","subRangeIterator","deleteSubtree","remove","extractSubtree","getNodesInRange","nodeTypes","filter","regex","filterNodeTypes","filterExists","RegExp","join","nodes","RangeIterator","test","sc","ec","getName","clonePartiallySelectedTextNodes","collapsed","so","eo","commonAncestorContainer","isSingleCharacterDataNode","_first","_last","createAncestorFinder","assertNoDocTypeNotationEntityAncestor","allowSelf","getDocTypeNotationEntityAncestor","assertValidNodeType","invalidTypes","assertValidOffset","assertSameDocumentOrFragment","getDocumentOrFragmentContainer","assertNodeNotReadOnly","getReadonlyAncestor","assertNode","isOrphan","rootContainerNodeTypes","isValidOffset","isRangeValid","splitRangeBoundaries","startEndSame","setStartAndEnd","rangeToHtml","container","cloneContents","copyComparisonConstantsToObject","START_TO_START","s2s","START_TO_END","s2e","END_TO_END","e2e","END_TO_START","e2s","NODE_BEFORE","n_b","NODE_AFTER","n_a","NODE_BEFORE_AND_AFTER","n_b_a","NODE_INSIDE","n_i","copyComparisonConstants","constructor","createRangeContentRemover","remover","boundaryUpdater","boundary","reset","createPrototypeRange","createBeforeAfterNodeSetter","isBefore","isStart","beforeAfterNodeTypes","setRangeStart","setRangeEnd","F","setStart","setEnd","args","setBoundary","setStartBefore","setStartAfter","setEndBefore","setEndAfter","collapse","selectNodeContents","selectNode","start","end","extractContents","deleteContents","canSurroundContents","boundariesInvalid","splitBoundaries","splitBoundariesPreservingPositions","normalizeBoundaries","mergeForward","sibling","appendData","removeChild","mergeBackward","nodeLength","insertData","nodeIndex","normalizeStart","endNode","startNode","collapseToPoint","updateCollapsedAndCommonAncestor","updateBoundaries","Range","current","subRange","cloneRange","readonlyNodeTypes","insertableNodeTypes","surroundNodeTypes","styleEl","htmlParsingConforms","createContextualFragment","fragmentStr","rangeProperties","compareBoundaryPoints","how","prefixA","prefixB","insertNode","clone","surroundContents","content","hasChildNodes","lastChild","prop","textParts","compareNode","comparePoint","toHtml","intersectsNode","isPointInRange","intersectsRange","intersectsOrTouchesRange","intersection","intersectionRange","union","unionRange","containsNode","allowPartial","containsNodeContents","containsRange","containsNodeText","nodeRange","textNodes","getNodes","lastTextNode","pop","collapseBefore","collapseAfter","getBookmark","containerNode","preSelectionRange","moveToBookmark","bookmark","charIndex","nextCharIndex","nodeStack","foundStart","rangesEqual","isValid","r1","r2","DomRange","WrappedRange","WrappedTextRange","updateRangeProperties","nativeRange","updateNativeRange","startMoved","endMoved","nativeRangeDifferent","rangeProto","refresh","testTextNode","oppositeName","range2","createNativeRange","getTextRangeContainerElement","textRange","parentEl","duplicate","startEl","endEl","startEndContainer","textRangeIsCollapsed","compareEndPoints","getTextRangeBoundaryPosition","wholeRangeContainerElement","isCollapsed","startInfo","workingRange","containerElement","canHaveHTML","boundaryPosition","nodeInfo","workingNode","comparison","previousNode","boundaryNode","workingComparisonType","childNodeCount","moveToElementText","Math","floor","setEndPoint","tempRange","rangeLength","text","replace","moveStart","createBoundaryTextRange","boundaryParent","boundaryOffset","nodeIsDataNode","startBoundary","rangeContainerElement","rangeToTextRange","startRange","endRange","toTextRange","globalObj","f","createRangyRange","createIframeRange","createIframeRangyRange","isDirectionBackward","dir","WrappedSelection","getWinSelection","winParam","getSelection","getDocSelection","winSelectionIsBackward","sel","backward","anchorNode","anchorOffset","focusNode","focusOffset","updateAnchorAndFocusFromRange","anchorPrefix","focusPrefix","updateAnchorAndFocusFromNativeSelection","nativeSel","nativeSelection","updateEmptySelection","rangeCount","_ranges","getNativeRange","rangeContainsSingleElement","rangeNodes","getSingleElementFromRange","updateFromTextRange","wrappedRange","updateControlSelection","docSelection","controlRange","item","addRangeToControlSelection","rangeElement","newControlRange","createControlRange","add","select","deleteProperties","detached","actOnCachedSelection","action","cached","cachedRangySelections","createControlSelection","ranges","assertNodeInSameDocument","createStartOrEndSetter","getRangeAt","setSingleRange","isBackward","rangeInspects","anchor","focus","checkSelectionRanges","getNativeSelection","selectionIsCollapsed","BOOLEAN","NUMBER","CONTROL","implementsWinGetSelection","implementsDocSelection","useDocumentSelection","isSelectionValid","testSelection","selectionHasAnchorAndFocus","selectionHasExtend","selectionHasRangeCount","selectionSupportsMultipleRanges","collapsedNonEditableSelectionsSupported","addRangeBackwardToNative","addRange","originalSelectionRangeCount","selectionHasMultipleRanges","originalSelectionRanges","originalSelectionBackward","testEl","contentEditable","removeAllRanges","chromeMatch","navigator","appVersion","match","parseInt","testControlRange","implementsControlRange","getSelectionRangeAt","docSel","getIframeSelection","selProto","addRangeBackward","direction","previousRangeCount","clonedNativeRange","selectionIsBackward","setRanges","empty","refreshSelection","checkForChanges","oldRanges","oldAnchorNode","oldAnchorOffset","removeRangeManually","getAllRanges","removeRange","removed","isBackwards","rangeTexts","collapseToStart","collapseToEnd","selectAllChildren","deleteFromDocument","element","eachRange","callMethodOnEachRange","params","results","changeEachRange","rangeBookmarks","rangeBookmark","selRanges","rangeHtmls","getNativeTextRange","detachAll","Selection","docReady","loadHandler","require","gEBI","getElementById","insertRangeBoundaryMarker","atStart","markerEl","markerId","Date","random","boundaryRange","style","lineHeight","display","className","markerTextChar","setRangeBoundary","compareRanges","saveRange","startMarkerId","endMarkerId","restoreRange","rangeInfo","normalize","saveRanges","rangeInfos","sort","saveSelection","restored","restoreRanges","restoreSelection","savedSelection","preserveDirection","removeMarkerElement","removeMarkers","Base","_instance","_static","_prototyping","proto","base","klass","_constructing","forEach","implement","valueOf","source","value","method","previous","toSource","hidden","key","block","context","undefined","browser","iosVersion","userAgent","androidVersion","isIE","equation","re","rv","appName","exec","parseFloat","$1","testElement","isGecko","indexOf","isWebKit","isChrome","isOpera","USER_AGENT","hasContentEditableSupport","hasEditingApiSupport","execCommand","queryCommandSupported","queryCommandState","hasQuerySelectorSupport","querySelector","querySelectorAll","isIncompatibleMobileBrowser","isIos","isAndroid","isTouchDevice","supportsEvent","supportsSandboxedIframes","throwsMixedContentWarningWhenIframeSrcIsEmpty","displaysCaretInEmptyContentEditableCorrectly","hasCurrentStyleProperty","insertsLineBreaksOnReturn","supportsPlaceholderAttributeOn","eventName","setAttribute","supportsEventsInIframeCorrectly","supportsHTML5Tags","html5","supportsCommand","buggyCommands","formatBlock","insertUnorderedList","insertOrderedList","insertHTML","command","isBuggy","e1","queryCommandEnabled","e2","doesAutoLinkingInContentEditable","canDisableAutoLinking","clearsContentEditableCorrectly","supportsGetAttributeCorrectly","td","getAttribute","canSelectImagesInContentEditable","autoScrollsToCaret","autoClosesUnclosedTags","clonedTestElement","supportsNativeGetElementsByClassName","getElementsByClassName","supportsSelectionModify","needsSpaceAfterLineBreak","supportsSpeechApiOn","input","chromeVersion","crashesWhenDefineProperty","property","doesAsyncFocus","hasProblemsSettingCaretAfterImg","hasUndoInContextMenu","hasInsertNodeIssue","hasIframeFocusIssue","createsNestedInvalidMarkupAfterPaste","supportsMutationEvents","supportsModenPaste","array","contains","needle","without","arrayToSubstract","newArr","newArray","map","callback","thisArg","A","unique","vals","max","idx","Dispatcher","on","handler","events","off","handlers","newHandlers","fire","payload","observe","stopObserving","merge","otherObj","newObj","isPlainObject","isFunction","WHITE_SPACE_START","WHITE_SPACE_END","ENTITY_REG_EXP","ENTITY_MAP","&","<",">","\"","\t","string","str","trim","interpolate","vars","by","search","split","escapeHTML","linebreaks","convertSpaces","html","c","autoLink","ignoreInClasses","_hasParentThatShouldBeIgnored","_parseNode","_convertUrlsToLinks","URL_REG_EXP","url","punctuation","TRAILING_CHAR_REG_EXP","opening","BRACKETS","realUrl","displayUrl","MAX_DISPLAY_LENGTH","substr","_getTempElement","tempElement","_wysihtml5_tempElement","_wrapMatchesInNode","nodeValue","IGNORE_URLS_IN","childNodesLength",")","]","}","addClass","classList","hasClass","removeClass","elementClassName","compareDocumentPosition","convertToList","_createListItem","list","listItem","_createList","listType","uneditableClass","childNode","lineBreak","isBlockElement","isLineBreak","currentListItem","lineBreaks","lineBreaksLength","getStyle","from","insert","after","replaceChild","copyAttributes","attributesToCopy","elementToCopyFrom","to","elementToCopyTo","attribute","andTo","callee","BOX_SIZING_PROPERTIES","shouldIgnoreBoxSizingBorderBox","hasBoxSizingBorderBox","offsetWidth","copyStyles","stylesToCopy","cssText","setStyles","delegate","selector","event","domNode","defaultNodeTypes","_isBlankText","prev","prevNode","types","ignoreBlankTexts","lastLeafNode","leafClasses","getAsDom","_innerHTMLShiv","_ensureHTML5Compatibility","_wysihtml5_supportsHTML5Tags","HTML5_ELEMENTS","getParentElement","_isSameNodeName","desiredNodeNames","_isElement","_hasClassName","classRegExp","classNames","_hasStyle","cssStyle","styleRegExp","styles","matchingSet","levels","findByStyle","findByClass","camelize","REG_EXP_CAMELIZE","charAt","toUpperCase","stylePropertyMapping","float","camelizedProperty","styleValue","originalOverflow","needsOverflowReset","overflow","getPropertyValue","getTextNodes","ingoreEmpty","all","textContent","hasElementWithTagName","_getDocumentIdentifier","_wysihtml5_identifier","DOCUMENT_IDENTIFIER","LIVE_CACHE","cacheEntry","hasElementWithClassName","elementToInsert","before","into","insertCSS","rules","styleElement","styleSheet","link","head","_isLineBreak","_isLineBreakOrBlockElement","eventNames","handlerWrapper","parse","elementOrHtml_current","config_current","elementOrHtml","currentRules","defaultRules","isString","clearInternals","selectors","_applySelectorRules","_convert","cleanUp","unjoinNbsps","txtnodes","getCorrectInnerHTML","oldNode","newChild","nodeDisplay","oldNodeType","oldChilds","oldChildsLength","NODE_TYPE_MAPPING","blockElements","DEFAULT_NODE_NAME","attributes","selectorRules","els","elementHandlingMethods","_handleElement","rule","renameTag","tagRules","tags","scopeName","_wysihtml5","outerHTML","unwrap","rename_tag","one_of_type","_testTypes","remove_action","remove_action_rename_to","_handleAttributes","_handleStyles","definition","type_definitions","_testType","classesLength","a","attr","styleProp","nodeClasses","nodeStyles","methods","m","typeCeckMethods","classes","WHITE_SPACE_REG_EXP","sp","attrs","v","keep_styles","styleFloat","cssFloat","_getAttributesBeginningWith","beginning","returnAttributes","_checkAttribute","attributeName","attributeValue","newAttributeValue","attributeCheckMethods","_checkAttributes","local_attributes","newValue","matchingAttributes","globalAttributes","checkAttributes","oldAttributes","getAttributes","imax","currentClass","newClass","setClass","set_class","add_class","addStyle","add_style","setAttributes","set_attributes","allowedClasses","newClasses","oldClasses","check_attributes","addClassMethods","addStyleMethods","newStyle","classes_blacklist","src","width","height","_handleText","_handleComment","comments","createComment","1","3","8","REG_EXP","href","alt","numbers","any","align_text","mapping","left","right","center","align_img","justify","clear_br","both","size_font","2","4","5","6","7","-","+","has_visible_contet","txt","visibleElements","offsetHeight","removeEmptyTextNodes","renameElement","newNodeName","newElement","replaceWithChildNodes","_isBlockElement","_appendLineBreak","resolveList","useLineBreaks","isLastChild","shouldAppendLineBreak","paragraph","firstElementChild","windowProperties","windowProperties2","documentProperties","Sandbox","readyCallback","editableArea","_createIframe","insertInto","getIframe","_readyError","destroy","iframe","that","security","allowtransparency","frameborder","marginwidth","marginheight","onload","onreadystatechange","_onLoadIframe","iframeWindow","iframeDocument","charset","characterSet","sandboxHtml","_getHtml","stylesheets","open","write","close","onerror","fileName","lineNumber","_unset","loaded","setTimeout","templateVars","setter","__defineGetter__","__defineSetter__","ContentEditableArea","getContentEditable","_bindElement","_createElement","_loadElement","contentExists","simulatePlaceholder","editor","view","placeholderText","CLASS_NAME","unset","composerIsVisible","hasPlaceholderSet","clear","placeholderSet","isEmpty","setValue","setTextContent","getTextContent","HAS_GET_ATTRIBUTE_BUG","isLoadedImage","hasAttribute","specified","complete","mozMatchesSelector","queryInList","query","q","ret","unshift","removeElement","referenceNode","tag","MapCell","cell","isColspan","isRowspan","firstCol","lastCol","firstRow","lastRow","isReal","spanCollection","modified","TableModifyerByCell","table","addSpannedCellToMap","r","cspan","rspan","spanCollect","rmax","cmax","rr","cc","setCellAsModified","smax","setTableMap","ridx","row","cells","cidx","tableRows","getTableRows","getRowCells","inlineTables","inlineCells","allCells","tableCells","inlineRows","allRows","getMapIndex","r_length","c_length","r_idx","c_idx","col","getElementAtIndex","getMapElsTo","to_cell","idx_start","idx_end","temp_idx","temp_cidx","maxr","maxc","orderSelectionEnds","secondcell","createCells","nr","correctColIndexForUnreals","corrIdx","getLastNewCellOnRow","rowLimit","removeEmptyTable","splitRowToCells","colspan","cType","newCells","removeAttribute","getRealRowEl","force","injectRowAt","new_cells","n_cidx","canMerge","decreaseCellSpan","span","removeSurplusLines","allRowspan","fillMissingCells","r_max","c_max","prevcell","rectify","unmerge","thisCell","rowspan","collapseCellToNextRow","cellIdx","newRowIdx","newIdx","lastCell","removeRowCell","getRowElementsByCell","modRow","getColumnElementsByCell","removeRow","oldRow","removeColCell","removeColumn","what","addRow","where","newRow","addRowCell","cr","colSpanAttr","addColumn","addColCell","doAdd","handleCellAddWithRowspan","modCell","temp_r_cells","nrow","addRowsNr","crow","getCellsBetween","cell1","cell2","c1","addCells","removeCells","mergeCellsBetween","unmergeCell","findCell","findRowByCell","findColumnByCell","elements","thisOwner","otherOwner","point","parents","location_index","smallest_common_ancestor","this_index","other_index","getPastedHtml","clipboardData","getData","getPastedHtmlWithDiv","composer","selBookmark","cleanerDiv","setBookmark","cleanPastedHTML","styleToRegex","styleStr","trimmedStr","escapedStr","extendRulesWithStyleExceptions","exceptStyles","newRules","pickRuleset","ruleset","defaultSet","condition","newHtml","color","fontSize","ensureProperClearing","clearIfNecessary","TILDE_ESCAPED","urlToSearch","elementsWithTilde","redraw","tableCellsSelection","editable","handleSelectionMousedown","removeCellSelections","selection_class","moveHandler","handleMouseMove","upHandler","handleMouseUp","selectedCells","addSelections","oldEnd","curTable","deselect","bindSideclick","sideClickHandler","selectCells","RGBA_REGEX","RGB_REGEX","HEX6_REGEX","HEX3_REGEX","param_REGX","styleParser","parseColor","stylesStr","paramName","colorMatch","paramRegex","radix","shift","d","unparseColor","parseFontSize","_getCumulativeOffsetTop","top","offsetTop","offsetParent","getDepth","expandRangeToSurround","common","start_depth","end_depth","contain","unselectableClass","getRange","setSelection","setBefore","creteTemporaryCaretSpaceAfter","caretPlaceholder","caretPlaceholderText","placeholderRemover","keyDownHandler","delayedPlaceholderRemover","setAfter","which","ctrlKey","metaKey","minWidth","zIndex","originalScrollTop","scrollTop","pageYOffset","originalScrollLeft","scrollLeft","pageXOffset","scrollTo","avoidInvisibleSpace","isElement","displayStyle","getSelectedNode","fixSelBorders","getSelectedOwnNodes","getOwnRanges","ownNodes","maxi","findNodesInSelection","curNodes","containsUneditable","uneditables","getOwnUneditables","startParent","endParent","ev","CustomEvent","dispatchEvent","err","getPreviousNode","ignoreEmpty","getSelectionParentsByTag","curEl","getRangeToNodeEnd","sNode","lastR","caretIsLastInSelection","endc","endtxt","caretIsFirstInSelection","caretIsInTheBeginnig","ofNode","caretIsBeforeUneditable","contentNodes","lastNode","prevLeaf","executeAndRestoreRangy","executeAndRestore","restoreScrollPosition","newCaretPlaceholder","prevSibling","newRange","oldScrollTop","oldScrollLeft","placeholderHtml","surround","nodeOptions","deblockAndSurround","tempDivElements","tempElements","scrollIntoView","tolerance","hasScrollBars","scrollHeight","_wysihtml5ScrollIntoViewElement","selectLine","_selectLine_W3C","_selectLine_MSIE","modify","toLineBoundary","location","rangeBottom","rangeEnd","measureNode","j","rangeTop","boundingTop","scrollWidth","moveToPoint","getText","fixRangeOverflow","containment","_detectInlineRangeProblems","previousElementSibling","_endOffsetForNode","dontFix","allUneditables","deepUneditables","tmpRanges","tmpRange","jmax","getHtml","getPlainText","isEndToEndInNode","nodeNames","cssClass","regExp","matchingClassNames","hasStyleAttr","removeStyle","s2","getMatchingStyleRegexp","regexes","sSplit","elStyle","isMatchingAllready","areMatchingAllready","removeOrChangeStyle","exactRegex","hasSameClasses","el1","el2","REG_EXP_WHITE_SPACE","replaceWithOwnChildren","elementsHaveSameNonClassAttributes","attr1","attr2","getNamedItem","isSplitPoint","splitNodeAt","descendantNode","descendantOffset","Merge","firstNode","isElementMerge","firstTextNode","HTMLApplier","tagNames","similarClassRegExp","similarStyleRegExp","defaultTagName","applyToAnyTagName","doMerge","textBits","getLength","getAncestorWithClass","cssClassMatch","getAncestorWithStyle","cssStyleMatch","getMatchingAncestor","matchType","postApply","currentMerge","precedingTextNode","merges","rangeStartNode","rangeEndNode","rangeStartOffset","rangeEndOffset","getAdjacentMergeableTextNode","nextTextNode","forward","adjacentNode","isTextNode","areElementsMergeable","createContainer","applyToTextNode","isRemovable","undoToTextNode","ancestorWithClass","ancestorWithStyle","styleMode","styleChanged","ancestorRange","applyToRange","ri","undoToRange","getTextSelectedByRange","isAppliedToRange","appliedType","coverage","selectedText","toggleRange","parentsExactMatch","isApplied","Commands","support","result","state","stateValue","bold","formatInline","execWithToggle","_format","anchors","hasElementChild","elementToSetCaretAfter","whiteSpace","tempClass","tempClassRegExp","undef","NODE_NAME","_changeLinks","oldAttrs","oa","createLink","_removeFormat","codeElement","removeLink","size","fontSizeStyle","st","foreColor","foreColorStyle","colString","colorVals","colorStr","bgColorStyle","_addClass","_removeClass","_addStyle","_removeStyle","_removeLastChildIfLineBreak","_selectionWrap","surroundedNodes","_hasClasses","_hasStyles","BLOCK_ELEMENTS_GROUP","selectedNodes","classRemoveAction","blockRenameFound","styleRemoveAction","blockElement","defaultNodeName","b","hasClasses","hasStyles","formatCode","classname","pre","selectedNode","_getTagNames","alias","ALIAS_MAPPING","_getApplier","identifier","htmlApplier","strong","em","dontRestoreSelect","noCleanup","ownRanges","state_element","aliasTagName","insertBlockQuote","endToEndParent","qouteEl","insertImage","image","imagesInSelection","LINE_BREAK","insertLineBreak","insertList","isNode","findListEl","other","parentLi","otherNodeName","handleSameTypeList","innerLists","otherLists","getListsInSelection","l","handleOtherTypeList","renameLists","createListFallback","tempClassName","getTime","uneditableContainerClassname","cmd","italic","justifyCenter","justifyLeft","justifyRight","justifyFull","STYLE_STR","alignRightStyle","alignLeftStyle","alignCenterStyle","redo","undoManager","underline","undo","createTable","cols","rows","tableStyle","mergeTableCells","tableSelection","addTableCells","tableSelect","deleteTableCells","selCell","indentList","listEls","tryToPushLiLevel","liNodes","listTag","prevLi","liNode","prevLiList","found","outdentList","tryToPullLiLevel","listNode","outerListNode","outerLiNode","afterList","getAfterList","newList","Z_KEY","Y_KEY","MAX_HISTORY_ENTRIES","DATA_ATTR_NODE","DATA_ATTR_OFFSET","UndoManager","historyStr","historyDom","transact","_observe","lastKey","sandbox","altKey","keyCode","isUndo","shiftKey","isRedo","previousHtml","currentHtml","getValue","getChildNodeIndex","undoPossible","redoPossible","historyEntry","getChildNodeByIndex","View","textareaElement","noTextarea","_observeViewChange","currentView","show","hide","disable","enable","Composer","CARET_HACK","editableElement","textarea","contentEditableMode","_initContentEditableArea","_initSandbox","_displayStyle","disabled","setToEnd","_create","_createWysiwygFormField","form","hiddenField","composerClassName","placeholder","_initAutoLinking","_initObjectResizing","_initUndoManager","_initLineBreaking","initSync","sync","supportsDisablingOfAutoLinking","supportsAutoLinking","nodeWithSelection","isInUneditable","links","urlRegExp","newTextContent","properties","propertiesLength","adjust","USE_NATIVE_LINE_BREAK_INSIDE_TAGS","LIST_TAGS","HOST_TEMPLATE","TEXT_FORMATTING","BOX_FORMATTING","ADDITIONAL_CSS_RULES","focusWithoutScrolling","setActive","elementStyle","originalStyles","WebkitUserSelect","displayValueForCopying","originalActiveElement","hasPlaceholder","originalPlaceholder","originalDisplayValue","originalDisabled","focusStylesHost","blurStylesHost","disabledStylesHost","blur","boxFormattingStyles","shortcuts","66","73","85","addListeners","removeListeners","handleDeleteKeyPress","beforeUneditable","handleTabKeyDown","handleDomNodeRemoved","domNodeRemovedInterval","clearInterval","handleUserInteraction","handleFocus","focusState","handleBlur","changeevent","create","handlePaste","handleCopy","copyedFromMarking","setData","handleKeyUp","handleMouseDown","allImages","notMyImages","myImages","handleMouseOver","title","titlePrefixes","IMG","handleClick","uneditable","handleDrop","handleKeyDown","handleTabKey","handleIframeFocus","handleIframeBlur","initTableHandling","hideHandlers","iframeInitiator","focusBlurElement","setInterval","handleTables","INTERVAL","Synchronizer","fromComposerToTextarea","shouldParseHtml","fromTextareaToComposer","textareaValue","interval","startInterval","stopInterval","Textarea","supportsPlaceholder","eventMapping","focusin","focusout","defaultConfig","showToolbarAfterInit","parserRules","br","div","pasteParserRulesets","parser","bodyClassName","supportTouchDevices","Editor","_isCompatible","_initParser","handleBeforeLoad","synchronizer","Toolbar","isCompatible","htmlOrElement","parseContext","oldHtml","_cleanAndPaste","pastedHTML","cleanHtml"],"mappings":";;CAOA,WAWE,GAVKA,MAAMC,UAAUC,iBACnBF,MAAMC,UAAUC,eAAe,WAC7BC,KAAKC,aAAY,IAGhBJ,MAAMC,UAAUI,kBACnBL,MAAMC,UAAUI,gBAAgB,WAC9BF,KAAKG,cAAa,KAGjBC,QAAQN,UAAUO,iBAAkB,CACvC,GAAIC,MAEAD,EAAiB,SAASE,EAAKC,GACjC,GAAIC,GAAKT,KACLU,EAAQ,SAASC,GACnBA,EAAEC,OAAOD,EAAEE,WACXF,EAAEG,cAAcL,EACZD,EAASO,YACXP,EAASO,YAAYJ,GAErBH,EAASQ,KAAKP,EAAKE,GAGvB,IAAU,oBAANJ,EAA0B,CAC5B,GAAIU,GAAS,SAASN,GACK,YAArBO,SAASC,YACXT,EAAQC,GAMZ,IAHAO,SAASE,YAAY,qBAAqBH,GAC1CX,EAAee,MAAMC,OAAOtB,KAAKO,KAAKA,EAAKC,SAASA,EAASE,QAAQO,IAE5C,YAArBC,SAASC,WAAwB,CACnC,GAAIR,GAAE,GAAId,MACVc,GAAEE,WAAWU,OACbN,EAASN,QAGXX,MAAKoB,YAAY,KAAKb,EAAKG,GAC3BJ,EAAee,MAAMC,OAAOtB,KAAKO,KAAKA,EAAKC,SAASA,EAASE,QAAQA,KAGrEc,EAAoB,SAASjB,EAAKC,GAEpC,IADA,GAAIiB,GAAQ,EACLA,EAAQnB,EAAeoB,QAAQ,CACpC,GAAIC,GAAcrB,EAAemB,EACjC,IAAIE,EAAcL,QAAQtB,MAAQ2B,EAAcpB,MAAMA,GAAQoB,EAAcnB,UAAUA,EAAU,CACpF,oBAAND,EACFP,KAAK4B,YAAY,qBAAqBD,EAAcjB,SAEpDV,KAAK4B,YAAY,KAAKrB,EAAKoB,EAAcjB,SAE3CJ,EAAeuB,OAAOJ,EAAS,EAC/B,SAE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PE html>
+
+<meta http-equiv="X-UA-Compatible" content="IE=Edge">
+<meta charset="utf-8">
+
+<title>wysihtml5 - Advanced Demo</title>
+
+<style>
+ body {
+ font-family: Verdana;
+ font-size: 11px;
+ }
+
+ h2 {
+ margin-bottom: 0;
+ }
+
+ small {
+ display: block;
+ margin-top: 40px;
+ font-size: 9px;
+ }
+
+ small,
+ small a {
+ color: #666;
+ }
+
+ a {
+ color: #000;
+ text-decoration: underline;
+ cursor: pointer;
+ }
+
+ #toolbar [data-wysihtml5-action] {
+ float: right;
+ }
+
+ #toolbar,
+ textarea {
+ width: 920px;
+ padding: 5px;
+ -webkit-box-sizing: border-box;
+ -ms-box-sizing: border-box;
+ -moz-box-sizing: border-box;
+ box-sizing: border-box;
+ }
+
+ textarea {
+ height: 280px;
+ border: 2px solid green;
+ font-family: Verdana;
+ font-size: 11px;
+ }
+
+ textarea:focus {
+ color: black;
+ border: 2px solid black;
+ }
+
+ .wysihtml5-command-active {
+ font-weight: bold;
+ }
+
+ [data-wysihtml5-dialog] {
+ margin: 5px 0 0;
+ padding: 5px;
+ border: 1px solid #666;
+ }
+
+ a[data-wysihtml5-command-value="red"] {
+ color: red;
+ }
+
+ a[data-wysihtml5-command-value="green"] {
+ color: green;
+ }
+
+ a[data-wysihtml5-command-value="blue"] {
+ color: blue;
+ }
+</style>
+
+<h1>wysihtml5 - Advanced Editor Example</h1>
+
+<form class="ewrapper">
+ <div class="toolbar" style="display: none;">
+ <a data-wysihtml5-command="bold" title="CTRL+B">bold</a> |
+ <a data-wysihtml5-command="italic" title="CTRL+I">italic</a> |
+ <a data-wysihtml5-command="createLink">link</a> |
+ <a data-wysihtml5-command="removeLink"><s>link</s></a> |
+ <a data-wysihtml5-command="insertImage">insert image</a> |
+ <a data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="h1">h1</a> |
+ <a data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="h2">h2</a> |
+ <a data-wysihtml5-command="insertUnorderedList">insertUnorderedList</a> |
+ <a data-wysihtml5-command="insertOrderedList">insertOrderedList</a> |
+ <a data-wysihtml5-command="foreColor" data-wysihtml5-command-value="red">red</a> |
+ <a data-wysihtml5-command="foreColor" data-wysihtml5-command-value="green">green</a> |
+ <a data-wysihtml5-command="foreColor" data-wysihtml5-command-value="blue">blue</a> |
+ <a data-wysihtml5-command="formatCode" data-wysihtml5-command-value="language-html">Code</a> |
+ <a data-wysihtml5-command="undo">undo</a> |
+ <a data-wysihtml5-command="redo">redo</a> |
+ <a data-wysihtml5-command="insertSpeech">speech</a>
+ <a data-wysihtml5-action="change_view">switch to html view</a>
+
+ <div data-wysihtml5-dialog="createLink" style="display: none;">
+ <label>
+ Link:
+ <input data-wysihtml5-dialog-field="href" value="http://">
+ </label>
+ <a data-wysihtml5-dialog-action="save">OK</a> <a data-wysihtml5-dialog-action="cancel">Cancel</a>
+ </div>
+
+ <div data-wysihtml5-dialog="insertImage" style="display: none;">
+ <label>
+ Image:
+ <input data-wysihtml5-dialog-field="src" value="http://">
+ </label>
+ <label>
+ Align:
+ <select data-wysihtml5-dialog-field="className">
+ <option value="">default</option>
+ <option value="wysiwyg-float-left">left</option>
+ <option value="wysiwyg-float-right">right</option>
+ </select>
+ </label>
+ <a data-wysihtml5-dialog-action="save">OK</a> <a data-wysihtml5-dialog-action="cancel">Cancel</a>
+ </div>
+
+ </div>
+ <textarea class="editable" placeholder="Enter text ..."></textarea>
+ <br><input type="reset" value="Reset form!">
+</form>
+
+<br/><br>asdasdasd:<br/>
+<form class="ewrapper">
+ <div class="toolbar" style="display: none;">
+ <a data-wysihtml5-command="bold" title="CTRL+B">bold</a> |
+ <a data-wysihtml5-command="italic" title="CTRL+I">italic</a> |
+ <a data-wysihtml5-command="createLink">link</a> |
+ <a data-wysihtml5-command="removeLink"><s>link</s></a> |
+ <a data-wysihtml5-command="insertImage">insert image</a> |
+ <a data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="h1">h1</a> |
+ <a data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="h2">h2</a> |
+ <a data-wysihtml5-command="insertUnorderedList">insertUnorderedList</a> |
+ <a data-wysihtml5-command="insertOrderedList">insertOrderedList</a> |
+ <a data-wysihtml5-command="foreColor" data-wysihtml5-command-value="red">red</a> |
+ <a data-wysihtml5-command="foreColor" data-wysihtml5-command-value="green">green</a> |
+ <a data-wysihtml5-command="foreColor" data-wysihtml5-command-value="blue">blue</a> |
+ <a data-wysihtml5-command="undo">undo</a> |
+ <a data-wysihtml5-command="redo">redo</a> |
+ <a data-wysihtml5-command="insertSpeech">speech</a>
+ <a data-wysihtml5-action="change_view">switch to html view</a>
+
+ <div data-wysihtml5-dialog="createLink" style="display: none;">
+ <label>
+ Link:
+ <input data-wysihtml5-dialog-field="href" value="http://">
+ </label>
+ <a data-wysihtml5-dialog-action="save">OK</a> <a data-wysihtml5-dialog-action="cancel">Cancel</a>
+ </div>
+
+ <div data-wysihtml5-dialog="insertImage" style="display: none;">
+ <label>
+ Image:
+ <input data-wysihtml5-dialog-field="src" value="http://">
+ </label>
+ <label>
+ Align:
+ <select data-wysihtml5-dialog-field="className">
+ <option value="">default</option>
+ <option value="wysiwyg-float-left">left</option>
+ <option value="wysiwyg-float-right">right</option>
+ </select>
+ </label>
+ <a data-wysihtml5-dialog-action="save">OK</a> <a data-wysihtml5-dialog-action="cancel">Cancel</a>
+ </div>
+
+ </div>
+ <textarea class="editable" placeholder="Enter text ..."></textarea>
+ <br><input type="reset" value="Reset form!">
+</form>
+
+<h2>Events:</h2>
+<div id="log"></div>
+
+<small>powered by <a href="https://github.com/xing/wysihtml5" target="_blank">wysihtml5</a>.</small>
+
+<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
+
+<script src="../parser_rules/advanced_unwrap.js"></script>
+<script src="../dist/wysihtml5x-toolbar.min.js"></script>
+<script>
+var editors = [];
+
+ $('.ewrapper').each(function(idx, wrapper) {
+ var e = new wysihtml5.Editor($(wrapper).find('.editable').get(0), {
+ toolbar: $(wrapper).find('.toolbar').get(0),
+ parserRules: wysihtml5ParserRules,
+ stylesheets: "css/stylesheet.css"
+ //showToolbarAfterInit: false
+ });
+ editors.push(e);
+ });
+
+
+ /*
+ var editor = new wysihtml5.Editor("textarea", {
+ toolbar: "toolbar",
+ stylesheets: "css/stylesheet.css",
+ parserRules: wysihtml5ParserRules
+ });
+
+ var log = document.getElementById("log");
+
+ editor
+ .on("load", function() {
+ log.innerHTML += "<div>load</div>";
+ })
+ .on("focus", function() {
+ log.innerHTML += "<div>focus</div>";
+ })
+ .on("blur", function() {
+ log.innerHTML += "<div>blur</div>";
+ })
+ .on("change", function() {
+ log.innerHTML += "<div>change</div>";
+ })
+ .on("paste", function() {
+ log.innerHTML += "<div>paste</div>";
+ })
+ .on("newword:composer", function() {
+ log.innerHTML += "<div>newword:composer</div>";
+ })
+ .on("undo:composer", function() {
+ log.innerHTML += "<div>undo:composer</div>";
+ })
+ .on("redo:composer", function() {
+ log.innerHTML += "<div>redo:composer</div>";
+ });*/
+</script>
\ No newline at end of file
--- /dev/null
+<!DOCTYPE html>
+
+<meta http-equiv="X-UA-Compatible" content="IE=Edge">
+<meta charset="utf-8">
+
+<title>wysihtml5 - Advanced Demo</title>
+<link rel="stylesheet" href="css/stylesheet.css" type="text/css" media="screen" title="no title" charset="utf-8">
+
+
+<style>
+
+ body {
+ font-family: Verdana;
+ font-size: 11px;
+ }
+
+ h2 {
+ margin-bottom: 0;
+ }
+
+ small {
+ display: block;
+ margin-top: 40px;
+ font-size: 9px;
+ }
+
+ small,
+ small a {
+ color: #666;
+ }
+
+ a {
+ color: #000;
+ text-decoration: underline;
+ cursor: pointer;
+ }
+
+ #toolbar [data-wysihtml5-action] {
+ float: right;
+ }
+
+ #toolbar,
+ textarea {
+ width: 920px;
+ padding: 5px;
+ -webkit-box-sizing: border-box;
+ -ms-box-sizing: border-box;
+ -moz-box-sizing: border-box;
+ box-sizing: border-box;
+ }
+
+ textarea {
+ height: 280px;
+ border: 2px solid green;
+ font-family: Verdana;
+ font-size: 11px;
+ }
+
+ textarea:focus {
+ color: black;
+ border: 2px solid black;
+ }
+
+ .wysihtml5-command-active {
+ font-weight: bold;
+ }
+
+ [data-wysihtml5-dialog] {
+ margin: 5px 0 0;
+ padding: 5px;
+ border: 1px solid #666;
+ }
+
+
+
+ a[data-wysihtml5-command-value="red"] {
+ color: red;
+ }
+
+ a[data-wysihtml5-command-value="green"] {
+ color: green;
+ }
+
+ a[data-wysihtml5-command-value="blue"] {
+ color: blue;
+ }
+
+ .wysihtml5-editor, .wysihtml5-editor table td {
+ outline: 1px dotted #abc;
+
+ }
+
+ code {
+ background: #ddd;
+ padding: 10px;
+ white-space: pre;
+ display: block;
+ margin: 1em 0;
+ }
+
+ .toolbar {
+ display: block;
+ border-radius: 3px;
+ border: 1px solid #fff;
+ margin-bottom: 9px;
+ line-height: 1em;
+ }
+ .toolbar a {
+ display: inline-block;
+ height: 1.5em;
+ border-radius: 3px;
+ font-size: 9px;
+ line-height: 1.5em;
+ text-decoration: none;
+ background: #e1e1e1;
+ border: 1px solid #ddd;
+ padding: 0 0.2em;
+ margin: 1px 0;
+ }
+ .toolbar a.wysihtml5-command-active {
+ background: #222;
+ color: white;
+ }
+ .toolbar .block {
+ padding: 1px 1px;
+ display: inline-block;
+ background: #eee;
+ border-radius: 3px;
+ margin: 0px 1px 1px 0;
+ }
+
+ div[data-wysihtml5-dialog="createTable"] {
+ position: absolute;
+ background: white;
+ }
+
+ div[data-wysihtml5-dialog="createTable"] td {
+ width: 10px; height: 5px;
+ border: 1px solid #666;
+ }
+
+ .wysihtml5-editor table td.wysiwyg-tmp-selected-cell {
+ outline: 2px solid green;
+ }
+
+ .editor-container-tag {
+ padding: 5px 10px;
+ position: absolute;
+ color: white;
+ background: rgba(0,0,0,0.8);
+ width: 100px;
+ margin-left: -50px;
+ -webkit-transition: 0.1s left, 0.1s top;
+ }
+
+ .wrap {
+ max-width: 700px;
+ margin: 40px;
+ }
+
+ .editable .wysihtml5-uneditable-container {
+ outline: 1px dotted gray;
+ position: relative;
+ }
+ .editable .wysihtml5-uneditable-container-right {
+ float: right;
+ width: 50%;
+ margin-left: 2em;
+ margin-bottom: 1em;
+ }
+
+ .editable .wysihtml5-uneditable-container-left {
+ float: left;
+ width: 50%;
+ margin-right: 2em;
+ margin-bottom: 1em;
+ }
+
+</style>
+<div class="wrap">
+ <h1>wysihtml5 - Advanced Editor Example</h1>
+
+ <div class="ewrapper" contentEditable="false">
+ <div class="toolbar" style="display: none;">
+ <div class="block">
+ <a data-wysihtml5-command="bold" title="CTRL+B">bold</a>
+ <a data-wysihtml5-command="italic" title="CTRL+I">italic</a>
+ <a data-wysihtml5-command="underline" title="CTRL+U">underline</a>
+ </div>
+ <div class="block">
+ <a data-wysihtml5-command="createLink">link</a>
+ <a data-wysihtml5-command="removeLink"><s>link</s></a>
+ <a data-wysihtml5-command="insertImage">image</a>
+ <a data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="h1">h1</a>
+ <a data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="h2">h2</a>
+ <a data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="h3">h3</a>
+ <a data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="p">p</a>
+ <a data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="pre">pre</a>
+ <a data-wysihtml5-command="insertBlockQuote">blockquote</a>
+ <a data-wysihtml5-command="formatCode" data-wysihtml5-command-value="language-html">Code</a>
+ </div>
+
+ <div class="block">
+ <a data-wysihtml5-command="fontSizeStyle">Size</a>
+ <div data-wysihtml5-dialog="fontSizeStyle" style="display: none;">
+ Size:
+ <input type="text" data-wysihtml5-dialog-field="size" style="width: 60px;" value="" />
+ <a data-wysihtml5-dialog-action="save">OK</a> <a data-wysihtml5-dialog-action="cancel">Cancel</a>
+ </div>
+ </div>
+
+ <div class="block">
+ <a data-wysihtml5-command="insertUnorderedList">• List</a>
+ <a data-wysihtml5-command="insertOrderedList">1. List</a>
+ </div>
+ <div class="block">
+ <a data-wysihtml5-command="outdentList"><-</a>
+ <a data-wysihtml5-command="indentList">-></a>
+ </div>
+ <div class="block">
+ <a data-wysihtml5-command="justifyLeft">justifyLeft</a>
+ <a data-wysihtml5-command="justifyRight">justifyRight</a>
+ <a data-wysihtml5-command="justifyFull">justifyFull</a>
+ </div>
+
+ <div class="block">
+ <a data-wysihtml5-command="alignLeftStyle">alignLeft</a>
+ <a data-wysihtml5-command="alignRightStyle">alignRight</a>
+ <a data-wysihtml5-command="alignCenterStyle">alignCenter</a>
+ </div>
+
+ <div class="block">
+ <a data-wysihtml5-command="foreColorStyle">Color</a>
+ <div data-wysihtml5-dialog="foreColorStyle" style="display: none;">
+ Color:
+ <input type="text" data-wysihtml5-dialog-field="color" value="rgba(0,0,0,1)" />
+ <a data-wysihtml5-dialog-action="save">OK</a> <a data-wysihtml5-dialog-action="cancel">Cancel</a>
+ </div>
+ </div>
+
+ <div class="block">
+ <a data-wysihtml5-command="bgColorStyle">BG Color</a>
+ <div data-wysihtml5-dialog="bgColorStyle" style="display: none;">
+ Color:
+ <input type="text" data-wysihtml5-dialog-field="color" value="rgba(0,0,0,1)" />
+ <a data-wysihtml5-dialog-action="save">OK</a> <a data-wysihtml5-dialog-action="cancel">Cancel</a>
+ </div>
+ </div>
+
+ <div class="block">
+ <a data-wysihtml5-command="undo">undo</a>
+ <a data-wysihtml5-command="redo">redo</a>
+ </div>
+
+ <div class="block">
+ <a data-wysihtml5-action="showSource">HTML</a>
+ </div>
+
+ <div data-wysihtml5-dialog="createLink" style="display: none;">
+ <label>
+ Link:
+ <input data-wysihtml5-dialog-field="href" value="http://">
+ </label>
+ <a data-wysihtml5-dialog-action="save">OK</a> <a data-wysihtml5-dialog-action="cancel">Cancel</a>
+ </div>
+ <div data-wysihtml5-dialog="insertImage" style="display: none;">
+ <label>
+ Image:
+ <input data-wysihtml5-dialog-field="src" value="http://">
+ </label>
+ <label>
+ Align:
+ <select data-wysihtml5-dialog-field="className">
+ <option value="">default</option>
+ <option value="wysiwyg-float-left">left</option>
+ <option value="wysiwyg-float-right">right</option>
+ </select>
+ </label>
+ <a data-wysihtml5-dialog-action="save">OK</a> <a data-wysihtml5-dialog-action="cancel">Cancel</a>
+ </div>
+ </div><!-- toolbar -->
+
+ <div class="editable" data-placeholder="Enter text ...">
+
+ <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
+ <p>Nullam egestas nisl augue, a fermentum quam laoreet at.</p>
+ <p>Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.</p>
+
+ <p>XXX Pellentesque ullamcorper ultrices nibh mollis mattis. Etiam ac fermentum nisi. Sed sagittis porta augue, vel congue mi. Vivamus egestas vestibulum sem, a suscipit libero faucibus ut. Quisque mauris metus, imperdiet at velit a, suscipit fermentum ante. Nullam pretium mauris at risus eleifend ultrices. Vestibulum ullamcorper mattis est non lobortis. Donec consequat magna quis felis mollis tristique. Fusce sed congue felis.
+ Aenean ut nulla orci. Praesent id mollis massa. Fusce interdum eleifend bibendum. Nulla luctus nisl sit amet sapien sodales ornare. Duis blandit, purus eu egestas pretium, nisi augue aliquet quam, non suscipit diam velit eu enim. Suspendisse vulputate nibh et porta eleifend. Pellentesque rhoncus hendrerit quam. Ut sit amet ligula ac tortor porta ullamcorper.
+ </p>
+ <div contentEditable="false" class="wysihtml5-uneditable-container wysihtml5-uneditable-container-left" style="padding: 10px;">
+ <h1>This content is not editable</h1>
+ <p>thus it is suitable to build own modules of image and videos inside editor.</p>
+ Aenean ut nulla orci. Praesent id mollis massa. Fusce interdum eleifend bibendum. Nulla luctus nisl sit amet sapien sodales ornare. Duis blandit, purus eu egestas pretium, nisi augue aliquet quam, non suscipit diam velit eu enim. Suspendisse vulputate nibh et porta eleifend. Pellentesque rhoncus hendrerit quam. Ut sit amet ligula ac tortor porta ullamcorper.
+ </div>
+ <p>Nulla facilisi. Ut quis pellentesque nisi, eget convallis nisi. Fusce dapibus tortor sem, et blandit nunc porttitor eget. Etiam eu nulla id nibh aliquet semper ut ut lorem. Nullam dapibus massa interdum interdum vehicula. Sed ante urna, pulvinar ut lacinia hendrerit, tristique ut enim. Fusce euismod adipiscing justo, nec malesuada massa sodales a. Integer pulvinar sed ligula et consectetur. Curabitur pulvinar cursus venenatis. Morbi in justo eget ipsum rhoncus accumsan. Sed felis orci, sodales eget est sit amet, sollicitudin lacinia justo. Aliquam et eros faucibus, tincidunt leo at, feugiat eros. Duis malesuada laoreet lorem eu molestie. Nulla vestibulum tincidunt diam ut placerat.</p>
+
+ <p>Aenean pretium diam nunc, at imperdiet elit vehicula a. Mauris nec felis non sem condimentum adipiscing ut et lacus. Donec facilisis facilisis lacinia. Nam posuere at nulla ut malesuada. Fusce ultricies lectus eu iaculis molestie. Ut consequat id magna et placerat. Nulla sed ante lectus. Donec congue, velit in ultricies tempus, felis lectus tempus sem, non bibendum lorem mi vel lorem. Mauris a placerat dui, nec auctor erat.</p>
+
+ <p>Suspendisse id mauris vel urna venenatis pharetra. Pellentesque luctus et nulla in vulputate. Donec id ligula id enim congue convallis id eu nibh. Phasellus a leo non dui porta sodales ac vel justo. Etiam sed dignissim ligula. Morbi consequat adipiscing risus vitae accumsan. Curabitur dignissim nec quam non blandit. Etiam venenatis, est a facilisis convallis, mauris nibh ultricies sapien, eget egestas neque eros sed libero. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas et velit sit amet quam pulvinar accumsan. Donec id sollicitudin dolor.</p>
+ </div>
+
+ </div>
+
+ <!-- oldschool clearfix -->
+ <div style="height: 1px; width: 100%; overflow: hidden; clear: both"></div>
+
+ <br/>
+ <br/>
+
+
+ <div class="ewrapper" contentEditable="false">
+ <div class="toolbar" style="display: none;">
+ <div class="block">
+ <a data-wysihtml5-command="bold" title="CTRL+B">bold</a>
+ <a data-wysihtml5-command="italic" title="CTRL+I">italic</a>
+ <a data-wysihtml5-command="underline" title="CTRL+U">underline</a>
+ </div>
+ <div class="block">
+ <a data-wysihtml5-command="createLink">link</a>
+ <a data-wysihtml5-command="removeLink"><s>link</s></a>
+ <a data-wysihtml5-command="insertImage">image</a>
+ <a data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="h1">h1</a>
+ <a data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="h2">h2</a>
+ <a data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="h3">h3</a>
+ <a data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="p">p</a>
+ <a data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="pre">pre</a>
+ </div>
+
+ <div class="block">
+ <a data-wysihtml5-command="fontSizeStyle">Size</a>
+ <div data-wysihtml5-dialog="fontSizeStyle" style="display: none;">
+ Size:
+ <input type="text" data-wysihtml5-dialog-field="size" style="width: 60px;" value="" />
+ <a data-wysihtml5-dialog-action="save">OK</a> <a data-wysihtml5-dialog-action="cancel">Cancel</a>
+ </div>
+ </div>
+
+ <div class="block">
+ <a data-wysihtml5-command="insertUnorderedList">• List</a>
+ <a data-wysihtml5-command="insertOrderedList">1. List</a>
+ </div>
+ <div class="block">
+ <a data-wysihtml5-command="justifyLeft">justifyLeft</a>
+ <a data-wysihtml5-command="justifyRight">justifyRight</a>
+ <a data-wysihtml5-command="justifyFull">justifyFull</a>
+ </div>
+
+ <div class="block">
+ <a data-wysihtml5-command="foreColorStyle">Color</a>
+ <div data-wysihtml5-dialog="foreColorStyle" style="display: none;">
+ Color:
+ <input type="text" data-wysihtml5-dialog-field="color" value="rgba(0,0,0,1)" />
+ <a data-wysihtml5-dialog-action="save">OK</a> <a data-wysihtml5-dialog-action="cancel">Cancel</a>
+ </div>
+ </div>
+
+ <div class="block">
+ <a data-wysihtml5-command="bgColorStyle">BG Color</a>
+ <div data-wysihtml5-dialog="bgColorStyle" style="display: none;">
+ Color:
+ <input type="text" data-wysihtml5-dialog-field="color" value="rgba(0,0,0,1)" />
+ <a data-wysihtml5-dialog-action="save">OK</a> <a data-wysihtml5-dialog-action="cancel">Cancel</a>
+ </div>
+ </div>
+
+ <div class="block">
+ <a data-wysihtml5-command="undo">undo</a>
+ <a data-wysihtml5-command="redo">redo</a>
+ </div>
+ <div class="block">
+ <a data-wysihtml5-action="showSource">HTML</a>
+ </div>
+
+ <div class="block">
+ <a data-wysihtml5-command="createTable">Table</a>
+ <div data-wysihtml5-dialog="createTable" style="display: none;">
+ Rows: <input type="text" data-wysihtml5-dialog-field="rows" /><br/>
+ Cols: <input type="text" data-wysihtml5-dialog-field="cols" /><br/>
+ <a data-wysihtml5-dialog-action="save">OK</a> <a data-wysihtml5-dialog-action="cancel">Cancel</a>
+ </div>
+ </div>
+ <div class="block" data-wysihtml5-hiddentools="table" style="display: none;">
+ <a data-wysihtml5-command="mergeTableCells">Merge</a>
+ <a data-wysihtml5-command="addTableCells" data-wysihtml5-command-value="above">row-before</a>
+ <a data-wysihtml5-command="addTableCells" data-wysihtml5-command-value="below">row-after</a>
+ <a data-wysihtml5-command="addTableCells" data-wysihtml5-command-value="before">col-before</a>
+ <a data-wysihtml5-command="addTableCells" data-wysihtml5-command-value="after">col-after</a>
+
+ <a data-wysihtml5-command="deleteTableCells" data-wysihtml5-command-value="row">delete row</a>
+ <a data-wysihtml5-command="deleteTableCells" data-wysihtml5-command-value="column">delete col</a>
+
+ </div>
+
+
+ <div data-wysihtml5-dialog="createLink" style="display: none;">
+ <label>
+ Link:
+ <input data-wysihtml5-dialog-field="href" value="http://">
+ </label>
+ <a data-wysihtml5-dialog-action="save">OK</a> <a data-wysihtml5-dialog-action="cancel">Cancel</a>
+ </div>
+ <div data-wysihtml5-dialog="insertImage" style="display: none;">
+ <label>
+ Image:
+ <input data-wysihtml5-dialog-field="src" value="http://">
+ </label>
+ <label>
+ Align:
+ <select data-wysihtml5-dialog-field="className">
+ <option value="">default</option>
+ <option value="wysiwyg-float-left">left</option>
+ <option value="wysiwyg-float-right">right</option>
+ </select>
+ </label>
+ <a data-wysihtml5-dialog-action="save">OK</a> <a data-wysihtml5-dialog-action="cancel">Cancel</a>
+ </div>
+ </div><!-- toolbar -->
+
+ <div class="editable" data-placeholder="Enter text ...">
+ Pellentesque ullamcorper ultrices nibh mollis mattis. Etiam ac fermentum nisi. Sed sagittis porta augue, vel congue mi. Vivamus egestas vestibulum sem, a suscipit libero faucibus ut. Quisque mauris metus, imperdiet at velit a, suscipit fermentum ante. Nullam pretium mauris at risus eleifend ultrices. Vestibulum ullamcorper mattis est non lobortis. Donec consequat magna quis felis mollis tristique. Fusce sed congue felis.
+ <br/>
+ Nulla facilisi. Ut quis pellentesque nisi, eget convallis nisi. Fusce dapibus tortor sem, et blandit nunc porttitor eget. Etiam eu nulla id nibh aliquet semper ut ut lorem. Nullam dapibus massa interdum interdum vehicula.
+ <br/><br/>
+ <table>
+ <tr>
+ <td>1 </td><td>2 </td><td>3 </td>
+ </tr>
+ <tr>
+ <td>4 </td><td> </td><td> </td>
+ </tr>
+ <tr>
+ <td>7 </td><td> </td><td> </td>
+ </tr>
+ </table>
+ </div>
+ </div>
+
+</div><!-- //wrap -->
+
+
+
+<h2>Events:</h2>
+<div id="log"></div>
+
+<small>powered by <a href="https://github.com/xing/wysihtml5" target="_blank">wysihtml5</a>.</small>
+
+<script src="jquery.1.10.2.js" type="text/javascript" charset="utf-8"></script>
+
+<script src="../dist/wysihtml5x-toolbar.min.js"></script>
+<script src="../parser_rules/advanced_and_extended.js"></script>
+
+
+<script>
+var editors = [];
+
+ $('.ewrapper').each(function(idx, wrapper) {
+ var e = new wysihtml5.Editor($(wrapper).find('.editable').get(0), {
+ toolbar: $(wrapper).find('.toolbar').get(0),
+ parserRules: wysihtml5ParserRules,
+ pasteParserRulesets: wysihtml5ParserPasteRulesets
+ //showToolbarAfterInit: false
+ });
+ editors.push(e);
+
+ e.on("showSource", function() {
+ alert(e.getValue(true));
+ });
+
+ });
+
+</script>
\ No newline at end of file
--- /dev/null
+.wysiwyg-font-size-smaller {
+ font-size: smaller;
+}
+
+.wysiwyg-font-size-larger {
+ font-size: larger;
+}
+
+.wysiwyg-font-size-xx-large {
+ font-size: xx-large;
+}
+
+.wysiwyg-font-size-x-large {
+ font-size: x-large;
+}
+
+.wysiwyg-font-size-large {
+ font-size: large;
+}
+
+.wysiwyg-font-size-medium {
+ font-size: medium;
+}
+
+.wysiwyg-font-size-small {
+ font-size: small;
+}
+
+.wysiwyg-font-size-x-small {
+ font-size: x-small;
+}
+
+.wysiwyg-font-size-xx-small {
+ font-size: xx-small;
+}
+
+.wysiwyg-color-black {
+ color: black;
+}
+
+.wysiwyg-color-silver {
+ color: silver;
+}
+
+.wysiwyg-color-gray {
+ color: gray;
+}
+
+.wysiwyg-color-white {
+ color: white;
+}
+
+.wysiwyg-color-maroon {
+ color: maroon;
+}
+
+.wysiwyg-color-red {
+ color: red;
+}
+
+.wysiwyg-color-purple {
+ color: purple;
+}
+
+.wysiwyg-color-fuchsia {
+ color: fuchsia;
+}
+
+.wysiwyg-color-green {
+ color: green;
+}
+
+.wysiwyg-color-lime {
+ color: lime;
+}
+
+.wysiwyg-color-olive {
+ color: olive;
+}
+
+.wysiwyg-color-yellow {
+ color: yellow;
+}
+
+.wysiwyg-color-navy {
+ color: navy;
+}
+
+.wysiwyg-color-blue {
+ color: blue;
+}
+
+.wysiwyg-color-teal {
+ color: teal;
+}
+
+.wysiwyg-color-aqua {
+ color: aqua;
+}
+
+.wysiwyg-text-align-right {
+ text-align: right;
+}
+
+.wysiwyg-text-align-center {
+ text-align: center;
+}
+
+.wysiwyg-text-align-left {
+ text-align: left;
+}
+
+.wysiwyg-text-align-justify {
+ text-align: justify;
+}
+
+.wysiwyg-float-left {
+ float: left;
+ margin: 0 8px 8px 0;
+}
+
+.wysiwyg-float-right {
+ float: right;
+ margin: 0 0 8px 8px;
+}
+
+.wysiwyg-clear-right {
+ clear: right;
+}
+
+.wysiwyg-clear-left {
+ clear: left;
+}
--- /dev/null
+/*! jQuery v1.10.2 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license
+//@ sourceMappingURL=jquery-1.10.2.min.map
+*/
+(function(e,t){var n,r,i=typeof t,o=e.location,a=e.document,s=a.documentElement,l=e.jQuery,u=e.$,c={},p=[],f="1.10.2",d=p.concat,h=p.push,g=p.slice,m=p.indexOf,y=c.toString,v=c.hasOwnProperty,b=f.trim,x=function(e,t){return new x.fn.init(e,t,r)},w=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,T=/\S+/g,C=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,N=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,k=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,E=/^[\],:{}\s]*$/,S=/(?:^|:|,)(?:\s*\[)+/g,A=/\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g,j=/"[^"\\\r\n]*"|true|false|null|-?(?:\d+\.|)\d+(?:[eE][+-]?\d+|)/g,D=/^-ms-/,L=/-([\da-z])/gi,H=function(e,t){return t.toUpperCase()},q=function(e){(a.addEventListener||"load"===e.type||"complete"===a.readyState)&&(_(),x.ready())},_=function(){a.addEventListener?(a.removeEventListener("DOMContentLoaded",q,!1),e.removeEventListener("load",q,!1)):(a.detachEvent("onreadystatechange",q),e.detachEvent("onload",q))};x.fn=x.prototype={jquery:f,constructor:x,init:function(e,n,r){var i,o;if(!e)return this;if("string"==typeof e){if(i="<"===e.charAt(0)&&">"===e.charAt(e.length-1)&&e.length>=3?[null,e,null]:N.exec(e),!i||!i[1]&&n)return!n||n.jquery?(n||r).find(e):this.constructor(n).find(e);if(i[1]){if(n=n instanceof x?n[0]:n,x.merge(this,x.parseHTML(i[1],n&&n.nodeType?n.ownerDocument||n:a,!0)),k.test(i[1])&&x.isPlainObject(n))for(i in n)x.isFunction(this[i])?this[i](n[i]):this.attr(i,n[i]);return this}if(o=a.getElementById(i[2]),o&&o.parentNode){if(o.id!==i[2])return r.find(e);this.length=1,this[0]=o}return this.context=a,this.selector=e,this}return e.nodeType?(this.context=this[0]=e,this.length=1,this):x.isFunction(e)?r.ready(e):(e.selector!==t&&(this.selector=e.selector,this.context=e.context),x.makeArray(e,this))},selector:"",length:0,toArray:function(){return g.call(this)},get:function(e){return null==e?this.toArray():0>e?this[this.length+e]:this[e]},pushStack:function(e){var t=x.merge(this.constructor(),e);return t.prevObject=this,t.context=this.context,t},each:function(e,t){return x.each(this,e,t)},ready:function(e){return x.ready.promise().done(e),this},slice:function(){return this.pushStack(g.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(e){var t=this.length,n=+e+(0>e?t:0);return this.pushStack(n>=0&&t>n?[this[n]]:[])},map:function(e){return this.pushStack(x.map(this,function(t,n){return e.call(t,n,t)}))},end:function(){return this.prevObject||this.constructor(null)},push:h,sort:[].sort,splice:[].splice},x.fn.init.prototype=x.fn,x.extend=x.fn.extend=function(){var e,n,r,i,o,a,s=arguments[0]||{},l=1,u=arguments.length,c=!1;for("boolean"==typeof s&&(c=s,s=arguments[1]||{},l=2),"object"==typeof s||x.isFunction(s)||(s={}),u===l&&(s=this,--l);u>l;l++)if(null!=(o=arguments[l]))for(i in o)e=s[i],r=o[i],s!==r&&(c&&r&&(x.isPlainObject(r)||(n=x.isArray(r)))?(n?(n=!1,a=e&&x.isArray(e)?e:[]):a=e&&x.isPlainObject(e)?e:{},s[i]=x.extend(c,a,r)):r!==t&&(s[i]=r));return s},x.extend({expando:"jQuery"+(f+Math.random()).replace(/\D/g,""),noConflict:function(t){return e.$===x&&(e.$=u),t&&e.jQuery===x&&(e.jQuery=l),x},isReady:!1,readyWait:1,holdReady:function(e){e?x.readyWait++:x.ready(!0)},ready:function(e){if(e===!0?!--x.readyWait:!x.isReady){if(!a.body)return setTimeout(x.ready);x.isReady=!0,e!==!0&&--x.readyWait>0||(n.resolveWith(a,[x]),x.fn.trigger&&x(a).trigger("ready").off("ready"))}},isFunction:function(e){return"function"===x.type(e)},isArray:Array.isArray||function(e){return"array"===x.type(e)},isWindow:function(e){return null!=e&&e==e.window},isNumeric:function(e){return!isNaN(parseFloat(e))&&isFinite(e)},type:function(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?c[y.call(e)]||"object":typeof e},isPlainObject:function(e){var n;if(!e||"object"!==x.type(e)||e.nodeType||x.isWindow(e))return!1;try{if(e.constructor&&!v.call(e,"constructor")&&!v.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(r){return!1}if(x.support.ownLast)for(n in e)return v.call(e,n);for(n in e);return n===t||v.call(e,n)},isEmptyObject:function(e){var t;for(t in e)return!1;return!0},error:function(e){throw Error(e)},parseHTML:function(e,t,n){if(!e||"string"!=typeof e)return null;"boolean"==typeof t&&(n=t,t=!1),t=t||a;var r=k.exec(e),i=!n&&[];return r?[t.createElement(r[1])]:(r=x.buildFragment([e],t,i),i&&x(i).remove(),x.merge([],r.childNodes))},parseJSON:function(n){return e.JSON&&e.JSON.parse?e.JSON.parse(n):null===n?n:"string"==typeof n&&(n=x.trim(n),n&&E.test(n.replace(A,"@").replace(j,"]").replace(S,"")))?Function("return "+n)():(x.error("Invalid JSON: "+n),t)},parseXML:function(n){var r,i;if(!n||"string"!=typeof n)return null;try{e.DOMParser?(i=new DOMParser,r=i.parseFromString(n,"text/xml")):(r=new ActiveXObject("Microsoft.XMLDOM"),r.async="false",r.loadXML(n))}catch(o){r=t}return r&&r.documentElement&&!r.getElementsByTagName("parsererror").length||x.error("Invalid XML: "+n),r},noop:function(){},globalEval:function(t){t&&x.trim(t)&&(e.execScript||function(t){e.eval.call(e,t)})(t)},camelCase:function(e){return e.replace(D,"ms-").replace(L,H)},nodeName:function(e,t){return e.nodeName&&e.nodeName.toLowerCase()===t.toLowerCase()},each:function(e,t,n){var r,i=0,o=e.length,a=M(e);if(n){if(a){for(;o>i;i++)if(r=t.apply(e[i],n),r===!1)break}else for(i in e)if(r=t.apply(e[i],n),r===!1)break}else if(a){for(;o>i;i++)if(r=t.call(e[i],i,e[i]),r===!1)break}else for(i in e)if(r=t.call(e[i],i,e[i]),r===!1)break;return e},trim:b&&!b.call("\ufeff\u00a0")?function(e){return null==e?"":b.call(e)}:function(e){return null==e?"":(e+"").replace(C,"")},makeArray:function(e,t){var n=t||[];return null!=e&&(M(Object(e))?x.merge(n,"string"==typeof e?[e]:e):h.call(n,e)),n},inArray:function(e,t,n){var r;if(t){if(m)return m.call(t,e,n);for(r=t.length,n=n?0>n?Math.max(0,r+n):n:0;r>n;n++)if(n in t&&t[n]===e)return n}return-1},merge:function(e,n){var r=n.length,i=e.length,o=0;if("number"==typeof r)for(;r>o;o++)e[i++]=n[o];else while(n[o]!==t)e[i++]=n[o++];return e.length=i,e},grep:function(e,t,n){var r,i=[],o=0,a=e.length;for(n=!!n;a>o;o++)r=!!t(e[o],o),n!==r&&i.push(e[o]);return i},map:function(e,t,n){var r,i=0,o=e.length,a=M(e),s=[];if(a)for(;o>i;i++)r=t(e[i],i,n),null!=r&&(s[s.length]=r);else for(i in e)r=t(e[i],i,n),null!=r&&(s[s.length]=r);return d.apply([],s)},guid:1,proxy:function(e,n){var r,i,o;return"string"==typeof n&&(o=e[n],n=e,e=o),x.isFunction(e)?(r=g.call(arguments,2),i=function(){return e.apply(n||this,r.concat(g.call(arguments)))},i.guid=e.guid=e.guid||x.guid++,i):t},access:function(e,n,r,i,o,a,s){var l=0,u=e.length,c=null==r;if("object"===x.type(r)){o=!0;for(l in r)x.access(e,n,l,r[l],!0,a,s)}else if(i!==t&&(o=!0,x.isFunction(i)||(s=!0),c&&(s?(n.call(e,i),n=null):(c=n,n=function(e,t,n){return c.call(x(e),n)})),n))for(;u>l;l++)n(e[l],r,s?i:i.call(e[l],l,n(e[l],r)));return o?e:c?n.call(e):u?n(e[0],r):a},now:function(){return(new Date).getTime()},swap:function(e,t,n,r){var i,o,a={};for(o in t)a[o]=e.style[o],e.style[o]=t[o];i=n.apply(e,r||[]);for(o in t)e.style[o]=a[o];return i}}),x.ready.promise=function(t){if(!n)if(n=x.Deferred(),"complete"===a.readyState)setTimeout(x.ready);else if(a.addEventListener)a.addEventListener("DOMContentLoaded",q,!1),e.addEventListener("load",q,!1);else{a.attachEvent("onreadystatechange",q),e.attachEvent("onload",q);var r=!1;try{r=null==e.frameElement&&a.documentElement}catch(i){}r&&r.doScroll&&function o(){if(!x.isReady){try{r.doScroll("left")}catch(e){return setTimeout(o,50)}_(),x.ready()}}()}return n.promise(t)},x.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(e,t){c["[object "+t+"]"]=t.toLowerCase()});function M(e){var t=e.length,n=x.type(e);return x.isWindow(e)?!1:1===e.nodeType&&t?!0:"array"===n||"function"!==n&&(0===t||"number"==typeof t&&t>0&&t-1 in e)}r=x(a),function(e,t){var n,r,i,o,a,s,l,u,c,p,f,d,h,g,m,y,v,b="sizzle"+-new Date,w=e.document,T=0,C=0,N=st(),k=st(),E=st(),S=!1,A=function(e,t){return e===t?(S=!0,0):0},j=typeof t,D=1<<31,L={}.hasOwnProperty,H=[],q=H.pop,_=H.push,M=H.push,O=H.slice,F=H.indexOf||function(e){var t=0,n=this.length;for(;n>t;t++)if(this[t]===e)return t;return-1},B="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",P="[\\x20\\t\\r\\n\\f]",R="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",W=R.replace("w","w#"),$="\\["+P+"*("+R+")"+P+"*(?:([*^$|!~]?=)"+P+"*(?:(['\"])((?:\\\\.|[^\\\\])*?)\\3|("+W+")|)|)"+P+"*\\]",I=":("+R+")(?:\\(((['\"])((?:\\\\.|[^\\\\])*?)\\3|((?:\\\\.|[^\\\\()[\\]]|"+$.replace(3,8)+")*)|.*)\\)|)",z=RegExp("^"+P+"+|((?:^|[^\\\\])(?:\\\\.)*)"+P+"+$","g"),X=RegExp("^"+P+"*,"+P+"*"),U=RegExp("^"+P+"*([>+~]|"+P+")"+P+"*"),V=RegExp(P+"*[+~]"),Y=RegExp("="+P+"*([^\\]'\"]*)"+P+"*\\]","g"),J=RegExp(I),G=RegExp("^"+W+"$"),Q={ID:RegExp("^#("+R+")"),CLASS:RegExp("^\\.("+R+")"),TAG:RegExp("^("+R.replace("w","w*")+")"),ATTR:RegExp("^"+$),PSEUDO:RegExp("^"+I),CHILD:RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+P+"*(even|odd|(([+-]|)(\\d*)n|)"+P+"*(?:([+-]|)"+P+"*(\\d+)|))"+P+"*\\)|)","i"),bool:RegExp("^(?:"+B+")$","i"),needsContext:RegExp("^"+P+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+P+"*((?:-\\d)?\\d*)"+P+"*\\)|)(?=[^-]|$)","i")},K=/^[^{]+\{\s*\[native \w/,Z=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,et=/^(?:input|select|textarea|button)$/i,tt=/^h\d$/i,nt=/'|\\/g,rt=RegExp("\\\\([\\da-f]{1,6}"+P+"?|("+P+")|.)","ig"),it=function(e,t,n){var r="0x"+t-65536;return r!==r||n?t:0>r?String.fromCharCode(r+65536):String.fromCharCode(55296|r>>10,56320|1023&r)};try{M.apply(H=O.call(w.childNodes),w.childNodes),H[w.childNodes.length].nodeType}catch(ot){M={apply:H.length?function(e,t){_.apply(e,O.call(t))}:function(e,t){var n=e.length,r=0;while(e[n++]=t[r++]);e.length=n-1}}}function at(e,t,n,i){var o,a,s,l,u,c,d,m,y,x;if((t?t.ownerDocument||t:w)!==f&&p(t),t=t||f,n=n||[],!e||"string"!=typeof e)return n;if(1!==(l=t.nodeType)&&9!==l)return[];if(h&&!i){if(o=Z.exec(e))if(s=o[1]){if(9===l){if(a=t.getElementById(s),!a||!a.parentNode)return n;if(a.id===s)return n.push(a),n}else if(t.ownerDocument&&(a=t.ownerDocument.getElementById(s))&&v(t,a)&&a.id===s)return n.push(a),n}else{if(o[2])return M.apply(n,t.getElementsByTagName(e)),n;if((s=o[3])&&r.getElementsByClassName&&t.getElementsByClassName)return M.apply(n,t.getElementsByClassName(s)),n}if(r.qsa&&(!g||!g.test(e))){if(m=d=b,y=t,x=9===l&&e,1===l&&"object"!==t.nodeName.toLowerCase()){c=mt(e),(d=t.getAttribute("id"))?m=d.replace(nt,"\\$&"):t.setAttribute("id",m),m="[id='"+m+"'] ",u=c.length;while(u--)c[u]=m+yt(c[u]);y=V.test(e)&&t.parentNode||t,x=c.join(",")}if(x)try{return M.apply(n,y.querySelectorAll(x)),n}catch(T){}finally{d||t.removeAttribute("id")}}}return kt(e.replace(z,"$1"),t,n,i)}function st(){var e=[];function t(n,r){return e.push(n+=" ")>o.cacheLength&&delete t[e.shift()],t[n]=r}return t}function lt(e){return e[b]=!0,e}function ut(e){var t=f.createElement("div");try{return!!e(t)}catch(n){return!1}finally{t.parentNode&&t.parentNode.removeChild(t),t=null}}function ct(e,t){var n=e.split("|"),r=e.length;while(r--)o.attrHandle[n[r]]=t}function pt(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&(~t.sourceIndex||D)-(~e.sourceIndex||D);if(r)return r;if(n)while(n=n.nextSibling)if(n===t)return-1;return e?1:-1}function ft(e){return function(t){var n=t.nodeName.toLowerCase();return"input"===n&&t.type===e}}function dt(e){return function(t){var n=t.nodeName.toLowerCase();return("input"===n||"button"===n)&&t.type===e}}function ht(e){return lt(function(t){return t=+t,lt(function(n,r){var i,o=e([],n.length,t),a=o.length;while(a--)n[i=o[a]]&&(n[i]=!(r[i]=n[i]))})})}s=at.isXML=function(e){var t=e&&(e.ownerDocument||e).documentElement;return t?"HTML"!==t.nodeName:!1},r=at.support={},p=at.setDocument=function(e){var n=e?e.ownerDocument||e:w,i=n.defaultView;return n!==f&&9===n.nodeType&&n.documentElement?(f=n,d=n.documentElement,h=!s(n),i&&i.attachEvent&&i!==i.top&&i.attachEvent("onbeforeunload",function(){p()}),r.attributes=ut(function(e){return e.className="i",!e.getAttribute("className")}),r.getElementsByTagName=ut(function(e){return e.appendChild(n.createComment("")),!e.getElementsByTagName("*").length}),r.getElementsByClassName=ut(function(e){return e.innerHTML="<div class='a'></div><div class='a i'></div>",e.firstChild.className="i",2===e.getElementsByClassName("i").length}),r.getById=ut(function(e){return d.appendChild(e).id=b,!n.getElementsByName||!n.getElementsByName(b).length}),r.getById?(o.find.ID=function(e,t){if(typeof t.getElementById!==j&&h){var n=t.getElementById(e);return n&&n.parentNode?[n]:[]}},o.filter.ID=function(e){var t=e.replace(rt,it);return function(e){return e.getAttribute("id")===t}}):(delete o.find.ID,o.filter.ID=function(e){var t=e.replace(rt,it);return function(e){var n=typeof e.getAttributeNode!==j&&e.getAttributeNode("id");return n&&n.value===t}}),o.find.TAG=r.getElementsByTagName?function(e,n){return typeof n.getElementsByTagName!==j?n.getElementsByTagName(e):t}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){while(n=o[i++])1===n.nodeType&&r.push(n);return r}return o},o.find.CLASS=r.getElementsByClassName&&function(e,n){return typeof n.getElementsByClassName!==j&&h?n.getElementsByClassName(e):t},m=[],g=[],(r.qsa=K.test(n.querySelectorAll))&&(ut(function(e){e.innerHTML="<select><option selected=''></option></select>",e.querySelectorAll("[selected]").length||g.push("\\["+P+"*(?:value|"+B+")"),e.querySelectorAll(":checked").length||g.push(":checked")}),ut(function(e){var t=n.createElement("input");t.setAttribute("type","hidden"),e.appendChild(t).setAttribute("t",""),e.querySelectorAll("[t^='']").length&&g.push("[*^$]="+P+"*(?:''|\"\")"),e.querySelectorAll(":enabled").length||g.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),g.push(",.*:")})),(r.matchesSelector=K.test(y=d.webkitMatchesSelector||d.mozMatchesSelector||d.oMatchesSelector||d.msMatchesSelector))&&ut(function(e){r.disconnectedMatch=y.call(e,"div"),y.call(e,"[s!='']:x"),m.push("!=",I)}),g=g.length&&RegExp(g.join("|")),m=m.length&&RegExp(m.join("|")),v=K.test(d.contains)||d.compareDocumentPosition?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)while(t=t.parentNode)if(t===e)return!0;return!1},A=d.compareDocumentPosition?function(e,t){if(e===t)return S=!0,0;var i=t.compareDocumentPosition&&e.compareDocumentPosition&&e.compareDocumentPosition(t);return i?1&i||!r.sortDetached&&t.compareDocumentPosition(e)===i?e===n||v(w,e)?-1:t===n||v(w,t)?1:c?F.call(c,e)-F.call(c,t):0:4&i?-1:1:e.compareDocumentPosition?-1:1}:function(e,t){var r,i=0,o=e.parentNode,a=t.parentNode,s=[e],l=[t];if(e===t)return S=!0,0;if(!o||!a)return e===n?-1:t===n?1:o?-1:a?1:c?F.call(c,e)-F.call(c,t):0;if(o===a)return pt(e,t);r=e;while(r=r.parentNode)s.unshift(r);r=t;while(r=r.parentNode)l.unshift(r);while(s[i]===l[i])i++;return i?pt(s[i],l[i]):s[i]===w?-1:l[i]===w?1:0},n):f},at.matches=function(e,t){return at(e,null,null,t)},at.matchesSelector=function(e,t){if((e.ownerDocument||e)!==f&&p(e),t=t.replace(Y,"='$1']"),!(!r.matchesSelector||!h||m&&m.test(t)||g&&g.test(t)))try{var n=y.call(e,t);if(n||r.disconnectedMatch||e.document&&11!==e.document.nodeType)return n}catch(i){}return at(t,f,null,[e]).length>0},at.contains=function(e,t){return(e.ownerDocument||e)!==f&&p(e),v(e,t)},at.attr=function(e,n){(e.ownerDocument||e)!==f&&p(e);var i=o.attrHandle[n.toLowerCase()],a=i&&L.call(o.attrHandle,n.toLowerCase())?i(e,n,!h):t;return a===t?r.attributes||!h?e.getAttribute(n):(a=e.getAttributeNode(n))&&a.specified?a.value:null:a},at.error=function(e){throw Error("Syntax error, unrecognized expression: "+e)},at.uniqueSort=function(e){var t,n=[],i=0,o=0;if(S=!r.detectDuplicates,c=!r.sortStable&&e.slice(0),e.sort(A),S){while(t=e[o++])t===e[o]&&(i=n.push(o));while(i--)e.splice(n[i],1)}return e},a=at.getText=function(e){var t,n="",r=0,i=e.nodeType;if(i){if(1===i||9===i||11===i){if("string"==typeof e.textContent)return e.textContent;for(e=e.firstChild;e;e=e.nextSibling)n+=a(e)}else if(3===i||4===i)return e.nodeValue}else for(;t=e[r];r++)n+=a(t);return n},o=at.selectors={cacheLength:50,createPseudo:lt,match:Q,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(rt,it),e[3]=(e[4]||e[5]||"").replace(rt,it),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||at.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&at.error(e[0]),e},PSEUDO:function(e){var n,r=!e[5]&&e[2];return Q.CHILD.test(e[0])?null:(e[3]&&e[4]!==t?e[2]=e[4]:r&&J.test(r)&&(n=mt(r,!0))&&(n=r.indexOf(")",r.length-n)-r.length)&&(e[0]=e[0].slice(0,n),e[2]=r.slice(0,n)),e.slice(0,3))}},filter:{TAG:function(e){var t=e.replace(rt,it).toLowerCase();return"*"===e?function(){return!0}:function(e){return e.nodeName&&e.nodeName.toLowerCase()===t}},CLASS:function(e){var t=N[e+" "];return t||(t=RegExp("(^|"+P+")"+e+"("+P+"|$)"))&&N(e,function(e){return t.test("string"==typeof e.className&&e.className||typeof e.getAttribute!==j&&e.getAttribute("class")||"")})},ATTR:function(e,t,n){return function(r){var i=at.attr(r,e);return null==i?"!="===t:t?(i+="","="===t?i===n:"!="===t?i!==n:"^="===t?n&&0===i.indexOf(n):"*="===t?n&&i.indexOf(n)>-1:"$="===t?n&&i.slice(-n.length)===n:"~="===t?(" "+i+" ").indexOf(n)>-1:"|="===t?i===n||i.slice(0,n.length+1)===n+"-":!1):!0}},CHILD:function(e,t,n,r,i){var o="nth"!==e.slice(0,3),a="last"!==e.slice(-4),s="of-type"===t;return 1===r&&0===i?function(e){return!!e.parentNode}:function(t,n,l){var u,c,p,f,d,h,g=o!==a?"nextSibling":"previousSibling",m=t.parentNode,y=s&&t.nodeName.toLowerCase(),v=!l&&!s;if(m){if(o){while(g){p=t;while(p=p[g])if(s?p.nodeName.toLowerCase()===y:1===p.nodeType)return!1;h=g="only"===e&&!h&&"nextSibling"}return!0}if(h=[a?m.firstChild:m.lastChild],a&&v){c=m[b]||(m[b]={}),u=c[e]||[],d=u[0]===T&&u[1],f=u[0]===T&&u[2],p=d&&m.childNodes[d];while(p=++d&&p&&p[g]||(f=d=0)||h.pop())if(1===p.nodeType&&++f&&p===t){c[e]=[T,d,f];break}}else if(v&&(u=(t[b]||(t[b]={}))[e])&&u[0]===T)f=u[1];else while(p=++d&&p&&p[g]||(f=d=0)||h.pop())if((s?p.nodeName.toLowerCase()===y:1===p.nodeType)&&++f&&(v&&((p[b]||(p[b]={}))[e]=[T,f]),p===t))break;return f-=i,f===r||0===f%r&&f/r>=0}}},PSEUDO:function(e,t){var n,r=o.pseudos[e]||o.setFilters[e.toLowerCase()]||at.error("unsupported pseudo: "+e);return r[b]?r(t):r.length>1?(n=[e,e,"",t],o.setFilters.hasOwnProperty(e.toLowerCase())?lt(function(e,n){var i,o=r(e,t),a=o.length;while(a--)i=F.call(e,o[a]),e[i]=!(n[i]=o[a])}):function(e){return r(e,0,n)}):r}},pseudos:{not:lt(function(e){var t=[],n=[],r=l(e.replace(z,"$1"));return r[b]?lt(function(e,t,n,i){var o,a=r(e,null,i,[]),s=e.length;while(s--)(o=a[s])&&(e[s]=!(t[s]=o))}):function(e,i,o){return t[0]=e,r(t,null,o,n),!n.pop()}}),has:lt(function(e){return function(t){return at(e,t).length>0}}),contains:lt(function(e){return function(t){return(t.textContent||t.innerText||a(t)).indexOf(e)>-1}}),lang:lt(function(e){return G.test(e||"")||at.error("unsupported lang: "+e),e=e.replace(rt,it).toLowerCase(),function(t){var n;do if(n=h?t.lang:t.getAttribute("xml:lang")||t.getAttribute("lang"))return n=n.toLowerCase(),n===e||0===n.indexOf(e+"-");while((t=t.parentNode)&&1===t.nodeType);return!1}}),target:function(t){var n=e.location&&e.location.hash;return n&&n.slice(1)===t.id},root:function(e){return e===d},focus:function(e){return e===f.activeElement&&(!f.hasFocus||f.hasFocus())&&!!(e.type||e.href||~e.tabIndex)},enabled:function(e){return e.disabled===!1},disabled:function(e){return e.disabled===!0},checked:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&!!e.checked||"option"===t&&!!e.selected},selected:function(e){return e.parentNode&&e.parentNode.selectedIndex,e.selected===!0},empty:function(e){for(e=e.firstChild;e;e=e.nextSibling)if(e.nodeName>"@"||3===e.nodeType||4===e.nodeType)return!1;return!0},parent:function(e){return!o.pseudos.empty(e)},header:function(e){return tt.test(e.nodeName)},input:function(e){return et.test(e.nodeName)},button:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&"button"===e.type||"button"===t},text:function(e){var t;return"input"===e.nodeName.toLowerCase()&&"text"===e.type&&(null==(t=e.getAttribute("type"))||t.toLowerCase()===e.type)},first:ht(function(){return[0]}),last:ht(function(e,t){return[t-1]}),eq:ht(function(e,t,n){return[0>n?n+t:n]}),even:ht(function(e,t){var n=0;for(;t>n;n+=2)e.push(n);return e}),odd:ht(function(e,t){var n=1;for(;t>n;n+=2)e.push(n);return e}),lt:ht(function(e,t,n){var r=0>n?n+t:n;for(;--r>=0;)e.push(r);return e}),gt:ht(function(e,t,n){var r=0>n?n+t:n;for(;t>++r;)e.push(r);return e})}},o.pseudos.nth=o.pseudos.eq;for(n in{radio:!0,checkbox:!0,file:!0,password:!0,image:!0})o.pseudos[n]=ft(n);for(n in{submit:!0,reset:!0})o.pseudos[n]=dt(n);function gt(){}gt.prototype=o.filters=o.pseudos,o.setFilters=new gt;function mt(e,t){var n,r,i,a,s,l,u,c=k[e+" "];if(c)return t?0:c.slice(0);s=e,l=[],u=o.preFilter;while(s){(!n||(r=X.exec(s)))&&(r&&(s=s.slice(r[0].length)||s),l.push(i=[])),n=!1,(r=U.exec(s))&&(n=r.shift(),i.push({value:n,type:r[0].replace(z," ")}),s=s.slice(n.length));for(a in o.filter)!(r=Q[a].exec(s))||u[a]&&!(r=u[a](r))||(n=r.shift(),i.push({value:n,type:a,matches:r}),s=s.slice(n.length));if(!n)break}return t?s.length:s?at.error(e):k(e,l).slice(0)}function yt(e){var t=0,n=e.length,r="";for(;n>t;t++)r+=e[t].value;return r}function vt(e,t,n){var r=t.dir,o=n&&"parentNode"===r,a=C++;return t.first?function(t,n,i){while(t=t[r])if(1===t.nodeType||o)return e(t,n,i)}:function(t,n,s){var l,u,c,p=T+" "+a;if(s){while(t=t[r])if((1===t.nodeType||o)&&e(t,n,s))return!0}else while(t=t[r])if(1===t.nodeType||o)if(c=t[b]||(t[b]={}),(u=c[r])&&u[0]===p){if((l=u[1])===!0||l===i)return l===!0}else if(u=c[r]=[p],u[1]=e(t,n,s)||i,u[1]===!0)return!0}}function bt(e){return e.length>1?function(t,n,r){var i=e.length;while(i--)if(!e[i](t,n,r))return!1;return!0}:e[0]}function xt(e,t,n,r,i){var o,a=[],s=0,l=e.length,u=null!=t;for(;l>s;s++)(o=e[s])&&(!n||n(o,r,i))&&(a.push(o),u&&t.push(s));return a}function wt(e,t,n,r,i,o){return r&&!r[b]&&(r=wt(r)),i&&!i[b]&&(i=wt(i,o)),lt(function(o,a,s,l){var u,c,p,f=[],d=[],h=a.length,g=o||Nt(t||"*",s.nodeType?[s]:s,[]),m=!e||!o&&t?g:xt(g,f,e,s,l),y=n?i||(o?e:h||r)?[]:a:m;if(n&&n(m,y,s,l),r){u=xt(y,d),r(u,[],s,l),c=u.length;while(c--)(p=u[c])&&(y[d[c]]=!(m[d[c]]=p))}if(o){if(i||e){if(i){u=[],c=y.length;while(c--)(p=y[c])&&u.push(m[c]=p);i(null,y=[],u,l)}c=y.length;while(c--)(p=y[c])&&(u=i?F.call(o,p):f[c])>-1&&(o[u]=!(a[u]=p))}}else y=xt(y===a?y.splice(h,y.length):y),i?i(null,a,y,l):M.apply(a,y)})}function Tt(e){var t,n,r,i=e.length,a=o.relative[e[0].type],s=a||o.relative[" "],l=a?1:0,c=vt(function(e){return e===t},s,!0),p=vt(function(e){return F.call(t,e)>-1},s,!0),f=[function(e,n,r){return!a&&(r||n!==u)||((t=n).nodeType?c(e,n,r):p(e,n,r))}];for(;i>l;l++)if(n=o.relative[e[l].type])f=[vt(bt(f),n)];else{if(n=o.filter[e[l].type].apply(null,e[l].matches),n[b]){for(r=++l;i>r;r++)if(o.relative[e[r].type])break;return wt(l>1&&bt(f),l>1&&yt(e.slice(0,l-1).concat({value:" "===e[l-2].type?"*":""})).replace(z,"$1"),n,r>l&&Tt(e.slice(l,r)),i>r&&Tt(e=e.slice(r)),i>r&&yt(e))}f.push(n)}return bt(f)}function Ct(e,t){var n=0,r=t.length>0,a=e.length>0,s=function(s,l,c,p,d){var h,g,m,y=[],v=0,b="0",x=s&&[],w=null!=d,C=u,N=s||a&&o.find.TAG("*",d&&l.parentNode||l),k=T+=null==C?1:Math.random()||.1;for(w&&(u=l!==f&&l,i=n);null!=(h=N[b]);b++){if(a&&h){g=0;while(m=e[g++])if(m(h,l,c)){p.push(h);break}w&&(T=k,i=++n)}r&&((h=!m&&h)&&v--,s&&x.push(h))}if(v+=b,r&&b!==v){g=0;while(m=t[g++])m(x,y,l,c);if(s){if(v>0)while(b--)x[b]||y[b]||(y[b]=q.call(p));y=xt(y)}M.apply(p,y),w&&!s&&y.length>0&&v+t.length>1&&at.uniqueSort(p)}return w&&(T=k,u=C),x};return r?lt(s):s}l=at.compile=function(e,t){var n,r=[],i=[],o=E[e+" "];if(!o){t||(t=mt(e)),n=t.length;while(n--)o=Tt(t[n]),o[b]?r.push(o):i.push(o);o=E(e,Ct(i,r))}return o};function Nt(e,t,n){var r=0,i=t.length;for(;i>r;r++)at(e,t[r],n);return n}function kt(e,t,n,i){var a,s,u,c,p,f=mt(e);if(!i&&1===f.length){if(s=f[0]=f[0].slice(0),s.length>2&&"ID"===(u=s[0]).type&&r.getById&&9===t.nodeType&&h&&o.relative[s[1].type]){if(t=(o.find.ID(u.matches[0].replace(rt,it),t)||[])[0],!t)return n;e=e.slice(s.shift().value.length)}a=Q.needsContext.test(e)?0:s.length;while(a--){if(u=s[a],o.relative[c=u.type])break;if((p=o.find[c])&&(i=p(u.matches[0].replace(rt,it),V.test(s[0].type)&&t.parentNode||t))){if(s.splice(a,1),e=i.length&&yt(s),!e)return M.apply(n,i),n;break}}}return l(e,f)(i,t,!h,n,V.test(e)),n}r.sortStable=b.split("").sort(A).join("")===b,r.detectDuplicates=S,p(),r.sortDetached=ut(function(e){return 1&e.compareDocumentPosition(f.createElement("div"))}),ut(function(e){return e.innerHTML="<a href='#'></a>","#"===e.firstChild.getAttribute("href")})||ct("type|href|height|width",function(e,n,r){return r?t:e.getAttribute(n,"type"===n.toLowerCase()?1:2)}),r.attributes&&ut(function(e){return e.innerHTML="<input/>",e.firstChild.setAttribute("value",""),""===e.firstChild.getAttribute("value")})||ct("value",function(e,n,r){return r||"input"!==e.nodeName.toLowerCase()?t:e.defaultValue}),ut(function(e){return null==e.getAttribute("disabled")})||ct(B,function(e,n,r){var i;return r?t:(i=e.getAttributeNode(n))&&i.specified?i.value:e[n]===!0?n.toLowerCase():null}),x.find=at,x.expr=at.selectors,x.expr[":"]=x.expr.pseudos,x.unique=at.uniqueSort,x.text=at.getText,x.isXMLDoc=at.isXML,x.contains=at.contains}(e);var O={};function F(e){var t=O[e]={};return x.each(e.match(T)||[],function(e,n){t[n]=!0}),t}x.Callbacks=function(e){e="string"==typeof e?O[e]||F(e):x.extend({},e);var n,r,i,o,a,s,l=[],u=!e.once&&[],c=function(t){for(r=e.memory&&t,i=!0,a=s||0,s=0,o=l.length,n=!0;l&&o>a;a++)if(l[a].apply(t[0],t[1])===!1&&e.stopOnFalse){r=!1;break}n=!1,l&&(u?u.length&&c(u.shift()):r?l=[]:p.disable())},p={add:function(){if(l){var t=l.length;(function i(t){x.each(t,function(t,n){var r=x.type(n);"function"===r?e.unique&&p.has(n)||l.push(n):n&&n.length&&"string"!==r&&i(n)})})(arguments),n?o=l.length:r&&(s=t,c(r))}return this},remove:function(){return l&&x.each(arguments,function(e,t){var r;while((r=x.inArray(t,l,r))>-1)l.splice(r,1),n&&(o>=r&&o--,a>=r&&a--)}),this},has:function(e){return e?x.inArray(e,l)>-1:!(!l||!l.length)},empty:function(){return l=[],o=0,this},disable:function(){return l=u=r=t,this},disabled:function(){return!l},lock:function(){return u=t,r||p.disable(),this},locked:function(){return!u},fireWith:function(e,t){return!l||i&&!u||(t=t||[],t=[e,t.slice?t.slice():t],n?u.push(t):c(t)),this},fire:function(){return p.fireWith(this,arguments),this},fired:function(){return!!i}};return p},x.extend({Deferred:function(e){var t=[["resolve","done",x.Callbacks("once memory"),"resolved"],["reject","fail",x.Callbacks("once memory"),"rejected"],["notify","progress",x.Callbacks("memory")]],n="pending",r={state:function(){return n},always:function(){return i.done(arguments).fail(arguments),this},then:function(){var e=arguments;return x.Deferred(function(n){x.each(t,function(t,o){var a=o[0],s=x.isFunction(e[t])&&e[t];i[o[1]](function(){var e=s&&s.apply(this,arguments);e&&x.isFunction(e.promise)?e.promise().done(n.resolve).fail(n.reject).progress(n.notify):n[a+"With"](this===r?n.promise():this,s?[e]:arguments)})}),e=null}).promise()},promise:function(e){return null!=e?x.extend(e,r):r}},i={};return r.pipe=r.then,x.each(t,function(e,o){var a=o[2],s=o[3];r[o[1]]=a.add,s&&a.add(function(){n=s},t[1^e][2].disable,t[2][2].lock),i[o[0]]=function(){return i[o[0]+"With"](this===i?r:this,arguments),this},i[o[0]+"With"]=a.fireWith}),r.promise(i),e&&e.call(i,i),i},when:function(e){var t=0,n=g.call(arguments),r=n.length,i=1!==r||e&&x.isFunction(e.promise)?r:0,o=1===i?e:x.Deferred(),a=function(e,t,n){return function(r){t[e]=this,n[e]=arguments.length>1?g.call(arguments):r,n===s?o.notifyWith(t,n):--i||o.resolveWith(t,n)}},s,l,u;if(r>1)for(s=Array(r),l=Array(r),u=Array(r);r>t;t++)n[t]&&x.isFunction(n[t].promise)?n[t].promise().done(a(t,u,n)).fail(o.reject).progress(a(t,l,s)):--i;return i||o.resolveWith(u,n),o.promise()}}),x.support=function(t){var n,r,o,s,l,u,c,p,f,d=a.createElement("div");if(d.setAttribute("className","t"),d.innerHTML=" <link/><table></table><a href='/a'>a</a><input type='checkbox'/>",n=d.getElementsByTagName("*")||[],r=d.getElementsByTagName("a")[0],!r||!r.style||!n.length)return t;s=a.createElement("select"),u=s.appendChild(a.createElement("option")),o=d.getElementsByTagName("input")[0],r.style.cssText="top:1px;float:left;opacity:.5",t.getSetAttribute="t"!==d.className,t.leadingWhitespace=3===d.firstChild.nodeType,t.tbody=!d.getElementsByTagName("tbody").length,t.htmlSerialize=!!d.getElementsByTagName("link").length,t.style=/top/.test(r.getAttribute("style")),t.hrefNormalized="/a"===r.getAttribute("href"),t.opacity=/^0.5/.test(r.style.opacity),t.cssFloat=!!r.style.cssFloat,t.checkOn=!!o.value,t.optSelected=u.selected,t.enctype=!!a.createElement("form").enctype,t.html5Clone="<:nav></:nav>"!==a.createElement("nav").cloneNode(!0).outerHTML,t.inlineBlockNeedsLayout=!1,t.shrinkWrapBlocks=!1,t.pixelPosition=!1,t.deleteExpando=!0,t.noCloneEvent=!0,t.reliableMarginRight=!0,t.boxSizingReliable=!0,o.checked=!0,t.noCloneChecked=o.cloneNode(!0).checked,s.disabled=!0,t.optDisabled=!u.disabled;try{delete d.test}catch(h){t.deleteExpando=!1}o=a.createElement("input"),o.setAttribute("value",""),t.input=""===o.getAttribute("value"),o.value="t",o.setAttribute("type","radio"),t.radioValue="t"===o.value,o.setAttribute("checked","t"),o.setAttribute("name","t"),l=a.createDocumentFragment(),l.appendChild(o),t.appendChecked=o.checked,t.checkClone=l.cloneNode(!0).cloneNode(!0).lastChild.checked,d.attachEvent&&(d.attachEvent("onclick",function(){t.noCloneEvent=!1}),d.cloneNode(!0).click());for(f in{submit:!0,change:!0,focusin:!0})d.setAttribute(c="on"+f,"t"),t[f+"Bubbles"]=c in e||d.attributes[c].expando===!1;d.style.backgroundClip="content-box",d.cloneNode(!0).style.backgroundClip="",t.clearCloneStyle="content-box"===d.style.backgroundClip;for(f in x(t))break;return t.ownLast="0"!==f,x(function(){var n,r,o,s="padding:0;margin:0;border:0;display:block;box-sizing:content-box;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;",l=a.getElementsByTagName("body")[0];l&&(n=a.createElement("div"),n.style.cssText="border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px",l.appendChild(n).appendChild(d),d.innerHTML="<table><tr><td></td><td>t</td></tr></table>",o=d.getElementsByTagName("td"),o[0].style.cssText="padding:0;margin:0;border:0;display:none",p=0===o[0].offsetHeight,o[0].style.display="",o[1].style.display="none",t.reliableHiddenOffsets=p&&0===o[0].offsetHeight,d.innerHTML="",d.style.cssText="box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%;",x.swap(l,null!=l.style.zoom?{zoom:1}:{},function(){t.boxSizing=4===d.offsetWidth}),e.getComputedStyle&&(t.pixelPosition="1%"!==(e.getComputedStyle(d,null)||{}).top,t.boxSizingReliable="4px"===(e.getComputedStyle(d,null)||{width:"4px"}).width,r=d.appendChild(a.createElement("div")),r.style.cssText=d.style.cssText=s,r.style.marginRight=r.style.width="0",d.style.width="1px",t.reliableMarginRight=!parseFloat((e.getComputedStyle(r,null)||{}).marginRight)),typeof d.style.zoom!==i&&(d.innerHTML="",d.style.cssText=s+"width:1px;padding:1px;display:inline;zoom:1",t.inlineBlockNeedsLayout=3===d.offsetWidth,d.style.display="block",d.innerHTML="<div></div>",d.firstChild.style.width="5px",t.shrinkWrapBlocks=3!==d.offsetWidth,t.inlineBlockNeedsLayout&&(l.style.zoom=1)),l.removeChild(n),n=d=o=r=null)}),n=s=l=u=r=o=null,t
+}({});var B=/(?:\{[\s\S]*\}|\[[\s\S]*\])$/,P=/([A-Z])/g;function R(e,n,r,i){if(x.acceptData(e)){var o,a,s=x.expando,l=e.nodeType,u=l?x.cache:e,c=l?e[s]:e[s]&&s;if(c&&u[c]&&(i||u[c].data)||r!==t||"string"!=typeof n)return c||(c=l?e[s]=p.pop()||x.guid++:s),u[c]||(u[c]=l?{}:{toJSON:x.noop}),("object"==typeof n||"function"==typeof n)&&(i?u[c]=x.extend(u[c],n):u[c].data=x.extend(u[c].data,n)),a=u[c],i||(a.data||(a.data={}),a=a.data),r!==t&&(a[x.camelCase(n)]=r),"string"==typeof n?(o=a[n],null==o&&(o=a[x.camelCase(n)])):o=a,o}}function W(e,t,n){if(x.acceptData(e)){var r,i,o=e.nodeType,a=o?x.cache:e,s=o?e[x.expando]:x.expando;if(a[s]){if(t&&(r=n?a[s]:a[s].data)){x.isArray(t)?t=t.concat(x.map(t,x.camelCase)):t in r?t=[t]:(t=x.camelCase(t),t=t in r?[t]:t.split(" ")),i=t.length;while(i--)delete r[t[i]];if(n?!I(r):!x.isEmptyObject(r))return}(n||(delete a[s].data,I(a[s])))&&(o?x.cleanData([e],!0):x.support.deleteExpando||a!=a.window?delete a[s]:a[s]=null)}}}x.extend({cache:{},noData:{applet:!0,embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"},hasData:function(e){return e=e.nodeType?x.cache[e[x.expando]]:e[x.expando],!!e&&!I(e)},data:function(e,t,n){return R(e,t,n)},removeData:function(e,t){return W(e,t)},_data:function(e,t,n){return R(e,t,n,!0)},_removeData:function(e,t){return W(e,t,!0)},acceptData:function(e){if(e.nodeType&&1!==e.nodeType&&9!==e.nodeType)return!1;var t=e.nodeName&&x.noData[e.nodeName.toLowerCase()];return!t||t!==!0&&e.getAttribute("classid")===t}}),x.fn.extend({data:function(e,n){var r,i,o=null,a=0,s=this[0];if(e===t){if(this.length&&(o=x.data(s),1===s.nodeType&&!x._data(s,"parsedAttrs"))){for(r=s.attributes;r.length>a;a++)i=r[a].name,0===i.indexOf("data-")&&(i=x.camelCase(i.slice(5)),$(s,i,o[i]));x._data(s,"parsedAttrs",!0)}return o}return"object"==typeof e?this.each(function(){x.data(this,e)}):arguments.length>1?this.each(function(){x.data(this,e,n)}):s?$(s,e,x.data(s,e)):null},removeData:function(e){return this.each(function(){x.removeData(this,e)})}});function $(e,n,r){if(r===t&&1===e.nodeType){var i="data-"+n.replace(P,"-$1").toLowerCase();if(r=e.getAttribute(i),"string"==typeof r){try{r="true"===r?!0:"false"===r?!1:"null"===r?null:+r+""===r?+r:B.test(r)?x.parseJSON(r):r}catch(o){}x.data(e,n,r)}else r=t}return r}function I(e){var t;for(t in e)if(("data"!==t||!x.isEmptyObject(e[t]))&&"toJSON"!==t)return!1;return!0}x.extend({queue:function(e,n,r){var i;return e?(n=(n||"fx")+"queue",i=x._data(e,n),r&&(!i||x.isArray(r)?i=x._data(e,n,x.makeArray(r)):i.push(r)),i||[]):t},dequeue:function(e,t){t=t||"fx";var n=x.queue(e,t),r=n.length,i=n.shift(),o=x._queueHooks(e,t),a=function(){x.dequeue(e,t)};"inprogress"===i&&(i=n.shift(),r--),i&&("fx"===t&&n.unshift("inprogress"),delete o.stop,i.call(e,a,o)),!r&&o&&o.empty.fire()},_queueHooks:function(e,t){var n=t+"queueHooks";return x._data(e,n)||x._data(e,n,{empty:x.Callbacks("once memory").add(function(){x._removeData(e,t+"queue"),x._removeData(e,n)})})}}),x.fn.extend({queue:function(e,n){var r=2;return"string"!=typeof e&&(n=e,e="fx",r--),r>arguments.length?x.queue(this[0],e):n===t?this:this.each(function(){var t=x.queue(this,e,n);x._queueHooks(this,e),"fx"===e&&"inprogress"!==t[0]&&x.dequeue(this,e)})},dequeue:function(e){return this.each(function(){x.dequeue(this,e)})},delay:function(e,t){return e=x.fx?x.fx.speeds[e]||e:e,t=t||"fx",this.queue(t,function(t,n){var r=setTimeout(t,e);n.stop=function(){clearTimeout(r)}})},clearQueue:function(e){return this.queue(e||"fx",[])},promise:function(e,n){var r,i=1,o=x.Deferred(),a=this,s=this.length,l=function(){--i||o.resolveWith(a,[a])};"string"!=typeof e&&(n=e,e=t),e=e||"fx";while(s--)r=x._data(a[s],e+"queueHooks"),r&&r.empty&&(i++,r.empty.add(l));return l(),o.promise(n)}});var z,X,U=/[\t\r\n\f]/g,V=/\r/g,Y=/^(?:input|select|textarea|button|object)$/i,J=/^(?:a|area)$/i,G=/^(?:checked|selected)$/i,Q=x.support.getSetAttribute,K=x.support.input;x.fn.extend({attr:function(e,t){return x.access(this,x.attr,e,t,arguments.length>1)},removeAttr:function(e){return this.each(function(){x.removeAttr(this,e)})},prop:function(e,t){return x.access(this,x.prop,e,t,arguments.length>1)},removeProp:function(e){return e=x.propFix[e]||e,this.each(function(){try{this[e]=t,delete this[e]}catch(n){}})},addClass:function(e){var t,n,r,i,o,a=0,s=this.length,l="string"==typeof e&&e;if(x.isFunction(e))return this.each(function(t){x(this).addClass(e.call(this,t,this.className))});if(l)for(t=(e||"").match(T)||[];s>a;a++)if(n=this[a],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(U," "):" ")){o=0;while(i=t[o++])0>r.indexOf(" "+i+" ")&&(r+=i+" ");n.className=x.trim(r)}return this},removeClass:function(e){var t,n,r,i,o,a=0,s=this.length,l=0===arguments.length||"string"==typeof e&&e;if(x.isFunction(e))return this.each(function(t){x(this).removeClass(e.call(this,t,this.className))});if(l)for(t=(e||"").match(T)||[];s>a;a++)if(n=this[a],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(U," "):"")){o=0;while(i=t[o++])while(r.indexOf(" "+i+" ")>=0)r=r.replace(" "+i+" "," ");n.className=e?x.trim(r):""}return this},toggleClass:function(e,t){var n=typeof e;return"boolean"==typeof t&&"string"===n?t?this.addClass(e):this.removeClass(e):x.isFunction(e)?this.each(function(n){x(this).toggleClass(e.call(this,n,this.className,t),t)}):this.each(function(){if("string"===n){var t,r=0,o=x(this),a=e.match(T)||[];while(t=a[r++])o.hasClass(t)?o.removeClass(t):o.addClass(t)}else(n===i||"boolean"===n)&&(this.className&&x._data(this,"__className__",this.className),this.className=this.className||e===!1?"":x._data(this,"__className__")||"")})},hasClass:function(e){var t=" "+e+" ",n=0,r=this.length;for(;r>n;n++)if(1===this[n].nodeType&&(" "+this[n].className+" ").replace(U," ").indexOf(t)>=0)return!0;return!1},val:function(e){var n,r,i,o=this[0];{if(arguments.length)return i=x.isFunction(e),this.each(function(n){var o;1===this.nodeType&&(o=i?e.call(this,n,x(this).val()):e,null==o?o="":"number"==typeof o?o+="":x.isArray(o)&&(o=x.map(o,function(e){return null==e?"":e+""})),r=x.valHooks[this.type]||x.valHooks[this.nodeName.toLowerCase()],r&&"set"in r&&r.set(this,o,"value")!==t||(this.value=o))});if(o)return r=x.valHooks[o.type]||x.valHooks[o.nodeName.toLowerCase()],r&&"get"in r&&(n=r.get(o,"value"))!==t?n:(n=o.value,"string"==typeof n?n.replace(V,""):null==n?"":n)}}}),x.extend({valHooks:{option:{get:function(e){var t=x.find.attr(e,"value");return null!=t?t:e.text}},select:{get:function(e){var t,n,r=e.options,i=e.selectedIndex,o="select-one"===e.type||0>i,a=o?null:[],s=o?i+1:r.length,l=0>i?s:o?i:0;for(;s>l;l++)if(n=r[l],!(!n.selected&&l!==i||(x.support.optDisabled?n.disabled:null!==n.getAttribute("disabled"))||n.parentNode.disabled&&x.nodeName(n.parentNode,"optgroup"))){if(t=x(n).val(),o)return t;a.push(t)}return a},set:function(e,t){var n,r,i=e.options,o=x.makeArray(t),a=i.length;while(a--)r=i[a],(r.selected=x.inArray(x(r).val(),o)>=0)&&(n=!0);return n||(e.selectedIndex=-1),o}}},attr:function(e,n,r){var o,a,s=e.nodeType;if(e&&3!==s&&8!==s&&2!==s)return typeof e.getAttribute===i?x.prop(e,n,r):(1===s&&x.isXMLDoc(e)||(n=n.toLowerCase(),o=x.attrHooks[n]||(x.expr.match.bool.test(n)?X:z)),r===t?o&&"get"in o&&null!==(a=o.get(e,n))?a:(a=x.find.attr(e,n),null==a?t:a):null!==r?o&&"set"in o&&(a=o.set(e,r,n))!==t?a:(e.setAttribute(n,r+""),r):(x.removeAttr(e,n),t))},removeAttr:function(e,t){var n,r,i=0,o=t&&t.match(T);if(o&&1===e.nodeType)while(n=o[i++])r=x.propFix[n]||n,x.expr.match.bool.test(n)?K&&Q||!G.test(n)?e[r]=!1:e[x.camelCase("default-"+n)]=e[r]=!1:x.attr(e,n,""),e.removeAttribute(Q?n:r)},attrHooks:{type:{set:function(e,t){if(!x.support.radioValue&&"radio"===t&&x.nodeName(e,"input")){var n=e.value;return e.setAttribute("type",t),n&&(e.value=n),t}}}},propFix:{"for":"htmlFor","class":"className"},prop:function(e,n,r){var i,o,a,s=e.nodeType;if(e&&3!==s&&8!==s&&2!==s)return a=1!==s||!x.isXMLDoc(e),a&&(n=x.propFix[n]||n,o=x.propHooks[n]),r!==t?o&&"set"in o&&(i=o.set(e,r,n))!==t?i:e[n]=r:o&&"get"in o&&null!==(i=o.get(e,n))?i:e[n]},propHooks:{tabIndex:{get:function(e){var t=x.find.attr(e,"tabindex");return t?parseInt(t,10):Y.test(e.nodeName)||J.test(e.nodeName)&&e.href?0:-1}}}}),X={set:function(e,t,n){return t===!1?x.removeAttr(e,n):K&&Q||!G.test(n)?e.setAttribute(!Q&&x.propFix[n]||n,n):e[x.camelCase("default-"+n)]=e[n]=!0,n}},x.each(x.expr.match.bool.source.match(/\w+/g),function(e,n){var r=x.expr.attrHandle[n]||x.find.attr;x.expr.attrHandle[n]=K&&Q||!G.test(n)?function(e,n,i){var o=x.expr.attrHandle[n],a=i?t:(x.expr.attrHandle[n]=t)!=r(e,n,i)?n.toLowerCase():null;return x.expr.attrHandle[n]=o,a}:function(e,n,r){return r?t:e[x.camelCase("default-"+n)]?n.toLowerCase():null}}),K&&Q||(x.attrHooks.value={set:function(e,n,r){return x.nodeName(e,"input")?(e.defaultValue=n,t):z&&z.set(e,n,r)}}),Q||(z={set:function(e,n,r){var i=e.getAttributeNode(r);return i||e.setAttributeNode(i=e.ownerDocument.createAttribute(r)),i.value=n+="","value"===r||n===e.getAttribute(r)?n:t}},x.expr.attrHandle.id=x.expr.attrHandle.name=x.expr.attrHandle.coords=function(e,n,r){var i;return r?t:(i=e.getAttributeNode(n))&&""!==i.value?i.value:null},x.valHooks.button={get:function(e,n){var r=e.getAttributeNode(n);return r&&r.specified?r.value:t},set:z.set},x.attrHooks.contenteditable={set:function(e,t,n){z.set(e,""===t?!1:t,n)}},x.each(["width","height"],function(e,n){x.attrHooks[n]={set:function(e,r){return""===r?(e.setAttribute(n,"auto"),r):t}}})),x.support.hrefNormalized||x.each(["href","src"],function(e,t){x.propHooks[t]={get:function(e){return e.getAttribute(t,4)}}}),x.support.style||(x.attrHooks.style={get:function(e){return e.style.cssText||t},set:function(e,t){return e.style.cssText=t+""}}),x.support.optSelected||(x.propHooks.selected={get:function(e){var t=e.parentNode;return t&&(t.selectedIndex,t.parentNode&&t.parentNode.selectedIndex),null}}),x.each(["tabIndex","readOnly","maxLength","cellSpacing","cellPadding","rowSpan","colSpan","useMap","frameBorder","contentEditable"],function(){x.propFix[this.toLowerCase()]=this}),x.support.enctype||(x.propFix.enctype="encoding"),x.each(["radio","checkbox"],function(){x.valHooks[this]={set:function(e,n){return x.isArray(n)?e.checked=x.inArray(x(e).val(),n)>=0:t}},x.support.checkOn||(x.valHooks[this].get=function(e){return null===e.getAttribute("value")?"on":e.value})});var Z=/^(?:input|select|textarea)$/i,et=/^key/,tt=/^(?:mouse|contextmenu)|click/,nt=/^(?:focusinfocus|focusoutblur)$/,rt=/^([^.]*)(?:\.(.+)|)$/;function it(){return!0}function ot(){return!1}function at(){try{return a.activeElement}catch(e){}}x.event={global:{},add:function(e,n,r,o,a){var s,l,u,c,p,f,d,h,g,m,y,v=x._data(e);if(v){r.handler&&(c=r,r=c.handler,a=c.selector),r.guid||(r.guid=x.guid++),(l=v.events)||(l=v.events={}),(f=v.handle)||(f=v.handle=function(e){return typeof x===i||e&&x.event.triggered===e.type?t:x.event.dispatch.apply(f.elem,arguments)},f.elem=e),n=(n||"").match(T)||[""],u=n.length;while(u--)s=rt.exec(n[u])||[],g=y=s[1],m=(s[2]||"").split(".").sort(),g&&(p=x.event.special[g]||{},g=(a?p.delegateType:p.bindType)||g,p=x.event.special[g]||{},d=x.extend({type:g,origType:y,data:o,handler:r,guid:r.guid,selector:a,needsContext:a&&x.expr.match.needsContext.test(a),namespace:m.join(".")},c),(h=l[g])||(h=l[g]=[],h.delegateCount=0,p.setup&&p.setup.call(e,o,m,f)!==!1||(e.addEventListener?e.addEventListener(g,f,!1):e.attachEvent&&e.attachEvent("on"+g,f))),p.add&&(p.add.call(e,d),d.handler.guid||(d.handler.guid=r.guid)),a?h.splice(h.delegateCount++,0,d):h.push(d),x.event.global[g]=!0);e=null}},remove:function(e,t,n,r,i){var o,a,s,l,u,c,p,f,d,h,g,m=x.hasData(e)&&x._data(e);if(m&&(c=m.events)){t=(t||"").match(T)||[""],u=t.length;while(u--)if(s=rt.exec(t[u])||[],d=g=s[1],h=(s[2]||"").split(".").sort(),d){p=x.event.special[d]||{},d=(r?p.delegateType:p.bindType)||d,f=c[d]||[],s=s[2]&&RegExp("(^|\\.)"+h.join("\\.(?:.*\\.|)")+"(\\.|$)"),l=o=f.length;while(o--)a=f[o],!i&&g!==a.origType||n&&n.guid!==a.guid||s&&!s.test(a.namespace)||r&&r!==a.selector&&("**"!==r||!a.selector)||(f.splice(o,1),a.selector&&f.delegateCount--,p.remove&&p.remove.call(e,a));l&&!f.length&&(p.teardown&&p.teardown.call(e,h,m.handle)!==!1||x.removeEvent(e,d,m.handle),delete c[d])}else for(d in c)x.event.remove(e,d+t[u],n,r,!0);x.isEmptyObject(c)&&(delete m.handle,x._removeData(e,"events"))}},trigger:function(n,r,i,o){var s,l,u,c,p,f,d,h=[i||a],g=v.call(n,"type")?n.type:n,m=v.call(n,"namespace")?n.namespace.split("."):[];if(u=f=i=i||a,3!==i.nodeType&&8!==i.nodeType&&!nt.test(g+x.event.triggered)&&(g.indexOf(".")>=0&&(m=g.split("."),g=m.shift(),m.sort()),l=0>g.indexOf(":")&&"on"+g,n=n[x.expando]?n:new x.Event(g,"object"==typeof n&&n),n.isTrigger=o?2:3,n.namespace=m.join("."),n.namespace_re=n.namespace?RegExp("(^|\\.)"+m.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,n.result=t,n.target||(n.target=i),r=null==r?[n]:x.makeArray(r,[n]),p=x.event.special[g]||{},o||!p.trigger||p.trigger.apply(i,r)!==!1)){if(!o&&!p.noBubble&&!x.isWindow(i)){for(c=p.delegateType||g,nt.test(c+g)||(u=u.parentNode);u;u=u.parentNode)h.push(u),f=u;f===(i.ownerDocument||a)&&h.push(f.defaultView||f.parentWindow||e)}d=0;while((u=h[d++])&&!n.isPropagationStopped())n.type=d>1?c:p.bindType||g,s=(x._data(u,"events")||{})[n.type]&&x._data(u,"handle"),s&&s.apply(u,r),s=l&&u[l],s&&x.acceptData(u)&&s.apply&&s.apply(u,r)===!1&&n.preventDefault();if(n.type=g,!o&&!n.isDefaultPrevented()&&(!p._default||p._default.apply(h.pop(),r)===!1)&&x.acceptData(i)&&l&&i[g]&&!x.isWindow(i)){f=i[l],f&&(i[l]=null),x.event.triggered=g;try{i[g]()}catch(y){}x.event.triggered=t,f&&(i[l]=f)}return n.result}},dispatch:function(e){e=x.event.fix(e);var n,r,i,o,a,s=[],l=g.call(arguments),u=(x._data(this,"events")||{})[e.type]||[],c=x.event.special[e.type]||{};if(l[0]=e,e.delegateTarget=this,!c.preDispatch||c.preDispatch.call(this,e)!==!1){s=x.event.handlers.call(this,e,u),n=0;while((o=s[n++])&&!e.isPropagationStopped()){e.currentTarget=o.elem,a=0;while((i=o.handlers[a++])&&!e.isImmediatePropagationStopped())(!e.namespace_re||e.namespace_re.test(i.namespace))&&(e.handleObj=i,e.data=i.data,r=((x.event.special[i.origType]||{}).handle||i.handler).apply(o.elem,l),r!==t&&(e.result=r)===!1&&(e.preventDefault(),e.stopPropagation()))}return c.postDispatch&&c.postDispatch.call(this,e),e.result}},handlers:function(e,n){var r,i,o,a,s=[],l=n.delegateCount,u=e.target;if(l&&u.nodeType&&(!e.button||"click"!==e.type))for(;u!=this;u=u.parentNode||this)if(1===u.nodeType&&(u.disabled!==!0||"click"!==e.type)){for(o=[],a=0;l>a;a++)i=n[a],r=i.selector+" ",o[r]===t&&(o[r]=i.needsContext?x(r,this).index(u)>=0:x.find(r,this,null,[u]).length),o[r]&&o.push(i);o.length&&s.push({elem:u,handlers:o})}return n.length>l&&s.push({elem:this,handlers:n.slice(l)}),s},fix:function(e){if(e[x.expando])return e;var t,n,r,i=e.type,o=e,s=this.fixHooks[i];s||(this.fixHooks[i]=s=tt.test(i)?this.mouseHooks:et.test(i)?this.keyHooks:{}),r=s.props?this.props.concat(s.props):this.props,e=new x.Event(o),t=r.length;while(t--)n=r[t],e[n]=o[n];return e.target||(e.target=o.srcElement||a),3===e.target.nodeType&&(e.target=e.target.parentNode),e.metaKey=!!e.metaKey,s.filter?s.filter(e,o):e},props:"altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(e,t){return null==e.which&&(e.which=null!=t.charCode?t.charCode:t.keyCode),e}},mouseHooks:{props:"button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(e,n){var r,i,o,s=n.button,l=n.fromElement;return null==e.pageX&&null!=n.clientX&&(i=e.target.ownerDocument||a,o=i.documentElement,r=i.body,e.pageX=n.clientX+(o&&o.scrollLeft||r&&r.scrollLeft||0)-(o&&o.clientLeft||r&&r.clientLeft||0),e.pageY=n.clientY+(o&&o.scrollTop||r&&r.scrollTop||0)-(o&&o.clientTop||r&&r.clientTop||0)),!e.relatedTarget&&l&&(e.relatedTarget=l===e.target?n.toElement:l),e.which||s===t||(e.which=1&s?1:2&s?3:4&s?2:0),e}},special:{load:{noBubble:!0},focus:{trigger:function(){if(this!==at()&&this.focus)try{return this.focus(),!1}catch(e){}},delegateType:"focusin"},blur:{trigger:function(){return this===at()&&this.blur?(this.blur(),!1):t},delegateType:"focusout"},click:{trigger:function(){return x.nodeName(this,"input")&&"checkbox"===this.type&&this.click?(this.click(),!1):t},_default:function(e){return x.nodeName(e.target,"a")}},beforeunload:{postDispatch:function(e){e.result!==t&&(e.originalEvent.returnValue=e.result)}}},simulate:function(e,t,n,r){var i=x.extend(new x.Event,n,{type:e,isSimulated:!0,originalEvent:{}});r?x.event.trigger(i,null,t):x.event.dispatch.call(t,i),i.isDefaultPrevented()&&n.preventDefault()}},x.removeEvent=a.removeEventListener?function(e,t,n){e.removeEventListener&&e.removeEventListener(t,n,!1)}:function(e,t,n){var r="on"+t;e.detachEvent&&(typeof e[r]===i&&(e[r]=null),e.detachEvent(r,n))},x.Event=function(e,n){return this instanceof x.Event?(e&&e.type?(this.originalEvent=e,this.type=e.type,this.isDefaultPrevented=e.defaultPrevented||e.returnValue===!1||e.getPreventDefault&&e.getPreventDefault()?it:ot):this.type=e,n&&x.extend(this,n),this.timeStamp=e&&e.timeStamp||x.now(),this[x.expando]=!0,t):new x.Event(e,n)},x.Event.prototype={isDefaultPrevented:ot,isPropagationStopped:ot,isImmediatePropagationStopped:ot,preventDefault:function(){var e=this.originalEvent;this.isDefaultPrevented=it,e&&(e.preventDefault?e.preventDefault():e.returnValue=!1)},stopPropagation:function(){var e=this.originalEvent;this.isPropagationStopped=it,e&&(e.stopPropagation&&e.stopPropagation(),e.cancelBubble=!0)},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=it,this.stopPropagation()}},x.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(e,t){x.event.special[e]={delegateType:t,bindType:t,handle:function(e){var n,r=this,i=e.relatedTarget,o=e.handleObj;return(!i||i!==r&&!x.contains(r,i))&&(e.type=o.origType,n=o.handler.apply(this,arguments),e.type=t),n}}}),x.support.submitBubbles||(x.event.special.submit={setup:function(){return x.nodeName(this,"form")?!1:(x.event.add(this,"click._submit keypress._submit",function(e){var n=e.target,r=x.nodeName(n,"input")||x.nodeName(n,"button")?n.form:t;r&&!x._data(r,"submitBubbles")&&(x.event.add(r,"submit._submit",function(e){e._submit_bubble=!0}),x._data(r,"submitBubbles",!0))}),t)},postDispatch:function(e){e._submit_bubble&&(delete e._submit_bubble,this.parentNode&&!e.isTrigger&&x.event.simulate("submit",this.parentNode,e,!0))},teardown:function(){return x.nodeName(this,"form")?!1:(x.event.remove(this,"._submit"),t)}}),x.support.changeBubbles||(x.event.special.change={setup:function(){return Z.test(this.nodeName)?(("checkbox"===this.type||"radio"===this.type)&&(x.event.add(this,"propertychange._change",function(e){"checked"===e.originalEvent.propertyName&&(this._just_changed=!0)}),x.event.add(this,"click._change",function(e){this._just_changed&&!e.isTrigger&&(this._just_changed=!1),x.event.simulate("change",this,e,!0)})),!1):(x.event.add(this,"beforeactivate._change",function(e){var t=e.target;Z.test(t.nodeName)&&!x._data(t,"changeBubbles")&&(x.event.add(t,"change._change",function(e){!this.parentNode||e.isSimulated||e.isTrigger||x.event.simulate("change",this.parentNode,e,!0)}),x._data(t,"changeBubbles",!0))}),t)},handle:function(e){var n=e.target;return this!==n||e.isSimulated||e.isTrigger||"radio"!==n.type&&"checkbox"!==n.type?e.handleObj.handler.apply(this,arguments):t},teardown:function(){return x.event.remove(this,"._change"),!Z.test(this.nodeName)}}),x.support.focusinBubbles||x.each({focus:"focusin",blur:"focusout"},function(e,t){var n=0,r=function(e){x.event.simulate(t,e.target,x.event.fix(e),!0)};x.event.special[t]={setup:function(){0===n++&&a.addEventListener(e,r,!0)},teardown:function(){0===--n&&a.removeEventListener(e,r,!0)}}}),x.fn.extend({on:function(e,n,r,i,o){var a,s;if("object"==typeof e){"string"!=typeof n&&(r=r||n,n=t);for(a in e)this.on(a,n,r,e[a],o);return this}if(null==r&&null==i?(i=n,r=n=t):null==i&&("string"==typeof n?(i=r,r=t):(i=r,r=n,n=t)),i===!1)i=ot;else if(!i)return this;return 1===o&&(s=i,i=function(e){return x().off(e),s.apply(this,arguments)},i.guid=s.guid||(s.guid=x.guid++)),this.each(function(){x.event.add(this,e,i,r,n)})},one:function(e,t,n,r){return this.on(e,t,n,r,1)},off:function(e,n,r){var i,o;if(e&&e.preventDefault&&e.handleObj)return i=e.handleObj,x(e.delegateTarget).off(i.namespace?i.origType+"."+i.namespace:i.origType,i.selector,i.handler),this;if("object"==typeof e){for(o in e)this.off(o,n,e[o]);return this}return(n===!1||"function"==typeof n)&&(r=n,n=t),r===!1&&(r=ot),this.each(function(){x.event.remove(this,e,r,n)})},trigger:function(e,t){return this.each(function(){x.event.trigger(e,t,this)})},triggerHandler:function(e,n){var r=this[0];return r?x.event.trigger(e,n,r,!0):t}});var st=/^.[^:#\[\.,]*$/,lt=/^(?:parents|prev(?:Until|All))/,ut=x.expr.match.needsContext,ct={children:!0,contents:!0,next:!0,prev:!0};x.fn.extend({find:function(e){var t,n=[],r=this,i=r.length;if("string"!=typeof e)return this.pushStack(x(e).filter(function(){for(t=0;i>t;t++)if(x.contains(r[t],this))return!0}));for(t=0;i>t;t++)x.find(e,r[t],n);return n=this.pushStack(i>1?x.unique(n):n),n.selector=this.selector?this.selector+" "+e:e,n},has:function(e){var t,n=x(e,this),r=n.length;return this.filter(function(){for(t=0;r>t;t++)if(x.contains(this,n[t]))return!0})},not:function(e){return this.pushStack(ft(this,e||[],!0))},filter:function(e){return this.pushStack(ft(this,e||[],!1))},is:function(e){return!!ft(this,"string"==typeof e&&ut.test(e)?x(e):e||[],!1).length},closest:function(e,t){var n,r=0,i=this.length,o=[],a=ut.test(e)||"string"!=typeof e?x(e,t||this.context):0;for(;i>r;r++)for(n=this[r];n&&n!==t;n=n.parentNode)if(11>n.nodeType&&(a?a.index(n)>-1:1===n.nodeType&&x.find.matchesSelector(n,e))){n=o.push(n);break}return this.pushStack(o.length>1?x.unique(o):o)},index:function(e){return e?"string"==typeof e?x.inArray(this[0],x(e)):x.inArray(e.jquery?e[0]:e,this):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(e,t){var n="string"==typeof e?x(e,t):x.makeArray(e&&e.nodeType?[e]:e),r=x.merge(this.get(),n);return this.pushStack(x.unique(r))},addBack:function(e){return this.add(null==e?this.prevObject:this.prevObject.filter(e))}});function pt(e,t){do e=e[t];while(e&&1!==e.nodeType);return e}x.each({parent:function(e){var t=e.parentNode;return t&&11!==t.nodeType?t:null},parents:function(e){return x.dir(e,"parentNode")},parentsUntil:function(e,t,n){return x.dir(e,"parentNode",n)},next:function(e){return pt(e,"nextSibling")},prev:function(e){return pt(e,"previousSibling")},nextAll:function(e){return x.dir(e,"nextSibling")},prevAll:function(e){return x.dir(e,"previousSibling")},nextUntil:function(e,t,n){return x.dir(e,"nextSibling",n)},prevUntil:function(e,t,n){return x.dir(e,"previousSibling",n)},siblings:function(e){return x.sibling((e.parentNode||{}).firstChild,e)},children:function(e){return x.sibling(e.firstChild)},contents:function(e){return x.nodeName(e,"iframe")?e.contentDocument||e.contentWindow.document:x.merge([],e.childNodes)}},function(e,t){x.fn[e]=function(n,r){var i=x.map(this,t,n);return"Until"!==e.slice(-5)&&(r=n),r&&"string"==typeof r&&(i=x.filter(r,i)),this.length>1&&(ct[e]||(i=x.unique(i)),lt.test(e)&&(i=i.reverse())),this.pushStack(i)}}),x.extend({filter:function(e,t,n){var r=t[0];return n&&(e=":not("+e+")"),1===t.length&&1===r.nodeType?x.find.matchesSelector(r,e)?[r]:[]:x.find.matches(e,x.grep(t,function(e){return 1===e.nodeType}))},dir:function(e,n,r){var i=[],o=e[n];while(o&&9!==o.nodeType&&(r===t||1!==o.nodeType||!x(o).is(r)))1===o.nodeType&&i.push(o),o=o[n];return i},sibling:function(e,t){var n=[];for(;e;e=e.nextSibling)1===e.nodeType&&e!==t&&n.push(e);return n}});function ft(e,t,n){if(x.isFunction(t))return x.grep(e,function(e,r){return!!t.call(e,r,e)!==n});if(t.nodeType)return x.grep(e,function(e){return e===t!==n});if("string"==typeof t){if(st.test(t))return x.filter(t,e,n);t=x.filter(t,e)}return x.grep(e,function(e){return x.inArray(e,t)>=0!==n})}function dt(e){var t=ht.split("|"),n=e.createDocumentFragment();if(n.createElement)while(t.length)n.createElement(t.pop());return n}var ht="abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",gt=/ jQuery\d+="(?:null|\d+)"/g,mt=RegExp("<(?:"+ht+")[\\s/>]","i"),yt=/^\s+/,vt=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,bt=/<([\w:]+)/,xt=/<tbody/i,wt=/<|&#?\w+;/,Tt=/<(?:script|style|link)/i,Ct=/^(?:checkbox|radio)$/i,Nt=/checked\s*(?:[^=]|=\s*.checked.)/i,kt=/^$|\/(?:java|ecma)script/i,Et=/^true\/(.*)/,St=/^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g,At={option:[1,"<select multiple='multiple'>","</select>"],legend:[1,"<fieldset>","</fieldset>"],area:[1,"<map>","</map>"],param:[1,"<object>","</object>"],thead:[1,"<table>","</table>"],tr:[2,"<table><tbody>","</tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],_default:x.support.htmlSerialize?[0,"",""]:[1,"X<div>","</div>"]},jt=dt(a),Dt=jt.appendChild(a.createElement("div"));At.optgroup=At.option,At.tbody=At.tfoot=At.colgroup=At.caption=At.thead,At.th=At.td,x.fn.extend({text:function(e){return x.access(this,function(e){return e===t?x.text(this):this.empty().append((this[0]&&this[0].ownerDocument||a).createTextNode(e))},null,e,arguments.length)},append:function(){return this.domManip(arguments,function(e){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var t=Lt(this,e);t.appendChild(e)}})},prepend:function(){return this.domManip(arguments,function(e){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var t=Lt(this,e);t.insertBefore(e,t.firstChild)}})},before:function(){return this.domManip(arguments,function(e){this.parentNode&&this.parentNode.insertBefore(e,this)})},after:function(){return this.domManip(arguments,function(e){this.parentNode&&this.parentNode.insertBefore(e,this.nextSibling)})},remove:function(e,t){var n,r=e?x.filter(e,this):this,i=0;for(;null!=(n=r[i]);i++)t||1!==n.nodeType||x.cleanData(Ft(n)),n.parentNode&&(t&&x.contains(n.ownerDocument,n)&&_t(Ft(n,"script")),n.parentNode.removeChild(n));return this},empty:function(){var e,t=0;for(;null!=(e=this[t]);t++){1===e.nodeType&&x.cleanData(Ft(e,!1));while(e.firstChild)e.removeChild(e.firstChild);e.options&&x.nodeName(e,"select")&&(e.options.length=0)}return this},clone:function(e,t){return e=null==e?!1:e,t=null==t?e:t,this.map(function(){return x.clone(this,e,t)})},html:function(e){return x.access(this,function(e){var n=this[0]||{},r=0,i=this.length;if(e===t)return 1===n.nodeType?n.innerHTML.replace(gt,""):t;if(!("string"!=typeof e||Tt.test(e)||!x.support.htmlSerialize&&mt.test(e)||!x.support.leadingWhitespace&&yt.test(e)||At[(bt.exec(e)||["",""])[1].toLowerCase()])){e=e.replace(vt,"<$1></$2>");try{for(;i>r;r++)n=this[r]||{},1===n.nodeType&&(x.cleanData(Ft(n,!1)),n.innerHTML=e);n=0}catch(o){}}n&&this.empty().append(e)},null,e,arguments.length)},replaceWith:function(){var e=x.map(this,function(e){return[e.nextSibling,e.parentNode]}),t=0;return this.domManip(arguments,function(n){var r=e[t++],i=e[t++];i&&(r&&r.parentNode!==i&&(r=this.nextSibling),x(this).remove(),i.insertBefore(n,r))},!0),t?this:this.remove()},detach:function(e){return this.remove(e,!0)},domManip:function(e,t,n){e=d.apply([],e);var r,i,o,a,s,l,u=0,c=this.length,p=this,f=c-1,h=e[0],g=x.isFunction(h);if(g||!(1>=c||"string"!=typeof h||x.support.checkClone)&&Nt.test(h))return this.each(function(r){var i=p.eq(r);g&&(e[0]=h.call(this,r,i.html())),i.domManip(e,t,n)});if(c&&(l=x.buildFragment(e,this[0].ownerDocument,!1,!n&&this),r=l.firstChild,1===l.childNodes.length&&(l=r),r)){for(a=x.map(Ft(l,"script"),Ht),o=a.length;c>u;u++)i=l,u!==f&&(i=x.clone(i,!0,!0),o&&x.merge(a,Ft(i,"script"))),t.call(this[u],i,u);if(o)for(s=a[a.length-1].ownerDocument,x.map(a,qt),u=0;o>u;u++)i=a[u],kt.test(i.type||"")&&!x._data(i,"globalEval")&&x.contains(s,i)&&(i.src?x._evalUrl(i.src):x.globalEval((i.text||i.textContent||i.innerHTML||"").replace(St,"")));l=r=null}return this}});function Lt(e,t){return x.nodeName(e,"table")&&x.nodeName(1===t.nodeType?t:t.firstChild,"tr")?e.getElementsByTagName("tbody")[0]||e.appendChild(e.ownerDocument.createElement("tbody")):e}function Ht(e){return e.type=(null!==x.find.attr(e,"type"))+"/"+e.type,e}function qt(e){var t=Et.exec(e.type);return t?e.type=t[1]:e.removeAttribute("type"),e}function _t(e,t){var n,r=0;for(;null!=(n=e[r]);r++)x._data(n,"globalEval",!t||x._data(t[r],"globalEval"))}function Mt(e,t){if(1===t.nodeType&&x.hasData(e)){var n,r,i,o=x._data(e),a=x._data(t,o),s=o.events;if(s){delete a.handle,a.events={};for(n in s)for(r=0,i=s[n].length;i>r;r++)x.event.add(t,n,s[n][r])}a.data&&(a.data=x.extend({},a.data))}}function Ot(e,t){var n,r,i;if(1===t.nodeType){if(n=t.nodeName.toLowerCase(),!x.support.noCloneEvent&&t[x.expando]){i=x._data(t);for(r in i.events)x.removeEvent(t,r,i.handle);t.removeAttribute(x.expando)}"script"===n&&t.text!==e.text?(Ht(t).text=e.text,qt(t)):"object"===n?(t.parentNode&&(t.outerHTML=e.outerHTML),x.support.html5Clone&&e.innerHTML&&!x.trim(t.innerHTML)&&(t.innerHTML=e.innerHTML)):"input"===n&&Ct.test(e.type)?(t.defaultChecked=t.checked=e.checked,t.value!==e.value&&(t.value=e.value)):"option"===n?t.defaultSelected=t.selected=e.defaultSelected:("input"===n||"textarea"===n)&&(t.defaultValue=e.defaultValue)}}x.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(e,t){x.fn[e]=function(e){var n,r=0,i=[],o=x(e),a=o.length-1;for(;a>=r;r++)n=r===a?this:this.clone(!0),x(o[r])[t](n),h.apply(i,n.get());return this.pushStack(i)}});function Ft(e,n){var r,o,a=0,s=typeof e.getElementsByTagName!==i?e.getElementsByTagName(n||"*"):typeof e.querySelectorAll!==i?e.querySelectorAll(n||"*"):t;if(!s)for(s=[],r=e.childNodes||e;null!=(o=r[a]);a++)!n||x.nodeName(o,n)?s.push(o):x.merge(s,Ft(o,n));return n===t||n&&x.nodeName(e,n)?x.merge([e],s):s}function Bt(e){Ct.test(e.type)&&(e.defaultChecked=e.checked)}x.extend({clone:function(e,t,n){var r,i,o,a,s,l=x.contains(e.ownerDocument,e);if(x.support.html5Clone||x.isXMLDoc(e)||!mt.test("<"+e.nodeName+">")?o=e.cloneNode(!0):(Dt.innerHTML=e.outerHTML,Dt.removeChild(o=Dt.firstChild)),!(x.support.noCloneEvent&&x.support.noCloneChecked||1!==e.nodeType&&11!==e.nodeType||x.isXMLDoc(e)))for(r=Ft(o),s=Ft(e),a=0;null!=(i=s[a]);++a)r[a]&&Ot(i,r[a]);if(t)if(n)for(s=s||Ft(e),r=r||Ft(o),a=0;null!=(i=s[a]);a++)Mt(i,r[a]);else Mt(e,o);return r=Ft(o,"script"),r.length>0&&_t(r,!l&&Ft(e,"script")),r=s=i=null,o},buildFragment:function(e,t,n,r){var i,o,a,s,l,u,c,p=e.length,f=dt(t),d=[],h=0;for(;p>h;h++)if(o=e[h],o||0===o)if("object"===x.type(o))x.merge(d,o.nodeType?[o]:o);else if(wt.test(o)){s=s||f.appendChild(t.createElement("div")),l=(bt.exec(o)||["",""])[1].toLowerCase(),c=At[l]||At._default,s.innerHTML=c[1]+o.replace(vt,"<$1></$2>")+c[2],i=c[0];while(i--)s=s.lastChild;if(!x.support.leadingWhitespace&&yt.test(o)&&d.push(t.createTextNode(yt.exec(o)[0])),!x.support.tbody){o="table"!==l||xt.test(o)?"<table>"!==c[1]||xt.test(o)?0:s:s.firstChild,i=o&&o.childNodes.length;while(i--)x.nodeName(u=o.childNodes[i],"tbody")&&!u.childNodes.length&&o.removeChild(u)}x.merge(d,s.childNodes),s.textContent="";while(s.firstChild)s.removeChild(s.firstChild);s=f.lastChild}else d.push(t.createTextNode(o));s&&f.removeChild(s),x.support.appendChecked||x.grep(Ft(d,"input"),Bt),h=0;while(o=d[h++])if((!r||-1===x.inArray(o,r))&&(a=x.contains(o.ownerDocument,o),s=Ft(f.appendChild(o),"script"),a&&_t(s),n)){i=0;while(o=s[i++])kt.test(o.type||"")&&n.push(o)}return s=null,f},cleanData:function(e,t){var n,r,o,a,s=0,l=x.expando,u=x.cache,c=x.support.deleteExpando,f=x.event.special;for(;null!=(n=e[s]);s++)if((t||x.acceptData(n))&&(o=n[l],a=o&&u[o])){if(a.events)for(r in a.events)f[r]?x.event.remove(n,r):x.removeEvent(n,r,a.handle);
+u[o]&&(delete u[o],c?delete n[l]:typeof n.removeAttribute!==i?n.removeAttribute(l):n[l]=null,p.push(o))}},_evalUrl:function(e){return x.ajax({url:e,type:"GET",dataType:"script",async:!1,global:!1,"throws":!0})}}),x.fn.extend({wrapAll:function(e){if(x.isFunction(e))return this.each(function(t){x(this).wrapAll(e.call(this,t))});if(this[0]){var t=x(e,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&t.insertBefore(this[0]),t.map(function(){var e=this;while(e.firstChild&&1===e.firstChild.nodeType)e=e.firstChild;return e}).append(this)}return this},wrapInner:function(e){return x.isFunction(e)?this.each(function(t){x(this).wrapInner(e.call(this,t))}):this.each(function(){var t=x(this),n=t.contents();n.length?n.wrapAll(e):t.append(e)})},wrap:function(e){var t=x.isFunction(e);return this.each(function(n){x(this).wrapAll(t?e.call(this,n):e)})},unwrap:function(){return this.parent().each(function(){x.nodeName(this,"body")||x(this).replaceWith(this.childNodes)}).end()}});var Pt,Rt,Wt,$t=/alpha\([^)]*\)/i,It=/opacity\s*=\s*([^)]*)/,zt=/^(top|right|bottom|left)$/,Xt=/^(none|table(?!-c[ea]).+)/,Ut=/^margin/,Vt=RegExp("^("+w+")(.*)$","i"),Yt=RegExp("^("+w+")(?!px)[a-z%]+$","i"),Jt=RegExp("^([+-])=("+w+")","i"),Gt={BODY:"block"},Qt={position:"absolute",visibility:"hidden",display:"block"},Kt={letterSpacing:0,fontWeight:400},Zt=["Top","Right","Bottom","Left"],en=["Webkit","O","Moz","ms"];function tn(e,t){if(t in e)return t;var n=t.charAt(0).toUpperCase()+t.slice(1),r=t,i=en.length;while(i--)if(t=en[i]+n,t in e)return t;return r}function nn(e,t){return e=t||e,"none"===x.css(e,"display")||!x.contains(e.ownerDocument,e)}function rn(e,t){var n,r,i,o=[],a=0,s=e.length;for(;s>a;a++)r=e[a],r.style&&(o[a]=x._data(r,"olddisplay"),n=r.style.display,t?(o[a]||"none"!==n||(r.style.display=""),""===r.style.display&&nn(r)&&(o[a]=x._data(r,"olddisplay",ln(r.nodeName)))):o[a]||(i=nn(r),(n&&"none"!==n||!i)&&x._data(r,"olddisplay",i?n:x.css(r,"display"))));for(a=0;s>a;a++)r=e[a],r.style&&(t&&"none"!==r.style.display&&""!==r.style.display||(r.style.display=t?o[a]||"":"none"));return e}x.fn.extend({css:function(e,n){return x.access(this,function(e,n,r){var i,o,a={},s=0;if(x.isArray(n)){for(o=Rt(e),i=n.length;i>s;s++)a[n[s]]=x.css(e,n[s],!1,o);return a}return r!==t?x.style(e,n,r):x.css(e,n)},e,n,arguments.length>1)},show:function(){return rn(this,!0)},hide:function(){return rn(this)},toggle:function(e){return"boolean"==typeof e?e?this.show():this.hide():this.each(function(){nn(this)?x(this).show():x(this).hide()})}}),x.extend({cssHooks:{opacity:{get:function(e,t){if(t){var n=Wt(e,"opacity");return""===n?"1":n}}}},cssNumber:{columnCount:!0,fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":x.support.cssFloat?"cssFloat":"styleFloat"},style:function(e,n,r,i){if(e&&3!==e.nodeType&&8!==e.nodeType&&e.style){var o,a,s,l=x.camelCase(n),u=e.style;if(n=x.cssProps[l]||(x.cssProps[l]=tn(u,l)),s=x.cssHooks[n]||x.cssHooks[l],r===t)return s&&"get"in s&&(o=s.get(e,!1,i))!==t?o:u[n];if(a=typeof r,"string"===a&&(o=Jt.exec(r))&&(r=(o[1]+1)*o[2]+parseFloat(x.css(e,n)),a="number"),!(null==r||"number"===a&&isNaN(r)||("number"!==a||x.cssNumber[l]||(r+="px"),x.support.clearCloneStyle||""!==r||0!==n.indexOf("background")||(u[n]="inherit"),s&&"set"in s&&(r=s.set(e,r,i))===t)))try{u[n]=r}catch(c){}}},css:function(e,n,r,i){var o,a,s,l=x.camelCase(n);return n=x.cssProps[l]||(x.cssProps[l]=tn(e.style,l)),s=x.cssHooks[n]||x.cssHooks[l],s&&"get"in s&&(a=s.get(e,!0,r)),a===t&&(a=Wt(e,n,i)),"normal"===a&&n in Kt&&(a=Kt[n]),""===r||r?(o=parseFloat(a),r===!0||x.isNumeric(o)?o||0:a):a}}),e.getComputedStyle?(Rt=function(t){return e.getComputedStyle(t,null)},Wt=function(e,n,r){var i,o,a,s=r||Rt(e),l=s?s.getPropertyValue(n)||s[n]:t,u=e.style;return s&&(""!==l||x.contains(e.ownerDocument,e)||(l=x.style(e,n)),Yt.test(l)&&Ut.test(n)&&(i=u.width,o=u.minWidth,a=u.maxWidth,u.minWidth=u.maxWidth=u.width=l,l=s.width,u.width=i,u.minWidth=o,u.maxWidth=a)),l}):a.documentElement.currentStyle&&(Rt=function(e){return e.currentStyle},Wt=function(e,n,r){var i,o,a,s=r||Rt(e),l=s?s[n]:t,u=e.style;return null==l&&u&&u[n]&&(l=u[n]),Yt.test(l)&&!zt.test(n)&&(i=u.left,o=e.runtimeStyle,a=o&&o.left,a&&(o.left=e.currentStyle.left),u.left="fontSize"===n?"1em":l,l=u.pixelLeft+"px",u.left=i,a&&(o.left=a)),""===l?"auto":l});function on(e,t,n){var r=Vt.exec(t);return r?Math.max(0,r[1]-(n||0))+(r[2]||"px"):t}function an(e,t,n,r,i){var o=n===(r?"border":"content")?4:"width"===t?1:0,a=0;for(;4>o;o+=2)"margin"===n&&(a+=x.css(e,n+Zt[o],!0,i)),r?("content"===n&&(a-=x.css(e,"padding"+Zt[o],!0,i)),"margin"!==n&&(a-=x.css(e,"border"+Zt[o]+"Width",!0,i))):(a+=x.css(e,"padding"+Zt[o],!0,i),"padding"!==n&&(a+=x.css(e,"border"+Zt[o]+"Width",!0,i)));return a}function sn(e,t,n){var r=!0,i="width"===t?e.offsetWidth:e.offsetHeight,o=Rt(e),a=x.support.boxSizing&&"border-box"===x.css(e,"boxSizing",!1,o);if(0>=i||null==i){if(i=Wt(e,t,o),(0>i||null==i)&&(i=e.style[t]),Yt.test(i))return i;r=a&&(x.support.boxSizingReliable||i===e.style[t]),i=parseFloat(i)||0}return i+an(e,t,n||(a?"border":"content"),r,o)+"px"}function ln(e){var t=a,n=Gt[e];return n||(n=un(e,t),"none"!==n&&n||(Pt=(Pt||x("<iframe frameborder='0' width='0' height='0'/>").css("cssText","display:block !important")).appendTo(t.documentElement),t=(Pt[0].contentWindow||Pt[0].contentDocument).document,t.write("<!doctype html><html><body>"),t.close(),n=un(e,t),Pt.detach()),Gt[e]=n),n}function un(e,t){var n=x(t.createElement(e)).appendTo(t.body),r=x.css(n[0],"display");return n.remove(),r}x.each(["height","width"],function(e,n){x.cssHooks[n]={get:function(e,r,i){return r?0===e.offsetWidth&&Xt.test(x.css(e,"display"))?x.swap(e,Qt,function(){return sn(e,n,i)}):sn(e,n,i):t},set:function(e,t,r){var i=r&&Rt(e);return on(e,t,r?an(e,n,r,x.support.boxSizing&&"border-box"===x.css(e,"boxSizing",!1,i),i):0)}}}),x.support.opacity||(x.cssHooks.opacity={get:function(e,t){return It.test((t&&e.currentStyle?e.currentStyle.filter:e.style.filter)||"")?.01*parseFloat(RegExp.$1)+"":t?"1":""},set:function(e,t){var n=e.style,r=e.currentStyle,i=x.isNumeric(t)?"alpha(opacity="+100*t+")":"",o=r&&r.filter||n.filter||"";n.zoom=1,(t>=1||""===t)&&""===x.trim(o.replace($t,""))&&n.removeAttribute&&(n.removeAttribute("filter"),""===t||r&&!r.filter)||(n.filter=$t.test(o)?o.replace($t,i):o+" "+i)}}),x(function(){x.support.reliableMarginRight||(x.cssHooks.marginRight={get:function(e,n){return n?x.swap(e,{display:"inline-block"},Wt,[e,"marginRight"]):t}}),!x.support.pixelPosition&&x.fn.position&&x.each(["top","left"],function(e,n){x.cssHooks[n]={get:function(e,r){return r?(r=Wt(e,n),Yt.test(r)?x(e).position()[n]+"px":r):t}}})}),x.expr&&x.expr.filters&&(x.expr.filters.hidden=function(e){return 0>=e.offsetWidth&&0>=e.offsetHeight||!x.support.reliableHiddenOffsets&&"none"===(e.style&&e.style.display||x.css(e,"display"))},x.expr.filters.visible=function(e){return!x.expr.filters.hidden(e)}),x.each({margin:"",padding:"",border:"Width"},function(e,t){x.cssHooks[e+t]={expand:function(n){var r=0,i={},o="string"==typeof n?n.split(" "):[n];for(;4>r;r++)i[e+Zt[r]+t]=o[r]||o[r-2]||o[0];return i}},Ut.test(e)||(x.cssHooks[e+t].set=on)});var cn=/%20/g,pn=/\[\]$/,fn=/\r?\n/g,dn=/^(?:submit|button|image|reset|file)$/i,hn=/^(?:input|select|textarea|keygen)/i;x.fn.extend({serialize:function(){return x.param(this.serializeArray())},serializeArray:function(){return this.map(function(){var e=x.prop(this,"elements");return e?x.makeArray(e):this}).filter(function(){var e=this.type;return this.name&&!x(this).is(":disabled")&&hn.test(this.nodeName)&&!dn.test(e)&&(this.checked||!Ct.test(e))}).map(function(e,t){var n=x(this).val();return null==n?null:x.isArray(n)?x.map(n,function(e){return{name:t.name,value:e.replace(fn,"\r\n")}}):{name:t.name,value:n.replace(fn,"\r\n")}}).get()}}),x.param=function(e,n){var r,i=[],o=function(e,t){t=x.isFunction(t)?t():null==t?"":t,i[i.length]=encodeURIComponent(e)+"="+encodeURIComponent(t)};if(n===t&&(n=x.ajaxSettings&&x.ajaxSettings.traditional),x.isArray(e)||e.jquery&&!x.isPlainObject(e))x.each(e,function(){o(this.name,this.value)});else for(r in e)gn(r,e[r],n,o);return i.join("&").replace(cn,"+")};function gn(e,t,n,r){var i;if(x.isArray(t))x.each(t,function(t,i){n||pn.test(e)?r(e,i):gn(e+"["+("object"==typeof i?t:"")+"]",i,n,r)});else if(n||"object"!==x.type(t))r(e,t);else for(i in t)gn(e+"["+i+"]",t[i],n,r)}x.each("blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error contextmenu".split(" "),function(e,t){x.fn[t]=function(e,n){return arguments.length>0?this.on(t,null,e,n):this.trigger(t)}}),x.fn.extend({hover:function(e,t){return this.mouseenter(e).mouseleave(t||e)},bind:function(e,t,n){return this.on(e,null,t,n)},unbind:function(e,t){return this.off(e,null,t)},delegate:function(e,t,n,r){return this.on(t,e,n,r)},undelegate:function(e,t,n){return 1===arguments.length?this.off(e,"**"):this.off(t,e||"**",n)}});var mn,yn,vn=x.now(),bn=/\?/,xn=/#.*$/,wn=/([?&])_=[^&]*/,Tn=/^(.*?):[ \t]*([^\r\n]*)\r?$/gm,Cn=/^(?:about|app|app-storage|.+-extension|file|res|widget):$/,Nn=/^(?:GET|HEAD)$/,kn=/^\/\//,En=/^([\w.+-]+:)(?:\/\/([^\/?#:]*)(?::(\d+)|)|)/,Sn=x.fn.load,An={},jn={},Dn="*/".concat("*");try{yn=o.href}catch(Ln){yn=a.createElement("a"),yn.href="",yn=yn.href}mn=En.exec(yn.toLowerCase())||[];function Hn(e){return function(t,n){"string"!=typeof t&&(n=t,t="*");var r,i=0,o=t.toLowerCase().match(T)||[];if(x.isFunction(n))while(r=o[i++])"+"===r[0]?(r=r.slice(1)||"*",(e[r]=e[r]||[]).unshift(n)):(e[r]=e[r]||[]).push(n)}}function qn(e,n,r,i){var o={},a=e===jn;function s(l){var u;return o[l]=!0,x.each(e[l]||[],function(e,l){var c=l(n,r,i);return"string"!=typeof c||a||o[c]?a?!(u=c):t:(n.dataTypes.unshift(c),s(c),!1)}),u}return s(n.dataTypes[0])||!o["*"]&&s("*")}function _n(e,n){var r,i,o=x.ajaxSettings.flatOptions||{};for(i in n)n[i]!==t&&((o[i]?e:r||(r={}))[i]=n[i]);return r&&x.extend(!0,e,r),e}x.fn.load=function(e,n,r){if("string"!=typeof e&&Sn)return Sn.apply(this,arguments);var i,o,a,s=this,l=e.indexOf(" ");return l>=0&&(i=e.slice(l,e.length),e=e.slice(0,l)),x.isFunction(n)?(r=n,n=t):n&&"object"==typeof n&&(a="POST"),s.length>0&&x.ajax({url:e,type:a,dataType:"html",data:n}).done(function(e){o=arguments,s.html(i?x("<div>").append(x.parseHTML(e)).find(i):e)}).complete(r&&function(e,t){s.each(r,o||[e.responseText,t,e])}),this},x.each(["ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"],function(e,t){x.fn[t]=function(e){return this.on(t,e)}}),x.extend({active:0,lastModified:{},etag:{},ajaxSettings:{url:yn,type:"GET",isLocal:Cn.test(mn[1]),global:!0,processData:!0,async:!0,contentType:"application/x-www-form-urlencoded; charset=UTF-8",accepts:{"*":Dn,text:"text/plain",html:"text/html",xml:"application/xml, text/xml",json:"application/json, text/javascript"},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText",json:"responseJSON"},converters:{"* text":String,"text html":!0,"text json":x.parseJSON,"text xml":x.parseXML},flatOptions:{url:!0,context:!0}},ajaxSetup:function(e,t){return t?_n(_n(e,x.ajaxSettings),t):_n(x.ajaxSettings,e)},ajaxPrefilter:Hn(An),ajaxTransport:Hn(jn),ajax:function(e,n){"object"==typeof e&&(n=e,e=t),n=n||{};var r,i,o,a,s,l,u,c,p=x.ajaxSetup({},n),f=p.context||p,d=p.context&&(f.nodeType||f.jquery)?x(f):x.event,h=x.Deferred(),g=x.Callbacks("once memory"),m=p.statusCode||{},y={},v={},b=0,w="canceled",C={readyState:0,getResponseHeader:function(e){var t;if(2===b){if(!c){c={};while(t=Tn.exec(a))c[t[1].toLowerCase()]=t[2]}t=c[e.toLowerCase()]}return null==t?null:t},getAllResponseHeaders:function(){return 2===b?a:null},setRequestHeader:function(e,t){var n=e.toLowerCase();return b||(e=v[n]=v[n]||e,y[e]=t),this},overrideMimeType:function(e){return b||(p.mimeType=e),this},statusCode:function(e){var t;if(e)if(2>b)for(t in e)m[t]=[m[t],e[t]];else C.always(e[C.status]);return this},abort:function(e){var t=e||w;return u&&u.abort(t),k(0,t),this}};if(h.promise(C).complete=g.add,C.success=C.done,C.error=C.fail,p.url=((e||p.url||yn)+"").replace(xn,"").replace(kn,mn[1]+"//"),p.type=n.method||n.type||p.method||p.type,p.dataTypes=x.trim(p.dataType||"*").toLowerCase().match(T)||[""],null==p.crossDomain&&(r=En.exec(p.url.toLowerCase()),p.crossDomain=!(!r||r[1]===mn[1]&&r[2]===mn[2]&&(r[3]||("http:"===r[1]?"80":"443"))===(mn[3]||("http:"===mn[1]?"80":"443")))),p.data&&p.processData&&"string"!=typeof p.data&&(p.data=x.param(p.data,p.traditional)),qn(An,p,n,C),2===b)return C;l=p.global,l&&0===x.active++&&x.event.trigger("ajaxStart"),p.type=p.type.toUpperCase(),p.hasContent=!Nn.test(p.type),o=p.url,p.hasContent||(p.data&&(o=p.url+=(bn.test(o)?"&":"?")+p.data,delete p.data),p.cache===!1&&(p.url=wn.test(o)?o.replace(wn,"$1_="+vn++):o+(bn.test(o)?"&":"?")+"_="+vn++)),p.ifModified&&(x.lastModified[o]&&C.setRequestHeader("If-Modified-Since",x.lastModified[o]),x.etag[o]&&C.setRequestHeader("If-None-Match",x.etag[o])),(p.data&&p.hasContent&&p.contentType!==!1||n.contentType)&&C.setRequestHeader("Content-Type",p.contentType),C.setRequestHeader("Accept",p.dataTypes[0]&&p.accepts[p.dataTypes[0]]?p.accepts[p.dataTypes[0]]+("*"!==p.dataTypes[0]?", "+Dn+"; q=0.01":""):p.accepts["*"]);for(i in p.headers)C.setRequestHeader(i,p.headers[i]);if(p.beforeSend&&(p.beforeSend.call(f,C,p)===!1||2===b))return C.abort();w="abort";for(i in{success:1,error:1,complete:1})C[i](p[i]);if(u=qn(jn,p,n,C)){C.readyState=1,l&&d.trigger("ajaxSend",[C,p]),p.async&&p.timeout>0&&(s=setTimeout(function(){C.abort("timeout")},p.timeout));try{b=1,u.send(y,k)}catch(N){if(!(2>b))throw N;k(-1,N)}}else k(-1,"No Transport");function k(e,n,r,i){var c,y,v,w,T,N=n;2!==b&&(b=2,s&&clearTimeout(s),u=t,a=i||"",C.readyState=e>0?4:0,c=e>=200&&300>e||304===e,r&&(w=Mn(p,C,r)),w=On(p,w,C,c),c?(p.ifModified&&(T=C.getResponseHeader("Last-Modified"),T&&(x.lastModified[o]=T),T=C.getResponseHeader("etag"),T&&(x.etag[o]=T)),204===e||"HEAD"===p.type?N="nocontent":304===e?N="notmodified":(N=w.state,y=w.data,v=w.error,c=!v)):(v=N,(e||!N)&&(N="error",0>e&&(e=0))),C.status=e,C.statusText=(n||N)+"",c?h.resolveWith(f,[y,N,C]):h.rejectWith(f,[C,N,v]),C.statusCode(m),m=t,l&&d.trigger(c?"ajaxSuccess":"ajaxError",[C,p,c?y:v]),g.fireWith(f,[C,N]),l&&(d.trigger("ajaxComplete",[C,p]),--x.active||x.event.trigger("ajaxStop")))}return C},getJSON:function(e,t,n){return x.get(e,t,n,"json")},getScript:function(e,n){return x.get(e,t,n,"script")}}),x.each(["get","post"],function(e,n){x[n]=function(e,r,i,o){return x.isFunction(r)&&(o=o||i,i=r,r=t),x.ajax({url:e,type:n,dataType:o,data:r,success:i})}});function Mn(e,n,r){var i,o,a,s,l=e.contents,u=e.dataTypes;while("*"===u[0])u.shift(),o===t&&(o=e.mimeType||n.getResponseHeader("Content-Type"));if(o)for(s in l)if(l[s]&&l[s].test(o)){u.unshift(s);break}if(u[0]in r)a=u[0];else{for(s in r){if(!u[0]||e.converters[s+" "+u[0]]){a=s;break}i||(i=s)}a=a||i}return a?(a!==u[0]&&u.unshift(a),r[a]):t}function On(e,t,n,r){var i,o,a,s,l,u={},c=e.dataTypes.slice();if(c[1])for(a in e.converters)u[a.toLowerCase()]=e.converters[a];o=c.shift();while(o)if(e.responseFields[o]&&(n[e.responseFields[o]]=t),!l&&r&&e.dataFilter&&(t=e.dataFilter(t,e.dataType)),l=o,o=c.shift())if("*"===o)o=l;else if("*"!==l&&l!==o){if(a=u[l+" "+o]||u["* "+o],!a)for(i in u)if(s=i.split(" "),s[1]===o&&(a=u[l+" "+s[0]]||u["* "+s[0]])){a===!0?a=u[i]:u[i]!==!0&&(o=s[0],c.unshift(s[1]));break}if(a!==!0)if(a&&e["throws"])t=a(t);else try{t=a(t)}catch(p){return{state:"parsererror",error:a?p:"No conversion from "+l+" to "+o}}}return{state:"success",data:t}}x.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/(?:java|ecma)script/},converters:{"text script":function(e){return x.globalEval(e),e}}}),x.ajaxPrefilter("script",function(e){e.cache===t&&(e.cache=!1),e.crossDomain&&(e.type="GET",e.global=!1)}),x.ajaxTransport("script",function(e){if(e.crossDomain){var n,r=a.head||x("head")[0]||a.documentElement;return{send:function(t,i){n=a.createElement("script"),n.async=!0,e.scriptCharset&&(n.charset=e.scriptCharset),n.src=e.url,n.onload=n.onreadystatechange=function(e,t){(t||!n.readyState||/loaded|complete/.test(n.readyState))&&(n.onload=n.onreadystatechange=null,n.parentNode&&n.parentNode.removeChild(n),n=null,t||i(200,"success"))},r.insertBefore(n,r.firstChild)},abort:function(){n&&n.onload(t,!0)}}}});var Fn=[],Bn=/(=)\?(?=&|$)|\?\?/;x.ajaxSetup({jsonp:"callback",jsonpCallback:function(){var e=Fn.pop()||x.expando+"_"+vn++;return this[e]=!0,e}}),x.ajaxPrefilter("json jsonp",function(n,r,i){var o,a,s,l=n.jsonp!==!1&&(Bn.test(n.url)?"url":"string"==typeof n.data&&!(n.contentType||"").indexOf("application/x-www-form-urlencoded")&&Bn.test(n.data)&&"data");return l||"jsonp"===n.dataTypes[0]?(o=n.jsonpCallback=x.isFunction(n.jsonpCallback)?n.jsonpCallback():n.jsonpCallback,l?n[l]=n[l].replace(Bn,"$1"+o):n.jsonp!==!1&&(n.url+=(bn.test(n.url)?"&":"?")+n.jsonp+"="+o),n.converters["script json"]=function(){return s||x.error(o+" was not called"),s[0]},n.dataTypes[0]="json",a=e[o],e[o]=function(){s=arguments},i.always(function(){e[o]=a,n[o]&&(n.jsonpCallback=r.jsonpCallback,Fn.push(o)),s&&x.isFunction(a)&&a(s[0]),s=a=t}),"script"):t});var Pn,Rn,Wn=0,$n=e.ActiveXObject&&function(){var e;for(e in Pn)Pn[e](t,!0)};function In(){try{return new e.XMLHttpRequest}catch(t){}}function zn(){try{return new e.ActiveXObject("Microsoft.XMLHTTP")}catch(t){}}x.ajaxSettings.xhr=e.ActiveXObject?function(){return!this.isLocal&&In()||zn()}:In,Rn=x.ajaxSettings.xhr(),x.support.cors=!!Rn&&"withCredentials"in Rn,Rn=x.support.ajax=!!Rn,Rn&&x.ajaxTransport(function(n){if(!n.crossDomain||x.support.cors){var r;return{send:function(i,o){var a,s,l=n.xhr();if(n.username?l.open(n.type,n.url,n.async,n.username,n.password):l.open(n.type,n.url,n.async),n.xhrFields)for(s in n.xhrFields)l[s]=n.xhrFields[s];n.mimeType&&l.overrideMimeType&&l.overrideMimeType(n.mimeType),n.crossDomain||i["X-Requested-With"]||(i["X-Requested-With"]="XMLHttpRequest");try{for(s in i)l.setRequestHeader(s,i[s])}catch(u){}l.send(n.hasContent&&n.data||null),r=function(e,i){var s,u,c,p;try{if(r&&(i||4===l.readyState))if(r=t,a&&(l.onreadystatechange=x.noop,$n&&delete Pn[a]),i)4!==l.readyState&&l.abort();else{p={},s=l.status,u=l.getAllResponseHeaders(),"string"==typeof l.responseText&&(p.text=l.responseText);try{c=l.statusText}catch(f){c=""}s||!n.isLocal||n.crossDomain?1223===s&&(s=204):s=p.text?200:404}}catch(d){i||o(-1,d)}p&&o(s,c,p,u)},n.async?4===l.readyState?setTimeout(r):(a=++Wn,$n&&(Pn||(Pn={},x(e).unload($n)),Pn[a]=r),l.onreadystatechange=r):r()},abort:function(){r&&r(t,!0)}}}});var Xn,Un,Vn=/^(?:toggle|show|hide)$/,Yn=RegExp("^(?:([+-])=|)("+w+")([a-z%]*)$","i"),Jn=/queueHooks$/,Gn=[nr],Qn={"*":[function(e,t){var n=this.createTween(e,t),r=n.cur(),i=Yn.exec(t),o=i&&i[3]||(x.cssNumber[e]?"":"px"),a=(x.cssNumber[e]||"px"!==o&&+r)&&Yn.exec(x.css(n.elem,e)),s=1,l=20;if(a&&a[3]!==o){o=o||a[3],i=i||[],a=+r||1;do s=s||".5",a/=s,x.style(n.elem,e,a+o);while(s!==(s=n.cur()/r)&&1!==s&&--l)}return i&&(a=n.start=+a||+r||0,n.unit=o,n.end=i[1]?a+(i[1]+1)*i[2]:+i[2]),n}]};function Kn(){return setTimeout(function(){Xn=t}),Xn=x.now()}function Zn(e,t,n){var r,i=(Qn[t]||[]).concat(Qn["*"]),o=0,a=i.length;for(;a>o;o++)if(r=i[o].call(n,t,e))return r}function er(e,t,n){var r,i,o=0,a=Gn.length,s=x.Deferred().always(function(){delete l.elem}),l=function(){if(i)return!1;var t=Xn||Kn(),n=Math.max(0,u.startTime+u.duration-t),r=n/u.duration||0,o=1-r,a=0,l=u.tweens.length;for(;l>a;a++)u.tweens[a].run(o);return s.notifyWith(e,[u,o,n]),1>o&&l?n:(s.resolveWith(e,[u]),!1)},u=s.promise({elem:e,props:x.extend({},t),opts:x.extend(!0,{specialEasing:{}},n),originalProperties:t,originalOptions:n,startTime:Xn||Kn(),duration:n.duration,tweens:[],createTween:function(t,n){var r=x.Tween(e,u.opts,t,n,u.opts.specialEasing[t]||u.opts.easing);return u.tweens.push(r),r},stop:function(t){var n=0,r=t?u.tweens.length:0;if(i)return this;for(i=!0;r>n;n++)u.tweens[n].run(1);return t?s.resolveWith(e,[u,t]):s.rejectWith(e,[u,t]),this}}),c=u.props;for(tr(c,u.opts.specialEasing);a>o;o++)if(r=Gn[o].call(u,e,c,u.opts))return r;return x.map(c,Zn,u),x.isFunction(u.opts.start)&&u.opts.start.call(e,u),x.fx.timer(x.extend(l,{elem:e,anim:u,queue:u.opts.queue})),u.progress(u.opts.progress).done(u.opts.done,u.opts.complete).fail(u.opts.fail).always(u.opts.always)}function tr(e,t){var n,r,i,o,a;for(n in e)if(r=x.camelCase(n),i=t[r],o=e[n],x.isArray(o)&&(i=o[1],o=e[n]=o[0]),n!==r&&(e[r]=o,delete e[n]),a=x.cssHooks[r],a&&"expand"in a){o=a.expand(o),delete e[r];for(n in o)n in e||(e[n]=o[n],t[n]=i)}else t[r]=i}x.Animation=x.extend(er,{tweener:function(e,t){x.isFunction(e)?(t=e,e=["*"]):e=e.split(" ");var n,r=0,i=e.length;for(;i>r;r++)n=e[r],Qn[n]=Qn[n]||[],Qn[n].unshift(t)},prefilter:function(e,t){t?Gn.unshift(e):Gn.push(e)}});function nr(e,t,n){var r,i,o,a,s,l,u=this,c={},p=e.style,f=e.nodeType&&nn(e),d=x._data(e,"fxshow");n.queue||(s=x._queueHooks(e,"fx"),null==s.unqueued&&(s.unqueued=0,l=s.empty.fire,s.empty.fire=function(){s.unqueued||l()}),s.unqueued++,u.always(function(){u.always(function(){s.unqueued--,x.queue(e,"fx").length||s.empty.fire()})})),1===e.nodeType&&("height"in t||"width"in t)&&(n.overflow=[p.overflow,p.overflowX,p.overflowY],"inline"===x.css(e,"display")&&"none"===x.css(e,"float")&&(x.support.inlineBlockNeedsLayout&&"inline"!==ln(e.nodeName)?p.zoom=1:p.display="inline-block")),n.overflow&&(p.overflow="hidden",x.support.shrinkWrapBlocks||u.always(function(){p.overflow=n.overflow[0],p.overflowX=n.overflow[1],p.overflowY=n.overflow[2]}));for(r in t)if(i=t[r],Vn.exec(i)){if(delete t[r],o=o||"toggle"===i,i===(f?"hide":"show"))continue;c[r]=d&&d[r]||x.style(e,r)}if(!x.isEmptyObject(c)){d?"hidden"in d&&(f=d.hidden):d=x._data(e,"fxshow",{}),o&&(d.hidden=!f),f?x(e).show():u.done(function(){x(e).hide()}),u.done(function(){var t;x._removeData(e,"fxshow");for(t in c)x.style(e,t,c[t])});for(r in c)a=Zn(f?d[r]:0,r,u),r in d||(d[r]=a.start,f&&(a.end=a.start,a.start="width"===r||"height"===r?1:0))}}function rr(e,t,n,r,i){return new rr.prototype.init(e,t,n,r,i)}x.Tween=rr,rr.prototype={constructor:rr,init:function(e,t,n,r,i,o){this.elem=e,this.prop=n,this.easing=i||"swing",this.options=t,this.start=this.now=this.cur(),this.end=r,this.unit=o||(x.cssNumber[n]?"":"px")},cur:function(){var e=rr.propHooks[this.prop];return e&&e.get?e.get(this):rr.propHooks._default.get(this)},run:function(e){var t,n=rr.propHooks[this.prop];return this.pos=t=this.options.duration?x.easing[this.easing](e,this.options.duration*e,0,1,this.options.duration):e,this.now=(this.end-this.start)*t+this.start,this.options.step&&this.options.step.call(this.elem,this.now,this),n&&n.set?n.set(this):rr.propHooks._default.set(this),this}},rr.prototype.init.prototype=rr.prototype,rr.propHooks={_default:{get:function(e){var t;return null==e.elem[e.prop]||e.elem.style&&null!=e.elem.style[e.prop]?(t=x.css(e.elem,e.prop,""),t&&"auto"!==t?t:0):e.elem[e.prop]},set:function(e){x.fx.step[e.prop]?x.fx.step[e.prop](e):e.elem.style&&(null!=e.elem.style[x.cssProps[e.prop]]||x.cssHooks[e.prop])?x.style(e.elem,e.prop,e.now+e.unit):e.elem[e.prop]=e.now}}},rr.propHooks.scrollTop=rr.propHooks.scrollLeft={set:function(e){e.elem.nodeType&&e.elem.parentNode&&(e.elem[e.prop]=e.now)}},x.each(["toggle","show","hide"],function(e,t){var n=x.fn[t];x.fn[t]=function(e,r,i){return null==e||"boolean"==typeof e?n.apply(this,arguments):this.animate(ir(t,!0),e,r,i)}}),x.fn.extend({fadeTo:function(e,t,n,r){return this.filter(nn).css("opacity",0).show().end().animate({opacity:t},e,n,r)},animate:function(e,t,n,r){var i=x.isEmptyObject(e),o=x.speed(t,n,r),a=function(){var t=er(this,x.extend({},e),o);(i||x._data(this,"finish"))&&t.stop(!0)};return a.finish=a,i||o.queue===!1?this.each(a):this.queue(o.queue,a)},stop:function(e,n,r){var i=function(e){var t=e.stop;delete e.stop,t(r)};return"string"!=typeof e&&(r=n,n=e,e=t),n&&e!==!1&&this.queue(e||"fx",[]),this.each(function(){var t=!0,n=null!=e&&e+"queueHooks",o=x.timers,a=x._data(this);if(n)a[n]&&a[n].stop&&i(a[n]);else for(n in a)a[n]&&a[n].stop&&Jn.test(n)&&i(a[n]);for(n=o.length;n--;)o[n].elem!==this||null!=e&&o[n].queue!==e||(o[n].anim.stop(r),t=!1,o.splice(n,1));(t||!r)&&x.dequeue(this,e)})},finish:function(e){return e!==!1&&(e=e||"fx"),this.each(function(){var t,n=x._data(this),r=n[e+"queue"],i=n[e+"queueHooks"],o=x.timers,a=r?r.length:0;for(n.finish=!0,x.queue(this,e,[]),i&&i.stop&&i.stop.call(this,!0),t=o.length;t--;)o[t].elem===this&&o[t].queue===e&&(o[t].anim.stop(!0),o.splice(t,1));for(t=0;a>t;t++)r[t]&&r[t].finish&&r[t].finish.call(this);delete n.finish})}});function ir(e,t){var n,r={height:e},i=0;for(t=t?1:0;4>i;i+=2-t)n=Zt[i],r["margin"+n]=r["padding"+n]=e;return t&&(r.opacity=r.width=e),r}x.each({slideDown:ir("show"),slideUp:ir("hide"),slideToggle:ir("toggle"),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(e,t){x.fn[e]=function(e,n,r){return this.animate(t,e,n,r)}}),x.speed=function(e,t,n){var r=e&&"object"==typeof e?x.extend({},e):{complete:n||!n&&t||x.isFunction(e)&&e,duration:e,easing:n&&t||t&&!x.isFunction(t)&&t};return r.duration=x.fx.off?0:"number"==typeof r.duration?r.duration:r.duration in x.fx.speeds?x.fx.speeds[r.duration]:x.fx.speeds._default,(null==r.queue||r.queue===!0)&&(r.queue="fx"),r.old=r.complete,r.complete=function(){x.isFunction(r.old)&&r.old.call(this),r.queue&&x.dequeue(this,r.queue)},r},x.easing={linear:function(e){return e},swing:function(e){return.5-Math.cos(e*Math.PI)/2}},x.timers=[],x.fx=rr.prototype.init,x.fx.tick=function(){var e,n=x.timers,r=0;for(Xn=x.now();n.length>r;r++)e=n[r],e()||n[r]!==e||n.splice(r--,1);n.length||x.fx.stop(),Xn=t},x.fx.timer=function(e){e()&&x.timers.push(e)&&x.fx.start()},x.fx.interval=13,x.fx.start=function(){Un||(Un=setInterval(x.fx.tick,x.fx.interval))},x.fx.stop=function(){clearInterval(Un),Un=null},x.fx.speeds={slow:600,fast:200,_default:400},x.fx.step={},x.expr&&x.expr.filters&&(x.expr.filters.animated=function(e){return x.grep(x.timers,function(t){return e===t.elem}).length}),x.fn.offset=function(e){if(arguments.length)return e===t?this:this.each(function(t){x.offset.setOffset(this,e,t)});var n,r,o={top:0,left:0},a=this[0],s=a&&a.ownerDocument;if(s)return n=s.documentElement,x.contains(n,a)?(typeof a.getBoundingClientRect!==i&&(o=a.getBoundingClientRect()),r=or(s),{top:o.top+(r.pageYOffset||n.scrollTop)-(n.clientTop||0),left:o.left+(r.pageXOffset||n.scrollLeft)-(n.clientLeft||0)}):o},x.offset={setOffset:function(e,t,n){var r=x.css(e,"position");"static"===r&&(e.style.position="relative");var i=x(e),o=i.offset(),a=x.css(e,"top"),s=x.css(e,"left"),l=("absolute"===r||"fixed"===r)&&x.inArray("auto",[a,s])>-1,u={},c={},p,f;l?(c=i.position(),p=c.top,f=c.left):(p=parseFloat(a)||0,f=parseFloat(s)||0),x.isFunction(t)&&(t=t.call(e,n,o)),null!=t.top&&(u.top=t.top-o.top+p),null!=t.left&&(u.left=t.left-o.left+f),"using"in t?t.using.call(e,u):i.css(u)}},x.fn.extend({position:function(){if(this[0]){var e,t,n={top:0,left:0},r=this[0];return"fixed"===x.css(r,"position")?t=r.getBoundingClientRect():(e=this.offsetParent(),t=this.offset(),x.nodeName(e[0],"html")||(n=e.offset()),n.top+=x.css(e[0],"borderTopWidth",!0),n.left+=x.css(e[0],"borderLeftWidth",!0)),{top:t.top-n.top-x.css(r,"marginTop",!0),left:t.left-n.left-x.css(r,"marginLeft",!0)}}},offsetParent:function(){return this.map(function(){var e=this.offsetParent||s;while(e&&!x.nodeName(e,"html")&&"static"===x.css(e,"position"))e=e.offsetParent;return e||s})}}),x.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(e,n){var r=/Y/.test(n);x.fn[e]=function(i){return x.access(this,function(e,i,o){var a=or(e);return o===t?a?n in a?a[n]:a.document.documentElement[i]:e[i]:(a?a.scrollTo(r?x(a).scrollLeft():o,r?o:x(a).scrollTop()):e[i]=o,t)},e,i,arguments.length,null)}});function or(e){return x.isWindow(e)?e:9===e.nodeType?e.defaultView||e.parentWindow:!1}x.each({Height:"height",Width:"width"},function(e,n){x.each({padding:"inner"+e,content:n,"":"outer"+e},function(r,i){x.fn[i]=function(i,o){var a=arguments.length&&(r||"boolean"!=typeof i),s=r||(i===!0||o===!0?"margin":"border");return x.access(this,function(n,r,i){var o;return x.isWindow(n)?n.document.documentElement["client"+e]:9===n.nodeType?(o=n.documentElement,Math.max(n.body["scroll"+e],o["scroll"+e],n.body["offset"+e],o["offset"+e],o["client"+e])):i===t?x.css(n,r,s):x.style(n,r,i,s)},n,a?i:t,a,null)}})}),x.fn.size=function(){return this.length},x.fn.andSelf=x.fn.addBack,"object"==typeof module&&module&&"object"==typeof module.exports?module.exports=x:(e.jQuery=e.$=x,"function"==typeof define&&define.amd&&define("jquery",[],function(){return x}))})(window);
--- /dev/null
+<!DOCTYPE html>
+
+<meta http-equiv="X-UA-Compatible" content="IE=Edge">
+<meta charset="utf-8">
+
+<title>wysihtml5 - Simple Demo</title>
+
+<style>
+ body {
+ font-family: Verdana;
+ font-size: 11px;
+ }
+
+ h2 {
+ margin-bottom: 0;
+ }
+
+ small {
+ display: block;
+ margin-top: 40px;
+ font-size: 9px;
+ }
+
+ small,
+ small a {
+ color: #666;
+ }
+
+ a {
+ color: #000;
+ text-decoration: underline;
+ cursor: pointer;
+ }
+
+ #toolbar [data-wysihtml5-action] {
+ float: right;
+ margin-right: 10px;
+ }
+
+ #toolbar,
+ textarea {
+ width: 600px;
+ padding: 5px;
+ }
+
+ textarea {
+ height: 280px;
+ border: 2px solid green;
+ box-sizing: boder-box;
+ -webkit-box-sizing: border-box;
+ -ms-box-sizing: border-box;
+ -moz-box-sizing: border-box;
+ font-family: Verdana;
+ font-size: 11px;
+ }
+
+ textarea:focus {
+ color: black;
+ border: 2px solid black;
+ }
+
+ .wysihtml5-command-active {
+ font-weight: bold;
+ }
+</style>
+
+<h1>wysihtml5 - Simple Editor Example</h1>
+
+<p>
+ Uses a custom rule set that allows the following elements: <em>strong, b, em, i, a, span</em><br>
+ Links will automatically receive <i>target="_blank"</i> and <i>rel="nofollow"</i>. Check the source code of this page.
+</p>
+
+<form>
+ <div id="toolbar" style="display: none;">
+ <a data-wysihtml5-command="bold" title="CTRL+B">bold</a> |
+ <a data-wysihtml5-command="italic" title="CTRL+I">italic</a>
+ <a data-wysihtml5-action="change_view">switch to html view</a>
+ </div>
+ <textarea id="textarea" placeholder="Enter text ..."></textarea>
+ <br><input type="reset" value="Reset form!">
+</form>
+
+<h2>Events:</h2>
+<div id="log"></div>
+
+<small>powered by <a href="https://github.com/xing/wysihtml5" target="_blank">wysihtml5</a>.</small>
+
+<script src="../parser_rules/simple.js"></script>
+<script src="../dist/wysihtml5x-toolbar.min.js"></script>
+<script>
+ var editor = new wysihtml5.Editor("textarea", {
+ toolbar: "toolbar",
+ parserRules: wysihtml5ParserRules,
+ useLineBreaks: false
+ });
+
+ var log = document.getElementById("log");
+
+ editor
+ .on("load", function() {
+ log.innerHTML += "<div>load</div>";
+ })
+ .on("focus", function() {
+ log.innerHTML += "<div>focus</div>";
+ })
+ .on("blur", function() {
+ log.innerHTML += "<div>blur</div>";
+ })
+ .on("change", function() {
+ log.innerHTML += "<div>change</div>";
+ })
+ .on("paste", function() {
+ log.innerHTML += "<div>paste</div>";
+ })
+ .on("newword:composer", function() {
+ log.innerHTML += "<div>newword:composer</div>";
+ })
+ .on("undo:composer", function() {
+ log.innerHTML += "<div>undo:composer</div>";
+ })
+ .on("redo:composer", function() {
+ log.innerHTML += "<div>redo:composer</div>";
+ });
+</script>
\ No newline at end of file
--- /dev/null
+<!DOCTYPE html>
+
+<meta http-equiv="X-UA-Compatible" content="IE=Edge">
+<meta charset="utf-8">
+
+<title>wysihtml5 - Advanced Demo</title>
+<link rel="stylesheet" href="css/stylesheet.css" type="text/css" media="screen" title="no title" charset="utf-8">
+
+
+<style>
+ body {
+ font-family: Verdana;
+ font-size: 11px;
+ }
+
+ h2 {
+ margin-bottom: 0;
+ }
+
+ small {
+ display: block;
+ margin-top: 40px;
+ font-size: 9px;
+ }
+
+ small,
+ small a {
+ color: #666;
+ }
+
+ a {
+ color: #000;
+ text-decoration: underline;
+ cursor: pointer;
+ }
+
+ #toolbar [data-wysihtml5-action] {
+ float: right;
+ }
+
+ #toolbar,
+ textarea {
+ width: 920px;
+ padding: 5px;
+ -webkit-box-sizing: border-box;
+ -ms-box-sizing: border-box;
+ -moz-box-sizing: border-box;
+ box-sizing: border-box;
+ }
+
+ textarea {
+ height: 280px;
+ border: 2px solid green;
+ font-family: Verdana;
+ font-size: 11px;
+ }
+
+ textarea:focus {
+ color: black;
+ border: 2px solid black;
+ }
+
+ .wysihtml5-command-active {
+ font-weight: bold;
+ }
+
+ [data-wysihtml5-dialog] {
+ margin: 5px 0 0;
+ padding: 5px;
+ border: 1px solid #666;
+ }
+
+ a[data-wysihtml5-command-value="red"] {
+ color: red;
+ }
+
+ a[data-wysihtml5-command-value="green"] {
+ color: green;
+ }
+
+ a[data-wysihtml5-command-value="blue"] {
+ color: blue;
+ }
+
+ code {
+ background: #ddd;
+ padding: 10px;
+ white-space: pre;
+ display: block;
+ margin: 1em 0;
+ }
+
+ .toolbar {
+ display: block;
+ border-radius: 3px;
+ border: 1px solid #fff;
+ margin-bottom: 10px;
+ }
+ .toolbar a {
+ display: inline-block;
+ height: 1.7em;
+ border-radius: 3px;
+ font-size: 11px;
+ line-height: 1.7em;
+ text-decoration: none;
+ background: #e1e1e1;
+ border: 1px solid #ddd;
+ padding: 0 0.5em;
+ margin: 1px 0;
+ }
+ .toolbar a.active {
+ background: #222;
+ color: white;
+ }
+ .toolbar .block {
+ padding: 2px 3px;
+ display: inline-block;
+ background: #eee;
+ border-radius: 3px;
+ margin: 2px 2px 2px 0;
+ }
+
+ .wysihtml5-editor table td, .wysihtml5-editor table th {
+ outline: 1px dotted #ddd;
+ }
+ .wysihtml5-editor table .wysiwyg-tmp-selected-cell {
+ outline: 1px solid green;
+ }
+
+ .toolbar .color-btn, .toolbar .bg-color-btn {
+ height: 1.7em;
+ width: 1.7em;
+ text-align: center;
+ border: 2px solid #ddd;
+ padding:0;
+ margin:0;
+ color: white;
+ }
+
+ .toolbar .color-btn.active, .toolbar .bg-color-btn.active {
+ border: 2px solid #333;
+ }
+
+</style>
+
+<h1>wysihtml5 - Advanced Editor Example</h1>
+
+<div class="ewrapper">
+ <div class="toolbar">
+
+ <div class="block">
+ <a id="boldbtn" class="editor-btn">bold</a>
+ <a id="italicbtn" class="editor-btn">italic</a>
+
+ <a id="colorbtn" class="editor-btn">color</a>
+ <span style="display:none" id="colorBtns">
+ <a class="color-btn" style="background-color: rgb(255,0,0)" data-value="rgb(255,0,0)">R</a>
+ <a class="color-btn" style="background-color: rgb(0,255,0)" data-value="rgb(0,255,0)">G</a>
+ <a class="color-btn" style="background-color: rgb(0,0,255)" data-value="rgb(0,0,255)">B</a>
+ </span>
+
+ <a id="bgcolorbtn" class="editor-btn">BG color</a>
+ <span style="display:none" id="bgColorBtns">
+ <a class="bg-color-btn" style="background-color: rgb(255,128,128)" data-value="rgb(255,128,128)">R</a>
+ <a class="bg-color-btn" style="background-color: rgb(128,255,128)" data-value="rgb(128,255,128)">G</a>
+ <a class="bg-color-btn" style="background-color: rgb(128,128,255)" data-value="rgb(128,128,255)">B</a>
+ </span>
+
+
+ <a id="fontSizeSmaller" class="editor-btn">-</a>
+ <input type="text" style="width: 30px; border: none; text-align: right;" id="fontSize"/>
+ <a id="fontSizeRemove" class="editor-btn">x</a>
+ <a id="fontSizeBigger" class="editor-btn">+</a>
+
+
+ <span style="display:none" id="tableBtns">
+
+ <a id="addRowAbove" class="editor-btn">+⋀</a>
+ <a id="addRowBelow" class="editor-btn">+⋁</a>
+ <a id="addRowBefore" class="editor-btn">+<</a>
+ <a id="addRowAfter" class="editor-btn">+></a>
+
+
+ <a id="removeRow" class="editor-btn">-=</a>
+ <a id="removeCol" class="editor-btn">-||</a>
+
+
+ <a id="merge" class="editor-btn">[ ]</a>
+ </span>
+
+ <a id="leftbtn" class="editor-btn">Left</a>
+ <a id="centerbtn" class="editor-btn">Center</a>
+ <a id="rightbtn" class="editor-btn">Right</a>
+
+ </div>
+ </div><!-- toolbar -->
+
+ <div class="editable" data-placeholder="Enter text ...">
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam egestas nisl augue, a fermentum quam laoreet at. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Pellentesque ullamcorper ultrices nibh mollis mattis. Etiam ac fermentum nisi. Sed sagittis porta augue, vel congue mi. Vivamus egestas vestibulum sem, a suscipit libero faucibus ut. Quisque mauris metus, imperdiet at velit a, suscipit fermentum ante. Nullam pretium mauris at risus eleifend ultrices. Vestibulum ullamcorper mattis est non lobortis. Donec consequat magna quis felis mollis tristique. Fusce sed congue felis.
+ <div contentEditable="false" class="wysihtml5-uneditable-container" style="padding: 10px; border: 1px dotted gray;">
+ Aenean ut nulla orci. Praesent id mollis massa. Fusce interdum eleifend bibendum. Nulla luctus nisl sit amet sapien sodales ornare. Duis blandit, purus eu egestas pretium, nisi augue aliquet quam, non suscipit diam velit eu enim. Suspendisse vulputate nibh et porta eleifend. Pellentesque rhoncus hendrerit quam. Ut sit amet ligula ac tortor porta ullamcorper.
+ </div>
+ Aenean ut nulla orci. Praesent id mollis massa. Fusce interdum eleifend bibendum. Nulla luctus nisl sit amet sapien sodales ornare. Duis blandit, purus eu egestas pretium, nisi augue aliquet quam, non suscipit diam velit eu enim. Suspendisse vulputate nibh et porta eleifend. Pellentesque rhoncus hendrerit quam. Ut sit amet ligula ac tortor porta ullamcorper.
+
+ Nulla facilisi. Ut quis pellentesque nisi, eget convallis nisi. Fusce dapibus tortor sem, et blandit nunc porttitor eget. Etiam eu nulla id nibh aliquet semper ut ut lorem. Nullam dapibus massa interdum interdum vehicula. Sed ante urna, pulvinar ut lacinia hendrerit, tristique ut enim. Fusce euismod adipiscing justo, nec malesuada massa sodales a. Integer pulvinar sed ligula et consectetur. Curabitur pulvinar cursus venenatis. Morbi in justo eget ipsum rhoncus accumsan. Sed felis orci, sodales eget est sit amet, sollicitudin lacinia justo. Aliquam et eros faucibus, tincidunt leo at, feugiat eros. Duis malesuada laoreet lorem eu molestie. Nulla vestibulum tincidunt diam ut placerat.
+
+ Aenean pretium diam nunc, at imperdiet elit vehicula a. Mauris nec felis non sem condimentum adipiscing ut et lacus. Donec facilisis facilisis lacinia. Nam posuere at nulla ut malesuada. Fusce ultricies lectus eu iaculis molestie. Ut consequat id magna et placerat. Nulla sed ante lectus. Donec congue, velit in ultricies tempus, felis lectus tempus sem, non bibendum lorem mi vel lorem. Mauris a placerat dui, nec auctor erat.
+
+ Suspendisse id mauris vel urna venenatis pharetra. Pellentesque luctus et nulla in vulputate. Donec id ligula id enim congue convallis id eu nibh. Phasellus a leo non dui porta sodales ac vel justo. Etiam sed dignissim ligula. Morbi consequat adipiscing risus vitae accumsan. Curabitur dignissim nec quam non blandit. Etiam venenatis, est a facilisis convallis, mauris nibh ultricies sapien, eget egestas neque eros sed libero. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas et velit sit amet quam pulvinar accumsan. Donec id sollicitudin dolor.
+ <table>
+ <tr>
+ <th>1 </th><th>2 </th><th>3 </th>
+ </tr>
+ <tr>
+ <td>4 </td><td> </td><td> </td>
+ </tr>
+ <tr>
+ <td>7 </td><td> </td><td> </td>
+ </tr>
+ </table>
+
+ </div>
+</div>
+
+<!-- oldschool clearfix -->
+<div style="height: 1px; width: 100%; overflow: hidden; clear: both"></div>
+
+
+<br>
+
+<h2>Events:</h2>
+<div id="log"></div>
+
+<small>powered by <a href="https://github.com/xing/wysihtml5" target="_blank">wysihtml5</a>.</small>
+
+<script src="jquery.1.10.2.js" type="text/javascript" charset="utf-8"></script>
+
+
+<script src="../parser_rules/advanced_unwrap.js"></script>
+<script src="../dist/wysihtml5x.min.js"></script>
+<script>
+
+
+
+ var editor = new wysihtml5.Editor($('.editable').get(0), {
+ parserRules: wysihtml5ParserRules
+ //showToolbarAfterInit: false
+ }),
+ composer = editor.composer;
+
+ function updateStates() {
+ var value;
+
+ if (composer.commands.state('bold')) {
+ $('#boldbtn').addClass('active');
+ } else {
+ $('#boldbtn').removeClass('active');
+ }
+
+ if (composer.commands.state('italic')) {
+ $('#italicbtn').addClass('active');
+ } else {
+ $('#italicbtn').removeClass('active');
+ }
+
+ if (composer.commands.state('mergeTableCells')) {
+ $('#merge').addClass('active');
+ } else {
+ $('#merge').removeClass('active');
+ }
+
+ if (composer.commands.state('alignLeftStyle')) {
+ $('#leftbtn').addClass('active');
+ } else {
+ $('#leftbtn').removeClass('active');
+ }
+
+ if (composer.commands.state('alignRightStyle')) {
+ $('#rightbtn').addClass('active');
+ } else {
+ $('#rightbtn').removeClass('active');
+ }
+
+ if (composer.commands.state('alignCenterStyle')) {
+ $('#centerbtn').addClass('active');
+ } else {
+ $('#centerbtn').removeClass('active');
+ }
+
+ if (composer.commands.state('foreColorStyle')) {
+ $('#colorbtn').addClass('active');
+ value = composer.commands.stateValue('foreColorStyle');
+ $('.color-btn.active').removeClass('active');
+ if (value) {
+ $('.color-btn[data-value="'+ value +'"]').addClass('active');
+ }
+
+ $('#colorBtns').show();
+
+ } else {
+ $('#colorbtn').removeClass('active');
+ $('#colorBtns').hide();
+ }
+
+ if (composer.commands.state('bgColorStyle')) {
+ $('#bgcolorbtn').addClass('active');
+ value = composer.commands.stateValue('bgColorStyle');
+ $('.bg-color-btn.active').removeClass('active');
+ if (value) {
+ $('.bg-color-btn[data-value="'+ value +'"]').addClass('active');
+ }
+
+ $('#bgColorBtns').show();
+
+ } else {
+ $('#bgcolorbtn').removeClass('active');
+ $('#bgColorBtns').hide();
+ }
+
+ // font size state
+ if (composer.commands.state('fontSizeStyle')) {
+ $('#fontSize').val(composer.commands.stateValue('fontSizeStyle'));
+ $('#fontSizeRemove').addClass('active');
+ } else {
+ $('#fontSize').val('');
+ $('#fontSizeRemove').removeClass('active');
+ }
+
+ }
+
+// Listen to events and update menu
+ editor.on("interaction", function() {
+ updateStates();
+ });
+
+ editor.on("tableselect", function() {
+ $('#tableBtns').show();
+ });
+
+ editor.on("tableunselect", function() {
+ $('#tableBtns').hide();
+ });
+
+// Prevent buttons from deselecting selected text before action is performed
+ $(".editor-btn").mousedown(function(event){
+ var b = composer.selection.getBookmark();
+ event.preventDefault();
+
+ // ie8 bug fix. mousedown does not prevent loosing focus
+ setTimeout(function() {
+ composer.selection.setBookmark(b);
+ }, 0);
+
+ });
+
+// commands binding
+ $('#boldbtn').click(function(event) {
+ event.preventDefault();
+ composer.commands.exec('bold');
+ updateStates();
+ });
+
+ $('#italicbtn').click(function(event) {
+ event.preventDefault();
+ composer.commands.exec('italic');
+ updateStates();
+ });
+
+ $('#leftbtn').click(function(event) {
+ event.preventDefault();
+ composer.commands.exec('alignLeftStyle');
+ updateStates();
+ });
+
+ $('#rightbtn').click(function(event) {
+ event.preventDefault();
+ composer.commands.exec('alignRightStyle');
+ updateStates();
+ });
+
+ $('#centerbtn').click(function(event) {
+ event.preventDefault();
+ composer.commands.exec('alignCenterStyle');
+ updateStates();
+ });
+
+
+
+ //table
+ $('#addRowBelow').click(function(event) {
+ event.preventDefault();
+ composer.commands.exec("addTableCells", "below");
+ });
+
+ $('#addRowAbove').click(function(event) {
+ event.preventDefault();
+ composer.commands.exec("addTableCells", "above");
+ });
+
+ $('#addRowBefore').click(function(event) {
+ event.preventDefault();
+ composer.commands.exec("addTableCells", "before");
+ });
+
+ $('#addRowAfter').click(function(event) {
+ event.preventDefault();
+ composer.commands.exec("addTableCells", "after");
+ });
+
+ $('#removeRow').click(function(event) {
+ event.preventDefault();
+ composer.commands.exec("deleteTableCells", "row");
+ });
+
+ $('#removeCol').click(function(event) {
+ event.preventDefault();
+ composer.commands.exec("deleteTableCells", "column");
+ });
+
+ $('#merge').click(function(event) {
+ event.preventDefault();
+ composer.commands.exec("mergeTableCells");
+ });
+
+
+
+ // color by style
+ $('#colorbtn').click(function(event) {
+ event.preventDefault();
+ $('#colorBtns').show();
+ });
+
+ $('.color-btn').mousedown(function(event) {
+ event.preventDefault();
+ event.stopPropagation();
+ var val = $(this).data("value");
+ composer.commands.exec("foreColorStyle", val);
+ updateStates();
+ });
+
+ $('#bgcolorbtn').click(function(event) {
+ event.preventDefault();
+ $('#bgColorBtns').show();
+ });
+
+ $('.bg-color-btn').mousedown(function(event) {
+ event.preventDefault();
+ event.stopPropagation();
+ var val = $(this).data("value");
+ composer.commands.exec("bgColorStyle", val);
+ updateStates();
+ });
+
+// font size actions
+ var selBookmark = null;
+ $('#fontSize').mousedown(function() {
+ if (selBookmark == null) {
+ selBookmark = composer.selection.getBookmark();
+ }
+ });
+
+ $('#fontSize').change(function(){
+ if (selBookmark) {
+ setTimeout(function() {
+ composer.selection.setBookmark(selBookmark);
+ composer.commands.exec("fontSizeStyle", $('#fontSize').val());
+ selBookmark = null;
+ },0);
+ }
+ });
+
+ $('#fontSize').keydown(function(event) {
+ if (event.which == 13) {
+ event.preventDefault();
+ $('#fontSize').trigger('blur');
+ }
+ });
+
+ $('#fontSizeSmaller').click(function(event) {
+ event.preventDefault();
+ selBookmark = composer.selection.getBookmark();
+ var val = $('#fontSize').val(),
+ nr;
+ if (val && !(/^\s*$/).test(val)) {
+ nr = parseInt(val, 10);
+ if (nr > 1) {
+ $('#fontSize').val(val.replace(/\d+/, nr -1)).trigger('change');
+ selBookmark = null;
+ }
+ }
+ });
+
+ $('#fontSizeBigger').click(function(event) {
+ event.preventDefault();
+ selBookmark = composer.selection.getBookmark();
+ var val = $('#fontSize').val(),
+ nr;
+ if (val && !(/^\s*$/).test(val)) {
+ nr = parseInt(val, 10);
+ $('#fontSize').val(val.replace(/\d+/, nr +1)).trigger('change');
+ selBookmark = null;
+ }
+ });
+
+ // executing with same value removes size
+ $('#fontSizeRemove').click(function(event) {
+ event.preventDefault();
+ var val = composer.commands.stateValue('fontSizeStyle');
+ if (val) {
+ composer.commands.exec("fontSizeStyle", val);
+ selBookmark = null;
+ }
+ });
+
+</script>
\ No newline at end of file
--- /dev/null
+/*
+ Base.js, version 1.1a
+ Copyright 2006-2010, Dean Edwards
+ License: http://www.opensource.org/licenses/mit-license.php
+*/
+
+var Base = function() {
+ // dummy
+};
+
+Base.extend = function(_instance, _static) { // subclass
+ var extend = Base.prototype.extend;
+
+ // build the prototype
+ Base._prototyping = true;
+ var proto = new this;
+ extend.call(proto, _instance);
+ proto.base = function() {
+ // call this method from any other method to invoke that method's ancestor
+ };
+ delete Base._prototyping;
+
+ // create the wrapper for the constructor function
+ //var constructor = proto.constructor.valueOf(); //-dean
+ var constructor = proto.constructor;
+ var klass = proto.constructor = function() {
+ if (!Base._prototyping) {
+ if (this._constructing || this.constructor == klass) { // instantiation
+ this._constructing = true;
+ constructor.apply(this, arguments);
+ delete this._constructing;
+ } else if (arguments[0] != null) { // casting
+ return (arguments[0].extend || extend).call(arguments[0], proto);
+ }
+ }
+ };
+
+ // build the class interface
+ klass.ancestor = this;
+ klass.extend = this.extend;
+ klass.forEach = this.forEach;
+ klass.implement = this.implement;
+ klass.prototype = proto;
+ klass.toString = this.toString;
+ klass.valueOf = function(type) {
+ //return (type == "object") ? klass : constructor; //-dean
+ return (type == "object") ? klass : constructor.valueOf();
+ };
+ extend.call(klass, _static);
+ // class initialisation
+ if (typeof klass.init == "function") klass.init();
+ return klass;
+};
+
+Base.prototype = {
+ extend: function(source, value) {
+ if (arguments.length > 1) { // extending with a name/value pair
+ var ancestor = this[source];
+ if (ancestor && (typeof value == "function") && // overriding a method?
+ // the valueOf() comparison is to avoid circular references
+ (!ancestor.valueOf || ancestor.valueOf() != value.valueOf()) &&
+ /\bbase\b/.test(value)) {
+ // get the underlying method
+ var method = value.valueOf();
+ // override
+ value = function() {
+ var previous = this.base || Base.prototype.base;
+ this.base = ancestor;
+ var returnValue = method.apply(this, arguments);
+ this.base = previous;
+ return returnValue;
+ };
+ // point to the underlying method
+ value.valueOf = function(type) {
+ return (type == "object") ? value : method;
+ };
+ value.toString = Base.toString;
+ }
+ this[source] = value;
+ } else if (source) { // extending with an object literal
+ var extend = Base.prototype.extend;
+ // if this object has a customised extend method then use it
+ if (!Base._prototyping && typeof this != "function") {
+ extend = this.extend || extend;
+ }
+ var proto = {toSource: null};
+ // do the "toString" and other methods manually
+ var hidden = ["constructor", "toString", "valueOf"];
+ // if we are prototyping then include the constructor
+ var i = Base._prototyping ? 0 : 1;
+ while (key = hidden[i++]) {
+ if (source[key] != proto[key]) {
+ extend.call(this, key, source[key]);
+
+ }
+ }
+ // copy each of the source object's properties to this object
+ for (var key in source) {
+ if (!proto[key]) extend.call(this, key, source[key]);
+ }
+ }
+ return this;
+ }
+};
+
+// initialise
+Base = Base.extend({
+ constructor: function() {
+ this.extend(arguments[0]);
+ }
+}, {
+ ancestor: Object,
+ version: "1.1",
+
+ forEach: function(object, block, context) {
+ for (var key in object) {
+ if (this.prototype[key] === undefined) {
+ block.call(context, object[key], key, object);
+ }
+ }
+ },
+
+ implement: function() {
+ for (var i = 0; i < arguments.length; i++) {
+ if (typeof arguments[i] == "function") {
+ // if it's a function, call it
+ arguments[i](this.prototype);
+ } else {
+ // add the interface using the extend method
+ this.prototype.extend(arguments[i]);
+ }
+ }
+ return this;
+ },
+
+ toString: function() {
+ return String(this.valueOf());
+ }
+});
\ No newline at end of file
--- /dev/null
+{
+ "name": "wysihtml5x",
+ "version": "0.4.17",
+ "devDependencies": {
+ "grunt": "~0.4.4",
+ "grunt-contrib-concat": "~0.4.0",
+ "grunt-contrib-jshint": "~0.6.3",
+ "grunt-contrib-nodeunit": "~0.2.0",
+ "grunt-contrib-uglify": "~0.3.0",
+ "happen": "^0.1.3",
+ "qunitjs": "1.15.0",
+ "qunit-assert-html": "^0.2.3"
+ },
+ "dependencies": {
+ "rangy": "^1.3.0-alpha.20140921"
+ },
+ "description": "h1. wysihtml5x 0.4.17",
+ "main": "Gruntfile.js",
+ "directories": {
+ "example": "examples",
+ "test": "test"
+ },
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/Edicy/wysihtml5"
+ },
+ "author": "XING AG",
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/Edicy/wysihtml5/issues"
+ },
+ "homepage": "https://github.com/Edicy/wysihtml5"
+}
--- /dev/null
+/**
+ * Full HTML5 compatibility rule set
+ * These rules define which tags and CSS classes are supported and which tags should be specially treated.
+ *
+ * Examples based on this rule set:
+ *
+ * <a href="http://foobar.com">foo</a>
+ * ... becomes ...
+ * <a href="http://foobar.com" target="_blank" rel="nofollow">foo</a>
+ *
+ * <img align="left" src="http://foobar.com/image.png">
+ * ... becomes ...
+ * <img class="wysiwyg-float-left" src="http://foobar.com/image.png" alt="">
+ *
+ * <div>foo<script>alert(document.cookie)</script></div>
+ * ... becomes ...
+ * <div>foo</div>
+ *
+ * <marquee>foo</marquee>
+ * ... becomes ...
+ * <span>foo</span>
+ *
+ * foo <br clear="both"> bar
+ * ... becomes ...
+ * foo <br class="wysiwyg-clear-both"> bar
+ *
+ * <div>hello <iframe src="http://google.com"></iframe></div>
+ * ... becomes ...
+ * <div>hello </div>
+ *
+ * <center>hello</center>
+ * ... becomes ...
+ * <div class="wysiwyg-text-align-center">hello</div>
+ */
+var wysihtml5ParserRules = {
+ /**
+ * CSS Class white-list
+ * Following CSS classes won't be removed when parsed by the wysihtml5 HTML parser
+ */
+ "classes": {
+ "wysiwyg-clear-both": 1,
+ "wysiwyg-clear-left": 1,
+ "wysiwyg-clear-right": 1,
+ "wysiwyg-color-aqua": 1,
+ "wysiwyg-color-black": 1,
+ "wysiwyg-color-blue": 1,
+ "wysiwyg-color-fuchsia": 1,
+ "wysiwyg-color-gray": 1,
+ "wysiwyg-color-green": 1,
+ "wysiwyg-color-lime": 1,
+ "wysiwyg-color-maroon": 1,
+ "wysiwyg-color-navy": 1,
+ "wysiwyg-color-olive": 1,
+ "wysiwyg-color-purple": 1,
+ "wysiwyg-color-red": 1,
+ "wysiwyg-color-silver": 1,
+ "wysiwyg-color-teal": 1,
+ "wysiwyg-color-white": 1,
+ "wysiwyg-color-yellow": 1,
+ "wysiwyg-float-left": 1,
+ "wysiwyg-float-right": 1,
+ "wysiwyg-font-size-large": 1,
+ "wysiwyg-font-size-larger": 1,
+ "wysiwyg-font-size-medium": 1,
+ "wysiwyg-font-size-small": 1,
+ "wysiwyg-font-size-smaller": 1,
+ "wysiwyg-font-size-x-large": 1,
+ "wysiwyg-font-size-x-small": 1,
+ "wysiwyg-font-size-xx-large": 1,
+ "wysiwyg-font-size-xx-small": 1,
+ "wysiwyg-text-align-center": 1,
+ "wysiwyg-text-align-justify": 1,
+ "wysiwyg-text-align-left": 1,
+ "wysiwyg-text-align-right": 1
+ },
+ /**
+ * Tag list
+ *
+ * The following options are available:
+ *
+ * - add_class: converts and deletes the given HTML4 attribute (align, clear, ...) via the given method to a css class
+ * The following methods are implemented in wysihtml5.dom.parse:
+ * - align_text: converts align attribute values (right/left/center/justify) to their corresponding css class "wysiwyg-text-align-*")
+ * <p align="center">foo</p> ... becomes ... <p class="wysiwyg-text-align-center">foo</p>
+ * - clear_br: converts clear attribute values left/right/all/both to their corresponding css class "wysiwyg-clear-*"
+ * <br clear="all"> ... becomes ... <br class="wysiwyg-clear-both">
+ * - align_img: converts align attribute values (right/left) on <img> to their corresponding css class "wysiwyg-float-*"
+ *
+ * - add_style: converts and deletes the given HTML4 attribute (align) via the given method to a css style
+ * The following methods are implemented in wysihtml5.dom.parse:
+ * - align_text: converts align attribute values (right/left/center) to their corresponding css style)
+ * <p align="center">foo</p> ... becomes ... <p style="text-align:center">foo</p>
+ *
+ * - remove: removes the element and its content
+ *
+ * - unwrap removes element but leaves content
+ *
+ * - rename_tag: renames the element to the given tag
+ *
+ * - set_class: adds the given class to the element (note: make sure that the class is in the "classes" white list above)
+ *
+ * - set_attributes: sets/overrides the given attributes
+ *
+ * - check_attributes: checks the given HTML attribute via the given method
+ * - url: allows only valid urls (starting with http:// or https://)
+ * - src: allows something like "/foobar.jpg", "http://google.com", ...
+ * - href: allows something like "mailto:bert@foo.com", "http://google.com", "/foobar.jpg"
+ * - alt: strips unwanted characters. if the attribute is not set, then it gets set (to ensure valid and compatible HTML)
+ * - numbers: ensures that the attribute only contains numeric characters
+ * - any: allows anything to pass
+ */
+ "tags": {
+ "tr": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "strike": {
+ "remove": 1
+ },
+ "form": {
+ "rename_tag": "div"
+ },
+ "rt": {
+ "rename_tag": "span"
+ },
+ "code": {},
+ "acronym": {
+ "rename_tag": "span"
+ },
+ "br": {
+ "add_class": {
+ "clear": "clear_br"
+ }
+ },
+ "details": {
+ "rename_tag": "div"
+ },
+ "h4": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "em": {},
+ "title": {
+ "remove": 1
+ },
+ "multicol": {
+ "rename_tag": "div"
+ },
+ "figure": {
+ "rename_tag": "div"
+ },
+ "xmp": {
+ "rename_tag": "span"
+ },
+ "small": {
+ "rename_tag": "span",
+ "set_class": "wysiwyg-font-size-smaller"
+ },
+ "area": {
+ "remove": 1
+ },
+ "time": {
+ "rename_tag": "span"
+ },
+ "dir": {
+ "rename_tag": "ul"
+ },
+ "bdi": {
+ "rename_tag": "span"
+ },
+ "command": {
+ "remove": 1
+ },
+ "ul": {},
+ "progress": {
+ "rename_tag": "span"
+ },
+ "dfn": {
+ "rename_tag": "span"
+ },
+ "iframe": {
+ "remove": 1
+ },
+ "figcaption": {
+ "rename_tag": "div"
+ },
+ "a": {
+ "check_attributes": {
+ "target": "any",
+ "href": "url" // if you compiled master manually then change this from 'url' to 'href'
+ },
+ "set_attributes": {
+ "rel": "nofollow"
+ }
+ },
+ "img": {
+ "check_attributes": {
+ "width": "numbers",
+ "alt": "alt",
+ "src": "url", // if you compiled master manually then change this from 'url' to 'src'
+ "height": "numbers"
+ },
+ "add_class": {
+ "align": "align_img"
+ }
+ },
+ "rb": {
+ "rename_tag": "span"
+ },
+ "footer": {
+ "rename_tag": "div"
+ },
+ "noframes": {
+ "remove": 1
+ },
+ "abbr": {
+ "rename_tag": "span"
+ },
+ "u": {},
+ "bgsound": {
+ "remove": 1
+ },
+ "sup": {
+ "rename_tag": "span"
+ },
+ "address": {
+ "rename_tag": "div"
+ },
+ "basefont": {
+ "remove": 1
+ },
+ "nav": {
+ "rename_tag": "div"
+ },
+ "h1": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "head": {
+ "remove": 1
+ },
+ "tbody": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "dd": {
+ "rename_tag": "div"
+ },
+ "s": {
+ "rename_tag": "span"
+ },
+ "li": {},
+ "td": {
+ "check_attributes": {
+ "rowspan": "numbers",
+ "colspan": "numbers"
+ },
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "object": {
+ "remove": 1
+ },
+ "div": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "option": {
+ "rename_tag": "span"
+ },
+ "select": {
+ "rename_tag": "span"
+ },
+ "i": {},
+ "track": {
+ "remove": 1
+ },
+ "wbr": {
+ "remove": 1
+ },
+ "fieldset": {
+ "rename_tag": "div"
+ },
+ "big": {
+ "rename_tag": "span",
+ "set_class": "wysiwyg-font-size-larger"
+ },
+ "button": {
+ "rename_tag": "span"
+ },
+ "noscript": {
+ "remove": 1
+ },
+ "svg": {
+ "remove": 1
+ },
+ "input": {
+ "remove": 1
+ },
+ "table": {},
+ "keygen": {
+ "remove": 1
+ },
+ "h5": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "meta": {
+ "remove": 1
+ },
+ "map": {
+ "rename_tag": "div"
+ },
+ "isindex": {
+ "remove": 1
+ },
+ "mark": {
+ "rename_tag": "span"
+ },
+ "caption": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "tfoot": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "base": {
+ "remove": 1
+ },
+ "video": {
+ "remove": 1
+ },
+ "strong": {},
+ "canvas": {
+ "remove": 1
+ },
+ "output": {
+ "rename_tag": "span"
+ },
+ "marquee": {
+ "rename_tag": "span"
+ },
+ "b": {},
+ "q": {
+ "check_attributes": {
+ "cite": "url"
+ }
+ },
+ "applet": {
+ "remove": 1
+ },
+ "span": {},
+ "rp": {
+ "rename_tag": "span"
+ },
+ "spacer": {
+ "remove": 1
+ },
+ "source": {
+ "remove": 1
+ },
+ "aside": {
+ "rename_tag": "div"
+ },
+ "frame": {
+ "remove": 1
+ },
+ "section": {
+ "rename_tag": "div"
+ },
+ "body": {
+ "rename_tag": "div"
+ },
+ "ol": {},
+ "nobr": {
+ "rename_tag": "span"
+ },
+ "html": {
+ "rename_tag": "div"
+ },
+ "summary": {
+ "rename_tag": "span"
+ },
+ "var": {
+ "rename_tag": "span"
+ },
+ "del": {
+ "remove": 1
+ },
+ "blockquote": {
+ "check_attributes": {
+ "cite": "url"
+ }
+ },
+ "style": {
+ "remove": 1
+ },
+ "device": {
+ "remove": 1
+ },
+ "meter": {
+ "rename_tag": "span"
+ },
+ "h3": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "textarea": {
+ "rename_tag": "span"
+ },
+ "embed": {
+ "remove": 1
+ },
+ "hgroup": {
+ "rename_tag": "div"
+ },
+ "font": {
+ "rename_tag": "span",
+ "add_class": {
+ "size": "size_font"
+ }
+ },
+ "tt": {
+ "rename_tag": "span"
+ },
+ "noembed": {
+ "remove": 1
+ },
+ "thead": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "blink": {
+ "rename_tag": "span"
+ },
+ "plaintext": {
+ "rename_tag": "span"
+ },
+ "xml": {
+ "remove": 1
+ },
+ "h6": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "param": {
+ "remove": 1
+ },
+ "th": {
+ "check_attributes": {
+ "rowspan": "numbers",
+ "colspan": "numbers"
+ },
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "legend": {
+ "rename_tag": "span"
+ },
+ "hr": {},
+ "label": {
+ "rename_tag": "span"
+ },
+ "dl": {
+ "rename_tag": "div"
+ },
+ "kbd": {
+ "rename_tag": "span"
+ },
+ "listing": {
+ "rename_tag": "div"
+ },
+ "dt": {
+ "rename_tag": "span"
+ },
+ "nextid": {
+ "remove": 1
+ },
+ "pre": {},
+ "center": {
+ "rename_tag": "div",
+ "set_class": "wysiwyg-text-align-center"
+ },
+ "audio": {
+ "remove": 1
+ },
+ "datalist": {
+ "rename_tag": "span"
+ },
+ "samp": {
+ "rename_tag": "span"
+ },
+ "col": {
+ "remove": 1
+ },
+ "article": {
+ "rename_tag": "div"
+ },
+ "cite": {},
+ "link": {
+ "remove": 1
+ },
+ "script": {
+ "remove": 1
+ },
+ "bdo": {
+ "rename_tag": "span"
+ },
+ "menu": {
+ "rename_tag": "ul"
+ },
+ "colgroup": {
+ "remove": 1
+ },
+ "ruby": {
+ "rename_tag": "span"
+ },
+ "h2": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "ins": {
+ "rename_tag": "span"
+ },
+ "p": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "sub": {
+ "rename_tag": "span"
+ },
+ "comment": {
+ "remove": 1
+ },
+ "frameset": {
+ "remove": 1
+ },
+ "optgroup": {
+ "rename_tag": "span"
+ },
+ "header": {
+ "rename_tag": "div"
+ }
+ }
+};
--- /dev/null
+/**
+ * Full HTML5 compatibility rule set
+ * Loosened and extended ruleset. Allows more freedom on user side
+ * These rules define which tags and CSS classes are supported and which tags should be specially treated.
+ */
+
+var wysihtml5ParserRulesDefaults = {
+ "blockLevelEl": {
+ "keep_styles": {
+ "textAlign": /^((left)|(right)|(center)|(justify))$/i,
+ "float": 1
+ },
+ "add_style": {
+ "align": "align_text"
+ },
+ "check_attributes": {
+ "id": "any"
+ }
+ },
+
+ "makeDiv": {
+ "rename_tag": "div",
+ "one_of_type": {
+ "alignment_object": 1
+ },
+ "remove_action": "unwrap",
+ "keep_styles": {
+ "textAlign": 1,
+ "float": 1
+ },
+ "add_style": {
+ "align": "align_text"
+ },
+ "check_attributes": {
+ "id": "any"
+ }
+ }
+};
+
+var wysihtml5ParserRules = {
+ /**
+ * CSS Class white-list
+ * Following CSS classes won't be removed when parsed by the wysihtml5 HTML parser
+ * If all classes should pass "any" as classes value. Ex: "classes": "any"
+ */
+ "classes": "any",
+
+ /* blacklist of classes is only available if classes is set to any */
+ "classes_blacklist": {
+ "Apple-interchange-newline": 1,
+ "MsoNormal": 1,
+ "MsoPlainText": 1
+ },
+
+ "type_definitions": {
+
+ "alignment_object": {
+ "classes": {
+ "wysiwyg-text-align-center": 1,
+ "wysiwyg-text-align-justify": 1,
+ "wysiwyg-text-align-left": 1,
+ "wysiwyg-text-align-right": 1,
+ "wysiwyg-float-left": 1,
+ "wysiwyg-float-right": 1
+ },
+ "styles": {
+ "float": ["left", "right"],
+ "text-align": ["left", "right", "center"]
+ }
+ },
+
+ "valid_image_src": {
+ "attrs": {
+ "src": /^[^data\:]/i
+ }
+ },
+
+ "text_color_object": {
+ "styles": {
+ "color": true,
+ "background-color": true
+ }
+ },
+
+ "text_fontsize_object": {
+ "styles": {
+ "font-size": true
+ }
+ },
+
+ "text_formatting_object": {
+ "classes": {
+ "wysiwyg-color-aqua": 1,
+ "wysiwyg-color-black": 1,
+ "wysiwyg-color-blue": 1,
+ "wysiwyg-color-fuchsia": 1,
+ "wysiwyg-color-gray": 1,
+ "wysiwyg-color-green": 1,
+ "wysiwyg-color-lime": 1,
+ "wysiwyg-color-maroon": 1,
+ "wysiwyg-color-navy": 1,
+ "wysiwyg-color-olive": 1,
+ "wysiwyg-color-purple": 1,
+ "wysiwyg-color-red": 1,
+ "wysiwyg-color-silver": 1,
+ "wysiwyg-color-teal": 1,
+ "wysiwyg-color-white": 1,
+ "wysiwyg-color-yellow": 1,
+ "wysiwyg-font-size-large": 1,
+ "wysiwyg-font-size-larger": 1,
+ "wysiwyg-font-size-medium": 1,
+ "wysiwyg-font-size-small": 1,
+ "wysiwyg-font-size-smaller": 1,
+ "wysiwyg-font-size-x-large": 1,
+ "wysiwyg-font-size-x-small": 1,
+ "wysiwyg-font-size-xx-large": 1,
+ "wysiwyg-font-size-xx-small": 1
+ }
+ }
+ },
+
+ "comments": 1, // if set allows comments to pass
+
+ /**
+ * Tag list
+ *
+ * The following options are available:
+ *
+ * - add_class: converts and deletes the given HTML4 attribute (align, clear, ...) via the given method to a css class
+ * The following methods are implemented in wysihtml5.dom.parse:
+ * - align_text: converts align attribute values (right/left/center/justify) to their corresponding css class "wysiwyg-text-align-*")
+ * <p align="center">foo</p> ... becomes ... <p> class="wysiwyg-text-align-center">foo</p>
+ * - clear_br: converts clear attribute values left/right/all/both to their corresponding css class "wysiwyg-clear-*"
+ * <br clear="all"> ... becomes ... <br class="wysiwyg-clear-both">
+ * - align_img: converts align attribute values (right/left) on <img> to their corresponding css class "wysiwyg-float-*"
+ *
+ * - remove: removes the element and its content
+ *
+ * - unwrap removes element but leaves content
+ *
+ * - rename_tag: renames the element to the given tag
+ *
+ * - set_class: adds the given class to the element (note: make sure that the class is in the "classes" white list above)
+ *
+ * - set_attributes: sets/overrides the given attributes
+ *
+ * - check_attributes: checks the given HTML attribute via the given method
+ * - url: allows only valid urls (starting with http:// or https://)
+ * - src: allows something like "/foobar.jpg", "http://google.com", ...
+ * - href: allows something like "mailto:bert@foo.com", "http://google.com", "/foobar.jpg"
+ * - alt: strips unwanted characters. if the attribute is not set, then it gets set (to ensure valid and compatible HTML)
+ * - numbers: ensures that the attribute only contains numeric characters
+ * - any: allows anything to pass
+ */
+ "tags": {
+ "tr": {
+ "add_style": {
+ "align": "align_text"
+ },
+ "check_attributes": {
+ "id": "any"
+ }
+ },
+ "strike": {
+ "unwrap": 1
+ },
+ "form": {
+ "unwrap": 1
+ },
+ "rt": {
+ "rename_tag": "span"
+ },
+ "code": {},
+ "acronym": {
+ "rename_tag": "span"
+ },
+ "br": {
+ "add_class": {
+ "clear": "clear_br"
+ }
+ },
+ "details": {
+ "unwrap": 1
+ },
+ "h4": wysihtml5ParserRulesDefaults.blockLevelEl,
+ "em": {},
+ "title": {
+ "remove": 1
+ },
+ "multicol": {
+ "unwrap": 1
+ },
+ "figure": {
+ "unwrap": 1
+ },
+ "xmp": {
+ "unwrap": 1
+ },
+ "small": {
+ "rename_tag": "span",
+ "set_class": "wysiwyg-font-size-smaller"
+ },
+ "area": {
+ "remove": 1
+ },
+ "time": {
+ "unwrap": 1
+ },
+ "dir": {
+ "rename_tag": "ul"
+ },
+ "bdi": {
+ "unwrap": 1
+ },
+ "command": {
+ "unwrap": 1
+ },
+ "ul": {
+ "check_attributes": {
+ "id": "any"
+ }
+ },
+ "progress": {
+ "rename_tag": "span"
+ },
+ "dfn": {
+ "unwrap": 1
+ },
+ "iframe": {
+ "check_attributes": {
+ "src": "any",
+ "width": "any",
+ "height": "any",
+ "frameborder": "any",
+ "style": "any",
+ "id": "any"
+ }
+ },
+ "figcaption": {
+ "unwrap": 1
+ },
+ "a": {
+ "check_attributes": {
+ "href": "href", // if you compiled master manually then change this from 'url' to 'href'
+ "rel": "any",
+ "target": "any",
+ "id": "any"
+ }
+ },
+ "img": {
+ "one_of_type": {
+ "valid_image_src": 1
+ },
+ "check_attributes": {
+ "width": "numbers",
+ "alt": "alt",
+ "src": "src", // if you compiled master manually then change this from 'url' to 'src'
+ "height": "numbers",
+ "id": "any"
+ },
+ "add_class": {
+ "align": "align_img"
+ }
+ },
+ "rb": {
+ "unwrap": 1
+ },
+ "footer": wysihtml5ParserRulesDefaults.makeDiv,
+ "noframes": {
+ "remove": 1
+ },
+ "abbr": {
+ "unwrap": 1
+ },
+ "u": {},
+ "bgsound": {
+ "remove": 1
+ },
+ "sup": {
+ "unwrap": 1
+ },
+ "address": {
+ "unwrap": 1
+ },
+ "basefont": {
+ "remove": 1
+ },
+ "nav": {
+ "unwrap": 1
+ },
+ "h1": wysihtml5ParserRulesDefaults.blockLevelEl,
+ "head": {
+ "unwrap": 1
+ },
+ "tbody": wysihtml5ParserRulesDefaults.blockLevelEl,
+ "dd": {
+ "unwrap": 1
+ },
+ "s": {
+ "unwrap": 1
+ },
+ "li": {},
+ "td": {
+ "check_attributes": {
+ "rowspan": "numbers",
+ "colspan": "numbers",
+ "valign": "any",
+ "align": "any",
+ "id": "any",
+ "class": "any"
+ },
+ "keep_styles": {
+ "backgroundColor": 1,
+ "width": 1,
+ "height": 1
+ },
+ "add_style": {
+ "align": "align_text"
+ }
+ },
+ "object": {
+ "remove": 1
+ },
+
+ "div": {
+ "one_of_type": {
+ "alignment_object": 1
+ },
+ "remove_action": "unwrap",
+ "keep_styles": {
+ "textAlign": 1,
+ "float": 1
+ },
+ "add_style": {
+ "align": "align_text"
+ },
+ "check_attributes": {
+ "id": "any",
+ "contenteditable": "any"
+ }
+ },
+
+ "option": {
+ "remove":1
+ },
+ "select": {
+ "remove":1
+ },
+ "i": {},
+ "track": {
+ "remove": 1
+ },
+ "wbr": {
+ "remove": 1
+ },
+ "fieldset": {
+ "unwrap": 1
+ },
+ "big": {
+ "rename_tag": "span",
+ "set_class": "wysiwyg-font-size-larger"
+ },
+ "button": {
+ "unwrap": 1
+ },
+ "noscript": {
+ "remove": 1
+ },
+ "svg": {
+ "remove": 1
+ },
+ "input": {
+ "remove": 1
+ },
+ "table": {
+ "keep_styles": {
+ "width": 1,
+ "textAlign": 1,
+ "float": 1
+ },
+ "check_attributes": {
+ "id": "any"
+ }
+ },
+ "keygen": {
+ "remove": 1
+ },
+ "h5": wysihtml5ParserRulesDefaults.blockLevelEl,
+ "meta": {
+ "remove": 1
+ },
+ "map": {
+ "remove": 1
+ },
+ "isindex": {
+ "remove": 1
+ },
+ "mark": {
+ "unwrap": 1
+ },
+ "caption": wysihtml5ParserRulesDefaults.blockLevelEl,
+ "tfoot": wysihtml5ParserRulesDefaults.blockLevelEl,
+ "base": {
+ "remove": 1
+ },
+ "video": {
+ "remove": 1
+ },
+ "strong": {},
+ "canvas": {
+ "remove": 1
+ },
+ "output": {
+ "unwrap": 1
+ },
+ "marquee": {
+ "unwrap": 1
+ },
+ "b": {},
+ "q": {
+ "check_attributes": {
+ "cite": "url",
+ "id": "any"
+ }
+ },
+ "applet": {
+ "remove": 1
+ },
+ "span": {
+ "one_of_type": {
+ "text_formatting_object": 1,
+ "text_color_object": 1,
+ "text_fontsize_object": 1
+ },
+ "keep_styles": {
+ "color": 1,
+ "backgroundColor": 1,
+ "fontSize": 1
+ },
+ "remove_action": "unwrap",
+ "check_attributes": {
+ "id": "any"
+ }
+ },
+ "rp": {
+ "unwrap": 1
+ },
+ "spacer": {
+ "remove": 1
+ },
+ "source": {
+ "remove": 1
+ },
+ "aside": wysihtml5ParserRulesDefaults.makeDiv,
+ "frame": {
+ "remove": 1
+ },
+ "section": wysihtml5ParserRulesDefaults.makeDiv,
+ "body": {
+ "unwrap": 1
+ },
+ "ol": {},
+ "nobr": {
+ "unwrap": 1
+ },
+ "html": {
+ "unwrap": 1
+ },
+ "summary": {
+ "unwrap": 1
+ },
+ "var": {
+ "unwrap": 1
+ },
+ "del": {
+ "unwrap": 1
+ },
+ "blockquote": {
+ "keep_styles": {
+ "textAlign": 1,
+ "float": 1
+ },
+ "add_style": {
+ "align": "align_text"
+ },
+ "check_attributes": {
+ "cite": "url",
+ "id": "any"
+ }
+ },
+ "style": {
+ "check_attributes": {
+ "type": "any",
+ "src": "any",
+ "charset": "any"
+ }
+ },
+ "device": {
+ "remove": 1
+ },
+ "meter": {
+ "unwrap": 1
+ },
+ "h3": wysihtml5ParserRulesDefaults.blockLevelEl,
+ "textarea": {
+ "unwrap": 1
+ },
+ "embed": {
+ "remove": 1
+ },
+ "hgroup": {
+ "unwrap": 1
+ },
+ "font": {
+ "rename_tag": "span",
+ "add_class": {
+ "size": "size_font"
+ }
+ },
+ "tt": {
+ "unwrap": 1
+ },
+ "noembed": {
+ "remove": 1
+ },
+ "thead": {
+ "add_style": {
+ "align": "align_text"
+ },
+ "check_attributes": {
+ "id": "any"
+ }
+ },
+ "blink": {
+ "unwrap": 1
+ },
+ "plaintext": {
+ "unwrap": 1
+ },
+ "xml": {
+ "remove": 1
+ },
+ "h6": wysihtml5ParserRulesDefaults.blockLevelEl,
+ "param": {
+ "remove": 1
+ },
+ "th": {
+ "check_attributes": {
+ "rowspan": "numbers",
+ "colspan": "numbers",
+ "valign": "any",
+ "align": "any",
+ "id": "any"
+ },
+ "keep_styles": {
+ "backgroundColor": 1,
+ "width": 1,
+ "height": 1
+ },
+ "add_style": {
+ "align": "align_text"
+ }
+ },
+ "legend": {
+ "unwrap": 1
+ },
+ "hr": {},
+ "label": {
+ "unwrap": 1
+ },
+ "dl": {
+ "unwrap": 1
+ },
+ "kbd": {
+ "unwrap": 1
+ },
+ "listing": {
+ "unwrap": 1
+ },
+ "dt": {
+ "unwrap": 1
+ },
+ "nextid": {
+ "remove": 1
+ },
+ "pre": {},
+ "center": wysihtml5ParserRulesDefaults.makeDiv,
+ "audio": {
+ "remove": 1
+ },
+ "datalist": {
+ "unwrap": 1
+ },
+ "samp": {
+ "unwrap": 1
+ },
+ "col": {
+ "remove": 1
+ },
+ "article": wysihtml5ParserRulesDefaults.makeDiv,
+ "cite": {},
+ "link": {
+ "remove": 1
+ },
+ "script": {
+ "check_attributes": {
+ "type": "any",
+ "src": "any",
+ "charset": "any"
+ }
+ },
+ "bdo": {
+ "unwrap": 1
+ },
+ "menu": {
+ "rename_tag": "ul"
+ },
+ "colgroup": {
+ "remove": 1
+ },
+ "ruby": {
+ "unwrap": 1
+ },
+ "h2": wysihtml5ParserRulesDefaults.blockLevelEl,
+ "ins": {
+ "unwrap": 1
+ },
+ "p": wysihtml5ParserRulesDefaults.blockLevelEl,
+ "sub": {
+ "unwrap": 1
+ },
+ "comment": {
+ "remove": 1
+ },
+ "frameset": {
+ "remove": 1
+ },
+ "optgroup": {
+ "unwrap": 1
+ },
+ "header": wysihtml5ParserRulesDefaults.makeDiv
+ }
+};
+
+
+(function() {
+ // Paste cleanup rules universal for all rules (also applied to content copied from editor)
+ var commonRules = wysihtml5.lang.object(wysihtml5ParserRules).clone(true);
+ commonRules.comments = false;
+ commonRules.selectors = { "a u": "unwrap"};
+ commonRules.tags.style = { "remove": 1 };
+ commonRules.tags.script = { "remove": 1 };
+ commonRules.tags.head = { "remove": 1 };
+
+ // Paste cleanup for unindentified source
+ var universalRules = wysihtml5.lang.object(commonRules).clone(true);
+ universalRules.tags.div.one_of_type.alignment_object = 1;
+ universalRules.tags.div.remove_action = "unwrap";
+ universalRules.tags.div.check_attributes.style = false;
+ universalRules.tags.div.keep_styles = {
+ "textAlign": /^((left)|(right)|(center)|(justify))$/i,
+ "float": 1
+ };
+ universalRules.tags.span.keep_styles = false;
+
+ // Paste cleanup for MS Office
+ // TODO: should be extended to stricter ruleset, as current set will probably not cover all Office bizarreness
+ var msOfficeRules = wysihtml5.lang.object(universalRules).clone(true);
+ msOfficeRules.classes = {};
+
+ window.wysihtml5ParserPasteRulesets = [
+ {
+ condition: /<font face="Times New Roman"|class="?Mso|style="[^"]*\bmso-|style='[^'']*\bmso-|w:WordDocument|class="OutlineElement|id="?docs\-internal\-guid\-/i,
+ set: msOfficeRules
+ },{
+ condition: /<meta name="copied-from" content="wysihtml5">/i,
+ set: commonRules
+ },{
+ set: universalRules
+ }
+ ];
+
+})();
--- /dev/null
+/**
+ * Full HTML5 compatibility rule set
+ * These rules define which tags and CSS classes are supported and which tags should be specially treated.
+ *
+ * Examples based on this rule set:
+ *
+ * <a href="http://foobar.com">foo</a>
+ * ... becomes ...
+ * <a href="http://foobar.com" target="_blank" rel="nofollow">foo</a>
+ *
+ * <img align="left" src="http://foobar.com/image.png">
+ * ... becomes ...
+ * <img class="wysiwyg-float-left" src="http://foobar.com/image.png" alt="">
+ *
+ * <div>foo<script>alert(document.cookie);</script></div>
+ * ... becomes ...
+ * <div>foo</div>
+ *
+ * <marquee>foo</marquee>
+ * ... becomes ...
+ * <span>foo</span>
+ *
+ * foo <br clear="both"> bar
+ * ... becomes ...
+ * foo <br class="wysiwyg-clear-both"> bar
+ *
+ * <div>hello <iframe src="http://google.com"></iframe></div>
+ * ... becomes ...
+ * <div>hello </div>
+ *
+ * <center>hello</center>
+ * ... becomes ...
+ * <div class="wysiwyg-text-align-center">hello</div>
+ */
+var wysihtml5ParserRules = {
+ /**
+ * CSS Class white-list
+ * Following CSS classes won't be removed when parsed by the wysihtml5 HTML parser
+ * If all classes should pass "any" as classes value. Ex: "classes": "any"
+ */
+ "classes": {
+ "wysiwyg-clear-both": 1,
+ "wysiwyg-clear-left": 1,
+ "wysiwyg-clear-right": 1,
+ "wysiwyg-color-aqua": 1,
+ "wysiwyg-color-black": 1,
+ "wysiwyg-color-blue": 1,
+ "wysiwyg-color-fuchsia": 1,
+ "wysiwyg-color-gray": 1,
+ "wysiwyg-color-green": 1,
+ "wysiwyg-color-lime": 1,
+ "wysiwyg-color-maroon": 1,
+ "wysiwyg-color-navy": 1,
+ "wysiwyg-color-olive": 1,
+ "wysiwyg-color-purple": 1,
+ "wysiwyg-color-red": 1,
+ "wysiwyg-color-silver": 1,
+ "wysiwyg-color-teal": 1,
+ "wysiwyg-color-white": 1,
+ "wysiwyg-color-yellow": 1,
+ "wysiwyg-float-left": 1,
+ "wysiwyg-float-right": 1,
+ "wysiwyg-font-size-large": 1,
+ "wysiwyg-font-size-larger": 1,
+ "wysiwyg-font-size-medium": 1,
+ "wysiwyg-font-size-small": 1,
+ "wysiwyg-font-size-smaller": 1,
+ "wysiwyg-font-size-x-large": 1,
+ "wysiwyg-font-size-x-small": 1,
+ "wysiwyg-font-size-xx-large": 1,
+ "wysiwyg-font-size-xx-small": 1,
+ "wysiwyg-text-align-center": 1,
+ "wysiwyg-text-align-justify": 1,
+ "wysiwyg-text-align-left": 1,
+ "wysiwyg-text-align-right": 1
+ },
+
+
+ "type_definitions": {
+
+ "visible_content_object": {
+ "methods": {
+ "has_visible_contet": 1
+ }
+ },
+
+ "alignment_object": {
+ "classes": {
+ "wysiwyg-text-align-center": 1,
+ "wysiwyg-text-align-justify": 1,
+ "wysiwyg-text-align-left": 1,
+ "wysiwyg-text-align-right": 1,
+ "wysiwyg-float-left": 1,
+ "wysiwyg-float-right": 1
+ },
+ "styles": {
+ "float": ["left", "right"],
+ "text-align": ["left", "right", "center"]
+ }
+ },
+
+ "valid_image_src": {
+ "attrs": {
+ "src": /^[^data\:]/i
+ }
+ },
+
+ "text_color_object": {
+ "styles": {
+ "color": true,
+ "background-color": true
+ }
+ },
+
+ "text_fontsize_object": {
+ "styles": {
+ "font-size": true
+ }
+ },
+
+ "text_formatting_object": {
+ "classes": {
+ "wysiwyg-color-aqua": 1,
+ "wysiwyg-color-black": 1,
+ "wysiwyg-color-blue": 1,
+ "wysiwyg-color-fuchsia": 1,
+ "wysiwyg-color-gray": 1,
+ "wysiwyg-color-green": 1,
+ "wysiwyg-color-lime": 1,
+ "wysiwyg-color-maroon": 1,
+ "wysiwyg-color-navy": 1,
+ "wysiwyg-color-olive": 1,
+ "wysiwyg-color-purple": 1,
+ "wysiwyg-color-red": 1,
+ "wysiwyg-color-silver": 1,
+ "wysiwyg-color-teal": 1,
+ "wysiwyg-color-white": 1,
+ "wysiwyg-color-yellow": 1,
+ "wysiwyg-font-size-large": 1,
+ "wysiwyg-font-size-larger": 1,
+ "wysiwyg-font-size-medium": 1,
+ "wysiwyg-font-size-small": 1,
+ "wysiwyg-font-size-smaller": 1,
+ "wysiwyg-font-size-x-large": 1,
+ "wysiwyg-font-size-x-small": 1,
+ "wysiwyg-font-size-xx-large": 1,
+ "wysiwyg-font-size-xx-small": 1
+ }
+ }
+ },
+
+ "comments": 1, // if set allows comments to pass
+
+ /**
+ * Tag list
+ *
+ * The following options are available:
+ *
+ * - add_class: converts and deletes the given HTML4 attribute (align, clear, ...) via the given method to a css class
+ * The following methods are implemented in wysihtml5.dom.parse:
+ * - align_text: converts align attribute values (right/left/center/justify) to their corresponding css class "wysiwyg-text-align-*")
+ * <p align="center">foo</p> ... becomes ... <p class="wysiwyg-text-align-center">foo</p>
+ * - clear_br: converts clear attribute values left/right/all/both to their corresponding css class "wysiwyg-clear-*"
+ * <br clear="all"> ... becomes ... <br class="wysiwyg-clear-both">
+ * - align_img: converts align attribute values (right/left) on <img> to their corresponding css class "wysiwyg-float-*"
+ *
+ * - add_style: converts and deletes the given HTML4 attribute (align) via the given method to a css style
+ * The following methods are implemented in wysihtml5.dom.parse:
+ * - align_text: converts align attribute values (right/left/center) to their corresponding css style)
+ * <p align="center">foo</p> ... becomes ... <p style="text-align:center">foo</p>
+ *
+ * - remove: removes the element and its content
+ *
+ * - unwrap removes element but leaves content
+ *
+ * - rename_tag: renames the element to the given tag
+ *
+ * - set_class: adds the given class to the element (note: make sure that the class is in the "classes" white list above)
+ *
+ * - set_attributes: sets/overrides the given attributes
+ *
+ * - check_attributes: checks the given HTML attribute via the given method
+ * - url: allows only valid urls (starting with http:// or https://)
+ * - src: allows something like "/foobar.jpg", "http://google.com", ...
+ * - href: allows something like "mailto:bert@foo.com", "http://google.com", "/foobar.jpg"
+ * - alt: strips unwanted characters. if the attribute is not set, then it gets set (to ensure valid and compatible HTML)
+ * - numbers: ensures that the attribute only contains numeric characters
+ * - any: allows anything to pass
+ */
+ "tags": {
+ "tr": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "strike": {
+ "unwrap": 1
+ },
+ "form": {
+ "unwrap": 1
+ },
+ "rt": {
+ "rename_tag": "span"
+ },
+ "code": {},
+ "acronym": {
+ "rename_tag": "span"
+ },
+ "br": {
+ "add_class": {
+ "clear": "clear_br"
+ }
+ },
+ "details": {
+ "unwrap": 1
+ },
+ "h4": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "em": {},
+ "title": {
+ "remove": 1
+ },
+ "multicol": {
+ "unwrap": 1
+ },
+ "figure": {
+ "unwrap": 1
+ },
+ "xmp": {
+ "unwrap": 1
+ },
+ "small": {
+ "rename_tag": "span",
+ "set_class": "wysiwyg-font-size-smaller"
+ },
+ "area": {
+ "remove": 1
+ },
+ "time": {
+ "unwrap": 1
+ },
+ "dir": {
+ "rename_tag": "ul"
+ },
+ "bdi": {
+ "unwrap": 1
+ },
+ "command": {
+ "unwrap": 1
+ },
+ "ul": {},
+ "progress": {
+ "rename_tag": "span"
+ },
+ "dfn": {
+ "unwrap": 1
+ },
+ "iframe": {
+ "remove": 1
+ },
+ "figcaption": {
+ "unwrap": 1
+ },
+ "a": {
+ "check_attributes": {
+ "href": "href", // if you compiled master manually then change this from 'url' to 'href'
+ "target": "any"
+ },
+ "set_attributes": {
+ "rel": "nofollow"
+ }
+ },
+ "img": {
+ "one_of_type": {
+ "valid_image_src": 1
+ },
+ "check_attributes": {
+ "width": "numbers",
+ "alt": "alt",
+ "src": "src", // if you compiled master manually then change this from 'url' to 'src'
+ "height": "numbers"
+ },
+ "add_class": {
+ "align": "align_img"
+ }
+ },
+ "rb": {
+ "unwrap": 1
+ },
+ "footer": {
+ "rename_tag": "div"
+ },
+ "noframes": {
+ "remove": 1
+ },
+ "abbr": {
+ "unwrap": 1
+ },
+ "u": {},
+ "bgsound": {
+ "remove": 1
+ },
+ "sup": {
+ "unwrap": 1
+ },
+ "address": {
+ "unwrap": 1
+ },
+ "basefont": {
+ "remove": 1
+ },
+ "nav": {
+ "unwrap": 1
+ },
+ "h1": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "head": {
+ "unwrap": 1
+ },
+ "tbody": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "dd": {
+ "unwrap": 1
+ },
+ "s": {
+ "unwrap": 1
+ },
+ "li": {},
+ "td": {
+ "check_attributes": {
+ "rowspan": "numbers",
+ "colspan": "numbers",
+ "valign": "any",
+ "align": "any"
+ },
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "object": {
+ "remove": 1
+ },
+
+ "div": {
+ "one_of_type": {
+ "visible_content_object": 1
+ },
+ "remove_action": "unwrap",
+ "keep_styles": {
+ "textAlign": 1,
+ "float": 1
+ },
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+
+ "option": {
+ "remove":1
+ },
+ "select": {
+ "remove":1
+ },
+ "i": {},
+ "track": {
+ "remove": 1
+ },
+ "wbr": {
+ "remove": 1
+ },
+ "fieldset": {
+ "unwrap": 1
+ },
+ "big": {
+ "rename_tag": "span",
+ "set_class": "wysiwyg-font-size-larger"
+ },
+ "button": {
+ "unwrap": 1
+ },
+ "noscript": {
+ "remove": 1
+ },
+ "svg": {
+ "remove": 1
+ },
+ "input": {
+ "remove": 1
+ },
+ "table": {},
+ "keygen": {
+ "remove": 1
+ },
+ "h5": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "meta": {
+ "remove": 1
+ },
+ "map": {
+ "remove": 1
+ },
+ "isindex": {
+ "remove": 1
+ },
+ "mark": {
+ "unwrap": 1
+ },
+ "caption": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "tfoot": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "base": {
+ "remove": 1
+ },
+ "video": {
+ "remove": 1
+ },
+ "strong": {},
+ "canvas": {
+ "remove": 1
+ },
+ "output": {
+ "unwrap": 1
+ },
+ "marquee": {
+ "unwrap": 1
+ },
+ "b": {},
+ "q": {
+ "check_attributes": {
+ "cite": "url"
+ }
+ },
+ "applet": {
+ "remove": 1
+ },
+ "span": {
+ "one_of_type": {
+ "text_formatting_object": 1,
+ "text_color_object": 1,
+ "text_fontsize_object": 1
+ },
+ "keep_styles": {
+ "color": 1,
+ "backgroundColor": 1,
+ "fontSize": 1
+ },
+ "remove_action": "unwrap"
+ },
+ "rp": {
+ "unwrap": 1
+ },
+ "spacer": {
+ "remove": 1
+ },
+ "source": {
+ "remove": 1
+ },
+ "aside": {
+ "rename_tag": "div"
+ },
+ "frame": {
+ "remove": 1
+ },
+ "section": {
+ "rename_tag": "div"
+ },
+ "body": {
+ "unwrap": 1
+ },
+ "ol": {},
+ "nobr": {
+ "unwrap": 1
+ },
+ "html": {
+ "unwrap": 1
+ },
+ "summary": {
+ "unwrap": 1
+ },
+ "var": {
+ "unwrap": 1
+ },
+ "del": {
+ "unwrap": 1
+ },
+ "blockquote": {
+ "check_attributes": {
+ "cite": "url"
+ }
+ },
+ "style": {
+ "remove": 1
+ },
+ "device": {
+ "remove": 1
+ },
+ "meter": {
+ "unwrap": 1
+ },
+ "h3": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "textarea": {
+ "unwrap": 1
+ },
+ "embed": {
+ "remove": 1
+ },
+ "hgroup": {
+ "unwrap": 1
+ },
+ "font": {
+ "rename_tag": "span",
+ "add_class": {
+ "size": "size_font"
+ }
+ },
+ "tt": {
+ "unwrap": 1
+ },
+ "noembed": {
+ "remove": 1
+ },
+ "thead": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "blink": {
+ "unwrap": 1
+ },
+ "plaintext": {
+ "unwrap": 1
+ },
+ "xml": {
+ "remove": 1
+ },
+ "h6": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "param": {
+ "remove": 1
+ },
+ "th": {
+ "check_attributes": {
+ "rowspan": "numbers",
+ "colspan": "numbers"
+ },
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "legend": {
+ "unwrap": 1
+ },
+ "hr": {},
+ "label": {
+ "unwrap": 1
+ },
+ "dl": {
+ "unwrap": 1
+ },
+ "kbd": {
+ "unwrap": 1
+ },
+ "listing": {
+ "unwrap": 1
+ },
+ "dt": {
+ "unwrap": 1
+ },
+ "nextid": {
+ "remove": 1
+ },
+ "pre": {},
+ "center": {
+ "rename_tag": "div",
+ "set_class": "wysiwyg-text-align-center"
+ },
+ "audio": {
+ "remove": 1
+ },
+ "datalist": {
+ "unwrap": 1
+ },
+ "samp": {
+ "unwrap": 1
+ },
+ "col": {
+ "remove": 1
+ },
+ "article": {
+ "rename_tag": "div"
+ },
+ "cite": {},
+ "link": {
+ "remove": 1
+ },
+ "script": {
+ "remove": 1
+ },
+ "bdo": {
+ "unwrap": 1
+ },
+ "menu": {
+ "rename_tag": "ul"
+ },
+ "colgroup": {
+ "remove": 1
+ },
+ "ruby": {
+ "unwrap": 1
+ },
+ "h2": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "ins": {
+ "unwrap": 1
+ },
+ "p": {
+ "add_class": {
+ "align": "align_text"
+ }
+ },
+ "sub": {
+ "unwrap": 1
+ },
+ "comment": {
+ "remove": 1
+ },
+ "frameset": {
+ "remove": 1
+ },
+ "optgroup": {
+ "unwrap": 1
+ },
+ "header": {
+ "rename_tag": "div"
+ }
+ }
+};
\ No newline at end of file
--- /dev/null
+/**
+ * Very simple basic rule set
+ *
+ * Allows
+ * <i>, <em>, <b>, <strong>, <p>, <div>, <a href="http://foo"></a>, <br>, <span>, <ol>, <ul>, <li>
+ *
+ * For a proper documentation of the format check advanced.js
+ */
+var wysihtml5ParserRules = {
+ tags: {
+ strong: {},
+ b: {},
+ i: {},
+ em: {},
+ br: {},
+ p: {},
+ div: {},
+ span: {},
+ ul: {},
+ ol: {},
+ li: {},
+ a: {
+ set_attributes: {
+ target: "_blank",
+ rel: "nofollow"
+ },
+ check_attributes: {
+ href: "url" // important to avoid XSS
+ }
+ }
+ }
+};
\ No newline at end of file
--- /dev/null
+var wysihtml5 = wysihtml5 || {};
+wysihtml5.assert = wysihtml5.assert || {};
+
+/**
+ * Compare html strings without stumbling upon browser misbehaviors
+ * Uses and takes the same parameters as QUnit's equal method
+ *
+ * @example
+ * wysihtml5.assert.htmlEqual(
+ * removeAttributes('<p align="center">foo</p>'),
+ * '<p>foo</p>',
+ * 'Removed align attribute on <p>'
+ * );
+ */
+wysihtml5.assert.htmlEqual = (function() {
+ var htmlHost = document.createElement("div");
+
+ /**
+ * IE uppercases tags and attribute names
+ * and also removes quotes around attribute values whenever possible
+ */
+ var NEEDS_TO_BE_PREPARSED = (function() {
+ var html = '<img alt="foo" width=1 height="1" data-foo="1">';
+ htmlHost.innerHTML = html;
+ return htmlHost.innerHTML != html;
+ })();
+
+ var DOESNT_PRESERVE_WHITE_SPACE = (function() {
+ var div = document.createElement("div"),
+ a = document.createElement("a"),
+ p = document.createElement("p");
+ a.appendChild(p);
+ div.appendChild(a);
+ return div.innerHTML.toLowerCase() != "<a><p></p></a>";
+ })();
+
+ /**
+ * Browsers don't preserve original attribute order
+ * In order to be able to compare html we simply split both, the expected and actual html at spaces and element-ends,
+ * sort them alphabetically and put them back together
+ * TODO: This solution is a bit crappy. Maybe there's a smarter way. However it works for now.
+ */
+ var tokenizeHTML = (function() {
+ var REG_EXP = /\s+|\>|</;
+ return function(html) {
+ return html.split(REG_EXP).sort().join(" ");
+ };
+ })();
+
+ var normalizeWhiteSpace = (function() {
+ var PRE_REG_EXP = /(<pre[\^>]*>)([\S\s]*?)(<\/pre>)/mgi,
+ WHITE_SPACE_REG_EXP = /\s+/gm,
+ PLACEHOLDER = "___PRE_CONTENT___",
+ PLACEHOLDER_REG_EXP = new RegExp(PLACEHOLDER, "g");
+ return function(html) {
+ var preContents = [];
+ // Extract content of elements that preserve white space first
+ html = html.replace(PRE_REG_EXP, function(match, $1, $2, $3) {
+ preContents.push($2);
+ return $1 + PLACEHOLDER + $3;
+ });
+
+ // Normalize space
+ html = html.replace(WHITE_SPACE_REG_EXP, " ");
+
+ // Reinsert original pre content
+ html = html.replace(PLACEHOLDER_REG_EXP, function() {
+ return preContents.shift();
+ });
+
+ return html;
+ };
+ })();
+
+ var removeWhiteSpace = (function() {
+ var REG_EXP = /(>)(\s*?)(<)/gm;
+ return function(html) {
+ return wysihtml5.lang.string(html.replace(REG_EXP, "$1$3")).trim();
+ };
+ })();
+
+ return function(actual, expected, message, config) {
+ config = config || {};
+ if (NEEDS_TO_BE_PREPARSED) {
+ actual = wysihtml5.dom.getAsDom(actual).innerHTML;
+ expected = wysihtml5.dom.getAsDom(expected).innerHTML;
+ }
+
+ if (config.normalizeWhiteSpace || DOESNT_PRESERVE_WHITE_SPACE) {
+ actual = normalizeWhiteSpace(actual);
+ expected = normalizeWhiteSpace(expected);
+ }
+
+ if (config.removeWhiteSpace) {
+ actual = removeWhiteSpace(actual);
+ expected = removeWhiteSpace(expected);
+ }
+
+ actual = tokenizeHTML(actual);
+ expected = tokenizeHTML(expected);
+ ok(actual == expected, message);
+ };
+})();
--- /dev/null
+/**
+ * Detect browser support for specific features
+ */
+wysihtml5.browser = (function() {
+ var userAgent = navigator.userAgent,
+ testElement = document.createElement("div"),
+ // Browser sniffing is unfortunately needed since some behaviors are impossible to feature detect
+ isGecko = userAgent.indexOf("Gecko") !== -1 && userAgent.indexOf("KHTML") === -1,
+ isWebKit = userAgent.indexOf("AppleWebKit/") !== -1,
+ isChrome = userAgent.indexOf("Chrome/") !== -1,
+ isOpera = userAgent.indexOf("Opera/") !== -1;
+
+ function iosVersion(userAgent) {
+ return +((/ipad|iphone|ipod/.test(userAgent) && userAgent.match(/ os (\d+).+? like mac os x/)) || [undefined, 0])[1];
+ }
+
+ function androidVersion(userAgent) {
+ return +(userAgent.match(/android (\d+)/) || [undefined, 0])[1];
+ }
+
+ function isIE(version, equation) {
+ var rv = -1,
+ re;
+
+ if (navigator.appName == 'Microsoft Internet Explorer') {
+ re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
+ } else if (navigator.appName == 'Netscape') {
+ re = new RegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})");
+ }
+
+ if (re && re.exec(navigator.userAgent) != null) {
+ rv = parseFloat(RegExp.$1);
+ }
+
+ if (rv === -1) { return false; }
+ if (!version) { return true; }
+ if (!equation) { return version === rv; }
+ if (equation === "<") { return version < rv; }
+ if (equation === ">") { return version > rv; }
+ if (equation === "<=") { return version <= rv; }
+ if (equation === ">=") { return version >= rv; }
+ }
+
+ return {
+ // Static variable needed, publicly accessible, to be able override it in unit tests
+ USER_AGENT: userAgent,
+
+ /**
+ * Exclude browsers that are not capable of displaying and handling
+ * contentEditable as desired:
+ * - iPhone, iPad (tested iOS 4.2.2) and Android (tested 2.2) refuse to make contentEditables focusable
+ * - IE < 8 create invalid markup and crash randomly from time to time
+ *
+ * @return {Boolean}
+ */
+ supported: function() {
+ var userAgent = this.USER_AGENT.toLowerCase(),
+ // Essential for making html elements editable
+ hasContentEditableSupport = "contentEditable" in testElement,
+ // Following methods are needed in order to interact with the contentEditable area
+ hasEditingApiSupport = document.execCommand && document.queryCommandSupported && document.queryCommandState,
+ // document selector apis are only supported by IE 8+, Safari 4+, Chrome and Firefox 3.5+
+ hasQuerySelectorSupport = document.querySelector && document.querySelectorAll,
+ // contentEditable is unusable in mobile browsers (tested iOS 4.2.2, Android 2.2, Opera Mobile, WebOS 3.05)
+ isIncompatibleMobileBrowser = (this.isIos() && iosVersion(userAgent) < 5) || (this.isAndroid() && androidVersion(userAgent) < 4) || userAgent.indexOf("opera mobi") !== -1 || userAgent.indexOf("hpwos/") !== -1;
+ return hasContentEditableSupport
+ && hasEditingApiSupport
+ && hasQuerySelectorSupport
+ && !isIncompatibleMobileBrowser;
+ },
+
+ isTouchDevice: function() {
+ return this.supportsEvent("touchmove");
+ },
+
+ isIos: function() {
+ return (/ipad|iphone|ipod/i).test(this.USER_AGENT);
+ },
+
+ isAndroid: function() {
+ return this.USER_AGENT.indexOf("Android") !== -1;
+ },
+
+ /**
+ * Whether the browser supports sandboxed iframes
+ * Currently only IE 6+ offers such feature <iframe security="restricted">
+ *
+ * http://msdn.microsoft.com/en-us/library/ms534622(v=vs.85).aspx
+ * http://blogs.msdn.com/b/ie/archive/2008/01/18/using-frames-more-securely.aspx
+ *
+ * HTML5 sandboxed iframes are still buggy and their DOM is not reachable from the outside (except when using postMessage)
+ */
+ supportsSandboxedIframes: function() {
+ return isIE();
+ },
+
+ /**
+ * IE6+7 throw a mixed content warning when the src of an iframe
+ * is empty/unset or about:blank
+ * window.querySelector is implemented as of IE8
+ */
+ throwsMixedContentWarningWhenIframeSrcIsEmpty: function() {
+ return !("querySelector" in document);
+ },
+
+ /**
+ * Whether the caret is correctly displayed in contentEditable elements
+ * Firefox sometimes shows a huge caret in the beginning after focusing
+ */
+ displaysCaretInEmptyContentEditableCorrectly: function() {
+ return isIE();
+ },
+
+ /**
+ * Opera and IE are the only browsers who offer the css value
+ * in the original unit, thx to the currentStyle object
+ * All other browsers provide the computed style in px via window.getComputedStyle
+ */
+ hasCurrentStyleProperty: function() {
+ return "currentStyle" in testElement;
+ },
+
+ /**
+ * Whether the browser inserts a <br> when pressing enter in a contentEditable element
+ */
+ insertsLineBreaksOnReturn: function() {
+ return isGecko;
+ },
+
+ supportsPlaceholderAttributeOn: function(element) {
+ return "placeholder" in element;
+ },
+
+ supportsEvent: function(eventName) {
+ return "on" + eventName in testElement || (function() {
+ testElement.setAttribute("on" + eventName, "return;");
+ return typeof(testElement["on" + eventName]) === "function";
+ })();
+ },
+
+ /**
+ * Opera doesn't correctly fire focus/blur events when clicking in- and outside of iframe
+ */
+ supportsEventsInIframeCorrectly: function() {
+ return !isOpera;
+ },
+
+ /**
+ * Everything below IE9 doesn't know how to treat HTML5 tags
+ *
+ * @param {Object} context The document object on which to check HTML5 support
+ *
+ * @example
+ * wysihtml5.browser.supportsHTML5Tags(document);
+ */
+ supportsHTML5Tags: function(context) {
+ var element = context.createElement("div"),
+ html5 = "<article>foo</article>";
+ element.innerHTML = html5;
+ return element.innerHTML.toLowerCase() === html5;
+ },
+
+ /**
+ * Checks whether a document supports a certain queryCommand
+ * In particular, Opera needs a reference to a document that has a contentEditable in it's dom tree
+ * in oder to report correct results
+ *
+ * @param {Object} doc Document object on which to check for a query command
+ * @param {String} command The query command to check for
+ * @return {Boolean}
+ *
+ * @example
+ * wysihtml5.browser.supportsCommand(document, "bold");
+ */
+ supportsCommand: (function() {
+ // Following commands are supported but contain bugs in some browsers
+ var buggyCommands = {
+ // formatBlock fails with some tags (eg. <blockquote>)
+ "formatBlock": isIE(10, "<="),
+ // When inserting unordered or ordered lists in Firefox, Chrome or Safari, the current selection or line gets
+ // converted into a list (<ul><li>...</li></ul>, <ol><li>...</li></ol>)
+ // IE and Opera act a bit different here as they convert the entire content of the current block element into a list
+ "insertUnorderedList": isIE(),
+ "insertOrderedList": isIE()
+ };
+
+ // Firefox throws errors for queryCommandSupported, so we have to build up our own object of supported commands
+ var supported = {
+ "insertHTML": isGecko
+ };
+
+ return function(doc, command) {
+ var isBuggy = buggyCommands[command];
+ if (!isBuggy) {
+ // Firefox throws errors when invoking queryCommandSupported or queryCommandEnabled
+ try {
+ return doc.queryCommandSupported(command);
+ } catch(e1) {}
+
+ try {
+ return doc.queryCommandEnabled(command);
+ } catch(e2) {
+ return !!supported[command];
+ }
+ }
+ return false;
+ };
+ })(),
+
+ /**
+ * IE: URLs starting with:
+ * www., http://, https://, ftp://, gopher://, mailto:, new:, snews:, telnet:, wasis:, file://,
+ * nntp://, newsrc:, ldap://, ldaps://, outlook:, mic:// and url:
+ * will automatically be auto-linked when either the user inserts them via copy&paste or presses the
+ * space bar when the caret is directly after such an url.
+ * This behavior cannot easily be avoided in IE < 9 since the logic is hardcoded in the mshtml.dll
+ * (related blog post on msdn
+ * http://blogs.msdn.com/b/ieinternals/archive/2009/09/17/prevent-automatic-hyperlinking-in-contenteditable-html.aspx).
+ */
+ doesAutoLinkingInContentEditable: function() {
+ return isIE();
+ },
+
+ /**
+ * As stated above, IE auto links urls typed into contentEditable elements
+ * Since IE9 it's possible to prevent this behavior
+ */
+ canDisableAutoLinking: function() {
+ return this.supportsCommand(document, "AutoUrlDetect");
+ },
+
+ /**
+ * IE leaves an empty paragraph in the contentEditable element after clearing it
+ * Chrome/Safari sometimes an empty <div>
+ */
+ clearsContentEditableCorrectly: function() {
+ return isGecko || isOpera || isWebKit;
+ },
+
+ /**
+ * IE gives wrong results for getAttribute
+ */
+ supportsGetAttributeCorrectly: function() {
+ var td = document.createElement("td");
+ return td.getAttribute("rowspan") != "1";
+ },
+
+ /**
+ * When clicking on images in IE, Opera and Firefox, they are selected, which makes it easy to interact with them.
+ * Chrome and Safari both don't support this
+ */
+ canSelectImagesInContentEditable: function() {
+ return isGecko || isIE() || isOpera;
+ },
+
+ /**
+ * All browsers except Safari and Chrome automatically scroll the range/caret position into view
+ */
+ autoScrollsToCaret: function() {
+ return !isWebKit;
+ },
+
+ /**
+ * Check whether the browser automatically closes tags that don't need to be opened
+ */
+ autoClosesUnclosedTags: function() {
+ var clonedTestElement = testElement.cloneNode(false),
+ returnValue,
+ innerHTML;
+
+ clonedTestElement.innerHTML = "<p><div></div>";
+ innerHTML = clonedTestElement.innerHTML.toLowerCase();
+ returnValue = innerHTML === "<p></p><div></div>" || innerHTML === "<p><div></div></p>";
+
+ // Cache result by overwriting current function
+ this.autoClosesUnclosedTags = function() { return returnValue; };
+
+ return returnValue;
+ },
+
+ /**
+ * Whether the browser supports the native document.getElementsByClassName which returns live NodeLists
+ */
+ supportsNativeGetElementsByClassName: function() {
+ return String(document.getElementsByClassName).indexOf("[native code]") !== -1;
+ },
+
+ /**
+ * As of now (19.04.2011) only supported by Firefox 4 and Chrome
+ * See https://developer.mozilla.org/en/DOM/Selection/modify
+ */
+ supportsSelectionModify: function() {
+ return "getSelection" in window && "modify" in window.getSelection();
+ },
+
+ /**
+ * Opera needs a white space after a <br> in order to position the caret correctly
+ */
+ needsSpaceAfterLineBreak: function() {
+ return isOpera;
+ },
+
+ /**
+ * Whether the browser supports the speech api on the given element
+ * See http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/
+ *
+ * @example
+ * var input = document.createElement("input");
+ * if (wysihtml5.browser.supportsSpeechApiOn(input)) {
+ * // ...
+ * }
+ */
+ supportsSpeechApiOn: function(input) {
+ var chromeVersion = userAgent.match(/Chrome\/(\d+)/) || [undefined, 0];
+ return chromeVersion[1] >= 11 && ("onwebkitspeechchange" in input || "speech" in input);
+ },
+
+ /**
+ * IE9 crashes when setting a getter via Object.defineProperty on XMLHttpRequest or XDomainRequest
+ * See https://connect.microsoft.com/ie/feedback/details/650112
+ * or try the POC http://tifftiff.de/ie9_crash/
+ */
+ crashesWhenDefineProperty: function(property) {
+ return isIE(9) && (property === "XMLHttpRequest" || property === "XDomainRequest");
+ },
+
+ /**
+ * IE is the only browser who fires the "focus" event not immediately when .focus() is called on an element
+ */
+ doesAsyncFocus: function() {
+ return isIE();
+ },
+
+ /**
+ * In IE it's impssible for the user and for the selection library to set the caret after an <img> when it's the lastChild in the document
+ */
+ hasProblemsSettingCaretAfterImg: function() {
+ return isIE();
+ },
+
+ hasUndoInContextMenu: function() {
+ return isGecko || isChrome || isOpera;
+ },
+
+ /**
+ * Opera sometimes doesn't insert the node at the right position when range.insertNode(someNode)
+ * is used (regardless if rangy or native)
+ * This especially happens when the caret is positioned right after a <br> because then
+ * insertNode() will insert the node right before the <br>
+ */
+ hasInsertNodeIssue: function() {
+ return isOpera;
+ },
+
+ /**
+ * IE 8+9 don't fire the focus event of the <body> when the iframe gets focused (even though the caret gets set into the <body>)
+ */
+ hasIframeFocusIssue: function() {
+ return isIE();
+ },
+
+ /**
+ * Chrome + Safari create invalid nested markup after paste
+ *
+ * <p>
+ * foo
+ * <p>bar</p> <!-- BOO! -->
+ * </p>
+ */
+ createsNestedInvalidMarkupAfterPaste: function() {
+ return isWebKit;
+ },
+
+ supportsMutationEvents: function() {
+ return ("MutationEvent" in window);
+ },
+
+ /**
+ IE (at least up to 11) does not support clipboardData on event.
+ It is on window but cannot return text/html
+ Should actually check for clipboardData on paste event, but cannot in firefox
+ */
+ supportsModenPaste: function () {
+ return !("clipboardData" in window);
+ }
+ };
+})();
--- /dev/null
+/**
+ * Rich Text Query/Formatting Commands
+ *
+ * @example
+ * var commands = new wysihtml5.Commands(editor);
+ */
+wysihtml5.Commands = Base.extend(
+ /** @scope wysihtml5.Commands.prototype */ {
+ constructor: function(editor) {
+ this.editor = editor;
+ this.composer = editor.composer;
+ this.doc = this.composer.doc;
+ },
+
+ /**
+ * Check whether the browser supports the given command
+ *
+ * @param {String} command The command string which to check (eg. "bold", "italic", "insertUnorderedList")
+ * @example
+ * commands.supports("createLink");
+ */
+ support: function(command) {
+ return wysihtml5.browser.supportsCommand(this.doc, command);
+ },
+
+ /**
+ * Check whether the browser supports the given command
+ *
+ * @param {String} command The command string which to execute (eg. "bold", "italic", "insertUnorderedList")
+ * @param {String} [value] The command value parameter, needed for some commands ("createLink", "insertImage", ...), optional for commands that don't require one ("bold", "underline", ...)
+ * @example
+ * commands.exec("insertImage", "http://a1.twimg.com/profile_images/113868655/schrei_twitter_reasonably_small.jpg");
+ */
+ exec: function(command, value) {
+ var obj = wysihtml5.commands[command],
+ args = wysihtml5.lang.array(arguments).get(),
+ method = obj && obj.exec,
+ result = null;
+
+ // If composer ahs placeholder unset it before command
+ // Do not apply on commands that are behavioral
+ if (this.composer.hasPlaceholderSet() && !wysihtml5.lang.array(['styleWithCSS', 'enableObjectResizing', 'enableInlineTableEditing']).contains(command)) {
+ this.composer.element.innerHTML = "";
+ this.composer.selection.selectNode(this.composer.element);
+ }
+
+ this.editor.fire("beforecommand:composer");
+
+ if (method) {
+ args.unshift(this.composer);
+ result = method.apply(obj, args);
+ } else {
+ try {
+ // try/catch for buggy firefox
+ result = this.doc.execCommand(command, false, value);
+ } catch(e) {}
+ }
+
+ this.editor.fire("aftercommand:composer");
+ return result;
+ },
+
+ /**
+ * Check whether the current command is active
+ * If the caret is within a bold text, then calling this with command "bold" should return true
+ *
+ * @param {String} command The command string which to check (eg. "bold", "italic", "insertUnorderedList")
+ * @param {String} [commandValue] The command value parameter (eg. for "insertImage" the image src)
+ * @return {Boolean} Whether the command is active
+ * @example
+ * var isCurrentSelectionBold = commands.state("bold");
+ */
+ state: function(command, commandValue) {
+ var obj = wysihtml5.commands[command],
+ args = wysihtml5.lang.array(arguments).get(),
+ method = obj && obj.state;
+ if (method) {
+ args.unshift(this.composer);
+ return method.apply(obj, args);
+ } else {
+ try {
+ // try/catch for buggy firefox
+ return this.doc.queryCommandState(command);
+ } catch(e) {
+ return false;
+ }
+ }
+ },
+
+ /* Get command state parsed value if command has stateValue parsing function */
+ stateValue: function(command) {
+ var obj = wysihtml5.commands[command],
+ args = wysihtml5.lang.array(arguments).get(),
+ method = obj && obj.stateValue;
+ if (method) {
+ args.unshift(this.composer);
+ return method.apply(obj, args);
+ } else {
+ return false;
+ }
+ }
+});
--- /dev/null
+wysihtml5.commands.addTableCells = {
+ exec: function(composer, command, value) {
+ if (composer.tableSelection && composer.tableSelection.start && composer.tableSelection.end) {
+
+ // switches start and end if start is bigger than end (reverse selection)
+ var tableSelect = wysihtml5.dom.table.orderSelectionEnds(composer.tableSelection.start, composer.tableSelection.end);
+ if (value == "before" || value == "above") {
+ wysihtml5.dom.table.addCells(tableSelect.start, value);
+ } else if (value == "after" || value == "below") {
+ wysihtml5.dom.table.addCells(tableSelect.end, value);
+ }
+ setTimeout(function() {
+ composer.tableSelection.select(tableSelect.start, tableSelect.end);
+ },0);
+ }
+ },
+
+ state: function(composer, command) {
+ return false;
+ }
+};
--- /dev/null
+(function(wysihtml5) {
+ var STYLE_STR = "text-align: center;",
+ REG_EXP = /(\s|^)text-align\s*:\s*[^;\s]+;?/gi;
+
+ wysihtml5.commands.alignCenterStyle = {
+ exec: function(composer, command) {
+ return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", null, null, null, STYLE_STR, REG_EXP);
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatBlock.state(composer, "formatBlock", null, null, null, STYLE_STR, REG_EXP);
+ }
+ };
+})(wysihtml5);
--- /dev/null
+(function(wysihtml5) {
+ var STYLE_STR = "text-align: left;",
+ REG_EXP = /(\s|^)text-align\s*:\s*[^;\s]+;?/gi;
+
+ wysihtml5.commands.alignLeftStyle = {
+ exec: function(composer, command) {
+ return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", null, null, null, STYLE_STR, REG_EXP);
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatBlock.state(composer, "formatBlock", null, null, null, STYLE_STR, REG_EXP);
+ }
+ };
+})(wysihtml5);
--- /dev/null
+(function(wysihtml5) {
+ var STYLE_STR = "text-align: right;",
+ REG_EXP = /(\s|^)text-align\s*:\s*[^;\s]+;?/gi;
+
+ wysihtml5.commands.alignRightStyle = {
+ exec: function(composer, command) {
+ return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", null, null, null, STYLE_STR, REG_EXP);
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatBlock.state(composer, "formatBlock", null, null, null, STYLE_STR, REG_EXP);
+ }
+ };
+})(wysihtml5);
--- /dev/null
+/* In case background adjustment to any color defined by user is preferred, we cannot use classes and must use inline styles. */
+(function(wysihtml5) {
+ var REG_EXP = /(\s|^)background-color\s*:\s*[^;\s]+;?/gi;
+
+ wysihtml5.commands.bgColorStyle = {
+ exec: function(composer, command, color) {
+ var colorVals = wysihtml5.quirks.styleParser.parseColor((typeof(color) == "object") ? "background-color:" + color.color : "background-color:" + color, "background-color"),
+ colString;
+
+ if (colorVals) {
+ colString = "background-color: rgb(" + colorVals[0] + ',' + colorVals[1] + ',' + colorVals[2] + ');';
+ if (colorVals[3] !== 1) {
+ colString += "background-color: rgba(" + colorVals[0] + ',' + colorVals[1] + ',' + colorVals[2] + ',' + colorVals[3] + ');';
+ }
+ wysihtml5.commands.formatInline.execWithToggle(composer, command, "span", false, false, colString, REG_EXP);
+ }
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatInline.state(composer, command, "span", false, false, "background-color", REG_EXP);
+ },
+
+ stateValue: function(composer, command, props) {
+ var st = this.state(composer, command),
+ colorStr,
+ val = false;
+
+ if (st && wysihtml5.lang.object(st).isArray()) {
+ st = st[0];
+ }
+
+ if (st) {
+ colorStr = st.getAttribute('style');
+ if (colorStr) {
+ val = wysihtml5.quirks.styleParser.parseColor(colorStr, "background-color");
+ return wysihtml5.quirks.styleParser.unparseColor(val, props);
+ }
+ }
+ return false;
+ }
+
+ };
+})(wysihtml5);
--- /dev/null
+wysihtml5.commands.bold = {
+ exec: function(composer, command) {
+ wysihtml5.commands.formatInline.execWithToggle(composer, command, "b");
+ },
+
+ state: function(composer, command) {
+ // element.ownerDocument.queryCommandState("bold") results:
+ // firefox: only <b>
+ // chrome: <b>, <strong>, <h1>, <h2>, ...
+ // ie: <b>, <strong>
+ // opera: <b>, <strong>
+ return wysihtml5.commands.formatInline.state(composer, command, "b");
+ }
+};
+
--- /dev/null
+(function(wysihtml5) {
+ var undef,
+ NODE_NAME = "A",
+ dom = wysihtml5.dom;
+
+ function _format(composer, attributes) {
+ var doc = composer.doc,
+ tempClass = "_wysihtml5-temp-" + (+new Date()),
+ tempClassRegExp = /non-matching-class/g,
+ i = 0,
+ length,
+ anchors,
+ anchor,
+ hasElementChild,
+ isEmpty,
+ elementToSetCaretAfter,
+ textContent,
+ whiteSpace,
+ j;
+ wysihtml5.commands.formatInline.exec(composer, undef, NODE_NAME, tempClass, tempClassRegExp, undef, undef, true, true);
+ anchors = doc.querySelectorAll(NODE_NAME + "." + tempClass);
+ length = anchors.length;
+ for (; i<length; i++) {
+ anchor = anchors[i];
+ anchor.removeAttribute("class");
+ for (j in attributes) {
+ // Do not set attribute "text" as it is meant for setting string value if created link has no textual data
+ if (j !== "text") {
+ anchor.setAttribute(j, attributes[j]);
+ }
+ }
+ }
+
+ elementToSetCaretAfter = anchor;
+ if (length === 1) {
+ textContent = dom.getTextContent(anchor);
+ hasElementChild = !!anchor.querySelector("*");
+ isEmpty = textContent === "" || textContent === wysihtml5.INVISIBLE_SPACE;
+ if (!hasElementChild && isEmpty) {
+ dom.setTextContent(anchor, attributes.text || anchor.href);
+ whiteSpace = doc.createTextNode(" ");
+ composer.selection.setAfter(anchor);
+ dom.insert(whiteSpace).after(anchor);
+ elementToSetCaretAfter = whiteSpace;
+ }
+ }
+ composer.selection.setAfter(elementToSetCaretAfter);
+ }
+
+ // Changes attributes of links
+ function _changeLinks(composer, anchors, attributes) {
+ var oldAttrs;
+ for (var a = anchors.length; a--;) {
+
+ // Remove all old attributes
+ oldAttrs = anchors[a].attributes;
+ for (var oa = oldAttrs.length; oa--;) {
+ anchors[a].removeAttribute(oldAttrs.item(oa).name);
+ }
+
+ // Set new attributes
+ for (var j in attributes) {
+ if (attributes.hasOwnProperty(j)) {
+ anchors[a].setAttribute(j, attributes[j]);
+ }
+ }
+
+ }
+ }
+
+ wysihtml5.commands.createLink = {
+ /**
+ * TODO: Use HTMLApplier or formatInline here
+ *
+ * Turns selection into a link
+ * If selection is already a link, it just changes the attributes
+ *
+ * @example
+ * // either ...
+ * wysihtml5.commands.createLink.exec(composer, "createLink", "http://www.google.de");
+ * // ... or ...
+ * wysihtml5.commands.createLink.exec(composer, "createLink", { href: "http://www.google.de", target: "_blank" });
+ */
+ exec: function(composer, command, value) {
+ var anchors = this.state(composer, command);
+ if (anchors) {
+ // Selection contains links then change attributes of these links
+ composer.selection.executeAndRestore(function() {
+ _changeLinks(composer, anchors, value);
+ });
+ } else {
+ // Create links
+ value = typeof(value) === "object" ? value : { href: value };
+ _format(composer, value);
+ }
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatInline.state(composer, command, "A");
+ }
+ };
+})(wysihtml5);
--- /dev/null
+wysihtml5.commands.createTable = {
+ exec: function(composer, command, value) {
+ var col, row, html;
+ if (value && value.cols && value.rows && parseInt(value.cols, 10) > 0 && parseInt(value.rows, 10) > 0) {
+ if (value.tableStyle) {
+ html = "<table style=\"" + value.tableStyle + "\">";
+ } else {
+ html = "<table>";
+ }
+ html += "<tbody>";
+ for (row = 0; row < value.rows; row ++) {
+ html += '<tr>';
+ for (col = 0; col < value.cols; col ++) {
+ html += "<td> </td>";
+ }
+ html += '</tr>';
+ }
+ html += "</tbody></table>";
+ composer.commands.exec("insertHTML", html);
+ //composer.selection.insertHTML(html);
+ }
+
+
+ },
+
+ state: function(composer, command) {
+ return false;
+ }
+};
--- /dev/null
+wysihtml5.commands.deleteTableCells = {
+ exec: function(composer, command, value) {
+ if (composer.tableSelection && composer.tableSelection.start && composer.tableSelection.end) {
+ var tableSelect = wysihtml5.dom.table.orderSelectionEnds(composer.tableSelection.start, composer.tableSelection.end),
+ idx = wysihtml5.dom.table.indexOf(tableSelect.start),
+ selCell,
+ table = composer.tableSelection.table;
+
+ wysihtml5.dom.table.removeCells(tableSelect.start, value);
+ setTimeout(function() {
+ // move selection to next or previous if not present
+ selCell = wysihtml5.dom.table.findCell(table, idx);
+
+ if (!selCell){
+ if (value == "row") {
+ selCell = wysihtml5.dom.table.findCell(table, {
+ "row": idx.row - 1,
+ "col": idx.col
+ });
+ }
+
+ if (value == "column") {
+ selCell = wysihtml5.dom.table.findCell(table, {
+ "row": idx.row,
+ "col": idx.col - 1
+ });
+ }
+ }
+ if (selCell) {
+ composer.tableSelection.select(selCell, selCell);
+ }
+ }, 0);
+
+ }
+ },
+
+ state: function(composer, command) {
+ return false;
+ }
+};
--- /dev/null
+/**
+ * document.execCommand("fontSize") will create either inline styles (firefox, chrome) or use font tags
+ * which we don't want
+ * Instead we set a css class
+ */
+(function(wysihtml5) {
+ var REG_EXP = /wysiwyg-font-size-[0-9a-z\-]+/g;
+
+ wysihtml5.commands.fontSize = {
+ exec: function(composer, command, size) {
+ wysihtml5.commands.formatInline.execWithToggle(composer, command, "span", "wysiwyg-font-size-" + size, REG_EXP);
+ },
+
+ state: function(composer, command, size) {
+ return wysihtml5.commands.formatInline.state(composer, command, "span", "wysiwyg-font-size-" + size, REG_EXP);
+ }
+ };
+})(wysihtml5);
--- /dev/null
+/* In case font size adjustment to any number defined by user is preferred, we cannot use classes and must use inline styles. */
+(function(wysihtml5) {
+ var REG_EXP = /(\s|^)font-size\s*:\s*[^;\s]+;?/gi;
+
+ wysihtml5.commands.fontSizeStyle = {
+ exec: function(composer, command, size) {
+ size = (typeof(size) == "object") ? size.size : size;
+ if (!(/^\s*$/).test(size)) {
+ wysihtml5.commands.formatInline.execWithToggle(composer, command, "span", false, false, "font-size:" + size, REG_EXP);
+ }
+ },
+
+ state: function(composer, command, size) {
+ return wysihtml5.commands.formatInline.state(composer, command, "span", false, false, "font-size", REG_EXP);
+ },
+
+ stateValue: function(composer, command) {
+ var st = this.state(composer, command),
+ styleStr, fontsizeMatches,
+ val = false;
+
+ if (st && wysihtml5.lang.object(st).isArray()) {
+ st = st[0];
+ }
+ if (st) {
+ styleStr = st.getAttribute('style');
+ if (styleStr) {
+ return wysihtml5.quirks.styleParser.parseFontSize(styleStr);
+ }
+ }
+ return false;
+ }
+ };
+})(wysihtml5);
--- /dev/null
+/**
+ * document.execCommand("foreColor") will create either inline styles (firefox, chrome) or use font tags
+ * which we don't want
+ * Instead we set a css class
+ */
+(function(wysihtml5) {
+ var REG_EXP = /wysiwyg-color-[0-9a-z]+/g;
+
+ wysihtml5.commands.foreColor = {
+ exec: function(composer, command, color) {
+ wysihtml5.commands.formatInline.execWithToggle(composer, command, "span", "wysiwyg-color-" + color, REG_EXP);
+ },
+
+ state: function(composer, command, color) {
+ return wysihtml5.commands.formatInline.state(composer, command, "span", "wysiwyg-color-" + color, REG_EXP);
+ }
+ };
+})(wysihtml5);
--- /dev/null
+/**
+ * document.execCommand("foreColor") will create either inline styles (firefox, chrome) or use font tags
+ * which we don't want
+ * Instead we set a css class
+ */
+(function(wysihtml5) {
+ var REG_EXP = /(\s|^)color\s*:\s*[^;\s]+;?/gi;
+
+ wysihtml5.commands.foreColorStyle = {
+ exec: function(composer, command, color) {
+ var colorVals = wysihtml5.quirks.styleParser.parseColor((typeof(color) == "object") ? "color:" + color.color : "color:" + color, "color"),
+ colString;
+
+ if (colorVals) {
+ colString = "color: rgb(" + colorVals[0] + ',' + colorVals[1] + ',' + colorVals[2] + ');';
+ if (colorVals[3] !== 1) {
+ colString += "color: rgba(" + colorVals[0] + ',' + colorVals[1] + ',' + colorVals[2] + ',' + colorVals[3] + ');';
+ }
+ wysihtml5.commands.formatInline.execWithToggle(composer, command, "span", false, false, colString, REG_EXP);
+ }
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatInline.state(composer, command, "span", false, false, "color", REG_EXP);
+ },
+
+ stateValue: function(composer, command, props) {
+ var st = this.state(composer, command),
+ colorStr;
+
+ if (st && wysihtml5.lang.object(st).isArray()) {
+ st = st[0];
+ }
+
+ if (st) {
+ colorStr = st.getAttribute('style');
+ if (colorStr) {
+ if (colorStr) {
+ val = wysihtml5.quirks.styleParser.parseColor(colorStr, "color");
+ return wysihtml5.quirks.styleParser.unparseColor(val, props);
+ }
+ }
+ }
+ return false;
+ }
+
+ };
+})(wysihtml5);
--- /dev/null
+(function(wysihtml5) {
+ var dom = wysihtml5.dom,
+ // Following elements are grouped
+ // when the caret is within a H1 and the H4 is invoked, the H1 should turn into H4
+ // instead of creating a H4 within a H1 which would result in semantically invalid html
+ BLOCK_ELEMENTS_GROUP = ["H1", "H2", "H3", "H4", "H5", "H6", "P", "PRE", "DIV"];
+
+ /**
+ * Remove similiar classes (based on classRegExp)
+ * and add the desired class name
+ */
+ function _addClass(element, className, classRegExp) {
+ if (element.className) {
+ _removeClass(element, classRegExp);
+ element.className = wysihtml5.lang.string(element.className + " " + className).trim();
+ } else {
+ element.className = className;
+ }
+ }
+
+ function _addStyle(element, cssStyle, styleRegExp) {
+ _removeStyle(element, styleRegExp);
+ if (element.getAttribute('style')) {
+ element.setAttribute('style', wysihtml5.lang.string(element.getAttribute('style') + " " + cssStyle).trim());
+ } else {
+ element.setAttribute('style', cssStyle);
+ }
+ }
+
+ function _removeClass(element, classRegExp) {
+ var ret = classRegExp.test(element.className);
+ element.className = element.className.replace(classRegExp, "");
+ if (wysihtml5.lang.string(element.className).trim() == '') {
+ element.removeAttribute('class');
+ }
+ return ret;
+ }
+
+ function _removeStyle(element, styleRegExp) {
+ var ret = styleRegExp.test(element.getAttribute('style'));
+ element.setAttribute('style', (element.getAttribute('style') || "").replace(styleRegExp, ""));
+ if (wysihtml5.lang.string(element.getAttribute('style') || "").trim() == '') {
+ element.removeAttribute('style');
+ }
+ return ret;
+ }
+
+ function _removeLastChildIfLineBreak(node) {
+ var lastChild = node.lastChild;
+ if (lastChild && _isLineBreak(lastChild)) {
+ lastChild.parentNode.removeChild(lastChild);
+ }
+ }
+
+ function _isLineBreak(node) {
+ return node.nodeName === "BR";
+ }
+
+ /**
+ * Execute native query command
+ * and if necessary modify the inserted node's className
+ */
+ function _execCommand(doc, composer, command, nodeName, className) {
+ var ranges = composer.selection.getOwnRanges();
+ for (var i = ranges.length; i--;){
+ composer.selection.getSelection().removeAllRanges();
+ composer.selection.setSelection(ranges[i]);
+ if (className) {
+ var eventListener = dom.observe(doc, "DOMNodeInserted", function(event) {
+ var target = event.target,
+ displayStyle;
+ if (target.nodeType !== wysihtml5.ELEMENT_NODE) {
+ return;
+ }
+ displayStyle = dom.getStyle("display").from(target);
+ if (displayStyle.substr(0, 6) !== "inline") {
+ // Make sure that only block elements receive the given class
+ target.className += " " + className;
+ }
+ });
+ }
+ doc.execCommand(command, false, nodeName);
+
+ if (eventListener) {
+ eventListener.stop();
+ }
+ }
+ }
+
+ function _selectionWrap(composer, options) {
+ if (composer.selection.isCollapsed()) {
+ composer.selection.selectLine();
+ }
+
+ var surroundedNodes = composer.selection.surround(options);
+ for (var i = 0, imax = surroundedNodes.length; i < imax; i++) {
+ wysihtml5.dom.lineBreaks(surroundedNodes[i]).remove();
+ _removeLastChildIfLineBreak(surroundedNodes[i]);
+ }
+
+ // rethink restoring selection
+ // composer.selection.selectNode(element, wysihtml5.browser.displaysCaretInEmptyContentEditableCorrectly());
+ }
+
+ function _hasClasses(element) {
+ return !!wysihtml5.lang.string(element.className).trim();
+ }
+
+ function _hasStyles(element) {
+ return !!wysihtml5.lang.string(element.getAttribute('style') || '').trim();
+ }
+
+ wysihtml5.commands.formatBlock = {
+ exec: function(composer, command, nodeName, className, classRegExp, cssStyle, styleRegExp) {
+ var doc = composer.doc,
+ blockElements = this.state(composer, command, nodeName, className, classRegExp, cssStyle, styleRegExp),
+ useLineBreaks = composer.config.useLineBreaks,
+ defaultNodeName = useLineBreaks ? "DIV" : "P",
+ selectedNodes, classRemoveAction, blockRenameFound, styleRemoveAction, blockElement;
+ nodeName = typeof(nodeName) === "string" ? nodeName.toUpperCase() : nodeName;
+
+ if (blockElements.length) {
+ composer.selection.executeAndRestoreRangy(function() {
+ for (var b = blockElements.length; b--;) {
+ if (classRegExp) {
+ classRemoveAction = _removeClass(blockElements[b], classRegExp);
+ }
+ if (styleRegExp) {
+ styleRemoveAction = _removeStyle(blockElements[b], styleRegExp);
+ }
+
+ if ((styleRemoveAction || classRemoveAction) && nodeName === null && blockElements[b].nodeName != defaultNodeName) {
+ // dont rename or remove element when just setting block formating class or style
+ return;
+ }
+
+ var hasClasses = _hasClasses(blockElements[b]),
+ hasStyles = _hasStyles(blockElements[b]);
+
+ if (!hasClasses && !hasStyles && (useLineBreaks || nodeName === "P")) {
+ // Insert a line break afterwards and beforewards when there are siblings
+ // that are not of type line break or block element
+ wysihtml5.dom.lineBreaks(blockElements[b]).add();
+ dom.replaceWithChildNodes(blockElements[b]);
+ } else {
+ // Make sure that styling is kept by renaming the element to a <div> or <p> and copying over the class name
+ dom.renameElement(blockElements[b], nodeName === "P" ? "DIV" : defaultNodeName);
+ }
+ }
+ });
+
+ return;
+ }
+
+ // Find similiar block element and rename it (<h2 class="foo"></h2> => <h1 class="foo"></h1>)
+ if (nodeName === null || wysihtml5.lang.array(BLOCK_ELEMENTS_GROUP).contains(nodeName)) {
+ selectedNodes = composer.selection.findNodesInSelection(BLOCK_ELEMENTS_GROUP).concat(composer.selection.getSelectedOwnNodes());
+ composer.selection.executeAndRestoreRangy(function() {
+ for (var n = selectedNodes.length; n--;) {
+ blockElement = dom.getParentElement(selectedNodes[n], {
+ nodeName: BLOCK_ELEMENTS_GROUP
+ });
+ if (blockElement == composer.element) {
+ blockElement = null;
+ }
+ if (blockElement) {
+ // Rename current block element to new block element and add class
+ if (nodeName) {
+ blockElement = dom.renameElement(blockElement, nodeName);
+ }
+ if (className) {
+ _addClass(blockElement, className, classRegExp);
+ }
+ if (cssStyle) {
+ _addStyle(blockElement, cssStyle, styleRegExp);
+ }
+ blockRenameFound = true;
+ }
+ }
+
+ });
+
+ if (blockRenameFound) {
+ return;
+ }
+ }
+
+ _selectionWrap(composer, {
+ "nodeName": (nodeName || defaultNodeName),
+ "className": className || null,
+ "cssStyle": cssStyle || null
+ });
+ },
+
+ state: function(composer, command, nodeName, className, classRegExp, cssStyle, styleRegExp) {
+ var nodes = composer.selection.getSelectedOwnNodes(),
+ parents = [],
+ parent;
+
+ nodeName = typeof(nodeName) === "string" ? nodeName.toUpperCase() : nodeName;
+
+ //var selectedNode = composer.selection.getSelectedNode();
+ for (var i = 0, maxi = nodes.length; i < maxi; i++) {
+ parent = dom.getParentElement(nodes[i], {
+ nodeName: nodeName,
+ className: className,
+ classRegExp: classRegExp,
+ cssStyle: cssStyle,
+ styleRegExp: styleRegExp
+ });
+ if (parent && wysihtml5.lang.array(parents).indexOf(parent) == -1) {
+ parents.push(parent);
+ }
+ }
+ if (parents.length == 0) {
+ return false;
+ }
+ return parents;
+ }
+
+
+ };
+})(wysihtml5);
--- /dev/null
+/* Formats block for as a <pre><code class="classname"></code></pre> block
+ * Useful in conjuction for sytax highlight utility: highlight.js
+ *
+ * Usage:
+ *
+ * editorInstance.composer.commands.exec("formatCode", "language-html");
+*/
+
+wysihtml5.commands.formatCode = {
+
+ exec: function(composer, command, classname) {
+ var pre = this.state(composer),
+ code, range, selectedNodes;
+ if (pre) {
+ // caret is already within a <pre><code>...</code></pre>
+ composer.selection.executeAndRestore(function() {
+ code = pre.querySelector("code");
+ wysihtml5.dom.replaceWithChildNodes(pre);
+ if (code) {
+ wysihtml5.dom.replaceWithChildNodes(code);
+ }
+ });
+ } else {
+ // Wrap in <pre><code>...</code></pre>
+ range = composer.selection.getRange();
+ selectedNodes = range.extractContents();
+ pre = composer.doc.createElement("pre");
+ code = composer.doc.createElement("code");
+
+ if (classname) {
+ code.className = classname;
+ }
+
+ pre.appendChild(code);
+ code.appendChild(selectedNodes);
+ range.insertNode(pre);
+ composer.selection.selectNode(pre);
+ }
+ },
+
+ state: function(composer) {
+ var selectedNode = composer.selection.getSelectedNode();
+ if (selectedNode && selectedNode.nodeName && selectedNode.nodeName == "PRE"&&
+ selectedNode.firstChild && selectedNode.firstChild.nodeName && selectedNode.firstChild.nodeName == "CODE") {
+ return selectedNode;
+ } else {
+ return wysihtml5.dom.getParentElement(selectedNode, { nodeName: "CODE" }) && wysihtml5.dom.getParentElement(selectedNode, { nodeName: "PRE" });
+ }
+ }
+};
\ No newline at end of file
--- /dev/null
+/**
+ * formatInline scenarios for tag "B" (| = caret, |foo| = selected text)
+ *
+ * #1 caret in unformatted text:
+ * abcdefg|
+ * output:
+ * abcdefg<b>|</b>
+ *
+ * #2 unformatted text selected:
+ * abc|deg|h
+ * output:
+ * abc<b>|deg|</b>h
+ *
+ * #3 unformatted text selected across boundaries:
+ * ab|c <span>defg|h</span>
+ * output:
+ * ab<b>|c </b><span><b>defg</b>|h</span>
+ *
+ * #4 formatted text entirely selected
+ * <b>|abc|</b>
+ * output:
+ * |abc|
+ *
+ * #5 formatted text partially selected
+ * <b>ab|c|</b>
+ * output:
+ * <b>ab</b>|c|
+ *
+ * #6 formatted text selected across boundaries
+ * <span>ab|c</span> <b>de|fgh</b>
+ * output:
+ * <span>ab|c</span> de|<b>fgh</b>
+ */
+(function(wysihtml5) {
+ var // Treat <b> as <strong> and vice versa
+ ALIAS_MAPPING = {
+ "strong": "b",
+ "em": "i",
+ "b": "strong",
+ "i": "em"
+ },
+ htmlApplier = {};
+
+ function _getTagNames(tagName) {
+ var alias = ALIAS_MAPPING[tagName];
+ return alias ? [tagName.toLowerCase(), alias.toLowerCase()] : [tagName.toLowerCase()];
+ }
+
+ function _getApplier(tagName, className, classRegExp, cssStyle, styleRegExp, container) {
+ var identifier = tagName;
+
+ if (className) {
+ identifier += ":" + className;
+ }
+ if (cssStyle) {
+ identifier += ":" + cssStyle;
+ }
+
+ if (!htmlApplier[identifier]) {
+ htmlApplier[identifier] = new wysihtml5.selection.HTMLApplier(_getTagNames(tagName), className, classRegExp, true, cssStyle, styleRegExp, container);
+ }
+
+ return htmlApplier[identifier];
+ }
+
+ wysihtml5.commands.formatInline = {
+ exec: function(composer, command, tagName, className, classRegExp, cssStyle, styleRegExp, dontRestoreSelect, noCleanup) {
+ var range = composer.selection.createRange(),
+ ownRanges = composer.selection.getOwnRanges();
+
+ if (!ownRanges || ownRanges.length == 0) {
+ return false;
+ }
+ composer.selection.getSelection().removeAllRanges();
+
+ _getApplier(tagName, className, classRegExp, cssStyle, styleRegExp, composer.element).toggleRange(ownRanges);
+
+ if (!dontRestoreSelect) {
+ range.setStart(ownRanges[0].startContainer, ownRanges[0].startOffset);
+ range.setEnd(
+ ownRanges[ownRanges.length - 1].endContainer,
+ ownRanges[ownRanges.length - 1].endOffset
+ );
+ composer.selection.setSelection(range);
+ composer.selection.executeAndRestore(function() {
+ if (!noCleanup) {
+ composer.cleanUp();
+ }
+ }, true, true);
+ } else if (!noCleanup) {
+ composer.cleanUp();
+ }
+ },
+
+ // Executes so that if collapsed caret is in a state and executing that state it should unformat that state
+ // It is achieved by selecting the entire state element before executing.
+ // This works on built in contenteditable inline format commands
+ execWithToggle: function(composer, command, tagName, className, classRegExp, cssStyle, styleRegExp) {
+ var that = this;
+
+ if (this.state(composer, command, tagName, className, classRegExp, cssStyle, styleRegExp) &&
+ composer.selection.isCollapsed() &&
+ !composer.selection.caretIsLastInSelection() &&
+ !composer.selection.caretIsFirstInSelection()
+ ) {
+ var state_element = that.state(composer, command, tagName, className, classRegExp)[0];
+ composer.selection.executeAndRestoreRangy(function() {
+ var parent = state_element.parentNode;
+ composer.selection.selectNode(state_element, true);
+ wysihtml5.commands.formatInline.exec(composer, command, tagName, className, classRegExp, cssStyle, styleRegExp, true, true);
+ });
+ } else {
+ if (this.state(composer, command, tagName, className, classRegExp, cssStyle, styleRegExp) && !composer.selection.isCollapsed()) {
+ composer.selection.executeAndRestoreRangy(function() {
+ wysihtml5.commands.formatInline.exec(composer, command, tagName, className, classRegExp, cssStyle, styleRegExp, true, true);
+ });
+ } else {
+ wysihtml5.commands.formatInline.exec(composer, command, tagName, className, classRegExp, cssStyle, styleRegExp);
+ }
+ }
+ },
+
+ state: function(composer, command, tagName, className, classRegExp, cssStyle, styleRegExp) {
+ var doc = composer.doc,
+ aliasTagName = ALIAS_MAPPING[tagName] || tagName,
+ ownRanges, isApplied;
+
+ // Check whether the document contains a node with the desired tagName
+ if (!wysihtml5.dom.hasElementWithTagName(doc, tagName) &&
+ !wysihtml5.dom.hasElementWithTagName(doc, aliasTagName)) {
+ return false;
+ }
+
+ // Check whether the document contains a node with the desired className
+ if (className && !wysihtml5.dom.hasElementWithClassName(doc, className)) {
+ return false;
+ }
+
+ ownRanges = composer.selection.getOwnRanges();
+
+ if (!ownRanges || ownRanges.length === 0) {
+ return false;
+ }
+
+ isApplied = _getApplier(tagName, className, classRegExp, cssStyle, styleRegExp, composer.element).isAppliedToRange(ownRanges);
+
+ return (isApplied && isApplied.elements) ? isApplied.elements : false;
+ }
+ };
+})(wysihtml5);
--- /dev/null
+wysihtml5.commands.indentList = {
+ exec: function(composer, command, value) {
+ var listEls = composer.selection.getSelectionParentsByTag('LI');
+ if (listEls) {
+ return this.tryToPushLiLevel(listEls, composer.selection);
+ }
+ return false;
+ },
+
+ state: function(composer, command) {
+ return false;
+ },
+
+ tryToPushLiLevel: function(liNodes, selection) {
+ var listTag, list, prevLi, liNode, prevLiList,
+ found = false;
+
+ selection.executeAndRestoreRangy(function() {
+
+ for (var i = liNodes.length; i--;) {
+ liNode = liNodes[i];
+ listTag = (liNode.parentNode.nodeName === 'OL') ? 'OL' : 'UL';
+ list = liNode.ownerDocument.createElement(listTag);
+ prevLi = wysihtml5.dom.domNode(liNode).prev({nodeTypes: [wysihtml5.ELEMENT_NODE]});
+ prevLiList = (prevLi) ? prevLi.querySelector('ul, ol') : null;
+
+ if (prevLi) {
+ if (prevLiList) {
+ prevLiList.appendChild(liNode);
+ } else {
+ list.appendChild(liNode);
+ prevLi.appendChild(list);
+ }
+ found = true;
+ }
+ }
+
+ });
+ return found;
+ }
+};
--- /dev/null
+(function(wysihtml5) {
+
+ wysihtml5.commands.insertBlockQuote = {
+ exec: function(composer, command) {
+ var state = this.state(composer, command),
+ endToEndParent = composer.selection.isEndToEndInNode(['H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'P']),
+ prevNode, nextNode;
+
+ composer.selection.executeAndRestore(function() {
+ if (state) {
+ if (composer.config.useLineBreaks) {
+ wysihtml5.dom.lineBreaks(state).add();
+ }
+ wysihtml5.dom.unwrap(state);
+ } else {
+ if (composer.selection.isCollapsed()) {
+ composer.selection.selectLine();
+ }
+
+ if (endToEndParent) {
+ var qouteEl = endToEndParent.ownerDocument.createElement('blockquote');
+ wysihtml5.dom.insert(qouteEl).after(endToEndParent);
+ qouteEl.appendChild(endToEndParent);
+ } else {
+ composer.selection.surround({nodeName: "blockquote"});
+ }
+ }
+ });
+ },
+ state: function(composer, command) {
+ var selectedNode = composer.selection.getSelectedNode(),
+ node = wysihtml5.dom.getParentElement(selectedNode, { nodeName: "BLOCKQUOTE" }, false, composer.element);
+
+ return (node) ? node : false;
+ }
+ };
+
+})(wysihtml5);
\ No newline at end of file
--- /dev/null
+wysihtml5.commands.insertHTML = {
+ exec: function(composer, command, html) {
+ if (composer.commands.support(command)) {
+ composer.doc.execCommand(command, false, html);
+ } else {
+ composer.selection.insertHTML(html);
+ }
+ },
+
+ state: function() {
+ return false;
+ }
+};
--- /dev/null
+(function(wysihtml5) {
+ var NODE_NAME = "IMG";
+
+ wysihtml5.commands.insertImage = {
+ /**
+ * Inserts an <img>
+ * If selection is already an image link, it removes it
+ *
+ * @example
+ * // either ...
+ * wysihtml5.commands.insertImage.exec(composer, "insertImage", "http://www.google.de/logo.jpg");
+ * // ... or ...
+ * wysihtml5.commands.insertImage.exec(composer, "insertImage", { src: "http://www.google.de/logo.jpg", title: "foo" });
+ */
+ exec: function(composer, command, value) {
+ value = typeof(value) === "object" ? value : { src: value };
+
+ var doc = composer.doc,
+ image = this.state(composer),
+ textNode,
+ parent;
+
+ if (image) {
+ // Image already selected, set the caret before it and delete it
+ composer.selection.setBefore(image);
+ parent = image.parentNode;
+ parent.removeChild(image);
+
+ // and it's parent <a> too if it hasn't got any other relevant child nodes
+ wysihtml5.dom.removeEmptyTextNodes(parent);
+ if (parent.nodeName === "A" && !parent.firstChild) {
+ composer.selection.setAfter(parent);
+ parent.parentNode.removeChild(parent);
+ }
+
+ // firefox and ie sometimes don't remove the image handles, even though the image got removed
+ wysihtml5.quirks.redraw(composer.element);
+ return;
+ }
+
+ image = doc.createElement(NODE_NAME);
+
+ for (var i in value) {
+ image.setAttribute(i === "className" ? "class" : i, value[i]);
+ }
+
+ composer.selection.insertNode(image);
+ if (wysihtml5.browser.hasProblemsSettingCaretAfterImg()) {
+ textNode = doc.createTextNode(wysihtml5.INVISIBLE_SPACE);
+ composer.selection.insertNode(textNode);
+ composer.selection.setAfter(textNode);
+ } else {
+ composer.selection.setAfter(image);
+ }
+ },
+
+ state: function(composer) {
+ var doc = composer.doc,
+ selectedNode,
+ text,
+ imagesInSelection;
+
+ if (!wysihtml5.dom.hasElementWithTagName(doc, NODE_NAME)) {
+ return false;
+ }
+
+ selectedNode = composer.selection.getSelectedNode();
+ if (!selectedNode) {
+ return false;
+ }
+
+ if (selectedNode.nodeName === NODE_NAME) {
+ // This works perfectly in IE
+ return selectedNode;
+ }
+
+ if (selectedNode.nodeType !== wysihtml5.ELEMENT_NODE) {
+ return false;
+ }
+
+ text = composer.selection.getText();
+ text = wysihtml5.lang.string(text).trim();
+ if (text) {
+ return false;
+ }
+
+ imagesInSelection = composer.selection.getNodes(wysihtml5.ELEMENT_NODE, function(node) {
+ return node.nodeName === "IMG";
+ });
+
+ if (imagesInSelection.length !== 1) {
+ return false;
+ }
+
+ return imagesInSelection[0];
+ }
+ };
+})(wysihtml5);
--- /dev/null
+(function(wysihtml5) {
+ var LINE_BREAK = "<br>" + (wysihtml5.browser.needsSpaceAfterLineBreak() ? " " : "");
+
+ wysihtml5.commands.insertLineBreak = {
+ exec: function(composer, command) {
+ if (composer.commands.support(command)) {
+ composer.doc.execCommand(command, false, null);
+ if (!wysihtml5.browser.autoScrollsToCaret()) {
+ composer.selection.scrollIntoView();
+ }
+ } else {
+ composer.commands.exec("insertHTML", LINE_BREAK);
+ }
+ },
+
+ state: function() {
+ return false;
+ }
+ };
+})(wysihtml5);
--- /dev/null
+wysihtml5.commands.insertList = (function(wysihtml5) {
+
+ var isNode = function(node, name) {
+ if (node && node.nodeName) {
+ if (typeof name === 'string') {
+ name = [name];
+ }
+ for (var n = name.length; n--;) {
+ if (node.nodeName === name[n]) {
+ return true;
+ }
+ }
+ }
+ return false;
+ };
+
+ var findListEl = function(node, nodeName, composer) {
+ var ret = {
+ el: null,
+ other: false
+ };
+
+ if (node) {
+ var parentLi = wysihtml5.dom.getParentElement(node, { nodeName: "LI" }),
+ otherNodeName = (nodeName === "UL") ? "OL" : "UL";
+
+ if (isNode(node, nodeName)) {
+ ret.el = node;
+ } else if (isNode(node, otherNodeName)) {
+ ret = {
+ el: node,
+ other: true
+ };
+ } else if (parentLi) {
+ if (isNode(parentLi.parentNode, nodeName)) {
+ ret.el = parentLi.parentNode;
+ } else if (isNode(parentLi.parentNode, otherNodeName)) {
+ ret = {
+ el : parentLi.parentNode,
+ other: true
+ };
+ }
+ }
+ }
+
+ // do not count list elements outside of composer
+ if (ret.el && !composer.element.contains(ret.el)) {
+ ret.el = null;
+ }
+
+ return ret;
+ };
+
+ var handleSameTypeList = function(el, nodeName, composer) {
+ var otherNodeName = (nodeName === "UL") ? "OL" : "UL",
+ otherLists, innerLists;
+ // Unwrap list
+ // <ul><li>foo</li><li>bar</li></ul>
+ // becomes:
+ // foo<br>bar<br>
+ composer.selection.executeAndRestore(function() {
+ var otherLists = getListsInSelection(otherNodeName, composer);
+ if (otherLists.length) {
+ for (var l = otherLists.length; l--;) {
+ wysihtml5.dom.renameElement(otherLists[l], nodeName.toLowerCase());
+ }
+ } else {
+ innerLists = getListsInSelection(['OL', 'UL'], composer);
+ for (var i = innerLists.length; i--;) {
+ wysihtml5.dom.resolveList(innerLists[i], composer.config.useLineBreaks);
+ }
+ wysihtml5.dom.resolveList(el, composer.config.useLineBreaks);
+ }
+ });
+ };
+
+ var handleOtherTypeList = function(el, nodeName, composer) {
+ var otherNodeName = (nodeName === "UL") ? "OL" : "UL";
+ // Turn an ordered list into an unordered list
+ // <ol><li>foo</li><li>bar</li></ol>
+ // becomes:
+ // <ul><li>foo</li><li>bar</li></ul>
+ // Also rename other lists in selection
+ composer.selection.executeAndRestore(function() {
+ var renameLists = [el].concat(getListsInSelection(otherNodeName, composer));
+
+ // All selection inner lists get renamed too
+ for (var l = renameLists.length; l--;) {
+ wysihtml5.dom.renameElement(renameLists[l], nodeName.toLowerCase());
+ }
+ });
+ };
+
+ var getListsInSelection = function(nodeName, composer) {
+ var ranges = composer.selection.getOwnRanges(),
+ renameLists = [];
+
+ for (var r = ranges.length; r--;) {
+ renameLists = renameLists.concat(ranges[r].getNodes([1], function(node) {
+ return isNode(node, nodeName);
+ }));
+ }
+
+ return renameLists;
+ };
+
+ var createListFallback = function(nodeName, composer) {
+ // Fallback for Create list
+ composer.selection.executeAndRestoreRangy(function() {
+ var tempClassName = "_wysihtml5-temp-" + new Date().getTime(),
+ tempElement = composer.selection.deblockAndSurround({
+ "nodeName": "div",
+ "className": tempClassName
+ }),
+ isEmpty, list;
+
+ // This space causes new lists to never break on enter
+ var INVISIBLE_SPACE_REG_EXP = /\uFEFF/g;
+ tempElement.innerHTML = tempElement.innerHTML.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "");
+
+ if (tempElement) {
+ isEmpty = wysihtml5.lang.array(["", "<br>", wysihtml5.INVISIBLE_SPACE]).contains(tempElement.innerHTML);
+ list = wysihtml5.dom.convertToList(tempElement, nodeName.toLowerCase(), composer.parent.config.uneditableContainerClassname);
+ if (isEmpty) {
+ composer.selection.selectNode(list.querySelector("li"), true);
+ }
+ }
+ });
+ };
+
+ return {
+ exec: function(composer, command, nodeName) {
+ var doc = composer.doc,
+ cmd = (nodeName === "OL") ? "insertOrderedList" : "insertUnorderedList",
+ selectedNode = composer.selection.getSelectedNode(),
+ list = findListEl(selectedNode, nodeName, composer);
+
+ if (!list.el) {
+ if (composer.commands.support(cmd)) {
+ doc.execCommand(cmd, false, null);
+ } else {
+ createListFallback(nodeName, composer);
+ }
+ } else if (list.other) {
+ handleOtherTypeList(list.el, nodeName, composer);
+ } else {
+ handleSameTypeList(list.el, nodeName, composer);
+ }
+ },
+
+ state: function(composer, command, nodeName) {
+ var selectedNode = composer.selection.getSelectedNode(),
+ list = findListEl(selectedNode, nodeName, composer);
+
+ return (list.el && !list.other) ? list.el : false;
+ }
+ };
+
+})(wysihtml5);
\ No newline at end of file
--- /dev/null
+wysihtml5.commands.insertOrderedList = {
+ exec: function(composer, command) {
+ wysihtml5.commands.insertList.exec(composer, command, "OL");
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.insertList.state(composer, command, "OL");
+ }
+};
--- /dev/null
+wysihtml5.commands.insertUnorderedList = {
+ exec: function(composer, command) {
+ wysihtml5.commands.insertList.exec(composer, command, "UL");
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.insertList.state(composer, command, "UL");
+ }
+};
--- /dev/null
+wysihtml5.commands.italic = {
+ exec: function(composer, command) {
+ wysihtml5.commands.formatInline.execWithToggle(composer, command, "i");
+ },
+
+ state: function(composer, command) {
+ // element.ownerDocument.queryCommandState("italic") results:
+ // firefox: only <i>
+ // chrome: <i>, <em>, <blockquote>, ...
+ // ie: <i>, <em>
+ // opera: only <i>
+ return wysihtml5.commands.formatInline.state(composer, command, "i");
+ }
+};
--- /dev/null
+(function(wysihtml5) {
+ var CLASS_NAME = "wysiwyg-text-align-center",
+ REG_EXP = /wysiwyg-text-align-[0-9a-z]+/g;
+
+ wysihtml5.commands.justifyCenter = {
+ exec: function(composer, command) {
+ return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", null, CLASS_NAME, REG_EXP);
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatBlock.state(composer, "formatBlock", null, CLASS_NAME, REG_EXP);
+ }
+ };
+})(wysihtml5);
--- /dev/null
+(function(wysihtml5) {
+ var CLASS_NAME = "wysiwyg-text-align-justify",
+ REG_EXP = /wysiwyg-text-align-[0-9a-z]+/g;
+
+ wysihtml5.commands.justifyFull = {
+ exec: function(composer, command) {
+ return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", null, CLASS_NAME, REG_EXP);
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatBlock.state(composer, "formatBlock", null, CLASS_NAME, REG_EXP);
+ }
+ };
+})(wysihtml5);
--- /dev/null
+(function(wysihtml5) {
+ var CLASS_NAME = "wysiwyg-text-align-left",
+ REG_EXP = /wysiwyg-text-align-[0-9a-z]+/g;
+
+ wysihtml5.commands.justifyLeft = {
+ exec: function(composer, command) {
+ return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", null, CLASS_NAME, REG_EXP);
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatBlock.state(composer, "formatBlock", null, CLASS_NAME, REG_EXP);
+ }
+ };
+})(wysihtml5);
--- /dev/null
+(function(wysihtml5) {
+ var CLASS_NAME = "wysiwyg-text-align-right",
+ REG_EXP = /wysiwyg-text-align-[0-9a-z]+/g;
+
+ wysihtml5.commands.justifyRight = {
+ exec: function(composer, command) {
+ return wysihtml5.commands.formatBlock.exec(composer, "formatBlock", null, CLASS_NAME, REG_EXP);
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatBlock.state(composer, "formatBlock", null, CLASS_NAME, REG_EXP);
+ }
+ };
+})(wysihtml5);
--- /dev/null
+wysihtml5.commands.mergeTableCells = {
+ exec: function(composer, command) {
+ if (composer.tableSelection && composer.tableSelection.start && composer.tableSelection.end) {
+ if (this.state(composer, command)) {
+ wysihtml5.dom.table.unmergeCell(composer.tableSelection.start);
+ } else {
+ wysihtml5.dom.table.mergeCellsBetween(composer.tableSelection.start, composer.tableSelection.end);
+ }
+ }
+ },
+
+ state: function(composer, command) {
+ if (composer.tableSelection) {
+ var start = composer.tableSelection.start,
+ end = composer.tableSelection.end;
+ if (start && end && start == end &&
+ ((
+ wysihtml5.dom.getAttribute(start, "colspan") &&
+ parseInt(wysihtml5.dom.getAttribute(start, "colspan"), 10) > 1
+ ) || (
+ wysihtml5.dom.getAttribute(start, "rowspan") &&
+ parseInt(wysihtml5.dom.getAttribute(start, "rowspan"), 10) > 1
+ ))
+ ) {
+ return [start];
+ }
+ }
+ return false;
+ }
+};
--- /dev/null
+wysihtml5.commands.outdentList = {
+ exec: function(composer, command, value) {
+ var listEls = composer.selection.getSelectionParentsByTag('LI');
+ if (listEls) {
+ return this.tryToPullLiLevel(listEls, composer);
+ }
+ return false;
+ },
+
+ state: function(composer, command) {
+ return false;
+ },
+
+ tryToPullLiLevel: function(liNodes, composer) {
+ var listNode, outerListNode, outerLiNode, list, prevLi, liNode, afterList,
+ found = false,
+ that = this;
+
+ composer.selection.executeAndRestoreRangy(function() {
+
+ for (var i = liNodes.length; i--;) {
+ liNode = liNodes[i];
+ if (liNode.parentNode) {
+ listNode = liNode.parentNode;
+
+ if (listNode.tagName === 'OL' || listNode.tagName === 'UL') {
+ found = true;
+
+ outerListNode = wysihtml5.dom.getParentElement(listNode.parentNode, { nodeName: ['OL', 'UL']}, false, composer.element);
+ outerLiNode = wysihtml5.dom.getParentElement(listNode.parentNode, { nodeName: ['LI']}, false, composer.element);
+
+ if (outerListNode && outerLiNode) {
+
+ if (liNode.nextSibling) {
+ afterList = that.getAfterList(listNode, liNode);
+ liNode.appendChild(afterList);
+ }
+ outerListNode.insertBefore(liNode, outerLiNode.nextSibling);
+
+ } else {
+
+ if (liNode.nextSibling) {
+ afterList = that.getAfterList(listNode, liNode);
+ liNode.appendChild(afterList);
+ }
+
+ for (var j = liNode.childNodes.length; j--;) {
+ listNode.parentNode.insertBefore(liNode.childNodes[j], listNode.nextSibling);
+ }
+
+ listNode.parentNode.insertBefore(document.createElement('br'), listNode.nextSibling);
+ liNode.parentNode.removeChild(liNode);
+
+ }
+
+ // cleanup
+ if (listNode.childNodes.length === 0) {
+ listNode.parentNode.removeChild(listNode);
+ }
+ }
+ }
+ }
+
+ });
+ return found;
+ },
+
+ getAfterList: function(listNode, liNode) {
+ var nodeName = listNode.nodeName,
+ newList = document.createElement(nodeName);
+
+ while (liNode.nextSibling) {
+ newList.appendChild(liNode.nextSibling);
+ }
+ return newList;
+ }
+
+};
\ No newline at end of file
--- /dev/null
+wysihtml5.commands.redo = {
+ exec: function(composer) {
+ return composer.undoManager.redo();
+ },
+
+ state: function(composer) {
+ return false;
+ }
+};
--- /dev/null
+(function(wysihtml5) {
+ var dom = wysihtml5.dom;
+
+ function _removeFormat(composer, anchors) {
+ var length = anchors.length,
+ i = 0,
+ anchor,
+ codeElement,
+ textContent;
+ for (; i<length; i++) {
+ anchor = anchors[i];
+ codeElement = dom.getParentElement(anchor, { nodeName: "code" });
+ textContent = dom.getTextContent(anchor);
+
+ // if <a> contains url-like text content, rename it to <code> to prevent re-autolinking
+ // else replace <a> with its childNodes
+ if (textContent.match(dom.autoLink.URL_REG_EXP) && !codeElement) {
+ // <code> element is used to prevent later auto-linking of the content
+ codeElement = dom.renameElement(anchor, "code");
+ } else {
+ dom.replaceWithChildNodes(anchor);
+ }
+ }
+ }
+
+ wysihtml5.commands.removeLink = {
+ /*
+ * If selection is a link, it removes the link and wraps it with a <code> element
+ * The <code> element is needed to avoid auto linking
+ *
+ * @example
+ * wysihtml5.commands.createLink.exec(composer, "removeLink");
+ */
+
+ exec: function(composer, command) {
+ var anchors = this.state(composer, command);
+ if (anchors) {
+ composer.selection.executeAndRestore(function() {
+ _removeFormat(composer, anchors);
+ });
+ }
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatInline.state(composer, command, "A");
+ }
+ };
+})(wysihtml5);
--- /dev/null
+wysihtml5.commands.underline = {
+ exec: function(composer, command) {
+ wysihtml5.commands.formatInline.execWithToggle(composer, command, "u");
+ },
+
+ state: function(composer, command) {
+ return wysihtml5.commands.formatInline.state(composer, command, "u");
+ }
+};
--- /dev/null
+wysihtml5.commands.undo = {
+ exec: function(composer) {
+ return composer.undoManager.undo();
+ },
+
+ state: function(composer) {
+ return false;
+ }
+};
--- /dev/null
+/**
+ * Find urls in descendant text nodes of an element and auto-links them
+ * Inspired by http://james.padolsey.com/javascript/find-and-replace-text-with-javascript/
+ *
+ * @param {Element} element Container element in which to search for urls
+ *
+ * @example
+ * <div id="text-container">Please click here: www.google.com</div>
+ * <script>wysihtml5.dom.autoLink(document.getElementById("text-container"));</script>
+ */
+(function(wysihtml5) {
+ var /**
+ * Don't auto-link urls that are contained in the following elements:
+ */
+ IGNORE_URLS_IN = wysihtml5.lang.array(["CODE", "PRE", "A", "SCRIPT", "HEAD", "TITLE", "STYLE"]),
+ /**
+ * revision 1:
+ * /(\S+\.{1}[^\s\,\.\!]+)/g
+ *
+ * revision 2:
+ * /(\b(((https?|ftp):\/\/)|(www\.))[-A-Z0-9+&@#\/%?=~_|!:,.;\[\]]*[-A-Z0-9+&@#\/%=~_|])/gim
+ *
+ * put this in the beginning if you don't wan't to match within a word
+ * (^|[\>\(\{\[\s\>])
+ */
+ URL_REG_EXP = /((https?:\/\/|www\.)[^\s<]{3,})/gi,
+ TRAILING_CHAR_REG_EXP = /([^\w\/\-](,?))$/i,
+ MAX_DISPLAY_LENGTH = 100,
+ BRACKETS = { ")": "(", "]": "[", "}": "{" };
+
+ function autoLink(element, ignoreInClasses) {
+ if (_hasParentThatShouldBeIgnored(element, ignoreInClasses)) {
+ return element;
+ }
+
+ if (element === element.ownerDocument.documentElement) {
+ element = element.ownerDocument.body;
+ }
+
+ return _parseNode(element, ignoreInClasses);
+ }
+
+ /**
+ * This is basically a rebuild of
+ * the rails auto_link_urls text helper
+ */
+ function _convertUrlsToLinks(str) {
+ return str.replace(URL_REG_EXP, function(match, url) {
+ var punctuation = (url.match(TRAILING_CHAR_REG_EXP) || [])[1] || "",
+ opening = BRACKETS[punctuation];
+ url = url.replace(TRAILING_CHAR_REG_EXP, "");
+
+ if (url.split(opening).length > url.split(punctuation).length) {
+ url = url + punctuation;
+ punctuation = "";
+ }
+ var realUrl = url,
+ displayUrl = url;
+ if (url.length > MAX_DISPLAY_LENGTH) {
+ displayUrl = displayUrl.substr(0, MAX_DISPLAY_LENGTH) + "...";
+ }
+ // Add http prefix if necessary
+ if (realUrl.substr(0, 4) === "www.") {
+ realUrl = "http://" + realUrl;
+ }
+
+ return '<a href="' + realUrl + '">' + displayUrl + '</a>' + punctuation;
+ });
+ }
+
+ /**
+ * Creates or (if already cached) returns a temp element
+ * for the given document object
+ */
+ function _getTempElement(context) {
+ var tempElement = context._wysihtml5_tempElement;
+ if (!tempElement) {
+ tempElement = context._wysihtml5_tempElement = context.createElement("div");
+ }
+ return tempElement;
+ }
+
+ /**
+ * Replaces the original text nodes with the newly auto-linked dom tree
+ */
+ function _wrapMatchesInNode(textNode) {
+ var parentNode = textNode.parentNode,
+ nodeValue = wysihtml5.lang.string(textNode.data).escapeHTML(),
+ tempElement = _getTempElement(parentNode.ownerDocument);
+
+ // We need to insert an empty/temporary <span /> to fix IE quirks
+ // Elsewise IE would strip white space in the beginning
+ tempElement.innerHTML = "<span></span>" + _convertUrlsToLinks(nodeValue);
+ tempElement.removeChild(tempElement.firstChild);
+
+ while (tempElement.firstChild) {
+ // inserts tempElement.firstChild before textNode
+ parentNode.insertBefore(tempElement.firstChild, textNode);
+ }
+ parentNode.removeChild(textNode);
+ }
+
+ function _hasParentThatShouldBeIgnored(node, ignoreInClasses) {
+ var nodeName;
+ while (node.parentNode) {
+ node = node.parentNode;
+ nodeName = node.nodeName;
+ if (node.className && wysihtml5.lang.array(node.className.split(' ')).contains(ignoreInClasses)) {
+ return true;
+ }
+ if (IGNORE_URLS_IN.contains(nodeName)) {
+ return true;
+ } else if (nodeName === "body") {
+ return false;
+ }
+ }
+ return false;
+ }
+
+ function _parseNode(element, ignoreInClasses) {
+ if (IGNORE_URLS_IN.contains(element.nodeName)) {
+ return;
+ }
+
+ if (element.className && wysihtml5.lang.array(element.className.split(' ')).contains(ignoreInClasses)) {
+ return;
+ }
+
+ if (element.nodeType === wysihtml5.TEXT_NODE && element.data.match(URL_REG_EXP)) {
+ _wrapMatchesInNode(element);
+ return;
+ }
+
+ var childNodes = wysihtml5.lang.array(element.childNodes).get(),
+ childNodesLength = childNodes.length,
+ i = 0;
+
+ for (; i<childNodesLength; i++) {
+ _parseNode(childNodes[i], ignoreInClasses);
+ }
+
+ return element;
+ }
+
+ wysihtml5.dom.autoLink = autoLink;
+
+ // Reveal url reg exp to the outside
+ wysihtml5.dom.autoLink.URL_REG_EXP = URL_REG_EXP;
+})(wysihtml5);
--- /dev/null
+(function(wysihtml5) {
+ var api = wysihtml5.dom;
+
+ api.addClass = function(element, className) {
+ var classList = element.classList;
+ if (classList) {
+ return classList.add(className);
+ }
+ if (api.hasClass(element, className)) {
+ return;
+ }
+ element.className += " " + className;
+ };
+
+ api.removeClass = function(element, className) {
+ var classList = element.classList;
+ if (classList) {
+ return classList.remove(className);
+ }
+
+ element.className = element.className.replace(new RegExp("(^|\\s+)" + className + "(\\s+|$)"), " ");
+ };
+
+ api.hasClass = function(element, className) {
+ var classList = element.classList;
+ if (classList) {
+ return classList.contains(className);
+ }
+
+ var elementClassName = element.className;
+ return (elementClassName.length > 0 && (elementClassName == className || new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName)));
+ };
+})(wysihtml5);
--- /dev/null
+wysihtml5.dom.compareDocumentPosition = (function() {
+ var documentElement = document.documentElement;
+ if (documentElement.compareDocumentPosition) {
+ return function(container, element) {
+ return container.compareDocumentPosition(element);
+ };
+ } else {
+ return function( container, element ) {
+ // implementation borrowed from https://github.com/tmpvar/jsdom/blob/681a8524b663281a0f58348c6129c8c184efc62c/lib/jsdom/level3/core.js // MIT license
+ var thisOwner, otherOwner;
+
+ if( container.nodeType === 9) // Node.DOCUMENT_NODE
+ thisOwner = container;
+ else
+ thisOwner = container.ownerDocument;
+
+ if( element.nodeType === 9) // Node.DOCUMENT_NODE
+ otherOwner = element;
+ else
+ otherOwner = element.ownerDocument;
+
+ if( container === element ) return 0;
+ if( container === element.ownerDocument ) return 4 + 16; //Node.DOCUMENT_POSITION_FOLLOWING + Node.DOCUMENT_POSITION_CONTAINED_BY;
+ if( container.ownerDocument === element ) return 2 + 8; //Node.DOCUMENT_POSITION_PRECEDING + Node.DOCUMENT_POSITION_CONTAINS;
+ if( thisOwner !== otherOwner ) return 1; // Node.DOCUMENT_POSITION_DISCONNECTED;
+
+ // Text nodes for attributes does not have a _parentNode. So we need to find them as attribute child.
+ if( container.nodeType === 2 /*Node.ATTRIBUTE_NODE*/ && container.childNodes && wysihtml5.lang.array(container.childNodes).indexOf( element ) !== -1)
+ return 4 + 16; //Node.DOCUMENT_POSITION_FOLLOWING + Node.DOCUMENT_POSITION_CONTAINED_BY;
+
+ if( element.nodeType === 2 /*Node.ATTRIBUTE_NODE*/ && element.childNodes && wysihtml5.lang.array(element.childNodes).indexOf( container ) !== -1)
+ return 2 + 8; //Node.DOCUMENT_POSITION_PRECEDING + Node.DOCUMENT_POSITION_CONTAINS;
+
+ var point = container;
+ var parents = [ ];
+ var previous = null;
+ while( point ) {
+ if( point == element ) return 2 + 8; //Node.DOCUMENT_POSITION_PRECEDING + Node.DOCUMENT_POSITION_CONTAINS;
+ parents.push( point );
+ point = point.parentNode;
+ }
+ point = element;
+ previous = null;
+ while( point ) {
+ if( point == container ) return 4 + 16; //Node.DOCUMENT_POSITION_FOLLOWING + Node.DOCUMENT_POSITION_CONTAINED_BY;
+ var location_index = wysihtml5.lang.array(parents).indexOf( point );
+ if( location_index !== -1) {
+ var smallest_common_ancestor = parents[ location_index ];
+ var this_index = wysihtml5.lang.array(smallest_common_ancestor.childNodes).indexOf( parents[location_index - 1]);//smallest_common_ancestor.childNodes.toArray().indexOf( parents[location_index - 1] );
+ var other_index = wysihtml5.lang.array(smallest_common_ancestor.childNodes).indexOf( previous ); //smallest_common_ancestor.childNodes.toArray().indexOf( previous );
+ if( this_index > other_index ) {
+ return 2; //Node.DOCUMENT_POSITION_PRECEDING;
+ }
+ else {
+ return 4; //Node.DOCUMENT_POSITION_FOLLOWING;
+ }
+ }
+ previous = point;
+ point = point.parentNode;
+ }
+ return 1; //Node.DOCUMENT_POSITION_DISCONNECTED;
+ };
+ }
+})();
--- /dev/null
+wysihtml5.dom.contains = (function() {
+ var documentElement = document.documentElement;
+ if (documentElement.contains) {
+ return function(container, element) {
+ if (element.nodeType !== wysihtml5.ELEMENT_NODE) {
+ element = element.parentNode;
+ }
+ return container !== element && container.contains(element);
+ };
+ } else if (documentElement.compareDocumentPosition) {
+ return function(container, element) {
+ // https://developer.mozilla.org/en/DOM/Node.compareDocumentPosition
+ return !!(container.compareDocumentPosition(element) & 16);
+ };
+ }
+})();
--- /dev/null
+(function(wysihtml5) {
+ var doc = document;
+ wysihtml5.dom.ContentEditableArea = Base.extend({
+ getContentEditable: function() {
+ return this.element;
+ },
+
+ getWindow: function() {
+ return this.element.ownerDocument.defaultView;
+ },
+
+ getDocument: function() {
+ return this.element.ownerDocument;
+ },
+
+ constructor: function(readyCallback, config, contentEditable) {
+ this.callback = readyCallback || wysihtml5.EMPTY_FUNCTION;
+ this.config = wysihtml5.lang.object({}).merge(config).get();
+ if (contentEditable) {
+ this.element = this._bindElement(contentEditable);
+ } else {
+ this.element = this._createElement();
+ }
+ },
+
+ // creates a new contenteditable and initiates it
+ _createElement: function() {
+ var element = doc.createElement("div");
+ element.className = "wysihtml5-sandbox";
+ this._loadElement(element);
+ return element;
+ },
+
+ // initiates an allready existent contenteditable
+ _bindElement: function(contentEditable) {
+ contentEditable.className = (contentEditable.className && contentEditable.className != '') ? contentEditable.className + " wysihtml5-sandbox" : "wysihtml5-sandbox";
+ this._loadElement(contentEditable, true);
+ return contentEditable;
+ },
+
+ _loadElement: function(element, contentExists) {
+ var that = this;
+ if (!contentExists) {
+ var sandboxHtml = this._getHtml();
+ element.innerHTML = sandboxHtml;
+ }
+
+ this.getWindow = function() { return element.ownerDocument.defaultView; };
+ this.getDocument = function() { return element.ownerDocument; };
+
+ // Catch js errors and pass them to the parent's onerror event
+ // addEventListener("error") doesn't work properly in some browsers
+ // TODO: apparently this doesn't work in IE9!
+ // TODO: figure out and bind the errors logic for contenteditble mode
+ /*iframeWindow.onerror = function(errorMessage, fileName, lineNumber) {
+ throw new Error("wysihtml5.Sandbox: " + errorMessage, fileName, lineNumber);
+ }
+ */
+ this.loaded = true;
+ // Trigger the callback
+ setTimeout(function() { that.callback(that); }, 0);
+ },
+
+ _getHtml: function(templateVars) {
+ return '';
+ }
+
+ });
+})(wysihtml5);
--- /dev/null
+/**
+ * Converts an HTML fragment/element into a unordered/ordered list
+ *
+ * @param {Element} element The element which should be turned into a list
+ * @param {String} listType The list type in which to convert the tree (either "ul" or "ol")
+ * @return {Element} The created list
+ *
+ * @example
+ * <!-- Assume the following dom: -->
+ * <span id="pseudo-list">
+ * eminem<br>
+ * dr. dre
+ * <div>50 Cent</div>
+ * </span>
+ *
+ * <script>
+ * wysihtml5.dom.convertToList(document.getElementById("pseudo-list"), "ul");
+ * </script>
+ *
+ * <!-- Will result in: -->
+ * <ul>
+ * <li>eminem</li>
+ * <li>dr. dre</li>
+ * <li>50 Cent</li>
+ * </ul>
+ */
+wysihtml5.dom.convertToList = (function() {
+ function _createListItem(doc, list) {
+ var listItem = doc.createElement("li");
+ list.appendChild(listItem);
+ return listItem;
+ }
+
+ function _createList(doc, type) {
+ return doc.createElement(type);
+ }
+
+ function convertToList(element, listType, uneditableClass) {
+ if (element.nodeName === "UL" || element.nodeName === "OL" || element.nodeName === "MENU") {
+ // Already a list
+ return element;
+ }
+
+ var doc = element.ownerDocument,
+ list = _createList(doc, listType),
+ lineBreaks = element.querySelectorAll("br"),
+ lineBreaksLength = lineBreaks.length,
+ childNodes,
+ childNodesLength,
+ childNode,
+ lineBreak,
+ parentNode,
+ isBlockElement,
+ isLineBreak,
+ currentListItem,
+ i;
+
+ // First find <br> at the end of inline elements and move them behind them
+ for (i=0; i<lineBreaksLength; i++) {
+ lineBreak = lineBreaks[i];
+ while ((parentNode = lineBreak.parentNode) && parentNode !== element && parentNode.lastChild === lineBreak) {
+ if (wysihtml5.dom.getStyle("display").from(parentNode) === "block") {
+ parentNode.removeChild(lineBreak);
+ break;
+ }
+ wysihtml5.dom.insert(lineBreak).after(lineBreak.parentNode);
+ }
+ }
+
+ childNodes = wysihtml5.lang.array(element.childNodes).get();
+ childNodesLength = childNodes.length;
+
+ for (i=0; i<childNodesLength; i++) {
+ currentListItem = currentListItem || _createListItem(doc, list);
+ childNode = childNodes[i];
+ isBlockElement = wysihtml5.dom.getStyle("display").from(childNode) === "block";
+ isLineBreak = childNode.nodeName === "BR";
+
+ // consider uneditable as an inline element
+ if (isBlockElement && (!uneditableClass || !wysihtml5.dom.hasClass(childNode, uneditableClass))) {
+ // Append blockElement to current <li> if empty, otherwise create a new one
+ currentListItem = currentListItem.firstChild ? _createListItem(doc, list) : currentListItem;
+ currentListItem.appendChild(childNode);
+ currentListItem = null;
+ continue;
+ }
+
+ if (isLineBreak) {
+ // Only create a new list item in the next iteration when the current one has already content
+ currentListItem = currentListItem.firstChild ? null : currentListItem;
+ continue;
+ }
+
+ currentListItem.appendChild(childNode);
+ }
+
+ if (childNodes.length === 0) {
+ _createListItem(doc, list);
+ }
+
+ element.parentNode.replaceChild(list, element);
+ return list;
+ }
+
+ return convertToList;
+})();
--- /dev/null
+/**
+ * Copy a set of attributes from one element to another
+ *
+ * @param {Array} attributesToCopy List of attributes which should be copied
+ * @return {Object} Returns an object which offers the "from" method which can be invoked with the element where to
+ * copy the attributes from., this again returns an object which provides a method named "to" which can be invoked
+ * with the element where to copy the attributes to (see example)
+ *
+ * @example
+ * var textarea = document.querySelector("textarea"),
+ * div = document.querySelector("div[contenteditable=true]"),
+ * anotherDiv = document.querySelector("div.preview");
+ * wysihtml5.dom.copyAttributes(["spellcheck", "value", "placeholder"]).from(textarea).to(div).andTo(anotherDiv);
+ *
+ */
+wysihtml5.dom.copyAttributes = function(attributesToCopy) {
+ return {
+ from: function(elementToCopyFrom) {
+ return {
+ to: function(elementToCopyTo) {
+ var attribute,
+ i = 0,
+ length = attributesToCopy.length;
+ for (; i<length; i++) {
+ attribute = attributesToCopy[i];
+ if (typeof(elementToCopyFrom[attribute]) !== "undefined" && elementToCopyFrom[attribute] !== "") {
+ elementToCopyTo[attribute] = elementToCopyFrom[attribute];
+ }
+ }
+ return { andTo: arguments.callee };
+ }
+ };
+ }
+ };
+};
--- /dev/null
+/**
+ * Copy a set of styles from one element to another
+ * Please note that this only works properly across browsers when the element from which to copy the styles
+ * is in the dom
+ *
+ * Interesting article on how to copy styles
+ *
+ * @param {Array} stylesToCopy List of styles which should be copied
+ * @return {Object} Returns an object which offers the "from" method which can be invoked with the element where to
+ * copy the styles from., this again returns an object which provides a method named "to" which can be invoked
+ * with the element where to copy the styles to (see example)
+ *
+ * @example
+ * var textarea = document.querySelector("textarea"),
+ * div = document.querySelector("div[contenteditable=true]"),
+ * anotherDiv = document.querySelector("div.preview");
+ * wysihtml5.dom.copyStyles(["overflow-y", "width", "height"]).from(textarea).to(div).andTo(anotherDiv);
+ *
+ */
+(function(dom) {
+
+ /**
+ * Mozilla, WebKit and Opera recalculate the computed width when box-sizing: boder-box; is set
+ * So if an element has "width: 200px; -moz-box-sizing: border-box; border: 1px;" then
+ * its computed css width will be 198px
+ *
+ * See https://bugzilla.mozilla.org/show_bug.cgi?id=520992
+ */
+ var BOX_SIZING_PROPERTIES = ["-webkit-box-sizing", "-moz-box-sizing", "-ms-box-sizing", "box-sizing"];
+
+ var shouldIgnoreBoxSizingBorderBox = function(element) {
+ if (hasBoxSizingBorderBox(element)) {
+ return parseInt(dom.getStyle("width").from(element), 10) < element.offsetWidth;
+ }
+ return false;
+ };
+
+ var hasBoxSizingBorderBox = function(element) {
+ var i = 0,
+ length = BOX_SIZING_PROPERTIES.length;
+ for (; i<length; i++) {
+ if (dom.getStyle(BOX_SIZING_PROPERTIES[i]).from(element) === "border-box") {
+ return BOX_SIZING_PROPERTIES[i];
+ }
+ }
+ };
+
+ dom.copyStyles = function(stylesToCopy) {
+ return {
+ from: function(element) {
+ if (shouldIgnoreBoxSizingBorderBox(element)) {
+ stylesToCopy = wysihtml5.lang.array(stylesToCopy).without(BOX_SIZING_PROPERTIES);
+ }
+
+ var cssText = "",
+ length = stylesToCopy.length,
+ i = 0,
+ property;
+ for (; i<length; i++) {
+ property = stylesToCopy[i];
+ cssText += property + ":" + dom.getStyle(property).from(element) + ";";
+ }
+
+ return {
+ to: function(element) {
+ dom.setStyles(cssText).on(element);
+ return { andTo: arguments.callee };
+ }
+ };
+ }
+ };
+ };
+})(wysihtml5.dom);
--- /dev/null
+/**
+ * Event Delegation
+ *
+ * @example
+ * wysihtml5.dom.delegate(document.body, "a", "click", function() {
+ * // foo
+ * });
+ */
+(function(wysihtml5) {
+
+ wysihtml5.dom.delegate = function(container, selector, eventName, handler) {
+ return wysihtml5.dom.observe(container, eventName, function(event) {
+ var target = event.target,
+ match = wysihtml5.lang.array(container.querySelectorAll(selector));
+
+ while (target && target !== container) {
+ if (match.contains(target)) {
+ handler.call(target, event);
+ break;
+ }
+ target = target.parentNode;
+ }
+ });
+ };
+
+})(wysihtml5);
--- /dev/null
+// TODO: Refactor dom tree traversing here
+(function(wysihtml5) {
+ wysihtml5.dom.domNode = function(node) {
+ var defaultNodeTypes = [wysihtml5.ELEMENT_NODE, wysihtml5.TEXT_NODE];
+
+ var _isBlankText = function(node) {
+ return node.nodeType === wysihtml5.TEXT_NODE && (/^\s*$/g).test(node.data);
+ };
+
+ return {
+
+ // var node = wysihtml5.dom.domNode(element).prev({nodeTypes: [1,3], ignoreBlankTexts: true});
+ prev: function(options) {
+ var prevNode = node.previousSibling,
+ types = (options && options.nodeTypes) ? options.nodeTypes : defaultNodeTypes;
+
+ if (!prevNode) {
+ return null;
+ }
+
+ if (
+ (!wysihtml5.lang.array(types).contains(prevNode.nodeType)) || // nodeTypes check.
+ (options && options.ignoreBlankTexts && _isBlankText(prevNode)) // Blank text nodes bypassed if set
+ ) {
+ return wysihtml5.dom.domNode(prevNode).prev(options);
+ }
+
+ return prevNode;
+ },
+
+ // var node = wysihtml5.dom.domNode(element).next({nodeTypes: [1,3], ignoreBlankTexts: true});
+ next: function(options) {
+ var nextNode = node.nextSibling,
+ types = (options && options.nodeTypes) ? options.nodeTypes : defaultNodeTypes;
+
+ if (!nextNode) {
+ return null;
+ }
+
+ if (
+ (!wysihtml5.lang.array(types).contains(nextNode.nodeType)) || // nodeTypes check.
+ (options && options.ignoreBlankTexts && _isBlankText(nextNode)) // blank text nodes bypassed if set
+ ) {
+ return wysihtml5.dom.domNode(nextNode).next(options);
+ }
+
+ return nextNode;
+ },
+
+ // Traverses a node for last children and their chidren (including itself), and finds the last node that has no children.
+ // Array of classes for forced last-leaves (ex: uneditable-container) can be defined (options = {leafClasses: [...]})
+ // Useful for finding the actually visible element before cursor
+ lastLeafNode: function(options) {
+ var lastChild;
+
+ // Returns non-element nodes
+ if (node.nodeType !== 1) {
+ return node;
+ }
+
+ // Returns if element is leaf
+ lastChild = node.lastChild;
+ if (!lastChild) {
+ return node;
+ }
+
+ // Returns if element is of of options.leafClasses leaf
+ if (options && options.leafClasses) {
+ for (var i = options.leafClasses.length; i--;) {
+ if (wysihtml5.dom.hasClass(node, options.leafClasses[i])) {
+ return node;
+ }
+ }
+ }
+
+ return wysihtml5.dom.domNode(lastChild).lastLeafNode(options);
+ }
+
+ };
+ };
+})(wysihtml5);
\ No newline at end of file
--- /dev/null
+/**
+ * Returns the given html wrapped in a div element
+ *
+ * Fixing IE's inability to treat unknown elements (HTML5 section, article, ...) correctly
+ * when inserted via innerHTML
+ *
+ * @param {String} html The html which should be wrapped in a dom element
+ * @param {Obejct} [context] Document object of the context the html belongs to
+ *
+ * @example
+ * wysihtml5.dom.getAsDom("<article>foo</article>");
+ */
+wysihtml5.dom.getAsDom = (function() {
+
+ var _innerHTMLShiv = function(html, context) {
+ var tempElement = context.createElement("div");
+ tempElement.style.display = "none";
+ context.body.appendChild(tempElement);
+ // IE throws an exception when trying to insert <frameset></frameset> via innerHTML
+ try { tempElement.innerHTML = html; } catch(e) {}
+ context.body.removeChild(tempElement);
+ return tempElement;
+ };
+
+ /**
+ * Make sure IE supports HTML5 tags, which is accomplished by simply creating one instance of each element
+ */
+ var _ensureHTML5Compatibility = function(context) {
+ if (context._wysihtml5_supportsHTML5Tags) {
+ return;
+ }
+ for (var i=0, length=HTML5_ELEMENTS.length; i<length; i++) {
+ context.createElement(HTML5_ELEMENTS[i]);
+ }
+ context._wysihtml5_supportsHTML5Tags = true;
+ };
+
+
+ /**
+ * List of html5 tags
+ * taken from http://simon.html5.org/html5-elements
+ */
+ var HTML5_ELEMENTS = [
+ "abbr", "article", "aside", "audio", "bdi", "canvas", "command", "datalist", "details", "figcaption",
+ "figure", "footer", "header", "hgroup", "keygen", "mark", "meter", "nav", "output", "progress",
+ "rp", "rt", "ruby", "svg", "section", "source", "summary", "time", "track", "video", "wbr"
+ ];
+
+ return function(html, context) {
+ context = context || document;
+ var tempElement;
+ if (typeof(html) === "object" && html.nodeType) {
+ tempElement = context.createElement("div");
+ tempElement.appendChild(html);
+ } else if (wysihtml5.browser.supportsHTML5Tags(context)) {
+ tempElement = context.createElement("div");
+ tempElement.innerHTML = html;
+ } else {
+ _ensureHTML5Compatibility(context);
+ tempElement = _innerHTMLShiv(html, context);
+ }
+ return tempElement;
+ };
+})();
--- /dev/null
+/**
+ * Get a set of attribute from one element
+ *
+ * IE gives wrong results for hasAttribute/getAttribute, for example:
+ * var td = document.createElement("td");
+ * td.getAttribute("rowspan"); // => "1" in IE
+ *
+ * Therefore we have to check the element's outerHTML for the attribute
+*/
+
+wysihtml5.dom.getAttribute = function(node, attributeName) {
+ var HAS_GET_ATTRIBUTE_BUG = !wysihtml5.browser.supportsGetAttributeCorrectly();
+ attributeName = attributeName.toLowerCase();
+ var nodeName = node.nodeName;
+ if (nodeName == "IMG" && attributeName == "src" && wysihtml5.dom.isLoadedImage(node) === true) {
+ // Get 'src' attribute value via object property since this will always contain the
+ // full absolute url (http://...)
+ // this fixes a very annoying bug in firefox (ver 3.6 & 4) and IE 8 where images copied from the same host
+ // will have relative paths, which the sanitizer strips out (see attributeCheckMethods.url)
+ return node.src;
+ } else if (HAS_GET_ATTRIBUTE_BUG && "outerHTML" in node) {
+ // Don't trust getAttribute/hasAttribute in IE 6-8, instead check the element's outerHTML
+ var outerHTML = node.outerHTML.toLowerCase(),
+ // TODO: This might not work for attributes without value: <input disabled>
+ hasAttribute = outerHTML.indexOf(" " + attributeName + "=") != -1;
+
+ return hasAttribute ? node.getAttribute(attributeName) : null;
+ } else{
+ return node.getAttribute(attributeName);
+ }
+};
--- /dev/null
+/**
+ * Get all attributes of an element
+ *
+ * IE gives wrong results for hasAttribute/getAttribute, for example:
+ * var td = document.createElement("td");
+ * td.getAttribute("rowspan"); // => "1" in IE
+ *
+ * Therefore we have to check the element's outerHTML for the attribute
+*/
+
+wysihtml5.dom.getAttributes = function(node) {
+ var HAS_GET_ATTRIBUTE_BUG = !wysihtml5.browser.supportsGetAttributeCorrectly(),
+ nodeName = node.nodeName,
+ attributes = [],
+ attr;
+
+ for (attr in node.attributes) {
+ if ((node.attributes.hasOwnProperty && node.attributes.hasOwnProperty(attr)) || (!node.attributes.hasOwnProperty && Object.prototype.hasOwnProperty.call(node.attributes, attr))) {
+ if (node.attributes[attr].specified) {
+ if (nodeName == "IMG" && node.attributes[attr].name.toLowerCase() == "src" && wysihtml5.dom.isLoadedImage(node) === true) {
+ attributes['src'] = node.src;
+ } else if (wysihtml5.lang.array(['rowspan', 'colspan']).contains(node.attributes[attr].name.toLowerCase()) && HAS_GET_ATTRIBUTE_BUG) {
+ if (node.attributes[attr].value !== 1) {
+ attributes[node.attributes[attr].name] = node.attributes[attr].value;
+ }
+ } else {
+ attributes[node.attributes[attr].name] = node.attributes[attr].value;
+ }
+ }
+ }
+ }
+ return attributes;
+};
\ No newline at end of file
--- /dev/null
+/**
+ * Walks the dom tree from the given node up until it finds a match
+ * Designed for optimal performance.
+ *
+ * @param {Element} node The from which to check the parent nodes
+ * @param {Object} matchingSet Object to match against (possible properties: nodeName, className, classRegExp)
+ * @param {Number} [levels] How many parents should the function check up from the current node (defaults to 50)
+ * @return {null|Element} Returns the first element that matched the desiredNodeName(s)
+ * @example
+ * var listElement = wysihtml5.dom.getParentElement(document.querySelector("li"), { nodeName: ["MENU", "UL", "OL"] });
+ * // ... or ...
+ * var unorderedListElement = wysihtml5.dom.getParentElement(document.querySelector("li"), { nodeName: "UL" });
+ * // ... or ...
+ * var coloredElement = wysihtml5.dom.getParentElement(myTextNode, { nodeName: "SPAN", className: "wysiwyg-color-red", classRegExp: /wysiwyg-color-[a-z]/g });
+ */
+wysihtml5.dom.getParentElement = (function() {
+
+ function _isSameNodeName(nodeName, desiredNodeNames) {
+ if (!desiredNodeNames || !desiredNodeNames.length) {
+ return true;
+ }
+
+ if (typeof(desiredNodeNames) === "string") {
+ return nodeName === desiredNodeNames;
+ } else {
+ return wysihtml5.lang.array(desiredNodeNames).contains(nodeName);
+ }
+ }
+
+ function _isElement(node) {
+ return node.nodeType === wysihtml5.ELEMENT_NODE;
+ }
+
+ function _hasClassName(element, className, classRegExp) {
+ var classNames = (element.className || "").match(classRegExp) || [];
+ if (!className) {
+ return !!classNames.length;
+ }
+ return classNames[classNames.length - 1] === className;
+ }
+
+ function _hasStyle(element, cssStyle, styleRegExp) {
+ var styles = (element.getAttribute('style') || "").match(styleRegExp) || [];
+ if (!cssStyle) {
+ return !!styles.length;
+ }
+ return styles[styles.length - 1] === cssStyle;
+ }
+
+ return function(node, matchingSet, levels, container) {
+ var findByStyle = (matchingSet.cssStyle || matchingSet.styleRegExp),
+ findByClass = (matchingSet.className || matchingSet.classRegExp);
+
+ levels = levels || 50; // Go max 50 nodes upwards from current node
+
+ // make the matching class regex from class name if omitted
+ if (findByClass && !matchingSet.classRegExp) {
+ matchingSet.classRegExp = new RegExp(matchingSet.className);
+ }
+
+ while (levels-- && node && node.nodeName !== "BODY" && (!container || node !== container)) {
+ if (_isElement(node) && (!matchingSet.nodeName || _isSameNodeName(node.nodeName, matchingSet.nodeName)) &&
+ (!findByStyle || _hasStyle(node, matchingSet.cssStyle, matchingSet.styleRegExp)) &&
+ (!findByClass || _hasClassName(node, matchingSet.className, matchingSet.classRegExp))
+ ) {
+ return node;
+ }
+ node = node.parentNode;
+ }
+ return null;
+ };
+})();
--- /dev/null
+/*
+ * Methods for fetching pasted html before it gets inserted into content
+**/
+
+/* Modern event.clipboardData driven approach.
+ * Advantage is that it does not have to loose selection or modify dom to catch the data.
+ * IE does not support though.
+**/
+wysihtml5.dom.getPastedHtml = function(event) {
+ var html;
+ if (event.clipboardData) {
+ if (wysihtml5.lang.array(event.clipboardData.types).contains('text/html')) {
+ html = event.clipboardData.getData('text/html');
+ } else if (wysihtml5.lang.array(event.clipboardData.types).contains('text/plain')) {
+ html = wysihtml5.lang.string(event.clipboardData.getData('text/plain')).escapeHTML(true, true);
+ }
+ }
+ return html;
+};
+
+/* Older temprorary contenteditable as paste source catcher method for fallbacks */
+wysihtml5.dom.getPastedHtmlWithDiv = function (composer, f) {
+ var selBookmark = composer.selection.getBookmark(),
+ doc = composer.element.ownerDocument,
+ cleanerDiv = doc.createElement('DIV');
+
+ doc.body.appendChild(cleanerDiv);
+
+ cleanerDiv.style.width = "1px";
+ cleanerDiv.style.height = "1px";
+ cleanerDiv.style.overflow = "hidden";
+
+ cleanerDiv.setAttribute('contenteditable', 'true');
+ cleanerDiv.focus();
+
+ setTimeout(function () {
+ composer.selection.setBookmark(selBookmark);
+ f(cleanerDiv.innerHTML);
+ cleanerDiv.parentNode.removeChild(cleanerDiv);
+ }, 0);
+};
\ No newline at end of file
--- /dev/null
+/**
+ * Get element's style for a specific css property
+ *
+ * @param {Element} element The element on which to retrieve the style
+ * @param {String} property The CSS property to retrieve ("float", "display", "text-align", ...)
+ *
+ * @example
+ * wysihtml5.dom.getStyle("display").from(document.body);
+ * // => "block"
+ */
+wysihtml5.dom.getStyle = (function() {
+ var stylePropertyMapping = {
+ "float": ("styleFloat" in document.createElement("div").style) ? "styleFloat" : "cssFloat"
+ },
+ REG_EXP_CAMELIZE = /\-[a-z]/g;
+
+ function camelize(str) {
+ return str.replace(REG_EXP_CAMELIZE, function(match) {
+ return match.charAt(1).toUpperCase();
+ });
+ }
+
+ return function(property) {
+ return {
+ from: function(element) {
+ if (element.nodeType !== wysihtml5.ELEMENT_NODE) {
+ return;
+ }
+
+ var doc = element.ownerDocument,
+ camelizedProperty = stylePropertyMapping[property] || camelize(property),
+ style = element.style,
+ currentStyle = element.currentStyle,
+ styleValue = style[camelizedProperty];
+ if (styleValue) {
+ return styleValue;
+ }
+
+ // currentStyle is no standard and only supported by Opera and IE but it has one important advantage over the standard-compliant
+ // window.getComputedStyle, since it returns css property values in their original unit:
+ // If you set an elements width to "50%", window.getComputedStyle will give you it's current width in px while currentStyle
+ // gives you the original "50%".
+ // Opera supports both, currentStyle and window.getComputedStyle, that's why checking for currentStyle should have higher prio
+ if (currentStyle) {
+ try {
+ return currentStyle[camelizedProperty];
+ } catch(e) {
+ //ie will occasionally fail for unknown reasons. swallowing exception
+ }
+ }
+
+ var win = doc.defaultView || doc.parentWindow,
+ needsOverflowReset = (property === "height" || property === "width") && element.nodeName === "TEXTAREA",
+ originalOverflow,
+ returnValue;
+
+ if (win.getComputedStyle) {
+ // Chrome and Safari both calculate a wrong width and height for textareas when they have scroll bars
+ // therfore we remove and restore the scrollbar and calculate the value in between
+ if (needsOverflowReset) {
+ originalOverflow = style.overflow;
+ style.overflow = "hidden";
+ }
+ returnValue = win.getComputedStyle(element, null).getPropertyValue(property);
+ if (needsOverflowReset) {
+ style.overflow = originalOverflow || "";
+ }
+ return returnValue;
+ }
+ }
+ };
+ };
+})();
--- /dev/null
+wysihtml5.dom.getTextNodes = function(node, ingoreEmpty){
+ var all = [];
+ for (node=node.firstChild;node;node=node.nextSibling){
+ if (node.nodeType == 3) {
+ if (!ingoreEmpty || !(/^\s*$/).test(node.innerText || node.textContent)) {
+ all.push(node);
+ }
+ } else {
+ all = all.concat(wysihtml5.dom.getTextNodes(node, ingoreEmpty));
+ }
+ }
+ return all;
+};
\ No newline at end of file
--- /dev/null
+/**
+ * High performant way to check whether an element with a specific class name is in the given document
+ * Optimized for being heavily executed
+ * Unleashes the power of live node lists
+ *
+ * @param {Object} doc The document object of the context where to check
+ * @param {String} tagName Upper cased tag name
+ * @example
+ * wysihtml5.dom.hasElementWithClassName(document, "foobar");
+ */
+(function(wysihtml5) {
+ var LIVE_CACHE = {},
+ DOCUMENT_IDENTIFIER = 1;
+
+ function _getDocumentIdentifier(doc) {
+ return doc._wysihtml5_identifier || (doc._wysihtml5_identifier = DOCUMENT_IDENTIFIER++);
+ }
+
+ wysihtml5.dom.hasElementWithClassName = function(doc, className) {
+ // getElementsByClassName is not supported by IE<9
+ // but is sometimes mocked via library code (which then doesn't return live node lists)
+ if (!wysihtml5.browser.supportsNativeGetElementsByClassName()) {
+ return !!doc.querySelector("." + className);
+ }
+
+ var key = _getDocumentIdentifier(doc) + ":" + className,
+ cacheEntry = LIVE_CACHE[key];
+ if (!cacheEntry) {
+ cacheEntry = LIVE_CACHE[key] = doc.getElementsByClassName(className);
+ }
+
+ return cacheEntry.length > 0;
+ };
+})(wysihtml5);
--- /dev/null
+/**
+ * High performant way to check whether an element with a specific tag name is in the given document
+ * Optimized for being heavily executed
+ * Unleashes the power of live node lists
+ *
+ * @param {Object} doc The document object of the context where to check
+ * @param {String} tagName Upper cased tag name
+ * @example
+ * wysihtml5.dom.hasElementWithTagName(document, "IMG");
+ */
+wysihtml5.dom.hasElementWithTagName = (function() {
+ var LIVE_CACHE = {},
+ DOCUMENT_IDENTIFIER = 1;
+
+ function _getDocumentIdentifier(doc) {
+ return doc._wysihtml5_identifier || (doc._wysihtml5_identifier = DOCUMENT_IDENTIFIER++);
+ }
+
+ return function(doc, tagName) {
+ var key = _getDocumentIdentifier(doc) + ":" + tagName,
+ cacheEntry = LIVE_CACHE[key];
+ if (!cacheEntry) {
+ cacheEntry = LIVE_CACHE[key] = doc.getElementsByTagName(tagName);
+ }
+
+ return cacheEntry.length > 0;
+ };
+})();
--- /dev/null
+wysihtml5.dom.insert = function(elementToInsert) {
+ return {
+ after: function(element) {
+ element.parentNode.insertBefore(elementToInsert, element.nextSibling);
+ },
+
+ before: function(element) {
+ element.parentNode.insertBefore(elementToInsert, element);
+ },
+
+ into: function(element) {
+ element.appendChild(elementToInsert);
+ }
+ };
+};
--- /dev/null
+wysihtml5.dom.insertCSS = function(rules) {
+ rules = rules.join("\n");
+
+ return {
+ into: function(doc) {
+ var styleElement = doc.createElement("style");
+ styleElement.type = "text/css";
+
+ if (styleElement.styleSheet) {
+ styleElement.styleSheet.cssText = rules;
+ } else {
+ styleElement.appendChild(doc.createTextNode(rules));
+ }
+
+ var link = doc.querySelector("head link");
+ if (link) {
+ link.parentNode.insertBefore(styleElement, link);
+ return;
+ } else {
+ var head = doc.querySelector("head");
+ if (head) {
+ head.appendChild(styleElement);
+ }
+ }
+ }
+ };
+};
--- /dev/null
+/**
+ * Check whether the given node is a proper loaded image
+ * FIXME: Returns undefined when unknown (Chrome, Safari)
+*/
+
+wysihtml5.dom.isLoadedImage = function (node) {
+ try {
+ return node.complete && !node.mozMatchesSelector(":-moz-broken");
+ } catch(e) {
+ if (node.complete && node.readyState === "complete") {
+ return true;
+ }
+ }
+};
--- /dev/null
+// TODO: Refactor dom tree traversing here
+(function(wysihtml5) {
+ wysihtml5.dom.lineBreaks = function(node) {
+
+ function _isLineBreak(n) {
+ return n.nodeName === "BR";
+ }
+
+ /**
+ * Checks whether the elment causes a visual line break
+ * (<br> or block elements)
+ */
+ function _isLineBreakOrBlockElement(element) {
+ if (_isLineBreak(element)) {
+ return true;
+ }
+
+ if (wysihtml5.dom.getStyle("display").from(element) === "block") {
+ return true;
+ }
+
+ return false;
+ }
+
+ return {
+
+ /* wysihtml5.dom.lineBreaks(element).add();
+ *
+ * Adds line breaks before and after the given node if the previous and next siblings
+ * aren't already causing a visual line break (block element or <br>)
+ */
+ add: function(options) {
+ var doc = node.ownerDocument,
+ nextSibling = wysihtml5.dom.domNode(node).next({ignoreBlankTexts: true}),
+ previousSibling = wysihtml5.dom.domNode(node).prev({ignoreBlankTexts: true});
+
+ if (nextSibling && !_isLineBreakOrBlockElement(nextSibling)) {
+ wysihtml5.dom.insert(doc.createElement("br")).after(node);
+ }
+ if (previousSibling && !_isLineBreakOrBlockElement(previousSibling)) {
+ wysihtml5.dom.insert(doc.createElement("br")).before(node);
+ }
+ },
+
+ /* wysihtml5.dom.lineBreaks(element).remove();
+ *
+ * Removes line breaks before and after the given node
+ */
+ remove: function(options) {
+ var nextSibling = wysihtml5.dom.domNode(node).next({ignoreBlankTexts: true}),
+ previousSibling = wysihtml5.dom.domNode(node).prev({ignoreBlankTexts: true});
+
+ if (nextSibling && _isLineBreak(nextSibling)) {
+ nextSibling.parentNode.removeChild(nextSibling);
+ }
+ if (previousSibling && _isLineBreak(previousSibling)) {
+ previousSibling.parentNode.removeChild(previousSibling);
+ }
+ }
+ };
+ };
+})(wysihtml5);
\ No newline at end of file
--- /dev/null
+/**
+ * Method to set dom events
+ *
+ * @example
+ * wysihtml5.dom.observe(iframe.contentWindow.document.body, ["focus", "blur"], function() { ... });
+ */
+wysihtml5.dom.observe = function(element, eventNames, handler) {
+ eventNames = typeof(eventNames) === "string" ? [eventNames] : eventNames;
+
+ var handlerWrapper,
+ eventName,
+ i = 0,
+ length = eventNames.length;
+
+ for (; i<length; i++) {
+ eventName = eventNames[i];
+ if (element.addEventListener) {
+ element.addEventListener(eventName, handler, false);
+ } else {
+ handlerWrapper = function(event) {
+ if (!("target" in event)) {
+ event.target = event.srcElement;
+ }
+ event.preventDefault = event.preventDefault || function() {
+ this.returnValue = false;
+ };
+ event.stopPropagation = event.stopPropagation || function() {
+ this.cancelBubble = true;
+ };
+ handler.call(element, event);
+ };
+ element.attachEvent("on" + eventName, handlerWrapper);
+ }
+ }
+
+ return {
+ stop: function() {
+ var eventName,
+ i = 0,
+ length = eventNames.length;
+ for (; i<length; i++) {
+ eventName = eventNames[i];
+ if (element.removeEventListener) {
+ element.removeEventListener(eventName, handler, false);
+ } else {
+ element.detachEvent("on" + eventName, handlerWrapper);
+ }
+ }
+ }
+ };
+};
--- /dev/null
+/**
+ * HTML Sanitizer
+ * Rewrites the HTML based on given rules
+ *
+ * @param {Element|String} elementOrHtml HTML String to be sanitized OR element whose content should be sanitized
+ * @param {Object} [rules] List of rules for rewriting the HTML, if there's no rule for an element it will
+ * be converted to a "span". Each rule is a key/value pair where key is the tag to convert, and value the
+ * desired substitution.
+ * @param {Object} context Document object in which to parse the html, needed to sandbox the parsing
+ *
+ * @return {Element|String} Depends on the elementOrHtml parameter. When html then the sanitized html as string elsewise the element.
+ *
+ * @example
+ * var userHTML = '<div id="foo" onclick="alert(1);"><p><font color="red">foo</font><script>alert(1);</script></p></div>';
+ * wysihtml5.dom.parse(userHTML, {
+ * tags {
+ * p: "div", // Rename p tags to div tags
+ * font: "span" // Rename font tags to span tags
+ * div: true, // Keep them, also possible (same result when passing: "div" or true)
+ * script: undefined // Remove script elements
+ * }
+ * });
+ * // => <div><div><span>foo bar</span></div></div>
+ *
+ * var userHTML = '<table><tbody><tr><td>I'm a table!</td></tr></tbody></table>';
+ * wysihtml5.dom.parse(userHTML);
+ * // => '<span><span><span><span>I'm a table!</span></span></span></span>'
+ *
+ * var userHTML = '<div>foobar<br>foobar</div>';
+ * wysihtml5.dom.parse(userHTML, {
+ * tags: {
+ * div: undefined,
+ * br: true
+ * }
+ * });
+ * // => ''
+ *
+ * var userHTML = '<div class="red">foo</div><div class="pink">bar</div>';
+ * wysihtml5.dom.parse(userHTML, {
+ * classes: {
+ * red: 1,
+ * green: 1
+ * },
+ * tags: {
+ * div: {
+ * rename_tag: "p"
+ * }
+ * }
+ * });
+ * // => '<p class="red">foo</p><p>bar</p>'
+ */
+
+wysihtml5.dom.parse = function(elementOrHtml_current, config_current) {
+ /* TODO: Currently escaped module pattern as otherwise folloowing default swill be shared among multiple editors.
+ * Refactor whole code as this method while workind is kind of awkward too */
+
+ /**
+ * It's not possible to use a XMLParser/DOMParser as HTML5 is not always well-formed XML
+ * new DOMParser().parseFromString('<img src="foo.gif">') will cause a parseError since the
+ * node isn't closed
+ *
+ * Therefore we've to use the browser's ordinary HTML parser invoked by setting innerHTML.
+ */
+ var NODE_TYPE_MAPPING = {
+ "1": _handleElement,
+ "3": _handleText,
+ "8": _handleComment
+ },
+ // Rename unknown tags to this
+ DEFAULT_NODE_NAME = "span",
+ WHITE_SPACE_REG_EXP = /\s+/,
+ defaultRules = { tags: {}, classes: {} },
+ currentRules = {},
+ blockElements = ["ADDRESS" ,"BLOCKQUOTE" ,"CENTER" ,"DIR" ,"DIV" ,"DL" ,"FIELDSET" ,
+ "FORM", "H1" ,"H2" ,"H3" ,"H4" ,"H5" ,"H6" ,"ISINDEX" ,"MENU",
+ "NOFRAMES", "NOSCRIPT" ,"OL" ,"P" ,"PRE","TABLE", "UL"];
+
+ /**
+ * Iterates over all childs of the element, recreates them, appends them into a document fragment
+ * which later replaces the entire body content
+ */
+ function parse(elementOrHtml, config) {
+ wysihtml5.lang.object(currentRules).merge(defaultRules).merge(config.rules).get();
+
+ var context = config.context || elementOrHtml.ownerDocument || document,
+ fragment = context.createDocumentFragment(),
+ isString = typeof(elementOrHtml) === "string",
+ clearInternals = false,
+ element,
+ newNode,
+ firstChild;
+
+ if (config.clearInternals === true) {
+ clearInternals = true;
+ }
+
+ if (isString) {
+ element = wysihtml5.dom.getAsDom(elementOrHtml, context);
+ } else {
+ element = elementOrHtml;
+ }
+
+ if (currentRules.selectors) {
+ _applySelectorRules(element, currentRules.selectors);
+ }
+
+ while (element.firstChild) {
+ firstChild = element.firstChild;
+ newNode = _convert(firstChild, config.cleanUp, clearInternals, config.uneditableClass);
+ if (newNode) {
+ fragment.appendChild(newNode);
+ }
+ if (firstChild !== newNode) {
+ element.removeChild(firstChild);
+ }
+ }
+
+ if (config.unjoinNbsps) {
+ // replace joined non-breakable spaces with unjoined
+ var txtnodes = wysihtml5.dom.getTextNodes(fragment);
+ for (var n = txtnodes.length; n--;) {
+ txtnodes[n].nodeValue = txtnodes[n].nodeValue.replace(/([\S\u00A0])\u00A0/gi, "$1 ");
+ }
+ }
+
+ // Clear element contents
+ element.innerHTML = "";
+
+ // Insert new DOM tree
+ element.appendChild(fragment);
+
+ return isString ? wysihtml5.quirks.getCorrectInnerHTML(element) : element;
+ }
+
+ function _convert(oldNode, cleanUp, clearInternals, uneditableClass) {
+ var oldNodeType = oldNode.nodeType,
+ oldChilds = oldNode.childNodes,
+ oldChildsLength = oldChilds.length,
+ method = NODE_TYPE_MAPPING[oldNodeType],
+ i = 0,
+ fragment,
+ newNode,
+ newChild,
+ nodeDisplay;
+
+ // Passes directly elemets with uneditable class
+ if (uneditableClass && oldNodeType === 1 && wysihtml5.dom.hasClass(oldNode, uneditableClass)) {
+ return oldNode;
+ }
+
+ newNode = method && method(oldNode, clearInternals);
+
+ // Remove or unwrap node in case of return value null or false
+ if (!newNode) {
+ if (newNode === false) {
+ // false defines that tag should be removed but contents should remain (unwrap)
+ fragment = oldNode.ownerDocument.createDocumentFragment();
+
+ for (i = oldChildsLength; i--;) {
+ if (oldChilds[i]) {
+ newChild = _convert(oldChilds[i], cleanUp, clearInternals, uneditableClass);
+ if (newChild) {
+ if (oldChilds[i] === newChild) {
+ i--;
+ }
+ fragment.insertBefore(newChild, fragment.firstChild);
+ }
+ }
+ }
+
+ nodeDisplay = wysihtml5.dom.getStyle("display").from(oldNode);
+
+ if (nodeDisplay === '') {
+ // Handle display style when element not in dom
+ nodeDisplay = wysihtml5.lang.array(blockElements).contains(oldNode.tagName) ? "block" : "";
+ }
+ if (wysihtml5.lang.array(["block", "flex", "table"]).contains(nodeDisplay)) {
+ fragment.appendChild(oldNode.ownerDocument.createElement("br"));
+ }
+
+ // TODO: try to minimize surplus spaces
+ if (wysihtml5.lang.array([
+ "div", "pre", "p",
+ "table", "td", "th",
+ "ul", "ol", "li",
+ "dd", "dl",
+ "footer", "header", "section",
+ "h1", "h2", "h3", "h4", "h5", "h6"
+ ]).contains(oldNode.nodeName.toLowerCase()) && oldNode.parentNode.lastChild !== oldNode) {
+ // add space at first when unwraping non-textflow elements
+ if (!oldNode.nextSibling || oldNode.nextSibling.nodeType !== 3 || !(/^\s/).test(oldNode.nextSibling.nodeValue)) {
+ fragment.appendChild(oldNode.ownerDocument.createTextNode(" "));
+ }
+ }
+
+ if (fragment.normalize) {
+ fragment.normalize();
+ }
+ return fragment;
+ } else {
+ // Remove
+ return null;
+ }
+ }
+
+ // Converts all childnodes
+ for (i=0; i<oldChildsLength; i++) {
+ if (oldChilds[i]) {
+ newChild = _convert(oldChilds[i], cleanUp, clearInternals, uneditableClass);
+ if (newChild) {
+ if (oldChilds[i] === newChild) {
+ i--;
+ }
+ newNode.appendChild(newChild);
+ }
+ }
+ }
+
+ // Cleanup senseless <span> elements
+ if (cleanUp &&
+ newNode.nodeName.toLowerCase() === DEFAULT_NODE_NAME &&
+ (!newNode.childNodes.length ||
+ ((/^\s*$/gi).test(newNode.innerHTML) && (clearInternals || (oldNode.className !== "_wysihtml5-temp-placeholder" && oldNode.className !== "rangySelectionBoundary"))) ||
+ !newNode.attributes.length)
+ ) {
+ fragment = newNode.ownerDocument.createDocumentFragment();
+ while (newNode.firstChild) {
+ fragment.appendChild(newNode.firstChild);
+ }
+ if (fragment.normalize) {
+ fragment.normalize();
+ }
+ return fragment;
+ }
+
+ if (newNode.normalize) {
+ newNode.normalize();
+ }
+ return newNode;
+ }
+
+ function _applySelectorRules (element, selectorRules) {
+ var sel, method, els;
+
+ for (sel in selectorRules) {
+ if (selectorRules.hasOwnProperty(sel)) {
+ if (wysihtml5.lang.object(selectorRules[sel]).isFunction()) {
+ method = selectorRules[sel];
+ } else if (typeof(selectorRules[sel]) === "string" && elementHandlingMethods[selectorRules[sel]]) {
+ method = elementHandlingMethods[selectorRules[sel]];
+ }
+ els = element.querySelectorAll(sel);
+ for (var i = els.length; i--;) {
+ method(els[i]);
+ }
+ }
+ }
+ }
+
+ function _handleElement(oldNode, clearInternals) {
+ var rule,
+ newNode,
+ tagRules = currentRules.tags,
+ nodeName = oldNode.nodeName.toLowerCase(),
+ scopeName = oldNode.scopeName,
+ renameTag;
+
+ /**
+ * We already parsed that element
+ * ignore it! (yes, this sometimes happens in IE8 when the html is invalid)
+ */
+ if (oldNode._wysihtml5) {
+ return null;
+ }
+ oldNode._wysihtml5 = 1;
+
+ if (oldNode.className === "wysihtml5-temp") {
+ return null;
+ }
+
+ /**
+ * IE is the only browser who doesn't include the namespace in the
+ * nodeName, that's why we have to prepend it by ourselves
+ * scopeName is a proprietary IE feature
+ * read more here http://msdn.microsoft.com/en-us/library/ms534388(v=vs.85).aspx
+ */
+ if (scopeName && scopeName != "HTML") {
+ nodeName = scopeName + ":" + nodeName;
+ }
+ /**
+ * Repair node
+ * IE is a bit bitchy when it comes to invalid nested markup which includes unclosed tags
+ * A <p> doesn't need to be closed according HTML4-5 spec, we simply replace it with a <div> to preserve its content and layout
+ */
+ if ("outerHTML" in oldNode) {
+ if (!wysihtml5.browser.autoClosesUnclosedTags() &&
+ oldNode.nodeName === "P" &&
+ oldNode.outerHTML.slice(-4).toLowerCase() !== "</p>") {
+ nodeName = "div";
+ }
+ }
+
+ if (nodeName in tagRules) {
+ rule = tagRules[nodeName];
+ if (!rule || rule.remove) {
+ return null;
+ } else if (rule.unwrap) {
+ return false;
+ }
+ rule = typeof(rule) === "string" ? { rename_tag: rule } : rule;
+ } else if (oldNode.firstChild) {
+ rule = { rename_tag: DEFAULT_NODE_NAME };
+ } else {
+ // Remove empty unknown elements
+ return null;
+ }
+
+ // tests if type condition is met or node should be removed/unwrapped/renamed
+ if (rule.one_of_type && !_testTypes(oldNode, currentRules, rule.one_of_type, clearInternals)) {
+ if (rule.remove_action) {
+ if (rule.remove_action === "unwrap") {
+ return false;
+ } else if (rule.remove_action === "rename") {
+ renameTag = rule.remove_action_rename_to || DEFAULT_NODE_NAME;
+ } else {
+ return null;
+ }
+ } else {
+ return null;
+ }
+ }
+
+ newNode = oldNode.ownerDocument.createElement(renameTag || rule.rename_tag || nodeName);
+ _handleAttributes(oldNode, newNode, rule, clearInternals);
+ _handleStyles(oldNode, newNode, rule);
+
+ oldNode = null;
+
+ if (newNode.normalize) { newNode.normalize(); }
+ return newNode;
+ }
+
+ function _testTypes(oldNode, rules, types, clearInternals) {
+ var definition, type;
+
+ // do not interfere with placeholder span or pasting caret position is not maintained
+ if (oldNode.nodeName === "SPAN" && !clearInternals && (oldNode.className === "_wysihtml5-temp-placeholder" || oldNode.className === "rangySelectionBoundary")) {
+ return true;
+ }
+
+ for (type in types) {
+ if (types.hasOwnProperty(type) && rules.type_definitions && rules.type_definitions[type]) {
+ definition = rules.type_definitions[type];
+ if (_testType(oldNode, definition)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ function array_contains(a, obj) {
+ var i = a.length;
+ while (i--) {
+ if (a[i] === obj) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ function _testType(oldNode, definition) {
+
+ var nodeClasses = oldNode.getAttribute("class"),
+ nodeStyles = oldNode.getAttribute("style"),
+ classesLength, s, s_corrected, a, attr, currentClass, styleProp;
+
+ // test for methods
+ if (definition.methods) {
+ for (var m in definition.methods) {
+ if (definition.methods.hasOwnProperty(m) && typeCeckMethods[m]) {
+
+ if (typeCeckMethods[m](oldNode)) {
+ return true;
+ }
+ }
+ }
+ }
+
+ // test for classes, if one found return true
+ if (nodeClasses && definition.classes) {
+ nodeClasses = nodeClasses.replace(/^\s+/g, '').replace(/\s+$/g, '').split(WHITE_SPACE_REG_EXP);
+ classesLength = nodeClasses.length;
+ for (var i = 0; i < classesLength; i++) {
+ if (definition.classes[nodeClasses[i]]) {
+ return true;
+ }
+ }
+ }
+
+ // test for styles, if one found return true
+ if (nodeStyles && definition.styles) {
+
+ nodeStyles = nodeStyles.split(';');
+ for (s in definition.styles) {
+ if (definition.styles.hasOwnProperty(s)) {
+ for (var sp = nodeStyles.length; sp--;) {
+ styleProp = nodeStyles[sp].split(':');
+
+ if (styleProp[0].replace(/\s/g, '').toLowerCase() === s) {
+ if (definition.styles[s] === true || definition.styles[s] === 1 || wysihtml5.lang.array(definition.styles[s]).contains(styleProp[1].replace(/\s/g, '').toLowerCase()) ) {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // test for attributes in general against regex match
+ if (definition.attrs) {
+ for (a in definition.attrs) {
+ if (definition.attrs.hasOwnProperty(a)) {
+ attr = wysihtml5.dom.getAttribute(oldNode, a);
+ if (typeof(attr) === "string") {
+ if (attr.search(definition.attrs[a]) > -1) {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+
+ function _handleStyles(oldNode, newNode, rule) {
+ var s, v;
+ if(rule && rule.keep_styles) {
+ for (s in rule.keep_styles) {
+ if (rule.keep_styles.hasOwnProperty(s)) {
+ v = (s === "float") ? oldNode.style.styleFloat || oldNode.style.cssFloat : oldNode.style[s];
+ // value can be regex and if so should match or style skipped
+ if (rule.keep_styles[s] instanceof RegExp && !(rule.keep_styles[s].test(v))) {
+ continue;
+ }
+ if (s === "float") {
+ // IE compability
+ newNode.style[(oldNode.style.styleFloat) ? 'styleFloat': 'cssFloat'] = v;
+ } else if (oldNode.style[s]) {
+ newNode.style[s] = v;
+ }
+ }
+ }
+ }
+ };
+
+ function _getAttributesBeginningWith(beginning, attributes) {
+ var returnAttributes = [];
+ for (var attr in attributes) {
+ if (attributes.hasOwnProperty(attr) && attr.indexOf(beginning) === 0) {
+ returnAttributes.push(attr);
+ }
+ }
+ return returnAttributes;
+ }
+
+ function _checkAttribute(attributeName, attributeValue, methodName, nodeName) {
+ var method = attributeCheckMethods[methodName],
+ newAttributeValue;
+
+ if (method) {
+ if (attributeValue || (attributeName === "alt" && nodeName == "IMG")) {
+ newAttributeValue = method(attributeValue);
+ if (typeof(newAttributeValue) === "string") {
+ return newAttributeValue;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ function _checkAttributes(oldNode, local_attributes) {
+ var globalAttributes = wysihtml5.lang.object(currentRules.attributes || {}).clone(), // global values for check/convert values of attributes
+ checkAttributes = wysihtml5.lang.object(globalAttributes).merge( wysihtml5.lang.object(local_attributes || {}).clone()).get(),
+ attributes = {},
+ oldAttributes = wysihtml5.dom.getAttributes(oldNode),
+ attributeName, newValue, matchingAttributes;
+
+ for (attributeName in checkAttributes) {
+ if ((/\*$/).test(attributeName)) {
+
+ matchingAttributes = _getAttributesBeginningWith(attributeName.slice(0,-1), oldAttributes);
+ for (var i = 0, imax = matchingAttributes.length; i < imax; i++) {
+
+ newValue = _checkAttribute(matchingAttributes[i], oldAttributes[matchingAttributes[i]], checkAttributes[attributeName], oldNode.nodeName);
+ if (newValue !== false) {
+ attributes[matchingAttributes[i]] = newValue;
+ }
+ }
+ } else {
+ newValue = _checkAttribute(attributeName, oldAttributes[attributeName], checkAttributes[attributeName], oldNode.nodeName);
+ if (newValue !== false) {
+ attributes[attributeName] = newValue;
+ }
+ }
+ }
+
+ return attributes;
+ }
+
+ // TODO: refactor. Too long to read
+ function _handleAttributes(oldNode, newNode, rule, clearInternals) {
+ var attributes = {}, // fresh new set of attributes to set on newNode
+ setClass = rule.set_class, // classes to set
+ addClass = rule.add_class, // add classes based on existing attributes
+ addStyle = rule.add_style, // add styles based on existing attributes
+ setAttributes = rule.set_attributes, // attributes to set on the current node
+ allowedClasses = currentRules.classes,
+ i = 0,
+ classes = [],
+ styles = [],
+ newClasses = [],
+ oldClasses = [],
+ classesLength,
+ newClassesLength,
+ currentClass,
+ newClass,
+ attributeName,
+ method;
+
+ if (setAttributes) {
+ attributes = wysihtml5.lang.object(setAttributes).clone();
+ }
+
+ // check/convert values of attributes
+ attributes = wysihtml5.lang.object(attributes).merge(_checkAttributes(oldNode, rule.check_attributes)).get();
+
+ if (setClass) {
+ classes.push(setClass);
+ }
+
+ if (addClass) {
+ for (attributeName in addClass) {
+ method = addClassMethods[addClass[attributeName]];
+ if (!method) {
+ continue;
+ }
+ newClass = method(wysihtml5.dom.getAttribute(oldNode, attributeName));
+ if (typeof(newClass) === "string") {
+ classes.push(newClass);
+ }
+ }
+ }
+
+ if (addStyle) {
+ for (attributeName in addStyle) {
+ method = addStyleMethods[addStyle[attributeName]];
+ if (!method) {
+ continue;
+ }
+
+ newStyle = method(wysihtml5.dom.getAttribute(oldNode, attributeName));
+ if (typeof(newStyle) === "string") {
+ styles.push(newStyle);
+ }
+ }
+ }
+
+
+ if (typeof(allowedClasses) === "string" && allowedClasses === "any" && oldNode.getAttribute("class")) {
+ if (currentRules.classes_blacklist) {
+ oldClasses = oldNode.getAttribute("class");
+ if (oldClasses) {
+ classes = classes.concat(oldClasses.split(WHITE_SPACE_REG_EXP));
+ }
+
+ classesLength = classes.length;
+ for (; i<classesLength; i++) {
+ currentClass = classes[i];
+ if (!currentRules.classes_blacklist[currentClass]) {
+ newClasses.push(currentClass);
+ }
+ }
+
+ if (newClasses.length) {
+ attributes["class"] = wysihtml5.lang.array(newClasses).unique().join(" ");
+ }
+
+ } else {
+ attributes["class"] = oldNode.getAttribute("class");
+ }
+ } else {
+ // make sure that wysihtml5 temp class doesn't get stripped out
+ if (!clearInternals) {
+ allowedClasses["_wysihtml5-temp-placeholder"] = 1;
+ allowedClasses["_rangySelectionBoundary"] = 1;
+ allowedClasses["wysiwyg-tmp-selected-cell"] = 1;
+ }
+
+ // add old classes last
+ oldClasses = oldNode.getAttribute("class");
+ if (oldClasses) {
+ classes = classes.concat(oldClasses.split(WHITE_SPACE_REG_EXP));
+ }
+ classesLength = classes.length;
+ for (; i<classesLength; i++) {
+ currentClass = classes[i];
+ if (allowedClasses[currentClass]) {
+ newClasses.push(currentClass);
+ }
+ }
+
+ if (newClasses.length) {
+ attributes["class"] = wysihtml5.lang.array(newClasses).unique().join(" ");
+ }
+ }
+
+ // remove table selection class if present
+ if (attributes["class"] && clearInternals) {
+ attributes["class"] = attributes["class"].replace("wysiwyg-tmp-selected-cell", "");
+ if ((/^\s*$/g).test(attributes["class"])) {
+ delete attributes["class"];
+ }
+ }
+
+ if (styles.length) {
+ attributes["style"] = wysihtml5.lang.array(styles).unique().join(" ");
+ }
+
+ // set attributes on newNode
+ for (attributeName in attributes) {
+ // Setting attributes can cause a js error in IE under certain circumstances
+ // eg. on a <img> under https when it's new attribute value is non-https
+ // TODO: Investigate this further and check for smarter handling
+ try {
+ newNode.setAttribute(attributeName, attributes[attributeName]);
+ } catch(e) {}
+ }
+
+ // IE8 sometimes loses the width/height attributes when those are set before the "src"
+ // so we make sure to set them again
+ if (attributes.src) {
+ if (typeof(attributes.width) !== "undefined") {
+ newNode.setAttribute("width", attributes.width);
+ }
+ if (typeof(attributes.height) !== "undefined") {
+ newNode.setAttribute("height", attributes.height);
+ }
+ }
+ }
+
+ function _handleText(oldNode) {
+ var nextSibling = oldNode.nextSibling;
+ if (nextSibling && nextSibling.nodeType === wysihtml5.TEXT_NODE) {
+ // Concatenate text nodes
+ nextSibling.data = oldNode.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "") + nextSibling.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "");
+ } else {
+ // \uFEFF = wysihtml5.INVISIBLE_SPACE (used as a hack in certain rich text editing situations)
+ var data = oldNode.data.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "");
+ return oldNode.ownerDocument.createTextNode(data);
+ }
+ }
+
+ function _handleComment(oldNode) {
+ if (currentRules.comments) {
+ return oldNode.ownerDocument.createComment(oldNode.nodeValue);
+ }
+ }
+
+ // ------------ attribute checks ------------ \\
+ var attributeCheckMethods = {
+ url: (function() {
+ var REG_EXP = /^https?:\/\//i;
+ return function(attributeValue) {
+ if (!attributeValue || !attributeValue.match(REG_EXP)) {
+ return null;
+ }
+ return attributeValue.replace(REG_EXP, function(match) {
+ return match.toLowerCase();
+ });
+ };
+ })(),
+
+ src: (function() {
+ var REG_EXP = /^(\/|https?:\/\/)/i;
+ return function(attributeValue) {
+ if (!attributeValue || !attributeValue.match(REG_EXP)) {
+ return null;
+ }
+ return attributeValue.replace(REG_EXP, function(match) {
+ return match.toLowerCase();
+ });
+ };
+ })(),
+
+ href: (function() {
+ var REG_EXP = /^(#|\/|https?:\/\/|mailto:)/i;
+ return function(attributeValue) {
+ if (!attributeValue || !attributeValue.match(REG_EXP)) {
+ return null;
+ }
+ return attributeValue.replace(REG_EXP, function(match) {
+ return match.toLowerCase();
+ });
+ };
+ })(),
+
+ alt: (function() {
+ var REG_EXP = /[^ a-z0-9_\-]/gi;
+ return function(attributeValue) {
+ if (!attributeValue) {
+ return "";
+ }
+ return attributeValue.replace(REG_EXP, "");
+ };
+ })(),
+
+ numbers: (function() {
+ var REG_EXP = /\D/g;
+ return function(attributeValue) {
+ attributeValue = (attributeValue || "").replace(REG_EXP, "");
+ return attributeValue || null;
+ };
+ })(),
+
+ any: (function() {
+ return function(attributeValue) {
+ return attributeValue;
+ };
+ })()
+ };
+
+ // ------------ style converter (converts an html attribute to a style) ------------ \\
+ var addStyleMethods = {
+ align_text: (function() {
+ var mapping = {
+ left: "text-align: left;",
+ right: "text-align: right;",
+ center: "text-align: center;"
+ };
+ return function(attributeValue) {
+ return mapping[String(attributeValue).toLowerCase()];
+ };
+ })(),
+ };
+
+ // ------------ class converter (converts an html attribute to a class name) ------------ \\
+ var addClassMethods = {
+ align_img: (function() {
+ var mapping = {
+ left: "wysiwyg-float-left",
+ right: "wysiwyg-float-right"
+ };
+ return function(attributeValue) {
+ return mapping[String(attributeValue).toLowerCase()];
+ };
+ })(),
+
+ align_text: (function() {
+ var mapping = {
+ left: "wysiwyg-text-align-left",
+ right: "wysiwyg-text-align-right",
+ center: "wysiwyg-text-align-center",
+ justify: "wysiwyg-text-align-justify"
+ };
+ return function(attributeValue) {
+ return mapping[String(attributeValue).toLowerCase()];
+ };
+ })(),
+
+ clear_br: (function() {
+ var mapping = {
+ left: "wysiwyg-clear-left",
+ right: "wysiwyg-clear-right",
+ both: "wysiwyg-clear-both",
+ all: "wysiwyg-clear-both"
+ };
+ return function(attributeValue) {
+ return mapping[String(attributeValue).toLowerCase()];
+ };
+ })(),
+
+ size_font: (function() {
+ var mapping = {
+ "1": "wysiwyg-font-size-xx-small",
+ "2": "wysiwyg-font-size-small",
+ "3": "wysiwyg-font-size-medium",
+ "4": "wysiwyg-font-size-large",
+ "5": "wysiwyg-font-size-x-large",
+ "6": "wysiwyg-font-size-xx-large",
+ "7": "wysiwyg-font-size-xx-large",
+ "-": "wysiwyg-font-size-smaller",
+ "+": "wysiwyg-font-size-larger"
+ };
+ return function(attributeValue) {
+ return mapping[String(attributeValue).charAt(0)];
+ };
+ })()
+ };
+
+ // checks if element is possibly visible
+ var typeCeckMethods = {
+ has_visible_contet: (function() {
+ var txt,
+ isVisible = false,
+ visibleElements = ['img', 'video', 'picture', 'br', 'script', 'noscript',
+ 'style', 'table', 'iframe', 'object', 'embed', 'audio',
+ 'svg', 'input', 'button', 'select','textarea', 'canvas'];
+
+ return function(el) {
+
+ // has visible innertext. so is visible
+ txt = (el.innerText || el.textContent).replace(/\s/g, '');
+ if (txt && txt.length > 0) {
+ return true;
+ }
+
+ // matches list of visible dimensioned elements
+ for (var i = visibleElements.length; i--;) {
+ if (el.querySelector(visibleElements[i])) {
+ return true;
+ }
+ }
+
+ // try to measure dimesions in last resort. (can find only of elements in dom)
+ if (el.offsetWidth && el.offsetWidth > 0 && el.offsetHeight && el.offsetHeight > 0) {
+ return true;
+ }
+
+ return false;
+ };
+ })()
+ };
+
+ var elementHandlingMethods = {
+ unwrap: function (element) {
+ wysihtml5.dom.unwrap(element);
+ },
+
+ remove: function (element) {
+ element.parentNode.removeChild(element);
+ }
+ };
+
+ return parse(elementOrHtml_current, config_current);
+};
--- /dev/null
+// does a selector query on element or array of elements
+
+wysihtml5.dom.query = function(elements, query) {
+ var ret = [],
+ q;
+
+ if (elements.nodeType) {
+ elements = [elements];
+ }
+
+ for (var e = 0, len = elements.length; e < len; e++) {
+ q = elements[e].querySelectorAll(query);
+ if (q) {
+ for(var i = q.length; i--; ret.unshift(q[i]));
+ }
+ }
+ return ret;
+};
--- /dev/null
+/**
+ * Checks for empty text node childs and removes them
+ *
+ * @param {Element} node The element in which to cleanup
+ * @example
+ * wysihtml5.dom.removeEmptyTextNodes(element);
+ */
+wysihtml5.dom.removeEmptyTextNodes = function(node) {
+ var childNode,
+ childNodes = wysihtml5.lang.array(node.childNodes).get(),
+ childNodesLength = childNodes.length,
+ i = 0;
+ for (; i<childNodesLength; i++) {
+ childNode = childNodes[i];
+ if (childNode.nodeType === wysihtml5.TEXT_NODE && childNode.data === "") {
+ childNode.parentNode.removeChild(childNode);
+ }
+ }
+};
--- /dev/null
+/**
+ * Renames an element (eg. a <div> to a <p>) and keeps its childs
+ *
+ * @param {Element} element The list element which should be renamed
+ * @param {Element} newNodeName The desired tag name
+ *
+ * @example
+ * <!-- Assume the following dom: -->
+ * <ul id="list">
+ * <li>eminem</li>
+ * <li>dr. dre</li>
+ * <li>50 Cent</li>
+ * </ul>
+ *
+ * <script>
+ * wysihtml5.dom.renameElement(document.getElementById("list"), "ol");
+ * </script>
+ *
+ * <!-- Will result in: -->
+ * <ol>
+ * <li>eminem</li>
+ * <li>dr. dre</li>
+ * <li>50 Cent</li>
+ * </ol>
+ */
+wysihtml5.dom.renameElement = function(element, newNodeName) {
+ var newElement = element.ownerDocument.createElement(newNodeName),
+ firstChild;
+ while (firstChild = element.firstChild) {
+ newElement.appendChild(firstChild);
+ }
+ wysihtml5.dom.copyAttributes(["align", "className"]).from(element).to(newElement);
+ element.parentNode.replaceChild(newElement, element);
+ return newElement;
+};
--- /dev/null
+/**
+ * Takes an element, removes it and replaces it with it's childs
+ *
+ * @param {Object} node The node which to replace with it's child nodes
+ * @example
+ * <div id="foo">
+ * <span>hello</span>
+ * </div>
+ * <script>
+ * // Remove #foo and replace with it's children
+ * wysihtml5.dom.replaceWithChildNodes(document.getElementById("foo"));
+ * </script>
+ */
+wysihtml5.dom.replaceWithChildNodes = function(node) {
+ if (!node.parentNode) {
+ return;
+ }
+
+ if (!node.firstChild) {
+ node.parentNode.removeChild(node);
+ return;
+ }
+
+ var fragment = node.ownerDocument.createDocumentFragment();
+ while (node.firstChild) {
+ fragment.appendChild(node.firstChild);
+ }
+ node.parentNode.replaceChild(fragment, node);
+ node = fragment = null;
+};
--- /dev/null
+/**
+ * Unwraps an unordered/ordered list
+ *
+ * @param {Element} element The list element which should be unwrapped
+ *
+ * @example
+ * <!-- Assume the following dom: -->
+ * <ul id="list">
+ * <li>eminem</li>
+ * <li>dr. dre</li>
+ * <li>50 Cent</li>
+ * </ul>
+ *
+ * <script>
+ * wysihtml5.dom.resolveList(document.getElementById("list"));
+ * </script>
+ *
+ * <!-- Will result in: -->
+ * eminem<br>
+ * dr. dre<br>
+ * 50 Cent<br>
+ */
+(function(dom) {
+ function _isBlockElement(node) {
+ return dom.getStyle("display").from(node) === "block";
+ }
+
+ function _isLineBreak(node) {
+ return node.nodeName === "BR";
+ }
+
+ function _appendLineBreak(element) {
+ var lineBreak = element.ownerDocument.createElement("br");
+ element.appendChild(lineBreak);
+ }
+
+ function resolveList(list, useLineBreaks) {
+ if (!list.nodeName.match(/^(MENU|UL|OL)$/)) {
+ return;
+ }
+
+ var doc = list.ownerDocument,
+ fragment = doc.createDocumentFragment(),
+ previousSibling = wysihtml5.dom.domNode(list).prev({ignoreBlankTexts: true}),
+ firstChild,
+ lastChild,
+ isLastChild,
+ shouldAppendLineBreak,
+ paragraph,
+ listItem;
+
+ if (useLineBreaks) {
+ // Insert line break if list is after a non-block element
+ if (previousSibling && !_isBlockElement(previousSibling) && !_isLineBreak(previousSibling)) {
+ _appendLineBreak(fragment);
+ }
+
+ while (listItem = (list.firstElementChild || list.firstChild)) {
+ lastChild = listItem.lastChild;
+ while (firstChild = listItem.firstChild) {
+ isLastChild = firstChild === lastChild;
+ // This needs to be done before appending it to the fragment, as it otherwise will lose style information
+ shouldAppendLineBreak = isLastChild && !_isBlockElement(firstChild) && !_isLineBreak(firstChild);
+ fragment.appendChild(firstChild);
+ if (shouldAppendLineBreak) {
+ _appendLineBreak(fragment);
+ }
+ }
+
+ listItem.parentNode.removeChild(listItem);
+ }
+ } else {
+ while (listItem = (list.firstElementChild || list.firstChild)) {
+ if (listItem.querySelector && listItem.querySelector("div, p, ul, ol, menu, blockquote, h1, h2, h3, h4, h5, h6")) {
+ while (firstChild = listItem.firstChild) {
+ fragment.appendChild(firstChild);
+ }
+ } else {
+ paragraph = doc.createElement("p");
+ while (firstChild = listItem.firstChild) {
+ paragraph.appendChild(firstChild);
+ }
+ fragment.appendChild(paragraph);
+ }
+ listItem.parentNode.removeChild(listItem);
+ }
+ }
+
+ list.parentNode.replaceChild(fragment, list);
+ }
+
+ dom.resolveList = resolveList;
+})(wysihtml5.dom);
--- /dev/null
+/**
+ * Sandbox for executing javascript, parsing css styles and doing dom operations in a secure way
+ *
+ * Browser Compatibility:
+ * - Secure in MSIE 6+, but only when the user hasn't made changes to his security level "restricted"
+ * - Partially secure in other browsers (Firefox, Opera, Safari, Chrome, ...)
+ *
+ * Please note that this class can't benefit from the HTML5 sandbox attribute for the following reasons:
+ * - sandboxing doesn't work correctly with inlined content (src="javascript:'<html>...</html>'")
+ * - sandboxing of physical documents causes that the dom isn't accessible anymore from the outside (iframe.contentWindow, ...)
+ * - setting the "allow-same-origin" flag would fix that, but then still javascript and dom events refuse to fire
+ * - therefore the "allow-scripts" flag is needed, which then would deactivate any security, as the js executed inside the iframe
+ * can do anything as if the sandbox attribute wasn't set
+ *
+ * @param {Function} [readyCallback] Method that gets invoked when the sandbox is ready
+ * @param {Object} [config] Optional parameters
+ *
+ * @example
+ * new wysihtml5.dom.Sandbox(function(sandbox) {
+ * sandbox.getWindow().document.body.innerHTML = '<img src=foo.gif onerror="alert(document.cookie)">';
+ * });
+ */
+(function(wysihtml5) {
+ var /**
+ * Default configuration
+ */
+ doc = document,
+ /**
+ * Properties to unset/protect on the window object
+ */
+ windowProperties = [
+ "parent", "top", "opener", "frameElement", "frames",
+ "localStorage", "globalStorage", "sessionStorage", "indexedDB"
+ ],
+ /**
+ * Properties on the window object which are set to an empty function
+ */
+ windowProperties2 = [
+ "open", "close", "openDialog", "showModalDialog",
+ "alert", "confirm", "prompt",
+ "openDatabase", "postMessage",
+ "XMLHttpRequest", "XDomainRequest"
+ ],
+ /**
+ * Properties to unset/protect on the document object
+ */
+ documentProperties = [
+ "referrer",
+ "write", "open", "close"
+ ];
+
+ wysihtml5.dom.Sandbox = Base.extend(
+ /** @scope wysihtml5.dom.Sandbox.prototype */ {
+
+ constructor: function(readyCallback, config) {
+ this.callback = readyCallback || wysihtml5.EMPTY_FUNCTION;
+ this.config = wysihtml5.lang.object({}).merge(config).get();
+ this.editableArea = this._createIframe();
+ },
+
+ insertInto: function(element) {
+ if (typeof(element) === "string") {
+ element = doc.getElementById(element);
+ }
+
+ element.appendChild(this.editableArea);
+ },
+
+ getIframe: function() {
+ return this.editableArea;
+ },
+
+ getWindow: function() {
+ this._readyError();
+ },
+
+ getDocument: function() {
+ this._readyError();
+ },
+
+ destroy: function() {
+ var iframe = this.getIframe();
+ iframe.parentNode.removeChild(iframe);
+ },
+
+ _readyError: function() {
+ throw new Error("wysihtml5.Sandbox: Sandbox iframe isn't loaded yet");
+ },
+
+ /**
+ * Creates the sandbox iframe
+ *
+ * Some important notes:
+ * - We can't use HTML5 sandbox for now:
+ * setting it causes that the iframe's dom can't be accessed from the outside
+ * Therefore we need to set the "allow-same-origin" flag which enables accessing the iframe's dom
+ * But then there's another problem, DOM events (focus, blur, change, keypress, ...) aren't fired.
+ * In order to make this happen we need to set the "allow-scripts" flag.
+ * A combination of allow-scripts and allow-same-origin is almost the same as setting no sandbox attribute at all.
+ * - Chrome & Safari, doesn't seem to support sandboxing correctly when the iframe's html is inlined (no physical document)
+ * - IE needs to have the security="restricted" attribute set before the iframe is
+ * inserted into the dom tree
+ * - Believe it or not but in IE "security" in document.createElement("iframe") is false, even
+ * though it supports it
+ * - When an iframe has security="restricted", in IE eval() & execScript() don't work anymore
+ * - IE doesn't fire the onload event when the content is inlined in the src attribute, therefore we rely
+ * on the onreadystatechange event
+ */
+ _createIframe: function() {
+ var that = this,
+ iframe = doc.createElement("iframe");
+ iframe.className = "wysihtml5-sandbox";
+ wysihtml5.dom.setAttributes({
+ "security": "restricted",
+ "allowtransparency": "true",
+ "frameborder": 0,
+ "width": 0,
+ "height": 0,
+ "marginwidth": 0,
+ "marginheight": 0
+ }).on(iframe);
+
+ // Setting the src like this prevents ssl warnings in IE6
+ if (wysihtml5.browser.throwsMixedContentWarningWhenIframeSrcIsEmpty()) {
+ iframe.src = "javascript:'<html></html>'";
+ }
+
+ iframe.onload = function() {
+ iframe.onreadystatechange = iframe.onload = null;
+ that._onLoadIframe(iframe);
+ };
+
+ iframe.onreadystatechange = function() {
+ if (/loaded|complete/.test(iframe.readyState)) {
+ iframe.onreadystatechange = iframe.onload = null;
+ that._onLoadIframe(iframe);
+ }
+ };
+
+ return iframe;
+ },
+
+ /**
+ * Callback for when the iframe has finished loading
+ */
+ _onLoadIframe: function(iframe) {
+ // don't resume when the iframe got unloaded (eg. by removing it from the dom)
+ if (!wysihtml5.dom.contains(doc.documentElement, iframe)) {
+ return;
+ }
+
+ var that = this,
+ iframeWindow = iframe.contentWindow,
+ iframeDocument = iframe.contentWindow.document,
+ charset = doc.characterSet || doc.charset || "utf-8",
+ sandboxHtml = this._getHtml({
+ charset: charset,
+ stylesheets: this.config.stylesheets
+ });
+
+ // Create the basic dom tree including proper DOCTYPE and charset
+ iframeDocument.open("text/html", "replace");
+ iframeDocument.write(sandboxHtml);
+ iframeDocument.close();
+
+ this.getWindow = function() { return iframe.contentWindow; };
+ this.getDocument = function() { return iframe.contentWindow.document; };
+
+ // Catch js errors and pass them to the parent's onerror event
+ // addEventListener("error") doesn't work properly in some browsers
+ // TODO: apparently this doesn't work in IE9!
+ iframeWindow.onerror = function(errorMessage, fileName, lineNumber) {
+ throw new Error("wysihtml5.Sandbox: " + errorMessage, fileName, lineNumber);
+ };
+
+ if (!wysihtml5.browser.supportsSandboxedIframes()) {
+ // Unset a bunch of sensitive variables
+ // Please note: This isn't hack safe!
+ // It more or less just takes care of basic attacks and prevents accidental theft of sensitive information
+ // IE is secure though, which is the most important thing, since IE is the only browser, who
+ // takes over scripts & styles into contentEditable elements when copied from external websites
+ // or applications (Microsoft Word, ...)
+ var i, length;
+ for (i=0, length=windowProperties.length; i<length; i++) {
+ this._unset(iframeWindow, windowProperties[i]);
+ }
+ for (i=0, length=windowProperties2.length; i<length; i++) {
+ this._unset(iframeWindow, windowProperties2[i], wysihtml5.EMPTY_FUNCTION);
+ }
+ for (i=0, length=documentProperties.length; i<length; i++) {
+ this._unset(iframeDocument, documentProperties[i]);
+ }
+ // This doesn't work in Safari 5
+ // See http://stackoverflow.com/questions/992461/is-it-possible-to-override-document-cookie-in-webkit
+ this._unset(iframeDocument, "cookie", "", true);
+ }
+
+ this.loaded = true;
+
+ // Trigger the callback
+ setTimeout(function() { that.callback(that); }, 0);
+ },
+
+ _getHtml: function(templateVars) {
+ var stylesheets = templateVars.stylesheets,
+ html = "",
+ i = 0,
+ length;
+ stylesheets = typeof(stylesheets) === "string" ? [stylesheets] : stylesheets;
+ if (stylesheets) {
+ length = stylesheets.length;
+ for (; i<length; i++) {
+ html += '<link rel="stylesheet" href="' + stylesheets[i] + '">';
+ }
+ }
+ templateVars.stylesheets = html;
+
+ return wysihtml5.lang.string(
+ '<!DOCTYPE html><html><head>'
+ + '<meta charset="#{charset}">#{stylesheets}</head>'
+ + '<body></body></html>'
+ ).interpolate(templateVars);
+ },
+
+ /**
+ * Method to unset/override existing variables
+ * @example
+ * // Make cookie unreadable and unwritable
+ * this._unset(document, "cookie", "", true);
+ */
+ _unset: function(object, property, value, setter) {
+ try { object[property] = value; } catch(e) {}
+
+ try { object.__defineGetter__(property, function() { return value; }); } catch(e) {}
+ if (setter) {
+ try { object.__defineSetter__(property, function() {}); } catch(e) {}
+ }
+
+ if (!wysihtml5.browser.crashesWhenDefineProperty(property)) {
+ try {
+ var config = {
+ get: function() { return value; }
+ };
+ if (setter) {
+ config.set = function() {};
+ }
+ Object.defineProperty(object, property, config);
+ } catch(e) {}
+ }
+ }
+ });
+})(wysihtml5);
--- /dev/null
+(function() {
+ var mapping = {
+ "className": "class"
+ };
+ wysihtml5.dom.setAttributes = function(attributes) {
+ return {
+ on: function(element) {
+ for (var i in attributes) {
+ element.setAttribute(mapping[i] || i, attributes[i]);
+ }
+ }
+ };
+ };
+})();
--- /dev/null
+wysihtml5.dom.setStyles = function(styles) {
+ return {
+ on: function(element) {
+ var style = element.style;
+ if (typeof(styles) === "string") {
+ style.cssText += ";" + styles;
+ return;
+ }
+ for (var i in styles) {
+ if (i === "float") {
+ style.cssFloat = styles[i];
+ style.styleFloat = styles[i];
+ } else {
+ style[i] = styles[i];
+ }
+ }
+ }
+ };
+};
--- /dev/null
+/**
+ * Simulate HTML5 placeholder attribute
+ *
+ * Needed since
+ * - div[contentEditable] elements don't support it
+ * - older browsers (such as IE8 and Firefox 3.6) don't support it at all
+ *
+ * @param {Object} parent Instance of main wysihtml5.Editor class
+ * @param {Element} view Instance of wysihtml5.views.* class
+ * @param {String} placeholderText
+ *
+ * @example
+ * wysihtml.dom.simulatePlaceholder(this, composer, "Foobar");
+ */
+(function(dom) {
+ dom.simulatePlaceholder = function(editor, view, placeholderText) {
+ var CLASS_NAME = "placeholder",
+ unset = function() {
+ var composerIsVisible = view.element.offsetWidth > 0 && view.element.offsetHeight > 0;
+ if (view.hasPlaceholderSet()) {
+ view.clear();
+ view.element.focus();
+ if (composerIsVisible ) {
+ setTimeout(function() {
+ var sel = view.selection.getSelection();
+ if (!sel.focusNode || !sel.anchorNode) {
+ view.selection.selectNode(view.element.firstChild || view.element);
+ }
+ }, 0);
+ }
+ }
+ view.placeholderSet = false;
+ dom.removeClass(view.element, CLASS_NAME);
+ },
+ set = function() {
+ if (view.isEmpty()) {
+ view.placeholderSet = true;
+ view.setValue(placeholderText);
+ dom.addClass(view.element, CLASS_NAME);
+ }
+ };
+
+ editor
+ .on("set_placeholder", set)
+ .on("unset_placeholder", unset)
+ .on("focus:composer", unset)
+ .on("paste:composer", unset)
+ .on("blur:composer", set);
+
+ set();
+ };
+})(wysihtml5.dom);
--- /dev/null
+(function(wysihtml5) {
+
+ var api = wysihtml5.dom;
+
+ var MapCell = function(cell) {
+ this.el = cell;
+ this.isColspan= false;
+ this.isRowspan= false;
+ this.firstCol= true;
+ this.lastCol= true;
+ this.firstRow= true;
+ this.lastRow= true;
+ this.isReal= true;
+ this.spanCollection= [];
+ this.modified = false;
+ };
+
+ var TableModifyerByCell = function (cell, table) {
+ if (cell) {
+ this.cell = cell;
+ this.table = api.getParentElement(cell, { nodeName: ["TABLE"] });
+ } else if (table) {
+ this.table = table;
+ this.cell = this.table.querySelectorAll('th, td')[0];
+ }
+ };
+
+ function queryInList(list, query) {
+ var ret = [],
+ q;
+ for (var e = 0, len = list.length; e < len; e++) {
+ q = list[e].querySelectorAll(query);
+ if (q) {
+ for(var i = q.length; i--; ret.unshift(q[i]));
+ }
+ }
+ return ret;
+ }
+
+ function removeElement(el) {
+ el.parentNode.removeChild(el);
+ }
+
+ function insertAfter(referenceNode, newNode) {
+ referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
+ }
+
+ function nextNode(node, tag) {
+ var element = node.nextSibling;
+ while (element.nodeType !=1) {
+ element = element.nextSibling;
+ if (!tag || tag == element.tagName.toLowerCase()) {
+ return element;
+ }
+ }
+ return null;
+ }
+
+ TableModifyerByCell.prototype = {
+
+ addSpannedCellToMap: function(cell, map, r, c, cspan, rspan) {
+ var spanCollect = [],
+ rmax = r + ((rspan) ? parseInt(rspan, 10) - 1 : 0),
+ cmax = c + ((cspan) ? parseInt(cspan, 10) - 1 : 0);
+
+ for (var rr = r; rr <= rmax; rr++) {
+ if (typeof map[rr] == "undefined") { map[rr] = []; }
+ for (var cc = c; cc <= cmax; cc++) {
+ map[rr][cc] = new MapCell(cell);
+ map[rr][cc].isColspan = (cspan && parseInt(cspan, 10) > 1);
+ map[rr][cc].isRowspan = (rspan && parseInt(rspan, 10) > 1);
+ map[rr][cc].firstCol = cc == c;
+ map[rr][cc].lastCol = cc == cmax;
+ map[rr][cc].firstRow = rr == r;
+ map[rr][cc].lastRow = rr == rmax;
+ map[rr][cc].isReal = cc == c && rr == r;
+ map[rr][cc].spanCollection = spanCollect;
+
+ spanCollect.push(map[rr][cc]);
+ }
+ }
+ },
+
+ setCellAsModified: function(cell) {
+ cell.modified = true;
+ if (cell.spanCollection.length > 0) {
+ for (var s = 0, smax = cell.spanCollection.length; s < smax; s++) {
+ cell.spanCollection[s].modified = true;
+ }
+ }
+ },
+
+ setTableMap: function() {
+ var map = [];
+ var tableRows = this.getTableRows(),
+ ridx, row, cells, cidx, cell,
+ c,
+ cspan, rspan;
+
+ for (ridx = 0; ridx < tableRows.length; ridx++) {
+ row = tableRows[ridx];
+ cells = this.getRowCells(row);
+ c = 0;
+ if (typeof map[ridx] == "undefined") { map[ridx] = []; }
+ for (cidx = 0; cidx < cells.length; cidx++) {
+ cell = cells[cidx];
+
+ // If cell allready set means it is set by col or rowspan,
+ // so increase cols index until free col is found
+ while (typeof map[ridx][c] != "undefined") { c++; }
+
+ cspan = api.getAttribute(cell, 'colspan');
+ rspan = api.getAttribute(cell, 'rowspan');
+
+ if (cspan || rspan) {
+ this.addSpannedCellToMap(cell, map, ridx, c, cspan, rspan);
+ c = c + ((cspan) ? parseInt(cspan, 10) : 1);
+ } else {
+ map[ridx][c] = new MapCell(cell);
+ c++;
+ }
+ }
+ }
+ this.map = map;
+ return map;
+ },
+
+ getRowCells: function(row) {
+ var inlineTables = this.table.querySelectorAll('table'),
+ inlineCells = (inlineTables) ? queryInList(inlineTables, 'th, td') : [],
+ allCells = row.querySelectorAll('th, td'),
+ tableCells = (inlineCells.length > 0) ? wysihtml5.lang.array(allCells).without(inlineCells) : allCells;
+
+ return tableCells;
+ },
+
+ getTableRows: function() {
+ var inlineTables = this.table.querySelectorAll('table'),
+ inlineRows = (inlineTables) ? queryInList(inlineTables, 'tr') : [],
+ allRows = this.table.querySelectorAll('tr'),
+ tableRows = (inlineRows.length > 0) ? wysihtml5.lang.array(allRows).without(inlineRows) : allRows;
+
+ return tableRows;
+ },
+
+ getMapIndex: function(cell) {
+ var r_length = this.map.length,
+ c_length = (this.map && this.map[0]) ? this.map[0].length : 0;
+
+ for (var r_idx = 0;r_idx < r_length; r_idx++) {
+ for (var c_idx = 0;c_idx < c_length; c_idx++) {
+ if (this.map[r_idx][c_idx].el === cell) {
+ return {'row': r_idx, 'col': c_idx};
+ }
+ }
+ }
+ return false;
+ },
+
+ getElementAtIndex: function(idx) {
+ this.setTableMap();
+ if (this.map[idx.row] && this.map[idx.row][idx.col] && this.map[idx.row][idx.col].el) {
+ return this.map[idx.row][idx.col].el;
+ }
+ return null;
+ },
+
+ getMapElsTo: function(to_cell) {
+ var els = [];
+ this.setTableMap();
+ this.idx_start = this.getMapIndex(this.cell);
+ this.idx_end = this.getMapIndex(to_cell);
+
+ // switch indexes if start is bigger than end
+ if (this.idx_start.row > this.idx_end.row || (this.idx_start.row == this.idx_end.row && this.idx_start.col > this.idx_end.col)) {
+ var temp_idx = this.idx_start;
+ this.idx_start = this.idx_end;
+ this.idx_end = temp_idx;
+ }
+ if (this.idx_start.col > this.idx_end.col) {
+ var temp_cidx = this.idx_start.col;
+ this.idx_start.col = this.idx_end.col;
+ this.idx_end.col = temp_cidx;
+ }
+
+ if (this.idx_start != null && this.idx_end != null) {
+ for (var row = this.idx_start.row, maxr = this.idx_end.row; row <= maxr; row++) {
+ for (var col = this.idx_start.col, maxc = this.idx_end.col; col <= maxc; col++) {
+ els.push(this.map[row][col].el);
+ }
+ }
+ }
+ return els;
+ },
+
+ orderSelectionEnds: function(secondcell) {
+ this.setTableMap();
+ this.idx_start = this.getMapIndex(this.cell);
+ this.idx_end = this.getMapIndex(secondcell);
+
+ // switch indexes if start is bigger than end
+ if (this.idx_start.row > this.idx_end.row || (this.idx_start.row == this.idx_end.row && this.idx_start.col > this.idx_end.col)) {
+ var temp_idx = this.idx_start;
+ this.idx_start = this.idx_end;
+ this.idx_end = temp_idx;
+ }
+ if (this.idx_start.col > this.idx_end.col) {
+ var temp_cidx = this.idx_start.col;
+ this.idx_start.col = this.idx_end.col;
+ this.idx_end.col = temp_cidx;
+ }
+
+ return {
+ "start": this.map[this.idx_start.row][this.idx_start.col].el,
+ "end": this.map[this.idx_end.row][this.idx_end.col].el
+ };
+ },
+
+ createCells: function(tag, nr, attrs) {
+ var doc = this.table.ownerDocument,
+ frag = doc.createDocumentFragment(),
+ cell;
+ for (var i = 0; i < nr; i++) {
+ cell = doc.createElement(tag);
+
+ if (attrs) {
+ for (var attr in attrs) {
+ if (attrs.hasOwnProperty(attr)) {
+ cell.setAttribute(attr, attrs[attr]);
+ }
+ }
+ }
+
+ // add non breaking space
+ cell.appendChild(document.createTextNode("\u00a0"));
+
+ frag.appendChild(cell);
+ }
+ return frag;
+ },
+
+ // Returns next real cell (not part of spanned cell unless first) on row if selected index is not real. I no real cells -1 will be returned
+ correctColIndexForUnreals: function(col, row) {
+ var r = this.map[row],
+ corrIdx = -1;
+ for (var i = 0, max = col; i < col; i++) {
+ if (r[i].isReal){
+ corrIdx++;
+ }
+ }
+ return corrIdx;
+ },
+
+ getLastNewCellOnRow: function(row, rowLimit) {
+ var cells = this.getRowCells(row),
+ cell, idx;
+
+ for (var cidx = 0, cmax = cells.length; cidx < cmax; cidx++) {
+ cell = cells[cidx];
+ idx = this.getMapIndex(cell);
+ if (idx === false || (typeof rowLimit != "undefined" && idx.row != rowLimit)) {
+ return cell;
+ }
+ }
+ return null;
+ },
+
+ removeEmptyTable: function() {
+ var cells = this.table.querySelectorAll('td, th');
+ if (!cells || cells.length == 0) {
+ removeElement(this.table);
+ return true;
+ } else {
+ return false;
+ }
+ },
+
+ // Splits merged cell on row to unique cells
+ splitRowToCells: function(cell) {
+ if (cell.isColspan) {
+ var colspan = parseInt(api.getAttribute(cell.el, 'colspan') || 1, 10),
+ cType = cell.el.tagName.toLowerCase();
+ if (colspan > 1) {
+ var newCells = this.createCells(cType, colspan -1);
+ insertAfter(cell.el, newCells);
+ }
+ cell.el.removeAttribute('colspan');
+ }
+ },
+
+ getRealRowEl: function(force, idx) {
+ var r = null,
+ c = null;
+
+ idx = idx || this.idx;
+
+ for (var cidx = 0, cmax = this.map[idx.row].length; cidx < cmax; cidx++) {
+ c = this.map[idx.row][cidx];
+ if (c.isReal) {
+ r = api.getParentElement(c.el, { nodeName: ["TR"] });
+ if (r) {
+ return r;
+ }
+ }
+ }
+
+ if (r === null && force) {
+ r = api.getParentElement(this.map[idx.row][idx.col].el, { nodeName: ["TR"] }) || null;
+ }
+
+ return r;
+ },
+
+ injectRowAt: function(row, col, colspan, cType, c) {
+ var r = this.getRealRowEl(false, {'row': row, 'col': col}),
+ new_cells = this.createCells(cType, colspan);
+
+ if (r) {
+ var n_cidx = this.correctColIndexForUnreals(col, row);
+ if (n_cidx >= 0) {
+ insertAfter(this.getRowCells(r)[n_cidx], new_cells);
+ } else {
+ r.insertBefore(new_cells, r.firstChild);
+ }
+ } else {
+ var rr = this.table.ownerDocument.createElement('tr');
+ rr.appendChild(new_cells);
+ insertAfter(api.getParentElement(c.el, { nodeName: ["TR"] }), rr);
+ }
+ },
+
+ canMerge: function(to) {
+ this.to = to;
+ this.setTableMap();
+ this.idx_start = this.getMapIndex(this.cell);
+ this.idx_end = this.getMapIndex(this.to);
+
+ // switch indexes if start is bigger than end
+ if (this.idx_start.row > this.idx_end.row || (this.idx_start.row == this.idx_end.row && this.idx_start.col > this.idx_end.col)) {
+ var temp_idx = this.idx_start;
+ this.idx_start = this.idx_end;
+ this.idx_end = temp_idx;
+ }
+ if (this.idx_start.col > this.idx_end.col) {
+ var temp_cidx = this.idx_start.col;
+ this.idx_start.col = this.idx_end.col;
+ this.idx_end.col = temp_cidx;
+ }
+
+ for (var row = this.idx_start.row, maxr = this.idx_end.row; row <= maxr; row++) {
+ for (var col = this.idx_start.col, maxc = this.idx_end.col; col <= maxc; col++) {
+ if (this.map[row][col].isColspan || this.map[row][col].isRowspan) {
+ return false;
+ }
+ }
+ }
+ return true;
+ },
+
+ decreaseCellSpan: function(cell, span) {
+ var nr = parseInt(api.getAttribute(cell.el, span), 10) - 1;
+ if (nr >= 1) {
+ cell.el.setAttribute(span, nr);
+ } else {
+ cell.el.removeAttribute(span);
+ if (span == 'colspan') {
+ cell.isColspan = false;
+ }
+ if (span == 'rowspan') {
+ cell.isRowspan = false;
+ }
+ cell.firstCol = true;
+ cell.lastCol = true;
+ cell.firstRow = true;
+ cell.lastRow = true;
+ cell.isReal = true;
+ }
+ },
+
+ removeSurplusLines: function() {
+ var row, cell, ridx, rmax, cidx, cmax, allRowspan;
+
+ this.setTableMap();
+ if (this.map) {
+ ridx = 0;
+ rmax = this.map.length;
+ for (;ridx < rmax; ridx++) {
+ row = this.map[ridx];
+ allRowspan = true;
+ cidx = 0;
+ cmax = row.length;
+ for (; cidx < cmax; cidx++) {
+ cell = row[cidx];
+ if (!(api.getAttribute(cell.el, "rowspan") && parseInt(api.getAttribute(cell.el, "rowspan"), 10) > 1 && cell.firstRow !== true)) {
+ allRowspan = false;
+ break;
+ }
+ }
+ if (allRowspan) {
+ cidx = 0;
+ for (; cidx < cmax; cidx++) {
+ this.decreaseCellSpan(row[cidx], 'rowspan');
+ }
+ }
+ }
+
+ // remove rows without cells
+ var tableRows = this.getTableRows();
+ ridx = 0;
+ rmax = tableRows.length;
+ for (;ridx < rmax; ridx++) {
+ row = tableRows[ridx];
+ if (row.childNodes.length == 0 && (/^\s*$/.test(row.textContent || row.innerText))) {
+ removeElement(row);
+ }
+ }
+ }
+ },
+
+ fillMissingCells: function() {
+ var r_max = 0,
+ c_max = 0,
+ prevcell = null;
+
+ this.setTableMap();
+ if (this.map) {
+
+ // find maximal dimensions of broken table
+ r_max = this.map.length;
+ for (var ridx = 0; ridx < r_max; ridx++) {
+ if (this.map[ridx].length > c_max) { c_max = this.map[ridx].length; }
+ }
+
+ for (var row = 0; row < r_max; row++) {
+ for (var col = 0; col < c_max; col++) {
+ if (this.map[row] && !this.map[row][col]) {
+ if (col > 0) {
+ this.map[row][col] = new MapCell(this.createCells('td', 1));
+ prevcell = this.map[row][col-1];
+ if (prevcell && prevcell.el && prevcell.el.parent) { // if parent does not exist element is removed from dom
+ insertAfter(this.map[row][col-1].el, this.map[row][col].el);
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+
+ rectify: function() {
+ if (!this.removeEmptyTable()) {
+ this.removeSurplusLines();
+ this.fillMissingCells();
+ return true;
+ } else {
+ return false;
+ }
+ },
+
+ unmerge: function() {
+ if (this.rectify()) {
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+
+ if (this.idx) {
+ var thisCell = this.map[this.idx.row][this.idx.col],
+ colspan = (api.getAttribute(thisCell.el, "colspan")) ? parseInt(api.getAttribute(thisCell.el, "colspan"), 10) : 1,
+ cType = thisCell.el.tagName.toLowerCase();
+
+ if (thisCell.isRowspan) {
+ var rowspan = parseInt(api.getAttribute(thisCell.el, "rowspan"), 10);
+ if (rowspan > 1) {
+ for (var nr = 1, maxr = rowspan - 1; nr <= maxr; nr++){
+ this.injectRowAt(this.idx.row + nr, this.idx.col, colspan, cType, thisCell);
+ }
+ }
+ thisCell.el.removeAttribute('rowspan');
+ }
+ this.splitRowToCells(thisCell);
+ }
+ }
+ },
+
+ // merges cells from start cell (defined in creating obj) to "to" cell
+ merge: function(to) {
+ if (this.rectify()) {
+ if (this.canMerge(to)) {
+ var rowspan = this.idx_end.row - this.idx_start.row + 1,
+ colspan = this.idx_end.col - this.idx_start.col + 1;
+
+ for (var row = this.idx_start.row, maxr = this.idx_end.row; row <= maxr; row++) {
+ for (var col = this.idx_start.col, maxc = this.idx_end.col; col <= maxc; col++) {
+
+ if (row == this.idx_start.row && col == this.idx_start.col) {
+ if (rowspan > 1) {
+ this.map[row][col].el.setAttribute('rowspan', rowspan);
+ }
+ if (colspan > 1) {
+ this.map[row][col].el.setAttribute('colspan', colspan);
+ }
+ } else {
+ // transfer content
+ if (!(/^\s*<br\/?>\s*$/.test(this.map[row][col].el.innerHTML.toLowerCase()))) {
+ this.map[this.idx_start.row][this.idx_start.col].el.innerHTML += ' ' + this.map[row][col].el.innerHTML;
+ }
+ removeElement(this.map[row][col].el);
+ }
+ }
+ }
+ this.rectify();
+ } else {
+ if (window.console) {
+ console.log('Do not know how to merge allready merged cells.');
+ }
+ }
+ }
+ },
+
+ // Decreases rowspan of a cell if it is done on first cell of rowspan row (real cell)
+ // Cell is moved to next row (if it is real)
+ collapseCellToNextRow: function(cell) {
+ var cellIdx = this.getMapIndex(cell.el),
+ newRowIdx = cellIdx.row + 1,
+ newIdx = {'row': newRowIdx, 'col': cellIdx.col};
+
+ if (newRowIdx < this.map.length) {
+
+ var row = this.getRealRowEl(false, newIdx);
+ if (row !== null) {
+ var n_cidx = this.correctColIndexForUnreals(newIdx.col, newIdx.row);
+ if (n_cidx >= 0) {
+ insertAfter(this.getRowCells(row)[n_cidx], cell.el);
+ } else {
+ var lastCell = this.getLastNewCellOnRow(row, newRowIdx);
+ if (lastCell !== null) {
+ insertAfter(lastCell, cell.el);
+ } else {
+ row.insertBefore(cell.el, row.firstChild);
+ }
+ }
+ if (parseInt(api.getAttribute(cell.el, 'rowspan'), 10) > 2) {
+ cell.el.setAttribute('rowspan', parseInt(api.getAttribute(cell.el, 'rowspan'), 10) - 1);
+ } else {
+ cell.el.removeAttribute('rowspan');
+ }
+ }
+ }
+ },
+
+ // Removes a cell when removing a row
+ // If is rowspan cell then decreases the rowspan
+ // and moves cell to next row if needed (is first cell of rowspan)
+ removeRowCell: function(cell) {
+ if (cell.isReal) {
+ if (cell.isRowspan) {
+ this.collapseCellToNextRow(cell);
+ } else {
+ removeElement(cell.el);
+ }
+ } else {
+ if (parseInt(api.getAttribute(cell.el, 'rowspan'), 10) > 2) {
+ cell.el.setAttribute('rowspan', parseInt(api.getAttribute(cell.el, 'rowspan'), 10) - 1);
+ } else {
+ cell.el.removeAttribute('rowspan');
+ }
+ }
+ },
+
+ getRowElementsByCell: function() {
+ var cells = [];
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+ if (this.idx !== false) {
+ var modRow = this.map[this.idx.row];
+ for (var cidx = 0, cmax = modRow.length; cidx < cmax; cidx++) {
+ if (modRow[cidx].isReal) {
+ cells.push(modRow[cidx].el);
+ }
+ }
+ }
+ return cells;
+ },
+
+ getColumnElementsByCell: function() {
+ var cells = [];
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+ if (this.idx !== false) {
+ for (var ridx = 0, rmax = this.map.length; ridx < rmax; ridx++) {
+ if (this.map[ridx][this.idx.col] && this.map[ridx][this.idx.col].isReal) {
+ cells.push(this.map[ridx][this.idx.col].el);
+ }
+ }
+ }
+ return cells;
+ },
+
+ // Removes the row of selected cell
+ removeRow: function() {
+ var oldRow = api.getParentElement(this.cell, { nodeName: ["TR"] });
+ if (oldRow) {
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+ if (this.idx !== false) {
+ var modRow = this.map[this.idx.row];
+ for (var cidx = 0, cmax = modRow.length; cidx < cmax; cidx++) {
+ if (!modRow[cidx].modified) {
+ this.setCellAsModified(modRow[cidx]);
+ this.removeRowCell(modRow[cidx]);
+ }
+ }
+ }
+ removeElement(oldRow);
+ }
+ },
+
+ removeColCell: function(cell) {
+ if (cell.isColspan) {
+ if (parseInt(api.getAttribute(cell.el, 'colspan'), 10) > 2) {
+ cell.el.setAttribute('colspan', parseInt(api.getAttribute(cell.el, 'colspan'), 10) - 1);
+ } else {
+ cell.el.removeAttribute('colspan');
+ }
+ } else if (cell.isReal) {
+ removeElement(cell.el);
+ }
+ },
+
+ removeColumn: function() {
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+ if (this.idx !== false) {
+ for (var ridx = 0, rmax = this.map.length; ridx < rmax; ridx++) {
+ if (!this.map[ridx][this.idx.col].modified) {
+ this.setCellAsModified(this.map[ridx][this.idx.col]);
+ this.removeColCell(this.map[ridx][this.idx.col]);
+ }
+ }
+ }
+ },
+
+ // removes row or column by selected cell element
+ remove: function(what) {
+ if (this.rectify()) {
+ switch (what) {
+ case 'row':
+ this.removeRow();
+ break;
+ case 'column':
+ this.removeColumn();
+ break;
+ }
+ this.rectify();
+ }
+ },
+
+ addRow: function(where) {
+ var doc = this.table.ownerDocument;
+
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+ if (where == "below" && api.getAttribute(this.cell, 'rowspan')) {
+ this.idx.row = this.idx.row + parseInt(api.getAttribute(this.cell, 'rowspan'), 10) - 1;
+ }
+
+ if (this.idx !== false) {
+ var modRow = this.map[this.idx.row],
+ newRow = doc.createElement('tr');
+
+ for (var ridx = 0, rmax = modRow.length; ridx < rmax; ridx++) {
+ if (!modRow[ridx].modified) {
+ this.setCellAsModified(modRow[ridx]);
+ this.addRowCell(modRow[ridx], newRow, where);
+ }
+ }
+
+ switch (where) {
+ case 'below':
+ insertAfter(this.getRealRowEl(true), newRow);
+ break;
+ case 'above':
+ var cr = api.getParentElement(this.map[this.idx.row][this.idx.col].el, { nodeName: ["TR"] });
+ if (cr) {
+ cr.parentNode.insertBefore(newRow, cr);
+ }
+ break;
+ }
+ }
+ },
+
+ addRowCell: function(cell, row, where) {
+ var colSpanAttr = (cell.isColspan) ? {"colspan" : api.getAttribute(cell.el, 'colspan')} : null;
+ if (cell.isReal) {
+ if (where != 'above' && cell.isRowspan) {
+ cell.el.setAttribute('rowspan', parseInt(api.getAttribute(cell.el,'rowspan'), 10) + 1);
+ } else {
+ row.appendChild(this.createCells('td', 1, colSpanAttr));
+ }
+ } else {
+ if (where != 'above' && cell.isRowspan && cell.lastRow) {
+ row.appendChild(this.createCells('td', 1, colSpanAttr));
+ } else if (c.isRowspan) {
+ cell.el.attr('rowspan', parseInt(api.getAttribute(cell.el, 'rowspan'), 10) + 1);
+ }
+ }
+ },
+
+ add: function(where) {
+ if (this.rectify()) {
+ if (where == 'below' || where == 'above') {
+ this.addRow(where);
+ }
+ if (where == 'before' || where == 'after') {
+ this.addColumn(where);
+ }
+ }
+ },
+
+ addColCell: function (cell, ridx, where) {
+ var doAdd,
+ cType = cell.el.tagName.toLowerCase();
+
+ // defines add cell vs expand cell conditions
+ // true means add
+ switch (where) {
+ case "before":
+ doAdd = (!cell.isColspan || cell.firstCol);
+ break;
+ case "after":
+ doAdd = (!cell.isColspan || cell.lastCol || (cell.isColspan && c.el == this.cell));
+ break;
+ }
+
+ if (doAdd){
+ // adds a cell before or after current cell element
+ switch (where) {
+ case "before":
+ cell.el.parentNode.insertBefore(this.createCells(cType, 1), cell.el);
+ break;
+ case "after":
+ insertAfter(cell.el, this.createCells(cType, 1));
+ break;
+ }
+
+ // handles if cell has rowspan
+ if (cell.isRowspan) {
+ this.handleCellAddWithRowspan(cell, ridx+1, where);
+ }
+
+ } else {
+ // expands cell
+ cell.el.setAttribute('colspan', parseInt(api.getAttribute(cell.el, 'colspan'), 10) + 1);
+ }
+ },
+
+ addColumn: function(where) {
+ var row, modCell;
+
+ this.setTableMap();
+ this.idx = this.getMapIndex(this.cell);
+ if (where == "after" && api.getAttribute(this.cell, 'colspan')) {
+ this.idx.col = this.idx.col + parseInt(api.getAttribute(this.cell, 'colspan'), 10) - 1;
+ }
+
+ if (this.idx !== false) {
+ for (var ridx = 0, rmax = this.map.length; ridx < rmax; ridx++ ) {
+ row = this.map[ridx];
+ if (row[this.idx.col]) {
+ modCell = row[this.idx.col];
+ if (!modCell.modified) {
+ this.setCellAsModified(modCell);
+ this.addColCell(modCell, ridx , where);
+ }
+ }
+ }
+ }
+ },
+
+ handleCellAddWithRowspan: function (cell, ridx, where) {
+ var addRowsNr = parseInt(api.getAttribute(this.cell, 'rowspan'), 10) - 1,
+ crow = api.getParentElement(cell.el, { nodeName: ["TR"] }),
+ cType = cell.el.tagName.toLowerCase(),
+ cidx, temp_r_cells,
+ doc = this.table.ownerDocument,
+ nrow;
+
+ for (var i = 0; i < addRowsNr; i++) {
+ cidx = this.correctColIndexForUnreals(this.idx.col, (ridx + i));
+ crow = nextNode(crow, 'tr');
+ if (crow) {
+ if (cidx > 0) {
+ switch (where) {
+ case "before":
+ temp_r_cells = this.getRowCells(crow);
+ if (cidx > 0 && this.map[ridx + i][this.idx.col].el != temp_r_cells[cidx] && cidx == temp_r_cells.length - 1) {
+ insertAfter(temp_r_cells[cidx], this.createCells(cType, 1));
+ } else {
+ temp_r_cells[cidx].parentNode.insertBefore(this.createCells(cType, 1), temp_r_cells[cidx]);
+ }
+
+ break;
+ case "after":
+ insertAfter(this.getRowCells(crow)[cidx], this.createCells(cType, 1));
+ break;
+ }
+ } else {
+ crow.insertBefore(this.createCells(cType, 1), crow.firstChild);
+ }
+ } else {
+ nrow = doc.createElement('tr');
+ nrow.appendChild(this.createCells(cType, 1));
+ this.table.appendChild(nrow);
+ }
+ }
+ }
+ };
+
+ api.table = {
+ getCellsBetween: function(cell1, cell2) {
+ var c1 = new TableModifyerByCell(cell1);
+ return c1.getMapElsTo(cell2);
+ },
+
+ addCells: function(cell, where) {
+ var c = new TableModifyerByCell(cell);
+ c.add(where);
+ },
+
+ removeCells: function(cell, what) {
+ var c = new TableModifyerByCell(cell);
+ c.remove(what);
+ },
+
+ mergeCellsBetween: function(cell1, cell2) {
+ var c1 = new TableModifyerByCell(cell1);
+ c1.merge(cell2);
+ },
+
+ unmergeCell: function(cell) {
+ var c = new TableModifyerByCell(cell);
+ c.unmerge();
+ },
+
+ orderSelectionEnds: function(cell, cell2) {
+ var c = new TableModifyerByCell(cell);
+ return c.orderSelectionEnds(cell2);
+ },
+
+ indexOf: function(cell) {
+ var c = new TableModifyerByCell(cell);
+ c.setTableMap();
+ return c.getMapIndex(cell);
+ },
+
+ findCell: function(table, idx) {
+ var c = new TableModifyerByCell(null, table);
+ return c.getElementAtIndex(idx);
+ },
+
+ findRowByCell: function(cell) {
+ var c = new TableModifyerByCell(cell);
+ return c.getRowElementsByCell();
+ },
+
+ findColumnByCell: function(cell) {
+ var c = new TableModifyerByCell(cell);
+ return c.getColumnElementsByCell();
+ },
+
+ canMerge: function(cell1, cell2) {
+ var c = new TableModifyerByCell(cell1);
+ return c.canMerge(cell2);
+ }
+ };
+
+
+
+})(wysihtml5);
--- /dev/null
+(function(dom) {
+ var documentElement = document.documentElement;
+ if ("textContent" in documentElement) {
+ dom.setTextContent = function(element, text) {
+ element.textContent = text;
+ };
+
+ dom.getTextContent = function(element) {
+ return element.textContent;
+ };
+ } else if ("innerText" in documentElement) {
+ dom.setTextContent = function(element, text) {
+ element.innerText = text;
+ };
+
+ dom.getTextContent = function(element) {
+ return element.innerText;
+ };
+ } else {
+ dom.setTextContent = function(element, text) {
+ element.nodeValue = text;
+ };
+
+ dom.getTextContent = function(element) {
+ return element.nodeValue;
+ };
+ }
+})(wysihtml5.dom);
+
--- /dev/null
+wysihtml5.dom.unwrap = function(node) {
+ if (node.parentNode) {
+ while (node.lastChild) {
+ wysihtml5.dom.insert(node.lastChild).after(node);
+ }
+ node.parentNode.removeChild(node);
+ }
+};
\ No newline at end of file
--- /dev/null
+/**
+ * WYSIHTML5 Editor
+ *
+ * @param {Element} editableElement Reference to the textarea which should be turned into a rich text interface
+ * @param {Object} [config] See defaultConfig object below for explanation of each individual config option
+ *
+ * @events
+ * load
+ * beforeload (for internal use only)
+ * focus
+ * focus:composer
+ * focus:textarea
+ * blur
+ * blur:composer
+ * blur:textarea
+ * change
+ * change:composer
+ * change:textarea
+ * paste
+ * paste:composer
+ * paste:textarea
+ * newword:composer
+ * destroy:composer
+ * undo:composer
+ * redo:composer
+ * beforecommand:composer
+ * aftercommand:composer
+ * enable:composer
+ * disable:composer
+ * change_view
+ */
+(function(wysihtml5) {
+ var undef;
+
+ var defaultConfig = {
+ // Give the editor a name, the name will also be set as class name on the iframe and on the iframe's body
+ name: undef,
+ // Whether the editor should look like the textarea (by adopting styles)
+ style: true,
+ // Id of the toolbar element, pass falsey value if you don't want any toolbar logic
+ toolbar: undef,
+ // Whether toolbar is displayed after init by script automatically.
+ // Can be set to false if toolobar is set to display only on editable area focus
+ showToolbarAfterInit: true,
+ // Whether urls, entered by the user should automatically become clickable-links
+ autoLink: true,
+ // Includes table editing events and cell selection tracking
+ handleTables: true,
+ // Tab key inserts tab into text as default behaviour. It can be disabled to regain keyboard navigation
+ handleTabKey: true,
+ // Object which includes parser rules to apply when html gets cleaned
+ // See parser_rules/*.js for examples
+ parserRules: { tags: { br: {}, span: {}, div: {}, p: {} }, classes: {} },
+ // Object which includes parser when the user inserts content via copy & paste. If null parserRules will be used instead
+ pasteParserRulesets: null,
+ // Parser method to use when the user inserts content
+ parser: wysihtml5.dom.parse,
+ // Class name which should be set on the contentEditable element in the created sandbox iframe, can be styled via the 'stylesheets' option
+ composerClassName: "wysihtml5-editor",
+ // Class name to add to the body when the wysihtml5 editor is supported
+ bodyClassName: "wysihtml5-supported",
+ // By default wysihtml5 will insert a <br> for line breaks, set this to false to use <p>
+ useLineBreaks: true,
+ // Array (or single string) of stylesheet urls to be loaded in the editor's iframe
+ stylesheets: [],
+ // Placeholder text to use, defaults to the placeholder attribute on the textarea element
+ placeholderText: undef,
+ // Whether the rich text editor should be rendered on touch devices (wysihtml5 >= 0.3.0 comes with basic support for iOS 5)
+ supportTouchDevices: true,
+ // Whether senseless <span> elements (empty or without attributes) should be removed/replaced with their content
+ cleanUp: true,
+ // Whether to use div instead of secure iframe
+ contentEditableMode: false,
+ // Classname of container that editor should not touch and pass through
+ // Pass false to disable
+ uneditableContainerClassname: "wysihtml5-uneditable-container",
+ // Browsers that support copied source handling will get a marking of the origin of the copied source (for determinig code cleanup rules on paste)
+ // Also copied source is based directly on selection -
+ // (very useful for webkit based browsers where copy will otherwise contain a lot of code and styles based on whatever and not actually in selection).
+ // If falsy value is passed source override is also disabled
+ copyedFromMarking: '<meta name="copied-from" content="wysihtml5">'
+ };
+
+ wysihtml5.Editor = wysihtml5.lang.Dispatcher.extend(
+ /** @scope wysihtml5.Editor.prototype */ {
+ constructor: function(editableElement, config) {
+ this.editableElement = typeof(editableElement) === "string" ? document.getElementById(editableElement) : editableElement;
+ this.config = wysihtml5.lang.object({}).merge(defaultConfig).merge(config).get();
+ this._isCompatible = wysihtml5.browser.supported();
+
+ if (this.editableElement.nodeName.toLowerCase() != "textarea") {
+ this.config.contentEditableMode = true;
+ this.config.noTextarea = true;
+ }
+ if (!this.config.noTextarea) {
+ this.textarea = new wysihtml5.views.Textarea(this, this.editableElement, this.config);
+ this.currentView = this.textarea;
+ }
+
+ // Sort out unsupported/unwanted browsers here
+ if (!this._isCompatible || (!this.config.supportTouchDevices && wysihtml5.browser.isTouchDevice())) {
+ var that = this;
+ setTimeout(function() { that.fire("beforeload").fire("load"); }, 0);
+ return;
+ }
+
+ // Add class name to body, to indicate that the editor is supported
+ wysihtml5.dom.addClass(document.body, this.config.bodyClassName);
+
+ this.composer = new wysihtml5.views.Composer(this, this.editableElement, this.config);
+ this.currentView = this.composer;
+
+ if (typeof(this.config.parser) === "function") {
+ this._initParser();
+ }
+
+ this.on("beforeload", this.handleBeforeLoad);
+ },
+
+ handleBeforeLoad: function() {
+ if (!this.config.noTextarea) {
+ this.synchronizer = new wysihtml5.views.Synchronizer(this, this.textarea, this.composer);
+ }
+ if (this.config.toolbar) {
+ this.toolbar = new wysihtml5.toolbar.Toolbar(this, this.config.toolbar, this.config.showToolbarAfterInit);
+ }
+ },
+
+ isCompatible: function() {
+ return this._isCompatible;
+ },
+
+ clear: function() {
+ this.currentView.clear();
+ return this;
+ },
+
+ getValue: function(parse, clearInternals) {
+ return this.currentView.getValue(parse, clearInternals);
+ },
+
+ setValue: function(html, parse) {
+ this.fire("unset_placeholder");
+
+ if (!html) {
+ return this.clear();
+ }
+
+ this.currentView.setValue(html, parse);
+ return this;
+ },
+
+ cleanUp: function() {
+ this.currentView.cleanUp();
+ },
+
+ focus: function(setToEnd) {
+ this.currentView.focus(setToEnd);
+ return this;
+ },
+
+ /**
+ * Deactivate editor (make it readonly)
+ */
+ disable: function() {
+ this.currentView.disable();
+ return this;
+ },
+
+ /**
+ * Activate editor
+ */
+ enable: function() {
+ this.currentView.enable();
+ return this;
+ },
+
+ isEmpty: function() {
+ return this.currentView.isEmpty();
+ },
+
+ hasPlaceholderSet: function() {
+ return this.currentView.hasPlaceholderSet();
+ },
+
+ parse: function(htmlOrElement, clearInternals) {
+ var parseContext = (this.config.contentEditableMode) ? document : ((this.composer) ? this.composer.sandbox.getDocument() : null);
+ var returnValue = this.config.parser(htmlOrElement, {
+ "rules": this.config.parserRules,
+ "cleanUp": this.config.cleanUp,
+ "context": parseContext,
+ "uneditableClass": this.config.uneditableContainerClassname,
+ "clearInternals" : clearInternals
+ });
+ if (typeof(htmlOrElement) === "object") {
+ wysihtml5.quirks.redraw(htmlOrElement);
+ }
+ return returnValue;
+ },
+
+ /**
+ * Prepare html parser logic
+ * - Observes for paste and drop
+ */
+ _initParser: function() {
+ var that = this,
+ oldHtml,
+ cleanHtml;
+
+ if (wysihtml5.browser.supportsModenPaste()) {
+ this.on("paste:composer", function(event) {
+ event.preventDefault();
+ oldHtml = wysihtml5.dom.getPastedHtml(event);
+ if (oldHtml) {
+ that._cleanAndPaste(oldHtml);
+ }
+ });
+
+ } else {
+ this.on("beforepaste:composer", function(event) {
+ event.preventDefault();
+ wysihtml5.dom.getPastedHtmlWithDiv(that.composer, function(pastedHTML) {
+ if (pastedHTML) {
+ that._cleanAndPaste(pastedHTML);
+ }
+ });
+ });
+
+ }
+ },
+
+ _cleanAndPaste: function (oldHtml) {
+ var cleanHtml = wysihtml5.quirks.cleanPastedHTML(oldHtml, {
+ "referenceNode": this.composer.element,
+ "rules": this.config.pasteParserRulesets || [{"set": this.config.parserRules}],
+ "uneditableClass": this.config.uneditableContainerClassname
+ });
+ this.composer.selection.deleteContents();
+ this.composer.selection.insertHTML(cleanHtml);
+ }
+ });
+})(wysihtml5);
--- /dev/null
+wysihtml5.lang.array = function(arr) {
+ return {
+ /**
+ * Check whether a given object exists in an array
+ *
+ * @example
+ * wysihtml5.lang.array([1, 2]).contains(1);
+ * // => true
+ *
+ * Can be used to match array with array. If intersection is found true is returned
+ */
+ contains: function(needle) {
+ if (Array.isArray(needle)) {
+ for (var i = needle.length; i--;) {
+ if (wysihtml5.lang.array(arr).indexOf(needle[i]) !== -1) {
+ return true;
+ }
+ }
+ return false;
+ } else {
+ return wysihtml5.lang.array(arr).indexOf(needle) !== -1;
+ }
+ },
+
+ /**
+ * Check whether a given object exists in an array and return index
+ * If no elelemt found returns -1
+ *
+ * @example
+ * wysihtml5.lang.array([1, 2]).indexOf(2);
+ * // => 1
+ */
+ indexOf: function(needle) {
+ if (arr.indexOf) {
+ return arr.indexOf(needle);
+ } else {
+ for (var i=0, length=arr.length; i<length; i++) {
+ if (arr[i] === needle) { return i; }
+ }
+ return -1;
+ }
+ },
+
+ /**
+ * Substract one array from another
+ *
+ * @example
+ * wysihtml5.lang.array([1, 2, 3, 4]).without([3, 4]);
+ * // => [1, 2]
+ */
+ without: function(arrayToSubstract) {
+ arrayToSubstract = wysihtml5.lang.array(arrayToSubstract);
+ var newArr = [],
+ i = 0,
+ length = arr.length;
+ for (; i<length; i++) {
+ if (!arrayToSubstract.contains(arr[i])) {
+ newArr.push(arr[i]);
+ }
+ }
+ return newArr;
+ },
+
+ /**
+ * Return a clean native array
+ *
+ * Following will convert a Live NodeList to a proper Array
+ * @example
+ * var childNodes = wysihtml5.lang.array(document.body.childNodes).get();
+ */
+ get: function() {
+ var i = 0,
+ length = arr.length,
+ newArray = [];
+ for (; i<length; i++) {
+ newArray.push(arr[i]);
+ }
+ return newArray;
+ },
+
+ /**
+ * Creates a new array with the results of calling a provided function on every element in this array.
+ * optionally this can be provided as second argument
+ *
+ * @example
+ * var childNodes = wysihtml5.lang.array([1,2,3,4]).map(function (value, index, array) {
+ return value * 2;
+ * });
+ * // => [2,4,6,8]
+ */
+ map: function(callback, thisArg) {
+ if (Array.prototype.map) {
+ return arr.map(callback, thisArg);
+ } else {
+ var len = arr.length >>> 0,
+ A = new Array(len),
+ i = 0;
+ for (; i < len; i++) {
+ A[i] = callback.call(thisArg, arr[i], i, arr);
+ }
+ return A;
+ }
+ },
+
+ /* ReturnS new array without duplicate entries
+ *
+ * @example
+ * var uniq = wysihtml5.lang.array([1,2,3,2,1,4]).unique();
+ * // => [1,2,3,4]
+ */
+ unique: function() {
+ var vals = [],
+ max = arr.length,
+ idx = 0;
+
+ while (idx < max) {
+ if (!wysihtml5.lang.array(vals).contains(arr[idx])) {
+ vals.push(arr[idx]);
+ }
+ idx++;
+ }
+ return vals;
+ }
+
+ };
+};
--- /dev/null
+wysihtml5.lang.Dispatcher = Base.extend(
+ /** @scope wysihtml5.lang.Dialog.prototype */ {
+ on: function(eventName, handler) {
+ this.events = this.events || {};
+ this.events[eventName] = this.events[eventName] || [];
+ this.events[eventName].push(handler);
+ return this;
+ },
+
+ off: function(eventName, handler) {
+ this.events = this.events || {};
+ var i = 0,
+ handlers,
+ newHandlers;
+ if (eventName) {
+ handlers = this.events[eventName] || [],
+ newHandlers = [];
+ for (; i<handlers.length; i++) {
+ if (handlers[i] !== handler && handler) {
+ newHandlers.push(handlers[i]);
+ }
+ }
+ this.events[eventName] = newHandlers;
+ } else {
+ // Clean up all events
+ this.events = {};
+ }
+ return this;
+ },
+
+ fire: function(eventName, payload) {
+ this.events = this.events || {};
+ var handlers = this.events[eventName] || [],
+ i = 0;
+ for (; i<handlers.length; i++) {
+ handlers[i].call(this, payload);
+ }
+ return this;
+ },
+
+ // deprecated, use .on()
+ observe: function() {
+ return this.on.apply(this, arguments);
+ },
+
+ // deprecated, use .off()
+ stopObserving: function() {
+ return this.off.apply(this, arguments);
+ }
+});
--- /dev/null
+wysihtml5.lang.object = function(obj) {
+ return {
+ /**
+ * @example
+ * wysihtml5.lang.object({ foo: 1, bar: 1 }).merge({ bar: 2, baz: 3 }).get();
+ * // => { foo: 1, bar: 2, baz: 3 }
+ */
+ merge: function(otherObj) {
+ for (var i in otherObj) {
+ obj[i] = otherObj[i];
+ }
+ return this;
+ },
+
+ get: function() {
+ return obj;
+ },
+
+ /**
+ * @example
+ * wysihtml5.lang.object({ foo: 1 }).clone();
+ * // => { foo: 1 }
+ *
+ * v0.4.14 adds options for deep clone : wysihtml5.lang.object({ foo: 1 }).clone(true);
+ */
+ clone: function(deep) {
+ var newObj = {},
+ i;
+
+ if (obj === null || !wysihtml5.lang.object(obj).isPlainObject()) {
+ return obj;
+ }
+
+ for (i in obj) {
+ if(obj.hasOwnProperty(i)) {
+ if (deep) {
+ newObj[i] = wysihtml5.lang.object(obj[i]).clone(deep);
+ } else {
+ newObj[i] = obj[i];
+ }
+ }
+ }
+ return newObj;
+ },
+
+ /**
+ * @example
+ * wysihtml5.lang.object([]).isArray();
+ * // => true
+ */
+ isArray: function() {
+ return Object.prototype.toString.call(obj) === "[object Array]";
+ },
+
+ /**
+ * @example
+ * wysihtml5.lang.object(function() {}).isFunction();
+ * // => true
+ */
+ isFunction: function() {
+ return Object.prototype.toString.call(obj) === '[object Function]';
+ },
+
+ isPlainObject: function () {
+ return Object.prototype.toString.call(obj) === '[object Object]';
+ }
+ };
+};
--- /dev/null
+(function() {
+ var WHITE_SPACE_START = /^\s+/,
+ WHITE_SPACE_END = /\s+$/,
+ ENTITY_REG_EXP = /[&<>\t"]/g,
+ ENTITY_MAP = {
+ '&': '&',
+ '<': '<',
+ '>': '>',
+ '"': """,
+ '\t':" "
+ };
+ wysihtml5.lang.string = function(str) {
+ str = String(str);
+ return {
+ /**
+ * @example
+ * wysihtml5.lang.string(" foo ").trim();
+ * // => "foo"
+ */
+ trim: function() {
+ return str.replace(WHITE_SPACE_START, "").replace(WHITE_SPACE_END, "");
+ },
+
+ /**
+ * @example
+ * wysihtml5.lang.string("Hello #{name}").interpolate({ name: "Christopher" });
+ * // => "Hello Christopher"
+ */
+ interpolate: function(vars) {
+ for (var i in vars) {
+ str = this.replace("#{" + i + "}").by(vars[i]);
+ }
+ return str;
+ },
+
+ /**
+ * @example
+ * wysihtml5.lang.string("Hello Tom").replace("Tom").with("Hans");
+ * // => "Hello Hans"
+ */
+ replace: function(search) {
+ return {
+ by: function(replace) {
+ return str.split(search).join(replace);
+ }
+ };
+ },
+
+ /**
+ * @example
+ * wysihtml5.lang.string("hello<br>").escapeHTML();
+ * // => "hello<br>"
+ */
+ escapeHTML: function(linebreaks, convertSpaces) {
+ var html = str.replace(ENTITY_REG_EXP, function(c) { return ENTITY_MAP[c]; });
+ if (linebreaks) {
+ html = html.replace(/(?:\r\n|\r|\n)/g, '<br />');
+ }
+ if (convertSpaces) {
+ html = html.replace(/ /gi, " ");
+ }
+ return html;
+ }
+ };
+ };
+})();
--- /dev/null
+// TODO: in future try to replace most inline compability checks with polyfills for code readability
+
+// IE8 SUPPORT BLOCK
+// You can compile wuthout all this if IE8 is not needed
+
+// addEventListener, removeEventListener
+// TODO: make usage of wysihtml5.dom.observe obsolete
+(function() {
+ if (!Event.prototype.preventDefault) {
+ Event.prototype.preventDefault=function() {
+ this.returnValue=false;
+ };
+ }
+ if (!Event.prototype.stopPropagation) {
+ Event.prototype.stopPropagation=function() {
+ this.cancelBubble=true;
+ };
+ }
+ if (!Element.prototype.addEventListener) {
+ var eventListeners=[];
+
+ var addEventListener=function(type,listener /*, useCapture (will be ignored) */) {
+ var self=this;
+ var wrapper=function(e) {
+ e.target=e.srcElement;
+ e.currentTarget=self;
+ if (listener.handleEvent) {
+ listener.handleEvent(e);
+ } else {
+ listener.call(self,e);
+ }
+ };
+ if (type=="DOMContentLoaded") {
+ var wrapper2=function(e) {
+ if (document.readyState=="complete") {
+ wrapper(e);
+ }
+ };
+ document.attachEvent("onreadystatechange",wrapper2);
+ eventListeners.push({object:this,type:type,listener:listener,wrapper:wrapper2});
+
+ if (document.readyState=="complete") {
+ var e=new Event();
+ e.srcElement=window;
+ wrapper2(e);
+ }
+ } else {
+ this.attachEvent("on"+type,wrapper);
+ eventListeners.push({object:this,type:type,listener:listener,wrapper:wrapper});
+ }
+ };
+ var removeEventListener=function(type,listener /*, useCapture (will be ignored) */) {
+ var counter=0;
+ while (counter<eventListeners.length) {
+ var eventListener=eventListeners[counter];
+ if (eventListener.object==this && eventListener.type==type && eventListener.listener==listener) {
+ if (type=="DOMContentLoaded") {
+ this.detachEvent("onreadystatechange",eventListener.wrapper);
+ } else {
+ this.detachEvent("on"+type,eventListener.wrapper);
+ }
+ eventListeners.splice(counter, 1);
+ break;
+ }
+ ++counter;
+ }
+ };
+ Element.prototype.addEventListener=addEventListener;
+ Element.prototype.removeEventListener=removeEventListener;
+ if (HTMLDocument) {
+ HTMLDocument.prototype.addEventListener=addEventListener;
+ HTMLDocument.prototype.removeEventListener=removeEventListener;
+ }
+ if (Window) {
+ Window.prototype.addEventListener=addEventListener;
+ Window.prototype.removeEventListener=removeEventListener;
+ }
+ }
+})();
+
+// element.textContent polyfill.
+if (Object.defineProperty && Object.getOwnPropertyDescriptor && Object.getOwnPropertyDescriptor(Element.prototype, "textContent") && !Object.getOwnPropertyDescriptor(Element.prototype, "textContent").get) {
+ (function() {
+ var innerText = Object.getOwnPropertyDescriptor(Element.prototype, "innerText");
+ Object.defineProperty(Element.prototype, "textContent",
+ {
+ get: function() {
+ return innerText.get.call(this);
+ },
+ set: function(s) {
+ return innerText.set.call(this, s);
+ }
+ }
+ );
+ })();
+}
+
+// isArray polyfill for ie8
+if(!Array.isArray) {
+ Array.isArray = function(arg) {
+ return Object.prototype.toString.call(arg) === '[object Array]';
+ };
+}
+
+// Function.prototype.bind()
+// TODO: clean the code from variable 'that' as it can be confusing
+if (!Function.prototype.bind) {
+ Function.prototype.bind = function(oThis) {
+ if (typeof this !== 'function') {
+ // closest thing possible to the ECMAScript 5
+ // internal IsCallable function
+ throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
+ }
+
+ var aArgs = Array.prototype.slice.call(arguments, 1),
+ fToBind = this,
+ fNOP = function() {},
+ fBound = function() {
+ return fToBind.apply(this instanceof fNOP && oThis
+ ? this
+ : oThis,
+ aArgs.concat(Array.prototype.slice.call(arguments)));
+ };
+
+ fNOP.prototype = this.prototype;
+ fBound.prototype = new fNOP();
+
+ return fBound;
+ };
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Fix most common html formatting misbehaviors of browsers implementation when inserting
+ * content via copy & paste contentEditable
+ *
+ * @author Christopher Blum
+ */
+wysihtml5.quirks.cleanPastedHTML = (function() {
+
+ var styleToRegex = function (styleStr) {
+ var trimmedStr = wysihtml5.lang.string(styleStr).trim(),
+ escapedStr = trimmedStr.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
+
+ return new RegExp("^((?!^" + escapedStr + "$).)*$", "i");
+ };
+
+ var extendRulesWithStyleExceptions = function (rules, exceptStyles) {
+ var newRules = wysihtml5.lang.object(rules).clone(true),
+ tag, style;
+
+ for (tag in newRules.tags) {
+
+ if (newRules.tags.hasOwnProperty(tag)) {
+ if (newRules.tags[tag].keep_styles) {
+ for (style in newRules.tags[tag].keep_styles) {
+ if (newRules.tags[tag].keep_styles.hasOwnProperty(style)) {
+ if (exceptStyles[style]) {
+ newRules.tags[tag].keep_styles[style] = styleToRegex(exceptStyles[style]);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return newRules;
+ };
+
+ var pickRuleset = function(ruleset, html) {
+ var pickedSet, defaultSet;
+
+ if (!ruleset) {
+ return null;
+ }
+
+ for (var i = 0, max = ruleset.length; i < max; i++) {
+ if (!ruleset[i].condition) {
+ defaultSet = ruleset[i].set;
+ }
+ if (ruleset[i].condition && ruleset[i].condition.test(html)) {
+ return ruleset[i].set;
+ }
+ }
+
+ return defaultSet;
+ };
+
+ return function(html, options) {
+ var exceptStyles = {
+ 'color': wysihtml5.dom.getStyle("color").from(options.referenceNode),
+ 'fontSize': wysihtml5.dom.getStyle("font-size").from(options.referenceNode)
+ },
+ rules = extendRulesWithStyleExceptions(pickRuleset(options.rules, html) || {}, exceptStyles),
+ newHtml;
+
+ newHtml = wysihtml5.dom.parse(html, {
+ "rules": rules,
+ "cleanUp": true, // <span> elements, empty or without attributes, should be removed/replaced with their content
+ "context": options.referenceNode.ownerDocument,
+ "uneditableClass": options.uneditableClass,
+ "clearInternals" : true, // don't paste temprorary selection and other markings
+ "unjoinNbsps" : true
+ });
+
+ return newHtml;
+ };
+
+})();
\ No newline at end of file
--- /dev/null
+/**
+ * IE and Opera leave an empty paragraph in the contentEditable element after clearing it
+ *
+ * @param {Object} contentEditableElement The contentEditable element to observe for clearing events
+ * @exaple
+ * wysihtml5.quirks.ensureProperClearing(myContentEditableElement);
+ */
+wysihtml5.quirks.ensureProperClearing = (function() {
+ var clearIfNecessary = function() {
+ var element = this;
+ setTimeout(function() {
+ var innerHTML = element.innerHTML.toLowerCase();
+ if (innerHTML == "<p> </p>" ||
+ innerHTML == "<p> </p><p> </p>") {
+ element.innerHTML = "";
+ }
+ }, 0);
+ };
+
+ return function(composer) {
+ wysihtml5.dom.observe(composer.element, ["cut", "keydown"], clearIfNecessary);
+ };
+})();
--- /dev/null
+// See https://bugzilla.mozilla.org/show_bug.cgi?id=664398
+//
+// In Firefox this:
+// var d = document.createElement("div");
+// d.innerHTML ='<a href="~"></a>';
+// d.innerHTML;
+// will result in:
+// <a href="%7E"></a>
+// which is wrong
+(function(wysihtml5) {
+ var TILDE_ESCAPED = "%7E";
+ wysihtml5.quirks.getCorrectInnerHTML = function(element) {
+ var innerHTML = element.innerHTML;
+ if (innerHTML.indexOf(TILDE_ESCAPED) === -1) {
+ return innerHTML;
+ }
+
+ var elementsWithTilde = element.querySelectorAll("[href*='~'], [src*='~']"),
+ url,
+ urlToSearch,
+ length,
+ i;
+ for (i=0, length=elementsWithTilde.length; i<length; i++) {
+ url = elementsWithTilde[i].href || elementsWithTilde[i].src;
+ urlToSearch = wysihtml5.lang.string(url).replace("~").by(TILDE_ESCAPED);
+ innerHTML = wysihtml5.lang.string(innerHTML).replace(urlToSearch).by(url);
+ }
+ return innerHTML;
+ };
+})(wysihtml5);
--- /dev/null
+/**
+ * Force rerendering of a given element
+ * Needed to fix display misbehaviors of IE
+ *
+ * @param {Element} element The element object which needs to be rerendered
+ * @example
+ * wysihtml5.quirks.redraw(document.body);
+ */
+(function(wysihtml5) {
+ var CLASS_NAME = "wysihtml5-quirks-redraw";
+
+ wysihtml5.quirks.redraw = function(element) {
+ wysihtml5.dom.addClass(element, CLASS_NAME);
+ wysihtml5.dom.removeClass(element, CLASS_NAME);
+
+ // Following hack is needed for firefox to make sure that image resize handles are properly removed
+ try {
+ var doc = element.ownerDocument;
+ doc.execCommand("italic", false, null);
+ doc.execCommand("italic", false, null);
+ } catch(e) {}
+ };
+})(wysihtml5);
--- /dev/null
+(function(wysihtml5) {
+ var RGBA_REGEX = /^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*([\d\.]+)\s*\)/i,
+ RGB_REGEX = /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/i,
+ HEX6_REGEX = /^#([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])/i,
+ HEX3_REGEX = /^#([0-9a-f])([0-9a-f])([0-9a-f])/i;
+
+ var param_REGX = function (p) {
+ return new RegExp("(^|\\s|;)" + p + "\\s*:\\s*[^;$]+" , "gi");
+ };
+
+ wysihtml5.quirks.styleParser = {
+
+ parseColor: function(stylesStr, paramName) {
+ var paramRegex = param_REGX(paramName),
+ params = stylesStr.match(paramRegex),
+ radix = 10,
+ str, colorMatch;
+
+ if (params) {
+ for (var i = params.length; i--;) {
+ params[i] = wysihtml5.lang.string(params[i].split(':')[1]).trim();
+ }
+ str = params[params.length-1];
+
+ if (RGBA_REGEX.test(str)) {
+ colorMatch = str.match(RGBA_REGEX);
+ } else if (RGB_REGEX.test(str)) {
+ colorMatch = str.match(RGB_REGEX);
+ } else if (HEX6_REGEX.test(str)) {
+ colorMatch = str.match(HEX6_REGEX);
+ radix = 16;
+ } else if (HEX3_REGEX.test(str)) {
+ colorMatch = str.match(HEX3_REGEX);
+ colorMatch.shift();
+ colorMatch.push(1);
+ return wysihtml5.lang.array(colorMatch).map(function(d, idx) {
+ return (idx < 3) ? (parseInt(d, 16) * 16) + parseInt(d, 16): parseFloat(d);
+ });
+ }
+
+ if (colorMatch) {
+ colorMatch.shift();
+ if (!colorMatch[3]) {
+ colorMatch.push(1);
+ }
+ return wysihtml5.lang.array(colorMatch).map(function(d, idx) {
+ return (idx < 3) ? parseInt(d, radix): parseFloat(d);
+ });
+ }
+ }
+ return false;
+ },
+
+ unparseColor: function(val, props) {
+ if (props) {
+ if (props == "hex") {
+ return (val[0].toString(16).toUpperCase()) + (val[1].toString(16).toUpperCase()) + (val[2].toString(16).toUpperCase());
+ } else if (props == "hash") {
+ return "#" + (val[0].toString(16).toUpperCase()) + (val[1].toString(16).toUpperCase()) + (val[2].toString(16).toUpperCase());
+ } else if (props == "rgb") {
+ return "rgb(" + val[0] + "," + val[1] + "," + val[2] + ")";
+ } else if (props == "rgba") {
+ return "rgba(" + val[0] + "," + val[1] + "," + val[2] + "," + val[3] + ")";
+ } else if (props == "csv") {
+ return val[0] + "," + val[1] + "," + val[2] + "," + val[3];
+ }
+ }
+
+ if (val[3] && val[3] !== 1) {
+ return "rgba(" + val[0] + "," + val[1] + "," + val[2] + "," + val[3] + ")";
+ } else {
+ return "rgb(" + val[0] + "," + val[1] + "," + val[2] + ")";
+ }
+ },
+
+ parseFontSize: function(stylesStr) {
+ var params = stylesStr.match(param_REGX('font-size'));
+ if (params) {
+ return wysihtml5.lang.string(params[params.length - 1].split(':')[1]).trim();
+ }
+ return false;
+ }
+ };
+
+})(wysihtml5);
--- /dev/null
+wysihtml5.quirks.tableCellsSelection = function(editable, editor) {
+
+ var dom = wysihtml5.dom,
+ select = {
+ table: null,
+ start: null,
+ end: null,
+ cells: null,
+ select: selectCells
+ },
+ selection_class = "wysiwyg-tmp-selected-cell",
+ moveHandler = null,
+ upHandler = null;
+
+ function init () {
+
+ dom.observe(editable, "mousedown", function(event) {
+ var target = wysihtml5.dom.getParentElement(event.target, { nodeName: ["TD", "TH"] });
+ if (target) {
+ handleSelectionMousedown(target);
+ }
+ });
+
+ return select;
+ }
+
+ function handleSelectionMousedown (target) {
+ select.start = target;
+ select.end = target;
+ select.cells = [target];
+ select.table = dom.getParentElement(select.start, { nodeName: ["TABLE"] });
+
+ if (select.table) {
+ removeCellSelections();
+ dom.addClass(target, selection_class);
+ moveHandler = dom.observe(editable, "mousemove", handleMouseMove);
+ upHandler = dom.observe(editable, "mouseup", handleMouseUp);
+ editor.fire("tableselectstart").fire("tableselectstart:composer");
+ }
+ }
+
+ // remove all selection classes
+ function removeCellSelections () {
+ if (editable) {
+ var selectedCells = editable.querySelectorAll('.' + selection_class);
+ if (selectedCells.length > 0) {
+ for (var i = 0; i < selectedCells.length; i++) {
+ dom.removeClass(selectedCells[i], selection_class);
+ }
+ }
+ }
+ }
+
+ function addSelections (cells) {
+ for (var i = 0; i < cells.length; i++) {
+ dom.addClass(cells[i], selection_class);
+ }
+ }
+
+ function handleMouseMove (event) {
+ var curTable = null,
+ cell = dom.getParentElement(event.target, { nodeName: ["TD","TH"] }),
+ oldEnd;
+
+ if (cell && select.table && select.start) {
+ curTable = dom.getParentElement(cell, { nodeName: ["TABLE"] });
+ if (curTable && curTable === select.table) {
+ removeCellSelections();
+ oldEnd = select.end;
+ select.end = cell;
+ select.cells = dom.table.getCellsBetween(select.start, cell);
+ if (select.cells.length > 1) {
+ editor.composer.selection.deselect();
+ }
+ addSelections(select.cells);
+ if (select.end !== oldEnd) {
+ editor.fire("tableselectchange").fire("tableselectchange:composer");
+ }
+ }
+ }
+ }
+
+ function handleMouseUp (event) {
+ moveHandler.stop();
+ upHandler.stop();
+ editor.fire("tableselect").fire("tableselect:composer");
+ setTimeout(function() {
+ bindSideclick();
+ },0);
+ }
+
+ function bindSideclick () {
+ var sideClickHandler = dom.observe(editable.ownerDocument, "click", function(event) {
+ sideClickHandler.stop();
+ if (dom.getParentElement(event.target, { nodeName: ["TABLE"] }) != select.table) {
+ removeCellSelections();
+ select.table = null;
+ select.start = null;
+ select.end = null;
+ editor.fire("tableunselect").fire("tableunselect:composer");
+ }
+ });
+ }
+
+ function selectCells (start, end) {
+ select.start = start;
+ select.end = end;
+ select.table = dom.getParentElement(select.start, { nodeName: ["TABLE"] });
+ selectedCells = dom.table.getCellsBetween(select.start, select.end);
+ addSelections(selectedCells);
+ bindSideclick();
+ editor.fire("tableselect").fire("tableselect:composer");
+ }
+
+ return init();
+
+};
--- /dev/null
+/**
+ * Inspired by the rangy CSS Applier module written by Tim Down and licensed under the MIT license.
+ * http://code.google.com/p/rangy/
+ *
+ * changed in order to be able ...
+ * - to use custom tags
+ * - to detect and replace similar css classes via reg exp
+ */
+(function(wysihtml5, rangy) {
+ var defaultTagName = "span";
+
+ var REG_EXP_WHITE_SPACE = /\s+/g;
+
+ function hasClass(el, cssClass, regExp) {
+ if (!el.className) {
+ return false;
+ }
+
+ var matchingClassNames = el.className.match(regExp) || [];
+ return matchingClassNames[matchingClassNames.length - 1] === cssClass;
+ }
+
+ function hasStyleAttr(el, regExp) {
+ if (!el.getAttribute || !el.getAttribute('style')) {
+ return false;
+ }
+ var matchingStyles = el.getAttribute('style').match(regExp);
+ return (el.getAttribute('style').match(regExp)) ? true : false;
+ }
+
+ function addStyle(el, cssStyle, regExp) {
+ if (el.getAttribute('style')) {
+ removeStyle(el, regExp);
+ if (el.getAttribute('style') && !(/^\s*$/).test(el.getAttribute('style'))) {
+ el.setAttribute('style', cssStyle + ";" + el.getAttribute('style'));
+ } else {
+ el.setAttribute('style', cssStyle);
+ }
+ } else {
+ el.setAttribute('style', cssStyle);
+ }
+ }
+
+ function addClass(el, cssClass, regExp) {
+ if (el.className) {
+ removeClass(el, regExp);
+ el.className += " " + cssClass;
+ } else {
+ el.className = cssClass;
+ }
+ }
+
+ function removeClass(el, regExp) {
+ if (el.className) {
+ el.className = el.className.replace(regExp, "");
+ }
+ }
+
+ function removeStyle(el, regExp) {
+ var s,
+ s2 = [];
+ if (el.getAttribute('style')) {
+ s = el.getAttribute('style').split(';');
+ for (var i = s.length; i--;) {
+ if (!s[i].match(regExp) && !(/^\s*$/).test(s[i])) {
+ s2.push(s[i]);
+ }
+ }
+ if (s2.length) {
+ el.setAttribute('style', s2.join(';'));
+ } else {
+ el.removeAttribute('style');
+ }
+ }
+ }
+
+ function getMatchingStyleRegexp(el, style) {
+ var regexes = [],
+ sSplit = style.split(';'),
+ elStyle = el.getAttribute('style');
+
+ if (elStyle) {
+ elStyle = elStyle.replace(/\s/gi, '').toLowerCase();
+ regexes.push(new RegExp("(^|\\s|;)" + style.replace(/\s/gi, '').replace(/([\(\)])/gi, "\\$1").toLowerCase().replace(";", ";?").replace(/rgb\\\((\d+),(\d+),(\d+)\\\)/gi, "\\s?rgb\\($1,\\s?$2,\\s?$3\\)"), "gi"));
+
+ for (var i = sSplit.length; i-- > 0;) {
+ if (!(/^\s*$/).test(sSplit[i])) {
+ regexes.push(new RegExp("(^|\\s|;)" + sSplit[i].replace(/\s/gi, '').replace(/([\(\)])/gi, "\\$1").toLowerCase().replace(";", ";?").replace(/rgb\\\((\d+),(\d+),(\d+)\\\)/gi, "\\s?rgb\\($1,\\s?$2,\\s?$3\\)"), "gi"));
+ }
+ }
+ for (var j = 0, jmax = regexes.length; j < jmax; j++) {
+ if (elStyle.match(regexes[j])) {
+ return regexes[j];
+ }
+ }
+ }
+
+ return false;
+ }
+
+ function isMatchingAllready(node, tags, style, className) {
+ if (style) {
+ return getMatchingStyleRegexp(node, style);
+ } else if (className) {
+ return wysihtml5.dom.hasClass(node, className);
+ } else {
+ return rangy.dom.arrayContains(tags, node.tagName.toLowerCase());
+ }
+ }
+
+ function areMatchingAllready(nodes, tags, style, className) {
+ for (var i = nodes.length; i--;) {
+ if (!isMatchingAllready(nodes[i], tags, style, className)) {
+ return false;
+ }
+ }
+ return nodes.length ? true : false;
+ }
+
+ function removeOrChangeStyle(el, style, regExp) {
+
+ var exactRegex = getMatchingStyleRegexp(el, style);
+ if (exactRegex) {
+ // adding same style value on property again removes style
+ removeStyle(el, exactRegex);
+ return "remove";
+ } else {
+ // adding new style value changes value
+ addStyle(el, style, regExp);
+ return "change";
+ }
+ }
+
+ function hasSameClasses(el1, el2) {
+ return el1.className.replace(REG_EXP_WHITE_SPACE, " ") == el2.className.replace(REG_EXP_WHITE_SPACE, " ");
+ }
+
+ function replaceWithOwnChildren(el) {
+ var parent = el.parentNode;
+ while (el.firstChild) {
+ parent.insertBefore(el.firstChild, el);
+ }
+ parent.removeChild(el);
+ }
+
+ function elementsHaveSameNonClassAttributes(el1, el2) {
+ if (el1.attributes.length != el2.attributes.length) {
+ return false;
+ }
+ for (var i = 0, len = el1.attributes.length, attr1, attr2, name; i < len; ++i) {
+ attr1 = el1.attributes[i];
+ name = attr1.name;
+ if (name != "class") {
+ attr2 = el2.attributes.getNamedItem(name);
+ if (attr1.specified != attr2.specified) {
+ return false;
+ }
+ if (attr1.specified && attr1.nodeValue !== attr2.nodeValue) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ function isSplitPoint(node, offset) {
+ if (rangy.dom.isCharacterDataNode(node)) {
+ if (offset == 0) {
+ return !!node.previousSibling;
+ } else if (offset == node.length) {
+ return !!node.nextSibling;
+ } else {
+ return true;
+ }
+ }
+
+ return offset > 0 && offset < node.childNodes.length;
+ }
+
+ function splitNodeAt(node, descendantNode, descendantOffset, container) {
+ var newNode;
+ if (rangy.dom.isCharacterDataNode(descendantNode)) {
+ if (descendantOffset == 0) {
+ descendantOffset = rangy.dom.getNodeIndex(descendantNode);
+ descendantNode = descendantNode.parentNode;
+ } else if (descendantOffset == descendantNode.length) {
+ descendantOffset = rangy.dom.getNodeIndex(descendantNode) + 1;
+ descendantNode = descendantNode.parentNode;
+ } else {
+ newNode = rangy.dom.splitDataNode(descendantNode, descendantOffset);
+ }
+ }
+ if (!newNode) {
+ if (!container || descendantNode !== container) {
+
+ newNode = descendantNode.cloneNode(false);
+ if (newNode.id) {
+ newNode.removeAttribute("id");
+ }
+ var child;
+ while ((child = descendantNode.childNodes[descendantOffset])) {
+ newNode.appendChild(child);
+ }
+ rangy.dom.insertAfter(newNode, descendantNode);
+
+ }
+ }
+ return (descendantNode == node) ? newNode : splitNodeAt(node, newNode.parentNode, rangy.dom.getNodeIndex(newNode), container);
+ }
+
+ function Merge(firstNode) {
+ this.isElementMerge = (firstNode.nodeType == wysihtml5.ELEMENT_NODE);
+ this.firstTextNode = this.isElementMerge ? firstNode.lastChild : firstNode;
+ this.textNodes = [this.firstTextNode];
+ }
+
+ Merge.prototype = {
+ doMerge: function() {
+ var textBits = [], textNode, parent, text;
+ for (var i = 0, len = this.textNodes.length; i < len; ++i) {
+ textNode = this.textNodes[i];
+ parent = textNode.parentNode;
+ textBits[i] = textNode.data;
+ if (i) {
+ parent.removeChild(textNode);
+ if (!parent.hasChildNodes()) {
+ parent.parentNode.removeChild(parent);
+ }
+ }
+ }
+ this.firstTextNode.data = text = textBits.join("");
+ return text;
+ },
+
+ getLength: function() {
+ var i = this.textNodes.length, len = 0;
+ while (i--) {
+ len += this.textNodes[i].length;
+ }
+ return len;
+ },
+
+ toString: function() {
+ var textBits = [];
+ for (var i = 0, len = this.textNodes.length; i < len; ++i) {
+ textBits[i] = "'" + this.textNodes[i].data + "'";
+ }
+ return "[Merge(" + textBits.join(",") + ")]";
+ }
+ };
+
+ function HTMLApplier(tagNames, cssClass, similarClassRegExp, normalize, cssStyle, similarStyleRegExp, container) {
+ this.tagNames = tagNames || [defaultTagName];
+ this.cssClass = cssClass || ((cssClass === false) ? false : "");
+ this.similarClassRegExp = similarClassRegExp;
+ this.cssStyle = cssStyle || "";
+ this.similarStyleRegExp = similarStyleRegExp;
+ this.normalize = normalize;
+ this.applyToAnyTagName = false;
+ this.container = container;
+ }
+
+ HTMLApplier.prototype = {
+ getAncestorWithClass: function(node) {
+ var cssClassMatch;
+ while (node) {
+ cssClassMatch = this.cssClass ? hasClass(node, this.cssClass, this.similarClassRegExp) : (this.cssStyle !== "") ? false : true;
+ if (node.nodeType == wysihtml5.ELEMENT_NODE && node.getAttribute("contenteditable") != "false" && rangy.dom.arrayContains(this.tagNames, node.tagName.toLowerCase()) && cssClassMatch) {
+ return node;
+ }
+ node = node.parentNode;
+ }
+ return false;
+ },
+
+ // returns parents of node with given style attribute
+ getAncestorWithStyle: function(node) {
+ var cssStyleMatch;
+ while (node) {
+ cssStyleMatch = this.cssStyle ? hasStyleAttr(node, this.similarStyleRegExp) : false;
+
+ if (node.nodeType == wysihtml5.ELEMENT_NODE && node.getAttribute("contenteditable") != "false" && rangy.dom.arrayContains(this.tagNames, node.tagName.toLowerCase()) && cssStyleMatch) {
+ return node;
+ }
+ node = node.parentNode;
+ }
+ return false;
+ },
+
+ getMatchingAncestor: function(node) {
+ var ancestor = this.getAncestorWithClass(node),
+ matchType = false;
+
+ if (!ancestor) {
+ ancestor = this.getAncestorWithStyle(node);
+ if (ancestor) {
+ matchType = "style";
+ }
+ } else {
+ if (this.cssStyle) {
+ matchType = "class";
+ }
+ }
+
+ return {
+ "element": ancestor,
+ "type": matchType
+ };
+ },
+
+ // Normalizes nodes after applying a CSS class to a Range.
+ postApply: function(textNodes, range) {
+ var firstNode = textNodes[0], lastNode = textNodes[textNodes.length - 1];
+
+ var merges = [], currentMerge;
+
+ var rangeStartNode = firstNode, rangeEndNode = lastNode;
+ var rangeStartOffset = 0, rangeEndOffset = lastNode.length;
+
+ var textNode, precedingTextNode;
+
+ for (var i = 0, len = textNodes.length; i < len; ++i) {
+ textNode = textNodes[i];
+ precedingTextNode = null;
+ if (textNode && textNode.parentNode) {
+ precedingTextNode = this.getAdjacentMergeableTextNode(textNode.parentNode, false);
+ }
+ if (precedingTextNode) {
+ if (!currentMerge) {
+ currentMerge = new Merge(precedingTextNode);
+ merges.push(currentMerge);
+ }
+ currentMerge.textNodes.push(textNode);
+ if (textNode === firstNode) {
+ rangeStartNode = currentMerge.firstTextNode;
+ rangeStartOffset = rangeStartNode.length;
+ }
+ if (textNode === lastNode) {
+ rangeEndNode = currentMerge.firstTextNode;
+ rangeEndOffset = currentMerge.getLength();
+ }
+ } else {
+ currentMerge = null;
+ }
+ }
+ // Test whether the first node after the range needs merging
+ if(lastNode && lastNode.parentNode) {
+ var nextTextNode = this.getAdjacentMergeableTextNode(lastNode.parentNode, true);
+ if (nextTextNode) {
+ if (!currentMerge) {
+ currentMerge = new Merge(lastNode);
+ merges.push(currentMerge);
+ }
+ currentMerge.textNodes.push(nextTextNode);
+ }
+ }
+ // Do the merges
+ if (merges.length) {
+ for (i = 0, len = merges.length; i < len; ++i) {
+ merges[i].doMerge();
+ }
+ // Set the range boundaries
+ range.setStart(rangeStartNode, rangeStartOffset);
+ range.setEnd(rangeEndNode, rangeEndOffset);
+ }
+ },
+
+ getAdjacentMergeableTextNode: function(node, forward) {
+ var isTextNode = (node.nodeType == wysihtml5.TEXT_NODE);
+ var el = isTextNode ? node.parentNode : node;
+ var adjacentNode;
+ var propName = forward ? "nextSibling" : "previousSibling";
+ if (isTextNode) {
+ // Can merge if the node's previous/next sibling is a text node
+ adjacentNode = node[propName];
+ if (adjacentNode && adjacentNode.nodeType == wysihtml5.TEXT_NODE) {
+ return adjacentNode;
+ }
+ } else {
+ // Compare element with its sibling
+ adjacentNode = el[propName];
+ if (adjacentNode && this.areElementsMergeable(node, adjacentNode)) {
+ return adjacentNode[forward ? "firstChild" : "lastChild"];
+ }
+ }
+ return null;
+ },
+
+ areElementsMergeable: function(el1, el2) {
+ return rangy.dom.arrayContains(this.tagNames, (el1.tagName || "").toLowerCase())
+ && rangy.dom.arrayContains(this.tagNames, (el2.tagName || "").toLowerCase())
+ && hasSameClasses(el1, el2)
+ && elementsHaveSameNonClassAttributes(el1, el2);
+ },
+
+ createContainer: function(doc) {
+ var el = doc.createElement(this.tagNames[0]);
+ if (this.cssClass) {
+ el.className = this.cssClass;
+ }
+ if (this.cssStyle) {
+ el.setAttribute('style', this.cssStyle);
+ }
+ return el;
+ },
+
+ applyToTextNode: function(textNode) {
+ var parent = textNode.parentNode;
+ if (parent.childNodes.length == 1 && rangy.dom.arrayContains(this.tagNames, parent.tagName.toLowerCase())) {
+
+ if (this.cssClass) {
+ addClass(parent, this.cssClass, this.similarClassRegExp);
+ }
+ if (this.cssStyle) {
+ addStyle(parent, this.cssStyle, this.similarStyleRegExp);
+ }
+ } else {
+ var el = this.createContainer(rangy.dom.getDocument(textNode));
+ textNode.parentNode.insertBefore(el, textNode);
+ el.appendChild(textNode);
+ }
+ },
+
+ isRemovable: function(el) {
+ return rangy.dom.arrayContains(this.tagNames, el.tagName.toLowerCase()) &&
+ wysihtml5.lang.string(el.className).trim() === "" &&
+ (
+ !el.getAttribute('style') ||
+ wysihtml5.lang.string(el.getAttribute('style')).trim() === ""
+ );
+ },
+
+ undoToTextNode: function(textNode, range, ancestorWithClass, ancestorWithStyle) {
+ var styleMode = (ancestorWithClass) ? false : true,
+ ancestor = ancestorWithClass || ancestorWithStyle,
+ styleChanged = false;
+ if (!range.containsNode(ancestor)) {
+ // Split out the portion of the ancestor from which we can remove the CSS class
+ var ancestorRange = range.cloneRange();
+ ancestorRange.selectNode(ancestor);
+
+ if (ancestorRange.isPointInRange(range.endContainer, range.endOffset) && isSplitPoint(range.endContainer, range.endOffset)) {
+ splitNodeAt(ancestor, range.endContainer, range.endOffset, this.container);
+ range.setEndAfter(ancestor);
+ }
+ if (ancestorRange.isPointInRange(range.startContainer, range.startOffset) && isSplitPoint(range.startContainer, range.startOffset)) {
+ ancestor = splitNodeAt(ancestor, range.startContainer, range.startOffset, this.container);
+ }
+ }
+
+ if (!styleMode && this.similarClassRegExp) {
+ removeClass(ancestor, this.similarClassRegExp);
+ }
+
+ if (styleMode && this.similarStyleRegExp) {
+ styleChanged = (removeOrChangeStyle(ancestor, this.cssStyle, this.similarStyleRegExp) === "change");
+ }
+ if (this.isRemovable(ancestor) && !styleChanged) {
+ replaceWithOwnChildren(ancestor);
+ }
+ },
+
+ applyToRange: function(range) {
+ var textNodes;
+ for (var ri = range.length; ri--;) {
+ textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
+
+ if (!textNodes.length) {
+ try {
+ var node = this.createContainer(range[ri].endContainer.ownerDocument);
+ range[ri].surroundContents(node);
+ this.selectNode(range[ri], node);
+ return;
+ } catch(e) {}
+ }
+
+ range[ri].splitBoundaries();
+ textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
+ if (textNodes.length) {
+ var textNode;
+
+ for (var i = 0, len = textNodes.length; i < len; ++i) {
+ textNode = textNodes[i];
+ if (!this.getMatchingAncestor(textNode).element) {
+ this.applyToTextNode(textNode);
+ }
+ }
+
+ range[ri].setStart(textNodes[0], 0);
+ textNode = textNodes[textNodes.length - 1];
+ range[ri].setEnd(textNode, textNode.length);
+
+ if (this.normalize) {
+ this.postApply(textNodes, range[ri]);
+ }
+ }
+
+ }
+ },
+
+ undoToRange: function(range) {
+ var textNodes, textNode, ancestorWithClass, ancestorWithStyle, ancestor;
+ for (var ri = range.length; ri--;) {
+
+ textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
+ if (textNodes.length) {
+ range[ri].splitBoundaries();
+ textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
+ } else {
+ var doc = range[ri].endContainer.ownerDocument,
+ node = doc.createTextNode(wysihtml5.INVISIBLE_SPACE);
+ range[ri].insertNode(node);
+ range[ri].selectNode(node);
+ textNodes = [node];
+ }
+
+ for (var i = 0, len = textNodes.length; i < len; ++i) {
+ if (range[ri].isValid()) {
+ textNode = textNodes[i];
+
+ ancestor = this.getMatchingAncestor(textNode);
+ if (ancestor.type === "style") {
+ this.undoToTextNode(textNode, range[ri], false, ancestor.element);
+ } else if (ancestor.element) {
+ this.undoToTextNode(textNode, range[ri], ancestor.element);
+ }
+ }
+ }
+
+ if (len == 1) {
+ this.selectNode(range[ri], textNodes[0]);
+ } else {
+ range[ri].setStart(textNodes[0], 0);
+ textNode = textNodes[textNodes.length - 1];
+ range[ri].setEnd(textNode, textNode.length);
+
+ if (this.normalize) {
+ this.postApply(textNodes, range[ri]);
+ }
+ }
+
+ }
+ },
+
+ selectNode: function(range, node) {
+ var isElement = node.nodeType === wysihtml5.ELEMENT_NODE,
+ canHaveHTML = "canHaveHTML" in node ? node.canHaveHTML : true,
+ content = isElement ? node.innerHTML : node.data,
+ isEmpty = (content === "" || content === wysihtml5.INVISIBLE_SPACE);
+
+ if (isEmpty && isElement && canHaveHTML) {
+ // Make sure that caret is visible in node by inserting a zero width no breaking space
+ try { node.innerHTML = wysihtml5.INVISIBLE_SPACE; } catch(e) {}
+ }
+ range.selectNodeContents(node);
+ if (isEmpty && isElement) {
+ range.collapse(false);
+ } else if (isEmpty) {
+ range.setStartAfter(node);
+ range.setEndAfter(node);
+ }
+ },
+
+ getTextSelectedByRange: function(textNode, range) {
+ var textRange = range.cloneRange();
+ textRange.selectNodeContents(textNode);
+
+ var intersectionRange = textRange.intersection(range);
+ var text = intersectionRange ? intersectionRange.toString() : "";
+ textRange.detach();
+
+ return text;
+ },
+
+ isAppliedToRange: function(range) {
+ var ancestors = [],
+ appliedType = "full",
+ ancestor, styleAncestor, textNodes;
+
+ for (var ri = range.length; ri--;) {
+
+ textNodes = range[ri].getNodes([wysihtml5.TEXT_NODE]);
+ if (!textNodes.length) {
+ ancestor = this.getMatchingAncestor(range[ri].startContainer).element;
+
+ return (ancestor) ? {
+ "elements": [ancestor],
+ "coverage": appliedType
+ } : false;
+ }
+
+ for (var i = 0, len = textNodes.length, selectedText; i < len; ++i) {
+ selectedText = this.getTextSelectedByRange(textNodes[i], range[ri]);
+ ancestor = this.getMatchingAncestor(textNodes[i]).element;
+ if (ancestor && selectedText != "") {
+ ancestors.push(ancestor);
+
+ if (wysihtml5.dom.getTextNodes(ancestor, true).length === 1) {
+ appliedType = "full";
+ } else if (appliedType === "full") {
+ appliedType = "inline";
+ }
+ } else if (!ancestor) {
+ appliedType = "partial";
+ }
+ }
+
+ }
+
+ return (ancestors.length) ? {
+ "elements": ancestors,
+ "coverage": appliedType
+ } : false;
+ },
+
+ toggleRange: function(range) {
+ var isApplied = this.isAppliedToRange(range),
+ parentsExactMatch;
+
+ if (isApplied) {
+ if (isApplied.coverage === "full") {
+ this.undoToRange(range);
+ } else if (isApplied.coverage === "inline") {
+ parentsExactMatch = areMatchingAllready(isApplied.elements, this.tagNames, this.cssStyle, this.cssClass);
+ this.undoToRange(range);
+ if (!parentsExactMatch) {
+ this.applyToRange(range);
+ }
+ } else {
+ // partial
+ if (!areMatchingAllready(isApplied.elements, this.tagNames, this.cssStyle, this.cssClass)) {
+ this.undoToRange(range);
+ }
+ this.applyToRange(range);
+ }
+ } else {
+ this.applyToRange(range);
+ }
+ }
+ };
+
+ wysihtml5.selection.HTMLApplier = HTMLApplier;
+
+})(wysihtml5, rangy);
--- /dev/null
+/**
+ * Selection API
+ *
+ * @example
+ * var selection = new wysihtml5.Selection(editor);
+ */
+(function(wysihtml5) {
+ var dom = wysihtml5.dom;
+
+ function _getCumulativeOffsetTop(element) {
+ var top = 0;
+ if (element.parentNode) {
+ do {
+ top += element.offsetTop || 0;
+ element = element.offsetParent;
+ } while (element);
+ }
+ return top;
+ }
+
+ // Provides the depth of ``descendant`` relative to ``ancestor``
+ function getDepth(ancestor, descendant) {
+ var ret = 0;
+ while (descendant !== ancestor) {
+ ret++;
+ descendant = descendant.parentNode;
+ if (!descendant)
+ throw new Error("not a descendant of ancestor!");
+ }
+ return ret;
+ }
+
+ // Should fix the obtained ranges that cannot surrond contents normally to apply changes upon
+ // Being considerate to firefox that sets range start start out of span and end inside on doubleclick initiated selection
+ function expandRangeToSurround(range) {
+ if (range.canSurroundContents()) return;
+
+ var common = range.commonAncestorContainer,
+ start_depth = getDepth(common, range.startContainer),
+ end_depth = getDepth(common, range.endContainer);
+
+ while(!range.canSurroundContents()) {
+ // In the following branches, we cannot just decrement the depth variables because the setStartBefore/setEndAfter may move the start or end of the range more than one level relative to ``common``. So we need to recompute the depth.
+ if (start_depth > end_depth) {
+ range.setStartBefore(range.startContainer);
+ start_depth = getDepth(common, range.startContainer);
+ }
+ else {
+ range.setEndAfter(range.endContainer);
+ end_depth = getDepth(common, range.endContainer);
+ }
+ }
+ }
+
+ wysihtml5.Selection = Base.extend(
+ /** @scope wysihtml5.Selection.prototype */ {
+ constructor: function(editor, contain, unselectableClass) {
+ // Make sure that our external range library is initialized
+ window.rangy.init();
+
+ this.editor = editor;
+ this.composer = editor.composer;
+ this.doc = this.composer.doc;
+ this.contain = contain;
+ this.unselectableClass = unselectableClass || false;
+ },
+
+ /**
+ * Get the current selection as a bookmark to be able to later restore it
+ *
+ * @return {Object} An object that represents the current selection
+ */
+ getBookmark: function() {
+ var range = this.getRange();
+ if (range) expandRangeToSurround(range);
+ return range && range.cloneRange();
+ },
+
+ /**
+ * Restore a selection retrieved via wysihtml5.Selection.prototype.getBookmark
+ *
+ * @param {Object} bookmark An object that represents the current selection
+ */
+ setBookmark: function(bookmark) {
+ if (!bookmark) {
+ return;
+ }
+
+ this.setSelection(bookmark);
+ },
+
+ /**
+ * Set the caret in front of the given node
+ *
+ * @param {Object} node The element or text node where to position the caret in front of
+ * @example
+ * selection.setBefore(myElement);
+ */
+ setBefore: function(node) {
+ var range = rangy.createRange(this.doc);
+ range.setStartBefore(node);
+ range.setEndBefore(node);
+ return this.setSelection(range);
+ },
+
+ // Constructs a self removing whitespace (ain absolute positioned span) for placing selection caret when normal methods fail.
+ // Webkit has an issue with placing caret into places where there are no textnodes near by.
+ creteTemporaryCaretSpaceAfter: function (node) {
+ var caretPlaceholder = this.doc.createElement('span'),
+ caretPlaceholderText = this.doc.createTextNode(wysihtml5.INVISIBLE_SPACE),
+ placeholderRemover = (function(event) {
+ // Self-destructs the caret and keeps the text inserted into it by user
+ var lastChild;
+
+ this.contain.removeEventListener('mouseup', placeholderRemover);
+ this.contain.removeEventListener('keydown', keyDownHandler);
+ this.contain.removeEventListener('touchstart', placeholderRemover);
+ this.contain.removeEventListener('focus', placeholderRemover);
+ this.contain.removeEventListener('blur', placeholderRemover);
+ this.contain.removeEventListener('paste', delayedPlaceholderRemover);
+ this.contain.removeEventListener('drop', delayedPlaceholderRemover);
+ this.contain.removeEventListener('beforepaste', delayedPlaceholderRemover);
+
+ // If user inserted sth it is in the placeholder and sgould be unwrapped and stripped of invisible whitespace hack
+ // Otherwise the wrapper can just be removed
+ if (caretPlaceholder && caretPlaceholder.parentNode) {
+ caretPlaceholder.innerHTML = caretPlaceholder.innerHTML.replace(wysihtml5.INVISIBLE_SPACE_REG_EXP, "");
+ if ((/[^\s]+/).test(caretPlaceholder.innerHTML)) {
+ lastChild = caretPlaceholder.lastChild;
+ wysihtml5.dom.unwrap(caretPlaceholder);
+ this.setAfter(lastChild);
+ } else {
+ caretPlaceholder.parentNode.removeChild(caretPlaceholder);
+ }
+
+ }
+ }).bind(this),
+ delayedPlaceholderRemover = function (event) {
+ if (caretPlaceholder && caretPlaceholder.parentNode) {
+ setTimeout(placeholderRemover, 0);
+ }
+ },
+ keyDownHandler = function(event) {
+ if (event.which !== 8 && event.which !== 91 && event.which !== 17 && (event.which !== 86 || (!event.ctrlKey && !event.metaKey))) {
+ placeholderRemover();
+ }
+ };
+
+ caretPlaceholder.style.position = 'absolute';
+ caretPlaceholder.style.display = 'block';
+ caretPlaceholder.style.minWidth = '1px';
+ caretPlaceholder.style.zIndex = '99999';
+ caretPlaceholder.appendChild(caretPlaceholderText);
+
+ node.parentNode.insertBefore(caretPlaceholder, node.nextSibling);
+ this.setBefore(caretPlaceholderText);
+
+ // Remove the caret fix on any of the following events (some are delayed as content change happens after event)
+ this.contain.addEventListener('mouseup', placeholderRemover);
+ this.contain.addEventListener('keydown', keyDownHandler);
+ this.contain.addEventListener('touchstart', placeholderRemover);
+ this.contain.addEventListener('focus', placeholderRemover);
+ this.contain.addEventListener('blur', placeholderRemover);
+ this.contain.addEventListener('paste', delayedPlaceholderRemover);
+ this.contain.addEventListener('drop', delayedPlaceholderRemover);
+ this.contain.addEventListener('beforepaste', delayedPlaceholderRemover);
+
+ return caretPlaceholder;
+ },
+
+ /**
+ * Set the caret after the given node
+ *
+ * @param {Object} node The element or text node where to position the caret in front of
+ * @example
+ * selection.setBefore(myElement);
+ */
+ setAfter: function(node) {
+ var range = rangy.createRange(this.doc),
+ originalScrollTop = this.doc.documentElement.scrollTop || this.doc.body.scrollTop || this.doc.defaultView.pageYOffset,
+ originalScrollLeft = this.doc.documentElement.scrollLeft || this.doc.body.scrollLeft || this.doc.defaultView.pageXOffset,
+ sel;
+
+ range.setStartAfter(node);
+ range.setEndAfter(node);
+ this.composer.element.focus();
+ this.doc.defaultView.scrollTo(originalScrollLeft, originalScrollTop);
+ sel = this.setSelection(range);
+
+ // Webkit fails to add selection if there are no textnodes in that region
+ // (like an uneditable container at the end of content).
+ if (!sel) {
+ this.creteTemporaryCaretSpaceAfter(node);
+ }
+ return sel;
+ },
+
+ /**
+ * Ability to select/mark nodes
+ *
+ * @param {Element} node The node/element to select
+ * @example
+ * selection.selectNode(document.getElementById("my-image"));
+ */
+ selectNode: function(node, avoidInvisibleSpace) {
+ var range = rangy.createRange(this.doc),
+ isElement = node.nodeType === wysihtml5.ELEMENT_NODE,
+ canHaveHTML = "canHaveHTML" in node ? node.canHaveHTML : (node.nodeName !== "IMG"),
+ content = isElement ? node.innerHTML : node.data,
+ isEmpty = (content === "" || content === wysihtml5.INVISIBLE_SPACE),
+ displayStyle = dom.getStyle("display").from(node),
+ isBlockElement = (displayStyle === "block" || displayStyle === "list-item");
+
+ if (isEmpty && isElement && canHaveHTML && !avoidInvisibleSpace) {
+ // Make sure that caret is visible in node by inserting a zero width no breaking space
+ try { node.innerHTML = wysihtml5.INVISIBLE_SPACE; } catch(e) {}
+ }
+
+ if (canHaveHTML) {
+ range.selectNodeContents(node);
+ } else {
+ range.selectNode(node);
+ }
+
+ if (canHaveHTML && isEmpty && isElement) {
+ range.collapse(isBlockElement);
+ } else if (canHaveHTML && isEmpty) {
+ range.setStartAfter(node);
+ range.setEndAfter(node);
+ }
+
+ this.setSelection(range);
+ },
+
+ /**
+ * Get the node which contains the selection
+ *
+ * @param {Boolean} [controlRange] (only IE) Whether it should return the selected ControlRange element when the selection type is a "ControlRange"
+ * @return {Object} The node that contains the caret
+ * @example
+ * var nodeThatContainsCaret = selection.getSelectedNode();
+ */
+ getSelectedNode: function(controlRange) {
+ var selection,
+ range;
+
+ if (controlRange && this.doc.selection && this.doc.selection.type === "Control") {
+ range = this.doc.selection.createRange();
+ if (range && range.length) {
+ return range.item(0);
+ }
+ }
+
+ selection = this.getSelection(this.doc);
+ if (selection.focusNode === selection.anchorNode) {
+ return selection.focusNode;
+ } else {
+ range = this.getRange(this.doc);
+ return range ? range.commonAncestorContainer : this.doc.body;
+ }
+ },
+
+ fixSelBorders: function() {
+ var range = this.getRange();
+ expandRangeToSurround(range);
+ this.setSelection(range);
+ },
+
+ getSelectedOwnNodes: function(controlRange) {
+ var selection,
+ ranges = this.getOwnRanges(),
+ ownNodes = [];
+
+ for (var i = 0, maxi = ranges.length; i < maxi; i++) {
+ ownNodes.push(ranges[i].commonAncestorContainer || this.doc.body);
+ }
+ return ownNodes;
+ },
+
+ findNodesInSelection: function(nodeTypes) {
+ var ranges = this.getOwnRanges(),
+ nodes = [], curNodes;
+ for (var i = 0, maxi = ranges.length; i < maxi; i++) {
+ curNodes = ranges[i].getNodes([1], function(node) {
+ return wysihtml5.lang.array(nodeTypes).contains(node.nodeName);
+ });
+ nodes = nodes.concat(curNodes);
+ }
+ return nodes;
+ },
+
+ containsUneditable: function() {
+ var uneditables = this.getOwnUneditables(),
+ selection = this.getSelection();
+
+ for (var i = 0, maxi = uneditables.length; i < maxi; i++) {
+ if (selection.containsNode(uneditables[i])) {
+ return true;
+ }
+ }
+
+ return false;
+ },
+
+ // Deletes selection contents making sure uneditables/unselectables are not partially deleted
+ // Triggers wysihtml5:uneditable:delete custom event on all deleted uneditables if customevents suppoorted
+ deleteContents: function() {
+ var range = this.getRange(),
+ startParent, endParent, uneditables, ev;
+
+ if (this.unselectableClass) {
+ if ((startParent = wysihtml5.dom.getParentElement(range.startContainer, { className: this.unselectableClass }, false, this.contain))) {
+ range.setStartBefore(startParent);
+ }
+ if ((endParent = wysihtml5.dom.getParentElement(range.endContainer, { className: this.unselectableClass }, false, this.contain))) {
+ range.setEndAfter(endParent);
+ }
+
+ // If customevents present notify uneditable elements of being deleted
+ uneditables = range.getNodes([1], (function (node) {
+ return wysihtml5.dom.hasClass(node, this.unselectableClass);
+ }).bind(this));
+ for (var i = uneditables.length; i--;) {
+ try {
+ ev = new CustomEvent("wysihtml5:uneditable:delete");
+ uneditables[i].dispatchEvent(ev);
+ } catch (err) {}
+ }
+
+ }
+ range.deleteContents();
+ this.setSelection(range);
+ },
+
+ getPreviousNode: function(node, ignoreEmpty) {
+ var displayStyle;
+ if (!node) {
+ var selection = this.getSelection();
+ node = selection.anchorNode;
+ }
+
+ if (node === this.contain) {
+ return false;
+ }
+
+ var ret = node.previousSibling,
+ parent;
+
+ if (ret === this.contain) {
+ return false;
+ }
+
+ if (ret && ret.nodeType !== 3 && ret.nodeType !== 1) {
+ // do not count comments and other node types
+ ret = this.getPreviousNode(ret, ignoreEmpty);
+ } else if (ret && ret.nodeType === 3 && (/^\s*$/).test(ret.textContent)) {
+ // do not count empty textnodes as previous nodes
+ ret = this.getPreviousNode(ret, ignoreEmpty);
+ } else if (ignoreEmpty && ret && ret.nodeType === 1) {
+ // Do not count empty nodes if param set.
+ // Contenteditable tends to bypass and delete these silently when deleting with caret when element is inline-like
+ displayStyle = wysihtml5.dom.getStyle("display").from(ret);
+ if (
+ !wysihtml5.lang.array(["BR", "HR", "IMG"]).contains(ret.nodeName) &&
+ !wysihtml5.lang.array(["block", "inline-block", "flex", "list-item", "table"]).contains(displayStyle) &&
+ (/^[\s]*$/).test(ret.innerHTML)
+ ) {
+ ret = this.getPreviousNode(ret, ignoreEmpty);
+ }
+ } else if (!ret && node !== this.contain) {
+ parent = node.parentNode;
+ if (parent !== this.contain) {
+ ret = this.getPreviousNode(parent, ignoreEmpty);
+ }
+ }
+
+ return (ret !== this.contain) ? ret : false;
+ },
+
+ getSelectionParentsByTag: function(tagName) {
+ var nodes = this.getSelectedOwnNodes(),
+ curEl, parents = [];
+
+ for (var i = 0, maxi = nodes.length; i < maxi; i++) {
+ curEl = (nodes[i].nodeName && nodes[i].nodeName === 'LI') ? nodes[i] : wysihtml5.dom.getParentElement(nodes[i], { nodeName: ['LI']}, false, this.contain);
+ if (curEl) {
+ parents.push(curEl);
+ }
+ }
+ return (parents.length) ? parents : null;
+ },
+
+ getRangeToNodeEnd: function() {
+ if (this.isCollapsed()) {
+ var range = this.getRange(),
+ sNode = range.startContainer,
+ pos = range.startOffset,
+ lastR = rangy.createRange(this.doc);
+
+ lastR.selectNodeContents(sNode);
+ lastR.setStart(sNode, pos);
+ return lastR;
+ }
+ },
+
+ caretIsLastInSelection: function() {
+ var r = rangy.createRange(this.doc),
+ s = this.getSelection(),
+ endc = this.getRangeToNodeEnd().cloneContents(),
+ endtxt = endc.textContent;
+
+ return (/^\s*$/).test(endtxt);
+ },
+
+ caretIsFirstInSelection: function() {
+ var r = rangy.createRange(this.doc),
+ s = this.getSelection(),
+ range = this.getRange(),
+ startNode = range.startContainer;
+
+ if (startNode) {
+ if (startNode.nodeType === wysihtml5.TEXT_NODE) {
+ return this.isCollapsed() && (startNode.nodeType === wysihtml5.TEXT_NODE && (/^\s*$/).test(startNode.data.substr(0,range.startOffset)));
+ } else {
+ r.selectNodeContents(this.getRange().commonAncestorContainer);
+ r.collapse(true);
+ return (this.isCollapsed() && (r.startContainer === s.anchorNode || r.endContainer === s.anchorNode) && r.startOffset === s.anchorOffset);
+ }
+ }
+ },
+
+ caretIsInTheBeginnig: function(ofNode) {
+ var selection = this.getSelection(),
+ node = selection.anchorNode,
+ offset = selection.anchorOffset;
+ if (ofNode && node) {
+ return (offset === 0 && (node.nodeName && node.nodeName === ofNode.toUpperCase() || wysihtml5.dom.getParentElement(node.parentNode, { nodeName: ofNode }, 1)));
+ } else if (node) {
+ return (offset === 0 && !this.getPreviousNode(node, true));
+ }
+ },
+
+ caretIsBeforeUneditable: function() {
+ var selection = this.getSelection(),
+ node = selection.anchorNode,
+ offset = selection.anchorOffset,
+ childNodes = [],
+ range, contentNodes, lastNode;
+
+ if (node) {
+ if (offset === 0) {
+ var prevNode = this.getPreviousNode(node, true),
+ prevLeaf = prevNode ? wysihtml5.dom.domNode(prevNode).lastLeafNode((this.unselectableClass) ? {leafClasses: [this.unselectableClass]} : false) : null;
+ if (prevLeaf) {
+ var uneditables = this.getOwnUneditables();
+ for (var i = 0, maxi = uneditables.length; i < maxi; i++) {
+ if (prevLeaf === uneditables[i]) {
+ return uneditables[i];
+ }
+ }
+ }
+ } else {
+ range = selection.getRangeAt(0);
+ range.setStart(range.startContainer, range.startOffset - 1);
+ // TODO: make getting children on range a separate funtion
+ if (range) {
+ contentNodes = range.getNodes([1,3]);
+ for (var n = 0, max = contentNodes.length; n < max; n++) {
+ if (contentNodes[n].parentNode && contentNodes[n].parentNode === node) {
+ childNodes.push(contentNodes[n]);
+ }
+ }
+ }
+ lastNode = childNodes.length > 0 ? childNodes[childNodes.length -1] : null;
+ if (lastNode && lastNode.nodeType === 1 && wysihtml5.dom.hasClass(lastNode, this.unselectableClass)) {
+ return lastNode;
+ }
+
+ }
+ }
+ return false;
+ },
+
+ // TODO: Figure out a method from following 2 that would work universally
+ executeAndRestoreRangy: function(method, restoreScrollPosition) {
+ var win = this.doc.defaultView || this.doc.parentWindow,
+ sel = rangy.saveSelection(win);
+
+ if (!sel) {
+ method();
+ } else {
+ try {
+ method();
+ } catch(e) {
+ setTimeout(function() { throw e; }, 0);
+ }
+ }
+ rangy.restoreSelection(sel);
+ },
+
+ // TODO: has problems in chrome 12. investigate block level and uneditable area inbetween
+ executeAndRestore: function(method, restoreScrollPosition) {
+ var body = this.doc.body,
+ oldScrollTop = restoreScrollPosition && body.scrollTop,
+ oldScrollLeft = restoreScrollPosition && body.scrollLeft,
+ className = "_wysihtml5-temp-placeholder",
+ placeholderHtml = '<span class="' + className + '">' + wysihtml5.INVISIBLE_SPACE + '</span>',
+ range = this.getRange(true),
+ caretPlaceholder,
+ newCaretPlaceholder,
+ nextSibling, prevSibling,
+ node, node2, range2,
+ newRange;
+
+ // Nothing selected, execute and say goodbye
+ if (!range) {
+ method(body, body);
+ return;
+ }
+
+ if (!range.collapsed) {
+ range2 = range.cloneRange();
+ node2 = range2.createContextualFragment(placeholderHtml);
+ range2.collapse(false);
+ range2.insertNode(node2);
+ range2.detach();
+ }
+
+ node = range.createContextualFragment(placeholderHtml);
+ range.insertNode(node);
+
+ if (node2) {
+ caretPlaceholder = this.contain.querySelectorAll("." + className);
+ range.setStartBefore(caretPlaceholder[0]);
+ range.setEndAfter(caretPlaceholder[caretPlaceholder.length -1]);
+ }
+ this.setSelection(range);
+
+ // Make sure that a potential error doesn't cause our placeholder element to be left as a placeholder
+ try {
+ method(range.startContainer, range.endContainer);
+ } catch(e) {
+ setTimeout(function() { throw e; }, 0);
+ }
+ caretPlaceholder = this.contain.querySelectorAll("." + className);
+ if (caretPlaceholder && caretPlaceholder.length) {
+ newRange = rangy.createRange(this.doc);
+ nextSibling = caretPlaceholder[0].nextSibling;
+ if (caretPlaceholder.length > 1) {
+ prevSibling = caretPlaceholder[caretPlaceholder.length -1].previousSibling;
+ }
+ if (prevSibling && nextSibling) {
+ newRange.setStartBefore(nextSibling);
+ newRange.setEndAfter(prevSibling);
+ } else {
+ newCaretPlaceholder = this.doc.createTextNode(wysihtml5.INVISIBLE_SPACE);
+ dom.insert(newCaretPlaceholder).after(caretPlaceholder[0]);
+ newRange.setStartBefore(newCaretPlaceholder);
+ newRange.setEndAfter(newCaretPlaceholder);
+ }
+ this.setSelection(newRange);
+ for (var i = caretPlaceholder.length; i--;) {
+ caretPlaceholder[i].parentNode.removeChild(caretPlaceholder[i]);
+ }
+
+ } else {
+ // fallback for when all hell breaks loose
+ this.contain.focus();
+ }
+
+ if (restoreScrollPosition) {
+ body.scrollTop = oldScrollTop;
+ body.scrollLeft = oldScrollLeft;
+ }
+
+ // Remove it again, just to make sure that the placeholder is definitely out of the dom tree
+ try {
+ caretPlaceholder.parentNode.removeChild(caretPlaceholder);
+ } catch(e2) {}
+ },
+
+ set: function(node, offset) {
+ var newRange = rangy.createRange(this.doc);
+ newRange.setStart(node, offset || 0);
+ this.setSelection(newRange);
+ },
+
+ /**
+ * Insert html at the caret position and move the cursor after the inserted html
+ *
+ * @param {String} html HTML string to insert
+ * @example
+ * selection.insertHTML("<p>foobar</p>");
+ */
+ insertHTML: function(html) {
+ var range = rangy.createRange(this.doc),
+ node = this.doc.createElement('DIV'),
+ fragment = this.doc.createDocumentFragment(),
+ lastChild;
+
+ node.innerHTML = html;
+ lastChild = node.lastChild;
+
+ while (node.firstChild) {
+ fragment.appendChild(node.firstChild);
+ }
+ this.insertNode(fragment);
+
+ if (lastChild) {
+ this.setAfter(lastChild);
+ }
+ },
+
+ /**
+ * Insert a node at the caret position and move the cursor behind it
+ *
+ * @param {Object} node HTML string to insert
+ * @example
+ * selection.insertNode(document.createTextNode("foobar"));
+ */
+ insertNode: function(node) {
+ var range = this.getRange();
+ if (range) {
+ range.insertNode(node);
+ }
+ },
+
+ /**
+ * Wraps current selection with the given node
+ *
+ * @param {Object} node The node to surround the selected elements with
+ */
+ surround: function(nodeOptions) {
+ var ranges = this.getOwnRanges(),
+ node, nodes = [];
+ if (ranges.length == 0) {
+ return nodes;
+ }
+
+ for (var i = ranges.length; i--;) {
+ node = this.doc.createElement(nodeOptions.nodeName);
+ nodes.push(node);
+ if (nodeOptions.className) {
+ node.className = nodeOptions.className;
+ }
+ if (nodeOptions.cssStyle) {
+ node.setAttribute('style', nodeOptions.cssStyle);
+ }
+ try {
+ // This only works when the range boundaries are not overlapping other elements
+ ranges[i].surroundContents(node);
+ this.selectNode(node);
+ } catch(e) {
+ // fallback
+ node.appendChild(ranges[i].extractContents());
+ ranges[i].insertNode(node);
+ }
+ }
+ return nodes;
+ },
+
+ deblockAndSurround: function(nodeOptions) {
+ var tempElement = this.doc.createElement('div'),
+ range = rangy.createRange(this.doc),
+ tempDivElements,
+ tempElements,
+ firstChild;
+
+ tempElement.className = nodeOptions.className;
+
+ this.composer.commands.exec("formatBlock", nodeOptions.nodeName, nodeOptions.className);
+ tempDivElements = this.contain.querySelectorAll("." + nodeOptions.className);
+ if (tempDivElements[0]) {
+ tempDivElements[0].parentNode.insertBefore(tempElement, tempDivElements[0]);
+
+ range.setStartBefore(tempDivElements[0]);
+ range.setEndAfter(tempDivElements[tempDivElements.length - 1]);
+ tempElements = range.extractContents();
+
+ while (tempElements.firstChild) {
+ firstChild = tempElements.firstChild;
+ if (firstChild.nodeType == 1 && wysihtml5.dom.hasClass(firstChild, nodeOptions.className)) {
+ while (firstChild.firstChild) {
+ tempElement.appendChild(firstChild.firstChild);
+ }
+ if (firstChild.nodeName !== "BR") { tempElement.appendChild(this.doc.createElement('br')); }
+ tempElements.removeChild(firstChild);
+ } else {
+ tempElement.appendChild(firstChild);
+ }
+ }
+ } else {
+ tempElement = null;
+ }
+
+ return tempElement;
+ },
+
+ /**
+ * Scroll the current caret position into the view
+ * FIXME: This is a bit hacky, there might be a smarter way of doing this
+ *
+ * @example
+ * selection.scrollIntoView();
+ */
+ scrollIntoView: function() {
+ var doc = this.doc,
+ tolerance = 5, // px
+ hasScrollBars = doc.documentElement.scrollHeight > doc.documentElement.offsetHeight,
+ tempElement = doc._wysihtml5ScrollIntoViewElement = doc._wysihtml5ScrollIntoViewElement || (function() {
+ var element = doc.createElement("span");
+ // The element needs content in order to be able to calculate it's position properly
+ element.innerHTML = wysihtml5.INVISIBLE_SPACE;
+ return element;
+ })(),
+ offsetTop;
+
+ if (hasScrollBars) {
+ this.insertNode(tempElement);
+ offsetTop = _getCumulativeOffsetTop(tempElement);
+ tempElement.parentNode.removeChild(tempElement);
+ if (offsetTop >= (doc.body.scrollTop + doc.documentElement.offsetHeight - tolerance)) {
+ doc.body.scrollTop = offsetTop;
+ }
+ }
+ },
+
+ /**
+ * Select line where the caret is in
+ */
+ selectLine: function() {
+ if (wysihtml5.browser.supportsSelectionModify()) {
+ this._selectLine_W3C();
+ } else if (this.doc.selection) {
+ this._selectLine_MSIE();
+ }
+ },
+
+ /**
+ * See https://developer.mozilla.org/en/DOM/Selection/modify
+ */
+ _selectLine_W3C: function() {
+ var win = this.doc.defaultView,
+ selection = win.getSelection();
+ selection.modify("move", "left", "lineboundary");
+ selection.modify("extend", "right", "lineboundary");
+ },
+
+ // collapses selection to current line beginning or end
+ toLineBoundary: function (location, collapse) {
+ collapse = (typeof collapse === 'undefined') ? false : collapse;
+ if (wysihtml5.browser.supportsSelectionModify()) {
+ var win = this.doc.defaultView,
+ selection = win.getSelection();
+
+ selection.modify("extend", location, "lineboundary");
+ if (collapse) {
+ if (location === "left") {
+ selection.collapseToStart();
+ } else if (location === "right") {
+ selection.collapseToEnd();
+ }
+ }
+ }
+ },
+
+ _selectLine_MSIE: function() {
+ var range = this.doc.selection.createRange(),
+ rangeTop = range.boundingTop,
+ scrollWidth = this.doc.body.scrollWidth,
+ rangeBottom,
+ rangeEnd,
+ measureNode,
+ i,
+ j;
+
+ if (!range.moveToPoint) {
+ return;
+ }
+
+ if (rangeTop === 0) {
+ // Don't know why, but when the selection ends at the end of a line
+ // range.boundingTop is 0
+ measureNode = this.doc.createElement("span");
+ this.insertNode(measureNode);
+ rangeTop = measureNode.offsetTop;
+ measureNode.parentNode.removeChild(measureNode);
+ }
+
+ rangeTop += 1;
+
+ for (i=-10; i<scrollWidth; i+=2) {
+ try {
+ range.moveToPoint(i, rangeTop);
+ break;
+ } catch(e1) {}
+ }
+
+ // Investigate the following in order to handle multi line selections
+ // rangeBottom = rangeTop + (rangeHeight ? (rangeHeight - 1) : 0);
+ rangeBottom = rangeTop;
+ rangeEnd = this.doc.selection.createRange();
+ for (j=scrollWidth; j>=0; j--) {
+ try {
+ rangeEnd.moveToPoint(j, rangeBottom);
+ break;
+ } catch(e2) {}
+ }
+
+ range.setEndPoint("EndToEnd", rangeEnd);
+ range.select();
+ },
+
+ getText: function() {
+ var selection = this.getSelection();
+ return selection ? selection.toString() : "";
+ },
+
+ getNodes: function(nodeType, filter) {
+ var range = this.getRange();
+ if (range) {
+ return range.getNodes([nodeType], filter);
+ } else {
+ return [];
+ }
+ },
+
+ fixRangeOverflow: function(range) {
+ if (this.contain && this.contain.firstChild && range) {
+ var containment = range.compareNode(this.contain);
+ if (containment !== 2) {
+ if (containment === 1) {
+ range.setStartBefore(this.contain.firstChild);
+ }
+ if (containment === 0) {
+ range.setEndAfter(this.contain.lastChild);
+ }
+ if (containment === 3) {
+ range.setStartBefore(this.contain.firstChild);
+ range.setEndAfter(this.contain.lastChild);
+ }
+ } else if (this._detectInlineRangeProblems(range)) {
+ var previousElementSibling = range.endContainer.previousElementSibling;
+ if (previousElementSibling) {
+ range.setEnd(previousElementSibling, this._endOffsetForNode(previousElementSibling));
+ }
+ }
+ }
+ },
+
+ _endOffsetForNode: function(node) {
+ var range = document.createRange();
+ range.selectNodeContents(node);
+ return range.endOffset;
+ },
+
+ _detectInlineRangeProblems: function(range) {
+ var position = dom.compareDocumentPosition(range.startContainer, range.endContainer);
+ return (
+ range.endOffset == 0 &&
+ position & 4 //Node.DOCUMENT_POSITION_FOLLOWING
+ );
+ },
+
+ getRange: function(dontFix) {
+ var selection = this.getSelection(),
+ range = selection && selection.rangeCount && selection.getRangeAt(0);
+
+ if (dontFix !== true) {
+ this.fixRangeOverflow(range);
+ }
+
+ return range;
+ },
+
+ getOwnUneditables: function() {
+ var allUneditables = dom.query(this.contain, '.' + this.unselectableClass),
+ deepUneditables = dom.query(allUneditables, '.' + this.unselectableClass);
+
+ return wysihtml5.lang.array(allUneditables).without(deepUneditables);
+ },
+
+ // Returns an array of ranges that belong only to this editable
+ // Needed as uneditable block in contenteditabel can split range into pieces
+ // If manipulating content reverse loop is usually needed as manipulation can shift subsequent ranges
+ getOwnRanges: function() {
+ var ranges = [],
+ r = this.getRange(),
+ tmpRanges;
+
+ if (r) { ranges.push(r); }
+
+ if (this.unselectableClass && this.contain && r) {
+ var uneditables = this.getOwnUneditables(),
+ tmpRange;
+ if (uneditables.length > 0) {
+ for (var i = 0, imax = uneditables.length; i < imax; i++) {
+ tmpRanges = [];
+ for (var j = 0, jmax = ranges.length; j < jmax; j++) {
+ if (ranges[j]) {
+ switch (ranges[j].compareNode(uneditables[i])) {
+ case 2:
+ // all selection inside uneditable. remove
+ break;
+ case 3:
+ //section begins before and ends after uneditable. spilt
+ tmpRange = ranges[j].cloneRange();
+ tmpRange.setEndBefore(uneditables[i]);
+ tmpRanges.push(tmpRange);
+
+ tmpRange = ranges[j].cloneRange();
+ tmpRange.setStartAfter(uneditables[i]);
+ tmpRanges.push(tmpRange);
+ break;
+ default:
+ // in all other cases uneditable does not touch selection. dont modify
+ tmpRanges.push(ranges[j]);
+ }
+ }
+ ranges = tmpRanges;
+ }
+ }
+ }
+ }
+ return ranges;
+ },
+
+ getSelection: function() {
+ return rangy.getSelection(this.doc.defaultView || this.doc.parentWindow);
+ },
+
+ // Sets selection in document to a given range
+ // Set selection method detects if it fails to set any selection in document and returns null on fail
+ // (especially needed in webkit where some ranges just can not create selection for no reason)
+ setSelection: function(range) {
+ var win = this.doc.defaultView || this.doc.parentWindow,
+ selection = rangy.getSelection(win);
+ selection.setSingleRange(range);
+ return (selection && selection.anchorNode && selection.focusNode) ? selection : null;
+ },
+
+ createRange: function() {
+ return rangy.createRange(this.doc);
+ },
+
+ isCollapsed: function() {
+ return this.getSelection().isCollapsed;
+ },
+
+ getHtml: function() {
+ return this.getSelection().toHtml();
+ },
+
+ getPlainText: function () {
+ return this.getSelection().toString();
+ },
+
+ isEndToEndInNode: function(nodeNames) {
+ var range = this.getRange(),
+ parentElement = range.commonAncestorContainer,
+ startNode = range.startContainer,
+ endNode = range.endContainer;
+
+
+ if (parentElement.nodeType === wysihtml5.TEXT_NODE) {
+ parentElement = parentElement.parentNode;
+ }
+
+ if (startNode.nodeType === wysihtml5.TEXT_NODE && !(/^\s*$/).test(startNode.data.substr(range.startOffset))) {
+ return false;
+ }
+
+ if (endNode.nodeType === wysihtml5.TEXT_NODE && !(/^\s*$/).test(endNode.data.substr(range.endOffset))) {
+ return false;
+ }
+
+ while (startNode && startNode !== parentElement) {
+ if (startNode.nodeType !== wysihtml5.TEXT_NODE && !wysihtml5.dom.contains(parentElement, startNode)) {
+ return false;
+ }
+ if (wysihtml5.dom.domNode(startNode).prev({ignoreBlankTexts: true})) {
+ return false;
+ }
+ startNode = startNode.parentNode;
+ }
+
+ while (endNode && endNode !== parentElement) {
+ if (endNode.nodeType !== wysihtml5.TEXT_NODE && !wysihtml5.dom.contains(parentElement, endNode)) {
+ return false;
+ }
+ if (wysihtml5.dom.domNode(endNode).next({ignoreBlankTexts: true})) {
+ return false;
+ }
+ endNode = endNode.parentNode;
+ }
+
+ return (wysihtml5.lang.array(nodeNames).contains(parentElement.nodeName)) ? parentElement : false;
+ },
+
+ deselect: function() {
+ var sel = this.getSelection();
+ sel && sel.removeAllRanges();
+ }
+ });
+
+})(wysihtml5);
--- /dev/null
+/**
+ * Toolbar Dialog
+ *
+ * @param {Element} link The toolbar link which causes the dialog to show up
+ * @param {Element} container The dialog container
+ *
+ * @example
+ * <!-- Toolbar link -->
+ * <a data-wysihtml5-command="insertImage">insert an image</a>
+ *
+ * <!-- Dialog -->
+ * <div data-wysihtml5-dialog="insertImage" style="display: none;">
+ * <label>
+ * URL: <input data-wysihtml5-dialog-field="src" value="http://">
+ * </label>
+ * <label>
+ * Alternative text: <input data-wysihtml5-dialog-field="alt" value="">
+ * </label>
+ * </div>
+ *
+ * <script>
+ * var dialog = new wysihtml5.toolbar.Dialog(
+ * document.querySelector("[data-wysihtml5-command='insertImage']"),
+ * document.querySelector("[data-wysihtml5-dialog='insertImage']")
+ * );
+ * dialog.observe("save", function(attributes) {
+ * // do something
+ * });
+ * </script>
+ */
+(function(wysihtml5) {
+ var dom = wysihtml5.dom,
+ CLASS_NAME_OPENED = "wysihtml5-command-dialog-opened",
+ SELECTOR_FORM_ELEMENTS = "input, select, textarea",
+ SELECTOR_FIELDS = "[data-wysihtml5-dialog-field]",
+ ATTRIBUTE_FIELDS = "data-wysihtml5-dialog-field";
+
+
+ wysihtml5.toolbar.Dialog = wysihtml5.lang.Dispatcher.extend(
+ /** @scope wysihtml5.toolbar.Dialog.prototype */ {
+ constructor: function(link, container) {
+ this.link = link;
+ this.container = container;
+ },
+
+ _observe: function() {
+ if (this._observed) {
+ return;
+ }
+
+ var that = this,
+ callbackWrapper = function(event) {
+ var attributes = that._serialize();
+ if (attributes == that.elementToChange) {
+ that.fire("edit", attributes);
+ } else {
+ that.fire("save", attributes);
+ }
+ that.hide();
+ event.preventDefault();
+ event.stopPropagation();
+ };
+
+ dom.observe(that.link, "click", function() {
+ if (dom.hasClass(that.link, CLASS_NAME_OPENED)) {
+ setTimeout(function() { that.hide(); }, 0);
+ }
+ });
+
+ dom.observe(this.container, "keydown", function(event) {
+ var keyCode = event.keyCode;
+ if (keyCode === wysihtml5.ENTER_KEY) {
+ callbackWrapper(event);
+ }
+ if (keyCode === wysihtml5.ESCAPE_KEY) {
+ that.fire("cancel");
+ that.hide();
+ }
+ });
+
+ dom.delegate(this.container, "[data-wysihtml5-dialog-action=save]", "click", callbackWrapper);
+
+ dom.delegate(this.container, "[data-wysihtml5-dialog-action=cancel]", "click", function(event) {
+ that.fire("cancel");
+ that.hide();
+ event.preventDefault();
+ event.stopPropagation();
+ });
+
+ var formElements = this.container.querySelectorAll(SELECTOR_FORM_ELEMENTS),
+ i = 0,
+ length = formElements.length,
+ _clearInterval = function() { clearInterval(that.interval); };
+ for (; i<length; i++) {
+ dom.observe(formElements[i], "change", _clearInterval);
+ }
+
+ this._observed = true;
+ },
+
+ /**
+ * Grabs all fields in the dialog and puts them in key=>value style in an object which
+ * then gets returned
+ */
+ _serialize: function() {
+ var data = this.elementToChange || {},
+ fields = this.container.querySelectorAll(SELECTOR_FIELDS),
+ length = fields.length,
+ i = 0;
+
+ for (; i<length; i++) {
+ data[fields[i].getAttribute(ATTRIBUTE_FIELDS)] = fields[i].value;
+ }
+ return data;
+ },
+
+ /**
+ * Takes the attributes of the "elementToChange"
+ * and inserts them in their corresponding dialog input fields
+ *
+ * Assume the "elementToChange" looks like this:
+ * <a href="http://www.google.com" target="_blank">foo</a>
+ *
+ * and we have the following dialog:
+ * <input type="text" data-wysihtml5-dialog-field="href" value="">
+ * <input type="text" data-wysihtml5-dialog-field="target" value="">
+ *
+ * after calling _interpolate() the dialog will look like this
+ * <input type="text" data-wysihtml5-dialog-field="href" value="http://www.google.com">
+ * <input type="text" data-wysihtml5-dialog-field="target" value="_blank">
+ *
+ * Basically it adopted the attribute values into the corresponding input fields
+ *
+ */
+ _interpolate: function(avoidHiddenFields) {
+ var field,
+ fieldName,
+ newValue,
+ focusedElement = document.querySelector(":focus"),
+ fields = this.container.querySelectorAll(SELECTOR_FIELDS),
+ length = fields.length,
+ i = 0;
+ for (; i<length; i++) {
+ field = fields[i];
+
+ // Never change elements where the user is currently typing in
+ if (field === focusedElement) {
+ continue;
+ }
+
+ // Don't update hidden fields
+ // See https://github.com/xing/wysihtml5/pull/14
+ if (avoidHiddenFields && field.type === "hidden") {
+ continue;
+ }
+
+ fieldName = field.getAttribute(ATTRIBUTE_FIELDS);
+ newValue = (this.elementToChange && typeof(this.elementToChange) !== 'boolean') ? (this.elementToChange.getAttribute(fieldName) || "") : field.defaultValue;
+ field.value = newValue;
+ }
+ },
+
+ /**
+ * Show the dialog element
+ */
+ show: function(elementToChange) {
+ if (dom.hasClass(this.link, CLASS_NAME_OPENED)) {
+ return;
+ }
+
+ var that = this,
+ firstField = this.container.querySelector(SELECTOR_FORM_ELEMENTS);
+ this.elementToChange = elementToChange;
+ this._observe();
+ this._interpolate();
+ if (elementToChange) {
+ this.interval = setInterval(function() { that._interpolate(true); }, 500);
+ }
+ dom.addClass(this.link, CLASS_NAME_OPENED);
+ this.container.style.display = "";
+ this.fire("show");
+ if (firstField && !elementToChange) {
+ try {
+ firstField.focus();
+ } catch(e) {}
+ }
+ },
+
+ /**
+ * Hide the dialog element
+ */
+ hide: function() {
+ clearInterval(this.interval);
+ this.elementToChange = null;
+ dom.removeClass(this.link, CLASS_NAME_OPENED);
+ this.container.style.display = "none";
+ this.fire("hide");
+ }
+ });
+})(wysihtml5);
--- /dev/null
+(function(wysihtml5) {
+ var dom = wysihtml5.dom,
+ SELECTOR_FIELDS = "[data-wysihtml5-dialog-field]",
+ ATTRIBUTE_FIELDS = "data-wysihtml5-dialog-field";
+
+ wysihtml5.toolbar.Dialog_bgColorStyle = wysihtml5.toolbar.Dialog.extend({
+ multiselect: true,
+
+ _serialize: function() {
+ var data = {},
+ fields = this.container.querySelectorAll(SELECTOR_FIELDS),
+ length = fields.length,
+ i = 0;
+
+ for (; i<length; i++) {
+ data[fields[i].getAttribute(ATTRIBUTE_FIELDS)] = fields[i].value;
+ }
+ return data;
+ },
+
+ _interpolate: function(avoidHiddenFields) {
+ var field,
+ fieldName,
+ newValue,
+ focusedElement = document.querySelector(":focus"),
+ fields = this.container.querySelectorAll(SELECTOR_FIELDS),
+ length = fields.length,
+ i = 0,
+ firstElement = (this.elementToChange) ? ((wysihtml5.lang.object(this.elementToChange).isArray()) ? this.elementToChange[0] : this.elementToChange) : null,
+ colorStr = (firstElement) ? firstElement.getAttribute('style') : null,
+ color = (colorStr) ? wysihtml5.quirks.styleParser.parseColor(colorStr, "background-color") : null;
+
+ for (; i<length; i++) {
+ field = fields[i];
+ // Never change elements where the user is currently typing in
+ if (field === focusedElement) {
+ continue;
+ }
+ // Don't update hidden fields3
+ if (avoidHiddenFields && field.type === "hidden") {
+ continue;
+ }
+ if (field.getAttribute(ATTRIBUTE_FIELDS) === "color") {
+ if (color) {
+ if (color[3] && color[3] != 1) {
+ field.value = "rgba(" + color[0] + "," + color[1] + "," + color[2] + "," + color[3] + ");";
+ } else {
+ field.value = "rgb(" + color[0] + "," + color[1] + "," + color[2] + ");";
+ }
+ } else {
+ field.value = "rgb(0,0,0);";
+ }
+ }
+ }
+ }
+
+ });
+})(wysihtml5);
--- /dev/null
+(function(wysihtml5) {
+ wysihtml5.toolbar.Dialog_createTable = wysihtml5.toolbar.Dialog.extend({
+ show: function(elementToChange) {
+ this.base(elementToChange);
+
+ }
+
+ });
+})(wysihtml5);
--- /dev/null
+(function(wysihtml5) {
+ var dom = wysihtml5.dom,
+ SELECTOR_FIELDS = "[data-wysihtml5-dialog-field]",
+ ATTRIBUTE_FIELDS = "data-wysihtml5-dialog-field";
+
+ wysihtml5.toolbar.Dialog_fontSizeStyle = wysihtml5.toolbar.Dialog.extend({
+ multiselect: true,
+
+ _serialize: function() {
+ return {"size" : this.container.querySelector('[data-wysihtml5-dialog-field="size"]').value};
+ },
+
+ _interpolate: function(avoidHiddenFields) {
+ var focusedElement = document.querySelector(":focus"),
+ field = this.container.querySelector("[data-wysihtml5-dialog-field='size']"),
+ firstElement = (this.elementToChange) ? ((wysihtml5.lang.object(this.elementToChange).isArray()) ? this.elementToChange[0] : this.elementToChange) : null,
+ styleStr = (firstElement) ? firstElement.getAttribute('style') : null,
+ size = (styleStr) ? wysihtml5.quirks.styleParser.parseFontSize(styleStr) : null;
+
+ if (field && field !== focusedElement && size && !(/^\s*$/).test(size)) {
+ field.value = size;
+ }
+ }
+
+ });
+})(wysihtml5);
--- /dev/null
+(function(wysihtml5) {
+ var dom = wysihtml5.dom,
+ SELECTOR_FIELDS = "[data-wysihtml5-dialog-field]",
+ ATTRIBUTE_FIELDS = "data-wysihtml5-dialog-field";
+
+ wysihtml5.toolbar.Dialog_foreColorStyle = wysihtml5.toolbar.Dialog.extend({
+ multiselect: true,
+
+ _serialize: function() {
+ var data = {},
+ fields = this.container.querySelectorAll(SELECTOR_FIELDS),
+ length = fields.length,
+ i = 0;
+
+ for (; i<length; i++) {
+ data[fields[i].getAttribute(ATTRIBUTE_FIELDS)] = fields[i].value;
+ }
+ return data;
+ },
+
+ _interpolate: function(avoidHiddenFields) {
+ var field,
+ fieldName,
+ newValue,
+ focusedElement = document.querySelector(":focus"),
+ fields = this.container.querySelectorAll(SELECTOR_FIELDS),
+ length = fields.length,
+ i = 0,
+ firstElement = (this.elementToChange) ? ((wysihtml5.lang.object(this.elementToChange).isArray()) ? this.elementToChange[0] : this.elementToChange) : null,
+ colorStr = (firstElement) ? firstElement.getAttribute('style') : null,
+ color = (colorStr) ? wysihtml5.quirks.styleParser.parseColor(colorStr, "color") : null;
+
+ for (; i<length; i++) {
+ field = fields[i];
+ // Never change elements where the user is currently typing in
+ if (field === focusedElement) {
+ continue;
+ }
+ // Don't update hidden fields3
+ if (avoidHiddenFields && field.type === "hidden") {
+ continue;
+ }
+ if (field.getAttribute(ATTRIBUTE_FIELDS) === "color") {
+ if (color) {
+ if (color[3] && color[3] != 1) {
+ field.value = "rgba(" + color[0] + "," + color[1] + "," + color[2] + "," + color[3] + ");";
+ } else {
+ field.value = "rgb(" + color[0] + "," + color[1] + "," + color[2] + ");";
+ }
+ } else {
+ field.value = "rgb(0,0,0);";
+ }
+ }
+ }
+ }
+
+ });
+})(wysihtml5);
--- /dev/null
+/**
+ * Converts speech-to-text and inserts this into the editor
+ * As of now (2011/03/25) this only is supported in Chrome >= 11
+ *
+ * Note that it sends the recorded audio to the google speech recognition api:
+ * http://stackoverflow.com/questions/4361826/does-chrome-have-buil-in-speech-recognition-for-input-type-text-x-webkit-speec
+ *
+ * Current HTML5 draft can be found here
+ * http://lists.w3.org/Archives/Public/public-xg-htmlspeech/2011Feb/att-0020/api-draft.html
+ *
+ * "Accessing Google Speech API Chrome 11"
+ * http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/
+ */
+(function(wysihtml5) {
+ var dom = wysihtml5.dom;
+
+ var linkStyles = {
+ position: "relative"
+ };
+
+ var wrapperStyles = {
+ left: 0,
+ margin: 0,
+ opacity: 0,
+ overflow: "hidden",
+ padding: 0,
+ position: "absolute",
+ top: 0,
+ zIndex: 1
+ };
+
+ var inputStyles = {
+ cursor: "inherit",
+ fontSize: "50px",
+ height: "50px",
+ marginTop: "-25px",
+ outline: 0,
+ padding: 0,
+ position: "absolute",
+ right: "-4px",
+ top: "50%"
+ };
+
+ var inputAttributes = {
+ "x-webkit-speech": "",
+ "speech": ""
+ };
+
+ wysihtml5.toolbar.Speech = function(parent, link) {
+ var input = document.createElement("input");
+ if (!wysihtml5.browser.supportsSpeechApiOn(input)) {
+ link.style.display = "none";
+ return;
+ }
+ var lang = parent.editor.textarea.element.getAttribute("lang");
+ if (lang) {
+ inputAttributes.lang = lang;
+ }
+
+ var wrapper = document.createElement("div");
+
+ wysihtml5.lang.object(wrapperStyles).merge({
+ width: link.offsetWidth + "px",
+ height: link.offsetHeight + "px"
+ });
+
+ dom.insert(input).into(wrapper);
+ dom.insert(wrapper).into(link);
+
+ dom.setStyles(inputStyles).on(input);
+ dom.setAttributes(inputAttributes).on(input);
+
+ dom.setStyles(wrapperStyles).on(wrapper);
+ dom.setStyles(linkStyles).on(link);
+
+ var eventName = "onwebkitspeechchange" in input ? "webkitspeechchange" : "speechchange";
+ dom.observe(input, eventName, function() {
+ parent.execCommand("insertText", input.value);
+ input.value = "";
+ });
+
+ dom.observe(input, "click", function(event) {
+ if (dom.hasClass(link, "wysihtml5-command-disabled")) {
+ event.preventDefault();
+ }
+
+ event.stopPropagation();
+ });
+ };
+})(wysihtml5);
--- /dev/null
+/**
+ * Toolbar
+ *
+ * @param {Object} parent Reference to instance of Editor instance
+ * @param {Element} container Reference to the toolbar container element
+ *
+ * @example
+ * <div id="toolbar">
+ * <a data-wysihtml5-command="createLink">insert link</a>
+ * <a data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="h1">insert h1</a>
+ * </div>
+ *
+ * <script>
+ * var toolbar = new wysihtml5.toolbar.Toolbar(editor, document.getElementById("toolbar"));
+ * </script>
+ */
+(function(wysihtml5) {
+ var CLASS_NAME_COMMAND_DISABLED = "wysihtml5-command-disabled",
+ CLASS_NAME_COMMANDS_DISABLED = "wysihtml5-commands-disabled",
+ CLASS_NAME_COMMAND_ACTIVE = "wysihtml5-command-active",
+ CLASS_NAME_ACTION_ACTIVE = "wysihtml5-action-active",
+ dom = wysihtml5.dom;
+
+ wysihtml5.toolbar.Toolbar = Base.extend(
+ /** @scope wysihtml5.toolbar.Toolbar.prototype */ {
+ constructor: function(editor, container, showOnInit) {
+ this.editor = editor;
+ this.container = typeof(container) === "string" ? document.getElementById(container) : container;
+ this.composer = editor.composer;
+
+ this._getLinks("command");
+ this._getLinks("action");
+
+ this._observe();
+ if (showOnInit) { this.show(); }
+
+ if (editor.config.classNameCommandDisabled != null) {
+ CLASS_NAME_COMMAND_DISABLED = editor.config.classNameCommandDisabled;
+ }
+ if (editor.config.classNameCommandsDisabled != null) {
+ CLASS_NAME_COMMANDS_DISABLED = editor.config.classNameCommandsDisabled;
+ }
+ if (editor.config.classNameCommandActive != null) {
+ CLASS_NAME_COMMAND_ACTIVE = editor.config.classNameCommandActive;
+ }
+ if (editor.config.classNameActionActive != null) {
+ CLASS_NAME_ACTION_ACTIVE = editor.config.classNameActionActive;
+ }
+
+ var speechInputLinks = this.container.querySelectorAll("[data-wysihtml5-command=insertSpeech]"),
+ length = speechInputLinks.length,
+ i = 0;
+ for (; i<length; i++) {
+ new wysihtml5.toolbar.Speech(this, speechInputLinks[i]);
+ }
+ },
+
+ _getLinks: function(type) {
+ var links = this[type + "Links"] = wysihtml5.lang.array(this.container.querySelectorAll("[data-wysihtml5-" + type + "]")).get(),
+ length = links.length,
+ i = 0,
+ mapping = this[type + "Mapping"] = {},
+ link,
+ group,
+ name,
+ value,
+ dialog;
+ for (; i<length; i++) {
+ link = links[i];
+ name = link.getAttribute("data-wysihtml5-" + type);
+ value = link.getAttribute("data-wysihtml5-" + type + "-value");
+ group = this.container.querySelector("[data-wysihtml5-" + type + "-group='" + name + "']");
+ dialog = this._getDialog(link, name);
+
+ mapping[name + ":" + value] = {
+ link: link,
+ group: group,
+ name: name,
+ value: value,
+ dialog: dialog,
+ state: false
+ };
+ }
+ },
+
+ _getDialog: function(link, command) {
+ var that = this,
+ dialogElement = this.container.querySelector("[data-wysihtml5-dialog='" + command + "']"),
+ dialog,
+ caretBookmark;
+
+ if (dialogElement) {
+ if (wysihtml5.toolbar["Dialog_" + command]) {
+ dialog = new wysihtml5.toolbar["Dialog_" + command](link, dialogElement);
+ } else {
+ dialog = new wysihtml5.toolbar.Dialog(link, dialogElement);
+ }
+
+ dialog.on("show", function() {
+ caretBookmark = that.composer.selection.getBookmark();
+
+ that.editor.fire("show:dialog", { command: command, dialogContainer: dialogElement, commandLink: link });
+ });
+
+ dialog.on("save", function(attributes) {
+ if (caretBookmark) {
+ that.composer.selection.setBookmark(caretBookmark);
+ }
+ that._execCommand(command, attributes);
+
+ that.editor.fire("save:dialog", { command: command, dialogContainer: dialogElement, commandLink: link });
+ });
+
+ dialog.on("cancel", function() {
+ that.editor.focus(false);
+ that.editor.fire("cancel:dialog", { command: command, dialogContainer: dialogElement, commandLink: link });
+ });
+ }
+ return dialog;
+ },
+
+ /**
+ * @example
+ * var toolbar = new wysihtml5.Toolbar();
+ * // Insert a <blockquote> element or wrap current selection in <blockquote>
+ * toolbar.execCommand("formatBlock", "blockquote");
+ */
+ execCommand: function(command, commandValue) {
+ if (this.commandsDisabled) {
+ return;
+ }
+
+ var commandObj = this.commandMapping[command + ":" + commandValue];
+
+ // Show dialog when available
+ if (commandObj && commandObj.dialog && !commandObj.state) {
+ commandObj.dialog.show();
+ } else {
+ this._execCommand(command, commandValue);
+ }
+ },
+
+ _execCommand: function(command, commandValue) {
+ // Make sure that composer is focussed (false => don't move caret to the end)
+ this.editor.focus(false);
+
+ this.composer.commands.exec(command, commandValue);
+ this._updateLinkStates();
+ },
+
+ execAction: function(action) {
+ var editor = this.editor;
+ if (action === "change_view") {
+ if (editor.textarea) {
+ if (editor.currentView === editor.textarea) {
+ editor.fire("change_view", "composer");
+ } else {
+ editor.fire("change_view", "textarea");
+ }
+ }
+ }
+ if (action == "showSource") {
+ editor.fire("showSource");
+ }
+ },
+
+ _observe: function() {
+ var that = this,
+ editor = this.editor,
+ container = this.container,
+ links = this.commandLinks.concat(this.actionLinks),
+ length = links.length,
+ i = 0;
+
+ for (; i<length; i++) {
+ // 'javascript:;' and unselectable=on Needed for IE, but done in all browsers to make sure that all get the same css applied
+ // (you know, a:link { ... } doesn't match anchors with missing href attribute)
+ if (links[i].nodeName === "A") {
+ dom.setAttributes({
+ href: "javascript:;",
+ unselectable: "on"
+ }).on(links[i]);
+ } else {
+ dom.setAttributes({ unselectable: "on" }).on(links[i]);
+ }
+ }
+
+ // Needed for opera and chrome
+ dom.delegate(container, "[data-wysihtml5-command], [data-wysihtml5-action]", "mousedown", function(event) { event.preventDefault(); });
+
+ dom.delegate(container, "[data-wysihtml5-command]", "click", function(event) {
+ var link = this,
+ command = link.getAttribute("data-wysihtml5-command"),
+ commandValue = link.getAttribute("data-wysihtml5-command-value");
+ that.execCommand(command, commandValue);
+ event.preventDefault();
+ });
+
+ dom.delegate(container, "[data-wysihtml5-action]", "click", function(event) {
+ var action = this.getAttribute("data-wysihtml5-action");
+ that.execAction(action);
+ event.preventDefault();
+ });
+
+ editor.on("interaction:composer", function() {
+ that._updateLinkStates();
+ });
+
+ editor.on("focus:composer", function() {
+ that.bookmark = null;
+ });
+
+ if (this.editor.config.handleTables) {
+ editor.on("tableselect:composer", function() {
+ that.container.querySelectorAll('[data-wysihtml5-hiddentools="table"]')[0].style.display = "";
+ });
+ editor.on("tableunselect:composer", function() {
+ that.container.querySelectorAll('[data-wysihtml5-hiddentools="table"]')[0].style.display = "none";
+ });
+ }
+
+ editor.on("change_view", function(currentView) {
+ // Set timeout needed in order to let the blur event fire first
+ if (editor.textarea) {
+ setTimeout(function() {
+ that.commandsDisabled = (currentView !== "composer");
+ that._updateLinkStates();
+ if (that.commandsDisabled) {
+ dom.addClass(container, CLASS_NAME_COMMANDS_DISABLED);
+ } else {
+ dom.removeClass(container, CLASS_NAME_COMMANDS_DISABLED);
+ }
+ }, 0);
+ }
+ });
+ },
+
+ _updateLinkStates: function() {
+
+ var commandMapping = this.commandMapping,
+ actionMapping = this.actionMapping,
+ i,
+ state,
+ action,
+ command;
+ // every millisecond counts... this is executed quite often
+ for (i in commandMapping) {
+ command = commandMapping[i];
+ if (this.commandsDisabled) {
+ state = false;
+ dom.removeClass(command.link, CLASS_NAME_COMMAND_ACTIVE);
+ if (command.group) {
+ dom.removeClass(command.group, CLASS_NAME_COMMAND_ACTIVE);
+ }
+ if (command.dialog) {
+ command.dialog.hide();
+ }
+ } else {
+ state = this.composer.commands.state(command.name, command.value);
+ dom.removeClass(command.link, CLASS_NAME_COMMAND_DISABLED);
+ if (command.group) {
+ dom.removeClass(command.group, CLASS_NAME_COMMAND_DISABLED);
+ }
+ }
+ if (command.state === state) {
+ continue;
+ }
+
+ command.state = state;
+ if (state) {
+ dom.addClass(command.link, CLASS_NAME_COMMAND_ACTIVE);
+ if (command.group) {
+ dom.addClass(command.group, CLASS_NAME_COMMAND_ACTIVE);
+ }
+ if (command.dialog) {
+ if (typeof(state) === "object" || wysihtml5.lang.object(state).isArray()) {
+
+ if (!command.dialog.multiselect && wysihtml5.lang.object(state).isArray()) {
+ // Grab first and only object/element in state array, otherwise convert state into boolean
+ // to avoid showing a dialog for multiple selected elements which may have different attributes
+ // eg. when two links with different href are selected, the state will be an array consisting of both link elements
+ // but the dialog interface can only update one
+ state = state.length === 1 ? state[0] : true;
+ command.state = state;
+ }
+ command.dialog.show(state);
+ } else {
+ command.dialog.hide();
+ }
+ }
+ } else {
+ dom.removeClass(command.link, CLASS_NAME_COMMAND_ACTIVE);
+ if (command.group) {
+ dom.removeClass(command.group, CLASS_NAME_COMMAND_ACTIVE);
+ }
+ if (command.dialog) {
+ command.dialog.hide();
+ }
+ }
+ }
+
+ for (i in actionMapping) {
+ action = actionMapping[i];
+
+ if (action.name === "change_view") {
+ action.state = this.editor.currentView === this.editor.textarea;
+ if (action.state) {
+ dom.addClass(action.link, CLASS_NAME_ACTION_ACTIVE);
+ } else {
+ dom.removeClass(action.link, CLASS_NAME_ACTION_ACTIVE);
+ }
+ }
+ }
+ },
+
+ show: function() {
+ this.container.style.display = "";
+ },
+
+ hide: function() {
+ this.container.style.display = "none";
+ }
+ });
+
+})(wysihtml5);
--- /dev/null
+/**
+ * Undo Manager for wysihtml5
+ * slightly inspired by http://rniwa.com/editing/undomanager.html#the-undomanager-interface
+ */
+(function(wysihtml5) {
+ var Z_KEY = 90,
+ Y_KEY = 89,
+ BACKSPACE_KEY = 8,
+ DELETE_KEY = 46,
+ MAX_HISTORY_ENTRIES = 25,
+ DATA_ATTR_NODE = "data-wysihtml5-selection-node",
+ DATA_ATTR_OFFSET = "data-wysihtml5-selection-offset",
+ UNDO_HTML = '<span id="_wysihtml5-undo" class="_wysihtml5-temp">' + wysihtml5.INVISIBLE_SPACE + '</span>',
+ REDO_HTML = '<span id="_wysihtml5-redo" class="_wysihtml5-temp">' + wysihtml5.INVISIBLE_SPACE + '</span>',
+ dom = wysihtml5.dom;
+
+ function cleanTempElements(doc) {
+ var tempElement;
+ while (tempElement = doc.querySelector("._wysihtml5-temp")) {
+ tempElement.parentNode.removeChild(tempElement);
+ }
+ }
+
+ wysihtml5.UndoManager = wysihtml5.lang.Dispatcher.extend(
+ /** @scope wysihtml5.UndoManager.prototype */ {
+ constructor: function(editor) {
+ this.editor = editor;
+ this.composer = editor.composer;
+ this.element = this.composer.element;
+
+ this.position = 0;
+ this.historyStr = [];
+ this.historyDom = [];
+
+ this.transact();
+
+ this._observe();
+ },
+
+ _observe: function() {
+ var that = this,
+ doc = this.composer.sandbox.getDocument(),
+ lastKey;
+
+ // Catch CTRL+Z and CTRL+Y
+ dom.observe(this.element, "keydown", function(event) {
+ if (event.altKey || (!event.ctrlKey && !event.metaKey)) {
+ return;
+ }
+
+ var keyCode = event.keyCode,
+ isUndo = keyCode === Z_KEY && !event.shiftKey,
+ isRedo = (keyCode === Z_KEY && event.shiftKey) || (keyCode === Y_KEY);
+
+ if (isUndo) {
+ that.undo();
+ event.preventDefault();
+ } else if (isRedo) {
+ that.redo();
+ event.preventDefault();
+ }
+ });
+
+ // Catch delete and backspace
+ dom.observe(this.element, "keydown", function(event) {
+ var keyCode = event.keyCode;
+ if (keyCode === lastKey) {
+ return;
+ }
+
+ lastKey = keyCode;
+
+ if (keyCode === BACKSPACE_KEY || keyCode === DELETE_KEY) {
+ that.transact();
+ }
+ });
+
+ this.editor
+ .on("newword:composer", function() {
+ that.transact();
+ })
+
+ .on("beforecommand:composer", function() {
+ that.transact();
+ });
+ },
+
+ transact: function() {
+ var previousHtml = this.historyStr[this.position - 1],
+ currentHtml = this.composer.getValue(false, false),
+ composerIsVisible = this.element.offsetWidth > 0 && this.element.offsetHeight > 0,
+ range, node, offset, element, position;
+
+ if (currentHtml === previousHtml) {
+ return;
+ }
+
+ var length = this.historyStr.length = this.historyDom.length = this.position;
+ if (length > MAX_HISTORY_ENTRIES) {
+ this.historyStr.shift();
+ this.historyDom.shift();
+ this.position--;
+ }
+
+ this.position++;
+
+ if (composerIsVisible) {
+ // Do not start saving selection if composer is not visible
+ range = this.composer.selection.getRange();
+ node = (range && range.startContainer) ? range.startContainer : this.element;
+ offset = (range && range.startOffset) ? range.startOffset : 0;
+
+ if (node.nodeType === wysihtml5.ELEMENT_NODE) {
+ element = node;
+ } else {
+ element = node.parentNode;
+ position = this.getChildNodeIndex(element, node);
+ }
+
+ element.setAttribute(DATA_ATTR_OFFSET, offset);
+ if (typeof(position) !== "undefined") {
+ element.setAttribute(DATA_ATTR_NODE, position);
+ }
+ }
+
+ var clone = this.element.cloneNode(!!currentHtml);
+ this.historyDom.push(clone);
+ this.historyStr.push(currentHtml);
+
+ if (element) {
+ element.removeAttribute(DATA_ATTR_OFFSET);
+ element.removeAttribute(DATA_ATTR_NODE);
+ }
+
+ },
+
+ undo: function() {
+ this.transact();
+
+ if (!this.undoPossible()) {
+ return;
+ }
+
+ this.set(this.historyDom[--this.position - 1]);
+ this.editor.fire("undo:composer");
+ },
+
+ redo: function() {
+ if (!this.redoPossible()) {
+ return;
+ }
+
+ this.set(this.historyDom[++this.position - 1]);
+ this.editor.fire("redo:composer");
+ },
+
+ undoPossible: function() {
+ return this.position > 1;
+ },
+
+ redoPossible: function() {
+ return this.position < this.historyStr.length;
+ },
+
+ set: function(historyEntry) {
+ this.element.innerHTML = "";
+
+ var i = 0,
+ childNodes = historyEntry.childNodes,
+ length = historyEntry.childNodes.length;
+
+ for (; i<length; i++) {
+ this.element.appendChild(childNodes[i].cloneNode(true));
+ }
+
+ // Restore selection
+ var offset,
+ node,
+ position;
+
+ if (historyEntry.hasAttribute(DATA_ATTR_OFFSET)) {
+ offset = historyEntry.getAttribute(DATA_ATTR_OFFSET);
+ position = historyEntry.getAttribute(DATA_ATTR_NODE);
+ node = this.element;
+ } else {
+ node = this.element.querySelector("[" + DATA_ATTR_OFFSET + "]") || this.element;
+ offset = node.getAttribute(DATA_ATTR_OFFSET);
+ position = node.getAttribute(DATA_ATTR_NODE);
+ node.removeAttribute(DATA_ATTR_OFFSET);
+ node.removeAttribute(DATA_ATTR_NODE);
+ }
+
+ if (position !== null) {
+ node = this.getChildNodeByIndex(node, +position);
+ }
+
+ this.composer.selection.set(node, offset);
+ },
+
+ getChildNodeIndex: function(parent, child) {
+ var i = 0,
+ childNodes = parent.childNodes,
+ length = childNodes.length;
+ for (; i<length; i++) {
+ if (childNodes[i] === child) {
+ return i;
+ }
+ }
+ },
+
+ getChildNodeByIndex: function(parent, index) {
+ return parent.childNodes[index];
+ }
+ });
+})(wysihtml5);
--- /dev/null
+(function(wysihtml5) {
+ var dom = wysihtml5.dom,
+ browser = wysihtml5.browser;
+
+ wysihtml5.views.Composer = wysihtml5.views.View.extend(
+ /** @scope wysihtml5.views.Composer.prototype */ {
+ name: "composer",
+
+ // Needed for firefox in order to display a proper caret in an empty contentEditable
+ CARET_HACK: "<br>",
+
+ constructor: function(parent, editableElement, config) {
+ this.base(parent, editableElement, config);
+ if (!this.config.noTextarea) {
+ this.textarea = this.parent.textarea;
+ } else {
+ this.editableArea = editableElement;
+ }
+ if (this.config.contentEditableMode) {
+ this._initContentEditableArea();
+ } else {
+ this._initSandbox();
+ }
+ },
+
+ clear: function() {
+ this.element.innerHTML = browser.displaysCaretInEmptyContentEditableCorrectly() ? "" : this.CARET_HACK;
+ },
+
+ getValue: function(parse, clearInternals) {
+ var value = this.isEmpty() ? "" : wysihtml5.quirks.getCorrectInnerHTML(this.element);
+ if (parse !== false) {
+ value = this.parent.parse(value, (clearInternals === false) ? false : true);
+ }
+
+ return value;
+ },
+
+ setValue: function(html, parse) {
+ if (parse) {
+ html = this.parent.parse(html);
+ }
+
+ try {
+ this.element.innerHTML = html;
+ } catch (e) {
+ this.element.innerText = html;
+ }
+ },
+
+ cleanUp: function() {
+ this.parent.parse(this.element);
+ },
+
+ show: function() {
+ this.editableArea.style.display = this._displayStyle || "";
+
+ if (!this.config.noTextarea && !this.textarea.element.disabled) {
+ // Firefox needs this, otherwise contentEditable becomes uneditable
+ this.disable();
+ this.enable();
+ }
+ },
+
+ hide: function() {
+ this._displayStyle = dom.getStyle("display").from(this.editableArea);
+ if (this._displayStyle === "none") {
+ this._displayStyle = null;
+ }
+ this.editableArea.style.display = "none";
+ },
+
+ disable: function() {
+ this.parent.fire("disable:composer");
+ this.element.removeAttribute("contentEditable");
+ },
+
+ enable: function() {
+ this.parent.fire("enable:composer");
+ this.element.setAttribute("contentEditable", "true");
+ },
+
+ focus: function(setToEnd) {
+ // IE 8 fires the focus event after .focus()
+ // This is needed by our simulate_placeholder.js to work
+ // therefore we clear it ourselves this time
+ if (wysihtml5.browser.doesAsyncFocus() && this.hasPlaceholderSet()) {
+ this.clear();
+ }
+
+ this.base();
+
+ var lastChild = this.element.lastChild;
+ if (setToEnd && lastChild && this.selection) {
+ if (lastChild.nodeName === "BR") {
+ this.selection.setBefore(this.element.lastChild);
+ } else {
+ this.selection.setAfter(this.element.lastChild);
+ }
+ }
+ },
+
+ getTextContent: function() {
+ return dom.getTextContent(this.element);
+ },
+
+ hasPlaceholderSet: function() {
+ return this.getTextContent() == ((this.config.noTextarea) ? this.editableArea.getAttribute("data-placeholder") : this.textarea.element.getAttribute("placeholder")) && this.placeholderSet;
+ },
+
+ isEmpty: function() {
+ var innerHTML = this.element.innerHTML.toLowerCase();
+ return (/^(\s|<br>|<\/br>|<p>|<\/p>)*$/i).test(innerHTML) ||
+ innerHTML === "" ||
+ innerHTML === "<br>" ||
+ innerHTML === "<p></p>" ||
+ innerHTML === "<p><br></p>" ||
+ this.hasPlaceholderSet();
+ },
+
+ _initContentEditableArea: function() {
+ var that = this;
+
+ if (this.config.noTextarea) {
+ this.sandbox = new dom.ContentEditableArea(function() {
+ that._create();
+ }, {}, this.editableArea);
+ } else {
+ this.sandbox = new dom.ContentEditableArea(function() {
+ that._create();
+ });
+ this.editableArea = this.sandbox.getContentEditable();
+ dom.insert(this.editableArea).after(this.textarea.element);
+ this._createWysiwygFormField();
+ }
+ },
+
+ _initSandbox: function() {
+ var that = this;
+
+ this.sandbox = new dom.Sandbox(function() {
+ that._create();
+ }, {
+ stylesheets: this.config.stylesheets
+ });
+ this.editableArea = this.sandbox.getIframe();
+
+ var textareaElement = this.textarea.element;
+ dom.insert(this.editableArea).after(textareaElement);
+
+ this._createWysiwygFormField();
+ },
+
+ // Creates hidden field which tells the server after submit, that the user used an wysiwyg editor
+ _createWysiwygFormField: function() {
+ if (this.textarea.element.form) {
+ var hiddenField = document.createElement("input");
+ hiddenField.type = "hidden";
+ hiddenField.name = "_wysihtml5_mode";
+ hiddenField.value = 1;
+ dom.insert(hiddenField).after(this.textarea.element);
+ }
+ },
+
+ _create: function() {
+ var that = this;
+ this.doc = this.sandbox.getDocument();
+ this.element = (this.config.contentEditableMode) ? this.sandbox.getContentEditable() : this.doc.body;
+ if (!this.config.noTextarea) {
+ this.textarea = this.parent.textarea;
+ this.element.innerHTML = this.textarea.getValue(true, false);
+ } else {
+ this.cleanUp(); // cleans contenteditable on initiation as it may contain html
+ }
+
+ // Make sure our selection handler is ready
+ this.selection = new wysihtml5.Selection(this.parent, this.element, this.config.uneditableContainerClassname);
+
+ // Make sure commands dispatcher is ready
+ this.commands = new wysihtml5.Commands(this.parent);
+
+ if (!this.config.noTextarea) {
+ dom.copyAttributes([
+ "className", "spellcheck", "title", "lang", "dir", "accessKey"
+ ]).from(this.textarea.element).to(this.element);
+ }
+
+ dom.addClass(this.element, this.config.composerClassName);
+ //
+ // Make the editor look like the original textarea, by syncing styles
+ if (this.config.style && !this.config.contentEditableMode) {
+ this.style();
+ }
+
+ this.observe();
+
+ var name = this.config.name;
+ if (name) {
+ dom.addClass(this.element, name);
+ if (!this.config.contentEditableMode) { dom.addClass(this.editableArea, name); }
+ }
+
+ this.enable();
+
+ if (!this.config.noTextarea && this.textarea.element.disabled) {
+ this.disable();
+ }
+
+ // Simulate html5 placeholder attribute on contentEditable element
+ var placeholderText = typeof(this.config.placeholder) === "string"
+ ? this.config.placeholder
+ : ((this.config.noTextarea) ? this.editableArea.getAttribute("data-placeholder") : this.textarea.element.getAttribute("placeholder"));
+ if (placeholderText) {
+ dom.simulatePlaceholder(this.parent, this, placeholderText);
+ }
+
+ // Make sure that the browser avoids using inline styles whenever possible
+ this.commands.exec("styleWithCSS", false);
+
+ this._initAutoLinking();
+ this._initObjectResizing();
+ this._initUndoManager();
+ this._initLineBreaking();
+
+ // Simulate html5 autofocus on contentEditable element
+ // This doesn't work on IOS (5.1.1)
+ if (!this.config.noTextarea && (this.textarea.element.hasAttribute("autofocus") || document.querySelector(":focus") == this.textarea.element) && !browser.isIos()) {
+ setTimeout(function() { that.focus(true); }, 100);
+ }
+
+ // IE sometimes leaves a single paragraph, which can't be removed by the user
+ if (!browser.clearsContentEditableCorrectly()) {
+ wysihtml5.quirks.ensureProperClearing(this);
+ }
+
+ // Set up a sync that makes sure that textarea and editor have the same content
+ if (this.initSync && this.config.sync) {
+ this.initSync();
+ }
+
+ // Okay hide the textarea, we are ready to go
+ if (!this.config.noTextarea) { this.textarea.hide(); }
+
+ // Fire global (before-)load event
+ this.parent.fire("beforeload").fire("load");
+ },
+
+ _initAutoLinking: function() {
+ var that = this,
+ supportsDisablingOfAutoLinking = browser.canDisableAutoLinking(),
+ supportsAutoLinking = browser.doesAutoLinkingInContentEditable();
+ if (supportsDisablingOfAutoLinking) {
+ this.commands.exec("autoUrlDetect", false);
+ }
+
+ if (!this.config.autoLink) {
+ return;
+ }
+
+ // Only do the auto linking by ourselves when the browser doesn't support auto linking
+ // OR when he supports auto linking but we were able to turn it off (IE9+)
+ if (!supportsAutoLinking || (supportsAutoLinking && supportsDisablingOfAutoLinking)) {
+ this.parent.on("newword:composer", function() {
+ if (dom.getTextContent(that.element).match(dom.autoLink.URL_REG_EXP)) {
+ var nodeWithSelection = that.selection.getSelectedNode(),
+ uneditables = that.element.querySelectorAll("." + that.config.uneditableContainerClassname),
+ isInUneditable = false;
+
+ for (var i = uneditables.length; i--;) {
+ if (wysihtml5.dom.contains(uneditables[i], nodeWithSelection)) {
+ isInUneditable = true;
+ }
+ }
+
+ if (!isInUneditable) dom.autoLink(nodeWithSelection, [that.config.uneditableContainerClassname]);
+ }
+ });
+
+ dom.observe(this.element, "blur", function() {
+ dom.autoLink(that.element, [that.config.uneditableContainerClassname]);
+ });
+ }
+
+ // Assuming we have the following:
+ // <a href="http://www.google.de">http://www.google.de</a>
+ // If a user now changes the url in the innerHTML we want to make sure that
+ // it's synchronized with the href attribute (as long as the innerHTML is still a url)
+ var // Use a live NodeList to check whether there are any links in the document
+ links = this.sandbox.getDocument().getElementsByTagName("a"),
+ // The autoLink helper method reveals a reg exp to detect correct urls
+ urlRegExp = dom.autoLink.URL_REG_EXP,
+ getTextContent = function(element) {
+ var textContent = wysihtml5.lang.string(dom.getTextContent(element)).trim();
+ if (textContent.substr(0, 4) === "www.") {
+ textContent = "http://" + textContent;
+ }
+ return textContent;
+ };
+
+ dom.observe(this.element, "keydown", function(event) {
+ if (!links.length) {
+ return;
+ }
+
+ var selectedNode = that.selection.getSelectedNode(event.target.ownerDocument),
+ link = dom.getParentElement(selectedNode, { nodeName: "A" }, 4),
+ textContent;
+
+ if (!link) {
+ return;
+ }
+
+ textContent = getTextContent(link);
+ // keydown is fired before the actual content is changed
+ // therefore we set a timeout to change the href
+ setTimeout(function() {
+ var newTextContent = getTextContent(link);
+ if (newTextContent === textContent) {
+ return;
+ }
+
+ // Only set href when new href looks like a valid url
+ if (newTextContent.match(urlRegExp)) {
+ link.setAttribute("href", newTextContent);
+ }
+ }, 0);
+ });
+ },
+
+ _initObjectResizing: function() {
+ this.commands.exec("enableObjectResizing", true);
+
+ // IE sets inline styles after resizing objects
+ // The following lines make sure that the width/height css properties
+ // are copied over to the width/height attributes
+ if (browser.supportsEvent("resizeend")) {
+ var properties = ["width", "height"],
+ propertiesLength = properties.length,
+ element = this.element;
+
+ dom.observe(element, "resizeend", function(event) {
+ var target = event.target || event.srcElement,
+ style = target.style,
+ i = 0,
+ property;
+
+ if (target.nodeName !== "IMG") {
+ return;
+ }
+
+ for (; i<propertiesLength; i++) {
+ property = properties[i];
+ if (style[property]) {
+ target.setAttribute(property, parseInt(style[property], 10));
+ style[property] = "";
+ }
+ }
+
+ // After resizing IE sometimes forgets to remove the old resize handles
+ wysihtml5.quirks.redraw(element);
+ });
+ }
+ },
+
+ _initUndoManager: function() {
+ this.undoManager = new wysihtml5.UndoManager(this.parent);
+ },
+
+ _initLineBreaking: function() {
+ var that = this,
+ USE_NATIVE_LINE_BREAK_INSIDE_TAGS = ["LI", "P", "H1", "H2", "H3", "H4", "H5", "H6"],
+ LIST_TAGS = ["UL", "OL", "MENU"];
+
+ function adjust(selectedNode) {
+ var parentElement = dom.getParentElement(selectedNode, { nodeName: ["P", "DIV"] }, 2);
+ if (parentElement && dom.contains(that.element, parentElement)) {
+ that.selection.executeAndRestore(function() {
+ if (that.config.useLineBreaks) {
+ dom.replaceWithChildNodes(parentElement);
+ } else if (parentElement.nodeName !== "P") {
+ dom.renameElement(parentElement, "p");
+ }
+ });
+ }
+ }
+
+ if (!this.config.useLineBreaks) {
+ dom.observe(this.element, ["focus", "keydown"], function() {
+ if (that.isEmpty()) {
+ var paragraph = that.doc.createElement("P");
+ that.element.innerHTML = "";
+ that.element.appendChild(paragraph);
+ if (!browser.displaysCaretInEmptyContentEditableCorrectly()) {
+ paragraph.innerHTML = "<br>";
+ that.selection.setBefore(paragraph.firstChild);
+ } else {
+ that.selection.selectNode(paragraph, true);
+ }
+ }
+ });
+ }
+
+ // Under certain circumstances Chrome + Safari create nested <p> or <hX> tags after paste
+ // Inserting an invisible white space in front of it fixes the issue
+ // This is too hacky and causes selection not to replace content on paste in chrome
+ /* if (browser.createsNestedInvalidMarkupAfterPaste()) {
+ dom.observe(this.element, "paste", function(event) {
+ var invisibleSpace = that.doc.createTextNode(wysihtml5.INVISIBLE_SPACE);
+ that.selection.insertNode(invisibleSpace);
+ });
+ }*/
+
+
+ dom.observe(this.element, "keydown", function(event) {
+ var keyCode = event.keyCode;
+
+ if (event.shiftKey) {
+ return;
+ }
+
+ if (keyCode !== wysihtml5.ENTER_KEY && keyCode !== wysihtml5.BACKSPACE_KEY) {
+ return;
+ }
+ var blockElement = dom.getParentElement(that.selection.getSelectedNode(), { nodeName: USE_NATIVE_LINE_BREAK_INSIDE_TAGS }, 4);
+ if (blockElement) {
+ setTimeout(function() {
+ // Unwrap paragraph after leaving a list or a H1-6
+ var selectedNode = that.selection.getSelectedNode(),
+ list;
+
+ if (blockElement.nodeName === "LI") {
+ if (!selectedNode) {
+ return;
+ }
+
+ list = dom.getParentElement(selectedNode, { nodeName: LIST_TAGS }, 2);
+
+ if (!list) {
+ adjust(selectedNode);
+ }
+ }
+
+ if (keyCode === wysihtml5.ENTER_KEY && blockElement.nodeName.match(/^H[1-6]$/)) {
+ adjust(selectedNode);
+ }
+ }, 0);
+ return;
+ }
+
+ if (that.config.useLineBreaks && keyCode === wysihtml5.ENTER_KEY && !wysihtml5.browser.insertsLineBreaksOnReturn()) {
+ event.preventDefault();
+ that.commands.exec("insertLineBreak");
+
+ }
+ });
+ }
+ });
+})(wysihtml5);
--- /dev/null
+/**
+ * Taking care of events
+ * - Simulating 'change' event on contentEditable element
+ * - Handling drag & drop logic
+ * - Catch paste events
+ * - Dispatch proprietary newword:composer event
+ * - Keyboard shortcuts
+ */
+(function(wysihtml5) {
+ var dom = wysihtml5.dom,
+ browser = wysihtml5.browser,
+ /**
+ * Map keyCodes to query commands
+ */
+ shortcuts = {
+ "66": "bold", // B
+ "73": "italic", // I
+ "85": "underline" // U
+ };
+
+ // Adds multiple eventlisteners to target, bound to one callback
+ // TODO: If needed elsewhere make it part of wysihtml5.dom or sth
+ var addListeners = function (target, events, callback) {
+ for(var i = 0, max = events.length; i < max; i++) {
+ target.addEventListener(events[i], callback, false);
+ }
+ };
+
+ // Removes multiple eventlisteners from target, bound to one callback
+ // TODO: If needed elsewhere make it part of wysihtml5.dom or sth
+ var removeListeners = function (target, events, callback) {
+ for(var i = 0, max = events.length; i < max; i++) {
+ target.removeEventListener(events[i], callback, false);
+ }
+ };
+
+ var deleteAroundEditable = function(selection, uneditable, element) {
+ // merge node with previous node from uneditable
+ var prevNode = selection.getPreviousNode(uneditable, true),
+ curNode = selection.getSelectedNode();
+
+ if (curNode.nodeType !== 1 && curNode.parentNode !== element) { curNode = curNode.parentNode; }
+ if (prevNode) {
+ if (curNode.nodeType == 1) {
+ var first = curNode.firstChild;
+
+ if (prevNode.nodeType == 1) {
+ while (curNode.firstChild) {
+ prevNode.appendChild(curNode.firstChild);
+ }
+ } else {
+ while (curNode.firstChild) {
+ uneditable.parentNode.insertBefore(curNode.firstChild, uneditable);
+ }
+ }
+ if (curNode.parentNode) {
+ curNode.parentNode.removeChild(curNode);
+ }
+ selection.setBefore(first);
+ } else {
+ if (prevNode.nodeType == 1) {
+ prevNode.appendChild(curNode);
+ } else {
+ uneditable.parentNode.insertBefore(curNode, uneditable);
+ }
+ selection.setBefore(curNode);
+ }
+ }
+ };
+
+ var handleDeleteKeyPress = function(event, composer) {
+ var selection = composer.selection,
+ element = composer.element;
+
+ if (selection.isCollapsed()) {
+ if (selection.caretIsInTheBeginnig('LI')) {
+ event.preventDefault();
+ composer.commands.exec('outdentList');
+ } else if (selection.caretIsInTheBeginnig()) {
+ event.preventDefault();
+ } else {
+
+ if (selection.caretIsFirstInSelection() &&
+ selection.getPreviousNode() &&
+ selection.getPreviousNode().nodeName &&
+ (/^H\d$/gi).test(selection.getPreviousNode().nodeName)
+ ) {
+ var prevNode = selection.getPreviousNode();
+ event.preventDefault();
+ if ((/^\s*$/).test(prevNode.textContent || prevNode.innerText)) {
+ // heading is empty
+ prevNode.parentNode.removeChild(prevNode);
+ } else {
+ var range = prevNode.ownerDocument.createRange();
+ range.selectNodeContents(prevNode);
+ range.collapse(false);
+ selection.setSelection(range);
+ }
+ }
+
+ var beforeUneditable = selection.caretIsBeforeUneditable();
+ // Do a special delete if caret would delete uneditable
+ if (beforeUneditable) {
+ event.preventDefault();
+ // If customevents present notify element of being deleted
+ // TODO: Investigate if browser support can be extended
+ try {
+ var ev = new CustomEvent("wysihtml5:uneditable:delete");
+ beforeUneditable.dispatchEvent(ev);
+ } catch (err) {}
+ beforeUneditable.parentNode.removeChild(beforeUneditable);
+ }
+ }
+ } else {
+ if (selection.containsUneditable()) {
+ event.preventDefault();
+ selection.deleteContents();
+ }
+ }
+ };
+
+ var handleTabKeyDown = function(composer, element) {
+ if (!composer.selection.isCollapsed()) {
+ composer.selection.deleteContents();
+ } else if (composer.selection.caretIsInTheBeginnig('LI')) {
+ if (composer.commands.exec('indentList')) return;
+ }
+
+ // Is   close enough to tab. Could not find enough counter arguments for now.
+ composer.commands.exec("insertHTML", " ");
+ };
+
+ var handleDomNodeRemoved = function(event) {
+ if (this.domNodeRemovedInterval) {
+ clearInterval(domNodeRemovedInterval);
+ }
+ this.parent.fire("destroy:composer");
+ };
+
+ // Listens to "drop", "paste", "mouseup", "focus", "keyup" events and fires
+ var handleUserInteraction = function (event) {
+ this.parent.fire("beforeinteraction").fire("beforeinteraction:composer");
+ setTimeout((function() {
+ this.parent.fire("interaction").fire("interaction:composer");
+ }).bind(this), 0);
+ };
+
+ var handleFocus = function(event) {
+ this.parent.fire("focus", event).fire("focus:composer", event);
+
+ // Delay storing of state until all focus handler are fired
+ // especially the one which resets the placeholder
+ setTimeout((function() {
+ this.focusState = this.getValue(false, false);
+ }).bind(this), 0);
+ };
+
+ var handleBlur = function(event) {
+ if (this.focusState !== this.getValue(false, false)) {
+ //create change event if supported (all except IE8)
+ var changeevent = event;
+ if(typeof Object.create == 'function') {
+ changeevent = Object.create(event, { type: { value: 'change' } });
+ }
+ this.parent.fire("change", changeevent).fire("change:composer", changeevent);
+ }
+ this.parent.fire("blur", event).fire("blur:composer", event);
+ };
+
+ var handlePaste = function(event) {
+ this.parent.fire(event.type, event).fire(event.type + ":composer", event);
+ if (event.type === "paste") {
+ setTimeout((function() {
+ this.parent.fire("newword:composer");
+ }).bind(this), 0);
+ }
+ };
+
+ var handleCopy = function(event) {
+ if (this.config.copyedFromMarking) {
+ // If supported the copied source can be based directly on selection
+ // Very useful for webkit based browsers where copy will otherwise contain a lot of code and styles based on whatever and not actually in selection.
+ if (event.clipboardData) {
+ event.clipboardData.setData("text/html", this.config.copyedFromMarking + this.selection.getHtml());
+ event.clipboardData.setData("text/plain", this.selection.getPlainText());
+ event.preventDefault();
+ }
+ this.parent.fire(event.type, event).fire(event.type + ":composer", event);
+ }
+ };
+
+ var handleKeyUp = function(event) {
+ var keyCode = event.keyCode;
+ if (keyCode === wysihtml5.SPACE_KEY || keyCode === wysihtml5.ENTER_KEY) {
+ this.parent.fire("newword:composer");
+ }
+ };
+
+ var handleMouseDown = function(event) {
+ if (!browser.canSelectImagesInContentEditable()) {
+ // Make sure that images are selected when clicking on them
+ var target = event.target,
+ allImages = this.element.querySelectorAll('img'),
+ notMyImages = this.element.querySelectorAll('.' + this.config.uneditableContainerClassname + ' img'),
+ myImages = wysihtml5.lang.array(allImages).without(notMyImages);
+
+ if (target.nodeName === "IMG" && wysihtml5.lang.array(myImages).contains(target)) {
+ this.selection.selectNode(target);
+ }
+ }
+ };
+
+ // TODO: mouseover is not actually a foolproof and obvious place for this, must be changed as it modifies dom on random basis
+ // Shows url in tooltip when hovering links or images
+ var handleMouseOver = function(event) {
+ var titlePrefixes = {
+ IMG: "Image: ",
+ A: "Link: "
+ },
+ target = event.target,
+ nodeName = target.nodeName,
+ title;
+
+ if (nodeName !== "A" && nodeName !== "IMG") {
+ return;
+ }
+ if(!target.hasAttribute("title")){
+ title = titlePrefixes[nodeName] + (target.getAttribute("href") || target.getAttribute("src"));
+ target.setAttribute("title", title);
+ }
+ };
+
+ var handleClick = function(event) {
+ if (this.config.uneditableContainerClassname) {
+ // If uneditables is configured, makes clicking on uneditable move caret after clicked element (so it can be deleted like text)
+ // If uneditable needs text selection itself event.stopPropagation can be used to prevent this behaviour
+ var uneditable = wysihtml5.dom.getParentElement(event.target, { className: this.config.uneditableContainerClassname }, false, this.element);
+ if (uneditable) {
+ this.selection.setAfter(uneditable);
+ }
+ }
+ };
+
+ var handleDrop = function(event) {
+ if (!browser.canSelectImagesInContentEditable()) {
+ // TODO: if I knew how to get dropped elements list from event I could limit it to only IMG element case
+ setTimeout((function() {
+ this.selection.getSelection().removeAllRanges();
+ }).bind(this), 0);
+ }
+ };
+
+ var handleKeyDown = function(event) {
+ var keyCode = event.keyCode,
+ command = shortcuts[keyCode],
+ target, parent;
+
+ // Shortcut logic
+ if ((event.ctrlKey || event.metaKey) && !event.altKey && command) {
+ this.commands.exec(command);
+ event.preventDefault();
+ }
+
+ if (keyCode === wysihtml5.BACKSPACE_KEY) {
+ // Delete key override for special cases
+ handleDeleteKeyPress(event, this);
+ }
+
+ // Make sure that when pressing backspace/delete on selected images deletes the image and it's anchor
+ if (keyCode === wysihtml5.BACKSPACE_KEY || keyCode === wysihtml5.DELETE_KEY) {
+ target = this.selection.getSelectedNode(true);
+ if (target && target.nodeName === "IMG") {
+ event.preventDefault();
+ parent = target.parentNode;
+ parent.removeChild(target);// delete the <img>
+ // And it's parent <a> too if it hasn't got any other child nodes
+ if (parent.nodeName === "A" && !parent.firstChild) {
+ parent.parentNode.removeChild(parent);
+ }
+ setTimeout(function() {
+ wysihtml5.quirks.redraw(element);
+ }, 0);
+ }
+ }
+
+ if (this.config.handleTabKey && keyCode === wysihtml5.TAB_KEY) {
+ // TAB key handling
+ event.preventDefault();
+ handleTabKeyDown(this, element);
+ }
+
+ };
+
+ var handleIframeFocus = function(event) {
+ setTimeout((function() {
+ if (this.doc.querySelector(":focus") !== this.element) {
+ this.focus();
+ }
+ }).bind(this), 0);
+ };
+
+ var handleIframeBlur = function(event) {
+ setTimeout((function() {
+ this.selection.getSelection().removeAllRanges();
+ }).bind(this), 0);
+ };
+
+ // Table management
+ // If present enableObjectResizing and enableInlineTableEditing command should be called with false to prevent native table handlers
+ var initTableHandling = function () {
+ var hideHandlers = function () {
+ this.doc.execCommand("enableObjectResizing", false, "false");
+ this.doc.execCommand("enableInlineTableEditing", false, "false");
+ },
+ iframeInitiator = (function() {
+ hideHandlers.call(this);
+ removeListeners(this.sandbox.getIframe(), ["focus", "mouseup", "mouseover"], iframeInitiator);
+ }).bind(this);
+
+ if( this.doc.execCommand &&
+ wysihtml5.browser.supportsCommand(this.doc, "enableObjectResizing") &&
+ wysihtml5.browser.supportsCommand(this.doc, "enableInlineTableEditing"))
+ {
+ if (this.sandbox.getIframe) {
+ addListeners(this.sandbox.getIframe(), ["focus", "mouseup", "mouseover"], iframeInitiator);
+ } else {
+ setTimeout((function() {
+ hideHandlers.call(this);
+ }).bind(this), 0);
+ }
+ }
+ this.tableSelection = wysihtml5.quirks.tableCellsSelection(this.element, this.parent);
+ };
+
+ wysihtml5.views.Composer.prototype.observe = function() {
+ var that = this,
+ container = (this.sandbox.getIframe) ? this.sandbox.getIframe() : this.sandbox.getContentEditable(),
+ element = this.element,
+ focusBlurElement = (browser.supportsEventsInIframeCorrectly() || this.sandbox.getContentEditable) ? this.element : this.sandbox.getWindow();
+
+ this.focusState = this.getValue(false, false);
+
+ // --------- destroy:composer event ---------
+ container.addEventListener(["DOMNodeRemoved"], handleDomNodeRemoved.bind(this), false);
+
+ // DOMNodeRemoved event is not supported in IE 8
+ // TODO: try to figure out a polyfill style fix, so it could be transferred to polyfills and removed if ie8 is not needed
+ if (!browser.supportsMutationEvents()) {
+ this.domNodeRemovedInterval = setInterval(function() {
+ if (!dom.contains(document.documentElement, container)) {
+ handleDomNodeRemoved.call(this);
+ }
+ }, 250);
+ }
+
+ // --------- User interactions --
+ if (this.config.handleTables) {
+ // If handleTables option is true, table handling functions are bound
+ initTableHandling.call(this);
+ }
+
+ addListeners(focusBlurElement, ["drop", "paste", "mouseup", "focus", "keyup"], handleUserInteraction.bind(this));
+ focusBlurElement.addEventListener("focus", handleFocus.bind(this), false);
+ focusBlurElement.addEventListener("blur", handleBlur.bind(this), false);
+
+ addListeners(this.element, ["drop", "paste", "beforepaste"], handlePaste.bind(this), false);
+ this.element.addEventListener("copy", handleCopy.bind(this), false);
+ this.element.addEventListener("mousedown", handleMouseDown.bind(this), false);
+ this.element.addEventListener("mouseover", handleMouseOver.bind(this), false);
+ this.element.addEventListener("click", handleClick.bind(this), false);
+ this.element.addEventListener("drop", handleDrop.bind(this), false);
+ this.element.addEventListener("keyup", handleKeyUp.bind(this), false);
+ this.element.addEventListener("keydown", handleKeyDown.bind(this), false);
+
+ this.element.addEventListener("dragenter", (function() {
+ this.parent.fire("unset_placeholder");
+ }).bind(this), false);
+
+ // --------- IE 8+9 focus the editor when the iframe is clicked (without actually firing the 'focus' event on the <body>) ---------
+ if (!this.config.contentEditableMode && browser.hasIframeFocusIssue()) {
+ container.addEventListener("focus", handleIframeFocus.bind(this), false);
+ container.addEventListener("blur", handleIframeBlur.bind(this), false);
+ }
+
+ };
+})(wysihtml5);
--- /dev/null
+(function(wysihtml5) {
+ var dom = wysihtml5.dom,
+ doc = document,
+ win = window,
+ HOST_TEMPLATE = doc.createElement("div"),
+ /**
+ * Styles to copy from textarea to the composer element
+ */
+ TEXT_FORMATTING = [
+ "background-color",
+ "color", "cursor",
+ "font-family", "font-size", "font-style", "font-variant", "font-weight",
+ "line-height", "letter-spacing",
+ "text-align", "text-decoration", "text-indent", "text-rendering",
+ "word-break", "word-wrap", "word-spacing"
+ ],
+ /**
+ * Styles to copy from textarea to the iframe
+ */
+ BOX_FORMATTING = [
+ "background-color",
+ "border-collapse",
+ "border-bottom-color", "border-bottom-style", "border-bottom-width",
+ "border-left-color", "border-left-style", "border-left-width",
+ "border-right-color", "border-right-style", "border-right-width",
+ "border-top-color", "border-top-style", "border-top-width",
+ "clear", "display", "float",
+ "margin-bottom", "margin-left", "margin-right", "margin-top",
+ "outline-color", "outline-offset", "outline-width", "outline-style",
+ "padding-left", "padding-right", "padding-top", "padding-bottom",
+ "position", "top", "left", "right", "bottom", "z-index",
+ "vertical-align", "text-align",
+ "-webkit-box-sizing", "-moz-box-sizing", "-ms-box-sizing", "box-sizing",
+ "-webkit-box-shadow", "-moz-box-shadow", "-ms-box-shadow","box-shadow",
+ "-webkit-border-top-right-radius", "-moz-border-radius-topright", "border-top-right-radius",
+ "-webkit-border-bottom-right-radius", "-moz-border-radius-bottomright", "border-bottom-right-radius",
+ "-webkit-border-bottom-left-radius", "-moz-border-radius-bottomleft", "border-bottom-left-radius",
+ "-webkit-border-top-left-radius", "-moz-border-radius-topleft", "border-top-left-radius",
+ "width", "height"
+ ],
+ ADDITIONAL_CSS_RULES = [
+ "html { height: 100%; }",
+ "body { height: 100%; padding: 1px 0 0 0; margin: -1px 0 0 0; }",
+ "body > p:first-child { margin-top: 0; }",
+ "._wysihtml5-temp { display: none; }",
+ wysihtml5.browser.isGecko ?
+ "body.placeholder { color: graytext !important; }" :
+ "body.placeholder { color: #a9a9a9 !important; }",
+ // Ensure that user see's broken images and can delete them
+ "img:-moz-broken { -moz-force-broken-image-icon: 1; height: 24px; width: 24px; }"
+ ];
+
+ /**
+ * With "setActive" IE offers a smart way of focusing elements without scrolling them into view:
+ * http://msdn.microsoft.com/en-us/library/ms536738(v=vs.85).aspx
+ *
+ * Other browsers need a more hacky way: (pssst don't tell my mama)
+ * In order to prevent the element being scrolled into view when focusing it, we simply
+ * move it out of the scrollable area, focus it, and reset it's position
+ */
+ var focusWithoutScrolling = function(element) {
+ if (element.setActive) {
+ // Following line could cause a js error when the textarea is invisible
+ // See https://github.com/xing/wysihtml5/issues/9
+ try { element.setActive(); } catch(e) {}
+ } else {
+ var elementStyle = element.style,
+ originalScrollTop = doc.documentElement.scrollTop || doc.body.scrollTop,
+ originalScrollLeft = doc.documentElement.scrollLeft || doc.body.scrollLeft,
+ originalStyles = {
+ position: elementStyle.position,
+ top: elementStyle.top,
+ left: elementStyle.left,
+ WebkitUserSelect: elementStyle.WebkitUserSelect
+ };
+
+ dom.setStyles({
+ position: "absolute",
+ top: "-99999px",
+ left: "-99999px",
+ // Don't ask why but temporarily setting -webkit-user-select to none makes the whole thing performing smoother
+ WebkitUserSelect: "none"
+ }).on(element);
+
+ element.focus();
+
+ dom.setStyles(originalStyles).on(element);
+
+ if (win.scrollTo) {
+ // Some browser extensions unset this method to prevent annoyances
+ // "Better PopUp Blocker" for Chrome http://code.google.com/p/betterpopupblocker/source/browse/trunk/blockStart.js#100
+ // Issue: http://code.google.com/p/betterpopupblocker/issues/detail?id=1
+ win.scrollTo(originalScrollLeft, originalScrollTop);
+ }
+ }
+ };
+
+
+ wysihtml5.views.Composer.prototype.style = function() {
+ var that = this,
+ originalActiveElement = doc.querySelector(":focus"),
+ textareaElement = this.textarea.element,
+ hasPlaceholder = textareaElement.hasAttribute("placeholder"),
+ originalPlaceholder = hasPlaceholder && textareaElement.getAttribute("placeholder"),
+ originalDisplayValue = textareaElement.style.display,
+ originalDisabled = textareaElement.disabled,
+ displayValueForCopying;
+
+ this.focusStylesHost = HOST_TEMPLATE.cloneNode(false);
+ this.blurStylesHost = HOST_TEMPLATE.cloneNode(false);
+ this.disabledStylesHost = HOST_TEMPLATE.cloneNode(false);
+
+ // Remove placeholder before copying (as the placeholder has an affect on the computed style)
+ if (hasPlaceholder) {
+ textareaElement.removeAttribute("placeholder");
+ }
+
+ if (textareaElement === originalActiveElement) {
+ textareaElement.blur();
+ }
+
+ // enable for copying styles
+ textareaElement.disabled = false;
+
+ // set textarea to display="none" to get cascaded styles via getComputedStyle
+ textareaElement.style.display = displayValueForCopying = "none";
+
+ if ((textareaElement.getAttribute("rows") && dom.getStyle("height").from(textareaElement) === "auto") ||
+ (textareaElement.getAttribute("cols") && dom.getStyle("width").from(textareaElement) === "auto")) {
+ textareaElement.style.display = displayValueForCopying = originalDisplayValue;
+ }
+
+ // --------- iframe styles (has to be set before editor styles, otherwise IE9 sets wrong fontFamily on blurStylesHost) ---------
+ dom.copyStyles(BOX_FORMATTING).from(textareaElement).to(this.editableArea).andTo(this.blurStylesHost);
+
+ // --------- editor styles ---------
+ dom.copyStyles(TEXT_FORMATTING).from(textareaElement).to(this.element).andTo(this.blurStylesHost);
+
+ // --------- apply standard rules ---------
+ dom.insertCSS(ADDITIONAL_CSS_RULES).into(this.element.ownerDocument);
+
+ // --------- :disabled styles ---------
+ textareaElement.disabled = true;
+ dom.copyStyles(BOX_FORMATTING).from(textareaElement).to(this.disabledStylesHost);
+ dom.copyStyles(TEXT_FORMATTING).from(textareaElement).to(this.disabledStylesHost);
+ textareaElement.disabled = originalDisabled;
+
+ // --------- :focus styles ---------
+ textareaElement.style.display = originalDisplayValue;
+ focusWithoutScrolling(textareaElement);
+ textareaElement.style.display = displayValueForCopying;
+
+ dom.copyStyles(BOX_FORMATTING).from(textareaElement).to(this.focusStylesHost);
+ dom.copyStyles(TEXT_FORMATTING).from(textareaElement).to(this.focusStylesHost);
+
+ // reset textarea
+ textareaElement.style.display = originalDisplayValue;
+
+ dom.copyStyles(["display"]).from(textareaElement).to(this.editableArea);
+
+ // Make sure that we don't change the display style of the iframe when copying styles oblur/onfocus
+ // this is needed for when the change_view event is fired where the iframe is hidden and then
+ // the blur event fires and re-displays it
+ var boxFormattingStyles = wysihtml5.lang.array(BOX_FORMATTING).without(["display"]);
+
+ // --------- restore focus ---------
+ if (originalActiveElement) {
+ originalActiveElement.focus();
+ } else {
+ textareaElement.blur();
+ }
+
+ // --------- restore placeholder ---------
+ if (hasPlaceholder) {
+ textareaElement.setAttribute("placeholder", originalPlaceholder);
+ }
+
+ // --------- Sync focus/blur styles ---------
+ this.parent.on("focus:composer", function() {
+ dom.copyStyles(boxFormattingStyles) .from(that.focusStylesHost).to(that.editableArea);
+ dom.copyStyles(TEXT_FORMATTING) .from(that.focusStylesHost).to(that.element);
+ });
+
+ this.parent.on("blur:composer", function() {
+ dom.copyStyles(boxFormattingStyles) .from(that.blurStylesHost).to(that.editableArea);
+ dom.copyStyles(TEXT_FORMATTING) .from(that.blurStylesHost).to(that.element);
+ });
+
+ this.parent.observe("disable:composer", function() {
+ dom.copyStyles(boxFormattingStyles) .from(that.disabledStylesHost).to(that.editableArea);
+ dom.copyStyles(TEXT_FORMATTING) .from(that.disabledStylesHost).to(that.element);
+ });
+
+ this.parent.observe("enable:composer", function() {
+ dom.copyStyles(boxFormattingStyles) .from(that.blurStylesHost).to(that.editableArea);
+ dom.copyStyles(TEXT_FORMATTING) .from(that.blurStylesHost).to(that.element);
+ });
+
+ return this;
+ };
+})(wysihtml5);
--- /dev/null
+/**
+ * Class that takes care that the value of the composer and the textarea is always in sync
+ */
+(function(wysihtml5) {
+ var INTERVAL = 400;
+
+ wysihtml5.views.Synchronizer = Base.extend(
+ /** @scope wysihtml5.views.Synchronizer.prototype */ {
+
+ constructor: function(editor, textarea, composer) {
+ this.editor = editor;
+ this.textarea = textarea;
+ this.composer = composer;
+
+ this._observe();
+ },
+
+ /**
+ * Sync html from composer to textarea
+ * Takes care of placeholders
+ * @param {Boolean} shouldParseHtml Whether the html should be sanitized before inserting it into the textarea
+ */
+ fromComposerToTextarea: function(shouldParseHtml) {
+ this.textarea.setValue(wysihtml5.lang.string(this.composer.getValue(false, false)).trim(), shouldParseHtml);
+ },
+
+ /**
+ * Sync value of textarea to composer
+ * Takes care of placeholders
+ * @param {Boolean} shouldParseHtml Whether the html should be sanitized before inserting it into the composer
+ */
+ fromTextareaToComposer: function(shouldParseHtml) {
+ var textareaValue = this.textarea.getValue(false, false);
+ if (textareaValue) {
+ this.composer.setValue(textareaValue, shouldParseHtml);
+ } else {
+ this.composer.clear();
+ this.editor.fire("set_placeholder");
+ }
+ },
+
+ /**
+ * Invoke syncing based on view state
+ * @param {Boolean} shouldParseHtml Whether the html should be sanitized before inserting it into the composer/textarea
+ */
+ sync: function(shouldParseHtml) {
+ if (this.editor.currentView.name === "textarea") {
+ this.fromTextareaToComposer(shouldParseHtml);
+ } else {
+ this.fromComposerToTextarea(shouldParseHtml);
+ }
+ },
+
+ /**
+ * Initializes interval-based syncing
+ * also makes sure that on-submit the composer's content is synced with the textarea
+ * immediately when the form gets submitted
+ */
+ _observe: function() {
+ var interval,
+ that = this,
+ form = this.textarea.element.form,
+ startInterval = function() {
+ interval = setInterval(function() { that.fromComposerToTextarea(); }, INTERVAL);
+ },
+ stopInterval = function() {
+ clearInterval(interval);
+ interval = null;
+ };
+
+ startInterval();
+
+ if (form) {
+ // If the textarea is in a form make sure that after onreset and onsubmit the composer
+ // has the correct state
+ wysihtml5.dom.observe(form, "submit", function() {
+ that.sync(true);
+ });
+ wysihtml5.dom.observe(form, "reset", function() {
+ setTimeout(function() { that.fromTextareaToComposer(); }, 0);
+ });
+ }
+
+ this.editor.on("change_view", function(view) {
+ if (view === "composer" && !interval) {
+ that.fromTextareaToComposer(true);
+ startInterval();
+ } else if (view === "textarea") {
+ that.fromComposerToTextarea(true);
+ stopInterval();
+ }
+ });
+
+ this.editor.on("destroy:composer", stopInterval);
+ }
+ });
+})(wysihtml5);
--- /dev/null
+wysihtml5.views.Textarea = wysihtml5.views.View.extend(
+ /** @scope wysihtml5.views.Textarea.prototype */ {
+ name: "textarea",
+
+ constructor: function(parent, textareaElement, config) {
+ this.base(parent, textareaElement, config);
+
+ this._observe();
+ },
+
+ clear: function() {
+ this.element.value = "";
+ },
+
+ getValue: function(parse) {
+ var value = this.isEmpty() ? "" : this.element.value;
+ if (parse !== false) {
+ value = this.parent.parse(value);
+ }
+ return value;
+ },
+
+ setValue: function(html, parse) {
+ if (parse) {
+ html = this.parent.parse(html);
+ }
+ this.element.value = html;
+ },
+
+ cleanUp: function() {
+ var html = this.parent.parse(this.element.value);
+ this.element.value = html;
+ },
+
+ hasPlaceholderSet: function() {
+ var supportsPlaceholder = wysihtml5.browser.supportsPlaceholderAttributeOn(this.element),
+ placeholderText = this.element.getAttribute("placeholder") || null,
+ value = this.element.value,
+ isEmpty = !value;
+ return (supportsPlaceholder && isEmpty) || (value === placeholderText);
+ },
+
+ isEmpty: function() {
+ return !wysihtml5.lang.string(this.element.value).trim() || this.hasPlaceholderSet();
+ },
+
+ _observe: function() {
+ var element = this.element,
+ parent = this.parent,
+ eventMapping = {
+ focusin: "focus",
+ focusout: "blur"
+ },
+ /**
+ * Calling focus() or blur() on an element doesn't synchronously trigger the attached focus/blur events
+ * This is the case for focusin and focusout, so let's use them whenever possible, kkthxbai
+ */
+ events = wysihtml5.browser.supportsEvent("focusin") ? ["focusin", "focusout", "change"] : ["focus", "blur", "change"];
+
+ parent.on("beforeload", function() {
+ wysihtml5.dom.observe(element, events, function(event) {
+ var eventName = eventMapping[event.type] || event.type;
+ parent.fire(eventName).fire(eventName + ":textarea");
+ });
+
+ wysihtml5.dom.observe(element, ["paste", "drop"], function() {
+ setTimeout(function() { parent.fire("paste").fire("paste:textarea"); }, 0);
+ });
+ });
+ }
+});
--- /dev/null
+/**
+ * TODO: the following methods still need unit test coverage
+ */
+wysihtml5.views.View = Base.extend(
+ /** @scope wysihtml5.views.View.prototype */ {
+ constructor: function(parent, textareaElement, config) {
+ this.parent = parent;
+ this.element = textareaElement;
+ this.config = config;
+ if (!this.config.noTextarea) {
+ this._observeViewChange();
+ }
+ },
+
+ _observeViewChange: function() {
+ var that = this;
+ this.parent.on("beforeload", function() {
+ that.parent.on("change_view", function(view) {
+ if (view === that.name) {
+ that.parent.currentView = that;
+ that.show();
+ // Using tiny delay here to make sure that the placeholder is set before focusing
+ setTimeout(function() { that.focus(); }, 0);
+ } else {
+ that.hide();
+ }
+ });
+ });
+ },
+
+ focus: function() {
+ if (this.element && this.element.ownerDocument && this.element.ownerDocument.querySelector(":focus") === this.element) {
+ return;
+ }
+
+ try { if(this.element) { this.element.focus(); } } catch(e) {}
+ },
+
+ hide: function() {
+ this.element.style.display = "none";
+ },
+
+ show: function() {
+ this.element.style.display = "";
+ },
+
+ disable: function() {
+ this.element.setAttribute("disabled", "disabled");
+ },
+
+ enable: function() {
+ this.element.removeAttribute("disabled");
+ }
+});
--- /dev/null
+/**
+ * @license wysihtml5x v@VERSION
+ * https://github.com/Edicy/wysihtml5
+ *
+ * Author: Christopher Blum (https://github.com/tiff)
+ * Secondary author of extended features: Oliver Pulges (https://github.com/pulges)
+ *
+ * Copyright (C) 2012 XING AG
+ * Licensed under the MIT license (MIT)
+ *
+ */
+var wysihtml5 = {
+ version: "@VERSION",
+
+ // namespaces
+ commands: {},
+ dom: {},
+ quirks: {},
+ toolbar: {},
+ lang: {},
+ selection: {},
+ views: {},
+
+ INVISIBLE_SPACE: "\uFEFF",
+ INVISIBLE_SPACE_REG_EXP: /\uFEFF/g,
+
+ EMPTY_FUNCTION: function() {},
+
+ ELEMENT_NODE: 1,
+ TEXT_NODE: 3,
+
+ BACKSPACE_KEY: 8,
+ ENTER_KEY: 13,
+ ESCAPE_KEY: 27,
+ SPACE_KEY: 32,
+ TAB_KEY: 9,
+ DELETE_KEY: 46
+};
--- /dev/null
+module("wysihtml5.browser", {
+ userAgents: {
+ iPad_iOS3: "Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10",
+ iPhone_iOS3: "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3",
+ iPad_iOS5: "Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3",
+ Android2: "Mozilla/5.0 (Linux; U; Android 2.1; en-us; Nexus One Build/ERD62) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17",
+ Android4: "Mozilla/5.0 (Linux; U; Android 4.0.4; en-gb; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
+ Chrome: "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.44 Safari/534.7",
+ OperaMobile: "Opera/9.80 (S60; SymbOS; Opera Mobi/498; U; en-GB) Presto/2.4.18 Version/10.00",
+ IE6: "Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0) (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
+ IE7: "Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; c .NET CLR 3.0.04506; .NET CLR 3.5.30707; InfoPath.1; el-GR)",
+ IE8: "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322)",
+ IE9: "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; Media Center PC 6.0; InfoPath.3; MS-RTC LM 8; Zune 4.7)"
+ },
+
+ setup: function() {
+ this.originalUserAgent = wysihtml5.browser.USER_AGENT;
+ this.originalExecCommand = document.execCommand;
+ this.originalQuerySelector = document.querySelector;
+ this.originalQuerySelectorAll = document.querySelectorAll;
+ },
+
+ teardown: function() {
+ wysihtml5.browser.USER_AGENT = this.originalUserAgent;
+ document.execCommand = this.originalExecCommand;
+ document.querySelector = this.originalQuerySelector;
+ document.querySelectorAll = this.originalQuerySelectorAll;
+ }
+});
+
+
+test("Check mobile contentEditable support", function() {
+ document.querySelector = document.querySelectorAll = function() {};
+
+ wysihtml5.browser.USER_AGENT = this.userAgents.iPad_iOS3;
+ ok(!wysihtml5.browser.supported(), "iPad iOS 3 is correctly unsupported");
+
+ wysihtml5.browser.USER_AGENT = this.userAgents.iPhone_iOS3;
+ ok(!wysihtml5.browser.supported(), "iPhone iOS 3 is correctly unsupported");
+
+ wysihtml5.browser.USER_AGENT = this.userAgents.iPad_iOS5;
+ ok(wysihtml5.browser.supported(), "iPad iOS 5 is correctly supported");
+
+ wysihtml5.browser.USER_AGENT = this.userAgents.Android2;
+ ok(!wysihtml5.browser.supported(), "Android 2 is correctly unsupported");
+
+ wysihtml5.browser.USER_AGENT = this.userAgents.Android4;
+ ok(wysihtml5.browser.supported(), "Android 4 is correctly supported");
+
+ wysihtml5.browser.USER_AGENT = this.userAgents.OperaMobile;
+ ok(!wysihtml5.browser.supported(), "Opera Mobile is correctly unsupported");
+});
+
+
+test("Check with missing document.execCommand", function() {
+ document.execCommand = null;
+ // I've no idea why this test fails in Opera... (if you run the test alone, everything works)
+ ok(!wysihtml5.browser.supported(), "Missing document.execCommand causes editor to be unsupported");
+});
+
+
+test("Check IE support", function() {
+ wysihtml5.browser.USER_AGENT = this.userAgents.IE6;
+ document.querySelector = document.querySelectorAll = null;
+ ok(!wysihtml5.browser.supported(), "IE6 is correctly unsupported");
+
+ wysihtml5.browser.USER_AGENT = this.userAgents.IE7;
+ document.querySelector = document.querySelectorAll = null;
+ ok(!wysihtml5.browser.supported(), "IE7 is correctly unsupported");
+
+ wysihtml5.browser.USER_AGENT = this.userAgents.IE8;
+ document.querySelector = document.querySelectorAll = function() {};
+ ok(wysihtml5.browser.supported(), "IE8 is correctly supported");
+
+ wysihtml5.browser.USER_AGENT = this.userAgents.IE9;
+ document.querySelector = document.querySelectorAll = function() {};
+ ok(wysihtml5.browser.supported(), "IE9 is correctly supported");
+});
+
+
+test("Check placeholder support", function() {
+ var pseudoElement = document.createElement("div");
+ pseudoElement.placeholder = "";
+ ok(wysihtml5.browser.supportsPlaceholderAttributeOn(pseudoElement));
+});
\ No newline at end of file
--- /dev/null
+module("wysihtml5.dom.autoLink", {
+ equal: function(actual, expected, message) {
+ return QUnit.assert.htmlEqual(actual, expected, message);
+ },
+
+ autoLink: function(html) {
+ var container = wysihtml5.dom.getAsDom(html);
+ return wysihtml5.dom.autoLink(container).innerHTML;
+ }
+});
+
+
+test("Basic test", function() {
+ ok(wysihtml5.dom.autoLink.URL_REG_EXP, "URL reg exp is revealed to be access globally");
+
+ this.equal(
+ this.autoLink("hey check out this search engine http://www.google.com"),
+ "hey check out this search engine <a href=\"http://www.google.com\">http://www.google.com</a>",
+ "Urls starting with http:// are correctly linked"
+ );
+
+ this.equal(
+ this.autoLink("hey check out this search engine https://www.google.com"),
+ "hey check out this search engine <a href=\"https://www.google.com\">https://www.google.com</a>",
+ "Urls starting with https:// are correctly linked"
+ );
+
+ this.equal(
+ this.autoLink("hey check out this search engine www.google.com"),
+ "hey check out this search engine <a href=\"http://www.google.com\">www.google.com</a>",
+ "Urls starting with www. are correctly linked"
+ );
+
+ this.equal(
+ this.autoLink("hey check out this mail christopher.blum@xing.com"),
+ "hey check out this mail christopher.blum@xing.com",
+ "E-Mails are not linked"
+ );
+
+ this.equal(
+ this.autoLink("http://google.de"),
+ "<a href=\"http://google.de\">http://google.de</a>",
+ "Single url without www. but with http:// is auto linked"
+ );
+
+ this.equal(
+ this.autoLink("hey check out this search engine <a href=\"http://www.google.com\">www.google.com</a>"),
+ "hey check out this search engine <a href=\"http://www.google.com\">www.google.com</a>",
+ "Already auto-linked stuff isn't causing a relinking"
+ );
+
+ this.equal(
+ this.autoLink("hey check out this search engine <code><span>http://www.google.com</span></code>"),
+ "hey check out this search engine <code><span>http://www.google.com</span></code>",
+ "Urls inside 'code' elements are not auto linked"
+ );
+
+ this.equal(
+ this.autoLink("hey check out this search engine <pre>http://www.google.com</pre>"),
+ "hey check out this search engine <pre>http://www.google.com</pre>",
+ "Urls inside 'pre' elements are not auto linked"
+ );
+
+ this.equal(
+ this.autoLink("hey check out this search engine (http://www.google.com)"),
+ "hey check out this search engine (<a href=\"http://www.google.com\">http://www.google.com</a>)",
+ "Parenthesis around url are not part of url #1"
+ );
+
+ this.equal(
+ this.autoLink("hey check out this search engine (http://www.google.com?q=hello(spencer))"),
+ "hey check out this search engine (<a href=\"http://www.google.com?q=hello(spencer)\">http://www.google.com?q=hello(spencer)</a>)",
+ "Parenthesis around url are not part of url #2"
+ );
+
+ this.equal(
+ this.autoLink("hey check out this search engine <span>http://www.google.com?q=hello(spencer)</span>"),
+ "hey check out this search engine <span><a href=\"http://www.google.com?q=hello(spencer)\">http://www.google.com?q=hello(spencer)</a></span>",
+ "Urls in tags are correctly auto linked"
+ );
+
+ this.equal(
+ this.autoLink("http://google.de and http://yahoo.com as well as <span>http://de.finance.yahoo.com</span> <a href=\"http://google.com\" class=\"more\">http://google.com</a>"),
+ "<a href=\"http://google.de\">http://google.de</a> and <a href=\"http://yahoo.com\">http://yahoo.com</a> as well as <span><a href=\"http://de.finance.yahoo.com\">http://de.finance.yahoo.com</a></span> <a href=\"http://google.com\" class=\"more\">http://google.com</a>",
+ "Multiple urls are correctly auto linked"
+ );
+
+ this.equal(
+ this.autoLink("<script>http://google.de</script>"),
+ "<script>http://google.de</script>",
+ "Urls in SCRIPT elements are not touched"
+ );
+
+ this.equal(
+ this.autoLink("<script>http://google.de</script>"),
+ "<script>http://google.de</script>",
+ "Urls in SCRIPT elements are not touched"
+ );
+
+ this.equal(
+ this.autoLink(" http://www.google.de"),
+ " <a href=\"http://www.google.de\">http://www.google.de</a>",
+ "Check if white space in front of url is preserved"
+ );
+
+ this.equal(
+ this.autoLink("<b>foo</b> http://www.google.de"),
+ "<b>foo</b> <a href=\"http://www.google.de\">http://www.google.de</a>",
+ "Check if plain HTML markup isn't evaluated"
+ );
+});
--- /dev/null
+module("wysihtml5.dom.compareDocumentPosition", {
+ setup: function() {
+ this.container = document.createElement("div");
+ this.child1 = document.createElement("div");
+ this.child2 = document.createElement("div");
+ document.body.appendChild(this.container);
+ this.container.appendChild(this.child1);
+ this.container.appendChild(this.child2);
+ },
+
+ teardown: function() {
+ this.container.parentNode.removeChild(this.container);
+ }
+});
+
+
+test("Basic test", function() {
+ strictEqual(wysihtml5.dom.compareDocumentPosition(this.container, this.child1), 20, 'compareDocumentPosition of nested element');
+ strictEqual(wysihtml5.dom.compareDocumentPosition(this.child1, this.child2), 4, 'compareDocumentPosition of sibling element');
+ strictEqual(wysihtml5.dom.compareDocumentPosition(this.child1, this.container), 10, 'compareDocumentPosition of parent element');
+});
--- /dev/null
+module("wysihtml5.dom.contains", {
+ setup: function() {
+ this.container = document.createElement("div");
+ document.body.appendChild(this.container);
+ },
+
+ teardown: function() {
+ this.container.parentNode.removeChild(this.container);
+ }
+});
+
+
+test("Basic test", function() {
+ ok(wysihtml5.dom.contains(document.documentElement, document.body));
+ ok(wysihtml5.dom.contains(document.body, this.container));
+ ok(!wysihtml5.dom.contains(this.container, document.body));
+ ok(!wysihtml5.dom.contains(document.body, document.body));
+});
\ No newline at end of file
--- /dev/null
+module("wysihtml5.dom.convertToList", {
+ equal: function(actual, expected, message) {
+ return QUnit.assert.htmlEqual(actual, expected, message);
+ },
+
+ convertToList: function(html, type) {
+ var container = wysihtml5.dom.getAsDom(html);
+ document.body.appendChild(container);
+ wysihtml5.dom.convertToList(container.firstChild, type);
+ var innerHTML = container.innerHTML;
+ container.parentNode.removeChild(container);
+ return innerHTML;
+ }
+});
+
+test("Basic tests for UL", function() {
+ this.equal(
+ this.convertToList("<div>foo</div>", "ul"),
+ "<ul><li>foo</li></ul>"
+ );
+
+ this.equal(
+ this.convertToList("<span></span>", "ul"),
+ "<ul><li></li></ul>"
+ );
+
+ this.equal(
+ this.convertToList("<span>foo<br>bar</span>", "ul"),
+ "<ul><li>foo</li><li>bar</li></ul>"
+ );
+
+ this.equal(
+ this.convertToList("<span>foo<br>bar<div>baz</div></span>", "ul"),
+ "<ul><li>foo</li><li>bar</li><li><div>baz</div></li></ul>"
+ );
+
+ this.equal(
+ this.convertToList("<span><div></div><h1></h1><p>yeah</p></span>", "ul"),
+ "<ul><li><div></div></li><li><h1></h1></li><li><p>yeah</p></li></ul>"
+ );
+
+ this.equal(
+ this.convertToList("<span><b>foo bar<br></b><b>foo bar</b></span>", "ul"),
+ "<ul><li><b>foo bar</b></li><li><b>foo bar</b></li></ul>"
+ );
+
+ this.equal(
+ this.convertToList("<span><div>foo</div><br><div>bar</div></span>", "ul"),
+ "<ul><li><div>foo</div></li><li><div>bar</div></li></ul>"
+ );
+
+ this.equal(
+ this.convertToList("<span><div>foo<br></div><div>bar</div></span>", "ul"),
+ "<ul><li><div>foo</div></li><li><div>bar</div></li></ul>"
+ );
+});
+
+test("Basic tests for OL", function() {
+ this.equal(
+ this.convertToList("<div>foo</div>", "ol"),
+ "<ol><li>foo</li></ol>"
+ );
+
+ this.equal(
+ this.convertToList("<span></span>", "ol"),
+ "<ol><li></li></ol>"
+ );
+
+ this.equal(
+ this.convertToList("<span>foo<br>bar</span>", "ol"),
+ "<ol><li>foo</li><li>bar</li></ol>"
+ );
+
+ this.equal(
+ this.convertToList("<span>foo<br>bar<div>baz</div></span>", "ol"),
+ "<ol><li>foo</li><li>bar</li><li><div>baz</div></li></ol>"
+ );
+
+ this.equal(
+ this.convertToList("<span><div></div><h1></h1><p>yeah</p></span>", "ol"),
+ "<ol><li><div></div></li><li><h1></h1></li><li><p>yeah</p></li></ol>"
+ );
+});
+
+
+test("Test whether it doesn't convert dom trees that are already a list", function() {
+ this.equal(
+ this.convertToList("<ol><li>foo</li></ol>", "ol"),
+ "<ol><li>foo</li></ol>"
+ );
+
+ this.equal(
+ this.convertToList("<menu><li>foo</li></menu>", "ol"),
+ "<menu><li>foo</li></menu>"
+ );
+
+ this.equal(
+ this.convertToList("<ul><li>foo</li></ul>", "ol"),
+ "<ul><li>foo</li></ul>"
+ );
+});
--- /dev/null
+module("wysihtml5.dom.copyAttributes", {
+ setup: function() {
+ this.div = document.createElement("div");
+ this.span = document.createElement("span");
+ this.anotherDiv = document.createElement("div");
+ this.iframe = document.createElement("iframe");
+
+ this.iframe.src = "javascript:'<html></html>'";
+ document.body.appendChild(this.iframe);
+ },
+
+ teardown: function() {
+ this.iframe.parentNode.removeChild(this.iframe);
+ }
+});
+
+
+test("Basic Tests", function() {
+ var attributes = { title: "foobar", lang: "en", className: "foo bar" };
+ wysihtml5.dom.setAttributes(attributes).on(this.div);
+ wysihtml5.dom.copyAttributes(["title", "lang", "className"]).from(this.div).to(this.span);
+
+ equal(this.span.title, attributes.title, "Title correctly copied");
+ equal(this.span.lang, attributes.lang, "Lang correctly copied");
+ equal(this.span.className, attributes.className, "Class correctly copied");
+});
+
+
+asyncTest("Test copying attributes from one element to another element which is in an iframe", function() {
+ expect(1);
+
+ var that = this;
+
+ // Timeout needed to make sure that the iframe is ready
+ setTimeout(function() {
+ var iframeDocument = that.iframe.contentWindow.document,
+ iframeElement = iframeDocument.createElement("div");
+
+ iframeDocument.body.appendChild(iframeElement);
+ that.span.title = "heya!";
+
+ wysihtml5.dom
+ .copyAttributes(["title"])
+ .from(that.span)
+ .to(iframeElement);
+
+ equal(iframeElement.title, "heya!", "Element in iframe correctly got attributes copied over");
+
+ start();
+ }, 1000);
+});
\ No newline at end of file
--- /dev/null
+module("wysihtml5.dom.copyStyles", {
+ setup: function() {
+ this.div = document.createElement("div");
+ this.span = document.createElement("span");
+ this.anotherDiv = document.createElement("div");
+ this.iframe = document.createElement("iframe");
+
+ this.span.id = "wysihtml5-test-span";
+ this.iframe.id = "javascript:'<html></html>'";
+
+ document.body.appendChild(this.div);
+ document.body.appendChild(this.span);
+ document.body.appendChild(this.anotherDiv);
+ document.body.appendChild(this.iframe);
+ },
+
+ teardown: function() {
+ this.div.parentNode.removeChild(this.div);
+ this.span.parentNode.removeChild(this.span);
+ this.anotherDiv.parentNode.removeChild(this.anotherDiv);
+ this.iframe.parentNode.removeChild(this.iframe);
+ }
+});
+
+
+test("Basic Tests", function() {
+ this.div.style.cssText = "width: 400px; height: 200px; text-align: right; float: left;";
+
+ wysihtml5.dom.copyStyles(["width", "height", "text-align", "float"]).from(this.div).to(this.span);
+
+ equal(wysihtml5.dom.getStyle("width") .from(this.span), "400px", "Width correctly copied");
+ equal(wysihtml5.dom.getStyle("height") .from(this.span), "200px", "Height correctly copied");
+ equal(wysihtml5.dom.getStyle("text-align") .from(this.span), "right", "Text-align correctly copied");
+ equal(wysihtml5.dom.getStyle("float") .from(this.span), "left", "Float correctly copied");
+});
+
+
+test("Whether it copies native user agent styles", function() {
+ wysihtml5.dom.copyStyles(["display"]).from(this.span).to(this.div);
+
+ equal(wysihtml5.dom.getStyle("display").from(this.div), "inline", "Display correctly copied");
+});
+
+
+test("Advanced tests", function() {
+ this.span.style.cssText = "color: rgb(255, 0, 0); -moz-border-radius: 5px 5px 5px 5px;";
+ this.div.style.cssText = "color: rgb(0, 255, 0); text-decoration: underline;";
+
+ wysihtml5.dom
+ .copyStyles(["color", "-moz-border-radius", "unknown-style"])
+ .from(this.span)
+ .to(this.div)
+ .andTo(this.anotherDiv);
+
+ // Opera and IE internally convert color values either to rgb or hexcode, and some version of IE either
+ // strip or add white spaces between rgb values
+ var divColor = wysihtml5.dom.getStyle("color").from(this.div).replace(/\s+/g, "");
+ ok(divColor == "rgb(255,0,0)" || divColor == "#ff0000", "First div has correct color");
+
+ var anotherDivColor = wysihtml5.dom.getStyle("color").from(this.anotherDiv).replace(/\s+/g, "");
+ ok(anotherDivColor == "rgb(255,0,0)" || anotherDivColor == "#ff0000", "Second div has correct color");
+
+ equal(wysihtml5.dom.getStyle("text-decoration").from(this.div), "underline", "Text-decoration hasn't been overwritten");
+
+ if ("MozBorderRadius" in this.div.style) {
+ equal(wysihtml5.dom.getStyle("-moz-border-radius").from(this.div), "5px 5px 5px 5px", "First div has correct border-radius");
+ equal(wysihtml5.dom.getStyle("-moz-border-radius").from(this.anotherDiv), "5px 5px 5px 5px", "Second div has correct border-radius");
+ }
+});
+
+
+asyncTest("Test copying styles from one element to another element which is in an iframe", function() {
+ expect(1);
+
+ var that = this;
+
+ // Timeout needed to make sure that the iframe is ready
+ setTimeout(function() {
+ var iframeDocument = that.iframe.contentWindow.document,
+ iframeElement = iframeDocument.createElement("div");
+
+ iframeDocument.body.appendChild(iframeElement);
+ that.span.style.cssText = "float: left;";
+
+ wysihtml5.dom
+ .copyStyles(["float"])
+ .from(that.span)
+ .to(iframeElement);
+
+ equal(iframeElement.style.styleFloat || iframeElement.style.cssFloat, "left", "Element in iframe correctly got css float copied over");
+
+ start();
+ }, 1000);
+});
+
+
+test("Test copying styles that were set via style element", function() {
+ wysihtml5.dom
+ .insertCSS(["span#wysihtml5-test-span { font-size: 16px; }"])
+ .into(document);
+
+ wysihtml5.dom
+ .copyStyles(["font-size"])
+ .from(this.span)
+ .to(this.div);
+
+ equal(
+ wysihtml5.dom.getStyle("font-size").from(this.div), "16px", "Font-size correctly copied"
+ );
+});
\ No newline at end of file
--- /dev/null
+module("wysihtml5.dom.delegate", {
+ setup: function() {
+ this.container = document.createElement("div");
+ this.link1 = document.createElement("a");
+ this.link2 = document.createElement("a");
+ this.nestedSpan = document.createElement("span");
+
+ this.link2.appendChild(this.nestedSpan);
+ this.container.appendChild(this.link1);
+ this.container.appendChild(this.link2);
+
+ document.body.appendChild(this.container);
+ },
+
+ teardown: function() {
+ this.container.parentNode.removeChild(this.container);
+ }
+});
+
+test("Basic test", function() {
+ expect(3);
+
+ var that = this;
+
+ wysihtml5.dom.delegate(this.container, "a", "click", function(event) {
+ ok(true, "Callback handler executed");
+ equal(this, that.link1, "Callback handler executed in correct scope");
+ ok(event.stopPropagation && event.preventDefault, "Parameter passed into callback handler is a proper event object");
+ });
+
+ happen.click(this.link1);
+});
+
+test("Click on nested element works as well", function() {
+ expect(3);
+
+ var that = this;
+
+ wysihtml5.dom.delegate(this.container, "a", "click", function(event) {
+ ok(true, "Callback handler executed");
+ equal(this, that.link2, "Callback handler executed in correct scope");
+ ok(event.stopPropagation && event.preventDefault, "Parameter passed into callback handler is a proper event object");
+ });
+
+ happen.click(this.nestedSpan);
+});
+
+test("Delegation on the body", function() {
+ expect(1);
+
+ var delegater = wysihtml5.dom.delegate(document.body, ".delegation-test", "mousedown", function() {
+ ok(true, "Callback handler executed");
+ });
+
+ this.link1.className = "delegation-test another-class";
+
+ happen.mousedown(this.link1);
+
+ delegater.stop();
+
+ happen.mousedown(this.link1);
+});
--- /dev/null
+module("wysihtml5.dom.domNode", {
+ setup: function() {
+ this.container = document.createElement("div");
+ }
+});
+
+test("Simple .prev() test", function() {
+ this.container.innerHTML = "<span></span><div></div>";
+ var lastItem = this.container.querySelector("div"),
+ firstItem = this.container.querySelector("span");
+ equal(wysihtml5.dom.domNode(lastItem).prev(), firstItem);
+});
+
+test(".prev() test with textnode in between", function() {
+ this.container.innerHTML = "<span></span> confusing text node <div></div>";
+ var lastItem = this.container.querySelector("div"),
+ firstItem = this.container.querySelector("span");
+ equal(wysihtml5.dom.domNode(lastItem).prev({nodeTypes: [1]}), firstItem);
+});
+
+test(".prev() test if no prev element exists", function() {
+ this.container.innerHTML = "<div></div>";
+ var lastItem = this.container.querySelector("div");
+ equal(wysihtml5.dom.domNode(lastItem).prev(), null);
+});
+
+test(".prev() test if no prev element exists with textnode", function() {
+ this.container.innerHTML = "confusing text node <div></div>";
+ var lastItem = this.container.querySelector("div");
+ equal(wysihtml5.dom.domNode(lastItem).prev({nodeTypes: [1]}), null);
+});
+
+test(".prev() test with empty textnode in between and ignoreBlankTexts", function() {
+ this.container.innerHTML = "<span></span> <div></div>";
+ var lastItem = this.container.querySelector("div"),
+ firstItem = this.container.querySelector("span");
+ equal(wysihtml5.dom.domNode(lastItem).prev({ignoreBlankTexts: true}), firstItem);
+});
+
+test("Simple .next() test", function() {
+ this.container.innerHTML = "<div></div><span></span>";
+ var firstItem = this.container.querySelector("div"),
+ lastItem = this.container.querySelector("span");
+ equal(wysihtml5.dom.domNode(firstItem).next(), lastItem);
+});
+
+test(".next() test with textnode in between", function() {
+ this.container.innerHTML = "<div></div> confusing text node <span></span>";
+ var firstItem = this.container.querySelector("div"),
+ lastItem = this.container.querySelector("span");
+ equal(wysihtml5.dom.domNode(firstItem).next({nodeTypes: [1]}), lastItem);
+});
+
+test(".next() test if no next element exists", function() {
+ this.container.innerHTML = "<div></div>";
+ var lastItem = this.container.querySelector("div");
+ equal(wysihtml5.dom.domNode(lastItem).next(), null);
+});
+
+test(".next() test if no next element exists with textnode", function() {
+ this.container.innerHTML = "<div></div> confusing text node ";
+ var lastItem = this.container.querySelector("div");
+ equal(wysihtml5.dom.domNode(lastItem).next({nodeTypes: [1]}), null);
+});
+
+test(".next() test with empty textnode in between and ignoreBlankTexts", function() {
+ this.container.innerHTML = "<div></div> <span></span>";
+ var firstItem = this.container.querySelector("div"),
+ lastItem = this.container.querySelector("span");
+ equal(wysihtml5.dom.domNode(firstItem).next({ignoreBlankTexts: true}), lastItem);
+});
+
+test(".lastLeafNode() test for element that is last leaf itself", function () {
+ this.container.innerHTML = "";
+ equal(wysihtml5.dom.domNode(this.container).lastLeafNode(), this.container);
+});
+
+test(".lastLeafNode() test for inner elements traversing", function () {
+ var txtNode = document.createTextNode("test"),
+ elementNode = document.createElement('div'),
+ innerElementNode = document.createElement('div');
+
+ this.container.innerHTML = "";
+
+ this.container.appendChild(txtNode);
+ equal(wysihtml5.dom.domNode(this.container).lastLeafNode(), txtNode, "Found last only child textnode");
+
+ this.container.appendChild(elementNode);
+ equal(wysihtml5.dom.domNode(this.container).lastLeafNode(), elementNode, "Found last div element");
+
+ elementNode.appendChild(innerElementNode);
+ equal(wysihtml5.dom.domNode(this.container).lastLeafNode(), innerElementNode, "Found last wrapped div element");
+
+ this.container.insertBefore(elementNode, txtNode);
+ equal(wysihtml5.dom.domNode(this.container).lastLeafNode(), txtNode, "Found last textnode after reordering elements");
+});
+
+test(".lastLeafNode() test for leafClasses option", function () {
+ var elementNode = document.createElement('div'),
+ innerElementNode = document.createElement('div');
+
+ this.container.innerHTML = "";
+
+ elementNode.className = "forced-leaf";
+ elementNode.appendChild(innerElementNode);
+ this.container.appendChild(elementNode);
+
+ equal(wysihtml5.dom.domNode(this.container).lastLeafNode(), innerElementNode, "Wihout leafClasses option finds inner element node");
+ equal(wysihtml5.dom.domNode(this.container).lastLeafNode({leafClasses: ['forced-leaf']}), elementNode, "With leafClasses option, stops search and returns the element with leafClass");
+});
+
+
+
+
+
+
--- /dev/null
+module("wysihtml5.dom.getAsDom", {
+ teardown: function() {
+ var iframe;
+ while (iframe = document.querySelector("iframe.wysihtml5-sandbox")) {
+ iframe.parentNode.removeChild(iframe);
+ }
+ }
+});
+
+test("Basic test", function() {
+ var result;
+
+ result = wysihtml5.dom.getAsDom('<span id="get-in-dom-element-test">foo</span>');
+ equal(result.nodeName, "DIV");
+ equal(result.ownerDocument, document);
+ equal(result.firstChild.nodeName, "SPAN");
+ equal(result.childNodes.length , 1);
+ equal(result.firstChild.innerHTML, "foo");
+ ok(!document.getElementById("get-in-dom-element-test"));
+
+ result = wysihtml5.dom.getAsDom("<i>1</i> <b>2</b>");
+ equal(result.childNodes.length, 3);
+
+ result = wysihtml5.dom.getAsDom(document.createElement("div"));
+ equal(result.innerHTML.toLowerCase(), "<div></div>");
+});
+
+
+test("HTML5 elements", function() {
+ var result;
+
+ result = wysihtml5.dom.getAsDom("<article><span>foo</span></article>");
+ equal(result.firstChild.nodeName.toLowerCase(), "article");
+ equal(result.firstChild.innerHTML.toLowerCase(), "<span>foo</span>");
+
+ result = wysihtml5.dom.getAsDom("<output>foo</output>");
+ equal(result.innerHTML.toLowerCase(), "<output>foo</output>");
+});
+
+
+asyncTest("Different document context", function() {
+ expect(2);
+
+ new wysihtml5.dom.Sandbox(function(sandbox) {
+ var result;
+
+ result = wysihtml5.dom.getAsDom("<div>hello</div>", sandbox.getDocument());
+ equal(result.firstChild.ownerDocument, sandbox.getDocument());
+
+ result = wysihtml5.dom.getAsDom("<header>hello</header>", sandbox.getDocument());
+ equal(result.innerHTML.toLowerCase(), "<header>hello</header>");
+
+ start();
+ }).insertInto(document.body);
+});
\ No newline at end of file
--- /dev/null
+module("wysihtml5.dom.getParentElement", {
+ setup: function() {
+ this.container = document.createElement("div");
+ }
+});
+
+
+test("Basic test - nodeName only", function() {
+ this.container.innerHTML = "<ul><li>foo</li></ul>";
+
+ var listItem = this.container.querySelector("li"),
+ textNode = listItem.firstChild,
+ list = this.container.querySelector("ul");
+ equal(wysihtml5.dom.getParentElement(listItem, { nodeName: "LI" }), listItem);
+ equal(wysihtml5.dom.getParentElement(listItem, { nodeName: ["LI", "UL"] }), listItem);
+ equal(wysihtml5.dom.getParentElement(listItem, { nodeName: "UL" }), list);
+ equal(wysihtml5.dom.getParentElement(textNode, { nodeName: "UL" }), list);
+ equal(wysihtml5.dom.getParentElement(listItem, { nodeName: "ul" }), null);
+ equal(wysihtml5.dom.getParentElement(listItem, { nodeName: "SPAN" }), null);
+});
+
+
+test("Check 'levels' param - nodeName only", function() {
+ this.container.innerHTML = "<div><div><ul><li></li></ul></div></div>";
+
+ var listItem = this.container.querySelector("li"),
+ nestedDiv = this.container.querySelector("div").querySelector("div");
+ equal(wysihtml5.dom.getParentElement(listItem, { nodeName: "DIV" }, 2), null);
+ equal(wysihtml5.dom.getParentElement(listItem, { nodeName: "DIV" }, 3), nestedDiv);
+
+});
+
+
+test("Basic test - nodeName + className", function() {
+ this.container.innerHTML = '<span class="wysiwyg-color-red wysiwyg-color-green">foo</span>';
+
+ var spanElement = this.container.firstChild,
+ textNode = this.container.firstChild.firstChild,
+ result;
+
+ result = wysihtml5.dom.getParentElement(textNode, {
+ nodeName: "SPAN",
+ className: "wysiwyg-color-green",
+ classRegExp: /wysiwyg-color-[a-z]+/g
+ });
+ equal(result, spanElement);
+
+ result = wysihtml5.dom.getParentElement(textNode, {
+ nodeName: ["STRONG", "SPAN"],
+ className: "wysiwyg-color-green",
+ classRegExp: /wysiwyg-color-[a-z]+/g
+ });
+ equal(result, spanElement);
+
+ result = wysihtml5.dom.getParentElement(textNode, {
+ nodeName: ["STRONG"],
+ className: "wysiwyg-color-green",
+ classRegExp: /wysiwyg-color-[a-z]+/g
+ });
+ equal(result, null);
+
+ result = wysihtml5.dom.getParentElement(textNode, {
+ nodeName: "DIV",
+ className: "wysiwyg-color-green",
+ classRegExp: /wysiwyg-color-[a-z]+/g
+ });
+ equal(result, null);
+
+ result = wysihtml5.dom.getParentElement(textNode, {
+ nodeName: "SPAN",
+ className: "wysiwyg-color-blue",
+ classRegExp: /wysiwyg-color-[a-z]+/g
+ });
+ equal(result, null);
+
+ result = wysihtml5.dom.getParentElement(textNode, {
+ nodeName: "SPAN",
+ className: "wysiwyg-color-red",
+ classRegExp: /wysiwyg-color-[a-z]+/g
+ });
+ equal(result, null);
+
+ result = wysihtml5.dom.getParentElement(spanElement, {
+ nodeName: "SPAN",
+ className: "wysiwyg-color-green",
+ classRegExp: /wysiwyg-color-[a-z]+/g
+ });
+ equal(result, spanElement);
+
+ result = wysihtml5.dom.getParentElement(spanElement, {
+ nodeName: "span",
+ className: "wysiwyg-color-green",
+ classRegExp: /wysiwyg-color-[a-z]+/g
+ });
+ equal(result, null);
+});
+
+
+test("Check 'levels' param - nodeName + className", function() {
+ this.container.innerHTML = '<div class="wysiwyg-color-green"><div class="wysiwyg-color-green"><ul><li></li></ul></blockquote></div></div>';
+
+ var listItem = this.container.querySelector("li"),
+ nestedDiv = this.container.querySelector("div").querySelector("div"),
+ result;
+
+ result = wysihtml5.dom.getParentElement(listItem, {
+ nodeName: "DIV",
+ className: "wysiwyg-color-green",
+ classRegExp: /wysiwyg-color-[a-z]+/g
+ }, 2);
+ equal(result, null);
+
+ result = wysihtml5.dom.getParentElement(listItem, {
+ nodeName: "DIV",
+ className: "wysiwyg-color-green",
+ classRegExp: /wysiwyg-color-[a-z]+/g
+ }, 3);
+ equal(result, nestedDiv);
+});
+
+
+test("Check - no nodeName", function() {
+ this.container.innerHTML = '<div><div class="wysiwyg-text-align-right"><span>foo</span></div></div>';
+
+ var spanElement = this.container.querySelector("span"),
+ alignedDiv = this.container.querySelector("div").querySelector("div"),
+ result;
+
+ result = wysihtml5.dom.getParentElement(spanElement, {
+ className: "wysiwyg-text-align-right",
+ classRegExp: /wysiwyg-text-align-[a-z]+/g
+ });
+ equal(result, alignedDiv);
+});
+
+test("Test - with no nodeName", function() {
+ this.container.innerHTML = '<div><div class="wysiwyg-text-align-right"><span>foo</span></div></div>';
+
+ var spanElement = this.container.querySelector("span"),
+ alignedDiv = this.container.querySelector("div").querySelector("div"),
+ result;
+
+ result = wysihtml5.dom.getParentElement(spanElement, {
+ className: "wysiwyg-text-align-right",
+ classRegExp: /wysiwyg-text-align-[a-z]+/g
+ });
+ equal(result, alignedDiv);
+});
+
+test("Test - with only a classRegExp", function() {
+ this.container.innerHTML = '<div><div class="wysiwyg-text-align-right"><span>foo</span></div></div>';
+
+ var spanElement = this.container.querySelector("span"),
+ alignedDiv = this.container.querySelector("div").querySelector("div"),
+ result;
+
+ result = wysihtml5.dom.getParentElement(spanElement, {
+ classRegExp: /wysiwyg-text-align-[a-z]+/g
+ });
+ equal(result, alignedDiv);
+});
+
+test("Test - with only a className", function() {
+ this.container.innerHTML = '<div><div class="wysiwyg-text-align-right"><span>foo</span></div></div>';
+
+ var spanElement = this.container.querySelector("span"),
+ alignedDiv = this.container.querySelector("div").querySelector("div"),
+ result;
+
+ result = wysihtml5.dom.getParentElement(spanElement, {
+ className: "wysiwyg-text-align-right"
+ });
+ equal(result, alignedDiv);
+});
+
+test("Test with parent container limit", function() {
+ this.container.innerHTML = '<div><div><p><span>foo</span></p></div></div>';
+
+ var spanElement = this.container.querySelector("span"),
+ limitEl = this.container.querySelector("p"),
+ nestedDiv = this.container.querySelector("div").querySelector("div"),
+ result;
+
+ result = wysihtml5.dom.getParentElement(spanElement, {
+ nodeName: "DIV"
+ }, false, limitEl);
+
+ equal(result, null);
+});
+
--- /dev/null
+module("wysihtml5.dom.getStyle", {
+ setup: function() {
+ this.container = document.createElement("div");
+ document.body.appendChild(this.container);
+ },
+
+ teardown: function() {
+ this.container.parentNode.removeChild(this.container);
+ }
+});
+
+
+test("Basic test", function() {
+ wysihtml5.dom.insertCSS([
+ ".test-element-2 { position: absolute }"
+ ]).into(document);
+
+ this.container.innerHTML = '<span class="test-element-1" style="float:left;">hello</span>';
+ this.container.innerHTML += '<span class="test-element-2">hello</span>';
+ this.container.innerHTML += '<i></i>';
+ this.container.innerHTML += '<div></div>';
+
+ equal(
+ wysihtml5.dom.getStyle("float").from(this.container.getElementsByTagName("span")[0]),
+ "left"
+ );
+
+ equal(
+ wysihtml5.dom.getStyle("position").from(this.container.getElementsByTagName("span")[1]),
+ "absolute"
+ );
+
+ equal(
+ wysihtml5.dom.getStyle("display").from(this.container.getElementsByTagName("div")[0]),
+ "block"
+ );
+
+ equal(
+ wysihtml5.dom.getStyle("display").from(this.container.getElementsByTagName("i")[0]),
+ "inline"
+ );
+});
+
+
+test("Textarea width/height when value causes overflow", function() {
+ var textarea = document.createElement("textarea");
+ textarea.style.width = "500px";
+ textarea.style.height = "200px";
+ textarea.value = Array(500).join("Lorem ipsum dolor foo bar");
+ this.container.appendChild(textarea);
+
+ equal(wysihtml5.dom.getStyle("width") .from(textarea), "500px");
+ equal(wysihtml5.dom.getStyle("height") .from(textarea), "200px");
+});
\ No newline at end of file
--- /dev/null
+if ("querySelector" in document || wysihtml5.browser.supportsNativeGetElementsByClassName()) {
+ module("wysihtml5.dom.hasElementWithClassName", {
+ teardown: function() {
+ var iframe;
+ while (iframe = document.querySelector("iframe.wysihtml5-sandbox")) {
+ iframe.parentNode.removeChild(iframe);
+ }
+ }
+ });
+
+
+ asyncTest("Basic test", function() {
+ expect(3);
+
+ new wysihtml5.dom.Sandbox(function(sandbox) {
+ var doc = sandbox.getDocument(),
+ tempElement = doc.createElement("i");
+ tempElement.className = "wysiwyg-color-aqua";
+
+ ok(!wysihtml5.dom.hasElementWithClassName(doc, "wysiwyg-color-aqua"));
+ doc.body.appendChild(tempElement);
+ ok(wysihtml5.dom.hasElementWithClassName(doc, "wysiwyg-color-aqua"));
+ tempElement.parentNode.removeChild(tempElement);
+ ok(!wysihtml5.dom.hasElementWithClassName(doc, "wysiwyg-color-aqua"));
+
+ start();
+ }).insertInto(document.body);
+ });
+}
--- /dev/null
+module("wysihtml5.dom.hasElementWithTagName", {
+ teardown: function() {
+ var iframe;
+ while (iframe = document.querySelector("iframe.wysihtml5-sandbox")) {
+ iframe.parentNode.removeChild(iframe);
+ }
+ }
+});
+
+
+asyncTest("Basic test", function() {
+ expect(3);
+
+ new wysihtml5.dom.Sandbox(function(sandbox) {
+ var doc = sandbox.getDocument(),
+ tempElement = doc.createElement("i");
+ ok(!wysihtml5.dom.hasElementWithTagName(doc, "I"));
+ doc.body.appendChild(tempElement);
+ ok(wysihtml5.dom.hasElementWithTagName(doc, "I"));
+ tempElement.parentNode.removeChild(tempElement);
+ ok(!wysihtml5.dom.hasElementWithTagName(doc, "I"));
+
+ start();
+ }).insertInto(document.body);
+});
\ No newline at end of file
--- /dev/null
+if (wysihtml5.browser.supported()) {
+
+ module("wysihtml5.dom.insertCSS", {
+ teardown: function() {
+ var iframe;
+ while (iframe = document.querySelector("iframe.wysihtml5-sandbox")) {
+ iframe.parentNode.removeChild(iframe);
+ }
+ }
+ });
+
+ asyncTest("Basic Tests", function() {
+ expect(3);
+
+ new wysihtml5.dom.Sandbox(function(sandbox) {
+ var doc = sandbox.getDocument(),
+ body = doc.body,
+ element = doc.createElement("sub");
+
+ body.appendChild(element);
+
+ wysihtml5.dom.insertCSS([
+ "sub { display: block; text-align: right; }",
+ "body { text-indent: 50px; }"
+ ]).into(doc);
+
+ equal(wysihtml5.dom.getStyle("display") .from(element), "block");
+ equal(wysihtml5.dom.getStyle("text-align") .from(element), "right");
+ equal(wysihtml5.dom.getStyle("text-indent").from(element), "50px");
+
+ start();
+ }).insertInto(document.body);
+ });
+
+ asyncTest("Check whether CSS is inserted before any loaded stylesheets", function() {
+ expect(1);
+
+ new wysihtml5.dom.Sandbox(function(sandbox) {
+ var doc = sandbox.getDocument();
+
+ wysihtml5.dom.insertCSS([".foo {}"]).into(doc);
+
+ ok(doc.querySelector("style[type='text/css'] + link[rel=stylesheet]"), "CSS has been inserted before any included stylesheet");
+
+ start();
+ }, {
+ stylesheets: "https://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/blitzer/jquery-ui.css"
+ }).insertInto(document.body);
+ });
+
+}
\ No newline at end of file
--- /dev/null
+module("wysihtml5.dom.observe", {
+ setup: function() {
+ this.container = document.createElement("div");
+ this.element = document.createElement("textarea");
+ this.container.appendChild(this.element);
+ document.body.appendChild(this.container);
+ },
+
+ teardown: function() {
+ this.container.parentNode.removeChild(this.container);
+
+ var iframe;
+ while (iframe = document.querySelector("iframe.wysihtml5-sandbox")) {
+ iframe.parentNode.removeChild(iframe);
+ }
+ }
+});
+
+
+test("Basic test", function() {
+ expect(4);
+
+ var element = this.element;
+
+ wysihtml5.dom.observe(element, ["mouseover", "mouseout"], function(event) {
+ ok(true, "'" + event.type + "' correctly fired");
+ });
+
+ wysihtml5.dom.observe(element, "click", function(event) {
+ equal(event.target, element, "event.target or event.srcElement are set");
+ ok(true, "'click' correctly fired");
+ });
+
+ happen.once(element, {type: "mouseover"});
+ happen.once(element, {type: "mouseout"});
+ happen.once(element, {type: "click"});
+});
+
+
+test("Test stopPropagation and scope of event handler", function(event) {
+ expect(2);
+ var element = this.element;
+
+ wysihtml5.dom.observe(this.container, "click", function(event) {
+ ok(false, "The event shouldn't have been bubbled!");
+ });
+
+ wysihtml5.dom.observe(this.element, "click", function(event) {
+ event.stopPropagation();
+ equal(this, element, "Event handler bound to correct scope");
+ ok(true, "stopPropagation correctly fired");
+ });
+
+ happen.once(this.element, {type: "click"});
+});
+
+test("Test detaching events", function() {
+ expect(0);
+ var eventListener = wysihtml5.dom.observe(this.element, "click", function() {
+ ok(false, "This should not be triggered");
+ });
+
+ eventListener.stop();
+ happen.once(this.element, {type: "click"});
+});
+
+asyncTest("Advanced test observing within a sandboxed iframe", function() {
+ expect(2);
+
+ var sandbox = new wysihtml5.dom.Sandbox(function() {
+ var element = sandbox.getDocument().createElement("div");
+ sandbox.getDocument().body.appendChild(element);
+ wysihtml5.dom.observe(element, ["click", "mousedown"], function(event) {
+ ok(true, "'" + event.type + "' correctly fired");
+ });
+ happen.click(element);
+ happen.mousedown(element);
+
+ start();
+ });
+
+ sandbox.insertInto(document.body);
+});
--- /dev/null
+if (wysihtml5.browser.supported()) {
+
+ module("wysihtml5.dom.parse", {
+ sanitize: function(html, rules, context, cleanUp, uneditableClass) {
+ return wysihtml5.dom.parse(html, {
+ "rules": rules,
+ "cleanUp": cleanUp,
+ "context": context,
+ "uneditableClass": uneditableClass
+ });
+ },
+
+ equal: function(actual, expected, message) {
+ return QUnit.assert.htmlEqual(actual, expected, message);
+ }
+ });
+
+ test("Simple tests using plain tags only", function() {
+ var rules = {
+ tags: {
+ p: "div",
+ script: undefined,
+ div: {}
+ }
+ };
+
+ this.equal(
+ this.sanitize("<i id=\"foo\">bar</i>", rules),
+ "<span>bar</span>",
+ "Unknown tag gets renamed to span"
+ );
+
+ this.equal(
+ this.sanitize("<p>foo</p>", rules),
+ "<div>foo</div>",
+ "Known tag gets renamed to it's corresponding conversion"
+ );
+
+ this.equal(
+ this.sanitize("<script>window;</script>", rules),
+ "",
+ "Forbidden tag gets correctly removed"
+ );
+
+ this.equal(
+ this.sanitize("foobar", rules),
+ "foobar",
+ "Plain text is kept"
+ );
+
+ this.equal(
+ this.sanitize("<table><tbody><tr><td>I'm a table!</td></tr></tbody></table>"),
+ "<span><span><span><span>I'm a table!</span></span></span></span>",
+ "Passing no conversion renames all into <span> elements"
+ );
+
+ this.equal(
+ this.sanitize("<p>foobar<br></p>", { tags: { p: true, br: true } }),
+ "<p>foobar<br></p>",
+ "Didn't rewrite the HTML"
+ );
+
+ this.equal(
+ this.sanitize("<div><!-- COMMENT -->foo</div>"),
+ "<span>foo</span>",
+ "Stripped out comments"
+ );
+
+ this.equal(
+ this.sanitize("<article>foo</article>", { tags: { article: true } }),
+ "<article>foo</article>",
+ "Check html5 tags"
+ );
+
+ this.equal(
+ this.sanitize("<!DOCTYPE html><p>html5 doctype</p>", { tags: { p: true } }),
+ "<p>html5 doctype</p>",
+ "Stripped out doctype"
+ );
+ });
+
+
+ test("Advanced tests using tags and attributes", function() {
+ var rules = {
+ tags: {
+ img: {
+ set_attributes: { alt: "foo", border: "1" },
+ check_attributes: { src: "url", width: "numbers", height: "numbers", border: "numbers" }
+ },
+ a: {
+ rename_tag: "i",
+ set_attributes: { title: "" }
+ },
+ video: undefined,
+ h1: { rename_tag: "h2" },
+ h2: true,
+ h3: undefined
+ }
+ };
+
+ this.equal(
+ this.sanitize(
+ '<h1 id="main-headline" >take this you snorty little sanitizer</h1>' +
+ '<h2>yes, you!</h2>' +
+ '<h3>i\'m old and ready to die</h3>' +
+ '<div><video src="pr0n.avi">foobar</video><img src="http://foo.gif" height="10" width="10"><img src="/foo.gif"></div>' +
+ '<div><a href="http://www.google.de"></a></div>',
+ rules
+ ),
+ '<h2>take this you snorty little sanitizer</h2>' +
+ '<h2>yes, you!</h2>' +
+ '<span><img alt="foo" border="1" src="http://foo.gif" height="10" width="10"><img alt="foo" border="1"></span>' +
+ '<span><i title=""></i></span>'
+ );
+ });
+ test("Attribute check of 'url' cleans up", function() {
+ var rules = {
+ tags: {
+ img: {
+ check_attributes: { src: "url" }
+ }
+ }
+ };
+
+ this.equal(
+ this.sanitize(
+ '<img src="http://url.gif">' +
+ '<img src="/path/to/absolute%20href.gif">' +
+ '<img src="mango time">',
+ rules
+ ),
+ '<img src="http://url.gif"><img><img>'
+ );
+ });
+
+ test("Attribute check of 'src' cleans up", function() {
+ var rules = {
+ tags: {
+ img: {
+ check_attributes: { src: "src" }
+ }
+ }
+ };
+
+ this.equal(
+ this.sanitize(
+ '<img src="HTTP://url.gif">' +
+ '<img src="/path/to/absolute%20href.gif">' +
+ '<img src="mailto:christopher@foobar.com">' +
+ '<img src="mango time">',
+ rules
+ ),
+ '<img src="http://url.gif">' +
+ '<img src="/path/to/absolute%20href.gif">' +
+ '<img>' +
+ '<img>'
+ );
+ });
+
+ test("Attribute check of 'href' cleans up", function() {
+ var rules = {
+ tags: {
+ a: {
+ check_attributes: { href: "href" }
+ }
+ }
+ };
+
+ this.equal(
+ this.sanitize(
+ '<a href="/foobar"></a>' +
+ '<a href="HTTPS://google.com"></a>' +
+ '<a href="http://google.com"></a>' +
+ '<a href="MAILTO:christopher@foobar.com"></a>' +
+ '<a href="mango time"></a>' +
+ '<a href="ftp://google.com"></a>',
+ rules
+ ),
+ '<a href="/foobar"></a>' +
+ '<a href="https://google.com"></a>' +
+ '<a href="http://google.com"></a>' +
+ '<a href="mailto:christopher@foobar.com"></a>' +
+ '<a></a>' +
+ '<a></a>'
+ );
+ });
+
+ test("Bug in IE8 where invalid html causes duplicated content", function() {
+ var rules = {
+ tags: { p: true, span: true, div: true }
+ };
+
+ var result = this.sanitize('<SPAN><P><SPAN><div>FOO</div>', rules);
+ ok(result.indexOf("FOO") === result.lastIndexOf("FOO"));
+ });
+
+
+ test("Bug in IE8 where elements are duplicated when multiple parsed", function() {
+ var rules = {
+ tags: { p: true, span: true, div: true }
+ };
+
+ var firstResult = this.sanitize('<SPAN><P><SPAN>foo<P></P>', rules);
+ var secondResult = this.sanitize(firstResult, rules);
+
+ ok(secondResult.indexOf("foo") !== -1);
+ this.equal(firstResult, secondResult);
+
+ firstResult = this.sanitize('<SPAN><DIV><SPAN>foo<DIV></DIV>', rules);
+ secondResult = this.sanitize(firstResult, rules);
+
+ ok(secondResult.indexOf("foo") !== -1);
+ this.equal(firstResult, secondResult);
+ });
+
+ test("Test cleanup mode", function() {
+ var rules = {
+ classes: { a: 1, c: 1 },
+ tags: { span: true, div: true }
+ };
+
+ this.equal(
+ this.sanitize("<div><span>foo</span></div>", rules, null, true),
+ "<div>foo</div>"
+ );
+
+ this.equal(
+ this.sanitize("<span><p>foo</p></span>", rules, null, true),
+ "foo"
+ );
+
+ this.equal(
+ this.sanitize('<span class="a"></span><span class="a">foo</span>', rules, null, true),
+ '<span class="a">foo</span>',
+ "Empty 'span' is correctly removed"
+ );
+
+ this.equal(
+ this.sanitize('<span><span class="a">1</span> <span class="b">2</span> <span class="c">3</span></span>', rules, null, true),
+ '<span class="a">1</span> 2 <span class="c">3</span>',
+ "Senseless 'span' is correctly removed"
+ );
+ });
+
+
+ test("Advanced tests for 'img' elements", function() {
+ var rules = {
+ classes: {
+ "wysiwyg-float-right": 1,
+ "wysiwyg-float-left": 1
+ },
+ tags: {
+ img: {
+ check_attributes: {
+ width: "numbers",
+ alt: "alt",
+ src: "url",
+ height: "numbers"
+ },
+ add_class: {
+ align: "align_img"
+ }
+ }
+ }
+ };
+
+ this.equal(
+ this.sanitize(
+ '<img src="https://www.xing.com/img/users/1/2/7/f98db1f73.6149675_s4.jpg" alt="Christopher Blum" width="57" height="75" class="wysiwyg-float-right">',
+ rules
+ ),
+ '<img alt="Christopher Blum" class="wysiwyg-float-right" height="75" src="https://www.xing.com/img/users/1/2/7/f98db1f73.6149675_s4.jpg" width="57">'
+ );
+
+ this.equal(
+ this.sanitize(
+ '<img src="https://www.xing.com/img/users/1/2/7/f98db1f73.6149675_s4.jpg" alt="Christopher Blum" width="57" height="75" ALIGN="RIGHT">',
+ rules
+ ),
+ '<img alt="Christopher Blum" class="wysiwyg-float-right" height="75" src="https://www.xing.com/img/users/1/2/7/f98db1f73.6149675_s4.jpg" width="57">'
+ );
+
+ this.equal(
+ this.sanitize(
+ '<img src="https://www.xing.com/img/users/1/2/7/f98db1f73.6149675_s4.jpg" alt="Christopher Blum" width="57" height="75" align="left">',
+ rules
+ ),
+ '<img alt="Christopher Blum" class="wysiwyg-float-left" height="75" src="https://www.xing.com/img/users/1/2/7/f98db1f73.6149675_s4.jpg" width="57">'
+ );
+
+ this.equal(
+ this.sanitize(
+ '<img src="https://www.xing.com/img/users/1/2/7/f98db1f73.6149675_s4.jpg" alt="Christopher Blum" width="57" height="75" align="">',
+ rules
+ ),
+ '<img alt="Christopher Blum" height="75" src="https://www.xing.com/img/users/1/2/7/f98db1f73.6149675_s4.jpg" width="57">'
+ );
+
+ this.equal(
+ this.sanitize(
+ '<img src="/img/users/1/2/7/f98db1f73.6149675_s4.jpg" alt="Christopher Blum" width="57" height="75">',
+ rules
+ ),
+ '<img alt="Christopher Blum" height="75" width="57">'
+ );
+
+ this.equal(
+ this.sanitize(
+ '<img src="file://foobar.jpg" alt="Christopher Blum" width="57" height="75">',
+ rules
+ ),
+ '<img alt="Christopher Blum" height="75" width="57">'
+ );
+
+ this.equal(
+ this.sanitize(
+ '<img src="https://www.xing.com/img/users/1/2/7/f98db1f73.6149675_s4.jpg" width="57" height="75">',
+ rules
+ ),
+ '<img alt="" height="75" src="https://www.xing.com/img/users/1/2/7/f98db1f73.6149675_s4.jpg" width="57">'
+ );
+
+ this.equal(
+ this.sanitize(
+ '<img>',
+ rules
+ ),
+ '<img alt="">'
+ );
+ });
+
+
+ test("Advanced tests for 'br' elements", function() {
+ var rules = {
+ classes: {
+ "wysiwyg-clear-both": 1,
+ "wysiwyg-clear-left": 1,
+ "wysiwyg-clear-right": 1
+ },
+ tags: {
+ div: true,
+ br: {
+ add_class: {
+ clear: "clear_br"
+ }
+ }
+ }
+ };
+
+ this.equal(
+ this.sanitize(
+ '<div>foo<br clear="both">bar</div>',
+ rules
+ ),
+ '<div>foo<br class="wysiwyg-clear-both">bar</div>'
+ );
+
+ this.equal(
+ this.sanitize(
+ '<div>foo<br clear="all">bar</div>',
+ rules
+ ),
+ '<div>foo<br class="wysiwyg-clear-both">bar</div>'
+ );
+
+ this.equal(
+ this.sanitize(
+ '<div>foo<br clear="left" id="foo">bar</div>',
+ rules
+ ),
+ '<div>foo<br class="wysiwyg-clear-left">bar</div>'
+ );
+
+ this.equal(
+ this.sanitize(
+ '<br clear="right">',
+ rules
+ ),
+ '<br class="wysiwyg-clear-right">'
+ );
+
+ this.equal(
+ this.sanitize(
+ '<br clear="">',
+ rules
+ ),
+ '<br>'
+ );
+
+ this.equal(
+ this.sanitize(
+ '<br clear="LEFT">',
+ rules
+ ),
+ '<br class="wysiwyg-clear-left">'
+ );
+
+ this.equal(
+ this.sanitize(
+ '<br class="wysiwyg-clear-left">',
+ rules
+ ),
+ '<br class="wysiwyg-clear-left">'
+ );
+
+ this.equal(
+ this.sanitize(
+ '<br clear="left" class="wysiwyg-clear-left">',
+ rules
+ ),
+ '<br class="wysiwyg-clear-left">'
+ );
+
+ this.equal(
+ this.sanitize(
+ '<br clear="left" class="wysiwyg-clear-left wysiwyg-clear-right">',
+ rules
+ ),
+ '<br class="wysiwyg-clear-left wysiwyg-clear-right">'
+ );
+
+ this.equal(
+ this.sanitize(
+ '<br clear="left" class="wysiwyg-clear-right">',
+ rules
+ ),
+ '<br class="wysiwyg-clear-left wysiwyg-clear-right">'
+ );
+ });
+
+
+ test("Advanced tests for 'font' elements", function() {
+ var rules = {
+ classes: {
+ "wysiwyg-font-size-xx-small": 1,
+ "wysiwyg-font-size-small": 1,
+ "wysiwyg-font-size-medium": 1,
+ "wysiwyg-font-size-large": 1,
+ "wysiwyg-font-size-x-large": 1,
+ "wysiwyg-font-size-xx-large": 1,
+ "wysiwyg-font-size-smaller": 1,
+ "wysiwyg-font-size-larger": 1
+ },
+ tags: {
+ font: {
+ add_class: { size: "size_font" },
+ rename_tag: "span"
+ }
+ }
+ };
+
+ this.equal(
+ this.sanitize(
+ '<font size="1">foo</font>',
+ rules
+ ),
+ '<span class="wysiwyg-font-size-xx-small">foo</span>'
+ );
+
+ this.equal(
+ this.sanitize(
+ '<font size="2">foo</font>',
+ rules
+ ),
+ '<span class="wysiwyg-font-size-small">foo</span>'
+ );
+
+ this.equal(
+ this.sanitize(
+ '<font size="3">foo</font>',
+ rules
+ ),
+ '<span class="wysiwyg-font-size-medium">foo</span>'
+ );
+
+ this.equal(
+ this.sanitize(
+ '<font size="4">foo</font>',
+ rules
+ ),
+ '<span class="wysiwyg-font-size-large">foo</span>'
+ );
+
+ this.equal(
+ this.sanitize(
+ '<font size="5">foo</font>',
+ rules
+ ),
+ '<span class="wysiwyg-font-size-x-large">foo</span>'
+ );
+
+ this.equal(
+ this.sanitize(
+ '<font size="6">foo</font>',
+ rules
+ ),
+ '<span class="wysiwyg-font-size-xx-large">foo</span>'
+ );
+
+ this.equal(
+ this.sanitize(
+ '<font size="7">foo</font>',
+ rules
+ ),
+ '<span class="wysiwyg-font-size-xx-large">foo</span>'
+ );
+
+ this.equal(
+ this.sanitize(
+ '<font size="+1">foo</font>',
+ rules
+ ),
+ '<span class="wysiwyg-font-size-larger">foo</span>'
+ );
+
+ this.equal(
+ this.sanitize(
+ '<font size="-1">foo</font>',
+ rules
+ ),
+ '<span class="wysiwyg-font-size-smaller">foo</span>'
+ );
+ });
+
+
+ test("Check whether namespaces are handled correctly", function() {
+ var rules = {
+ tags: {
+ p: true
+ }
+ };
+
+ this.equal(
+ this.sanitize("<o:p>foo</o:p>", rules),
+ "<span>foo</span>",
+ "Unknown tag with namespace gets renamed to span"
+ );
+ });
+
+
+ test("Check whether classes are correctly treated", function() {
+ var rules = {
+ classes: {
+ a: 1,
+ c: 1
+ },
+ tags: {
+ footer: "div"
+ }
+ };
+
+ this.equal(
+ this.sanitize('<header class="a b c">foo</header>', rules),
+ '<span class="a c">foo</span>',
+ "Allowed classes 'a' and 'c' are correctly kept and unknown class 'b' is correctly removed."
+ );
+
+ this.equal(
+ this.sanitize('<footer class="ab c d" class="a">foo</footer>', rules),
+ '<div class="c">foo</div>',
+ "Allowed classes 'c' is correctly kept and unknown class 'b' is correctly removed."
+ );
+ });
+
+ test("Check mailto links", function() {
+ var rules = {
+ tags: {
+ a: {
+ check_attributes: {
+ href: "href"
+ }
+ }
+ }
+ };
+
+
+ this.equal(
+ this.sanitize('<a href="mailto:foo@bar.com">foo</a>', rules),
+ '<a href="mailto:foo@bar.com">foo</a>',
+ "'mailto:' urls are not stripped"
+ );
+ });
+
+ test("Check anchor links", function() {
+ var rules = {
+ tags: {
+ a: {
+ check_attributes: {
+ href: "href"
+ }
+ }
+ }
+ };
+
+ this.equal(
+ this.sanitize('<a href="#anchor">foo</a>', rules),
+ '<a href="#anchor">foo</a>',
+ "'#'-starting anchor urls are not stripped"
+ );
+ });
+
+ test("Check custom data attributes", function() {
+ var rules = {
+ tags: {
+ span: {
+ check_attributes: {
+ "data-max-width": "numbers"
+ }
+ }
+ }
+ };
+
+
+ this.equal(
+ this.sanitize('<span data-max-width="24px" data-min-width="25">foo</span>', rules),
+ '<span data-max-width="24">foo</span>',
+ "custom data attributes are not stripped"
+ );
+ });
+
+ test("Check Firefox misbehavior with tilde characters in urls", function() {
+ var rules = {
+ tags: {
+ a: {
+ set_attributes: {
+ target: "_blank",
+ rel: "nofollow"
+ },
+ check_attributes: {
+ href: "url"
+ }
+ }
+ }
+ };
+
+ // See https://bugzilla.mozilla.org/show_bug.cgi?id=664398
+ //
+ // In Firefox this:
+ // var d = document.createElement("div");
+ // d.innerHTML ='<a href="~"></a>';
+ // d.innerHTML;
+ // will result in:
+ // <a href="%7E"></a>
+ // which is wrong
+ ok(
+ this.sanitize('<a href="http://google.com/~foo"></a>', rules).indexOf("~") !== -1
+ );
+ });
+
+ test("Check concatenation of text nodes", function() {
+ var rules = {
+ tags: { span: 1, div: 1 }
+ };
+
+ var tree = document.createElement("div");
+ tree.appendChild(document.createTextNode("foo "));
+ tree.appendChild(document.createTextNode("bar baz "));
+ tree.appendChild(document.createTextNode("bam! "));
+
+ var span = document.createElement("span");
+ span.innerHTML = "boobs! hihihi ...";
+ tree.appendChild(span);
+
+ var result = this.sanitize(tree, rules);
+ equal(result.childNodes.length, 2);
+ equal(result.innerHTML, "foo bar baz bam! <span>boobs! hihihi ...</span>");
+ });
+
+ test("Check element unwrapping", function() {
+ var rules = {
+ tags: {
+ div: {
+ unwrap: 1
+ },
+ span: {
+ unwrap: 1
+ }
+ }
+ },
+ input = "<div>Hi,<span> there<span></span>!</span></div>",
+ output = "Hi, there!<br>";
+ this.equal(this.sanitize(input, rules), output);
+ });
+
+ test("Check spacing when unwrapping elements", function() {
+ var rules = {
+ tags: {
+ table: {
+ unwrap: 1
+ },
+ td: {
+ unwrap: 1
+ },
+ tr: {
+ unwrap: 1
+ },
+ tbody: {
+ unwrap: 1
+ },
+ ul: {
+ unwrap: 1
+ },
+ li: {
+ unwrap: 1
+ }
+ }
+ },
+ input_list = "<ul><li>This</li><li>is</li><li>a</li><li>list</li></ul>",
+ output_list = "This is a list<br>",
+ input_table = "<table><tbody><tr><td>This</td><td>is</td><td>a</td><td>table</td></tr></tbody></table>",
+ output_table = "This is a table<br>";
+
+ this.equal(this.sanitize(input_list, rules), output_list, "List unwrapping working ok");
+ this.equal(this.sanitize(input_table, rules), output_table, "Table unwrapping working ok");
+ });
+
+ test("Test valid type check by attributes", function() {
+ var rules = {
+ "type_definitions": {
+ "valid_image_src": {
+ "attrs": {
+ "src": /^[^data\:]/i
+ }
+ }
+ },
+ "tags": {
+ "img": {
+ "one_of_type": {
+ "valid_image_src": 1
+ },
+ "check_attributes": {
+ "src": "src",
+ "height": "numbers",
+ "width": "numbers",
+ "alt": "alt"
+ }
+ }
+ }
+ },
+ input = '<img src="data:image/gif;base64,R0lGODlhAQABAPAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" alt="alt" />',
+ input_valid = '<img alt="" src="http://www.asd/a.jpg">',
+ input_valid_2 = '<img src="http://reykjavik.edicy.co/photos/photo02.jpg" alt="" height="243" width="710">';
+
+ this.equal(this.sanitize(input, rules), "", "Image with data src gets removed");
+ this.equal(this.sanitize(input_valid, rules), input_valid, "Valid image is kept");
+ this.equal(this.sanitize(input_valid_2, rules), input_valid_2, "Valid image is kept2");
+ });
+
+ test("Test valid type check and remove_action", function() {
+ var rules = {
+ "type_definitions": {
+ "valid_element": {
+ "classes": {
+ "testclass": 1
+ }
+ }
+ },
+ "tags": {
+ "div": {
+ "one_of_type": {
+ "valid_element": 1
+ },
+ "check_attributes": {
+ "class": "any"
+ },
+ "remove_action": "rename",
+ "remove_action_rename_to": "span"
+ },
+ "span": {
+ "check_attributes": {
+ "class": "any"
+ }
+ }
+ }
+ },
+ input = '<div class="testclass">Test</div>',
+ input2 = '<div class="otherclass">Test</div>',
+ output2 = '<span class="otherclass">Test</span>';
+
+ this.equal(this.sanitize(input, rules), input, "Div is kept as having valid class");
+ this.equal(this.sanitize(input2, rules), output2, "Div is renamed to span when type declaration is not met");
+ });
+
+ test("Test valid type definition visible_content_object ", function() {
+ var rules = {
+ "type_definitions": {
+ "visible_content_object": {
+ "methods": {
+ "has_visible_contet": 1
+ }
+ },
+ },
+ "tags": {
+ 'div': {
+ "one_of_type": {
+ "visible_content_object": 1
+ },
+ "remove_action": "unwrap",
+ "check_attributes": {
+ "style": "any"
+ }
+ },
+ 'img': {
+ "check_attributes": {
+ "src": "any"
+ }
+ },
+ 'span': {}
+ }
+ },
+ input1 = '<div></div>',
+ input2 = '<div> <span> </span> </div>',
+ input3 = '<div><img src="pic.jpg"/></div>',
+ input4 = '<div>test</div>',
+ input5 = '<div style="width: 10px; height: 10px;"> <span> </span> </div>',
+ tester = document.createElement('div');
+
+ this.equal(this.sanitize(input1, rules), "<br>", "Empty DIV gets removed");
+ this.equal(this.sanitize(input2, rules), " <span> </span> <br>", "DIV with no textual content gets unwrapped");
+
+ this.equal(this.sanitize(input3, rules), input3, "DIV with img inside is kept");
+ this.equal(this.sanitize(input4, rules), input4, "DIV with textual content is kept");
+
+ document.body.appendChild(tester);
+
+ tester.innerHTML = input2;
+ this.equal(this.sanitize(tester, rules).innerHTML, " <span> </span> <br>", "DIV with no dimesions and in dom gets unwrapped");
+
+ tester.innerHTML = input5;
+ this.equal(this.sanitize(tester, rules).innerHTML, input5 , "DIV with dimensions and in dom is kept");
+
+ });
+
+ test("Test keeping comments ", function() {
+ var rules = {
+ "comments": 1
+ },
+ input = 'Test <!-- some comment -->';
+ this.equal(this.sanitize(input, rules), input, "Comments are kept if configured to keep");
+ });
+
+ test("Test global valid attributes for all elements ", function() {
+ var rules = {
+ "attributes": {
+ "id": "any",
+ "data-*": "any"
+ },
+ "tags": {
+ 'div': {},
+ 'span': {
+ "check_attributes": {
+ "data-*": "numbers"
+ }
+ }
+ }
+ },
+ rules2 = {
+ "attributes": {
+ "id": "any",
+ "data-*": "any"
+ },
+ "tags": {
+ 'div': {}
+ }
+ },
+ input1 = '<div id="test">Test</div>',
+ input2 = '<div class="test">Test</div>',
+ output2 = '<div>Test</div>',
+ input3 = '<div data-name="test" data-value="test">Test</div>',
+ input4 = '<span data-name="test" data-value="1234">Test</span>',
+ output4 = '<span data-value="1234">Test</span>';
+
+ this.equal(this.sanitize(input1, rules), input1, "Global attribute allows id for all elements and div is allowewd tag and kept");
+ this.equal(this.sanitize(input1, rules2), input1, "Global attribute allows id for all elements and div is allowewd tag and kept even if no check_attributes");
+ this.equal(this.sanitize(input2, rules), output2, "Div is kept but attribute 'class' is not allowed locally and globally, so it is removed.");
+ this.equal(this.sanitize(input3, rules), input3, "Global eattribute configuration allows all attributes beginning with 'data-'.");
+ this.equal(this.sanitize(input4, rules), output4, "Local check_attributes overwrites global attributes");
+
+ });
+
+ test("Test classes blacklist ", function() {
+ var rules = {
+ "classes": "any",
+ "classes_blacklist": {
+ "Apple-interchange-newline": 1
+ },
+ "tags": {
+ 'span': {
+ }
+ }
+ },
+ input1 = '<span class="Apple-interchange-newline">Test</span',
+ output1 = '<span>Test</span>',
+ input2 = '<span class="SomeClass">Test</span>',
+ input3 = '<span class="SomeClass Apple-interchange-newline">Test</span>';
+
+ this.equal(this.sanitize(input1, rules), output1, "Blacklist class removed");
+ this.equal(this.sanitize(input2, rules), input2, "Other class kept");
+ this.equal(this.sanitize(input3, rules), input2, "Other class kept, but blacklisted class removed");
+
+
+ });
+}
--- /dev/null
+module("wysihtml5.dom.renameElement", {
+ equal: function(actual, expected, message) {
+ return QUnit.assert.htmlEqual(actual, expected, message);
+ },
+
+ renameElement: function(html, newNodeName) {
+ var container = wysihtml5.dom.getAsDom(html);
+ wysihtml5.dom.renameElement(container.firstChild, newNodeName);
+ return container.innerHTML;
+ }
+});
+
+test("Basic tests", function() {
+ this.equal(
+ this.renameElement("<p>foo</p>", "div"),
+ "<div>foo</div>"
+ );
+
+ this.equal(
+ this.renameElement("<ul><li>foo</li></ul>", "ol"),
+ "<ol><li>foo</li></ol>"
+ );
+
+ this.equal(
+ this.renameElement('<p align="left" class="foo"></p>', "h2"),
+ '<h2 align="left" class="foo"></h2>'
+ );
+});
--- /dev/null
+module("wysihtml5.dom.resolveList", {
+ equal: function(actual, expected, message) {
+ return QUnit.assert.htmlEqual(actual, expected, message);
+ },
+
+ resolveList: function(html, useLineBreaks) {
+ var container = wysihtml5.dom.getAsDom(html);
+ document.body.appendChild(container);
+ wysihtml5.dom.resolveList(container.firstChild, useLineBreaks);
+ var innerHTML = container.innerHTML;
+ container.parentNode.removeChild(container);
+ return innerHTML;
+ }
+});
+
+test("Basic tests (useLineBreaks = true)", function() {
+ this.equal(
+ this.resolveList("<ul><li>foo</li></ul>", true),
+ "foo<br>"
+ );
+
+ this.equal(
+ this.resolveList("<ul><li>foo</li><li>bar</li></ul>", true),
+ "foo<br>bar<br>"
+ );
+
+ this.equal(
+ this.resolveList("<ol><li>foo</li><li>bar</li></ol>", true),
+ "foo<br>bar<br>"
+ );
+
+ this.equal(
+ this.resolveList("<ol><li></li><li>bar</li></ol>", true),
+ "bar<br>"
+ );
+
+ this.equal(
+ this.resolveList("<ol><li>foo<br></li><li>bar</li></ol>", true),
+ "foo<br>bar<br>"
+ );
+
+ this.equal(
+ this.resolveList("<ul><li><h1>foo</h1></li><li><div>bar</div></li><li>baz</li></ul>", true),
+ "<h1>foo</h1><div>bar</div>baz<br>"
+ );
+});
+
+test("Basic tests (useLineBreaks = false)", function() {
+ this.equal(
+ this.resolveList("<ul><li>foo</li></ul>"),
+ "<p>foo</p>"
+ );
+
+ this.equal(
+ this.resolveList("<ul><li>foo</li><li>bar</li></ul>"),
+ "<p>foo</p><p>bar</p>"
+ );
+
+ this.equal(
+ this.resolveList("<ol><li>foo</li><li>bar</li></ol>"),
+ "<p>foo</p><p>bar</p>"
+ );
+
+ this.equal(
+ this.resolveList("<ol><li></li><li>bar</li></ol>"),
+ "<p></p><p>bar</p>"
+ );
+
+ this.equal(
+ this.resolveList("<ol><li>foo<br></li><li>bar</li></ol>"),
+ "<p>foo<br></p><p>bar</p>"
+ );
+
+ this.equal(
+ this.resolveList("<ul><li><h1>foo</h1></li><li><div>bar</div></li><li>baz</li></ul>"),
+ "<h1>foo</h1><div>bar</div><p>baz</p>"
+ );
+});
--- /dev/null
+module("wysihtml5.dom.Sandbox", {
+ teardown: function() {
+ var iframe;
+ while (iframe = document.querySelector("iframe.wysihtml5-sandbox")) {
+ iframe.parentNode.removeChild(iframe);
+ }
+ },
+
+ getCharset: function(doc) {
+ var charset = doc.characterSet || doc.charset;
+ if (/unicode|utf-8/.test(charset)) {
+ return "utf-8";
+ }
+ return charset;
+ },
+
+ eval: function(iframeWindow, code) {
+ try {
+ return iframeWindow.execScript ? iframeWindow.execScript(code) : iframeWindow.eval(code);
+ } catch(e) {
+ return null;
+ }
+ },
+
+ isUnset: function(evalCode, iframeWindow) {
+ var value = this.eval(iframeWindow, evalCode);
+ return !value || value == wysihtml5.EMPTY_FUNCTION;
+ }
+});
+
+
+asyncTest("Basic Test", function() {
+ expect(8);
+
+ var sandbox = new wysihtml5.dom.Sandbox(function(param) {
+ equal(param, sandbox, "The parameter passed into the readyCallback is the sandbox instance");
+
+ var iframes = document.querySelectorAll("iframe.wysihtml5-sandbox");
+ equal(iframes.length, 1, "iFrame sandbox inserted into dom tree");
+
+ var iframe = iframes[iframes.length - 1],
+ isIframeInvisible = iframe.width == 0 && iframe.height == 0 && iframe.frameBorder == 0;
+ ok(isIframeInvisible, "iframe is not visible");
+
+ var isSandboxed = iframe.getAttribute("security") == "restricted";
+ ok(isSandboxed, "iFrame is sandboxed");
+
+ var isWindowObject = sandbox.getWindow().setInterval && sandbox.getWindow().clearInterval;
+ ok(isWindowObject, "wysihtml5.Sandbox.prototype.getWindow() works properly");
+
+ var isDocumentObject = sandbox.getDocument().appendChild && sandbox.getDocument().body;
+ ok(isDocumentObject, "wysihtml5.Sandbox.prototype.getDocument() works properly");
+
+ equal(sandbox.getIframe(), iframe, "wysihtml5.Sandbox.prototype.getIframe() returns the iframe correctly");
+ equal(typeof(sandbox.getWindow().onerror), "function", "window.onerror is set");
+
+ start();
+ });
+
+ sandbox.insertInto(document.body);
+});
+
+
+asyncTest("Security test #1", function() {
+ expect(14);
+
+ var that = this;
+
+ var sandbox = new wysihtml5.dom.Sandbox(function() {
+ var iframeWindow = sandbox.getWindow();
+
+ var isSafari = wysihtml5.browser.USER_AGENT.indexOf("Safari") !== -1 && wysihtml5.browser.USER_AGENT.indexOf("Chrome") === 1;
+
+ if (isSafari) {
+ // This test fails in Safari 5, as it's impossible to unset a cookie there
+ ok(true, "Cookie is NOT unset (but that's expected in Safari)");
+ } else {
+ ok(that.isUnset("document.cookie", iframeWindow), "Cookie is unset");
+ }
+
+ ok(that.isUnset("document.open", iframeWindow), "document.open is unset");
+ ok(that.isUnset("document.write", iframeWindow), "document.write is unset");
+ ok(that.isUnset("window.parent", iframeWindow), "window.parent is unset");
+ ok(that.isUnset("window.opener", iframeWindow), "window.opener is unset");
+ ok(that.isUnset("window.localStorage", iframeWindow), "localStorage is unset");
+ ok(that.isUnset("window.globalStorage", iframeWindow), "globalStorage is unset");
+ ok(that.isUnset("window.XMLHttpRequest", iframeWindow), "XMLHttpRequest is an empty function");
+ ok(that.isUnset("window.XDomainRequest", iframeWindow), "XDomainRequest is an empty function");
+ ok(that.isUnset("window.alert", iframeWindow), "alert is an empty function");
+ ok(that.isUnset("window.prompt", iframeWindow), "prompt is an empty function");
+ ok(that.isUnset("window.openDatabase", iframeWindow), "window.openDatabase is unset");
+ ok(that.isUnset("window.indexedDB", iframeWindow), "window.indexedDB is unset");
+ ok(that.isUnset("window.postMessage", iframeWindow), "window.openDatabase is unset");
+
+ start();
+ });
+
+ sandbox.insertInto(document.body);
+});
+
+
+asyncTest("Security test #2", function() {
+ expect(2);
+
+ var sandbox = new wysihtml5.dom.Sandbox(function() {
+ var html = '<img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" onerror="#{script}" onload="try { window.parent._hackedCookie=document.cookie; } catch(e){}; try { window.parent._hackedVariable=1; } catch(e) {}">';
+ sandbox.getDocument().body.innerHTML = html;
+
+ setTimeout(function() {
+ equal(window._hackedCookie || "", "", "Cookie can't be easily stolen");
+ equal(window._hackedVariable || 0, 0, "iFrame has no access to parent");
+
+ start();
+ }, 2000);
+ });
+
+ sandbox.insertInto(document.body);
+});
+
+
+asyncTest("Check charset & doctype", function() {
+ expect(3);
+
+ var that = this;
+
+ var sandbox = new wysihtml5.dom.Sandbox(function() {
+ var iframeDocument = sandbox.getDocument(),
+ isQuirksMode = iframeDocument.compatMode == "BackCompat";
+
+ ok(!isQuirksMode, "iFrame isn't in quirks mode");
+ equal(that.getCharset(iframeDocument), that.getCharset(document), "Charset correctly inherited by iframe");
+
+ iframeDocument.body.innerHTML = '<meta charset="iso-8859-1">ü';
+
+ setTimeout(function() {
+ equal(that.getCharset(iframeDocument), that.getCharset(document), "Charset isn't overwritten");
+ start();
+ }, 500);
+ });
+
+ sandbox.insertInto(document.body);
+});
+
+
+asyncTest("Check insertion of single stylesheet", function() {
+ expect(1);
+
+ new wysihtml5.dom.Sandbox(function(sandbox) {
+ var doc = sandbox.getDocument();
+ equal(doc.getElementsByTagName("link").length, 1, "Correct amount of stylesheets inserted into the dom tree");
+ start();
+ }, {
+ stylesheets: "https://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/blitzer/jquery-ui.css"
+ }).insertInto(document.body);
+});
+
+
+asyncTest("Check insertion of multiple stylesheets", function() {
+ expect(1);
+
+ new wysihtml5.dom.Sandbox(function(sandbox) {
+ var doc = sandbox.getDocument();
+ equal(doc.getElementsByTagName("link").length, 2, "Correct amount of stylesheets inserted into the dom tree");
+ start();
+ }, {
+ stylesheets: [
+ "https://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/blitzer/jquery-ui.css",
+ "https://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/excite-bike/jquery-ui.css"
+ ]
+ }).insertInto(document.body);
+});
+
+
+asyncTest("Check X-UA-Compatible", function() {
+ expect(1);
+
+ new wysihtml5.dom.Sandbox(function(sandbox) {
+ var doc = sandbox.getDocument(),
+ docMode = doc.documentMode;
+
+ ok(doc.documentMode === document.documentMode, "iFrame is in in the same document mode as the parent site");
+ start();
+ }).insertInto(document.body);
+});
\ No newline at end of file
--- /dev/null
+module("wysihtml5.dom.setAttributes", {
+ setup: function() {
+ this.element = document.createElement("div");
+ }
+});
+
+test("Basic test", function() {
+ wysihtml5.dom.setAttributes({
+ id: "foo",
+ "class": "bar"
+ }).on(this.element);
+
+ equal(this.element.id, "foo");
+ equal(this.element.className, "bar");
+});
\ No newline at end of file
--- /dev/null
+module("wysihtml5.dom.setStyles", {
+ setup: function() {
+ this.element = document.createElement("div");
+ document.body.appendChild(this.element);
+ },
+
+ teardown: function() {
+ this.element.parentNode.removeChild(this.element);
+ }
+});
+
+test("Basic test", function() {
+ wysihtml5.dom.setStyles("text-align: right; float: left").on(this.element);
+ equal(wysihtml5.dom.getStyle("text-align").from(this.element), "right");
+ equal(wysihtml5.dom.getStyle("float").from(this.element), "left");
+
+ wysihtml5.dom.setStyles({ "float": "right" }).on(this.element);
+ equal(wysihtml5.dom.getStyle("float").from(this.element), "right");
+});
\ No newline at end of file
--- /dev/null
+module("wysihtml5.dom.table", {
+ setup: function() {
+ var row, cell;
+
+ this.wrapper = document.createElement("div");
+ this.wrapper.innerHTML = '<table id="my-table">\
+ <tr>\
+ <td></td><td></td><td></td><td></td>\
+ </tr>\
+ <tr>\
+ <td></td><td></td><td></td><td></td>\
+ </tr>\
+ <tr>\
+ <td></td><td></td><td></td><td></td>\
+ </tr>\
+ <tr>\
+ <td></td><td></td><td></td><td></td>\
+ </tr>\
+ </table>';
+ document.body.appendChild(this.wrapper);
+ this.table = document.getElementById('my-table');
+ },
+
+ teardown: function() {
+ this.wrapper.parentNode.removeChild(this.wrapper);
+ },
+
+ getTable: function() {
+ return this.table;
+ }
+});
+
+test("getCellsBetween", function() {
+ var cells = this.getTable().querySelectorAll('td'),
+ cellFirst = cells[0],
+ cellLast = cells[cells.length - 1],
+ secondCell = cells[1],
+ beforeLastCell = cells[cells.length - 2],
+ secondRowFirstCell = cells[4],
+ between = wysihtml5.dom.table.getCellsBetween(cellFirst, cellLast);
+
+ equal(between.length, 4*4, "All 16 cells are in list of selection from first to last cell");
+ equal(between[0], cellFirst, "First cell of selection in list and first");
+ equal(between[between.length - 1], cellLast, "Last cell of selection in list and last");
+
+ var inList1 = false;
+ var inList2 = false;
+ var inList3 = false;
+ for (var i = 0, imax = between.length; i < imax; i++) {
+ if (between[i] == secondRowFirstCell) {
+ inList1 = true;
+ }
+ if (between[i] == cellFirst) {
+ inList2 = true;
+ }
+ if (between[i] == cellLast) {
+ inList3 = true;
+ }
+ }
+ ok(inList1 && inList2 && inList3, "First, last and second row first cell are in list");
+
+ between = wysihtml5.dom.table.getCellsBetween(secondCell, beforeLastCell);
+ equal(between.length, 2*4, "List is 8 cells long if selections is moved from second cell to before last (first and last column not selected)");
+
+ var notInList = true;
+ for (var j = 0, jmax = between.length; j < jmax; j++) {
+ if (between[j] == secondRowFirstCell || between[j] == cellFirst || between[j] == cellLast) {
+ notInList = false;
+ }
+ }
+ ok(notInList, "First, last and second row first cell are not in list anymore");
+
+ between = wysihtml5.dom.table.getCellsBetween(secondCell, secondCell);
+ equal(between.length, 1, "List collapses to one cell if start and end cell are the same");
+ equal(between[0], secondCell, "The element in list is correct");
+});
+
+test("addCells (above/below)", function() {
+ var cells = this.getTable().querySelectorAll('td'),
+ rows = this.getTable().querySelectorAll('tr'),
+ cellFirst = cells[0],
+ cellLast = cells[cells.length - 1],
+ startRowsNr = rows.length;
+
+ wysihtml5.dom.table.addCells(cellLast,"below");
+ equal(this.getTable().querySelectorAll('tr').length, startRowsNr + 1, "One row added successfully to table location below");
+
+ var newrows = this.getTable().querySelectorAll('tr'),
+ bottomSecondRowCells = newrows[newrows.length - 2].querySelectorAll('td'),
+ lasCellOfBSrow = bottomSecondRowCells[bottomSecondRowCells.length - 1];
+
+ equal(lasCellOfBSrow, cellLast, "Row added correctly below cell and original DOM object is intact");
+
+ wysihtml5.dom.table.addCells(cellLast,"below");
+ equal(this.getTable().querySelectorAll('tr').length, startRowsNr + 2, "One row added successfully to table location belown (last to second row)");
+ equal(this.getTable().querySelectorAll('td')[15], cellLast, "Row added correctly below cell and original DOM object is intact");
+
+ wysihtml5.dom.table.addCells(cellFirst,"above");
+ equal(this.getTable().querySelectorAll('tr').length, startRowsNr + 3, "One row added successfully to table location above");
+ equal(this.getTable().querySelectorAll('td')[4], cellFirst, "Row added correctly above cell and original DOM object is intact");
+
+ wysihtml5.dom.table.addCells(cellFirst,"above");
+ equal(this.getTable().querySelectorAll('tr').length, startRowsNr + 4, "One row added successfully to table location above (on second row)");
+ equal(this.getTable().querySelectorAll('td')[8], cellFirst, "Row added correctly above cell and original DOM object is intact");
+});
+
+test("addCells (before/after)", function() {
+ var cells = this.getTable().querySelectorAll('td'),
+ nr_rows = this.getTable().querySelectorAll('tr').length,
+ cellFirst = cells[0],
+ cellLast = cells[cells.length - 1];
+
+ wysihtml5.dom.table.addCells(cellFirst, "before");
+ equal(this.getTable().querySelectorAll('td').length, cells.length + (1 * nr_rows), "One column added successfully to table location before");
+ equal(this.getTable().querySelectorAll('td')[1], cellFirst, "Row added correctly before cell and original DOM object is intact");
+
+ wysihtml5.dom.table.addCells(cellFirst, "before");
+ equal(this.getTable().querySelectorAll('td').length, cells.length + (2 * nr_rows), "One column added successfully to table location before (on second column)");
+ equal(this.getTable().querySelectorAll('td')[2], cellFirst, "Row added correctly before cell and original DOM object is intact");
+
+ wysihtml5.dom.table.addCells(cellLast, "after");
+ equal(this.getTable().querySelectorAll('td').length, cells.length + (3 * nr_rows), "One column added successfully to table location after");
+ equal(this.getTable().querySelectorAll('td')[this.getTable().querySelectorAll('td').length - 2], cellLast, "Row added correctly after cell and original DOM object is intact");
+
+ wysihtml5.dom.table.addCells(cellLast, "after");
+ equal(this.getTable().querySelectorAll('td').length, cells.length + (4 * nr_rows), "One column added successfully to table location after (on last to second column)");
+ equal(this.getTable().querySelectorAll('td')[this.getTable().querySelectorAll('td').length - 3], cellLast, "Row added correctly after cell and original DOM object is intact");
+});
+
+
+
+test("merge/unmerge", function() {
+ var cells = this.getTable().querySelectorAll('td'),
+ nr_cells = cells.length,
+ txt1 = document.createTextNode('Cell'),
+ txt2 = document.createTextNode('texts'),
+ txt3 = document.createTextNode('merged');
+
+ cells[0].appendChild(txt1);
+ cells[1].appendChild(txt2);
+ cells[5].appendChild(txt3);
+
+ // merge
+ equal(wysihtml5.dom.table.canMerge(cells[0], cells[9]), true , "canMerge returns true correctly for unmerged selection");
+
+ wysihtml5.dom.table.mergeCellsBetween(cells[0], cells[9]);
+ equal(this.getTable().querySelectorAll('td').length, nr_cells - 5, "Top left corner (6 cells) correctly merged");
+ equal(this.getTable().querySelectorAll('td')[0].getAttribute('colspan'), 2, "Colspan attribute added correctly");
+ equal(this.getTable().querySelectorAll('td')[0].getAttribute('rowspan'), 3, "Rowspan attribute added correctly");
+
+ equal(this.getTable().querySelectorAll('td')[0].innerHTML.replace(/\s\s+/g, ' ').replace(/\s+$/g, ''), "Cell texts merged" , "cell texts correctly merged");
+
+ var cells_m1 = this.getTable().querySelectorAll('td');
+
+ equal(wysihtml5.dom.table.canMerge(cells_m1[0], cells_m1[1]), false , "canMerge returns false correctly for selection containing merged cells");
+
+ wysihtml5.dom.table.mergeCellsBetween(cells_m1[cells_m1.length - 6], cells_m1[cells_m1.length - 1]);
+ equal(this.getTable().querySelectorAll('td').length, nr_cells - 8, "Bottom right corner (4 cells) correctly merged");
+
+ var cells_m2 = this.getTable().querySelectorAll('td');
+ equal(cells_m2[cells_m2.length -3].getAttribute('colspan'), 2, "Colspan attribute added correctly (Bottom right corner)");
+ equal(cells_m2[cells_m2.length -3].getAttribute('rowspan'), 2, "Rowspan attribute added correctly (Bottom right corner)");
+
+ var nr_cells_m2 = cells_m2.length;
+
+ // should not merge
+ wysihtml5.dom.table.mergeCellsBetween(cells_m2[0], cells_m2[cells_m2.length - 1]);
+ equal(this.getTable().querySelectorAll('td').length, nr_cells_m2, "Correctly refuses to merge allready merged cells");
+
+ // unmerge
+ var umerge_cell1 = cells_m2[cells_m2.length -3];
+
+ equal(umerge_cell1.getAttribute('colspan'), 2, "Colspan attribute is set before unmerge (Bottom right corner)");
+ equal(umerge_cell1.getAttribute('rowspan'), 2, "Rowspan attribute is set before unmerge (Bottom right corner)");
+
+ wysihtml5.dom.table.unmergeCell(umerge_cell1);
+ equal(this.getTable().querySelectorAll('td').length, nr_cells - 5, "Bottom right corner (4 cells) correctly unmerged");
+
+ var cells_m3 = this.getTable().querySelectorAll('td');
+ equal(cells_m3[cells_m3.length - 6], umerge_cell1, "Unmerged cell is intact and not removed from DOM");
+ equal(umerge_cell1.getAttribute('colspan'), null, "Colspan attribute removed correctly (Bottom right corner)");
+ equal(umerge_cell1.getAttribute('rowspan'), null, "Rowspan attribute removed correctly (Bottom right corner)");
+
+ equal(cells_m3[0].getAttribute('colspan') , 2, "Colspan of top right corner is untouched");
+ equal(cells_m3[0].getAttribute('rowspan'), 3, "Rowspan of top right corner is untouched");
+
+ wysihtml5.dom.table.unmergeCell(cells_m3[0]);
+
+ equal(this.getTable().querySelectorAll('td').length, nr_cells, "Top right unmerged correctly, table is back at start layout");
+
+ equal(this.getTable().querySelectorAll('td')[0].getAttribute('colspan') , null, "Colspan removed (Top Left)");
+ equal(this.getTable().querySelectorAll('td')[0].getAttribute('rowspan'), null, "Rowspan removed (Top Left)");
+
+ equal(this.getTable().querySelectorAll('td')[0].innerHTML.replace(/\s\s+/g, ' ').replace(/\s+$/g, ''), "Cell texts merged" , "cell texts correctly in first cell");
+});
+
+test("removeCells", function() {
+ var cells = this.getTable().querySelectorAll('td'),
+ nr_rows = this.getTable().querySelectorAll('tr').length,
+ nr_cols = this.getTable().querySelectorAll('tr')[0].querySelectorAll('td').length;
+
+ wysihtml5.dom.table.removeCells(cells[1], "column");
+ equal(this.getTable().querySelectorAll('tr')[0].querySelectorAll('td').length, nr_cols - 1, "One column removed successfully");
+ equal(this.getTable().querySelectorAll('tr').length, nr_rows, "Rows untouched");
+
+ wysihtml5.dom.table.removeCells(this.getTable().querySelectorAll('td')[4], "row");
+
+ equal(this.getTable().querySelectorAll('tr')[0].querySelectorAll('td').length, nr_cols - 1, "Columns untouched");
+ equal(this.getTable().querySelectorAll('tr').length, nr_rows -1, "One row removed successfully");
+
+ var cells1 = this.getTable().querySelectorAll('td');
+
+ wysihtml5.dom.table.mergeCellsBetween(cells1[0], cells1[4]);
+ equal(this.getTable().querySelectorAll('td')[0].getAttribute('rowspan'), 2, "One cell merged for testing, rowspan 2");
+ equal(this.getTable().querySelectorAll('td')[0].getAttribute('colspan'), 2, "One cell merged for testing, colspan 2");
+
+ wysihtml5.dom.table.removeCells(this.getTable().querySelectorAll('tr')[1].querySelectorAll('td')[0], "row");
+ equal(this.getTable().querySelectorAll('td')[0].getAttribute('rowspan'), null, "Meged cell rowspan removed correlctly");
+ equal(this.getTable().querySelectorAll('td')[0].getAttribute('colspan'), 2, "Colspan remained correct");
+
+
+ equal(this.getTable().querySelectorAll('tr')[1].querySelectorAll('td').length, nr_cols - 1, "Nr of columns correct");
+ equal(this.getTable().querySelectorAll('tr').length, nr_rows -2, "Nr of rows correct");
+
+ wysihtml5.dom.table.removeCells(this.getTable().querySelectorAll('td')[3], "column");
+
+ equal(this.getTable().querySelectorAll('tr')[0].querySelectorAll('td').length, nr_cols - 2, "Nr of columns correct afrer merged column removed");
+
+ equal(this.getTable().querySelectorAll('td')[0].getAttribute('colspan'), null, "Meged cell colspan removed correlctly");
+
+ wysihtml5.dom.table.removeCells(this.getTable().querySelectorAll('td')[0], "column");
+ wysihtml5.dom.table.removeCells(this.getTable().querySelectorAll('td')[0], "row");
+ wysihtml5.dom.table.removeCells(this.getTable().querySelectorAll('td')[0], "column");
+
+ equal(this.getTable().parentNode, null, "Table remove table from dom when last cell removed");
+
+});
+
+test("orderSelectionEnds", function() {
+ var cells = this.getTable().querySelectorAll('td'),
+ cellFirst = cells[0],
+ cellLast = cells[cells.length - 1];
+
+ var ends = wysihtml5.dom.table.orderSelectionEnds(cellLast, cellFirst);
+
+ ok(ends.end == cellLast && ends.start == cellFirst, "Given cells ordered correctly");
+});
+
+test("indexOf/findCell", function() {
+ wysihtml5.dom.table.mergeCellsBetween(this.getTable().querySelectorAll('td')[1], this.getTable().querySelectorAll('td')[6]);
+ var cell = this.getTable().querySelectorAll('td')[4],
+ idx = wysihtml5.dom.table.indexOf(cell);
+
+ ok(idx.row == 1 && idx.col == 3, "Index gets position correctly in table with merged cell");
+
+ equal(wysihtml5.dom.table.findCell(this.getTable(), idx), cell, "Cell element got correctly by index");
+});
+
--- /dev/null
+module("wysihtml5.dom.unwrap", {
+ setup: function() {
+ this.inner = "<span>test</span><p>tes2</p>";
+ this.container = document.createElement("div");
+ this.containerInner = document.createElement("div");
+ this.containerInner.innerHTML = this.inner;
+ this.container.appendChild(this.containerInner);
+ }
+});
+
+test("Basic test", function() {
+ wysihtml5.dom.unwrap(this.containerInner);
+ equal(this.container.innerHTML, this.inner, "Unwrapping element works splendid.");
+});
--- /dev/null
+if (wysihtml5.browser.supported()) {
+ module("wysihtml5.Editor.commands", {
+ setup: function() {
+
+ this.editableArea1 = document.createElement("div");
+ this.editableArea1.id = "wysihtml5-test-editable1";
+ this.editableArea1.className = "wysihtml5-test-class1";
+ this.editableArea1.title = "Please enter your foo";
+ this.editableArea1.innerHTML = "hey tiff, what's up?";
+
+ document.body.appendChild(this.editableArea1);
+
+ },
+
+ setCaretInsideNode: function(editor, el) {
+ var r1 = editor.composer.selection.createRange(),
+ e1 = el.childNodes[0];
+ r1.setEnd(e1, 1);
+ r1.setStart(e1, 1);
+ editor.composer.selection.setSelection(r1);
+ },
+
+ teardown: function() {
+ var leftover;
+ this.editableArea1.parentNode.removeChild(this.editableArea1);
+ while (leftover = document.querySelector("div.wysihtml5-test-class1, iframe.wysihtml5-sandbox, div.wysihtml5-sandbox")) {
+ leftover.parentNode.removeChild(leftover);
+ }
+ document.body.className = this.originalBodyClassName;
+ },
+
+ equal: function(actual, expected, message) {
+ return QUnit.assert.htmlEqual(actual, expected, message);
+ },
+ });
+
+
+// bold, italic, underline
+ asyncTest("Basic formating tests", function() {
+ expect(18);
+ var that = this,
+ text = "once upon a time there was an unformated text.",
+ parserRules = {
+ tags: {
+ b: true,
+ i: true,
+ u: true
+ }
+ },
+ editor = new wysihtml5.Editor(this.editableArea1, {
+ parserRules: parserRules
+ });
+
+ editor.on("load", function() {
+ var editableElement = that.editableArea1;
+ // basic bold
+ editor.setValue(text, true);
+ editor.composer.selection.selectNode(editor.editableElement);
+ editor.composer.commands.exec('bold');
+ equal(editableElement.innerHTML.toLowerCase(), "<b>" + text + "</b>", "Command bold sets text as bold correctly");
+
+ editor.composer.selection.getSelection().collapseToEnd();
+
+ ok(editor.composer.selection.getSelection().isCollapsed, "Text caret is collapsed");
+
+ editor.composer.commands.exec('bold');
+ editor.composer.selection.getSelection().collapseToEnd();
+ editor.composer.commands.exec('insertHtml', 'test');
+ ok(editor.composer.selection.getSelection().isCollapsed, "Text caret did remain collapsed");
+ equal(editableElement.innerHTML.toLowerCase().replace(/\uFEFF/g, ''), "<b>" + text + "</b>test", "With caret at last position bold is not removed but set to notbold at caret");
+
+
+ that.setCaretInsideNode(editor, editableElement.querySelector('b'));
+ editor.composer.commands.exec('bold');
+
+ equal(editableElement.innerHTML.toLowerCase().replace(/\uFEFF/g, ''), text + "test", "Bold is correctly removed when text caret is inside bold");
+ ok(editor.composer.selection.getSelection().isCollapsed, "Text caret did remain collapsed");
+
+ // basic italic
+ editor.setValue(text, true);
+ editor.composer.selection.selectNode(editor.editableElement);
+ editor.composer.commands.exec('italic');
+ equal(editableElement.innerHTML.toLowerCase(), "<i>" + text + "</i>", "Command italic sets text as italic correctly");
+
+ editor.composer.selection.getSelection().collapseToEnd();
+ ok(editor.composer.selection.getSelection().isCollapsed, "Text caret is collapsed");
+
+ editor.composer.commands.exec('italic');
+ editor.composer.selection.getSelection().collapseToEnd();
+ editor.composer.commands.exec('insertHtml', 'test');
+
+ equal(editableElement.innerHTML.toLowerCase().replace(/\uFEFF/g, ''), "<i>" + text + "</i>test", "With caret at last position italic is not removed but set to notitalic at caret");
+ ok(editor.composer.selection.getSelection().isCollapsed, "Text caret did remain collapsed");
+
+ that.setCaretInsideNode(editor, editableElement.querySelector('i'));
+ editor.composer.commands.exec('italic');
+
+ equal(editableElement.innerHTML.toLowerCase().replace(/\uFEFF/g, ''), text + "test", "Italic is correctly removed when text caret is inside italic");
+ ok(editor.composer.selection.getSelection().isCollapsed, "Text caret did remain collapsed");
+
+ // basic underline
+ editor.setValue(text, true);
+ editor.composer.selection.selectNode(editor.editableElement);
+ editor.composer.commands.exec('underline');
+ equal(editableElement.innerHTML.toLowerCase().replace(/\uFEFF/g, ''), "<u>" + text + "</u>", "Command underline sets text as underline correctly");
+
+ editor.composer.selection.getSelection().collapseToEnd();
+ ok(editor.composer.selection.getSelection().isCollapsed, "Text caret is collapsed");
+
+ editor.composer.commands.exec('underline');
+ editor.composer.selection.getSelection().collapseToEnd();
+ editor.composer.commands.exec('insertHtml', 'test');
+
+ equal(editableElement.innerHTML.toLowerCase().replace(/\uFEFF/g, ''), "<u>" + text + "</u>test", "With caret at last position underline is not removed but set to notunderline at caret");
+ ok(editor.composer.selection.getSelection().isCollapsed, "Text caret did remain collapsed");
+
+ that.setCaretInsideNode(editor, editableElement.querySelector('u'));
+ editor.composer.commands.exec('underline');
+
+ equal(editableElement.innerHTML.toLowerCase().replace(/\uFEFF/g, ''), text + "test", "Underline is correctly removed when text caret is inside underline");
+ ok(editor.composer.selection.getSelection().isCollapsed, "Text caret did remain collapsed");
+
+ start();
+ });
+ });
+
+// formatblock (alignment, headings, paragraph, pre, blockquote)
+ asyncTest("Format block", function() {
+ expect(12);
+ var that = this,
+ editor = new wysihtml5.Editor(this.editableArea1),
+ text = "once upon a time<br>there was an unformated text<br>spanning many lines.";
+
+ editor.on("load", function() {
+ var editableElement = that.editableArea1;
+ editor.setValue(text, true);
+ editor.composer.selection.selectNode(editor.editableElement);
+ editor.composer.commands.exec('justifyRight');
+ equal(editableElement.innerHTML.toLowerCase(), '<div class="wysiwyg-text-align-right">' + text + '</div>', "Text corectly wrapped in one aligning div");
+
+ editor.composer.commands.exec('justifyRight');
+ equal(editableElement.innerHTML.toLowerCase(), text, "Aligning div correctly removed");
+
+ editor.composer.selection.selectNode(editor.editableElement);
+ editor.composer.selection.getSelection().collapseToStart();
+
+ editor.composer.commands.exec('justifyRight');
+ editor.composer.selection.getSelection().collapseToStart();
+ equal(editableElement.innerHTML.toLowerCase(), '<div class="wysiwyg-text-align-right">once upon a time</div>there was an unformated text<br>spanning many lines.', "Only first line correctly wrapped in aligning div");
+
+ var node = editor.editableElement.querySelectorAll('.wysiwyg-text-align-right');
+ editor.composer.selection.selectNode(node[0].childNodes[0]);
+ editor.composer.commands.exec('justifyLeft');
+ equal(editableElement.innerHTML.toLowerCase(), '<div class="wysiwyg-text-align-left">once upon a time</div>there was an unformated text<br>spanning many lines.', "First line wrapper class changed correctly");
+
+ editor.composer.commands.exec('formatBlock', "h1");
+ equal(editableElement.innerHTML.toLowerCase(), '<h1 class="wysiwyg-text-align-left">once upon a time</h1>there was an unformated text<br>spanning many lines.', "Alignment div changed to heading ok");
+
+ editor.composer.commands.exec('formatBlock', "h1");
+ equal(editableElement.innerHTML.toLowerCase(), '<div class="wysiwyg-text-align-left">once upon a time</div>there was an unformated text<br>spanning many lines.', "heading back to div ok");
+
+ editor.composer.commands.exec('justifyRight');
+ editor.composer.commands.exec('formatBlock', "h1");
+ editor.composer.commands.exec('justifyRight');
+ equal(editableElement.innerHTML.toLowerCase(), '<h1>once upon a time</h1>there was an unformated text<br>spanning many lines.', "heading alignment removed sucessfully");
+
+ editor.composer.commands.exec('justifyRight');
+ editor.composer.commands.exec('formatBlock', "p");
+ editor.composer.commands.exec('justifyRight');
+ equal(editableElement.innerHTML.toLowerCase(), '<p>once upon a time</p>there was an unformated text<br>spanning many lines.', "heading alignment removed sucessfully");
+
+ editor.setValue(text, true);
+ editor.composer.selection.selectNode(editor.editableElement);
+ editor.composer.commands.exec('alignRightStyle');
+ equal(editableElement.innerHTML.toLowerCase(), '<div style="text-align: right;">' + text + '</div>', "Text corectly wrapped in one aligning div with style");
+
+ editor.composer.commands.exec('alignCenterStyle');
+ equal(editableElement.innerHTML.toLowerCase(), '<div style="text-align: center;">' + text + '</div>', "Alignment (style) changed correctly to center");
+
+ editor.composer.commands.exec('alignLeftStyle');
+ equal(editableElement.innerHTML.toLowerCase(), '<div style="text-align: left;">' + text + '</div>', "Alignment (style) changed correctly to left");
+
+ editor.composer.commands.exec('alignLeftStyle');
+ equal(editableElement.innerHTML.toLowerCase(), text, "Alignment (style) correctly removed");
+
+ start();
+ });
+ });
+
+// Format code
+ asyncTest("Format code", function() {
+ expect(2);
+ var that = this,
+ editor = new wysihtml5.Editor(this.editableArea1),
+ text = "once upon a time there was an unformated text.";
+
+ editor.on("load", function() {
+ var editableElement = that.editableArea1;
+ editor.setValue(text, true);
+
+ editor.composer.selection.selectNode(editor.editableElement);
+ editor.composer.commands.exec('formatCode', 'language-html');
+ equal(editableElement.innerHTML.toLowerCase(), '<pre><code class="language-html">' + text + '</code></pre>', "Text corectly wrapped in pre and code and classname addded");
+
+ editor.composer.commands.exec('formatCode', 'language-html');
+ equal(editableElement.innerHTML.toLowerCase(), text, "Code block correctly removed");
+
+ start();
+ });
+ });
+
+// createLink/removeLink
+ asyncTest("Create/remove link", function() {
+ expect(4);
+
+ var that = this,
+ editor = new wysihtml5.Editor(this.editableArea1),
+ text = "text";
+
+ editor.on("load", function() {
+ var editableElement = that.editableArea1;
+ editor.setValue(text, true);
+ editor.composer.selection.selectNode(editor.editableElement);
+
+ // Create
+ editor.composer.commands.exec('createLink', {
+ "href": "http://test.com", "title": "test"
+ });
+ that.equal(editableElement.innerHTML.toLowerCase(), '<a href="http://test.com" title="test">' + text + '</a>', "Link added correctly");
+
+ // Change
+ editor.composer.selection.selectNode(editor.editableElement);
+ editor.composer.commands.exec('createLink', {
+ "href": "http://changed.com"
+ });
+ that.equal(editableElement.innerHTML.toLowerCase(), '<a href="http://changed.com">' + text + '</a>', "Link attributes changed correctly when createLink is executed on existing link");
+
+ //Remove
+ editor.composer.selection.selectNode(editor.editableElement);
+ editor.composer.commands.exec('removeLink');
+ that.equal(editableElement.innerHTML, text, "Link remove correctly");
+
+ // Create with caret
+ editor.composer.selection.selectNode(editor.editableElement);
+ editor.composer.selection.getSelection().collapseToStart();
+ editor.composer.commands.exec('createLink', {
+ "href": "http://test.com", "title": "test"
+ });
+ that.equal(editableElement.innerHTML.toLowerCase(), '<a href="http://test.com" title="test">http://test.com/</a> ' + text + '', "Link with caret added correctly");
+
+ start();
+ });
+ });
+
+ // create table
+ asyncTest("Create table", function() {
+ expect(1);
+ var that = this,
+ editor = new wysihtml5.Editor(this.editableArea1),
+ text = "test";
+
+ editor.on("load", function() {
+ var editableElement = that.editableArea1,
+ expectText = '<table style="width: 100%;">' +
+ '<tbody>' +
+ '<tr>' +
+ '<td> </td>' +
+ '<td> </td>' +
+ '</tr>' +
+ '<tr>' +
+ '<td> </td>' +
+ '<td> </td>' +
+ '</tr>' +
+ '</tbody>' +
+ '</table>';
+ editor.setValue(text, true);
+ editor.composer.selection.selectNode(editor.editableElement);
+ editor.composer.commands.exec('createTable', {
+ cols: 2,
+ rows: 2,
+ tableStyle: "width: 100%;"
+ });
+ equal(editableElement.innerHTML.toLowerCase(), expectText, "Text corectly wrapped in one aligning div");
+ start();
+ });
+ });
+
+ // create table
+ asyncTest("Create lists", function() {
+ expect(7);
+ var that = this,
+ editor = new wysihtml5.Editor(this.editableArea1),
+ text = "";
+
+ editor.on("load", function() {
+ var editableElement = that.editableArea1,
+ expectText = '<ul><li></li></ul>',
+ expectTextBr = '<ul><li><br></li></ul>',
+ expectTextWithContents = '<ul><li>text</li></ul>',
+ expectTextWithContentsBr = '<ul><li>text<br></li></ul>',
+ expectOrdText = '<ol><li></li></ol>',
+ expectOrdTextBr = '<ol><li><br></li></ol>',
+ expectOrdTextWithContents = '<ol><li>text</li></ol>',
+ expectOrdTextWithContentsBr = '<ol><li>text<br></li></ol>';
+
+ editor.setValue(text, true);
+ editor.composer.selection.selectNode(editor.editableElement);
+ editor.composer.commands.exec('insertUnorderedList');
+ ok(editableElement.innerHTML.toLowerCase() == expectText || editableElement.innerHTML.toLowerCase() == expectTextBr, "Unordered list created");
+
+ editor.composer.commands.exec('insertHTML', 'text');
+ ok(editableElement.innerHTML.toLowerCase() == expectTextWithContents || editableElement.innerHTML.toLowerCase() == expectTextWithContentsBr , "In unordered list placed caret correctly");
+
+ editor.setValue(text, true);
+ editor.composer.selection.selectNode(editor.editableElement);
+ editor.composer.commands.exec('insertOrderedList');
+ ok(editableElement.innerHTML.toLowerCase() == expectOrdText || editableElement.innerHTML.toLowerCase() == expectOrdTextBr, "Ordered list created");
+
+ editor.composer.commands.exec('insertHTML', 'text');
+ ok(editableElement.innerHTML.toLowerCase() == expectOrdTextWithContents || editableElement.innerHTML.toLowerCase() == expectOrdTextWithContentsBr, "In ordered list placed caret correctly");
+
+ editableElement.innerHTML = '<ul><li>test</li><li class="second">test</li><li>test</li></ul>';
+ editor.composer.selection.selectNode(editor.editableElement.querySelector('.second'));
+ editor.composer.commands.exec('indentList');
+ equal(editableElement.innerHTML.toLowerCase(), '<ul><li>test<ul><li class="second">test</li></ul></li><li>test</li></ul>', "List indent increases level correctly");
+
+ editor.composer.commands.exec('outdentList');
+ equal(editableElement.innerHTML.toLowerCase(), '<ul><li>test</li><li class="second">test</li><li>test</li></ul>', "List outdent decreases level correctly");
+
+ editor.composer.commands.exec('outdentList');
+ equal(editableElement.innerHTML.toLowerCase(), '<ul><li>test</li></ul><br>test<ul><li>test</li></ul>', "List outdent escapes current list item correctly out of list");
+
+
+ start();
+ });
+ });
+
+
+ // create blockQuote
+ asyncTest("Create blockquote", function() {
+ expect(4);
+ var that = this,
+ editor = new wysihtml5.Editor(this.editableArea1, {
+ parserRules: {
+ tags: {
+ h1: true,
+ p: true,
+ blockquote: true
+ }
+ }
+ }),
+ text = "<h1>heading</h1><p>text</p>",
+ text2 = "test<h1>heading</h1>test";
+
+ editor.on("load", function() {
+ var editableElement = that.editableArea1;
+
+ editor.setValue(text, true);
+
+ editor.composer.selection.selectNode(editor.editableElement);
+ editor.composer.commands.exec('insertBlockQuote');
+ equal(editableElement.innerHTML.toLowerCase(), "<blockquote>" + text + "</blockquote>" , "Blockquote created with headings and paragraphs preserved.");
+
+ editor.composer.commands.exec('insertBlockQuote');
+ equal(editableElement.innerHTML.toLowerCase(), text, "Blockquote removed with headings and paragraphs preserved.");
+
+
+ editor.setValue(text2, true);
+ editor.composer.selection.selectNode(editor.editableElement.querySelector('h1'));
+ editor.composer.commands.exec('insertBlockQuote');
+ equal(editableElement.innerHTML.toLowerCase(), "test<blockquote><h1>heading</h1></blockquote>test" , "Blockquote created.");
+
+ editor.composer.commands.exec('insertBlockQuote');
+ equal(editableElement.innerHTML.toLowerCase(), "test<br><h1>heading</h1><br>test" , "Blockquote removed and line breaks added.");
+
+ start();
+ });
+ });
+
+
+
+}
\ No newline at end of file
--- /dev/null
+if (wysihtml5.browser.supported()) {
+ module("wysihtml5.Editor contenteditable mode", {
+ setup: function() {
+ wysihtml5.dom.insertCSS([
+ "#wysihtml5-test-editable { width: 50%; height: 100px; margin-top: 5px; font-style: italic; border: 2px solid red; border-radius: 2px; }",
+ "#wysihtml5-test-editable:focus { margin-top: 10px; }",
+ "#wysihtml5-test-editable:disabled { margin-top: 20px; }"
+ ]).into(document);
+
+ this.editableArea = document.createElement("div");
+ this.editableArea.id = "wysihtml5-test-editable";
+ this.editableArea.className = "wysihtml5-test-class";
+ this.editableArea.title = "Please enter your foo";
+ this.editableArea.innerHTML = "hey tiff, what's up?";
+
+ this.originalBodyClassName = document.body.className;
+
+ document.body.appendChild(this.editableArea);
+
+ },
+
+ teardown: function() {
+ var leftover;
+ this.editableArea.parentNode.removeChild(this.editableArea);
+ while (leftover = document.querySelector("div.wysihtml5-sandbox, div.wysihtml5-test-class")) {
+ leftover.parentNode.removeChild(leftover);
+ }
+ document.body.className = this.originalBodyClassName;
+ }
+ });
+// Editor initiation tests
+ asyncTest("Basic test", function() {
+ expect(14);
+ var that = this;
+ var editor = new wysihtml5.Editor(this.editableArea);
+ editor.on("load", function() {
+ var editableElement = that.editableArea;
+
+ ok(true, "Load callback triggered");
+ ok(wysihtml5.dom.hasClass(document.body, "wysihtml5-supported"), "<body> received correct class name");
+ ok(wysihtml5.dom.hasClass(editableElement, "wysihtml5-test-class"), "editable kept its original class name");
+ ok(wysihtml5.dom.hasClass(editableElement, "wysihtml5-sandbox"), "editable added its own sandbox class name");
+
+ equal(editor.config.contentEditableMode, true, "contentEditableMode deduced correctly as editable is initiated on non textarea");
+ equal(editor.config.noTextarea, true, "noTextarea mode deduced correctly as editable is initiated on non textarea");
+ equal(editableElement.style.display, "", "Editor contenteditable is visible");
+ equal(editor.currentView.name, "composer", "Current view is 'composer'");
+ equal(editableElement.getAttribute("contentEditable"), "true", "Element is editable");
+ equal(typeof editor.textarea, "undefined", "Textarea correctly not available on editor instance");
+ equal(editor.composer.element, editableElement, "contentEditable element available on editor instance");
+ equal(editableElement.innerHTML.toLowerCase(), "hey tiff, what's up?", "Initial value preserved in editor");
+ ok(wysihtml5.dom.hasClass(editableElement, "wysihtml5-editor"), "Editor element has correct class name");
+ equal(typeof editor.synchronizer, "undefined", "Syncronizer correctly not initiated in contenteditable mode");
+
+ start();
+ });
+ });
+
+// EVENTS TESTS
+ asyncTest("Check events", function() {
+ expect(17);
+
+ var that = this;
+ var editor = new wysihtml5.Editor(this.editableArea);
+
+ editor.on("beforeload", function() {
+ ok(true, "'beforeload' event correctly fired");
+ });
+
+ editor.on("load", function() {
+ var composerElement = that.editableArea;
+
+ editor.on("focus", function(event) {
+ ok(true, "'focus' event correctly fired");
+ ok(event, "event is defined");
+ ok(event instanceof Event, "event is instance of 'Event'");
+ ok(event && event.type === 'focus', "event is of type 'focus'");
+ });
+
+ editor.on("blur", function(event) {
+ ok(true, "'blur' event correctly fired");
+ ok(event, "event is defined");
+ ok(event instanceof Event, "event is instance of 'Event'");
+ ok(event && event.type === 'blur', "event is of type 'blur'");
+ });
+
+ editor.on("change", function(event) {
+ ok(true, "'change' event correctly fired");
+ ok(event, "event is defined");
+ ok(event instanceof Event, "event is instance of 'Event'");
+ ok(event && event.type === 'change', "event is of type 'change'");
+ });
+
+
+ editor.on("custom_event", function(event) {
+ ok(true, "'custom_event' correctly fired");
+ ok(event, "event is defined");
+ ok(event && event.type === 'custom_event', "event is of type 'custom_event'");
+ });
+
+ happen.once(composerElement, {type: "focus"});
+ editor.stopObserving("focus");
+
+ // Modify innerHTML in order to force 'change' event to trigger onblur
+ composerElement.innerHTML = "foobar";
+ happen.once(composerElement, {type: "blur"});
+ happen.once(composerElement, {type: "focusout"});
+
+ equal(wysihtml5.dom.getStyle("margin-top").from(composerElement), "5px", ":focus styles are correctly unset");
+
+
+ editor.fire("custom_event", { type: 'custom_event' });
+
+ setTimeout(function() { start(); }, 100);
+ });
+ });
+
+ asyncTest("Check events paste", function() {
+ expect(12);
+
+ var that = this;
+ var editor = new wysihtml5.Editor(this.editableArea);
+
+ editor.on("load", function() {
+ var composerElement = that.editableArea;
+
+ editor.on("paste", function(event) {
+ ok(event, "event is defined");
+ ok(event instanceof Event, "event is instance of 'Event'");
+ ok(event && event.type === 'paste', "event is of type 'paste'");
+ });
+
+ //Assure that the event on the dom element works as expected
+ that.editableArea.addEventListener('paste', function (event) {
+ ok(event, "event is defined");
+ ok(event instanceof Event, "event is instance of 'Event'");
+ ok(event && event.type === 'paste', "event is of type 'paste'");
+ });
+
+ happen.once(composerElement, {type: "paste"});
+ //Just to show that not happen.js is the source of error
+ var event = new Event('paste');
+ that.editableArea.dispatchEvent(event);
+ //QUnit.triggerEvent(composerElement, 'paste');
+
+ setTimeout(function() { start(); }, 100);
+ });
+ });
+
+ asyncTest("Check events drop", function() {
+ expect(12);
+
+ var that = this;
+ var editor = new wysihtml5.Editor(this.editableArea);
+
+ editor.on("load", function() {
+ var composerElement = that.editableArea;
+
+ //if changing from drop to paste it works
+ editor.on('drop', function(event) {
+ ok(event, "event is defined");
+ ok(event instanceof Event, "event is instance of 'Event'");
+ ok(event && event.type === 'drop', "event is of type 'drop'");
+ });
+
+ editor.on('paste', function(event) {
+ ok(false, "No 'paste' event was fired.");
+ });
+
+ //Assure that the event on the dom element works as expected
+ that.editableArea.addEventListener('drop', function (event) {
+ ok(event, "event is defined");
+ ok(event instanceof Event, "event is instance of 'Event'");
+ ok(event && event.type === 'drop', "event is of type 'drop'");
+ });
+
+ happen.once(composerElement, {type: "drop"});
+ //Just to show that not happen.js is the source of error
+ var event = new Event('drop');
+ that.editableArea.dispatchEvent(event);
+ //QUnit.triggerEvent(composerElement, 'drop');
+
+ setTimeout(function() { start(); }, 100);
+ });
+ });
+
+
+// Placeholder tests
+ asyncTest("Check placeholder", function() {
+ expect(12);
+
+ var that = this;
+
+ var placeholderText = "enter text ...";
+ this.editableArea.innerHTML = "";
+ this.editableArea.setAttribute("data-placeholder", "enter text ...");
+
+ var editor = new wysihtml5.Editor(this.editableArea);
+ editor.on("load", function() {
+ var composerElement = that.editableArea;
+ equal(wysihtml5.dom.getTextContent(composerElement), placeholderText, "Placeholder text correctly copied into textarea");
+
+ ok(wysihtml5.dom.hasClass(composerElement, "placeholder"), "Editor got 'placeholder' css class");
+ ok(editor.hasPlaceholderSet(), "'hasPlaceholderSet' returns correct value when placeholder is actually set");
+ editor.fire("focus:composer");
+ equal(wysihtml5.dom.getTextContent(composerElement), "", "Editor is empty after focus");
+ ok(!wysihtml5.dom.hasClass(composerElement, "placeholder"), "Editor hasn't got 'placeholder' css class");
+ ok(!editor.hasPlaceholderSet(), "'hasPlaceholderSet' returns correct value when placeholder isn't actually set");
+ editor.fire("blur:composer");
+ equal(wysihtml5.dom.getTextContent(composerElement), placeholderText, "Editor restored placeholder text after unfocus");
+ editor.fire("focus:composer");
+ equal(wysihtml5.dom.getTextContent(composerElement), "");
+ composerElement.innerHTML = "some content";
+ editor.fire("blur:composer");
+ equal(wysihtml5.dom.getTextContent(composerElement), "some content");
+ ok(!wysihtml5.dom.hasClass(composerElement, "placeholder"), "Editor hasn't got 'placeholder' css class");
+ editor.fire("focus:composer");
+ // Following html causes innerText and textContent to report an empty string
+ var html = '<img>';
+ composerElement.innerHTML = html;
+ editor.fire("blur:composer");
+ equal(composerElement.innerHTML.toLowerCase(), html, "HTML hasn't been cleared even though the innerText and textContent properties indicate empty content.");
+ ok(!wysihtml5.dom.hasClass(composerElement, "placeholder"), "Editor hasn't got 'placeholder' css class");
+ start();
+ });
+ });
+
+// Editor available functions test
+ asyncTest("Check public api", function() {
+ expect(13);
+
+ var that = this;
+
+ var editor = new wysihtml5.Editor(this.editableArea, {
+ parserRules: { tags: { p: { rename_tag: "div" } } },
+ bodyClassName: "editor-is-supported",
+ composerClassName: "editor"
+ });
+
+ editor.on("load", function() {
+ ok(editor.isCompatible(), "isCompatible() returns correct value");
+ ok(wysihtml5.dom.hasClass(document.body, "editor-is-supported"), "<body> received correct class name");
+
+ var composerElement = that.editableArea;
+ editor.clear();
+ equal(wysihtml5.dom.getTextContent(composerElement), "", "Editor empty after calling 'clear'");
+ ok(wysihtml5.dom.hasClass(composerElement, "editor"), "Composer element has correct class name");
+
+ var html = "hello <strong>foo</strong>!";
+ editor.setValue(html);
+ equal(composerElement.innerHTML.toLowerCase(), html, "Editor content correctly set after calling 'setValue'");
+ ok(!editor.isEmpty(), "'isEmpty' returns correct value when the composer element isn't actually empty");
+
+ var value = editor.getValue(false, false);
+ equal(value.toLowerCase(), html, "Editor content correctly returned after calling 'getValue(false, false)'");
+
+ editor.clear();
+ value = editor.getValue();
+ equal(value, "");
+ ok(editor.isEmpty(), "'isEmpty' returns correct value when the composer element is actually empty");
+
+ equal(editor.parse("<p>foo</p>").toLowerCase(), "<div>foo</div>", "'parse' returns correct value");
+
+ // Check disable/enable
+ editor.disable();
+ ok(!composerElement.getAttribute("contentEditable"), "When disabled the composer hasn't the contentEditable attribute");
+
+ editor.enable();
+ equal(composerElement.getAttribute("contentEditable"), "true", "After enabling the editor the contentEditable property is true");
+ ok(!composerElement.getAttribute("disabled"), "After enabling the disabled attribute is unset");
+
+ start();
+ });
+ });
+
+// Parser tests
+ asyncTest("Parser (default parser method with parserRules as object)", function() {
+ expect(2);
+
+ var parserRules = {
+ tags: {
+ div: true,
+ p: { rename_tag: "div" },
+ span: true,
+ script: undefined
+ }
+ };
+
+ var input = "<p>foobar</p>",
+ output = "<div>foobar</div>";
+
+ var editor = new wysihtml5.Editor(this.editableArea, {
+ parserRules: parserRules
+ });
+
+ editor.on("load", function() {
+ equal(editor.config.parserRules, parserRules, "Parser rules correctly set on config object");
+ // Invoke parsing via second parameter of setValue()
+ editor.setValue(input, true);
+ equal(editor.getValue(false, false).toLowerCase(), output, "HTML got correctly parsed within setValue()");
+ start();
+ });
+ });
+
+ asyncTest("Editable area html should be cleaned up upon initiation", function() {
+ expect(2);
+ var that = this,
+ parserRules = {
+ "tags": {
+ "div": { "unwrap": 1 }
+ }
+ },
+ input = "<div><div>Hi,</div> there!</div>",
+ output = "Hi,<br> there!<br>",
+ editor;
+
+ this.editableArea.innerHTML = input;
+ equal(that.editableArea.innerHTML, input, "Content is set as unclean before editor initiation");
+ editor = new wysihtml5.Editor(this.editableArea, {
+ parserRules: parserRules
+ });
+
+ editor.on("load", function() {
+ equal(that.editableArea.innerHTML, output, "Content is cleaned after initiation");
+ start();
+ });
+ });
+
+
+ asyncTest("Parser (custom parser method with parserRules as object", function() {
+ expect(6);
+
+ this.editableArea.innerHTML = "<p>foobar</p><script>alert(1);</script>";
+
+ var that = this,
+ parserRules = { script: undefined },
+ input = this.editableArea.innerHTML,
+ output = input;
+
+
+ var editor = new wysihtml5.Editor(this.editableArea, {
+ parserRules: parserRules,
+ parser: function(html, config) {
+ if (typeof html !== "string") {
+ html = html.innerHTML;
+ ok(true, "Custom parser is run element upon initiation");
+ }
+ equal(html.toLowerCase(), input, "HTML passed into parser is equal to the one which just got inserted");
+ equal(config.rules, parserRules, "Rules passed into parser are equal to those given to the editor");
+ return html.replace(/\<script\>.*?\<\/script\>/gi, "");
+ }
+ });
+
+ editor.on("load", function() {
+ var output2 = "<p>foobar</p>";
+ // Invoke parsing via second parameter of setValue()
+ equal(editor.getValue(true, true).toLowerCase(), output2, "HTML got correctly parsed within setValue()");
+ start();
+ });
+ });
+
+ asyncTest("Inserting an element which causes the textContent/innerText of the contentEditable element to be empty works correctly", function() {
+ expect(1);
+
+ var that = this;
+
+ var editor = new wysihtml5.Editor(this.editableArea);
+ editor.on("load", function() {
+ var html = '<img>',
+ composerElement = that.editableArea;
+
+ composerElement.innerHTML = html;
+
+ // Fire events that could cause a change in the composer
+
+ happen.once(composerElement, {type: "keypress"});
+ happen.once(composerElement, {type: "keyup"});
+ happen.once(composerElement, {type: "cut"});
+ happen.once(composerElement, {type: "blur"});
+
+ setTimeout(function() {
+ equal(composerElement.innerHTML.toLowerCase(), html, "Composer still has correct content");
+ start();
+ }, 500);
+ });
+ });
+
+ /*
+ // TODO: needs logic rethink of terms and conditions
+
+ asyncTest("If selection borders cross contenteditabel only editable gets modified", function() {
+ expect(3);
+ var that = this,
+ editor = new wysihtml5.Editor(this.editableArea);
+
+ editor.on("load", function() {
+ editor.setValue("foobar", true);
+ editor.composer.selection.selectNode(that.editableArea);
+ equal(that.editableArea.innerHTML, "foobar", "Content was not bold before");
+ window.e = editor;
+ editor.composer.commands.exec('bold');
+
+ ok(wysihtml5.dom.getStyle("font-weight").from(that.editableArea.children[0]) == 700 || wysihtml5.dom.getStyle("font-weight").from(that.editableArea.children[0]) == "bold", "First child has style bold");
+ ok(wysihtml5.dom.getStyle("font-weight").from(that.editableArea) == 400 || wysihtml5.dom.getStyle("font-weight").from(that.editableArea) == "normal", "Editable element itself is not bold");
+ start();
+ });
+ });
+ */
+
+}
--- /dev/null
+if (wysihtml5.browser.supported()) {
+ module("wysihtml5.Editor", {
+ setup: function() {
+ wysihtml5.dom.insertCSS([
+ "#wysihtml5-test-textarea { width: 50%; height: 100px; margin-top: 5px; font-style: italic; border: 2px solid red; border-radius: 2px; }",
+ "#wysihtml5-test-textarea:focus { margin-top: 10px; }",
+ "#wysihtml5-test-textarea:disabled { margin-top: 20px; }"
+ ]).into(document);
+
+ this.textareaElement = document.createElement("textarea");
+ this.textareaElement.id = "wysihtml5-test-textarea";
+ this.textareaElement.title = "Please enter your foo";
+ this.textareaElement.value = "hey tiff, what's up?";
+
+ this.form = document.createElement("form");
+ this.form.onsubmit = function() { return false; };
+ this.form.appendChild(this.textareaElement);
+
+ this.originalBodyClassName = document.body.className;
+
+ document.body.appendChild(this.form);
+ },
+
+ teardown: function() {
+ var leftover;
+ while (leftover = document.querySelector("iframe.wysihtml5-sandbox, input[name='_wysihtml5_mode']")) {
+ leftover.parentNode.removeChild(leftover);
+ }
+ this.form.parentNode.removeChild(this.form);
+ document.body.className = this.originalBodyClassName;
+ },
+
+ getComposerElement: function() {
+ return this.getIframeElement().contentWindow.document.body;
+ },
+
+ getIframeElement: function() {
+ var iframes = document.querySelectorAll("iframe.wysihtml5-sandbox");
+ return iframes[iframes.length - 1];
+ }
+ });
+
+ asyncTest("Basic test", function() {
+ expect(18);
+
+ var that = this;
+
+ var editor = new wysihtml5.Editor(this.textareaElement);
+ editor.on("load", function() {
+ var iframeElement = that.getIframeElement(),
+ composerElement = that.getComposerElement(),
+ textareaElement = that.textareaElement;
+ ok(true, "Load callback triggered");
+ ok(wysihtml5.dom.hasClass(document.body, "wysihtml5-supported"), "<body> received correct class name");
+ equal(textareaElement.style.display, "none", "Textarea not visible");
+ ok(iframeElement.style.display, "", "Editor iFrame is visible");
+ equal(editor.currentView.name, "composer", "Current view is 'composer'");
+
+ // Make textarea visible for a short amount of time, in order to calculate dimensions properly
+ textareaElement.style.display = "block";
+ deepEqual(
+ [iframeElement.offsetHeight, iframeElement.offsetWidth],
+ [textareaElement.offsetHeight, textareaElement.offsetWidth],
+ "Editor has the same dimensions as the original textarea"
+ );
+ textareaElement.style.display = "none";
+
+ var hiddenField = textareaElement.nextSibling;
+ equal(hiddenField.name, "_wysihtml5_mode", "Hidden field has correct name");
+ equal(hiddenField.value, "1", "Hidden field has correct value");
+ equal(hiddenField.type, "hidden", "Hidden field is actually hidden");
+ equal(textareaElement.nextSibling.nextSibling, iframeElement, "Editor iframe is inserted after the textarea");
+ equal(composerElement.getAttribute("contentEditable"), "true", "Body element in iframe is editable");
+ equal(editor.textarea.element, textareaElement, "Textarea correctly available on editor instance");
+ equal(editor.composer.element, composerElement, "contentEditable element available on editor instance");
+ equal(wysihtml5.dom.getStyle("font-style").from(composerElement), "italic", "Correct font-style applied to editor element");
+ equal(wysihtml5.dom.getStyle("width").from(iframeElement), "50%", "Correct width applied to iframe");
+ equal(wysihtml5.dom.getStyle("height").from(iframeElement), "100px", "Correct height applied to iframe");
+
+ if ("borderRadius" in document.createElement("div").style) {
+ expect(19);
+ ok(wysihtml5.dom.getStyle("border-top-right-radius").from(iframeElement).indexOf("2px") !== -1, "border-radius correctly copied");
+ }
+
+ equal(composerElement.innerHTML.toLowerCase(), "hey tiff, what's up?", "Copied the initial textarea value to the editor");
+ ok(wysihtml5.dom.hasClass(composerElement, "wysihtml5-editor"), "Editor element has correct class name");
+
+ start();
+ });
+ });
+
+
+ asyncTest("Check setting of name as class name on iframe and iframe's body", function() {
+ expect(4);
+
+ this.textareaElement.className = "death-star";
+
+ var that = this,
+ name = "star-wars-input",
+ editor = new wysihtml5.Editor(this.textareaElement, { name: "star-wars-input" });
+
+ editor.on("load", function() {
+ var iframeElement = that.getIframeElement(),
+ composerElement = that.getComposerElement(),
+ textareaElement = that.textareaElement;
+ ok(wysihtml5.dom.hasClass(iframeElement, name), "iFrame has adopted name as className");
+ ok(wysihtml5.dom.hasClass(composerElement, name), "iFrame's body has adopted name as className");
+ ok(wysihtml5.dom.hasClass(composerElement, "death-star"), "iFrame's body has adopted the textarea className");
+ ok(!wysihtml5.dom.hasClass(textareaElement, name), "Textarea has not adopted name as className");
+ start();
+ });
+ });
+
+
+ asyncTest("Check textarea with box-sizing: border-box;", function() {
+ expect(1);
+
+ var that = this;
+
+ wysihtml5.dom.setStyles({
+ MozBoxSizing: "border-box",
+ WebkitBoxSizing: "border-box",
+ MsBoxSizing: "border-box",
+ boxSizing: "border-box"
+ }).on(this.textareaElement);
+
+ var editor = new wysihtml5.Editor(this.textareaElement);
+ editor.on("load", function() {
+ // Make textarea visible for a short amount of time, in order to calculate dimensions properly
+ that.textareaElement.style.display = "block";
+ deepEqual(
+ [that.getIframeElement().offsetWidth, that.getIframeElement().offsetHeight],
+ [that.textareaElement.offsetWidth, that.textareaElement.offsetHeight],
+ "Editor has the same dimensions as the original textarea"
+ );
+ that.textareaElement.style.display = "none";
+
+ start();
+ });
+ });
+
+ asyncTest("Check whether cols and rows attribute is correctly handled", function() {
+ expect(2);
+
+ var that = this;
+
+ // Remove styles
+ this.textareaElement.removeAttribute("id");
+
+ // And set dimensions of <textarea> via rows/cols attribute
+ this.textareaElement.setAttribute("rows", 20);
+ this.textareaElement.setAttribute("cols", 50);
+
+ var editor = new wysihtml5.Editor(this.textareaElement);
+ editor.on("load", function() {
+ ok(that.getIframeElement().style.height.match(/\d+px/), "Rows attribute is correctly converted into a css height");
+ ok(that.getIframeElement().style.width.match(/\d+px/), "Cols attribute is correctly converted into a css width");
+ start();
+ });
+ });
+
+ asyncTest("Check whether attributes are copied", function() {
+ expect(1);
+
+ var that = this;
+
+ var editor = new wysihtml5.Editor(this.textareaElement);
+ editor.on("load", function() {
+ equal(that.getComposerElement().title, that.textareaElement.title, "Editor got attributes copied over from textarea");
+ start();
+ });
+ });
+
+
+ asyncTest("Check events", function() {
+ expect(8);
+
+ var that = this;
+
+ var editor = new wysihtml5.Editor(this.textareaElement);
+
+ editor.on("beforeload", function() {
+ ok(true, "'beforeload' event correctly fired");
+ });
+
+ editor.on("load", function() {
+ var composerElement = that.getComposerElement(),
+ iframeElement = that.getIframeElement();
+
+ editor.on("focus", function() {
+ ok(true, "'focus' event correctly fired");
+ });
+
+ editor.on("blur", function() {
+ ok(true, "'blur' event correctly fired");
+ });
+
+ editor.on("change", function() {
+ ok(true, "'change' event correctly fired");
+ });
+
+ editor.on("paste", function() {
+ ok(true, "'paste' event correctly fired");
+ });
+
+ editor.on("drop", function() {
+ ok(true, "'drop' event correctly fired");
+ });
+
+ editor.on("custom_event", function() {
+ ok(true, "'custom_event' correctly fired");
+ });
+
+ happen.once(composerElement, {type: "focus"});
+ editor.stopObserving("focus");
+
+ // Modify innerHTML in order to force 'change' event to trigger onblur
+ composerElement.innerHTML = "foobar";
+ happen.once(composerElement, {type: "blur"});
+ happen.once(composerElement, {type: "focusout"});
+ equal(wysihtml5.dom.getStyle("margin-top").from(iframeElement), "5px", ":focus styles are correctly unset");
+ happen.once(composerElement, {type: "paste"});
+ happen.once(composerElement, {type: "drop"});
+
+ editor.fire("custom_event");
+
+ // Delay teardown in order to avoid unwanted js errors caused by a too early removed sandbox iframe
+ // which then causes js errors in Safari 5
+ setTimeout(function() { start(); }, 100);
+ });
+ });
+
+
+ asyncTest("Check sync (basic)", function() {
+ expect(1);
+
+ var that = this;
+
+ var editor = new wysihtml5.Editor(this.textareaElement);
+ editor.on("load", function() {
+ var html = "<p>hello foobar, what up?</p>";
+ that.getComposerElement().innerHTML = html;
+
+ setTimeout(function() {
+ equal(that.textareaElement.value.toLowerCase(), html.toLowerCase(), "Editor content got correctly copied over to original textarea");
+ start();
+ }, 500);
+ });
+ });
+
+
+ asyncTest("Check sync (advanced)", function() {
+ expect(5);
+
+ var that = this;
+
+ var editor = new wysihtml5.Editor(this.textareaElement, {
+ parserRules: { tags: { "strong": true } }
+ });
+
+ editor.on("load", function() {
+ var html = "<strong>timmay!</strong>",
+ composerElement = that.getComposerElement();
+ composerElement.innerHTML = html;
+
+ setTimeout(function() {
+ equal(that.textareaElement.value.toLowerCase(), html.toLowerCase(), "Editor content got correctly copied over to original textarea");
+
+ composerElement.innerHTML = "<font color=\"red\">hey </font><strong>helen!</strong>";
+ editor.fire("change_view", "textarea");
+ equal(that.textareaElement.value.toLowerCase(), "hey <strong>helen!</strong>", "Editor got immediately copied over to textarea after switching the view");
+
+ that.textareaElement.value = "<i>hey </i><strong>richard!</strong>";
+ editor.fire("change_view", "composer");
+ equal(composerElement.innerHTML.toLowerCase(), "hey <strong>richard!</strong>", "Textarea sanitized and copied over it's value to the editor after switch");
+
+ composerElement.innerHTML = "<i>hey </i><strong>timmay!</strong>";
+ happen.once(that.form, {type: "submit"});
+ equal(that.textareaElement.value.toLowerCase(), "hey <strong>timmay!</strong>", "Textarea gets the sanitized content of the editor onsubmit");
+
+ setTimeout(function() {
+ that.form.reset();
+
+ // Timeout needed since reset() isn't executed synchronously
+ setTimeout(function() {
+ equal(wysihtml5.dom.getTextContent(composerElement), "", "Editor is empty after reset");
+ start();
+ }, 100);
+
+ }, 500);
+
+ }, 500);
+
+ });
+ });
+
+
+ asyncTest("Check placeholder", function() {
+ expect(13);
+
+ var that = this;
+
+ var placeholderText = "enter text ...";
+ this.textareaElement.value = "";
+ this.textareaElement.setAttribute("placeholder", "enter text ...");
+
+ var editor = new wysihtml5.Editor(this.textareaElement);
+ editor.on("load", function() {
+ var composerElement = that.getComposerElement();
+ equal(wysihtml5.dom.getTextContent(composerElement), placeholderText, "Placeholder text correctly copied into textarea");
+ ok(wysihtml5.dom.hasClass(composerElement, "placeholder"), "Editor got 'placeholder' css class");
+ ok(editor.hasPlaceholderSet(), "'hasPlaceholderSet' returns correct value when placeholder is actually set");
+ editor.fire("focus:composer");
+ equal(wysihtml5.dom.getTextContent(composerElement), "", "Editor is empty after focus");
+ ok(!wysihtml5.dom.hasClass(composerElement, "placeholder"), "Editor hasn't got 'placeholder' css class");
+ ok(!editor.hasPlaceholderSet(), "'hasPlaceholderSet' returns correct value when placeholder isn't actually set");
+ editor.fire("blur:composer");
+ equal(wysihtml5.dom.getTextContent(composerElement), placeholderText, "Editor restored placeholder text after unfocus");
+ editor.fire("focus:composer");
+ equal(wysihtml5.dom.getTextContent(composerElement), "");
+ composerElement.innerHTML = "some content";
+ editor.fire("blur:composer");
+ equal(wysihtml5.dom.getTextContent(composerElement), "some content");
+ ok(!wysihtml5.dom.hasClass(composerElement, "placeholder"), "Editor hasn't got 'placeholder' css class");
+ editor.fire("focus:composer");
+ // Following html causes innerText and textContent to report an empty string
+ var html = '<img>';
+ composerElement.innerHTML = html;
+ editor.fire("blur:composer");
+ equal(composerElement.innerHTML.toLowerCase(), html, "HTML hasn't been cleared even though the innerText and textContent properties indicate empty content.");
+ ok(!wysihtml5.dom.hasClass(composerElement, "placeholder"), "Editor hasn't got 'placeholder' css class");
+
+ setTimeout(function() {
+ that.form.reset();
+
+ // Timeout needed since reset() isn't executed synchronously
+ setTimeout(function() {
+ equal(wysihtml5.dom.getTextContent(composerElement), placeholderText, "After form reset the editor has the placeholder as content");
+ start();
+ }, 100);
+
+ }, 500);
+ });
+ });
+
+
+ asyncTest("Check public api", function() {
+ expect(13);
+
+ var that = this;
+
+ var editor = new wysihtml5.Editor(this.textareaElement, {
+ parserRules: { tags: { p: { rename_tag: "div" } } },
+ bodyClassName: "editor-is-supported",
+ composerClassName: "editor"
+ });
+
+ editor.on("load", function() {
+ ok(editor.isCompatible(), "isCompatible() returns correct value");
+ ok(wysihtml5.dom.hasClass(document.body, "editor-is-supported"), "<body> received correct class name");
+
+ var composerElement = that.getComposerElement();
+ editor.clear();
+ equal(wysihtml5.dom.getTextContent(composerElement), "", "Editor empty after calling 'clear'");
+ ok(wysihtml5.dom.hasClass(composerElement, "editor"), "Composer element has correct class name");
+
+ var html = "hello <strong>foo</strong>!";
+ editor.setValue(html);
+ equal(composerElement.innerHTML.toLowerCase(), html, "Editor content correctly set after calling 'setValue'");
+ ok(!editor.isEmpty(), "'isEmpty' returns correct value when the composer element isn't actually empty");
+
+ var value = editor.getValue(false, false);
+ equal(value.toLowerCase(), html, "Editor content correctly returned after calling 'getValue(false, false)'");
+
+ editor.clear();
+ value = editor.getValue();
+ equal(value, "");
+ ok(editor.isEmpty(), "'isEmpty' returns correct value when the composer element is actually empty");
+
+ equal(editor.parse("<p>foo</p>").toLowerCase(), "<div>foo</div>", "'parse' returns correct value");
+
+ // Check disable/enable
+ editor.disable();
+ ok(!composerElement.getAttribute("contentEditable"), "When disabled the composer hasn't the contentEditable attribute");
+
+ editor.enable();
+ equal(composerElement.getAttribute("contentEditable"), "true", "After enabling the editor the contentEditable property is true");
+ ok(!composerElement.getAttribute("disabled"), "After enabling the disabled attribute is unset");
+
+ start();
+ });
+ });
+
+
+ asyncTest("Parser (default parser method with parserRules as object", function() {
+ expect(2);
+
+ var parserRules = {
+ tags: {
+ div: true,
+ p: { rename_tag: "div" },
+ span: true,
+ script: undefined
+ }
+ };
+
+ var input = "<p>foobar</p>",
+ output = "<div>foobar</div>";
+
+ var editor = new wysihtml5.Editor(this.textareaElement, {
+ parserRules: parserRules
+ });
+
+ editor.on("load", function() {
+ equal(editor.config.parserRules, parserRules, "Parser rules correctly set on config object");
+ // Invoke parsing via second parameter of setValue()
+ editor.setValue(input, true);
+ equal(editor.getValue(false, false).toLowerCase(), output, "HTML got correctly parsed within setValue()");
+ start();
+ });
+ });
+
+
+ asyncTest("Parser (custom parser method with parserRules as object", function() {
+ expect(7);
+
+ var that = this,
+ parserRules = { script: undefined },
+ input = this.textareaElement.value,
+ output = input;
+ var editor = new wysihtml5.Editor(this.textareaElement, {
+ parserRules: parserRules,
+ parser: function(html, config) {
+ equal(html.toLowerCase(), input, "HTML passed into parser is equal to the one which just got inserted");
+ equal(config.rules, parserRules, "Rules passed into parser are equal to those given to the editor");
+ equal(config.context, that.getIframeElement().contentWindow.document, "Context passed into parser is equal the document object of the editor's iframe");
+ return html.replace(/\<script\>.*?\<\/script\>/gi, "");
+ }
+ });
+
+ editor.on("load", function() {
+ input = "<p>foobar</p><script>alert(1);</script>";
+ output = "<p>foobar</p>";
+
+ // Invoke parsing via second parameter of setValue()
+ editor.setValue(input, true);
+ equal(editor.getValue(false, false).toLowerCase(), output, "HTML got correctly parsed within setValue()");
+
+ start();
+ });
+ });
+
+
+ asyncTest("Inserting an element which causes the textContent/innerText of the contentEditable element to be empty works correctly", function() {
+ expect(2);
+
+ var that = this;
+
+ var editor = new wysihtml5.Editor(this.textareaElement);
+ editor.on("load", function() {
+ var html = '<img>',
+ composerElement = that.getComposerElement(),
+ textareaElement = that.textareaElement;
+ composerElement.innerHTML = html;
+
+ // Fire events that could cause a change in the composer
+ happen.once(composerElement, {type: "keypress"});
+ happen.once(composerElement, {type: "keyup"});
+ happen.once(composerElement, {type: "cut"});
+ happen.once(composerElement, {type: "blur"});
+
+ setTimeout(function() {
+ equal(composerElement.innerHTML.toLowerCase(), html, "Composer still has correct content");
+ equal(textareaElement.value.toLowerCase(), html, "Textarea got correct value");
+ start();
+ }, 500);
+ });
+ });
+
+
+ asyncTest("Check for stylesheets", function() {
+ expect(5);
+
+ var that = this;
+
+ var stylesheetUrls = [
+ "http://yui.yahooapis.com/2.8.2r1/build/reset/reset-min.css",
+ "http://yui.yahooapis.com/2.8.0/build/reset/reset-min.css"
+ ];
+
+ var editor = new wysihtml5.Editor(this.textareaElement, {
+ stylesheets: stylesheetUrls
+ });
+
+ editor.on("load", function() {
+ var iframeElement = that.getIframeElement(),
+ iframeDoc = iframeElement.contentWindow.document,
+ linkElements = iframeDoc.getElementsByTagName("link");
+ equal(linkElements.length, 2, "Correct amount of stylesheets inserted into the dom tree");
+ equal(linkElements[0].getAttribute("href"), stylesheetUrls[0]);
+ equal(linkElements[0].getAttribute("rel"), "stylesheet");
+ equal(linkElements[1].getAttribute("href"), stylesheetUrls[1]);
+ equal(linkElements[1].getAttribute("rel"), "stylesheet");
+ start();
+ });
+ });
+
+
+ asyncTest("Check config.supportTouchDevices = false", function() {
+ expect(2);
+
+ var that = this;
+
+ var originalIsTouchDevice = wysihtml5.browser.isTouchDevice;
+ wysihtml5.browser.isTouchDevice = function() { return true; };
+
+ var editor = new wysihtml5.Editor(this.textareaElement, {
+ supportTouchDevices: false
+ });
+
+ editor.on("load", function() {
+ ok(!that.getIframeElement(), "No editor iframe has been inserted");
+ equal(that.textareaElement.style.display, "", "Textarea is visible");
+
+ wysihtml5.browser.isTouchDevice = originalIsTouchDevice;
+
+ start();
+ });
+ });
+
+ asyncTest("Check whether everything works when the textarea is not within a form", function() {
+ expect(3);
+
+ var textareaElement = document.createElement("textarea");
+ document.body.appendChild(textareaElement);
+ var editor = new wysihtml5.Editor(textareaElement);
+
+ var that = this;
+ editor.on("load", function() {
+ ok(!document.querySelector("input[name='_wysihtml5_mode']"), "No hidden _wysihtml5_mode input has been created");
+ ok(that.getIframeElement(), "Editor's iframe has been created");
+ equal(textareaElement.style.display, "none", "Textarea is not visible");
+ textareaElement.parentNode.removeChild(textareaElement);
+
+ start();
+ });
+ });
+
+ asyncTest("Test disabled textarea", function() {
+ expect(2);
+
+ this.textareaElement.disabled = true;
+ var that = this;
+
+ var editor = new wysihtml5.Editor(this.textareaElement);
+
+ editor.on("load", function() {
+ var iframeElement = that.getIframeElement(),
+ composerElement = that.getComposerElement();
+ equal(wysihtml5.dom.getStyle("margin-top").from(iframeElement), "20px", "Correct :disabled styles applied");
+ ok(!composerElement.hasAttribute("contentEditable"), "Editor is unfocusable");
+ start();
+ });
+ });
+}
--- /dev/null
+module("wysihtml5 - Incompatible", {
+ setup: function() {
+ this.originalSupportCheck = wysihtml5.browser.supported;
+ wysihtml5.browser.supported = function() { return false; };
+
+ this.textareaElement = document.createElement("textarea");
+ document.body.appendChild(this.textareaElement);
+ },
+
+ teardown: function() {
+ wysihtml5.browser.supported = this.originalSupportCheck;
+ this.textareaElement.parentNode.removeChild(this.textareaElement);
+ }
+});
+
+
+asyncTest("Basic test", function() {
+ expect(12);
+
+ var that = this;
+
+ var oldIframesLength = document.getElementsByTagName("iframe").length;
+
+ var oldInputsLength = document.getElementsByTagName("input").length;
+
+ var editor = new wysihtml5.Editor(this.textareaElement);
+ editor.on("load", function() {
+ ok(true, "'load' event correctly triggered");
+ ok(!wysihtml5.dom.hasClass(document.body, "wysihtml5-supported"), "<body> didn't receive the 'wysihtml5-supported' class");
+ ok(!editor.isCompatible(), "isCompatible returns false when rich text editing is not correctly supported in the current browser");
+ equal(that.textareaElement.style.display, "", "Textarea is visible");
+ ok(!editor.composer, "Composer not initialized");
+
+ equal(document.getElementsByTagName("iframe").length, oldIframesLength, "No hidden field has been inserted into the dom");
+ equal(document.getElementsByTagName("input").length, oldInputsLength, "Composer not initialized");
+
+ var html = "foobar<br>";
+ editor.setValue(html);
+ equal(that.textareaElement.value, html);
+ equal(editor.getValue(), html);
+ editor.clear();
+ equal(that.textareaElement.value, "");
+
+ editor.on("focus", function() {
+ ok(true, "Generic 'focus' event fired");
+ });
+
+ editor.on("focus:textarea", function() {
+ ok(true, "Specific 'focus:textarea' event fired");
+ });
+
+ editor.on("focus:composer", function() {
+ ok(false, "Specific 'focus:composer' event fired, and that's wrong, there shouldn't be a composer element/view");
+ });
+
+ var eventOptions = {};
+ eventOptions.type = wysihtml5.browser.supportsEvent("focusin") ? "focusin" : "focus";
+ happen.once(that.textareaElement, eventOptions);
+
+ start();
+ });
+});
--- /dev/null
+<!DOCTYPE html>
+
+<meta http-equiv="X-UA-Compatible" content="IE=Edge">
+<meta charset="utf-8">
+
+<title>wysihtml5 - Test Suite</title>
+
+<link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css">
+
+<script src="../node_modules/qunitjs/qunit/qunit.js"></script>
+<script src="../node_modules/happen/happen.js"></script>
+<script src="../node_modules/qunit-assert-html/dist/qunit-assert-html.js"></script>
+
+<script src="../src/wysihtml5.js"></script>
+<script src="../node_modules/rangy/lib/rangy-core.js"></script>
+<script src="../node_modules/rangy/lib/rangy-selectionsaverestore.js"></script>
+<script src="../lib/base/base.js"></script>
+<script src="../src/polyfills.js"></script>
+<script src="../src/browser.js"></script>
+<script src="../src/lang/array.js"></script>
+<script src="../src/lang/dispatcher.js"></script>
+<script src="../src/lang/object.js"></script>
+<script src="../src/lang/string.js"></script>
+<script src="../src/dom/auto_link.js"></script>
+<script src="../src/dom/class.js"></script>
+<script src="../src/dom/compare_document_position.js"></script>
+<script src="../src/dom/contains.js"></script>
+<script src="../src/dom/convert_to_list.js"></script>
+<script src="../src/dom/copy_attributes.js"></script>
+<script src="../src/dom/copy_styles.js"></script>
+<script src="../src/dom/delegate.js"></script>
+<script src="../src/dom/get_as_dom.js"></script>
+<script src="../src/dom/get_parent_element.js"></script>
+<script src="../src/dom/dom_node.js"></script>
+<script src="../src/dom/get_style.js"></script>
+<script src="../src/dom/get_textnodes.js"></script>
+<script src="../src/dom/has_element_with_tag_name.js"></script>
+<script src="../src/dom/has_element_with_class_name.js"></script>
+<script src="../src/dom/insert.js"></script>
+<script src="../src/dom/insert_css.js"></script>
+<script src="../src/dom/observe.js"></script>
+<script src="../src/dom/parse.js"></script>
+<script src="../src/dom/remove_empty_text_nodes.js"></script>
+<script src="../src/dom/rename_element.js"></script>
+<script src="../src/dom/replace_with_child_nodes.js"></script>
+<script src="../src/dom/resolve_list.js"></script>
+<script src="../src/dom/sandbox.js"></script>
+<script src="../src/dom/set_attributes.js"></script>
+<script src="../src/dom/set_styles.js"></script>
+<script src="../src/dom/simulate_placeholder.js"></script>
+<script src="../src/dom/text_content.js"></script>
+<script src="../src/dom/get_attribute.js"></script>
+<script src="../src/dom/get_attributes.js"></script>
+<script src="../src/dom/is_loaded_image.js"></script>
+<script src="../src/dom/table.js"></script>
+<script src="../src/dom/query.js"></script>
+<script src="../src/dom/unwrap.js"></script>
+<script src="../src/dom/line_breaks.js"></script>
+<script src="../src/dom/get_pasted_html.js"></script>
+
+<script src="../src/quirks/clean_pasted_html.js"></script>
+<script src="../src/quirks/ensure_proper_clearing.js"></script>
+<script src="../src/quirks/get_correct_inner_html.js"></script>
+<script src="../src/quirks/redraw.js"></script>
+<script src="../src/quirks/table_cells_selection.js"></script>
+
+<script src="../src/selection/selection.js"></script>
+<script src="../src/selection/html_applier.js"></script>
+
+<script src="../src/commands.js"></script>
+<script src="../src/commands/bold.js"></script>
+<script src="../src/commands/createLink.js"></script>
+<script src="../src/commands/removeLink.js"></script>
+<script src="../src/commands/fontSize.js"></script>
+<script src="../src/commands/foreColor.js"></script>
+<script src="../src/commands/foreColorStyle.js"></script>
+<script src="../src/commands/formatBlock.js"></script>
+<script src="../src/commands/formatInline.js"></script>
+<script src="../src/commands/formatCode.js"></script>
+<script src="../src/commands/insertHTML.js"></script>
+<script src="../src/commands/insertImage.js"></script>
+<script src="../src/commands/insertLineBreak.js"></script>
+<script src="../src/commands/insertOrderedList.js"></script>
+<script src="../src/commands/insertUnorderedList.js"></script>
+<script src="../src/commands/insertList.js"></script>
+<script src="../src/commands/italic.js"></script>
+<script src="../src/commands/justifyCenter.js"></script>
+<script src="../src/commands/justifyLeft.js"></script>
+<script src="../src/commands/justifyRight.js"></script>
+<script src="../src/commands/justifyFull.js"></script>
+<script src="../src/commands/alignRightStyle.js"></script>
+<script src="../src/commands/alignLeftStyle.js"></script>
+<script src="../src/commands/alignCenterStyle.js"></script>
+<script src="../src/commands/redo.js"></script>
+<script src="../src/commands/underline.js"></script>
+<script src="../src/commands/undo.js"></script>
+<script src="../src/commands/addTableCells.js"></script>
+<script src="../src/commands/createTable.js"></script>
+<script src="../src/commands/deleteTableCells.js"></script>
+<script src="../src/commands/mergeTableCells.js"></script>
+<script src="../src/commands/indentList.js"></script>
+<script src="../src/commands/outdentList.js"></script>
+<script src="../src/commands/insertBlockQuote.js"></script>
+
+<script src="../src/undo_manager.js"></script>
+
+<script src="../src/views/view.js"></script>
+<script src="../src/views/composer.js"></script>
+<script src="../src/views/composer.style.js"></script>
+<script src="../src/views/composer.observe.js"></script>
+<script src="../src/views/synchronizer.js"></script>
+<script src="../src/views/textarea.js"></script>
+
+<script src="../src/toolbar/dialog.js"></script>
+<script src="../src/toolbar/dialog_foreColorStyle.js"></script>
+<script src="../src/toolbar/dialog_createTable.js"></script>
+<script src="../src/toolbar/speech.js"></script>
+<script src="../src/toolbar/toolbar.js"></script>
+
+<script src="../src/editor.js"></script>
+
+<!-- additions for iflameless -->
+<script src="../src/dom/contenteditable_area.js"></script>
+<!-- -->
+
+<script src="browser_test.js"></script>
+<script src="incompatible_test.js"></script>
+
+<script>
+ if (wysihtml5.browser.supported()) {
+ document.write(
+ '<script src="lang/array_test.js"><\/script>' +
+ '<script src="lang/object_test.js"><\/script>' +
+ '<script src="lang/string_test.js"><\/script>' +
+ '<script src="dom/auto_link_test.js"><\/script>' +
+ '<script src="dom/compare_document_position_test.js"><\/script>' +
+ '<script src="dom/contains_test.js"><\/script>' +
+ '<script src="dom/convert_to_list_test.js"><\/script>' +
+ '<script src="dom/copy_styles_test.js"><\/script>' +
+ '<script src="dom/copy_attributes_test.js"><\/script>' +
+ '<script src="dom/delegate_test.js"><\/script>' +
+ '<script src="dom/sandbox_test.js"><\/script>' +
+ '<script src="dom/observe_test.js"><\/script>' +
+ '<script src="dom/get_as_dom_test.js"><\/script>' +
+ '<script src="dom/get_parent_element_test.js"><\/script>' +
+ '<script src="dom/dom_node_test.js"><\/script>' +
+ '<script src="dom/get_style_test.js"><\/script>' +
+ '<script src="dom/has_element_with_tag_name_test.js"><\/script>' +
+ '<script src="dom/has_element_with_class_name_test.js"><\/script>' +
+ '<script src="dom/insert_css_test.js"><\/script>' +
+ '<script src="dom/resolve_list_test.js"><\/script>' +
+ '<script src="dom/rename_element_test.js"><\/script>' +
+ '<script src="dom/set_styles_test.js"><\/script>' +
+ '<script src="dom/set_attributes_test.js"><\/script>' +
+ '<script src="dom/parse_test.js"><\/script>' +
+ '<script src="dom/table_test.js"><\/script>' +
+ '<script src="dom/unwrap_test.js"><\/script>' +
+ '<script src="quirks/clean_pasted_html_test.js"><\/script>' +
+ '<script src="undo_manager_test.js"><\/script>' +
+ '<script src="editor_test.js"><\/script>' +
+ '<script src="editor_contenteditablemode_test.js"><\/script>' +
+ '<script src="editor_commands_test.js"><\/script>'
+ );
+ }
+</script>
+
+<h1 id="qunit-header">wysihtml5 - Test Suite</h1>
+<h2 id="qunit-banner"></h2>
+<div id="qunit-testrunner-toolbar"></div>
+<h2 id="qunit-userAgent"></h2>
+<ol id="qunit-tests"></ol>
--- /dev/null
+module("wysihtml5.lang.array");
+
+test("contains()", function() {
+ var arr = [1, "2", "foo"];
+ ok(wysihtml5.lang.array(arr).contains(1));
+ ok(!wysihtml5.lang.array(arr).contains(2));
+ ok(wysihtml5.lang.array(arr).contains("2"));
+ ok(wysihtml5.lang.array(arr).contains("foo"));
+});
+
+test("without()", function() {
+ var arr = [1, 2, 3];
+ deepEqual(wysihtml5.lang.array(arr).without([1]), [2, 3]);
+ deepEqual(wysihtml5.lang.array(arr).without([4]), [1, 2, 3]);
+});
+
+test("get()", function() {
+ var nodeList = document.getElementsByTagName("*"),
+ arr = wysihtml5.lang.array(nodeList).get();
+ equal(arr.length, nodeList.length);
+ ok(arr instanceof Array);
+});
\ No newline at end of file
--- /dev/null
+module("wysihtml5.lang.object");
+
+test("merge()", function() {
+ var obj = { foo: 1, bar: 1 },
+ returnValue = wysihtml5.lang.object(obj).merge({ bar: 2, baz: 3 }).get();
+ equal(returnValue, obj);
+ deepEqual(obj, { foo: 1, bar: 2, baz: 3 });
+});
+
+test("clone()", function() {
+ var obj = { foo: true },
+ returnValue = wysihtml5.lang.object(obj).clone();
+ ok(obj != returnValue);
+ deepEqual(obj, returnValue);
+});
+
+test("deep clone()", function() {
+ var obj = {
+ boo : {
+ foo: true
+ }
+ },
+ returnValueShallow = wysihtml5.lang.object(obj).clone(),
+ returnValueDeep = wysihtml5.lang.object(obj).clone(true);
+
+ ok(obj != returnValueShallow && obj.boo === returnValueShallow.boo);
+ deepEqual(obj, returnValueShallow);
+
+ ok(obj != returnValueDeep && obj.boo !== returnValueDeep.boo);
+ deepEqual(obj, returnValueDeep);
+});
+
+test("isArray()", function() {
+ ok(wysihtml5.lang.object([]).isArray());
+ ok(!wysihtml5.lang.object({}).isArray());
+ ok(!wysihtml5.lang.object(document.body.childNodes).isArray());
+ ok(!wysihtml5.lang.object("1,2,3").isArray());
+});
+
+test("isFunction()", function() {
+ ok(wysihtml5.lang.object(function() {}).isFunction());
+ ok(!wysihtml5.lang.object({}).isFunction());
+ ok(!wysihtml5.lang.object([]).isFunction());
+ ok(!wysihtml5.lang.object(document.body.childNodes).isFunction());
+ ok(!wysihtml5.lang.object("1,2,3").isFunction());
+});
\ No newline at end of file
--- /dev/null
+module("wysihtml5.lang.string");
+
+test("trim()", function() {
+ equal(wysihtml5.lang.string(" foo \n").trim(), "foo");
+});
+
+test("interpolate()", function() {
+ equal(
+ wysihtml5.lang.string("Hello #{name}, I LOVE YOUR NAME. IT'S VERY GERMAN AND SOUNDS STRONG.").interpolate({ name: "Reinhold" }),
+ "Hello Reinhold, I LOVE YOUR NAME. IT'S VERY GERMAN AND SOUNDS STRONG."
+ );
+});
+
+test("replace()", function() {
+ equal(
+ wysihtml5.lang.string("I LOVE CAKE").replace("CAKE").by("BOOBS"),
+ "I LOVE BOOBS"
+ );
+});
+
+test("escapeHTML()", function() {
+ equal(wysihtml5.lang.string('&<>"').escapeHTML(), "&<>"");
+});
\ No newline at end of file
--- /dev/null
+if (wysihtml5.browser.supported()) {
+ module("wysihtml5.quirks.cleanPastedHTML", {
+ setup: function() {
+ this.refNode = document.createElement("div");
+ this.refNode.style.fontSize = "24px";
+ this.refNode.style.color = "rgba(0,0,0)";
+ this.uneditableClass = "wysihtml5-uneditable-container";
+ },
+
+ teardown: function() {
+
+ }
+
+ });
+
+ test("Basic test", function(assert) {
+ var rules = {
+ tags: {
+ "u": {},
+ "a": {
+ "check_attributes": {
+ "href": "href",
+ "rel": "any",
+ "target": "any"
+ }
+ },
+ "b": {}
+ },
+ selectors: {
+ "a u": "unwrap"
+ }
+ };
+
+ var options = {
+ "referenceNode": this.refNode,
+ "rules": [{"set":rules}],
+ "uneditableClass": this.uneditableClass
+ };
+
+ assert.htmlEqual(
+ wysihtml5.quirks.cleanPastedHTML("<u>See: </u><a href=\"http://www.google.com\"><u><b>best search engine</b></u></a>", options),
+ "<u>See: </u><a href=\"http://www.google.com\"><b>best search engine</b></a>",
+ "Correctly removed <u> within <a>"
+ );
+ });
+
+ test("Non-breakable space test", function(assert) {
+ var options = {
+ "referenceNode": this.refNode,
+ "rules": [{"set": {}}],
+ "uneditableClass": this.uneditableClass
+ };
+
+ assert.htmlEqual(
+ wysihtml5.quirks.cleanPastedHTML("test ", options),
+ "test ",
+ "Correctly split nonbreakable spaces"
+ );
+ });
+
+ test("Ruleset picking tests", function(assert) {
+ var options = {
+ "referenceNode": this.refNode,
+ "rules": [
+ {
+ "condition": /class="?Mso/i,
+ "set": {
+ "tags": {
+ }
+ }
+ },
+ {
+ "set": {
+ "classes": "any",
+ "comments": 1,
+ "tags": {
+ "p": {},
+ "span": {}
+ }
+ }
+ }
+ ],
+ "uneditableClass": this.uneditableClass
+ };
+
+ assert.htmlEqual(
+ wysihtml5.quirks.cleanPastedHTML('<p class="MsoNormal">test</p>', options),
+ "test",
+ "Picked correctly to first ruleset"
+ );
+ assert.htmlEqual(
+ wysihtml5.quirks.cleanPastedHTML('<p class="MsoNormal">test<!-- secret comment here --></p>', options),
+ "test",
+ "First ruleset removes comments correctly"
+ );
+
+
+ assert.htmlEqual(
+ wysihtml5.quirks.cleanPastedHTML('<p class="SomeOtherClass">test</p>', options),
+ '<p class="SomeOtherClass">test</p>',
+ "Picked correctly to second ruleset"
+ );
+ assert.htmlEqual(
+ wysihtml5.quirks.cleanPastedHTML('<p class="SomeOtherClass">test<!-- secret comment here --></p>', options),
+ '<p class="SomeOtherClass">test<!-- secret comment here --></p>',
+ "Second ruleset keeps comments correctly"
+ );
+ });
+
+ test("Root color and font-size removal tests", function(assert) {
+ var options = {
+ "referenceNode": this.refNode,
+ "rules": [{"set": {
+ "tags": {
+ "span": {
+ "keep_styles": {
+ "color": 1,
+ "fontSize": 1
+ }
+ }
+ }
+ }}],
+ "uneditableClass": this.uneditableClass
+ };
+
+ assert.htmlEqual(
+ wysihtml5.quirks.cleanPastedHTML('<span style="color:rgba(0,0,0);font-size:24px;">test</span>', options),
+ 'test',
+ "Correctly removed defult styles"
+ );
+
+ assert.htmlEqual(
+ wysihtml5.quirks.cleanPastedHTML('<span style="color:rgb(1,2,3);">test</span>', options),
+ '<span style="color:rgb(1,2,3);">test</span>',
+ "Correctly kept different style"
+ );
+
+ assert.htmlEqual(
+ wysihtml5.quirks.cleanPastedHTML('<span style="color:rgb(1,2,3); font-size: 24px;">test</span>', options),
+ '<span style="color:rgb(1,2,3);">test</span>',
+ "Correctly moved one and kept another"
+ );
+
+ assert.htmlEqual(
+ wysihtml5.quirks.cleanPastedHTML('<span style="color:rgb(1,2,3); font-size: 35px;">test</span>', options),
+ '<span style="color:rgb(1,2,3); font-size: 35px;">test</span>',
+ "Correctly kept all styles"
+ );
+ });
+
+
+}
--- /dev/null
+if (wysihtml5.browser.supportsCommand(document, "insertHTML")) {
+
+ module("wysihtml5.UndoManager", {
+ setup: function() {
+ this.textareaElement = document.createElement("textarea");
+ this.textareaElement.value = "1";
+
+ document.body.appendChild(this.textareaElement);
+ },
+
+ teardown: function() {
+ var leftover;
+ while (leftover = document.querySelector("iframe.wysihtml5-sandbox, input[name='_wysihtml5_mode']")) {
+ leftover.parentNode.removeChild(leftover);
+ }
+ document.body.removeChild(this.textareaElement);
+ },
+
+ triggerUndo: function(editor) {
+ this.triggerKey(editor, 90);
+ },
+
+ triggerRedo: function(editor) {
+ this.triggerKey(editor, 89);
+ },
+
+ triggerKey: function(editor, keyCode) {
+ var event;
+ try {
+ event = editor.composer.sandbox.getDocument().createEvent("KeyEvents");
+ event.initKeyEvent("keydown", true, true, editor.composer.sandbox.getWindow(), true, false, false, false, keyCode, keyCode);
+ } catch(e) {
+ event = editor.composer.sandbox.getDocument().createEvent("Events");
+ event.initEvent("keydown", true, true);
+ event.ctrlKey = true;
+ event.keyCode = keyCode;
+ }
+ editor.composer.element.dispatchEvent(event);
+ }
+ });
+
+
+ asyncTest("Basic test", function() {
+ expect(5);
+
+ var that = this,
+ editor = new wysihtml5.Editor(this.textareaElement);
+ editor.on("load", function() {
+ editor.setValue("1 2").fire("newword:composer");
+ editor.setValue("1 2 3").fire("newword:composer");
+ editor.setValue("1 2 3 4").fire("newword:composer");
+ editor.setValue("1 2 3 4 5");
+
+ that.triggerUndo(editor);
+ equal(editor.getValue(false, false), "1 2 3 4");
+ that.triggerRedo(editor);
+ that.triggerRedo(editor);
+ equal(editor.getValue(false, false), "1 2 3 4 5");
+ that.triggerUndo(editor);
+ that.triggerUndo(editor);
+ equal(editor.getValue(false, false), "1 2 3");
+ that.triggerUndo(editor);
+ that.triggerUndo(editor);
+ equal(editor.getValue(false, false), "1");
+ that.triggerUndo(editor);
+ that.triggerUndo(editor);
+ equal(editor.getValue(false, false), "1");
+
+ start();
+ });
+ });
+
+
+ asyncTest("Test commands", function() {
+ expect(3);
+
+ var that = this,
+ editor = new wysihtml5.Editor(this.textareaElement);
+ editor.on("load", function() {
+ editor.setValue("<b>1</b>").fire("beforecommand:composer");
+ editor.setValue("<i><b>1</b></i>").fire("beforecommand:composer");
+
+ that.triggerUndo(editor);
+ equal(editor.getValue(false, false), "<b>1</b>");
+ that.triggerRedo(editor);
+ equal(editor.getValue(false, false), "<i><b>1</b></i>");
+ that.triggerUndo(editor);
+ that.triggerUndo(editor);
+ equal(editor.getValue(false, false), "1");
+
+ start();
+ });
+ });
+}
--- /dev/null
+{% load wysihtml5 %}
+<div id="{{ attrs.id }}-toolbar">
+ {% toolbar_button "bold" %}
+ {% toolbar_button "italic" %}
+ {% toolbar_button "formatBlock" "header" "H1" "h1" %}
+ {% toolbar_button "formatBlock" "paragraph" "Paragraph" "p" %}
+ {% toolbar_button "insertUnorderedList" "list-ul" "Unordered list" %}
+ {% toolbar_button "insertOrderedList" "list-ol" "Ordered list" %}
+ {% toolbar_button "createLink" "link" "Link" %}
+ {% toolbar_button "removeLink" "unlink" "Unlink" %}
+ <div data-wysihtml5-dialog="createLink" style="display: none;">
+ Link: <input data-wysihtml5-dialog-field="href" value="http://">
+ <a data-wysihtml5-dialog-action="save" class='button'>OK</a> <a data-wysihtml5-dialog-action="cancel" class='button secondary'>Cancel</a>
+ </div>
+</div>
+<textarea id="{{ attrs.id }}" name="{{ name }}" role='wysihtml5-rich-text' rows=10 cols=40>{{ value|safe }}</textarea>
--- /dev/null
+from django import template
+from django.utils.safestring import mark_safe
+
+register = template.Library()
+
+@register.simple_tag
+def toolbar_button(command, icon=None, alt=None, value=None, classes="button secondary"):
+ if icon is None:
+ icon = command
+ if alt is None:
+ alt = command
+ if value is None:
+ value = ""
+ else:
+ value = "data-wysihtml5-command-value='{}'".format(value)
+ button = mark_safe("""<button role='button'
+ class='{classes}'
+ data-wysihtml5-command='{command}'
+ {value}><i class='fa fa-{icon}' aria-label='{alt}'></i></button>""".format(
+ command=command,
+ value=value,
+ icon=icon,
+ alt=alt,
+ classes=classes
+ ))
+ print button
+ return button
+
+
--- /dev/null
+from django import forms
+from django.conf import settings
+from django.utils.safestring import mark_safe
+from django.template.loader import render_to_string
+
+class RichTextEditor(forms.Textarea):
+ def render(self, name, value, attrs=None):
+ return mark_safe(render_to_string("wysihtml5/widget.html", {
+ "name": name,
+ "value": value,
+ "attrs": attrs,
+ }))
+
+ class Media:
+ css = {'all': (settings.STATIC_URL + "wysihtml5/toolbar.css",)}
+ js = (
+ settings.STATIC_URL + "wysihtml5/wysihtml-0.4.17/dist/wysihtml5x-toolbar.min.js",
+ settings.STATIC_URL + "wysihtml5/wysihtml-0.4.17/parser_rules/advanced_and_extended.js",
+ settings.STATIC_URL + "wysihtml5/init.js",
+ )
+
+
function writeNoteFrame(contents) {
var dstFrame = document.getElementById('noteframe');
- var dstDoc = dstFrame.contentDocument || dstFrame.contentWindow.document;
- dstDoc.write(contents);
- dstDoc.close();
+ if (dstFrame) {
+ var dstDoc = dstFrame.contentDocument || dstFrame.contentWindow.document;
+ dstDoc.write(contents);
+ dstDoc.close();
+ }
}
function setupAnnotator(noteElement, readOnly) {
writeNoteFrame(data);
// run setupAnnotator in frame context
- var noteframe = document.getElementById('noteframe').contentWindow;
+ var parentFrame = document.getElementById('noteframe');
+ if (!parentFrame) {
+ return;
+ }
+ var noteframe = parentFrame.contentWindow;
injectRemoteCSS(annotator_css_url, noteframe);
injectScript("csrf_token = '" + csrf_token + "';", noteframe);
'karmaworld.apps.moderation',
'karmaworld.apps.licenses',
'karmaworld.apps.quizzes',
+ 'karmaworld.apps.wysihtml5',
)
# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
{% compress css %}
<link rel="stylesheet" type="text/css" media="all" href="{{ STATIC_URL }}css/note_course_pages.css">
<link rel="stylesheet" type="text/css" media="all" href="{{ STATIC_URL }}css/annotator.min.css" />
+ {{ note_edit_form.media.css }}
{% endcompress %}
{% endblock %}
<script src="{{ STATIC_URL }}js/pxem.jQuery.js"></script>
<script src="{{ STATIC_URL }}js/marked.js" ></script>
<script src="{{ STATIC_URL }}js/annotator-full.min.js"></script>
+ {{ note_edit_form.media.js }}
{% endcompress %}
<script>
{% if show_note_container %}
});
{% endif %}
</script>
+ <script type="text/javascript">
+ // wysihtml5 doesn't init correctly in a hidden div. So we remove it every
+ // time before showing it in the modal.
+
+ // This event will be renamed "open.fndtn.reveal" in future foundation:
+ // http://foundation.zurb.com/docs/components/reveal.html#event-bindings
+ $(document).on("open", "#note-edit-dialog", function() {
+ $(".wysihtml5-sandbox, .wysihtml5-toolbar").remove();
+ $("[role='wysihtml5-rich-text']").show();
+ initWysihtml5(document.querySelector("[role='wysihtml5-rich-text']"));
+ });
+ </script>
{% endblock %}
{% block raw_content %}
<p>{{ field.help_text }}</p>
{% endwith %}
</div>
+ <div class="small-12 columns">
+ {% with note_edit_form.html as field %}
+ {{ field.errors|safe }}
+ <label for="{{ field.id_for_label }}">{{ field.label }}:</label>
+ {{ field }}
+ <p>{{ field.help_text }}</p>
+ {% endwith %}
+ </div>
<div class="small-12 columns text-center">
<button type="submit"><i class="fa fa-save"></i> Save</button>
</div>
<div class="small-12 small-centered columns medium-12 large-12 body_copy">
<div id="note-content-wrapper" class="note-text">
{% if note.has_markdown %}
- <span id="note-markdown" data-markdown="{{note.notemarkdown.markdown}}"></span>
+ <div class='note-html'>
+ {{ note.notemarkdown.html|safe }}
+ </div>
{% else %}
<iframe style="border:none; width:100%; min-height: 1000px;"
id="noteframe"></iframe>
</div> <!-- .note-text -->
</div><!-- /body_copy -->
</div>
-</div><!-- /note_container -->
\ No newline at end of file
+</div><!-- /note_container -->
amqplib==1.0.2
django-sslify>=0.2
newrelic==2.40.0.34
+bleach==1.4
+bleach-whitelist==0.0.4
+Markdown==2.5.2