mirror of
https://github.com/Yetangitu/owncloud-apps.git
synced 2025-10-02 14:49:17 +02:00
reader: lots'a changes again, still in flux...
This commit is contained in:
parent
57a76be890
commit
c7ba1e3fb1
9 changed files with 265 additions and 211 deletions
|
@ -15,10 +15,10 @@ return ['routes' => [
|
|||
['name' => 'page#showReader', 'url' => '/', 'verb' => 'GET'],
|
||||
|
||||
// Bookmarks
|
||||
['name' => 'bookmark#get_cursor', 'url' => '/position/cursor/{fileId}', 'verb' => 'GET'],
|
||||
['name' => 'bookmark#set_cursor', 'url' => '/position/cursor/{fileId}/{value}', 'verb' => 'POST'],
|
||||
['name' => 'bookmark#get', 'url' => '/position/{fileId}/{name}', 'verb' => 'GET', 'defaults' => ['name' => '']],
|
||||
['name' => 'bookmark#set', 'url' => '/position/{fileId}/{name}/{value}', 'verb' => 'POST'],
|
||||
['name' => 'bookmark#get_cursor', 'url' => '/bookmark/cursor/{fileId}', 'verb' => 'GET'],
|
||||
['name' => 'bookmark#set_cursor', 'url' => '/bookmark/cursor/{fileId}/{value}', 'verb' => 'POST'],
|
||||
['name' => 'bookmark#get', 'url' => '/bookmark/{fileId}/{name}', 'verb' => 'GET', 'defaults' => ['name' => '']],
|
||||
['name' => 'bookmark#set', 'url' => '/bookmark/{fileId}/{name}/{value}', 'verb' => 'POST'],
|
||||
|
||||
// Metadata
|
||||
['name' => 'metadata#get', 'url' => '/metadata/{fileId}/{name}', 'verb' => 'GET', 'defaults' => ['name' => '']],
|
||||
|
|
|
@ -79,6 +79,7 @@ class PageController extends Controller {
|
|||
'cursor' => $this->toJson($this->bookmarkService->getCursor($fileId)),
|
||||
'defaults' => $this->toJson($this->preferenceService->getDefault($scope)),
|
||||
'preferences' => $this->toJson($this->preferenceService->get($scope, $fileId)),
|
||||
'defaults' => $this->toJson($this->preferenceService->getDefault($scope)),
|
||||
'metadata' => $this->toJson($this->metadataService->get($fileId))
|
||||
];
|
||||
|
||||
|
|
|
@ -12,12 +12,23 @@ namespace OCA\Files_Reader\Db;
|
|||
|
||||
use OCP\AppFramework\Db\Entity;
|
||||
|
||||
class Bookmark extends Entity {
|
||||
class Bookmark extends ReaderEntity implements \JsonSerializable {
|
||||
|
||||
protected $userId; // user
|
||||
protected $fileId; // book (identified by fileId) for which this mark is valid
|
||||
protected $name; // name, defaults to $location
|
||||
protected $value; // bookmark value (format-specific, eg. page number for PDF, CFI for epub, etc)
|
||||
protected $lastModified; // modification timestamp
|
||||
|
||||
public function jsonSerialize() {
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
'userId' => $this->getUserId(),
|
||||
'fileId' => $this->getFileId(),
|
||||
'name' => $this->getName(),
|
||||
'value' => static::conditional_json_decode($this->getValue()),
|
||||
'lastModified' => $this->getLastModified(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace OCA\Files_Reader\Db;
|
|||
|
||||
use OCP\AppFramework\Db\Entity;
|
||||
|
||||
class Preference extends Entity {
|
||||
class Preference extends ReaderEntity implements \JsonSerializable {
|
||||
|
||||
protected $userId; // user for whom this preference is valid
|
||||
protected $scope; // scope (default or specific renderer)
|
||||
|
@ -20,5 +20,16 @@ class Preference extends Entity {
|
|||
protected $name; // preference name
|
||||
protected $value; // preference value
|
||||
protected $lastModified; // modification timestamp
|
||||
|
||||
public function jsonSerialize() {
|
||||
return [
|
||||
'id' => $this->getId(),
|
||||
'scope' => $this->getScope(),
|
||||
'fileId' => $this->getFileId(),
|
||||
'name' => $this->getName(),
|
||||
'value' => $this->conditional_json_decode($this->getValue()),
|
||||
'lastModified' => $this->getLastModified(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@ use OCA\Files_Reader\Db\BookmarkMapper;
|
|||
|
||||
class BookmarkService extends Service {
|
||||
|
||||
// use 'CURSOR_$UserId' to identify cursor (current position in book)
|
||||
const CURSOR = 'CURSOR';
|
||||
// "bookmark" name to use for the cursor (current reading position)
|
||||
const CURSOR = '__CURSOR__';
|
||||
|
||||
private $bookmarkMapper;
|
||||
private $userId;
|
||||
|
@ -41,11 +41,7 @@ class BookmarkService extends Service {
|
|||
$result = $this->bookmarkMapper->get($fileId, $name);
|
||||
return array_map(
|
||||
function($entity) {
|
||||
return [
|
||||
'name' => $entity->getName(),
|
||||
'value' => $entity->getValue(),
|
||||
'lastModified' => $entity->getLastModified()
|
||||
];
|
||||
return $entity->toService();
|
||||
}, $result);
|
||||
}
|
||||
|
||||
|
@ -72,10 +68,7 @@ class BookmarkService extends Service {
|
|||
* @return array
|
||||
*/
|
||||
public function getCursor($fileId) {
|
||||
$cursor = self::CURSOR . '_' . $this->userId;
|
||||
if (!empty($value = $this->get($fileId, $cursor))) {
|
||||
return $value[0];
|
||||
}
|
||||
return $this->get($fileId, static::CURSOR);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,8 +80,7 @@ class BookmarkService extends Service {
|
|||
* @return array
|
||||
*/
|
||||
public function setCursor($fileId, $value) {
|
||||
$cursor = self::CURSOR . '_' . $this->userId;
|
||||
return $this->bookmarkMapper->set($fileId, $cursor, $value);
|
||||
return $this->bookmarkMapper->set($fileId, static::CURSOR, $value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,11 +44,7 @@ class PreferenceService extends Service {
|
|||
$result = $this->preferenceMapper->get($scope, $fileId, $name);
|
||||
return array_map(
|
||||
function($entity) {
|
||||
return [
|
||||
'name' => $entity->getName(),
|
||||
'value' => $entity->getValue(),
|
||||
'lastModified' => $entity->getLastModified()
|
||||
];
|
||||
return $entity->toService();
|
||||
}, $result);
|
||||
}
|
||||
|
||||
|
|
|
@ -103,22 +103,26 @@
|
|||
<!-- /toolbar -->
|
||||
|
||||
<!-- loading overlay -->
|
||||
<div id="cb-loading-overlay" class="cb-control control" name="loadingOverlay" style="display:none"></div>
|
||||
<div id="cbr-loading-overlay" class="cbr-control control overlay" name="loadingOverlay" style="display:none"></div>
|
||||
<!-- /loading overlay -->
|
||||
|
||||
<!-- busy overlay -->
|
||||
<div id="cbr-busy-overlay" class="cbr-control control overlay" name="busyOverlay" style="display:none"></div>
|
||||
<!-- /busy overlay -->
|
||||
|
||||
<!-- navigation -->
|
||||
<div data-trigger="click" data-action="navigation" data-navigate-side="left" class="cb-control navigate navigate-left control" name="navigateLeft">
|
||||
<div data-trigger="click" data-action="navigation" data-navigate-side="left" class="cbr-control navigate navigate-left control" name="navigateLeft">
|
||||
<span class="icon-navigate_before"></span>
|
||||
</div>
|
||||
<div data-trigger="click" data-action="toggleToolbar" class="toggle-controls control" name="toggleToolbar"></div>
|
||||
<div data-trigger="click" data-action="navigation" data-navigate-side="right" class="cb-control navigate navigate-right control" name="navigateRight">
|
||||
<div data-trigger="click" data-action="navigation" data-navigate-side="right" class="cbr-control navigate navigate-right control" name="navigateRight">
|
||||
<span class="icon-navigate_next"></span>
|
||||
</div>
|
||||
<!-- /navigation -->
|
||||
|
||||
<!-- inline progressbar -->
|
||||
<div id="cb-status" class="cb-control control" name="progressbar" style="display:none">
|
||||
<div id="cb-progress-bar">
|
||||
<div id="cbr-status" class="cbr-control control" name="progressbar" style="display:none">
|
||||
<div id="cbr-progress-bar">
|
||||
<div class="progressbar-value"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -133,6 +137,7 @@
|
|||
<button data-trigger="click" data-action="showSettings" title="show settings" class="icon-settings settings-view"></button>
|
||||
</div>
|
||||
<div class="pull-right">
|
||||
<button id="toc-populate" data-trigger="click" data-action="tocPopulate" title="generate thumbnails" class="icon-sync" style="display:none"></button>
|
||||
<button data-trigger="click" data-action="closeSidebar" title="close sidebar" class="icon-menu"></button>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -157,20 +162,21 @@
|
|||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="settings-container" name="enhancements">
|
||||
<div class="settings-container" name="enhancements" id="enhancements">
|
||||
<label for="enhancements">Image enhancements</label>
|
||||
<form name="image-enhancements" data-trigger="reset" data-action="resetEnhancements">
|
||||
<div class="sliders">
|
||||
<div class="control-group">
|
||||
<label title="adjust brightness" class="icon-brightness_low"></label>
|
||||
<input data-trigger="change" data-action="brightness" type="range" min="-100" max="100" step="1" value="0">
|
||||
<input id="brightness" data-trigger="change" data-action="brightness" type="range" min="-100" max="100" step="1" value="0">
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label title="adjust contrast" class="icon-contrast"></label>
|
||||
<input data-trigger="change" data-action="contrast" type="range" min="-1" max="1" step="0.1" value="0">
|
||||
<input id="contrast" data-trigger="change" data-action="brightness" type="range" min="-1" max="1" step="0.1" value="0">
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label title="sharpen" class="icon-droplet"></label>
|
||||
<input data-trigger="change" data-action="sharpen" type="range" min="0" max="1" step="0.1" value="0">
|
||||
<input id="sharpen" data-trigger="change" data-action="sharpen" type="range" min="0" max="1" step="0.1" value="0">
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group pull-left">
|
||||
|
@ -186,17 +192,14 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="settings-view view">
|
||||
<div class="settings-container" name="settings">
|
||||
<div class="settings-container" name="settings" id="thumbnail-settings">
|
||||
<label for="thumbnail-settings">Thumbnails</label>
|
||||
<form name="settings" data-trigger="reset" data-action="resetSettings">
|
||||
<div class="control-group pull-left">
|
||||
<input id="thumbnail-width" type="number" min="50" max="500" step="10" value="200" >
|
||||
<input id="thumbnail-generate" data-trigger="change" data-action="thumbnails" type="checkbox">
|
||||
<label for="thumbnail-generate">Use thumbnails in index </label>
|
||||
<input id="thumbnail-width" data-trigger="change" data-action="thumbnailWidth" type="number" min="50" max="500" step="10" value="200" >
|
||||
<label for="thumbnail-width">Thumbnail width</label>
|
||||
<input id="thumbnail-generate" type="checkbox" checked>
|
||||
<label for="thumbnail-generate">Thumbnails in index (disable to save memory)</label>
|
||||
</div>
|
||||
<div class="control-group pull-right">
|
||||
<input type="submit" value="save">
|
||||
<input type="reset" value="reset">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
|
76
reader/vendor/cbrjs/cbr.css
vendored
76
reader/vendor/cbrjs/cbr.css
vendored
|
@ -51,12 +51,12 @@ table {
|
|||
border-spacing: 0;
|
||||
}
|
||||
|
||||
.cb-control {
|
||||
.cbr-control {
|
||||
font-family: helvetica, arial, sans-serif;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.cb-control {
|
||||
.cbr-control {
|
||||
color: #fff;
|
||||
background-color: #111;
|
||||
padding: 10px;
|
||||
|
@ -114,14 +114,17 @@ body:not(.mobile) .navigate:hover {
|
|||
position: fixed;
|
||||
}
|
||||
|
||||
#cb-loading-overlay {
|
||||
#cbr-loading-overlay {
|
||||
z-index: 100;
|
||||
opacity: 0.8;
|
||||
background: #000 url("img/loading.gif") no-repeat center;
|
||||
}
|
||||
|
||||
.overlay {
|
||||
opacity: 0.7;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
#cb-status {
|
||||
#cbr-status {
|
||||
z-index: 101;
|
||||
font-size: 12px;
|
||||
right: 0;
|
||||
|
@ -130,16 +133,16 @@ body:not(.mobile) .navigate:hover {
|
|||
border-radius: 4px;
|
||||
}
|
||||
|
||||
#cb-progress-bar {
|
||||
#cbr-progress-bar {
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
#cb-progress-bar,
|
||||
#cb-progress-bar .progressbar-value {
|
||||
#cbr-progress-bar,
|
||||
#cbr-progress-bar .progressbar-value {
|
||||
height: 3px;
|
||||
}
|
||||
|
||||
#cb-progress-bar .progressbar-value {
|
||||
#cbr-progress-bar .progressbar-value {
|
||||
width: 0;
|
||||
background: #86C441;
|
||||
border-color: #3E7600;
|
||||
|
@ -209,8 +212,7 @@ body:not(.mobile) .toolbar:hover,
|
|||
opacity: 1;
|
||||
}
|
||||
|
||||
.toolbar div,
|
||||
.sidebar div {
|
||||
.toolbar div {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
}
|
||||
|
@ -257,12 +259,6 @@ body:not(.mobile) .toolbar button[data-action=close]:hover {
|
|||
/* sidebar */
|
||||
.sidebar.open {
|
||||
box-shadow: 3px 0px 3px 0px rgba(0, 0, 0, 0.4);
|
||||
/* transitions and animations cause problems on older devices...
|
||||
transform: translate3d(0,0,0);
|
||||
-webkit-transform: translate3d(0,0,0);
|
||||
transition: all 0.3s ease-out;
|
||||
-webkit-transition: all 0.3s ease-out;
|
||||
... so use display instead ...*/
|
||||
display: block;
|
||||
}
|
||||
|
||||
|
@ -274,21 +270,12 @@ body:not(.mobile) .toolbar button[data-action=close]:hover {
|
|||
min-width: 25em;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
/* transitions and animations cause problems on older devices...
|
||||
transform: translate3d(-20vw,0,0);
|
||||
-webkit-transform: translate3d(-20vw,0,0);
|
||||
transition: all 0.3s ease-out;
|
||||
-webkit-transition: all 0.3s ease-out;
|
||||
... so use display instead ...*/
|
||||
display: none;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.panels {
|
||||
position: fixed;
|
||||
overflow: hidden;
|
||||
box-shadow: 0px 1px 3px rgba(0,0,0,.6);
|
||||
z-index: 101;
|
||||
}
|
||||
|
||||
.panels .open {
|
||||
|
@ -299,6 +286,11 @@ body:not(.mobile) .toolbar button[data-action=close]:hover {
|
|||
display: block !important;
|
||||
}
|
||||
|
||||
#toc-populate.open {
|
||||
display: inline-block !important;
|
||||
background-color: #4e4e4e;
|
||||
}
|
||||
|
||||
.view {
|
||||
overflow-x: hidden;
|
||||
display: none !important;
|
||||
|
@ -312,32 +304,49 @@ body:not(.mobile) .toolbar button[data-action=close]:hover {
|
|||
font-family: Georgia, "Times New Roman", Times, serif;
|
||||
}
|
||||
|
||||
.toc-view img {
|
||||
.toc-view img, .placeholder {
|
||||
width: 100%;
|
||||
position: relative;
|
||||
background-color: #999;
|
||||
}
|
||||
|
||||
.toc-view img + span {
|
||||
position: absolute;
|
||||
.toc-view span {
|
||||
position: relative;
|
||||
font-size: 5em;
|
||||
font-weight: bold;
|
||||
color: #F8F8F8;
|
||||
left: 60%;
|
||||
margin-top: 75%;
|
||||
float: right;
|
||||
top: -2em;
|
||||
left: -2em;
|
||||
text-shadow: 0.05em 0.05em 0.02em rgba(70, 70, 70, 0.8);
|
||||
-webkit-text-stroke: 2px black;
|
||||
}
|
||||
|
||||
.settings-container {
|
||||
position: absolute;
|
||||
font-size: 1em;
|
||||
background: #F8F8F8;
|
||||
color: #111;
|
||||
padding: 1em;
|
||||
margin: 1em;
|
||||
margin-top: 1em;
|
||||
left: 1em;
|
||||
right: 1em;
|
||||
border-radius: 4px;
|
||||
box-shadow: 0 1px 10px rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.settings-container label {
|
||||
margin-right: 1em;
|
||||
}
|
||||
|
||||
.settings-container > label {
|
||||
font-weight: bold;
|
||||
width: 100%;
|
||||
display: inline-block;
|
||||
margin-bottom: 1em;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.view .control-group input[type=range] {
|
||||
width: 90%;
|
||||
float: right;
|
||||
|
@ -345,8 +354,7 @@ body:not(.mobile) .toolbar button[data-action=close]:hover {
|
|||
}
|
||||
|
||||
.view .control-group {
|
||||
padding: 0.5em;
|
||||
width: 95%;
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
.view .sliders {
|
||||
|
|
300
reader/vendor/cbrjs/cbr.js
vendored
300
reader/vendor/cbrjs/cbr.js
vendored
|
@ -20,6 +20,7 @@ CBRJS.Reader = function(bookPath, _options) {
|
|||
CBRJS.session.cursor = $('.session').data('cursor') || {};
|
||||
CBRJS.session.defaults = $('.session').data('defaults') || {};
|
||||
CBRJS.session.preferences = $('.session').data('preferences') || {};
|
||||
CBRJS.session.defaults = $('.session').data('defaults') || {};
|
||||
CBRJS.basePath = $('.session').data('basepath');
|
||||
CBRJS.downloadLink = $('.session').data('downloadlink');
|
||||
|
||||
|
@ -127,7 +128,7 @@ CBRJS.Reader = function(bookPath, _options) {
|
|||
|
||||
var title, page = 0;
|
||||
|
||||
var options = $.extend({
|
||||
var options = $.extend(true, {
|
||||
getPreference: function(name) {},
|
||||
setPreference: function(name, value) {},
|
||||
getDefault: function(name) {},
|
||||
|
@ -139,7 +140,9 @@ CBRJS.Reader = function(bookPath, _options) {
|
|||
vendorPath: 'vendor/'
|
||||
}, opts);
|
||||
|
||||
console.log("options:");
|
||||
console.log("opts before extractImages:");
|
||||
console.log(opts);
|
||||
console.log("options before extractImages:");
|
||||
console.log(options);
|
||||
|
||||
extractImages(url, {
|
||||
|
@ -182,13 +185,23 @@ CBRJS.Reader = function(bookPath, _options) {
|
|||
book.destroy();
|
||||
});
|
||||
|
||||
console.log("options:");
|
||||
console.log("options after extractImages:");
|
||||
console.log(options);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
function getPref (arr, name) {
|
||||
if (found = arr.find(function(e) { return e.name === name; })) {
|
||||
if (found.hasOwnProperty("value")) {
|
||||
console.log("property " + name + " has value " + found.value);
|
||||
return found.value;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
console.log("CBRJS:");console.log(CBRJS);
|
||||
|
||||
openComicArchive(bookPath, {
|
||||
|
@ -206,79 +219,28 @@ CBRJS.Reader = function(bookPath, _options) {
|
|||
return $.post(CBRJS.basePath + "preference/default/" + CBRJS.session.scope + "/" + name + "/" + JSON.stringify(value));
|
||||
},
|
||||
getBookmark: function(name) {
|
||||
return $.get(CBRJS.basePath + "position/" + CBRJS.session.fileId + "/" + name);
|
||||
return $.get(CBRJS.basePath + "bookmark/" + CBRJS.session.fileId + "/" + name);
|
||||
},
|
||||
setBookmark: function(name, value) {
|
||||
return $.post(CBRJS.basePath + "bookmark/" + CBRJS.session.fileId + "/" + name + "/" + JSON.stringify(value));
|
||||
},
|
||||
getCursor: function() {
|
||||
return $.get(CBRJS.basePath + "position/cursor/" + CBRJS.session.fileId);
|
||||
return $.get(CBRJS.basePath + "bookmark/cursor/" + CBRJS.session.fileId);
|
||||
},
|
||||
setCursor: function(value) {
|
||||
return $.post(CBRJS.basePath + "position/cursor/" + CBRJS.session.fileId + "/" + JSON.stringify(value));
|
||||
return $.post(CBRJS.basePath + "bookmark/cursor/" + CBRJS.session.fileId + "/" + JSON.stringify(value));
|
||||
},
|
||||
currentPage: (CBRJS.session.cursor.hasOwnProperty('value')) ? parseInt(CBRJS.session.cursor.value) : 0,
|
||||
filters: (CBRJS.session.preferences.hasOwnProperty('filters')) ? CBRJS.session.preferences.filters : {},
|
||||
manga: (CBRJS.session.preferences.hasOwnProperty('manga')) ? CBRJS.session.preferences.manga : false
|
||||
currentPage: parseInt(getPref(CBRJS.session.cursor, "__CURSOR__")) || 0,
|
||||
enhance: getPref(CBRJS.session.preferences, "enhance") || {},
|
||||
manga: getPref(CBRJS.session.preferences, "manga") || false,
|
||||
thumbnails: getPref(CBRJS.session.defaults, "thumbnails"),
|
||||
thumbnailWidth: parseInt(getPref(CBRJS.session.defaults, "thumbnailWidth")) || 200
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/*
|
||||
* object.watch polyfill
|
||||
*
|
||||
* 2012-04-03
|
||||
*
|
||||
* By Eli Grey, http://eligrey.com
|
||||
* Public Domain.
|
||||
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
||||
*/
|
||||
|
||||
// object.watch
|
||||
if (!Object.prototype.watch) {
|
||||
Object.defineProperty(Object.prototype, "watch", {
|
||||
enumerable: false
|
||||
, configurable: true
|
||||
, writable: false
|
||||
, value: function (prop, handler) {
|
||||
var
|
||||
oldval = this[prop]
|
||||
, newval = oldval
|
||||
, getter = function () {
|
||||
return newval;
|
||||
}
|
||||
, setter = function (val) {
|
||||
oldval = newval;
|
||||
return newval = handler.call(this, prop, oldval, val);
|
||||
}
|
||||
;
|
||||
|
||||
if (delete this[prop]) { // can't watch constants
|
||||
Object.defineProperty(this, prop, {
|
||||
get: getter
|
||||
, set: setter
|
||||
, enumerable: true
|
||||
, configurable: true
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// object.unwatch
|
||||
if (!Object.prototype.unwatch) {
|
||||
Object.defineProperty(Object.prototype, "unwatch", {
|
||||
enumerable: false
|
||||
, configurable: true
|
||||
, writable: false
|
||||
, value: function (prop) {
|
||||
var val = this[prop];
|
||||
delete this[prop]; // remove accessors
|
||||
this[prop] = val;
|
||||
}
|
||||
});
|
||||
}
|
||||
/* pixastic */
|
||||
|
||||
/*!
|
||||
* Pixastic - JavaScript Image Processing
|
||||
|
@ -1948,8 +1910,9 @@ ComicBook = (function ($) {
|
|||
zoomMode: 'fitWindow', // manual / fitWidth / fitWindow
|
||||
manga: false, // true / false
|
||||
fullscreen: false, // true / false
|
||||
enhance: {},
|
||||
thumbWidth: 200, // width of thumbnail
|
||||
enhance: {}, // image filters to use
|
||||
thumbnails: true, // true / false (use thumbnails in index)
|
||||
thumbnailWidth: 200, // width of thumbnail
|
||||
currentPage: 0, // current page
|
||||
keyboard: {
|
||||
32: 'next', // space
|
||||
|
@ -2028,7 +1991,7 @@ ComicBook = (function ($) {
|
|||
|
||||
if (shiv === false) {
|
||||
shiv = $(document.createElement('div'))
|
||||
.attr('id', 'cb-width-shiv')
|
||||
.attr('id', 'cbr-width-shiv')
|
||||
.css({
|
||||
width: '100%',
|
||||
position: 'absolute',
|
||||
|
@ -2116,9 +2079,41 @@ ComicBook = (function ($) {
|
|||
*/
|
||||
ComicBook.prototype.renderControls = function () {
|
||||
|
||||
var controls = {},
|
||||
$toolbar;
|
||||
var controls = {}, $toolbar;
|
||||
|
||||
// set values from preferences or defaults
|
||||
// do this before connecting listeners to avoid triggering callbacks
|
||||
for (var prop in options.enhance) {
|
||||
if(options.enhance.hasOwnProperty(prop)) {
|
||||
switch (prop) {
|
||||
case 'brightness':
|
||||
document.getElementById('brightness').value = options.enhance.brightness['brightness'];
|
||||
document.getElementById('contrast').value = options.enhance.brightness['contrast'];
|
||||
break;
|
||||
case 'sharpen':
|
||||
document.getElementById('sharpen').value = options.enhance.sharpen['strength'];
|
||||
break;
|
||||
case 'desaturate':
|
||||
$('#image-desaturate').prop('checked', true);
|
||||
break;
|
||||
case 'removenoise':
|
||||
$('#image-removenoise').prop('checked', true);
|
||||
break;
|
||||
default:
|
||||
console.log("unknown enhancement: " + JSON.stringify(prop));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// thumbnail controls
|
||||
$('#thumbnail-generate').prop('checked', options.thumbnails);
|
||||
$('#thumbnail-width').val(options.thumbnailWidth);
|
||||
if (!options.thumbnails) {
|
||||
$('#toc-populate').addClass('open');
|
||||
$('#thumbnail-width').prop('disabled', true);
|
||||
}
|
||||
|
||||
// connect callbacks
|
||||
$('.control').each(function () {
|
||||
|
||||
controls[$(this).attr('name')] = $(this);
|
||||
|
@ -2191,41 +2186,37 @@ ComicBook = (function ($) {
|
|||
*
|
||||
* @return Image
|
||||
*/
|
||||
ComicBook.prototype.getThumb = function (image, page) {
|
||||
ComicBook.prototype.getThumb = function (image) {
|
||||
var thumb = new Image();
|
||||
var scale = image.width / options.thumbWidth;
|
||||
|
||||
tcv.width = options.thumbWidth;
|
||||
var scale = image.width / options.thumbnailWidth;
|
||||
tcv.width = options.thumbnailWidth;
|
||||
tcv.height = Math.floor(image.height / scale);
|
||||
|
||||
tctx.drawImage(image, 0, 0, tcv.width, tcv.height);
|
||||
|
||||
thumb.src = tcv.toDataURL();
|
||||
thumb.addEventListener('click', function (e) {
|
||||
self.drawPage(page + 1, true);
|
||||
});
|
||||
tctx.clearRect(0, 0, tcv.width, tcv.height);
|
||||
|
||||
return thumb;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create empty TOC
|
||||
* Create empty TOC with placeholder images
|
||||
*/
|
||||
ComicBook.prototype.tocCreate = function (no_pages) {
|
||||
var width = options.thumbWidth;
|
||||
var height = options.thumbWidth * 1.414;
|
||||
// use small image with reasonable aspect ratio
|
||||
tcv.width = 5;
|
||||
tcv.height = 7;
|
||||
// transparent, style with .placeholder in CSS
|
||||
tctx.fillStyle = "rgba(200, 200, 200, 0)";
|
||||
tctx.fillRect(0, 0, tcv.width, tcv.height);
|
||||
var imgsrc = tcv.toDataURL();
|
||||
|
||||
for(var i = 0; i < no_pages; i++) {
|
||||
var item = document.createElement('li');
|
||||
var placeholder = document.createElement('div');
|
||||
placeholder.setAttribute("style","display:block;width:" + width + "px;height:" + height + "px;background:#AAA");
|
||||
placeholder.className = "placeholder";
|
||||
item.setAttribute("id", "page-" + parseInt(i + 1));
|
||||
var placeholder = new Image();
|
||||
placeholder.src = imgsrc;
|
||||
var label = document.createElement('span');
|
||||
label.innerHTML = i + 1;
|
||||
item.addEventListener('click', function (e) {
|
||||
self.drawPage(i + 1, true);
|
||||
});
|
||||
item.appendChild(placeholder);
|
||||
item.appendChild(label);
|
||||
toc.appendChild(item);
|
||||
|
@ -2235,9 +2226,33 @@ ComicBook = (function ($) {
|
|||
/**
|
||||
* Insert thumbnail into TOC
|
||||
*/
|
||||
ComicBook.prototype.tocInsert = function (thumb, page) {
|
||||
ComicBook.prototype.tocInsert = function (image, page, replace) {
|
||||
var placeholder = toc.children[page].firstChild;
|
||||
placeholder.parentNode.replaceChild(thumb,placeholder);
|
||||
if (replace === true) {
|
||||
placeholder.parentNode.replaceChild(
|
||||
self.getThumb(image),
|
||||
placeholder
|
||||
);
|
||||
}
|
||||
|
||||
toc.children[page].addEventListener('click', function (e) {
|
||||
self.drawPage(page + 1, true);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Populate TOC on demand
|
||||
*/
|
||||
ComicBook.prototype.tocPopulate = function () {
|
||||
var i = 0;
|
||||
while (i < srcs.length) {
|
||||
self.tocInsert(pages[i], i, true);
|
||||
i++;
|
||||
}
|
||||
|
||||
// set, but don't save
|
||||
options.thumbnails = true;
|
||||
$('#toc-populate').removeClass('open');
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -2268,7 +2283,7 @@ ComicBook = (function ($) {
|
|||
|
||||
// resize navigation controls
|
||||
$('.navigate').outerHeight(window.innerHeight);
|
||||
$('#cb-loading-overlay').outerWidth(windowWidth()).height(window.innerHeight);
|
||||
$('.overlay').outerWidth(windowWidth()).height(window.innerHeight);
|
||||
|
||||
// preload images if needed
|
||||
if (pages.length !== no_pages) {
|
||||
|
@ -2331,12 +2346,12 @@ ComicBook = (function ($) {
|
|||
page.onload = function () {
|
||||
|
||||
pages[i] = this;
|
||||
thumbs[i] = self.getThumb(this, i);
|
||||
self.tocInsert(thumbs[i], i);
|
||||
|
||||
self.tocInsert(this, i, options.thumbnails);
|
||||
|
||||
loaded.push(i);
|
||||
|
||||
$('#cb-progress-bar .progressbar-value').css('width', Math.floor((loaded.length / no_pages) * 100) + '%');
|
||||
$('#cbr-progress-bar .progressbar-value').css('width', Math.floor((loaded.length / no_pages) * 100) + '%');
|
||||
|
||||
// double page mode needs an extra page added
|
||||
var buffer = (options.displayMode === 'double' && options.currentPage < srcs.length - 1) ? 1 : 0;
|
||||
|
@ -2359,7 +2374,7 @@ ComicBook = (function ($) {
|
|||
loadImage(queue[0]);
|
||||
queue.splice(0, 1);
|
||||
} else {
|
||||
$('#cb-status').delay(500).fadeOut();
|
||||
$('#cbr-status').delay(500).fadeOut();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -2574,8 +2589,8 @@ ComicBook = (function ($) {
|
|||
}
|
||||
|
||||
// disable the fit width button if needed
|
||||
$('button.cb-fit-width').attr('disabled', (options.zoomMode === 'fitWidth'));
|
||||
$('button.cb-fit-window').attr('disabled', (options.zoomMode === 'fitWindow'));
|
||||
$('button.cbr-fit-width').attr('disabled', (options.zoomMode === 'fitWidth'));
|
||||
$('button.cbr-fit-window').attr('disabled', (options.zoomMode === 'fitWindow'));
|
||||
|
||||
// disable prev/next buttons if not needed
|
||||
$('.navigate').show();
|
||||
|
@ -2670,22 +2685,37 @@ ComicBook = (function ($) {
|
|||
window.scroll(0, 0);
|
||||
};
|
||||
|
||||
ComicBook.prototype.brightness = function () {
|
||||
options.enhance.brightness = $(this).val();
|
||||
self.enhance.brightness({
|
||||
brightness: options.enhance.brightness
|
||||
});
|
||||
/* default settings */
|
||||
|
||||
options.setPreference("filters",options.enhance);
|
||||
ComicBook.prototype.thumbnails = function() {
|
||||
if ($(this).is(':checked')) {
|
||||
options.thumbnails = true;
|
||||
document.getElementById('thumbnail-width').disabled = false;
|
||||
} else {
|
||||
options.thumbnails = false;
|
||||
document.getElementById('thumbnail-width').disabled = true;
|
||||
}
|
||||
|
||||
options.setDefault("thumbnails", options.thumbnails);
|
||||
};
|
||||
|
||||
ComicBook.prototype.contrast = function () {
|
||||
options.enhance.contrast = $(this).val();
|
||||
self.enhance.brightness({
|
||||
contrast: options.enhance.contrast
|
||||
});
|
||||
ComicBook.prototype.thumbnailWidth = function() {
|
||||
options.thumbnailWidth = $(this).val();
|
||||
options.setDefault("thumbnailWidth", options.thumbnailWidth);
|
||||
};
|
||||
|
||||
options.setPreference("filters",options.enhance);
|
||||
/* book-specific settings */
|
||||
|
||||
ComicBook.prototype.brightness = function () {
|
||||
var $brightness = {
|
||||
brightness: $('#brightness').val(),
|
||||
contrast: $('#contrast').val()
|
||||
};
|
||||
|
||||
self.enhance.brightness($brightness);
|
||||
options.enhance.brightness = $brightness;
|
||||
options.setPreference("enhance",options.enhance);
|
||||
console.log(options.enhance);
|
||||
};
|
||||
|
||||
ComicBook.prototype.sharpen = function () {
|
||||
|
@ -2694,7 +2724,8 @@ ComicBook = (function ($) {
|
|||
strength: options.enhance.sharpen
|
||||
});
|
||||
|
||||
options.setPreference("filters",options.enhance);
|
||||
options.setPreference("enhance",options.enhance);
|
||||
console.log(options.enhance);
|
||||
};
|
||||
|
||||
ComicBook.prototype.desaturate = function () {
|
||||
|
@ -2706,7 +2737,8 @@ ComicBook = (function ($) {
|
|||
self.enhance.resaturate();
|
||||
}
|
||||
|
||||
options.setPreference("filters",options.enhance);
|
||||
options.setPreference("enhance",options.enhance);
|
||||
console.log(options.enhance);
|
||||
};
|
||||
|
||||
ComicBook.prototype.removenoise = function () {
|
||||
|
@ -2718,11 +2750,14 @@ ComicBook = (function ($) {
|
|||
self.enhance.unremovenoise();
|
||||
}
|
||||
|
||||
options.setPreference("filters",options.enhance);
|
||||
options.setPreference("enhance",options.enhance);
|
||||
console.log(options.enhance);
|
||||
};
|
||||
|
||||
ComicBook.prototype.resetEnhancements = function () {
|
||||
self.enhance.reset();
|
||||
options.setPreference("enhance",options.enhance);
|
||||
console.log(options.enhance);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -2749,8 +2784,6 @@ ComicBook = (function ($) {
|
|||
delete options.enhance[method];
|
||||
}
|
||||
self.drawPage(null, false);
|
||||
|
||||
options.setPreference("filters",options.enhance);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -2791,7 +2824,6 @@ ComicBook = (function ($) {
|
|||
contrast: 0
|
||||
}, params);
|
||||
|
||||
// remember options for later
|
||||
options.enhance.brightness = opts;
|
||||
|
||||
// run the enhancement
|
||||
|
@ -2862,7 +2894,7 @@ ComicBook = (function ($) {
|
|||
ComicBook.prototype.navigation = function (e) {
|
||||
|
||||
// disable navigation when the overlay is showing
|
||||
if ($('#cb-loading-overlay').is(':visible')) {
|
||||
if ($('#cbr-loading-overlay').is(':visible')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2964,15 +2996,19 @@ ComicBook = (function ($) {
|
|||
ComicBook.prototype.openSidebar = function () {
|
||||
$('.sidebar').addClass('open');
|
||||
$('.toolbar').addClass('open');
|
||||
self.showControl('busyOverlay');
|
||||
self.scrollToc();
|
||||
};
|
||||
|
||||
ComicBook.prototype.closeSidebar = function () {
|
||||
$('.sidebar').removeClass('open');
|
||||
$('.toolbar').removeClass('open');
|
||||
self.hideControl('busyOverlay');
|
||||
};
|
||||
|
||||
ComicBook.prototype.toggleSidebar = function () {
|
||||
$('.sidebar').toggleClass('open');
|
||||
self.scrollToc();
|
||||
};
|
||||
|
||||
ComicBook.prototype.toggleFullscreen = function () {
|
||||
|
@ -2987,13 +3023,26 @@ ComicBook = (function ($) {
|
|||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Scroll TOC to page (default: current page)
|
||||
*/
|
||||
ComicBook.prototype.scrollToc = function (page) {
|
||||
if (page === undefined) {
|
||||
page = options.currentPage;
|
||||
}
|
||||
|
||||
document.getElementById('toc').parentNode.scrollTop =
|
||||
document.getElementById('page-' + page + 1).offsetTop
|
||||
- Math.floor($('.panels').height() * 1.5);
|
||||
};
|
||||
|
||||
ComicBook.prototype.showToc = function () {
|
||||
/* self.getControl('sidebar')
|
||||
.find('.view').hide().end()
|
||||
.find('#tocView').show(); */
|
||||
self.getControl('sidebar')
|
||||
.find('.open').removeClass('open').end()
|
||||
.find('.toc-view').addClass('open');
|
||||
if (!options.thumbnails) {
|
||||
$('#toc-populate').addClass('open');
|
||||
}
|
||||
};
|
||||
|
||||
ComicBook.prototype.showBookSettings = function () {
|
||||
|
@ -3022,23 +3071,6 @@ ComicBook = (function ($) {
|
|||
|
||||
setHash('');
|
||||
|
||||
/* ugly, but for now... */
|
||||
options.currentPage = undefined;
|
||||
no_pages = undefined;
|
||||
pages = undefined;
|
||||
thumbs = undefined;
|
||||
canvas = undefined;
|
||||
context = undefined;
|
||||
tcv = undefined;
|
||||
tctx = undefined;
|
||||
toc = undefined;
|
||||
loaded = undefined;
|
||||
scale = undefined;
|
||||
is_double_page_spread = undefined;
|
||||
controlsRendered = undefined;
|
||||
page_requested = undefined;
|
||||
shiv = undefined;
|
||||
|
||||
// $(this).trigger('destroy');
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue