Skip to content

Commit

Permalink
Notebook version updated
Browse files Browse the repository at this point in the history
  • Loading branch information
expertmodassir committed Oct 4, 2023
1 parent e76e7db commit 2059163
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 167 deletions.
1 change: 1 addition & 0 deletions components/open.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function fopener() {
$(".fetching-popup").remove();
/* clear Undo data when open new file data */
window.sessionStorage.removeItem("undoBackup");
$("#fopener").val("");
});
});
}
Expand Down
1 change: 0 additions & 1 deletion components/save.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { hidePopupWithEase } from "../exports/multiTaskHandler";
import tmpFilename from "../import/tmpFilename";
import textBackups from "../exports/textBackups";
import render from "../import/render";
import xhrSend from "../server/xhrSend";
Expand Down
Empty file removed components/save_all.js
Empty file.
4 changes: 2 additions & 2 deletions exports/contextOption.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function cbContext() {

export default function contextOption() {
readingOrder();
$(document).on("mousedown pointerdown visibilitychange resize", function(e) {
$(document).on("mousedown visibilitychange resize", function(e) {

if ($(e.target).parents(".tsd-list").length || $(e.target).is(".tsd-list")) {
return;
Expand Down Expand Up @@ -110,4 +110,4 @@ export default function contextOption() {
var checkbox = $("#writeDir")[0];
readingOrder=="rtl" ? (checkbox.checked=true) : (checkbox.checked=false);
});
}
}
43 changes: 43 additions & 0 deletions exports/download.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { checkActiveDownload } from "./multiTaskHandler";
import SBLogic from "../import/SBLogic";
import textBackups from "./textBackups";

function resetActivity() {
$(".line:first").empty().outerHeight(window.originalHeight).addClass("active");
$(".download, .clear-win").addClass("disabled");
$(".line:first, .counters span:first").nextAll().remove();
$(".writable-area").focus();
textBackups.text = "";
document.title = "Notebook";
SBLogic();
$(".ln, .col").text(1);
$(".extension").text("TXT");
$("body")
.attr("data-file-type", "txt").attr("data-file-exists", false) .removeAttr("data-file-opened");
}

export default function download() {
$(".download").click(function() {
$.ajax({
url: '/models/817248fb77fb5c2cef3f2c732ad257cb1fb9c5e4',
type: 'POST',
data: {File: checkActiveDownload()},
success: function(data) {
var download = document.createElement("a");
download.href=data;
var finfo = JSON.parse($.jsonParam(window.decodeURIComponent(this.data)));
download.download = finfo["File"]["File"] + "." + finfo["File"]["type"];
resetActivity();
download.click();
}
});
});
$(".clear-win").click(function() {
$.ajax({
url: '/models/817248fb77fb5c2cef3f2c732ad257cb1fb9c5e4',
type: 'POST',
data: {dispatch: checkActiveDownload()},
success: resetActivity
});
});
}
15 changes: 14 additions & 1 deletion exports/multiTaskHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ function multiTaskHandler() {
$(".s-edit").click(function() {
editOptionsEnableDisable(this);
});
$(".file-opt").click(checkActiveDownload);
}

function checkActiveDownload() {
var hasText = $(".line").text() && $(".line").text() !== " ";
var hasFile = $("body").attr("data-file-opened");
var hasType = $("body").attr("data-file-type");
var cHandle = hasFile && hasType ? "remove" : "add";
$(".download, .clear-win")[cHandle + "Class"]("disabled");

hasText ?
$(".clear-win").removeClass("disabled") : $(".clear-win").addClass("disabled");
return {File: hasFile, type: hasType};
}

function editOptionsEnableDisable(items) {
Expand Down Expand Up @@ -149,4 +162,4 @@ function enabledDisabledPastOpt(isSaveLocal, setEmpty) {
}

export default multiTaskHandler;
export { hidePopupWithEase, setUndoAtClickHandler, setUndoable, editOptionsEnableDisable };
export { hidePopupWithEase, setUndoAtClickHandler, setUndoable, editOptionsEnableDisable, checkActiveDownload };
2 changes: 2 additions & 0 deletions import/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import contextStatusBar from '../exports/contextStatusBar';
import onlineOffline from './onlineOffline';
import clickToZoomHandler from './ctozoom';
import previewPageContent from './preveiw';
import download from '../exports/download';
import settings from './settings';
import NBSinit from './NBSinit';
import render from './render';
Expand Down Expand Up @@ -65,6 +66,7 @@ render(
insertDate,
Undo,
multiTaskHandler,
download,
alertSaveChanges,
findReplace
);
Expand Down
4 changes: 4 additions & 0 deletions import/controlHoverList.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { editOptionsEnableDisable } from "../exports/multiTaskHandler";
import { checkActiveDownload } from "../exports/multiTaskHandler";

function controlHoverList() {
$(".list-opt").on("mouseover", function(e) {
Expand All @@ -14,6 +15,9 @@ function controlHoverList() {
if (ischecked && $(e.target).is("._2ndlist")) {
editOptionsEnableDisable(".s-edit");
}
if (ischecked && ($(e.target).is(".file-opt") || $(e.target).is(".fo"))) {
checkActiveDownload();
}
});
}
export default controlHoverList;
10 changes: 10 additions & 0 deletions import/line-increament.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ function lineIncrement() {
window.pasteMode=true;
return;
}
if (window.isUnod) {
window.pasteMode=true;
window.isPaste=true;
startIncreament($(".line").length, originalHeight, true);
adjustCounter();
window.isPaste=false;
window.isUnod=false;
window.pasteMode=false;
return;
}
var border = $(".line").css("border", true);
!window.activeFile && setDefaultFile();
var editorHeight = $(this).outerHeight();
Expand Down
8 changes: 6 additions & 2 deletions import/structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ function structure() {
<i style="width:20px;height:20px;background-repeat:no-repeat;background-size:100%;background-position:center;" class="editorlogo"></i>
</div>
</li>
<li class="list-opt">
<label for="File"><div class="__notebook-option" tabindex="1">File</div></label>
<li class="list-opt file-opt">
<label for="File"><div class="__notebook-option fo" tabindex="1">File</div></label>
<input type="checkbox" name="ctrltogglenav" id="File" class="btoggle">
<div class="__notebook-toggle">
<div class="__toggle-content" style="margin-left:1px;">
Expand All @@ -28,6 +28,10 @@ function structure() {
<li class="print"><div class="__toggle-option">Page setup</div></li>
<li class="print"><div class="__toggle-option">Print</div><div class="shortcut">Ctrl+P</div></li>
</ul>
<ul>
<li class="download disabled"><div class="__toggle-option">Download file</div><div class="shortcut">Ctrl+D</div></li>
<li class="clear-win disabled"><div class="__toggle-option">Clear window</div><div class="shortcut">Ctrl+Win</div></li>
</ul>
</div>
</div>
</li>
Expand Down
24 changes: 19 additions & 5 deletions mapping/keyboardShortcuts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { checkActiveDownload } from "../exports/multiTaskHandler";
import textBackups from "../exports/textBackups";
import { print } from "../components/print";
import { setCounters } from "../import/insertLine";

function keyboardShortcuts() {
var isShiftKey=false;
var isAltKey = false;
Expand Down Expand Up @@ -44,16 +46,19 @@ function keyboardShortcuts() {
return;
}

_KBDefZoom(event), _KBGoto(event), _KBReplace(event), _KBFind(event);
_KBDefZoom(event), _KBGoto(event), _KBReplace(event), _KBDownload(event), _KBClear(event);
_KBnew(event), _KBprint(event), _KBopen(event), _KBsave(event), _KBsaveAll(event), _KBUndo(event);
}
function _KBClear(event) {
if (isCtrlKey && event.keyCode===91) {
checkActiveDownload();
$(".clear-win").not(".disabled").click(), event.preventDefault();
}
}
function _KBReplace(event) {
isCtrlKey &&
(event.keyCode===70 && $(".find").click() && event.preventDefault()),
(event.keyCode===72 && $(".replace").click() && event.preventDefault());
}
function _KBFind(event) {

}
function _KBFindNextPrev(event, Shift) {
if (Shift) {
Expand All @@ -65,14 +70,23 @@ function keyboardShortcuts() {
}
!Shift && event.keyCode===114 && ($(".find-next").click(), event.preventDefault());
}
function _KBDownload(event) {
if (isCtrlKey && event.keyCode===68) {
checkActiveDownload();
$(".download").not(".disabled").click(), event.preventDefault()
}
}
function _KBGoto(event) {
isCtrlKey && event.keyCode===71 && ($(".goto").click(), event.preventDefault());
}
function _KBDefZoom(event) {
isCtrlKey && event.keyCode===48 && ($(".default-zoom").click());
}
function _KBUndo(event) {
isCtrlKey && event.keyCode===90 && textBackups.text === $(".line").text() && event.preventDefault();
if (isCtrlKey && event.keyCode===90) {
window.isUnod=true;
textBackups.text === $(".line").text() && (event.preventDefault());
}
}
function _KBsaveAll(event) {
isCtrlKey && isAltKey && event.keyCode===83 && ($(".s-save").click(), event.preventDefault());
Expand Down
28 changes: 28 additions & 0 deletions models/817248fb77fb5c2cef3f2c732ad257cb1fb9c5e4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
if (isset($_POST["File"]) && isset($_POST["File"]["File"]) && isset($_POST["File"]["type"])) {
$root_dir = "{$_SERVER["DOCUMENT_ROOT"]}/tmp/";
$filename = "{$_POST["File"]["File"]}.{$_POST["File"]["type"]}";
$file_path = "{$root_dir}{$filename}";

if (file_exists($file_path)) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime_type = finfo_file($finfo, $file_path);
finfo_close($finfo);

$filedata = file_get_contents($file_path);
$base64_encode = base64_encode($filedata);
$final_data = "data:{$mime_type};base64,{$base64_encode}";
unlink($file_path);
die($final_data);
}
}
if (isset($_POST["dispatch"]) && isset($_POST["dispatch"]["File"]) && isset($_POST["dispatch"]["type"])) {
header("Content-Type: application/json");
$root_dir = "{$_SERVER["DOCUMENT_ROOT"]}/tmp/";
$filename = "{$_POST["dispatch"]["File"]}.{$_POST["dispatch"]["type"]}";
$file_path = "{$root_dir}{$filename}";
if (file_exists($file_path) && unlink($file_path)) {
die(json_encode(["status"=> "success"]));
}
}
?>
Loading

0 comments on commit 2059163

Please sign in to comment.