-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathepub-local.js
83 lines (81 loc) · 4.34 KB
/
epub-local.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
// Generated by CoffeeScript 1.3.3
(function() {
define(['jquery', 'backbone', 'atc/controller', 'atc/models', 'epub/models', 'css!atc'], function(jQuery, Backbone, AtcController, AtcModels, Models) {
var CALLBACK_DELAY, CH1_ID, CH1_PATH, CH2_ID, CH2_PATH, FILES, NAV_PATH, OPF_ID, OPF_LANGUAGE, OPF_PATH, OPF_TITLE;
window.FILES = FILES = {};
Backbone.sync = function(method, model, options) {
var deferred, path, text;
deferred = jQuery.Deferred();
path = model.id || (typeof model.url === "function" ? model.url() : void 0) || model.url;
if (method === 'update') {
text = model.serialize();
FILES[path] = text;
if (options != null) {
if (typeof options.success === "function") {
options.success(model, 'SUCCESSFULLY_SAVED_IN_MEMORY', options);
}
}
deferred.resolve(model);
}
if (method === 'read') {
if (path in FILES) {
text = FILES[path];
if (options != null) {
if (typeof options.success === "function") {
options.success(model, text, options);
}
}
deferred.resolve(model);
} else {
if (options != null) {
if (typeof options.error === "function") {
options.error("PATH NOT FOUND: '" + path + "'");
}
}
deferred.reject("PATH NOT FOUND: '" + path + "'");
}
}
return deferred.promise();
};
CALLBACK_DELAY = 0;
OPF_ID = '12345';
OPF_TITLE = 'Github EPUB Editor';
OPF_LANGUAGE = 'en';
OPF_PATH = 'book.opf';
NAV_PATH = 'navigation.html';
CH1_PATH = 'background.html';
CH2_PATH = 'introduction.html';
CH1_ID = 'id-1-background';
CH2_ID = 'id-2-intro';
FILES['META-INF/container.xml'] = "<?xml version='1.0' encoding='UTF-8'?>\n<container xmlns=\"urn:oasis:names:tc:opendocument:xmlns:container\" version=\"1.0\">\n <rootfiles>\n <rootfile full-path=\"" + OPF_PATH + "\" media-type=\"application/oebps-package+xml\"/>\n </rootfiles>\n</container>";
FILES[OPF_PATH] = "<?xml version=\"1.0\"?>\n<package version=\"3.0\"\n xml:lang=\"en\"\n xmlns=\"http://www.idpf.org/2007/opf\"\n unique-identifier=\"pub-id\">\n <metadata xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n <dc:identifier\n id=\"pub-id\">" + OPF_ID + "</dc:identifier>\n <meta refines=\"#pub-id\"\n property=\"identifier-type\"\n scheme=\"xsd:string\">uuid</meta>\n\n <dc:language>" + OPF_LANGUAGE + "</dc:language>\n <dc:title>" + OPF_TITLE + "</dc:title>\n\n </metadata>\n\n <manifest>\n <item id=\"id-navigation\"\n properties=\"nav\"\n href=\"" + NAV_PATH + "\"\n media-type=\"application/xhtml+xml\"/>\n <item id=\"" + CH2_ID + "\"\n href=\"" + CH2_PATH + "\"\n media-type=\"application/xhtml+xml\"/>\n <item id=\"" + CH1_ID + "\"\n href=\"" + CH1_PATH + "\"\n media-type=\"application/xhtml+xml\"/>\n </manifest>\n <spine>\n <itemref idref=\"" + CH1_ID + "\"/>\n <itemref idref=\"" + CH2_ID + "\"/>\n </spine>\n</package>";
FILES[NAV_PATH] = "<p>Example Navigation</p>\n<nav>\n <ol>\n <li><a href=\"" + CH1_PATH + "\">" + CH1_ID + "</a></li>\n <li><a href=\"" + CH2_PATH + "\">" + CH2_ID + "</a></li>\n </ol>\n</nav>";
FILES[CH1_PATH] = '<h1>Background</h1>';
FILES[CH2_PATH] = '<h1>Introduction</h1>';
FILES['background.json'] = JSON.stringify({
title: 'Background Module Title'
});
return Models.EPUB_CONTAINER.loaded().then(function() {
console.log('Workspace loaded!');
AtcModels.SearchResults = AtcModels.SearchResults.extend({
initialize: function() {
var model, _i, _len, _ref, _results;
_ref = AtcModels.ALL_CONTENT.models;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
model = _ref[_i];
if (model.get('mediaType') !== 'text/x-module') {
_results.push(this.add(model, {
at: 0
}));
} else {
_results.push(this.add(model));
}
}
return _results;
}
});
return AtcController.start();
});
});
}).call(this);