|
@ -16,7 +16,8 @@
|
|||
"Tether",
|
||||
"Tooltip",
|
||||
"Drop",
|
||||
"Dropzone"
|
||||
"Dropzone",
|
||||
"dragula"
|
||||
],
|
||||
"browser": true,
|
||||
"boss": true,
|
||||
|
|
|
@ -34,7 +34,7 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
|
|||
didReceiveAttrs: function() {
|
||||
this.set('showToc', is.not.undefined(this.get('pages')) && this.get('pages').get('length') > 2);
|
||||
if (is.not.null(this.get('page'))) {
|
||||
this.send('clickGotoPage', this.get('page'));
|
||||
this.send('onEntryClick', this.get('page'));
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -52,6 +52,7 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
|
|||
|
||||
var s = $(".document-structure");
|
||||
var pos = s.position();
|
||||
|
||||
$(window).scroll(function() {
|
||||
var windowpos = $(window).scrollTop();
|
||||
if (windowpos - 200 >= pos.top) {
|
||||
|
@ -69,7 +70,7 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
|
|||
},
|
||||
|
||||
onDocumentPageAdded(pageId) {
|
||||
this.send('clickGotoPage', pageId);
|
||||
this.send('onEntryClick', pageId);
|
||||
},
|
||||
|
||||
// Controls what user can do with the toc (left sidebar).
|
||||
|
@ -253,7 +254,7 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
|
|||
|
||||
this.attrs.changePageSequence(pendingChanges);
|
||||
|
||||
this.send('clickGotoPage', this.get('page'));
|
||||
this.send('onEntryClick', this.get('page'));
|
||||
this.audit.record("moved-page-up");
|
||||
this.showNotification("Moved up");
|
||||
},
|
||||
|
@ -326,7 +327,7 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
|
|||
|
||||
this.attrs.changePageSequence(pendingChanges);
|
||||
|
||||
this.send('clickGotoPage', this.get('page'));
|
||||
this.send('onEntryClick', this.get('page'));
|
||||
this.audit.record("moved-page-down");
|
||||
this.showNotification("Moved down");
|
||||
},
|
||||
|
@ -362,9 +363,9 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
|
|||
|
||||
this.attrs.changePageLevel(pendingChanges);
|
||||
|
||||
this.send('clickGotoPage', this.get('page'));
|
||||
this.audit.record("changed-page-sequence");
|
||||
this.showNotification("Indent");
|
||||
this.audit.record("changed-page-sequence");
|
||||
this.send('onEntryClick', this.get('page'));
|
||||
},
|
||||
|
||||
// Outdent - changes a page from H3 to H2, etc.
|
||||
|
@ -397,12 +398,13 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
|
|||
}
|
||||
|
||||
this.attrs.changePageLevel(pendingChanges);
|
||||
this.audit.record("changed-page-sequence");
|
||||
|
||||
this.showNotification("Outdent");
|
||||
this.send('clickGotoPage', this.get('page'));
|
||||
this.audit.record("changed-page-sequence");
|
||||
this.send('onEntryClick', this.get('page'));
|
||||
},
|
||||
|
||||
clickGotoPage(id) {
|
||||
onEntryClick(id) {
|
||||
this.setState(id);
|
||||
this.attrs.gotoPage(id);
|
||||
},
|
||||
|
|
|
@ -10,10 +10,28 @@
|
|||
// https://documize.com
|
||||
|
||||
import Ember from 'ember';
|
||||
import models from '../../utils/model';
|
||||
import TooltipMixin from '../../mixins/tooltip';
|
||||
|
||||
export default Ember.Component.extend(TooltipMixin, {
|
||||
sectionService: Ember.inject.service('section'),
|
||||
documentService: Ember.inject.service('document'),
|
||||
|
||||
export default Ember.Component.extend({
|
||||
document: {},
|
||||
folder: {},
|
||||
sections: [],
|
||||
showToc: true,
|
||||
showSectionList: false,
|
||||
|
||||
// didRender() {
|
||||
// if (this.get('isEditor')) {
|
||||
// this.addTooltip(document.getElementById("add-section-button"));
|
||||
// }
|
||||
// },
|
||||
|
||||
// willDestroyElement() {
|
||||
// this.destroyTooltips();
|
||||
// },
|
||||
|
||||
actions: {
|
||||
// Page up - above pages shunt down.
|
||||
|
@ -21,7 +39,7 @@ export default Ember.Component.extend({
|
|||
this.attrs.changePageSequence(pendingChanges);
|
||||
},
|
||||
|
||||
// Move down -- pages below shift up.
|
||||
// Move down - pages below shift up.
|
||||
onPageLevelChange(pendingChanges) {
|
||||
this.attrs.changePageLevel(pendingChanges);
|
||||
},
|
||||
|
@ -29,5 +47,47 @@ export default Ember.Component.extend({
|
|||
gotoPage(id) {
|
||||
return this.attrs.gotoPage(id);
|
||||
},
|
||||
|
||||
addSection() {
|
||||
let self = this;
|
||||
|
||||
this.get('sectionService').getAll().then(function(sections) {
|
||||
self.set('sections', sections);
|
||||
self.set('showToc', false);
|
||||
self.set('showSectionList', true);
|
||||
});
|
||||
},
|
||||
|
||||
showToc() {
|
||||
this.set('showSectionList', false);
|
||||
this.set('showToc', true);
|
||||
},
|
||||
|
||||
onAddSection(section) {
|
||||
this.audit.record("added-section");
|
||||
this.audit.record("added-section-" + section.contentType);
|
||||
|
||||
let page = models.PageModel.create({
|
||||
documentId: this.get('document.id'),
|
||||
title: `${section.title} Section`,
|
||||
level: 2,
|
||||
sequence: 2048,
|
||||
body: "",
|
||||
contentType: section.contentType
|
||||
});
|
||||
|
||||
let meta = models.PageMetaModel.create({
|
||||
documentId: this.get('document.id'),
|
||||
rawBody: "",
|
||||
config: ""
|
||||
});
|
||||
|
||||
let model = {
|
||||
page: page,
|
||||
meta: meta
|
||||
};
|
||||
|
||||
this.attrs.onAddPage(model);
|
||||
}
|
||||
}
|
||||
});
|
|
@ -24,7 +24,6 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
|
|||
|
||||
didRender() {
|
||||
if (this.get('isEditor')) {
|
||||
this.addTooltip(document.getElementById("add-section-button"));
|
||||
this.addTooltip(document.getElementById("attachment-button"));
|
||||
this.addTooltip(document.getElementById("save-template-button"));
|
||||
this.addTooltip(document.getElementById("set-meta-button"));
|
||||
|
|
34
app/app/components/document/index-entry.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Component.extend({
|
||||
page: {},
|
||||
tagName: "li",
|
||||
classNames: ["item"],
|
||||
|
||||
indentLevel: Ember.computed('page', function() {
|
||||
let nodeLevel = this.get('page.level');
|
||||
let indent = (nodeLevel - 1) * 20;
|
||||
return indent;
|
||||
}),
|
||||
|
||||
didReceiveAttrs() {
|
||||
this.set('classNames', ["item", "margin-left-" + this.get("indentLevel")]);
|
||||
},
|
||||
|
||||
actions: {
|
||||
onClick(id) {
|
||||
this.get('onClick')(id);
|
||||
}
|
||||
}
|
||||
});
|
|
@ -13,55 +13,15 @@ import Ember from 'ember';
|
|||
import NotifierMixin from '../../mixins/notifier';
|
||||
|
||||
export default Ember.Component.extend(NotifierMixin, {
|
||||
title: "New Section",
|
||||
contentType: "",
|
||||
|
||||
didReceiveAttrs() {
|
||||
let section = this.get("sections").get('firstObject');
|
||||
section.set("selected", true);
|
||||
},
|
||||
|
||||
didInsertElement() {
|
||||
$("#page-title").removeClass("error").focus();
|
||||
},
|
||||
|
||||
actions: {
|
||||
setOption(id) {
|
||||
let sections = this.get("sections");
|
||||
|
||||
sections.forEach(function(option) {
|
||||
Ember.set(option, 'selected', option.id === id);
|
||||
});
|
||||
|
||||
this.set("sections", sections);
|
||||
|
||||
// if (this.session.get('popupBlocked')) {
|
||||
// this.showNotification("Hmm, looks like your browser is blocking popups...");
|
||||
// }
|
||||
},
|
||||
|
||||
onCancel() {
|
||||
this.attrs.onCancel();
|
||||
},
|
||||
|
||||
onAction() {
|
||||
let title = this.get("title");
|
||||
let section = this.get("sections").findBy("selected", true);
|
||||
let contentType = section.contentType;
|
||||
addSection(section) {
|
||||
|
||||
if (section.preview) {
|
||||
this.showNotification("Coming soon!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (is.empty(title)) {
|
||||
$("#page-title").addClass("error").focus();
|
||||
return;
|
||||
}
|
||||
|
||||
this.audit.record('added section ' + section.contentType);
|
||||
|
||||
this.attrs.onAction(title, contentType);
|
||||
this.attrs.onAction(section);
|
||||
}
|
||||
}
|
||||
});
|
|
@ -1,34 +0,0 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
import Ember from 'ember';
|
||||
|
||||
export function documentTocEntry(params) {
|
||||
let currentPage = params[0];
|
||||
let nodeId = params[1];
|
||||
let nodeLevel = params[2];
|
||||
let html = "";
|
||||
let indent = (nodeLevel - 1) * 20;
|
||||
|
||||
html += "<span style='margin-left: " + indent + "px;'></span>";
|
||||
|
||||
if (currentPage === nodeId) {
|
||||
html += "<span class='selected'></span>";
|
||||
html += "";
|
||||
} else {
|
||||
html += "<span class=''></span>";
|
||||
html += "";
|
||||
}
|
||||
|
||||
return new Ember.Handlebars.SafeString(html);
|
||||
}
|
||||
|
||||
export default Ember.Helper.helper(documentTocEntry);
|
|
@ -54,11 +54,11 @@ export default Ember.Controller.extend(NotifierMixin, {
|
|||
},
|
||||
|
||||
onPageSequenceChange(changes) {
|
||||
var self = this;
|
||||
let self = this;
|
||||
|
||||
this.get('documentService').changePageSequence(this.model.get('id'), changes).then(function() {
|
||||
_.each(changes, function(change) {
|
||||
var pageContent = _.findWhere(self.get('pages'), {
|
||||
let pageContent = _.findWhere(self.get('pages'), {
|
||||
id: change.pageId
|
||||
});
|
||||
|
||||
|
@ -72,19 +72,23 @@ export default Ember.Controller.extend(NotifierMixin, {
|
|||
},
|
||||
|
||||
onPageLevelChange(changes) {
|
||||
var self = this;
|
||||
let pages = this.get('pages');
|
||||
let self = this;
|
||||
|
||||
this.get('documentService').changePageLevel(this.model.get('id'), changes).then(function() {
|
||||
_.each(changes, function(change) {
|
||||
let pageContent = pages.findBy("id", change.pageId);
|
||||
let pageContent = _.findWhere(self.get('pages'), {
|
||||
id: change.pageId
|
||||
});
|
||||
|
||||
if (is.not.undefined(pageContent)) {
|
||||
pageContent.set('level', change.level);
|
||||
}
|
||||
});
|
||||
|
||||
self.set('pages', _.sortBy(self.get('pages'), "sequence"));
|
||||
let pages = self.get('pages');
|
||||
pages = _.sortBy(pages, "sequence");
|
||||
self.set('pages', []);
|
||||
self.set('pages', pages);
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -171,6 +175,19 @@ export default Ember.Controller.extend(NotifierMixin, {
|
|||
this.get('documentService').save(doc).then(function() {
|
||||
self.set('model', doc);
|
||||
});
|
||||
},
|
||||
|
||||
onAddPage(page) {
|
||||
let self = this;
|
||||
|
||||
this.get('documentService').addPage(this.get('model.id'), page).then(function(newPage) {
|
||||
self.transitionToRoute('document.edit',
|
||||
self.get('folder.id'),
|
||||
self.get('folder.slug'),
|
||||
self.get('model.id'),
|
||||
self.get('model.slug'),
|
||||
newPage.id);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
|
@ -8,7 +8,7 @@
|
|||
<div class="container-fluid background-color-white">
|
||||
<div class="row">
|
||||
<div class="col-lg-3 col-md-3 col-sm-3">
|
||||
{{document/document-sidebar document=model meta=meta folder=folder pages=pages page=page isEditor=isEditor changePageSequence=(action 'onPageSequenceChange') changePageLevel=(action 'onPageLevelChange') gotoPage=(action 'gotoPage')}}
|
||||
{{document/document-sidebar document=model meta=meta folder=folder pages=pages page=page isEditor=isEditor onAddPage=(action 'onAddPage') changePageSequence=(action 'onPageSequenceChange') changePageLevel=(action 'onPageLevelChange') gotoPage=(action 'gotoPage')}}
|
||||
</div>
|
||||
<div class="col-lg-9 col-md-9 col-sm-9">
|
||||
{{document/document-view document=model pages=pages attachments=attachments folder=folder folders=folders isEditor=isEditor onAttachmentDeleted=(action 'onAttachmentDeleted') onDeletePage=(action 'onPageDeleted')}}
|
||||
|
|
|
@ -34,3 +34,5 @@
|
|||
@import "section/gemini.scss";
|
||||
@import "section/github.scss";
|
||||
@import "section/markdown.scss";
|
||||
@import "section/table.scss";
|
||||
@import "section/code.scss";
|
||||
|
|
495
app/app/styles/section/code.scss
Normal file
|
@ -0,0 +1,495 @@
|
|||
/* BASICS */
|
||||
.CodeMirror {
|
||||
/* Set height, width, borders, and global font properties here */
|
||||
font-family: monospace;
|
||||
height: 300px;
|
||||
color: black;
|
||||
}
|
||||
|
||||
/* PADDING */
|
||||
|
||||
.CodeMirror-lines {
|
||||
padding: 4px 0; /* Vertical padding around content */
|
||||
}
|
||||
.CodeMirror pre {
|
||||
padding: 0 4px; /* Horizontal padding of content */
|
||||
}
|
||||
|
||||
.CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
|
||||
background-color: white; /* The little square between H and V scrollbars */
|
||||
}
|
||||
|
||||
/* GUTTER */
|
||||
|
||||
.CodeMirror-gutters {
|
||||
border-right: 1px solid #ddd;
|
||||
background-color: #f7f7f7;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.CodeMirror-linenumbers {}
|
||||
.CodeMirror-linenumber {
|
||||
padding: 0 3px 0 5px;
|
||||
min-width: 20px;
|
||||
text-align: right;
|
||||
color: #999;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.CodeMirror-guttermarker { color: black; }
|
||||
.CodeMirror-guttermarker-subtle { color: #999; }
|
||||
|
||||
/* CURSOR */
|
||||
|
||||
.CodeMirror-cursor {
|
||||
border-left: 1px solid black;
|
||||
border-right: none;
|
||||
width: 0;
|
||||
}
|
||||
/* Shown when moving in bi-directional text */
|
||||
.CodeMirror div.CodeMirror-secondarycursor {
|
||||
border-left: 1px solid silver;
|
||||
}
|
||||
.cm-fat-cursor .CodeMirror-cursor {
|
||||
width: auto;
|
||||
border: 0;
|
||||
background: #7e7;
|
||||
}
|
||||
.cm-fat-cursor div.CodeMirror-cursors {
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.cm-animate-fat-cursor {
|
||||
width: auto;
|
||||
border: 0;
|
||||
-webkit-animation: blink 1.06s steps(1) infinite;
|
||||
-moz-animation: blink 1.06s steps(1) infinite;
|
||||
animation: blink 1.06s steps(1) infinite;
|
||||
background-color: #7e7;
|
||||
}
|
||||
@-moz-keyframes blink {
|
||||
0% {}
|
||||
50% { background-color: transparent; }
|
||||
100% {}
|
||||
}
|
||||
@-webkit-keyframes blink {
|
||||
0% {}
|
||||
50% { background-color: transparent; }
|
||||
100% {}
|
||||
}
|
||||
@keyframes blink {
|
||||
0% {}
|
||||
50% { background-color: transparent; }
|
||||
100% {}
|
||||
}
|
||||
|
||||
/* Can style cursor different in overwrite (non-insert) mode */
|
||||
.CodeMirror-overwrite .CodeMirror-cursor {}
|
||||
|
||||
.cm-tab { display: inline-block; text-decoration: inherit; }
|
||||
|
||||
.CodeMirror-ruler {
|
||||
border-left: 1px solid #ccc;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
/* DEFAULT THEME */
|
||||
|
||||
.cm-s-default .cm-header {color: blue;}
|
||||
.cm-s-default .cm-quote {color: #090;}
|
||||
.cm-negative {color: #d44;}
|
||||
.cm-positive {color: #292;}
|
||||
.cm-header, .cm-strong {font-weight: bold;}
|
||||
.cm-em {font-style: italic;}
|
||||
.cm-link {text-decoration: underline;}
|
||||
.cm-strikethrough {text-decoration: line-through;}
|
||||
|
||||
.cm-s-default .cm-keyword {color: #708;}
|
||||
.cm-s-default .cm-atom {color: #219;}
|
||||
.cm-s-default .cm-number {color: #164;}
|
||||
.cm-s-default .cm-def {color: #00f;}
|
||||
.cm-s-default .cm-variable,
|
||||
.cm-s-default .cm-punctuation,
|
||||
.cm-s-default .cm-property,
|
||||
.cm-s-default .cm-operator {}
|
||||
.cm-s-default .cm-variable-2 {color: #05a;}
|
||||
.cm-s-default .cm-variable-3 {color: #085;}
|
||||
.cm-s-default .cm-comment {color: #a50;}
|
||||
.cm-s-default .cm-string {color: #a11;}
|
||||
.cm-s-default .cm-string-2 {color: #f50;}
|
||||
.cm-s-default .cm-meta {color: #555;}
|
||||
.cm-s-default .cm-qualifier {color: #555;}
|
||||
.cm-s-default .cm-builtin {color: #30a;}
|
||||
.cm-s-default .cm-bracket {color: #997;}
|
||||
.cm-s-default .cm-tag {color: #170;}
|
||||
.cm-s-default .cm-attribute {color: #00c;}
|
||||
.cm-s-default .cm-hr {color: #999;}
|
||||
.cm-s-default .cm-link {color: #00c;}
|
||||
|
||||
.cm-s-default .cm-error {color: #f00;}
|
||||
.cm-invalidchar {color: #f00;}
|
||||
|
||||
.CodeMirror-composing { border-bottom: 2px solid; }
|
||||
|
||||
/* Default styles for common addons */
|
||||
|
||||
div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
|
||||
div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
|
||||
.CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); }
|
||||
.CodeMirror-activeline-background {background: #e8f2ff;}
|
||||
|
||||
/* STOP */
|
||||
|
||||
/* The rest of this file contains styles related to the mechanics of
|
||||
the editor. You probably shouldn't touch them. */
|
||||
|
||||
.CodeMirror {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
background: white;
|
||||
}
|
||||
|
||||
.CodeMirror-scroll {
|
||||
overflow: scroll !important; /* Things will break if this is overridden */
|
||||
/* 30px is the magic margin used to hide the element's real scrollbars */
|
||||
/* See overflow: hidden in .CodeMirror */
|
||||
margin-bottom: -30px; margin-right: -30px;
|
||||
padding-bottom: 30px;
|
||||
height: 100%;
|
||||
outline: none; /* Prevent dragging from highlighting the element */
|
||||
position: relative;
|
||||
}
|
||||
.CodeMirror-sizer {
|
||||
position: relative;
|
||||
border-right: 30px solid transparent;
|
||||
}
|
||||
|
||||
/* The fake, visible scrollbars. Used to force redraw during scrolling
|
||||
before actual scrolling happens, thus preventing shaking and
|
||||
flickering artifacts. */
|
||||
.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
|
||||
position: absolute;
|
||||
z-index: 6;
|
||||
display: none;
|
||||
}
|
||||
.CodeMirror-vscrollbar {
|
||||
right: 0; top: 0;
|
||||
overflow-x: hidden;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
.CodeMirror-hscrollbar {
|
||||
bottom: 0; left: 0;
|
||||
overflow-y: hidden;
|
||||
overflow-x: scroll;
|
||||
}
|
||||
.CodeMirror-scrollbar-filler {
|
||||
right: 0; bottom: 0;
|
||||
}
|
||||
.CodeMirror-gutter-filler {
|
||||
left: 0; bottom: 0;
|
||||
}
|
||||
|
||||
.CodeMirror-gutters {
|
||||
position: absolute; left: 0; top: 0;
|
||||
z-index: 3;
|
||||
}
|
||||
.CodeMirror-gutter {
|
||||
white-space: normal;
|
||||
height: 100%;
|
||||
display: inline-block;
|
||||
margin-bottom: -30px;
|
||||
/* Hack to make IE7 behave */
|
||||
*zoom:1;
|
||||
*display:inline;
|
||||
}
|
||||
.CodeMirror-gutter-wrapper {
|
||||
position: absolute;
|
||||
z-index: 4;
|
||||
background: none !important;
|
||||
border: none !important;
|
||||
}
|
||||
.CodeMirror-gutter-background {
|
||||
position: absolute;
|
||||
top: 0; bottom: 0;
|
||||
z-index: 4;
|
||||
}
|
||||
.CodeMirror-gutter-elt {
|
||||
position: absolute;
|
||||
cursor: default;
|
||||
z-index: 4;
|
||||
}
|
||||
.CodeMirror-gutter-wrapper {
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.CodeMirror-lines {
|
||||
cursor: text;
|
||||
min-height: 1px; /* prevents collapsing before first draw */
|
||||
}
|
||||
.CodeMirror pre {
|
||||
/* Reset some styles that the rest of the page might have set */
|
||||
-moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
|
||||
border-width: 0;
|
||||
background: transparent;
|
||||
font-family: inherit;
|
||||
font-size: inherit;
|
||||
margin: 0;
|
||||
white-space: pre;
|
||||
word-wrap: normal;
|
||||
line-height: inherit;
|
||||
color: inherit;
|
||||
z-index: 2;
|
||||
position: relative;
|
||||
overflow: visible;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
.CodeMirror-wrap pre {
|
||||
word-wrap: break-word;
|
||||
white-space: pre-wrap;
|
||||
word-break: normal;
|
||||
}
|
||||
|
||||
.CodeMirror-linebackground {
|
||||
position: absolute;
|
||||
left: 0; right: 0; top: 0; bottom: 0;
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.CodeMirror-linewidget {
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.CodeMirror-widget {}
|
||||
|
||||
.CodeMirror-code {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
/* Force content-box sizing for the elements where we expect it */
|
||||
.CodeMirror-scroll,
|
||||
.CodeMirror-sizer,
|
||||
.CodeMirror-gutter,
|
||||
.CodeMirror-gutters,
|
||||
.CodeMirror-linenumber {
|
||||
-moz-box-sizing: content-box;
|
||||
box-sizing: content-box;
|
||||
}
|
||||
|
||||
.CodeMirror-measure {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 0;
|
||||
overflow: hidden;
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
.CodeMirror-cursor { position: absolute; }
|
||||
.CodeMirror-measure pre { position: static; }
|
||||
|
||||
div.CodeMirror-cursors {
|
||||
visibility: hidden;
|
||||
position: relative;
|
||||
z-index: 3;
|
||||
}
|
||||
div.CodeMirror-dragcursors {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.CodeMirror-focused div.CodeMirror-cursors {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.CodeMirror-selected { background: #d9d9d9; }
|
||||
.CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
|
||||
.CodeMirror-crosshair { cursor: crosshair; }
|
||||
.CodeMirror-line::selection, .CodeMirror-line > span::selection, .CodeMirror-line > span > span::selection { background: #d7d4f0; }
|
||||
.CodeMirror-line::-moz-selection, .CodeMirror-line > span::-moz-selection, .CodeMirror-line > span > span::-moz-selection { background: #d7d4f0; }
|
||||
|
||||
.cm-searching {
|
||||
background: #ffa;
|
||||
background: rgba(255, 255, 0, .4);
|
||||
}
|
||||
|
||||
/* IE7 hack to prevent it from returning funny offsetTops on the spans */
|
||||
.CodeMirror span { *vertical-align: text-bottom; }
|
||||
|
||||
/* Used to force a border model for a node */
|
||||
.cm-force-border { padding-right: .1px; }
|
||||
|
||||
@media print {
|
||||
/* Hide the cursor when printing */
|
||||
.CodeMirror div.CodeMirror-cursors {
|
||||
visibility: hidden;
|
||||
}
|
||||
}
|
||||
|
||||
/* See issue #2901 */
|
||||
.cm-tab-wrap-hack:after { content: ''; }
|
||||
|
||||
/* Help users use markselection to safely style text background */
|
||||
span.CodeMirror-selectedtext { background: none; }
|
||||
|
||||
/*
|
||||
Solarized theme for code-mirror
|
||||
http://ethanschoonover.com/solarized
|
||||
*/
|
||||
|
||||
/*
|
||||
Solarized color pallet
|
||||
http://ethanschoonover.com/solarized/img/solarized-palette.png
|
||||
*/
|
||||
|
||||
.solarized.base03 { color: #002b36; }
|
||||
.solarized.base02 { color: #073642; }
|
||||
.solarized.base01 { color: #586e75; }
|
||||
.solarized.base00 { color: #657b83; }
|
||||
.solarized.base0 { color: #839496; }
|
||||
.solarized.base1 { color: #93a1a1; }
|
||||
.solarized.base2 { color: #eee8d5; }
|
||||
.solarized.base3 { color: #fdf6e3; }
|
||||
.solarized.solar-yellow { color: #b58900; }
|
||||
.solarized.solar-orange { color: #cb4b16; }
|
||||
.solarized.solar-red { color: #dc322f; }
|
||||
.solarized.solar-magenta { color: #d33682; }
|
||||
.solarized.solar-violet { color: #6c71c4; }
|
||||
.solarized.solar-blue { color: #268bd2; }
|
||||
.solarized.solar-cyan { color: #2aa198; }
|
||||
.solarized.solar-green { color: #859900; }
|
||||
|
||||
/* Color scheme for code-mirror */
|
||||
|
||||
.cm-s-solarized {
|
||||
line-height: 1.45em;
|
||||
color-profile: sRGB;
|
||||
rendering-intent: auto;
|
||||
}
|
||||
.cm-s-solarized.cm-s-dark {
|
||||
color: #839496;
|
||||
background-color: #002b36;
|
||||
text-shadow: #002b36 0 1px;
|
||||
}
|
||||
.cm-s-solarized.cm-s-light {
|
||||
background-color: #fdf6e3;
|
||||
color: #657b83;
|
||||
text-shadow: #eee8d5 0 1px;
|
||||
}
|
||||
|
||||
.cm-s-solarized .CodeMirror-widget {
|
||||
text-shadow: none;
|
||||
}
|
||||
|
||||
.cm-s-solarized .cm-header { color: #586e75; }
|
||||
.cm-s-solarized .cm-quote { color: #93a1a1; }
|
||||
|
||||
.cm-s-solarized .cm-keyword { color: #cb4b16; }
|
||||
.cm-s-solarized .cm-atom { color: #d33682; }
|
||||
.cm-s-solarized .cm-number { color: #d33682; }
|
||||
.cm-s-solarized .cm-def { color: #2aa198; }
|
||||
|
||||
.cm-s-solarized .cm-variable { color: #839496; }
|
||||
.cm-s-solarized .cm-variable-2 { color: #b58900; }
|
||||
.cm-s-solarized .cm-variable-3 { color: #6c71c4; }
|
||||
|
||||
.cm-s-solarized .cm-property { color: #2aa198; }
|
||||
.cm-s-solarized .cm-operator { color: #6c71c4; }
|
||||
|
||||
.cm-s-solarized .cm-comment { color: #586e75; font-style:italic; }
|
||||
|
||||
.cm-s-solarized .cm-string { color: #859900; }
|
||||
.cm-s-solarized .cm-string-2 { color: #b58900; }
|
||||
|
||||
.cm-s-solarized .cm-meta { color: #859900; }
|
||||
.cm-s-solarized .cm-qualifier { color: #b58900; }
|
||||
.cm-s-solarized .cm-builtin { color: #d33682; }
|
||||
.cm-s-solarized .cm-bracket { color: #cb4b16; }
|
||||
.cm-s-solarized .CodeMirror-matchingbracket { color: #859900; }
|
||||
.cm-s-solarized .CodeMirror-nonmatchingbracket { color: #dc322f; }
|
||||
.cm-s-solarized .cm-tag { color: #93a1a1; }
|
||||
.cm-s-solarized .cm-attribute { color: #2aa198; }
|
||||
.cm-s-solarized .cm-hr {
|
||||
color: transparent;
|
||||
border-top: 1px solid #586e75;
|
||||
display: block;
|
||||
}
|
||||
.cm-s-solarized .cm-link { color: #93a1a1; cursor: pointer; }
|
||||
.cm-s-solarized .cm-special { color: #6c71c4; }
|
||||
.cm-s-solarized .cm-em {
|
||||
color: #999;
|
||||
text-decoration: underline;
|
||||
text-decoration-style: dotted;
|
||||
}
|
||||
.cm-s-solarized .cm-strong { color: #eee; }
|
||||
.cm-s-solarized .cm-error,
|
||||
.cm-s-solarized .cm-invalidchar {
|
||||
color: #586e75;
|
||||
border-bottom: 1px dotted #dc322f;
|
||||
}
|
||||
|
||||
.cm-s-solarized.cm-s-dark div.CodeMirror-selected { background: #073642; }
|
||||
.cm-s-solarized.cm-s-dark.CodeMirror ::selection { background: rgba(7, 54, 66, 0.99); }
|
||||
.cm-s-solarized.cm-s-dark .CodeMirror-line::-moz-selection, .cm-s-dark .CodeMirror-line > span::-moz-selection, .cm-s-dark .CodeMirror-line > span > span::-moz-selection { background: rgba(7, 54, 66, 0.99); }
|
||||
|
||||
.cm-s-solarized.cm-s-light div.CodeMirror-selected { background: #eee8d5; }
|
||||
.cm-s-solarized.cm-s-light .CodeMirror-line::selection, .cm-s-light .CodeMirror-line > span::selection, .cm-s-light .CodeMirror-line > span > span::selection { background: #eee8d5; }
|
||||
.cm-s-solarized.cm-s-light .CodeMirror-line::-moz-selection, .cm-s-ligh .CodeMirror-line > span::-moz-selection, .cm-s-ligh .CodeMirror-line > span > span::-moz-selection { background: #eee8d5; }
|
||||
|
||||
/* Editor styling */
|
||||
|
||||
/* Little shadow on the view-port of the buffer view */
|
||||
.cm-s-solarized.CodeMirror {
|
||||
-moz-box-shadow: inset 7px 0 12px -6px #000;
|
||||
-webkit-box-shadow: inset 7px 0 12px -6px #000;
|
||||
box-shadow: inset 7px 0 12px -6px #000;
|
||||
}
|
||||
|
||||
/* Gutter border and some shadow from it */
|
||||
.cm-s-solarized .CodeMirror-gutters {
|
||||
border-right: 1px solid;
|
||||
}
|
||||
|
||||
/* Gutter colors and line number styling based of color scheme (dark / light) */
|
||||
|
||||
/* Dark */
|
||||
.cm-s-solarized.cm-s-dark .CodeMirror-gutters {
|
||||
background-color: #002b36;
|
||||
border-color: #00232c;
|
||||
}
|
||||
|
||||
.cm-s-solarized.cm-s-dark .CodeMirror-linenumber {
|
||||
text-shadow: #021014 0 -1px;
|
||||
}
|
||||
|
||||
/* Light */
|
||||
.cm-s-solarized.cm-s-light .CodeMirror-gutters {
|
||||
background-color: #fdf6e3;
|
||||
border-color: #eee8d5;
|
||||
}
|
||||
|
||||
/* Common */
|
||||
.cm-s-solarized .CodeMirror-linenumber {
|
||||
color: #586e75;
|
||||
padding: 0 5px;
|
||||
}
|
||||
.cm-s-solarized .CodeMirror-guttermarker-subtle { color: #586e75; }
|
||||
.cm-s-solarized.cm-s-dark .CodeMirror-guttermarker { color: #ddd; }
|
||||
.cm-s-solarized.cm-s-light .CodeMirror-guttermarker { color: #cb4b16; }
|
||||
|
||||
.cm-s-solarized .CodeMirror-gutter .CodeMirror-gutter-text {
|
||||
color: #586e75;
|
||||
}
|
||||
|
||||
.cm-s-solarized .CodeMirror-cursor { border-left: 1px solid #819090; }
|
||||
|
||||
/*
|
||||
Active line. Negative margin compensates left padding of the text in the
|
||||
view-port
|
||||
*/
|
||||
.cm-s-solarized.cm-s-dark .CodeMirror-activeline-background {
|
||||
background: rgba(255, 255, 255, 0.10);
|
||||
}
|
||||
.cm-s-solarized.cm-s-light .CodeMirror-activeline-background {
|
||||
background: rgba(0, 0, 0, 0.10);
|
||||
}
|
1348
app/app/styles/section/table.scss
Normal file
|
@ -34,14 +34,15 @@
|
|||
}
|
||||
}
|
||||
|
||||
> .entries {
|
||||
.entries {
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
font-size: 13px;
|
||||
overflow-x: hidden;
|
||||
list-style-type: none;
|
||||
|
||||
> .item {
|
||||
padding: 2px 0;
|
||||
.item {
|
||||
padding: 4px 0;
|
||||
text-overflow: ellipsis;
|
||||
word-wrap: break-word;
|
||||
white-space: nowrap;
|
||||
|
|
|
@ -1,29 +1,7 @@
|
|||
.page-wizard {
|
||||
> .toolbar {
|
||||
@extend .z-depth-tiny;
|
||||
background-color: $color-white;
|
||||
width: 100%;
|
||||
padding: 20px 40px;
|
||||
|
||||
> .title {
|
||||
width: 50%;
|
||||
|
||||
> .input-control {
|
||||
margin: 0;
|
||||
|
||||
> input {
|
||||
margin: 0 0 5px 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
> .buttons {
|
||||
margin-top: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
.section-wizard {
|
||||
> .canvas {
|
||||
padding: 40px 40px;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
|
||||
> .list {
|
||||
margin: 0;
|
||||
|
@ -31,46 +9,47 @@
|
|||
|
||||
> .item {
|
||||
list-style: none;
|
||||
float: left;
|
||||
cursor: pointer;
|
||||
width: 400px;
|
||||
height: 80px;
|
||||
background-color: $color-white;
|
||||
border: 1px solid $color-border2;
|
||||
width: 100%;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 3px;
|
||||
margin: 0 30px 30px 0;
|
||||
margin: 0 0 20px 0;
|
||||
padding: 10px;
|
||||
|
||||
&:hover {
|
||||
@extend .z-depth-half;
|
||||
background-color: $color-card-active;
|
||||
border-color: $color-card-active;
|
||||
border: 1px solid $color-border2;
|
||||
transition: 0.2s all ease;
|
||||
}
|
||||
|
||||
> .img {
|
||||
.icon {
|
||||
text-align: center;
|
||||
margin: 17px 10px 0 20px;
|
||||
display: inline-block;
|
||||
|
||||
> .img {
|
||||
// margin: 17px 10px 0 20px;
|
||||
display: block;
|
||||
height: 45px;
|
||||
width: 45px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
> .details {
|
||||
vertical-align: top;
|
||||
display: inline-block;
|
||||
display: block;
|
||||
margin-top: 10px;
|
||||
|
||||
> .title {
|
||||
font-size: 1rem;
|
||||
font-weight: bold;
|
||||
color: $color-off-black;
|
||||
margin-top: 18px;
|
||||
// margin-top: 18px;
|
||||
margin-right: 10px;
|
||||
letter-spacing: 0.5px;
|
||||
|
||||
.preview {
|
||||
font-size: 0.7rem;
|
||||
color: #cc9933;
|
||||
display: inline-block;
|
||||
margin-left: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,17 +57,9 @@
|
|||
color: $color-stroke;
|
||||
font-size: 0.8rem;
|
||||
margin-top: 5px;
|
||||
max-width: 300px;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
> .selected {
|
||||
background-color: $color-card-active;
|
||||
border: 1px dotted $color-link;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,12 +19,9 @@
|
|||
</div>
|
||||
{{/if}}
|
||||
|
||||
<ul class="entries">
|
||||
{{#each pages key="id" as |node index|}}
|
||||
<li class="item">
|
||||
{{document/toc-entry page.id node.id node.level}}
|
||||
<a id="index-{{node.id}}" class="link toc-index-item" {{action 'clickGotoPage' node.id}}>{{node.title}}</a>
|
||||
</li>
|
||||
<ul id="document-index" class="entries">
|
||||
{{#each pages key="id" as |entry index|}}
|
||||
{{document/index-entry page=entry onClick=(action 'onEntryClick')}}
|
||||
{{/each}}
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -1,7 +1,27 @@
|
|||
<div class="document-container">
|
||||
<div class="sidebar">
|
||||
{{#if showToc}}
|
||||
{{#if isEditor}}
|
||||
<div class="margin-bottom-20 text-center">
|
||||
<div {{action 'addSection'}} class="regular-button button-green" id="add-section-button" data-tooltip="Add section" data-tooltip-position="top center">
|
||||
<i class="material-icons">add</i>
|
||||
<div class="name">section</div>
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
{{document/document-sidebar-toc document=model folder=folder pages=pages page=page isEditor=isEditor
|
||||
changePageSequence=(action 'onPageSequenceChange') changePageLevel=(action 'onPageLevelChange')
|
||||
gotoPage=(action 'gotoPage')}}
|
||||
{{/if}}
|
||||
|
||||
{{#if showSectionList}}
|
||||
<div class="margin-bottom-20 pull-right">
|
||||
<div {{action 'showToc'}} class="flat-button">
|
||||
Cancel
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearfix" />
|
||||
{{document/page-wizard document=model folder=folder sections=sections onAction=(action 'onAddSection')}}
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -39,12 +39,6 @@
|
|||
|
||||
<div class="actions pull-right hidden-xs hidden-sm">
|
||||
{{#if isEditor}}
|
||||
{{#link-to 'document.wizard' folder.id folder.slug document.id document.slug}}
|
||||
<div class="regular-button button-green" id="add-section-button" data-tooltip="Add section" data-tooltip-position="top center">
|
||||
<i class="material-icons">add</i>
|
||||
<div class="name">section</div>
|
||||
</div>
|
||||
{{/link-to}}
|
||||
<div class="button-gap"></div>
|
||||
<div class="square-button button-gray" id="attachment-button" data-tooltip="Attach file" data-tooltip-position="top center">
|
||||
<i class="material-icons">attach_file</i>
|
||||
|
|
1
app/app/templates/components/document/index-entry.hbs
Normal file
|
@ -0,0 +1 @@
|
|||
<a id="index-{{page.id}}" class="link toc-index-item" {{action 'onClick' page.id}}>{{page.title}}</a>
|
|
@ -1,24 +1,11 @@
|
|||
<div class="page-wizard">
|
||||
<div class="toolbar">
|
||||
<div class="title pull-left">
|
||||
<div class="input-control">
|
||||
<label>Title</label>
|
||||
<div class="tip">Add new section to <span class="bold">{{document.name}}</span></div>
|
||||
{{focus-input type='text' id="page-title" value=title class="mousetrap"}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="buttons pull-right">
|
||||
<div class="flat-button flat-gray" {{action 'onCancel'}}>Cancel</div>
|
||||
<div class="button-gap" />
|
||||
<div class="regular-button button-green" {{action 'onAction'}}>Add</div>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="section-wizard">
|
||||
<div class="canvas">
|
||||
<ul class="list">
|
||||
{{#each sections as |section|}}
|
||||
<li class="item {{if section.selected "selected"}}" {{action 'setOption' section.id}}>
|
||||
<li class="item" {{action 'addSection' section}}>
|
||||
<div class="icon">
|
||||
<img class="img" src="/sections/{{section.contentType}}.png" srcset="/sections/{{section.contentType}}@2x.png" />
|
||||
</div>
|
||||
<div class="details">
|
||||
<div class='title'>
|
||||
{{section.title}}
|
||||
|
@ -31,7 +18,9 @@
|
|||
</li>
|
||||
{{/each}}
|
||||
<li class="item">
|
||||
<img class="img" src="/sections/suggest.png" />
|
||||
<div class="icon">
|
||||
<img class="img" src="/sections/suggest.png" title="{{section.title}}" alt="{{section.title}}" />
|
||||
</div>
|
||||
<div class="details">
|
||||
<div class='title'>Suggest</div>
|
||||
<div class='desc'>We'll build the integrations you need - just let us know</div>
|
||||
|
|
|
@ -56,6 +56,7 @@ module.exports = function(defaults) {
|
|||
app.import('vendor/drop.js');
|
||||
app.import('vendor/tooltip.js');
|
||||
app.import('vendor/markdown-it.min.js');
|
||||
app.import('vendor/dragula.js');
|
||||
|
||||
return app.toTree();
|
||||
};
|
||||
|
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 2 KiB After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 2 KiB After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 2 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 2 KiB After Width: | Height: | Size: 2.2 KiB |
905
app/vendor/dragula.js
vendored
Normal file
|
@ -0,0 +1,905 @@
|
|||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.dragula = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
||||
'use strict';
|
||||
|
||||
var cache = {};
|
||||
var start = '(?:^|\\s)';
|
||||
var end = '(?:\\s|$)';
|
||||
|
||||
function lookupClass (className) {
|
||||
var cached = cache[className];
|
||||
if (cached) {
|
||||
cached.lastIndex = 0;
|
||||
} else {
|
||||
cache[className] = cached = new RegExp(start + className + end, 'g');
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
|
||||
function addClass (el, className) {
|
||||
var current = el.className;
|
||||
if (!current.length) {
|
||||
el.className = className;
|
||||
} else if (!lookupClass(className).test(current)) {
|
||||
el.className += ' ' + className;
|
||||
}
|
||||
}
|
||||
|
||||
function rmClass (el, className) {
|
||||
el.className = el.className.replace(lookupClass(className), ' ').trim();
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
add: addClass,
|
||||
rm: rmClass
|
||||
};
|
||||
|
||||
},{}],2:[function(require,module,exports){
|
||||
(function (global){
|
||||
'use strict';
|
||||
|
||||
var emitter = require('contra/emitter');
|
||||
var crossvent = require('crossvent');
|
||||
var classes = require('./classes');
|
||||
var doc = document;
|
||||
var documentElement = doc.documentElement;
|
||||
|
||||
function dragula (initialContainers, options) {
|
||||
var len = arguments.length;
|
||||
if (len === 1 && Array.isArray(initialContainers) === false) {
|
||||
options = initialContainers;
|
||||
initialContainers = [];
|
||||
}
|
||||
var _mirror; // mirror image
|
||||
var _source; // source container
|
||||
var _item; // item being dragged
|
||||
var _offsetX; // reference x
|
||||
var _offsetY; // reference y
|
||||
var _moveX; // reference move x
|
||||
var _moveY; // reference move y
|
||||
var _initialSibling; // reference sibling when grabbed
|
||||
var _currentSibling; // reference sibling now
|
||||
var _copy; // item used for copying
|
||||
var _renderTimer; // timer for setTimeout renderMirrorImage
|
||||
var _lastDropTarget = null; // last container item was over
|
||||
var _grabbed; // holds mousedown context until first mousemove
|
||||
|
||||
var o = options || {};
|
||||
if (o.moves === void 0) { o.moves = always; }
|
||||
if (o.accepts === void 0) { o.accepts = always; }
|
||||
if (o.invalid === void 0) { o.invalid = invalidTarget; }
|
||||
if (o.containers === void 0) { o.containers = initialContainers || []; }
|
||||
if (o.isContainer === void 0) { o.isContainer = never; }
|
||||
if (o.copy === void 0) { o.copy = false; }
|
||||
if (o.copySortSource === void 0) { o.copySortSource = false; }
|
||||
if (o.revertOnSpill === void 0) { o.revertOnSpill = false; }
|
||||
if (o.removeOnSpill === void 0) { o.removeOnSpill = false; }
|
||||
if (o.direction === void 0) { o.direction = 'vertical'; }
|
||||
if (o.ignoreInputTextSelection === void 0) { o.ignoreInputTextSelection = true; }
|
||||
if (o.mirrorContainer === void 0) { o.mirrorContainer = doc.body; }
|
||||
|
||||
var drake = emitter({
|
||||
containers: o.containers,
|
||||
start: manualStart,
|
||||
end: end,
|
||||
cancel: cancel,
|
||||
remove: remove,
|
||||
destroy: destroy,
|
||||
canMove: canMove,
|
||||
dragging: false
|
||||
});
|
||||
|
||||
if (o.removeOnSpill === true) {
|
||||
drake.on('over', spillOver).on('out', spillOut);
|
||||
}
|
||||
|
||||
events();
|
||||
|
||||
return drake;
|
||||
|
||||
function isContainer (el) {
|
||||
return drake.containers.indexOf(el) !== -1 || o.isContainer(el);
|
||||
}
|
||||
|
||||
function events (remove) {
|
||||
var op = remove ? 'remove' : 'add';
|
||||
touchy(documentElement, op, 'mousedown', grab);
|
||||
touchy(documentElement, op, 'mouseup', release);
|
||||
}
|
||||
|
||||
function eventualMovements (remove) {
|
||||
var op = remove ? 'remove' : 'add';
|
||||
touchy(documentElement, op, 'mousemove', startBecauseMouseMoved);
|
||||
}
|
||||
|
||||
function movements (remove) {
|
||||
var op = remove ? 'remove' : 'add';
|
||||
crossvent[op](documentElement, 'selectstart', preventGrabbed); // IE8
|
||||
crossvent[op](documentElement, 'click', preventGrabbed);
|
||||
}
|
||||
|
||||
function destroy () {
|
||||
events(true);
|
||||
release({});
|
||||
}
|
||||
|
||||
function preventGrabbed (e) {
|
||||
if (_grabbed) {
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
function grab (e) {
|
||||
_moveX = e.clientX;
|
||||
_moveY = e.clientY;
|
||||
|
||||
var ignore = whichMouseButton(e) !== 1 || e.metaKey || e.ctrlKey;
|
||||
if (ignore) {
|
||||
return; // we only care about honest-to-god left clicks and touch events
|
||||
}
|
||||
var item = e.target;
|
||||
var context = canStart(item);
|
||||
if (!context) {
|
||||
return;
|
||||
}
|
||||
_grabbed = context;
|
||||
eventualMovements();
|
||||
if (e.type === 'mousedown') {
|
||||
if (isInput(item)) { // see also: https://github.com/bevacqua/dragula/issues/208
|
||||
item.focus(); // fixes https://github.com/bevacqua/dragula/issues/176
|
||||
} else {
|
||||
e.preventDefault(); // fixes https://github.com/bevacqua/dragula/issues/155
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function startBecauseMouseMoved (e) {
|
||||
if (!_grabbed) {
|
||||
return;
|
||||
}
|
||||
if (whichMouseButton(e) === 0) {
|
||||
release({});
|
||||
return; // when text is selected on an input and then dragged, mouseup doesn't fire. this is our only hope
|
||||
}
|
||||
// truthy check fixes #239, equality fixes #207
|
||||
if (e.clientX !== void 0 && e.clientX === _moveX && e.clientY !== void 0 && e.clientY === _moveY) {
|
||||
return;
|
||||
}
|
||||
if (o.ignoreInputTextSelection) {
|
||||
var clientX = getCoord('clientX', e);
|
||||
var clientY = getCoord('clientY', e);
|
||||
var elementBehindCursor = doc.elementFromPoint(clientX, clientY);
|
||||
if (isInput(elementBehindCursor)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var grabbed = _grabbed; // call to end() unsets _grabbed
|
||||
eventualMovements(true);
|
||||
movements();
|
||||
end();
|
||||
start(grabbed);
|
||||
|
||||
var offset = getOffset(_item);
|
||||
_offsetX = getCoord('pageX', e) - offset.left;
|
||||
_offsetY = getCoord('pageY', e) - offset.top;
|
||||
|
||||
classes.add(_copy || _item, 'gu-transit');
|
||||
renderMirrorImage();
|
||||
drag(e);
|
||||
}
|
||||
|
||||
function canStart (item) {
|
||||
if (drake.dragging && _mirror) {
|
||||
return;
|
||||
}
|
||||
if (isContainer(item)) {
|
||||
return; // don't drag container itself
|
||||
}
|
||||
var handle = item;
|
||||
while (getParent(item) && isContainer(getParent(item)) === false) {
|
||||
if (o.invalid(item, handle)) {
|
||||
return;
|
||||
}
|
||||
item = getParent(item); // drag target should be a top element
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
var source = getParent(item);
|
||||
if (!source) {
|
||||
return;
|
||||
}
|
||||
if (o.invalid(item, handle)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var movable = o.moves(item, source, handle, nextEl(item));
|
||||
if (!movable) {
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
item: item,
|
||||
source: source
|
||||
};
|
||||
}
|
||||
|
||||
function canMove (item) {
|
||||
return !!canStart(item);
|
||||
}
|
||||
|
||||
function manualStart (item) {
|
||||
var context = canStart(item);
|
||||
if (context) {
|
||||
start(context);
|
||||
}
|
||||
}
|
||||
|
||||
function start (context) {
|
||||
if (isCopy(context.item, context.source)) {
|
||||
_copy = context.item.cloneNode(true);
|
||||
drake.emit('cloned', _copy, context.item, 'copy');
|
||||
}
|
||||
|
||||
_source = context.source;
|
||||
_item = context.item;
|
||||
_initialSibling = _currentSibling = nextEl(context.item);
|
||||
|
||||
drake.dragging = true;
|
||||
drake.emit('drag', _item, _source);
|
||||
}
|
||||
|
||||
function invalidTarget () {
|
||||
return false;
|
||||
}
|
||||
|
||||
function end () {
|
||||
if (!drake.dragging) {
|
||||
return;
|
||||
}
|
||||
var item = _copy || _item;
|
||||
drop(item, getParent(item));
|
||||
}
|
||||
|
||||
function ungrab () {
|
||||
_grabbed = false;
|
||||
eventualMovements(true);
|
||||
movements(true);
|
||||
}
|
||||
|
||||
function release (e) {
|
||||
ungrab();
|
||||
|
||||
if (!drake.dragging) {
|
||||
return;
|
||||
}
|
||||
var item = _copy || _item;
|
||||
var clientX = getCoord('clientX', e);
|
||||
var clientY = getCoord('clientY', e);
|
||||
var elementBehindCursor = getElementBehindPoint(_mirror, clientX, clientY);
|
||||
var dropTarget = findDropTarget(elementBehindCursor, clientX, clientY);
|
||||
if (dropTarget && ((_copy && o.copySortSource) || (!_copy || dropTarget !== _source))) {
|
||||
drop(item, dropTarget);
|
||||
} else if (o.removeOnSpill) {
|
||||
remove();
|
||||
} else {
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
|
||||
function drop (item, target) {
|
||||
var parent = getParent(item);
|
||||
if (_copy && o.copySortSource && target === _source) {
|
||||
parent.removeChild(_item);
|
||||
}
|
||||
if (isInitialPlacement(target)) {
|
||||
drake.emit('cancel', item, _source, _source);
|
||||
} else {
|
||||
drake.emit('drop', item, target, _source, _currentSibling);
|
||||
}
|
||||
cleanup();
|
||||
}
|
||||
|
||||
function remove () {
|
||||
if (!drake.dragging) {
|
||||
return;
|
||||
}
|
||||
var item = _copy || _item;
|
||||
var parent = getParent(item);
|
||||
if (parent) {
|
||||
parent.removeChild(item);
|
||||
}
|
||||
drake.emit(_copy ? 'cancel' : 'remove', item, parent, _source);
|
||||
cleanup();
|
||||
}
|
||||
|
||||
function cancel (revert) {
|
||||
if (!drake.dragging) {
|
||||
return;
|
||||
}
|
||||
var reverts = arguments.length > 0 ? revert : o.revertOnSpill;
|
||||
var item = _copy || _item;
|
||||
var parent = getParent(item);
|
||||
var initial = isInitialPlacement(parent);
|
||||
if (initial === false && reverts) {
|
||||
if (_copy) {
|
||||
parent.removeChild(_copy);
|
||||
} else {
|
||||
_source.insertBefore(item, _initialSibling);
|
||||
}
|
||||
}
|
||||
if (initial || reverts) {
|
||||
drake.emit('cancel', item, _source, _source);
|
||||
} else {
|
||||
drake.emit('drop', item, parent, _source, _currentSibling);
|
||||
}
|
||||
cleanup();
|
||||
}
|
||||
|
||||
function cleanup () {
|
||||
var item = _copy || _item;
|
||||
ungrab();
|
||||
removeMirrorImage();
|
||||
if (item) {
|
||||
classes.rm(item, 'gu-transit');
|
||||
}
|
||||
if (_renderTimer) {
|
||||
clearTimeout(_renderTimer);
|
||||
}
|
||||
drake.dragging = false;
|
||||
if (_lastDropTarget) {
|
||||
drake.emit('out', item, _lastDropTarget, _source);
|
||||
}
|
||||
drake.emit('dragend', item);
|
||||
_source = _item = _copy = _initialSibling = _currentSibling = _renderTimer = _lastDropTarget = null;
|
||||
}
|
||||
|
||||
function isInitialPlacement (target, s) {
|
||||
var sibling;
|
||||
if (s !== void 0) {
|
||||
sibling = s;
|
||||
} else if (_mirror) {
|
||||
sibling = _currentSibling;
|
||||
} else {
|
||||
sibling = nextEl(_copy || _item);
|
||||
}
|
||||
return target === _source && sibling === _initialSibling;
|
||||
}
|
||||
|
||||
function findDropTarget (elementBehindCursor, clientX, clientY) {
|
||||
var target = elementBehindCursor;
|
||||
while (target && !accepted()) {
|
||||
target = getParent(target);
|
||||
}
|
||||
return target;
|
||||
|
||||
function accepted () {
|
||||
var droppable = isContainer(target);
|
||||
if (droppable === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var immediate = getImmediateChild(target, elementBehindCursor);
|
||||
var reference = getReference(target, immediate, clientX, clientY);
|
||||
var initial = isInitialPlacement(target, reference);
|
||||
if (initial) {
|
||||
return true; // should always be able to drop it right back where it was
|
||||
}
|
||||
return o.accepts(_item, target, _source, reference);
|
||||
}
|
||||
}
|
||||
|
||||
function drag (e) {
|
||||
if (!_mirror) {
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
|
||||
var clientX = getCoord('clientX', e);
|
||||
var clientY = getCoord('clientY', e);
|
||||
var x = clientX - _offsetX;
|
||||
var y = clientY - _offsetY;
|
||||
|
||||
_mirror.style.left = x + 'px';
|
||||
_mirror.style.top = y + 'px';
|
||||
|
||||
var item = _copy || _item;
|
||||
var elementBehindCursor = getElementBehindPoint(_mirror, clientX, clientY);
|
||||
var dropTarget = findDropTarget(elementBehindCursor, clientX, clientY);
|
||||
var changed = dropTarget !== null && dropTarget !== _lastDropTarget;
|
||||
if (changed || dropTarget === null) {
|
||||
out();
|
||||
_lastDropTarget = dropTarget;
|
||||
over();
|
||||
}
|
||||
var parent = getParent(item);
|
||||
if (dropTarget === _source && _copy && !o.copySortSource) {
|
||||
if (parent) {
|
||||
parent.removeChild(item);
|
||||
}
|
||||
return;
|
||||
}
|
||||
var reference;
|
||||
var immediate = getImmediateChild(dropTarget, elementBehindCursor);
|
||||
if (immediate !== null) {
|
||||
reference = getReference(dropTarget, immediate, clientX, clientY);
|
||||
} else if (o.revertOnSpill === true && !_copy) {
|
||||
reference = _initialSibling;
|
||||
dropTarget = _source;
|
||||
} else {
|
||||
if (_copy && parent) {
|
||||
parent.removeChild(item);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (
|
||||
(reference === null && changed) ||
|
||||
reference !== item &&
|
||||
reference !== nextEl(item)
|
||||
) {
|
||||
_currentSibling = reference;
|
||||
dropTarget.insertBefore(item, reference);
|
||||
drake.emit('shadow', item, dropTarget, _source);
|
||||
}
|
||||
function moved (type) { drake.emit(type, item, _lastDropTarget, _source); }
|
||||
function over () { if (changed) { moved('over'); } }
|
||||
function out () { if (_lastDropTarget) { moved('out'); } }
|
||||
}
|
||||
|
||||
function spillOver (el) {
|
||||
classes.rm(el, 'gu-hide');
|
||||
}
|
||||
|
||||
function spillOut (el) {
|
||||
if (drake.dragging) { classes.add(el, 'gu-hide'); }
|
||||
}
|
||||
|
||||
function renderMirrorImage () {
|
||||
if (_mirror) {
|
||||
return;
|
||||
}
|
||||
var rect = _item.getBoundingClientRect();
|
||||
_mirror = _item.cloneNode(true);
|
||||
_mirror.style.width = getRectWidth(rect) + 'px';
|
||||
_mirror.style.height = getRectHeight(rect) + 'px';
|
||||
classes.rm(_mirror, 'gu-transit');
|
||||
classes.add(_mirror, 'gu-mirror');
|
||||
o.mirrorContainer.appendChild(_mirror);
|
||||
touchy(documentElement, 'add', 'mousemove', drag);
|
||||
classes.add(o.mirrorContainer, 'gu-unselectable');
|
||||
drake.emit('cloned', _mirror, _item, 'mirror');
|
||||
}
|
||||
|
||||
function removeMirrorImage () {
|
||||
if (_mirror) {
|
||||
classes.rm(o.mirrorContainer, 'gu-unselectable');
|
||||
touchy(documentElement, 'remove', 'mousemove', drag);
|
||||
getParent(_mirror).removeChild(_mirror);
|
||||
_mirror = null;
|
||||
}
|
||||
}
|
||||
|
||||
function getImmediateChild (dropTarget, target) {
|
||||
var immediate = target;
|
||||
while (immediate !== dropTarget && getParent(immediate) !== dropTarget) {
|
||||
immediate = getParent(immediate);
|
||||
}
|
||||
if (immediate === documentElement) {
|
||||
return null;
|
||||
}
|
||||
return immediate;
|
||||
}
|
||||
|
||||
function getReference (dropTarget, target, x, y) {
|
||||
var horizontal = o.direction === 'horizontal';
|
||||
var reference = target !== dropTarget ? inside() : outside();
|
||||
return reference;
|
||||
|
||||
function outside () { // slower, but able to figure out any position
|
||||
var len = dropTarget.children.length;
|
||||
var i;
|
||||
var el;
|
||||
var rect;
|
||||
for (i = 0; i < len; i++) {
|
||||
el = dropTarget.children[i];
|
||||
rect = el.getBoundingClientRect();
|
||||
if (horizontal && (rect.left + rect.width / 2) > x) { return el; }
|
||||
if (!horizontal && (rect.top + rect.height / 2) > y) { return el; }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function inside () { // faster, but only available if dropped inside a child element
|
||||
var rect = target.getBoundingClientRect();
|
||||
if (horizontal) {
|
||||
return resolve(x > rect.left + getRectWidth(rect) / 2);
|
||||
}
|
||||
return resolve(y > rect.top + getRectHeight(rect) / 2);
|
||||
}
|
||||
|
||||
function resolve (after) {
|
||||
return after ? nextEl(target) : target;
|
||||
}
|
||||
}
|
||||
|
||||
function isCopy (item, container) {
|
||||
return typeof o.copy === 'boolean' ? o.copy : o.copy(item, container);
|
||||
}
|
||||
}
|
||||
|
||||
function touchy (el, op, type, fn) {
|
||||
var touch = {
|
||||
mouseup: 'touchend',
|
||||
mousedown: 'touchstart',
|
||||
mousemove: 'touchmove'
|
||||
};
|
||||
var pointers = {
|
||||
mouseup: 'pointerup',
|
||||
mousedown: 'pointerdown',
|
||||
mousemove: 'pointermove'
|
||||
};
|
||||
var microsoft = {
|
||||
mouseup: 'MSPointerUp',
|
||||
mousedown: 'MSPointerDown',
|
||||
mousemove: 'MSPointerMove'
|
||||
};
|
||||
if (global.navigator.pointerEnabled) {
|
||||
crossvent[op](el, pointers[type], fn);
|
||||
} else if (global.navigator.msPointerEnabled) {
|
||||
crossvent[op](el, microsoft[type], fn);
|
||||
} else {
|
||||
crossvent[op](el, touch[type], fn);
|
||||
crossvent[op](el, type, fn);
|
||||
}
|
||||
}
|
||||
|
||||
function whichMouseButton (e) {
|
||||
if (e.touches !== void 0) { return e.touches.length; }
|
||||
if (e.which !== void 0 && e.which !== 0) { return e.which; } // see https://github.com/bevacqua/dragula/issues/261
|
||||
if (e.buttons !== void 0) { return e.buttons; }
|
||||
var button = e.button;
|
||||
if (button !== void 0) { // see https://github.com/jquery/jquery/blob/99e8ff1baa7ae341e94bb89c3e84570c7c3ad9ea/src/event.js#L573-L575
|
||||
return button & 1 ? 1 : button & 2 ? 3 : (button & 4 ? 2 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
function getOffset (el) {
|
||||
var rect = el.getBoundingClientRect();
|
||||
return {
|
||||
left: rect.left + getScroll('scrollLeft', 'pageXOffset'),
|
||||
top: rect.top + getScroll('scrollTop', 'pageYOffset')
|
||||
};
|
||||
}
|
||||
|
||||
function getScroll (scrollProp, offsetProp) {
|
||||
if (typeof global[offsetProp] !== 'undefined') {
|
||||
return global[offsetProp];
|
||||
}
|
||||
if (documentElement.clientHeight) {
|
||||
return documentElement[scrollProp];
|
||||
}
|
||||
return doc.body[scrollProp];
|
||||
}
|
||||
|
||||
function getElementBehindPoint (point, x, y) {
|
||||
var p = point || {};
|
||||
var state = p.className;
|
||||
var el;
|
||||
p.className += ' gu-hide';
|
||||
el = doc.elementFromPoint(x, y);
|
||||
p.className = state;
|
||||
return el;
|
||||
}
|
||||
|
||||
function never () { return false; }
|
||||
function always () { return true; }
|
||||
function getRectWidth (rect) { return rect.width || (rect.right - rect.left); }
|
||||
function getRectHeight (rect) { return rect.height || (rect.bottom - rect.top); }
|
||||
function getParent (el) { return el.parentNode === doc ? null : el.parentNode; }
|
||||
function isInput (el) { return el.tagName === 'INPUT' || el.tagName === 'TEXTAREA' || el.tagName === 'SELECT' || isEditable(el); }
|
||||
function isEditable (el) {
|
||||
if (!el) { return false; } // no parents were editable
|
||||
if (el.contentEditable === 'false') { return false; } // stop the lookup
|
||||
if (el.contentEditable === 'true') { return true; } // found a contentEditable element in the chain
|
||||
return isEditable(getParent(el)); // contentEditable is set to 'inherit'
|
||||
}
|
||||
|
||||
function nextEl (el) {
|
||||
return el.nextElementSibling || manually();
|
||||
function manually () {
|
||||
var sibling = el;
|
||||
do {
|
||||
sibling = sibling.nextSibling;
|
||||
} while (sibling && sibling.nodeType !== 1);
|
||||
return sibling;
|
||||
}
|
||||
}
|
||||
|
||||
function getEventHost (e) {
|
||||
// on touchend event, we have to use `e.changedTouches`
|
||||
// see http://stackoverflow.com/questions/7192563/touchend-event-properties
|
||||
// see https://github.com/bevacqua/dragula/issues/34
|
||||
if (e.targetTouches && e.targetTouches.length) {
|
||||
return e.targetTouches[0];
|
||||
}
|
||||
if (e.changedTouches && e.changedTouches.length) {
|
||||
return e.changedTouches[0];
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
function getCoord (coord, e) {
|
||||
var host = getEventHost(e);
|
||||
var missMap = {
|
||||
pageX: 'clientX', // IE8
|
||||
pageY: 'clientY' // IE8
|
||||
};
|
||||
if (coord in missMap && !(coord in host) && missMap[coord] in host) {
|
||||
coord = missMap[coord];
|
||||
}
|
||||
return host[coord];
|
||||
}
|
||||
|
||||
module.exports = dragula;
|
||||
|
||||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||||
|
||||
},{"./classes":1,"contra/emitter":4,"crossvent":8}],3:[function(require,module,exports){
|
||||
'use strict';
|
||||
|
||||
var ticky = require('ticky');
|
||||
|
||||
module.exports = function debounce (fn, args, ctx) {
|
||||
if (!fn) { return; }
|
||||
ticky(function run () {
|
||||
fn.apply(ctx || null, args || []);
|
||||
});
|
||||
};
|
||||
|
||||
},{"ticky":6}],4:[function(require,module,exports){
|
||||
'use strict';
|
||||
|
||||
var atoa = require('atoa');
|
||||
var debounce = require('./debounce');
|
||||
|
||||
module.exports = function emitter (thing, options) {
|
||||
var opts = options || {};
|
||||
var evt = {};
|
||||
if (thing === undefined) { thing = {}; }
|
||||
thing.on = function (type, fn) {
|
||||
if (!evt[type]) {
|
||||
evt[type] = [fn];
|
||||
} else {
|
||||
evt[type].push(fn);
|
||||
}
|
||||
return thing;
|
||||
};
|
||||
thing.once = function (type, fn) {
|
||||
fn._once = true; // thing.off(fn) still works!
|
||||
thing.on(type, fn);
|
||||
return thing;
|
||||
};
|
||||
thing.off = function (type, fn) {
|
||||
var c = arguments.length;
|
||||
if (c === 1) {
|
||||
delete evt[type];
|
||||
} else if (c === 0) {
|
||||
evt = {};
|
||||
} else {
|
||||
var et = evt[type];
|
||||
if (!et) { return thing; }
|
||||
et.splice(et.indexOf(fn), 1);
|
||||
}
|
||||
return thing;
|
||||
};
|
||||
thing.emit = function () {
|
||||
var args = atoa(arguments);
|
||||
return thing.emitterSnapshot(args.shift()).apply(this, args);
|
||||
};
|
||||
thing.emitterSnapshot = function (type) {
|
||||
var et = (evt[type] || []).slice(0);
|
||||
return function () {
|
||||
var args = atoa(arguments);
|
||||
var ctx = this || thing;
|
||||
if (type === 'error' && opts.throws !== false && !et.length) { throw args.length === 1 ? args[0] : args; }
|
||||
et.forEach(function emitter (listen) {
|
||||
if (opts.async) { debounce(listen, args, ctx); } else { listen.apply(ctx, args); }
|
||||
if (listen._once) { thing.off(type, listen); }
|
||||
});
|
||||
return thing;
|
||||
};
|
||||
};
|
||||
return thing;
|
||||
};
|
||||
|
||||
},{"./debounce":3,"atoa":5}],5:[function(require,module,exports){
|
||||
module.exports = function atoa (a, n) { return Array.prototype.slice.call(a, n); }
|
||||
|
||||
},{}],6:[function(require,module,exports){
|
||||
var si = typeof setImmediate === 'function', tick;
|
||||
if (si) {
|
||||
tick = function (fn) { setImmediate(fn); };
|
||||
} else {
|
||||
tick = function (fn) { setTimeout(fn, 0); };
|
||||
}
|
||||
|
||||
module.exports = tick;
|
||||
},{}],7:[function(require,module,exports){
|
||||
(function (global){
|
||||
|
||||
var NativeCustomEvent = global.CustomEvent;
|
||||
|
||||
function useNative () {
|
||||
try {
|
||||
var p = new NativeCustomEvent('cat', { detail: { foo: 'bar' } });
|
||||
return 'cat' === p.type && 'bar' === p.detail.foo;
|
||||
} catch (e) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cross-browser `CustomEvent` constructor.
|
||||
*
|
||||
* https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent.CustomEvent
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
|
||||
module.exports = useNative() ? NativeCustomEvent :
|
||||
|
||||
// IE >= 9
|
||||
'function' === typeof document.createEvent ? function CustomEvent (type, params) {
|
||||
var e = document.createEvent('CustomEvent');
|
||||
if (params) {
|
||||
e.initCustomEvent(type, params.bubbles, params.cancelable, params.detail);
|
||||
} else {
|
||||
e.initCustomEvent(type, false, false, void 0);
|
||||
}
|
||||
return e;
|
||||
} :
|
||||
|
||||
// IE <= 8
|
||||
function CustomEvent (type, params) {
|
||||
var e = document.createEventObject();
|
||||
e.type = type;
|
||||
if (params) {
|
||||
e.bubbles = Boolean(params.bubbles);
|
||||
e.cancelable = Boolean(params.cancelable);
|
||||
e.detail = params.detail;
|
||||
} else {
|
||||
e.bubbles = false;
|
||||
e.cancelable = false;
|
||||
e.detail = void 0;
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||||
|
||||
},{}],8:[function(require,module,exports){
|
||||
(function (global){
|
||||
'use strict';
|
||||
|
||||
var customEvent = require('custom-event');
|
||||
var eventmap = require('./eventmap');
|
||||
var doc = global.document;
|
||||
var addEvent = addEventEasy;
|
||||
var removeEvent = removeEventEasy;
|
||||
var hardCache = [];
|
||||
|
||||
if (!global.addEventListener) {
|
||||
addEvent = addEventHard;
|
||||
removeEvent = removeEventHard;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
add: addEvent,
|
||||
remove: removeEvent,
|
||||
fabricate: fabricateEvent
|
||||
};
|
||||
|
||||
function addEventEasy (el, type, fn, capturing) {
|
||||
return el.addEventListener(type, fn, capturing);
|
||||
}
|
||||
|
||||
function addEventHard (el, type, fn) {
|
||||
return el.attachEvent('on' + type, wrap(el, type, fn));
|
||||
}
|
||||
|
||||
function removeEventEasy (el, type, fn, capturing) {
|
||||
return el.removeEventListener(type, fn, capturing);
|
||||
}
|
||||
|
||||
function removeEventHard (el, type, fn) {
|
||||
var listener = unwrap(el, type, fn);
|
||||
if (listener) {
|
||||
return el.detachEvent('on' + type, listener);
|
||||
}
|
||||
}
|
||||
|
||||
function fabricateEvent (el, type, model) {
|
||||
var e = eventmap.indexOf(type) === -1 ? makeCustomEvent() : makeClassicEvent();
|
||||
if (el.dispatchEvent) {
|
||||
el.dispatchEvent(e);
|
||||
} else {
|
||||
el.fireEvent('on' + type, e);
|
||||
}
|
||||
function makeClassicEvent () {
|
||||
var e;
|
||||
if (doc.createEvent) {
|
||||
e = doc.createEvent('Event');
|
||||
e.initEvent(type, true, true);
|
||||
} else if (doc.createEventObject) {
|
||||
e = doc.createEventObject();
|
||||
}
|
||||
return e;
|
||||
}
|
||||
function makeCustomEvent () {
|
||||
return new customEvent(type, { detail: model });
|
||||
}
|
||||
}
|
||||
|
||||
function wrapperFactory (el, type, fn) {
|
||||
return function wrapper (originalEvent) {
|
||||
var e = originalEvent || global.event;
|
||||
e.target = e.target || e.srcElement;
|
||||
e.preventDefault = e.preventDefault || function preventDefault () { e.returnValue = false; };
|
||||
e.stopPropagation = e.stopPropagation || function stopPropagation () { e.cancelBubble = true; };
|
||||
e.which = e.which || e.keyCode;
|
||||
fn.call(el, e);
|
||||
};
|
||||
}
|
||||
|
||||
function wrap (el, type, fn) {
|
||||
var wrapper = unwrap(el, type, fn) || wrapperFactory(el, type, fn);
|
||||
hardCache.push({
|
||||
wrapper: wrapper,
|
||||
element: el,
|
||||
type: type,
|
||||
fn: fn
|
||||
});
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
function unwrap (el, type, fn) {
|
||||
var i = find(el, type, fn);
|
||||
if (i) {
|
||||
var wrapper = hardCache[i].wrapper;
|
||||
hardCache.splice(i, 1); // free up a tad of memory
|
||||
return wrapper;
|
||||
}
|
||||
}
|
||||
|
||||
function find (el, type, fn) {
|
||||
var i, item;
|
||||
for (i = 0; i < hardCache.length; i++) {
|
||||
item = hardCache[i];
|
||||
if (item.element === el && item.type === type && item.fn === fn) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||||
|
||||
},{"./eventmap":9,"custom-event":7}],9:[function(require,module,exports){
|
||||
(function (global){
|
||||
'use strict';
|
||||
|
||||
var eventmap = [];
|
||||
var eventname = '';
|
||||
var ron = /^on/;
|
||||
|
||||
for (eventname in global) {
|
||||
if (ron.test(eventname)) {
|
||||
eventmap.push(eventname.slice(2));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = eventmap;
|
||||
|
||||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||||
|
||||
},{}]},{},[2])(2)
|
||||
});
|