forked from scripting/concord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
concordUtils.js
242 lines (241 loc) · 7.6 KB
/
concordUtils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
// Copyright 2013, Small Picture, Inc.
var appTypeIcons = {
"blogpost": "file-text-alt",
"code": "laptop",
"html": "file-text-alt",
"include": "share-alt", //5/19/13 by DW
"index": "file-text-alt",
"link": "bookmark-empty",
"outline": "file-text-alt",
"photo": "camera",
"presentation": "file-text-alt",
"redirect": "refresh",
"river": "file-text-alt",
"rss": "rss",
"tabs": "file-text-alt",
"thread": "comments",
"thumblist": "th",
"profile": "user", //5/14/13 by DW
"calendar": "calendar", //6/3/13 by DW
"markdown": "file-text-alt", //6/3/13 by DW
"tweet": "twitter", //6/10/13 by DW
"metaWeblogPost": "file-text-alt"
}
var initialOpmltext =
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><opml version=\"2.0\"><head><title>Untitled</title></head><body><outline text=\"\"/></body></opml>";
var defaultUtilsOutliner = "#outliner";
//op glue routines
function opUndo () {
return ($(defaultUtilsOutliner).concord ().op.undo ())
}
function opCut () {
return ($(defaultUtilsOutliner).concord ().op.cut ())
}
function opCopy () {
return ($(defaultUtilsOutliner).concord ().op.copy ())
}
function opPaste () {
return ($(defaultUtilsOutliner).concord ().op.paste ())
}
function opReorg (dir, count) {
return ($(defaultUtilsOutliner).concord().op.reorg (dir, count));
}
function opSetFont (font, fontsize, lineheight) {
$(defaultUtilsOutliner).concord().prefs({"outlineFont": font, "outlineFontSize": fontsize, "outlineLineHeight": lineheight});
}
function opPromote () {
$(defaultUtilsOutliner).concord().op.promote();
}
function opDemote () {
$(defaultUtilsOutliner).concord().op.demote();
}
function opBold () {
return ($(defaultUtilsOutliner).concord().op.bold ());
}
function opItalic () {
return ($(defaultUtilsOutliner).concord().op.italic ());
}
function opLink (url) {
return ($(defaultUtilsOutliner).concord().op.link (url));
}
function opSetTextMode (fltextmode) {
$(defaultUtilsOutliner).concord ().op.setTextMode (fltextmode);
}
function opInTextMode () {
return ($(defaultUtilsOutliner).concord ().op.inTextMode ());
}
function opGetAtts () {
return $(defaultUtilsOutliner).concord().op.attributes.getAll();
}
function opGetOneAtt (name) {
return $(defaultUtilsOutliner).concord().op.attributes.getOne (name);
}
function opHasAtt (name) {
return (opGetOneAtt (name) != undefined);
}
function opSetOneAtt (name, value) {
return $(defaultUtilsOutliner).concord().op.attributes.setOne (name, value);
}
function opSetAtts (atts) {
return $(defaultUtilsOutliner).concord().op.attributes.setGroup(atts);
}
function opAddAtts (atts) {
return $(defaultUtilsOutliner).concord().op.attributes.addGroup(atts);
}
function opSetStyle (css) {
return $(defaultUtilsOutliner).concord ().op.setStyle (css);
}
function opGetLineText () {
return ($(defaultUtilsOutliner).concord().op.getLineText());
}
function opExpand () {
return ($(defaultUtilsOutliner).concord().op.expand());
}
function opExpandAllLevels () {
return ($(defaultUtilsOutliner).concord().op.expandAllLevels());
}
function opExpandEverything () {
return ($(defaultUtilsOutliner).concord().op.fullExpand());
}
function opCollapse () {
return ($(defaultUtilsOutliner).concord().op.collapse());
}
function opIsComment () {
return ($(defaultUtilsOutliner).concord ().script.isComment ());
}
function opMakeComment () {
return ($(defaultUtilsOutliner).concord ().script.makeComment ());
}
function opUnComment () {
return ($(defaultUtilsOutliner).concord ().script.unComment ());
}
function opToggleComment () {
if (opIsComment ()) {
opUnComment ();
}
else {
opMakeComment ();
}
}
function opCollapseEverything () {
return ($(defaultUtilsOutliner).concord().op.fullCollapse());
}
function opInsert (s, dir) {
return ($(defaultUtilsOutliner).concord().op.insert(s, dir));
}
function opInsertImage (url) {
return ($(defaultUtilsOutliner).concord ().op.insertImage (url));
}
function opSetLineText (s) {
return ($(defaultUtilsOutliner).concord().op.setLineText(s));
}
function opDeleteSubs () {
return ($(defaultUtilsOutliner).concord().op.deleteSubs());
}
function opCountSubs () {
return ($(defaultUtilsOutliner).concord().op.countSubs());
}
function opHasSubs () {
return (opCountSubs () > 0);
}
function opSubsExpanded () {
return ($(defaultUtilsOutliner).concord().op.subsExpanded());
}
function opGo (dir, ct) {
return ($(defaultUtilsOutliner).concord().op.go(dir, ct));
}
function opFirstSummit () {
opGo (left, 32767);
opGo (up, 32767);
}
function opXmlToOutline (xmltext) {
return ($(defaultUtilsOutliner).concord ().op.xmlToOutline (xmltext));
}
function opInsertXml (xmltext, dir) {
return ($(defaultUtilsOutliner).concord ().op.insertXml (xmltext, dir));
}
function opOutlineToXml (ownerName, ownerEmail, ownerId) {
return ($(defaultUtilsOutliner).concord ().op.outlineToXml (ownerName, ownerEmail, ownerId));
}
function opCursorToXml () {
return ($(defaultUtilsOutliner).concord ().op.cursorToXml ());
}
function opSetTitle (title) {
return ($(defaultUtilsOutliner).concord ().op.setTitle (title));
}
function opGetTitle () {
return ($(defaultUtilsOutliner).concord ().op.getTitle ());
}
function opHasChanged () {
return ($(defaultUtilsOutliner).concord ().op.changed ());
}
function opClearChanged () {
return ($(defaultUtilsOutliner).concord ().op.clearChanged ());
}
function opMarkChanged () {
return ($(defaultUtilsOutliner).concord ().op.markChanged ());
}
function opRedraw () {
return ($(defaultUtilsOutliner).concord ().op.redraw ());
}
function opVisitAll (callback) { //9/13/13 by DW
return ($(defaultUtilsOutliner).concord ().op.visitAll (callback));
}
function opWipe () { //9/14/13 by DW
return ($(defaultUtilsOutliner).concord ().op.wipe ());
}
//readText
var readHttpUrl = "http://trex.smallpicture.com/ajax/httpReadUrl";
function readText (url, callback, op, flAcceptOpml) {
var headerval = {};
if ((flAcceptOpml != undefined) && flAcceptOpml) { //5/14/13 by DW
headerval = {"Accept": "text/x-opml"};
}
var jxhr = $.ajax ({
url: readHttpUrl + "?url=" + encodeURIComponent (url) + "&type=" + encodeURIComponent ("text/plain"),
dataType: "text",
headers: headerval,
timeout: 30000
})
.success (function (data, status) {
callback (data, op);
})
.error (function (status) {
httpReadStatus = status;
});
}
//string routines
function filledString (s, ct) {
var theString = "";
for (var i = 0; i < ct; i++) {
theString += s;
}
return (theString);
}
function multipleReplaceAll (s, adrTable, flCaseSensitive, startCharacters, endCharacters) {
if(flCaseSensitive===undefined){
flCaseSensitive = false;
}
if(startCharacters===undefined){
startCharacters="";
}
if(endCharacters===undefined){
endCharacters="";
}
for( var item in adrTable){
var replacementValue = adrTable[item];
var regularExpressionModifier = "g";
if(!flCaseSensitive){
regularExpressionModifier = "gi";
}
var regularExpressionString = (startCharacters+item+endCharacters).replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
var regularExpression = new RegExp(regularExpressionString, regularExpressionModifier);
s = s.replace(regularExpression, replacementValue);
}
return s;
};
//misc
function secondsSince (when) {
var now = new Date ();
return ((now - when) / 1000);
}