init
This commit is contained in:
1
public/mobile/js/app/README.md
Normal file
1
public/mobile/js/app/README.md
Normal file
@@ -0,0 +1 @@
|
||||
TODO simpliy js
|
||||
821
public/mobile/js/app/mobile-common.js
Normal file
821
public/mobile/js/app/mobile-common.js
Normal file
@@ -0,0 +1,821 @@
|
||||
// --------------------- 命名空间
|
||||
// 最上级变量
|
||||
var LEA = {};
|
||||
// 命名空间
|
||||
var Notebook = {
|
||||
cache: {}, // notebookId => {Title, Seq}
|
||||
}
|
||||
var Note = {
|
||||
cache: {}, // noteId => {Title, Tags, Content, Desc}
|
||||
};
|
||||
// var UserInfo = {}; // 博客有问题, 会覆盖
|
||||
var Tag = {};
|
||||
var Notebook = {};
|
||||
var Share = {};
|
||||
|
||||
// markdown
|
||||
var Converter;
|
||||
var MarkdownEditor;
|
||||
var ScrollLink;
|
||||
|
||||
//---------------------
|
||||
// 公用方法
|
||||
|
||||
function trimLeft(str, substr) {
|
||||
if(!substr || substr == " ") {
|
||||
return $.trim(str);
|
||||
}
|
||||
while(str.indexOf(substr) == 0) {
|
||||
str = str.substring(substr.length);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
function json(str) {
|
||||
return eval("(" + str + ")")
|
||||
}
|
||||
|
||||
// '<div id="?" class="?" onclick="?">'
|
||||
function t() {
|
||||
var args = arguments;
|
||||
if(args.length <= 1) {
|
||||
return args[0];
|
||||
}
|
||||
var text = args[0];
|
||||
if(!text) {
|
||||
return text;
|
||||
}
|
||||
|
||||
// 先把所有的?替换成, 很有可能替换的值有?会造成循环,没有替换想要的
|
||||
var pattern = "LEAAEL"
|
||||
text = text.replace(/\?/g, pattern);
|
||||
|
||||
// args[1] 替换第一个?
|
||||
for(var i = 1; i <= args.length; ++i) {
|
||||
text = text.replace(pattern, args[i]);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
// 判断数组是否相等
|
||||
function arrayEqual(a, b) {
|
||||
a = a || [];
|
||||
b = b || [];
|
||||
return a.join(",") == b.join(",");
|
||||
}
|
||||
|
||||
//是否是数组
|
||||
function isArray(obj) {
|
||||
return Object.prototype.toString.call(obj) === '[object Array]';
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为空
|
||||
* 可判断任意类型,string array
|
||||
*/
|
||||
function isEmpty(obj) {
|
||||
if(!obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(isArray(obj)) {
|
||||
if(obj.length == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//------------
|
||||
//得到form的数据
|
||||
//返回json
|
||||
function getFormJsonData(formId) {
|
||||
var data = formArrDataToJson($('#' + formId).serializeArray());
|
||||
return data;
|
||||
}
|
||||
|
||||
//$('#form').serializeArray()的数据[{name: a, value: b}, {name: "c[]", value: d}]
|
||||
//转成{a:b}
|
||||
function formArrDataToJson(arrData) {
|
||||
var datas = {};
|
||||
var arrObj= {}; // {a:[1, 2], b:[2, 3]};
|
||||
for(var i in arrData) {
|
||||
var attr = arrData[i].name;
|
||||
var value = arrData[i].value;
|
||||
// 判断是否是a[]形式
|
||||
if(attr.substring(attr.length-2, attr.length) == '[]') {
|
||||
attr = attr.substring(0, attr.length-2);
|
||||
if(arrObj[attr] == undefined) {
|
||||
arrObj[attr] = [value];
|
||||
} else {
|
||||
arrObj[attr].push(value);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
datas[attr] = value;
|
||||
}
|
||||
|
||||
return $.extend(datas, arrObj);
|
||||
}
|
||||
|
||||
//将serialize的的form值转成json
|
||||
function formSerializeDataToJson(formSerializeData) {
|
||||
var arr = formSerializeData.split("&");
|
||||
var datas = {};
|
||||
var arrObj= {}; // {a:[1, 2], b:[2, 3]};
|
||||
for(var i = 0; i < arr.length; ++i) {
|
||||
var each = arr[i].split("=");
|
||||
var attr = decodeURI(each[0]);
|
||||
var value = decodeURI(each[1]);
|
||||
// 判断是否是a[]形式
|
||||
if(attr.substring(attr.length-2, attr.length) == '[]') {
|
||||
attr = attr.substring(0, attr.length-2);
|
||||
if(arrObj[attr] == undefined) {
|
||||
arrObj[attr] = [value];
|
||||
} else {
|
||||
arrObj[attr].push(value);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
datas[attr] = value;
|
||||
}
|
||||
|
||||
return $.extend(datas, arrObj);
|
||||
}
|
||||
|
||||
|
||||
// ajax请求返回结果后的操作
|
||||
// 用于ajaxGet(), ajaxPost()
|
||||
function _ajaxCallback(ret, successFunc, failureFunc) {
|
||||
// 总会执行
|
||||
if(ret === true || ret == "true" || typeof ret == "object") {
|
||||
// 是否是NOTELOGIN
|
||||
if(ret && typeof ret == "object") {
|
||||
if(ret.Msg == "NOTLOGIN") {
|
||||
alert("你还没有登录, 请先登录!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(typeof successFunc == "function") {
|
||||
successFunc(ret);
|
||||
}
|
||||
} else {
|
||||
if(typeof failureFunc == "function") {
|
||||
failureFunc(ret);
|
||||
} else {
|
||||
alert("error!")
|
||||
}
|
||||
}
|
||||
}
|
||||
function _ajax(type, url, param, successFunc, failureFunc, async) {
|
||||
log("-------------------ajax:");
|
||||
log(url);
|
||||
log(param);
|
||||
if(typeof async == "undefined") {
|
||||
async = true;
|
||||
} else {
|
||||
async = false;
|
||||
}
|
||||
$.ajax({
|
||||
type: type,
|
||||
url: url,
|
||||
data: param,
|
||||
async: async, // 是否异步
|
||||
success: function(ret) {
|
||||
_ajaxCallback(ret, successFunc, failureFunc);
|
||||
},
|
||||
error: function(ret) {
|
||||
_ajaxCallback(ret, successFunc, failureFunc);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送ajax get请求
|
||||
* @param url
|
||||
* @param param
|
||||
* @param successFunc
|
||||
* @param failureFunc
|
||||
* @param hasProgress
|
||||
* @param async 是否异步
|
||||
* @returns
|
||||
*/
|
||||
function ajaxGet(url, param, successFunc, failureFunc, async) {
|
||||
_ajax("GET", url, param, successFunc, failureFunc, async);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送post请求
|
||||
* @param url
|
||||
* @param param
|
||||
* @param successFunc
|
||||
* @param failureFunc
|
||||
* @param hasProgress
|
||||
* @param async 是否异步, 默认为true
|
||||
* @returns
|
||||
*/
|
||||
function ajaxPost(url, param, successFunc, failureFunc, async) {
|
||||
_ajax("POST", url, param, successFunc, failureFunc, async);
|
||||
}
|
||||
function ajaxPostJson(url, param, successFunc, failureFunc, async) {
|
||||
log("-------------------ajaxPostJson:");
|
||||
log(url);
|
||||
log(param);
|
||||
|
||||
// 默认是异步的
|
||||
if(typeof async == "undefined") {
|
||||
async = true;
|
||||
} else {
|
||||
async = false;
|
||||
}
|
||||
$.ajax({
|
||||
url : url,
|
||||
type : "POST",
|
||||
contentType: "application/json; charset=utf-8",
|
||||
datatype: "json",
|
||||
async: async,
|
||||
data : JSON.stringify(param),
|
||||
success : function(ret, stats) {
|
||||
_ajaxCallback(ret, successFunc, failureFunc);
|
||||
},
|
||||
error: function(ret) {
|
||||
_ajaxCallback(ret, successFunc, failureFunc);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function findParents(target, selector) {
|
||||
if($(target).is(selector)) {
|
||||
return $(target);
|
||||
}
|
||||
var parents = $(target).parents();
|
||||
for(var i = 0; i < parents.length; ++i) {
|
||||
log(parents.eq(i))
|
||||
if(parents.eq(i).is(selector)) {
|
||||
return parents.seq(i);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
ajaxPostJson(
|
||||
"http://localhost:9000/notebook/index?i=100&name=life",
|
||||
{Title: "you can", UserId:"52a9e409f4ea49d6576fdbca", Subs:[{title: "xxxxx", Seq:11}, {title:"life..."}]},
|
||||
function(e) {
|
||||
log(e);
|
||||
});
|
||||
*/
|
||||
|
||||
//-----------------
|
||||
//切换编辑器
|
||||
function switchEditor(isMarkdown) {
|
||||
// 富文本永远是2
|
||||
|
||||
if(!isMarkdown) {
|
||||
$("#editor").show();
|
||||
$("#mdEditor").css("z-index", 1);
|
||||
} else {
|
||||
$("#mdEditor").css("z-index", 3).show();
|
||||
}
|
||||
}
|
||||
|
||||
// editor 设置内容
|
||||
// 可能是tinymce还没有渲染成功
|
||||
var previewToken = "<div style='display: none'>FORTOKEN</div>"
|
||||
function setEditorContent(content, isMarkdown, preview) {
|
||||
if(!content) {
|
||||
content = "";
|
||||
}
|
||||
return;
|
||||
if(!isMarkdown) {
|
||||
$("#editorContent").html(content);
|
||||
var editor = tinymce.activeEditor;
|
||||
if(editor) {
|
||||
editor.setContent(content);
|
||||
editor.undoManager.clear(); // 4-7修复BUG
|
||||
} else {
|
||||
// 等下再设置
|
||||
setTimeout(function() {
|
||||
setEditorContent(content, false);
|
||||
}, 100);
|
||||
}
|
||||
} else {
|
||||
$("#wmd-input").val(content);
|
||||
if(!content || preview) { // 没有内容就不要解析了
|
||||
$("#wmd-preview").html(preview).css("height", "auto");
|
||||
ScrollLink.onPreviewFinished(); // 告诉scroll preview结束了
|
||||
} else {
|
||||
// 还要清空preview
|
||||
if(MarkdownEditor) {
|
||||
$("#wmd-preview").html(previewToken + "<div style='text-align:center; padding: 10px 0;'><img src='http://leanote.com/images/loading-24.gif' /> 正在转换...</div>");
|
||||
MarkdownEditor.refreshPreview();
|
||||
} else {
|
||||
// 等下再设置
|
||||
setTimeout(function() {
|
||||
setEditorContent(content, true, preview);
|
||||
}, 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// preview是否为空
|
||||
function previewIsEmpty(preview) {
|
||||
if(!preview || preview.substr(0, previewToken.length) == previewToken) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 有tinymce得到的content有<html>包围
|
||||
function getEditorContent(isMarkdown) {
|
||||
return;
|
||||
if(!isMarkdown) {
|
||||
var editor = tinymce.activeEditor;
|
||||
if(editor) {
|
||||
var content = $(editor.getBody());
|
||||
// 去掉恶心的花瓣注入
|
||||
// <pinit></pinit>
|
||||
// 把最后的<script>..</script>全去掉
|
||||
content.find("pinit").remove();
|
||||
content.find(".thunderpin").remove();
|
||||
content.find(".pin").parent().remove();
|
||||
content = $(content).html();
|
||||
if(content) {
|
||||
while(true) {
|
||||
var lastEndScriptPos = content.lastIndexOf("</script>");
|
||||
if (lastEndScriptPos == -1) {
|
||||
return content;
|
||||
}
|
||||
var length = content.length;
|
||||
// 证明</script>在最后, 去除之
|
||||
if(length - 9 == lastEndScriptPos) {
|
||||
var lastScriptPos = content.lastIndexOf("<script ");
|
||||
if(lastScriptPos == -1) {
|
||||
lastScriptPos = content.lastIndexOf("<script>");
|
||||
}
|
||||
if(lastScriptPos != -1) {
|
||||
content = content.substring(0, lastScriptPos);
|
||||
} else {
|
||||
return content;
|
||||
}
|
||||
} else {
|
||||
// 不在最后, 返回
|
||||
return content;
|
||||
}
|
||||
}
|
||||
}
|
||||
return content;
|
||||
}
|
||||
} else {
|
||||
return [$("#wmd-input").val(), $("#wmd-preview").html()]
|
||||
}
|
||||
}
|
||||
|
||||
// 禁用编辑
|
||||
LEA.editorStatus = true;
|
||||
function disableEditor() {
|
||||
return;
|
||||
var editor = tinymce.activeEditor;
|
||||
if(editor) {
|
||||
editor.hide();
|
||||
LEA.editorStatus = false;
|
||||
$("#mceTollbarMark").show().css("z-index", 1000);
|
||||
}
|
||||
|
||||
// toolbar 来个遮着...
|
||||
}
|
||||
function enableEditor() {
|
||||
return;
|
||||
if(LEA.editorStatus) {
|
||||
return;
|
||||
}
|
||||
$("#mceTollbarMark").css("z-index", -1).hide();
|
||||
var editor = tinymce.activeEditor;
|
||||
if(editor) {
|
||||
editor.show();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------
|
||||
// notify
|
||||
$(function() {
|
||||
|
||||
if($.pnotify) {
|
||||
$.pnotify.defaults.delay = 1000;
|
||||
}
|
||||
})
|
||||
|
||||
function notifyInfo(text) {
|
||||
$.pnotify({
|
||||
title: '通知',
|
||||
text: text,
|
||||
type: 'info',
|
||||
styling: 'bootstrap'
|
||||
});
|
||||
}
|
||||
function notifyError(text) {
|
||||
$.pnotify.defaults.delay = 2000
|
||||
$.pnotify({
|
||||
title: '通知',
|
||||
text: text,
|
||||
type: 'error',
|
||||
styling: 'bootstrap'
|
||||
});
|
||||
}
|
||||
|
||||
//-----------
|
||||
// dialog
|
||||
//-----------
|
||||
function showDialog(id, options) {
|
||||
$("#leanoteDialog #modalTitle").html(options.title);
|
||||
$("#leanoteDialog .modal-body").html($("#" + id + " .modal-body").html());
|
||||
$("#leanoteDialog .modal-footer").html($("#" + id + " .modal-footer").html());
|
||||
delete options.title;
|
||||
options.show = true;
|
||||
$("#leanoteDialog").modal(options);
|
||||
}
|
||||
function hideDialog(timeout) {
|
||||
if(!timeout) {
|
||||
timeout = 0;
|
||||
}
|
||||
setTimeout(function() {
|
||||
$("#leanoteDialog").modal('hide');
|
||||
}, timeout);
|
||||
}
|
||||
|
||||
// 更通用
|
||||
function closeDialog() {
|
||||
$(".modal").modal('hide');
|
||||
}
|
||||
|
||||
// 原生的
|
||||
function showDialog2(id, options) {
|
||||
options = options || {};
|
||||
options.show = true;
|
||||
$(id).modal(options);
|
||||
}
|
||||
function hideDialog2(id, timeout) {
|
||||
if(!timeout) {
|
||||
timeout = 0;
|
||||
}
|
||||
setTimeout(function() {
|
||||
$(id).modal('hide');
|
||||
}, timeout);
|
||||
}
|
||||
|
||||
// 远程
|
||||
function showDialogRemote(url, data) {
|
||||
data = data || {};
|
||||
url += "?";
|
||||
for(var i in data) {
|
||||
url += i + "=" + data[i] + "&";
|
||||
}
|
||||
$("#leanoteDialogRemote").modal({remote: url});
|
||||
}
|
||||
|
||||
function hideDialogRemote() {
|
||||
$("#leanoteDialogRemote").modal('hide');
|
||||
}
|
||||
//---------------
|
||||
// notify
|
||||
$(function() {
|
||||
if($.pnotify) {
|
||||
$.pnotify.defaults.delay = 1000;
|
||||
}
|
||||
})
|
||||
|
||||
function notifyInfo(text) {
|
||||
$.pnotify({
|
||||
title: '通知',
|
||||
text: text,
|
||||
type: 'info',
|
||||
styling: 'bootstrap'
|
||||
});
|
||||
}
|
||||
function notifyError(text) {
|
||||
$.pnotify.defaults.delay = 2000
|
||||
$.pnotify({
|
||||
title: '通知',
|
||||
text: text,
|
||||
type: 'error',
|
||||
styling: 'bootstrap'
|
||||
});
|
||||
}
|
||||
function notifySuccess(text) {
|
||||
$.pnotify({
|
||||
title: '通知',
|
||||
text: text,
|
||||
type: 'success',
|
||||
styling: 'bootstrap'
|
||||
});
|
||||
}
|
||||
|
||||
// 对Date的扩展,将 Date 转化为指定格式的String
|
||||
//月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
|
||||
//年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
|
||||
//例子:
|
||||
//(new Date()).format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
|
||||
//(new Date()).format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
|
||||
Date.prototype.format = function(fmt) { //author: meizz
|
||||
var o = {
|
||||
"M+" : this.getMonth()+1, //月份
|
||||
"d+" : this.getDate(), //日
|
||||
"h+" : this.getHours(), //小时
|
||||
"m+" : this.getMinutes(), //分
|
||||
"s+" : this.getSeconds(), //秒
|
||||
"q+" : Math.floor((this.getMonth()+3)/3), //季度
|
||||
"S" : this.getMilliseconds() //毫秒
|
||||
};
|
||||
if(/(y+)/.test(fmt))
|
||||
fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
|
||||
for(var k in o)
|
||||
if(new RegExp("("+ k +")").test(fmt))
|
||||
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
|
||||
return fmt;
|
||||
}
|
||||
|
||||
//2014-01-06T18:29:48.802+08:00
|
||||
function goNowToDatetime(goNow) {
|
||||
if(!goNow) {
|
||||
return "";
|
||||
}
|
||||
return goNow.substr(0, 10) + " " + goNow.substr(11, 8);
|
||||
}
|
||||
function getCurDate() {
|
||||
return (new Date()).format("yyyy-M-d");
|
||||
}
|
||||
|
||||
// 回车键的动作
|
||||
function enter(parent, children, func) {
|
||||
if(!parent) {
|
||||
parent = "body";
|
||||
}
|
||||
$(parent).on("keydown", children, function(e) {
|
||||
if (e.keyCode == 13) {
|
||||
func.call(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 回车则blue
|
||||
function enterBlur(parent, children) {
|
||||
if(!parent) {
|
||||
parent = "body";
|
||||
}
|
||||
if(!children) {
|
||||
children = parent;
|
||||
parent = "body";
|
||||
}
|
||||
$(parent).on("keydown", children, function(e) {
|
||||
if (e.keyCode == 13) {
|
||||
$(this).trigger("blur");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 生成mongodb ObjectId
|
||||
function getObjectId() {
|
||||
return ObjectId();
|
||||
}
|
||||
|
||||
//-----------------------------------------
|
||||
function resizeEditor(second) {
|
||||
var ifrParent = $("#editorContent_ifr").parent();
|
||||
ifrParent.css("overflow", "auto");
|
||||
var height = $("#editorContent").height();
|
||||
ifrParent.height(height);
|
||||
// log(height + '---------------------------------------')
|
||||
$("#editorContent_ifr").height(height);
|
||||
|
||||
/*
|
||||
// 第一次时可能会被改变
|
||||
if(!second) {
|
||||
setTimeout(function() {
|
||||
resizeEditorHeight(true);
|
||||
}, 1000);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
//----------
|
||||
// msg位置固定
|
||||
function showMsg(msg, timeout) {
|
||||
$("#msg").html(msg);
|
||||
if(timeout) {
|
||||
setTimeout(function() {
|
||||
$("#msg").html("");
|
||||
}, timeout)
|
||||
}
|
||||
}
|
||||
function showMsg2(id, msg, timeout) {
|
||||
$(id).html(msg);
|
||||
if(timeout) {
|
||||
setTimeout(function() {
|
||||
$(id).html("");
|
||||
}, timeout)
|
||||
}
|
||||
}
|
||||
|
||||
//--------------
|
||||
// type == danger, success, warning
|
||||
function showAlert(id, msg, type, id2Focus) {
|
||||
$(id).html(msg).removeClass("alert-danger").removeClass("alert-success").removeClass("alert-warning").addClass("alert-" + type).show();
|
||||
if(id2Focus) {
|
||||
$(id2Focus).focus();
|
||||
}
|
||||
}
|
||||
function hideAlert(id, timeout) {
|
||||
if(timeout) {
|
||||
setTimeout(function() {
|
||||
$(id).hide();
|
||||
}, timeout);
|
||||
} else {
|
||||
$(id).hide();
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------
|
||||
// for leanote ajax
|
||||
|
||||
// post
|
||||
// return {Ok, Msg, Data}
|
||||
// btnId 是按钮包括#
|
||||
function post(url, param, func, btnId) {
|
||||
var btnPreText;
|
||||
if(btnId) {
|
||||
btnPreText = $(btnId).html();
|
||||
$(btnId).html("正在处理").addClass("disabled");
|
||||
}
|
||||
ajaxPost(url, param, function(ret) {
|
||||
if(btnPreText) {
|
||||
$(btnId).html(btnPreText).removeClass("disabled");
|
||||
}
|
||||
if (typeof ret == "object") {
|
||||
if(typeof func == "function") {
|
||||
func(ret);
|
||||
}
|
||||
} else {
|
||||
alert("leanote出现了错误!");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 是否是正确的email
|
||||
function isEmail(email) {
|
||||
var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[0-9a-zA-Z]{2,3}$/;
|
||||
return myreg.test(email);
|
||||
}
|
||||
|
||||
// 正确返回该email
|
||||
function isEmailFromInput(inputId, msgId, selfBlankMsg, selfInvalidMsg) {
|
||||
var val = $(inputId).val();
|
||||
var msg = function() {};
|
||||
if(msgId) {
|
||||
msg = function(msgId, msg) {
|
||||
showAlert(msgId, msg, "danger", inputId);
|
||||
}
|
||||
}
|
||||
if(!val) {
|
||||
msg(msgId, selfBlankMsg || "请输入邮箱");
|
||||
} else if(!isEmail(val)) {
|
||||
msg(msgId, selfInvalidMsg || "请输入正确的邮箱");
|
||||
} else {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
// 复制文本
|
||||
function initCopy(aId, postFunc) {
|
||||
// 定义一个新的复制对象
|
||||
var clip = new ZeroClipboard(document.getElementById(aId), {
|
||||
moviePath: "/js/ZeroClipboard/ZeroClipboard.swf"
|
||||
});
|
||||
|
||||
// 复制内容到剪贴板成功后的操作
|
||||
clip.on('complete', function(client, args) {
|
||||
postFunc(args);
|
||||
});
|
||||
}
|
||||
|
||||
function showLoading() {
|
||||
$("#loading").show();
|
||||
}
|
||||
|
||||
function hideLoading() {
|
||||
$("#loading").hide();
|
||||
}
|
||||
|
||||
// 注销, 先清空cookie
|
||||
function logout() {
|
||||
$.removeCookie("REVEL_SESSION");
|
||||
location.href = "/logout?id=1";
|
||||
}
|
||||
|
||||
// 得到图片width, height, callback(ret); ret = {width:11, height:33}
|
||||
function getImageSize(url, callback) {
|
||||
var img = document.createElement('img');
|
||||
|
||||
function done(width, height) {
|
||||
img.parentNode.removeChild(img);
|
||||
callback({width: width, height: height});
|
||||
}
|
||||
|
||||
img.onload = function() {
|
||||
done(img.clientWidth, img.clientHeight);
|
||||
};
|
||||
|
||||
img.onerror = function() {
|
||||
done();
|
||||
};
|
||||
|
||||
img.src = url;
|
||||
|
||||
var style = img.style;
|
||||
style.visibility = 'hidden';
|
||||
style.position = 'fixed';
|
||||
style.bottom = style.left = 0;
|
||||
style.width = style.height = 'auto';
|
||||
|
||||
document.body.appendChild(img);
|
||||
}
|
||||
|
||||
// 插件中使用
|
||||
function hiddenIframeBorder() {
|
||||
$('.mce-window iframe').attr("frameborder", "no").attr("scrolling", "no");
|
||||
}
|
||||
|
||||
var email2LoginAddress = {
|
||||
'qq.com': 'http://mail.qq.com',
|
||||
'gmail.com': 'http://mail.google.com',
|
||||
'sina.com': 'http://mail.sina.com.cn',
|
||||
'163.com': 'http://mail.163.com',
|
||||
'126.com': 'http://mail.126.com',
|
||||
'yeah.net': 'http://www.yeah.net/',
|
||||
'sohu.com': 'http://mail.sohu.com/',
|
||||
'tom.com': 'http://mail.tom.com/',
|
||||
'sogou.com': 'http://mail.sogou.com/',
|
||||
'139.com': 'http://mail.10086.cn/',
|
||||
'hotmail.com': 'http://www.hotmail.com',
|
||||
'live.com': 'http://login.live.com/',
|
||||
'live.cn': 'http://login.live.cn/',
|
||||
'live.com.cn': 'http://login.live.com.cn',
|
||||
'189.com': 'http://webmail16.189.cn/webmail/',
|
||||
'yahoo.com.cn': 'http://mail.cn.yahoo.com/',
|
||||
'yahoo.cn': 'http://mail.cn.yahoo.com/',
|
||||
'eyou.com': 'http://www.eyou.com/',
|
||||
'21cn.com': 'http://mail.21cn.com/',
|
||||
'188.com': 'http://www.188.com/',
|
||||
'foxmail.coom': 'http://www.foxmail.com'
|
||||
};
|
||||
|
||||
function getEmailLoginAddress(email) {
|
||||
if(!email) {
|
||||
return;
|
||||
}
|
||||
var arr = email.split('@');
|
||||
if(!arr || arr.length < 2) {
|
||||
return;
|
||||
}
|
||||
var addr = arr[1];
|
||||
return email2LoginAddress[addr] || "http://mail." + addr;
|
||||
}
|
||||
|
||||
// 返回是否是re.Ok == true
|
||||
function reIsOk(re) {
|
||||
return re && typeof re == "object" && re.Ok;
|
||||
}
|
||||
|
||||
// marker
|
||||
// 下拉扩展工具栏用, 点击文档导航用
|
||||
LEA.bookmark = null;
|
||||
function saveBookmark() {
|
||||
return;
|
||||
try {
|
||||
bookmark = tinymce.activeEditor.selection.getBookmark(); // 光标, 为了处理后重新定位到那个位置
|
||||
} catch(e) {
|
||||
}
|
||||
}
|
||||
function restoreBookmark() {
|
||||
return;
|
||||
try {
|
||||
// 必须要focus()!!!
|
||||
var editor = tinymce.activeEditor;
|
||||
editor.focus();
|
||||
editor.selection.moveToBookmark(LEA.bookmark);
|
||||
} catch(e) {
|
||||
}
|
||||
}
|
||||
|
||||
// 是否是手机浏览器
|
||||
var u = navigator.userAgent;
|
||||
LEA.isMobile = u.indexOf('Android')>-1 || u.indexOf('Linux')>-1;
|
||||
//LEA.isMobile = true;
|
||||
|
||||
// 国际化
|
||||
function getMsg(key) {
|
||||
return MSG[key] || key;
|
||||
}
|
||||
1231
public/mobile/js/app/mobile-note.js
Normal file
1231
public/mobile/js/app/mobile-note.js
Normal file
File diff suppressed because it is too large
Load Diff
514
public/mobile/js/app/mobile-notebook.js
Normal file
514
public/mobile/js/app/mobile-notebook.js
Normal file
@@ -0,0 +1,514 @@
|
||||
Notebook.curNotebookId = "";
|
||||
Notebook.cache = {}; // notebookId => {};
|
||||
Notebook.notebooks = []; // 按次序
|
||||
// <li role="presentation"><a role="menuitem" tabindex="-1" href="#">CSS</a></li>
|
||||
Notebook.notebookNavForListNote = ""; // html 为了note list上面和新建时的ul
|
||||
Notebook.notebookNavForNewNote = ""; // html 为了note list上面和新建时的ul
|
||||
|
||||
// 设置缓存
|
||||
Notebook.setCache = function(notebook) {
|
||||
var notebookId = notebook.NotebookId;
|
||||
if(!notebookId) {
|
||||
return;
|
||||
}
|
||||
if(!Notebook.cache[notebookId]) {
|
||||
Notebook.cache[notebookId] = {};
|
||||
}
|
||||
$.extend(Notebook.cache[notebookId], notebook);
|
||||
}
|
||||
|
||||
Notebook.GetCurNotebookId = function() {
|
||||
return Notebook.curNotebookId;
|
||||
};
|
||||
|
||||
// 得到notebook标题, 给note显示其notebook标题用
|
||||
Notebook.GetNotebook = function(notebookId) {
|
||||
return Notebook.cache[notebookId];
|
||||
}
|
||||
Notebook.GetNotebookTitle = function(notebookId) {
|
||||
var notebook = Notebook.cache[notebookId];
|
||||
if(notebook) {
|
||||
return notebook.Title;
|
||||
} else {
|
||||
return "未知";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 我的notebooks
|
||||
<ul class="folderBody" id="notebookList">
|
||||
<li><a class="active">所有</a></li>
|
||||
<li><a class="active">Hadoop</a></li>
|
||||
<li><a>August 13, 2013</a></li>
|
||||
</ul>
|
||||
*/
|
||||
// TODO 层级
|
||||
Notebook.allNotebookId = "0";
|
||||
Notebook.trashNotebookId = "-1";
|
||||
Notebook.RenderNotebooks = function(notebooks) {
|
||||
if(!notebooks || typeof notebooks != "object" || notebooks.length < 0) {
|
||||
notebooks = [];
|
||||
}
|
||||
|
||||
notebooks = [{NotebookId: Notebook.allNotebookId, Title: getMsg("all")}].concat(notebooks);
|
||||
notebooks.push({NotebookId: Notebook.trashNotebookId, Title: getMsg("trash")});
|
||||
Notebook.notebooks = notebooks; // 缓存之
|
||||
|
||||
var $notebookList = $("#notebookList");
|
||||
var nav = "";
|
||||
for(var i in notebooks) {
|
||||
var notebook = notebooks[i];
|
||||
Notebook.cache[notebook.NotebookId] = notebook;
|
||||
var classes = "";
|
||||
if(i == 0) {
|
||||
classes = "active";
|
||||
Notebook.curNotebookId = notebook.NotebookId;
|
||||
}
|
||||
$notebookList.append(t('<li><a class="?" notebookId="?">?</a></li>', classes, notebook.NotebookId, notebook.Title))
|
||||
}
|
||||
|
||||
// 渲染nav
|
||||
// Notebook.renderNav();
|
||||
|
||||
// 渲染第一个notebook作为当前
|
||||
// Notebook.changeNotebookNavForNewNote(notebooks[0].NotebookId);
|
||||
}
|
||||
|
||||
// RenderNotebooks调用,
|
||||
// nav 为了新建, 快速选择, 移动笔记
|
||||
// 这些在添加,修改,删除notebooks都要变动!!!
|
||||
Notebook.renderNav = function(nav) {
|
||||
var navForListNote = "";
|
||||
var navForNewNote = "";
|
||||
var navForMoveNote = "";
|
||||
var len = Notebook.notebooks.length-1;
|
||||
var contextmenu = [];
|
||||
for(var i in Notebook.notebooks) {
|
||||
var notebook = Notebook.notebooks[i];
|
||||
var each = t('<li role="presentation"><a role="menuitem" tabindex="-1" href="#" notebookId="?">?</a></li>', notebook.NotebookId, notebook.Title);
|
||||
var eachForNew = t('<li role="presentation" class="clearfix"><div class="new-note-left pull-left" title="为该笔记本新建笔记" href="#" notebookId="?">?</div><div title="为该笔记本新建markdown笔记" class="new-note-right pull-left" notebookId="?">Markdown</div></li>', notebook.NotebookId, notebook.Title, notebook.NotebookId);
|
||||
navForListNote += each;
|
||||
if(i != 0 && i != len) {
|
||||
navForMoveNote += each;
|
||||
navForNewNote += eachForNew;
|
||||
}
|
||||
}
|
||||
|
||||
$("#notebookNavForListNote").html(navForListNote);
|
||||
$("#notebookNavForNewNote").html(navForNewNote);
|
||||
$("#notebookNavForMoveNote").html(navForMoveNote);
|
||||
}
|
||||
|
||||
// 修改,添加,删除notebook后调用
|
||||
// 改变nav
|
||||
// 直接从html中取!
|
||||
Notebook.changeNav = function() {
|
||||
var navForListNote = "";
|
||||
var navForNewNote = "";
|
||||
|
||||
var i = 0;
|
||||
var $list = $("#notebookList li a");
|
||||
var len = $list.length - 1;
|
||||
$list.each(function() {
|
||||
var notebookId = $(this).attr("notebookId");
|
||||
var notebook = Notebook.cache[notebookId];
|
||||
var each = t('<li role="presentation"><a role="menuitem" tabindex="-1" href="#" notebookId="?">?</a></li>', notebook.NotebookId, notebook.Title);
|
||||
var eachForNew = t('<li role="presentation" class="clearfix"><div class="new-note-left pull-left" title="为该笔记本新建笔记" href="#" notebookId="?">?</div><div title="为该笔记本新建markdown笔记" class="new-note-right pull-left" notebookId="?">Markdown</div></li>', notebook.NotebookId, notebook.Title, notebook.NotebookId);
|
||||
|
||||
navForListNote += each;
|
||||
var isActive = $(this).hasClass('active'); // 万一修改的是已选择的, 那么...
|
||||
if(isActive) {
|
||||
$("#curNotebookForListNote").html(notebook.Title);
|
||||
}
|
||||
if(i != 0 && i != len) {
|
||||
navForNewNote += eachForNew;
|
||||
if(isActive) {
|
||||
$("#curNotebookForNewNote").html(notebook.Title);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
});
|
||||
|
||||
$("#notebookNavForListNote").html(navForListNote);
|
||||
$("#notebookNavForNewNote").html(navForNewNote);
|
||||
$("#notebookNavForMoveNote").html(navForNewNote);
|
||||
|
||||
// 移动, 复制重新来, 因为nav变了, 移动至-----的notebook导航也变了
|
||||
Note.InitContextmenu();
|
||||
}
|
||||
|
||||
/**
|
||||
* 我的共享notebooks
|
||||
<div id="shareNotebooks">
|
||||
<div class="folderNote closed">
|
||||
<div class="folderHeader">
|
||||
<a>
|
||||
<h1>
|
||||
<i class="fa fa-angle-right"></i>
|
||||
Life's</h1>
|
||||
</a>
|
||||
</div>
|
||||
<ul class="folderBody">
|
||||
<li><a>Hadoop</a></li>
|
||||
<li><a>Node webkit</a></li>
|
||||
<li><a>Hadoop</a></li>
|
||||
<li><a>Node webkit</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
*/
|
||||
// TODO 层级
|
||||
Notebook.RenderShareNotebooks = function(sharedUserInfos, shareNotebooks) {
|
||||
if(isEmpty(sharedUserInfos)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!shareNotebooks || typeof shareNotebooks != "object" || shareNotebooks.length < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
var $shareNotebooks = $("#shareNotebooks");
|
||||
var user2ShareNotebooks = {};
|
||||
for(var i in shareNotebooks) {
|
||||
var userNotebooks = shareNotebooks[i];
|
||||
user2ShareNotebooks[userNotebooks.UserId] = userNotebooks;
|
||||
}
|
||||
for(var i in sharedUserInfos) {
|
||||
var userInfo = sharedUserInfos[i];
|
||||
var userNotebooks = user2ShareNotebooks[userInfo.UserId] || {ShareNotebooks:[]};
|
||||
|
||||
userNotebooks.ShareNotebooks = [{NotebookId: "-2", Title: "默认共享"}].concat(userNotebooks.ShareNotebooks)
|
||||
|
||||
var username = userInfo.Username || userInfo.Email;
|
||||
var header = t('<div class="folderNote closed"><div class="folderHeader"><a><h1 title="? 的共享"><i class="fa fa-angle-right"></i>?</h1></a></div>', username, username);
|
||||
var body = '<ul class="folderBody">';
|
||||
for(var j in userNotebooks.ShareNotebooks) {
|
||||
var notebook = userNotebooks.ShareNotebooks[j];
|
||||
body += t('<li><a notebookId="?">?</a></li>', notebook.NotebookId, notebook.Title)
|
||||
}
|
||||
body += "</ul>";
|
||||
|
||||
$shareNotebooks.append(header + body + "</div>")
|
||||
}
|
||||
}
|
||||
|
||||
// 左侧导航, 选中某个notebook
|
||||
Notebook.SelectNotebook = function(target) {
|
||||
$("#notebookList li a").removeClass("active");
|
||||
$(target).addClass("active");
|
||||
};
|
||||
|
||||
// 新建笔记导航
|
||||
Notebook.changeNotebookNavForNewNote = function(notebookId, title) {
|
||||
// 没有notebookId, 则选择第1个notebook
|
||||
// 第一个是全部笔记
|
||||
if(!notebookId) {
|
||||
var notebook = Notebook.notebooks[0];
|
||||
notebookId = notebook.NotebookId;
|
||||
title = notebook.Title;
|
||||
}
|
||||
if(!title) {
|
||||
var notebook = Notebook.cache[0];
|
||||
title = notebook.Title;
|
||||
}
|
||||
|
||||
if(!Notebook.IsAllNotebookId(notebookId) && !Notebook.IsTrashNotebookId(notebookId)) {
|
||||
$("#curNotebookForNewNote").html(title).attr("notebookId", notebookId);
|
||||
} else if(!$("#curNotebookForNewNote").attr("notebookId")) {
|
||||
// 但又没有一个笔记, 默认选第一个吧
|
||||
// 这里很可能会死循环, 万一用户没有其它笔记呢?
|
||||
// 服务端肯定要在新建一个用户时给他创建一个默认笔记本的
|
||||
if(Notebook.notebooks.length > 2) {
|
||||
var notebook = Notebook.notebooks[1];
|
||||
notebookId = notebook.NotebookId;
|
||||
title = notebook.Title;
|
||||
Notebook.changeNotebookNavForNewNote(notebookId, title);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 改变导航, 两处
|
||||
// 单击左侧, 单击新建下拉时调用
|
||||
// 1 选中左侧导航,
|
||||
// 2 notelist上面 >
|
||||
// 3 新建笔记 - js >
|
||||
// 转成我的nav <-> 共享
|
||||
Notebook.toggleToMyNav = function(userId, notebookId) {
|
||||
$("#sharedNotebookNavForListNav").hide();
|
||||
$("#myNotebookNavForListNav").show();
|
||||
|
||||
$("#newMyNote").show();
|
||||
$("#newShareNote").hide();
|
||||
|
||||
// 搜索tag隐藏
|
||||
$("#tagSearch").hide();
|
||||
}
|
||||
Notebook.changeNotebookNav = function(notebookId) {
|
||||
Notebook.toggleToMyNav();
|
||||
|
||||
// 1
|
||||
Notebook.SelectNotebook($(t('#notebookList [notebookId="?"]', notebookId)));
|
||||
|
||||
var notebook = Notebook.cache[notebookId];
|
||||
|
||||
if(!notebook) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 2
|
||||
$("#curNotebookForListNote").html(notebook.Title);
|
||||
|
||||
// 3
|
||||
Notebook.changeNotebookNavForNewNote(notebookId, notebook.Title);
|
||||
}
|
||||
|
||||
Notebook.IsAllNotebookId = function(notebookId) {
|
||||
return notebookId == Notebook.allNotebookId;
|
||||
}
|
||||
Notebook.IsTrashNotebookId = function(notebookId) {
|
||||
return notebookId == Notebook.trashNotebookId;
|
||||
}
|
||||
// 当前选中的笔记本是否是"所有"
|
||||
Notebook.CurActiveNotebookIsAll = function() {
|
||||
return Notebook.IsAllNotebookId($("#notebookList .active").attr("notebookId"));
|
||||
}
|
||||
|
||||
// 改变笔记本
|
||||
// 0. 改变样式
|
||||
// 1. 改变note, 此时需要先保存
|
||||
// 2. ajax得到该notebook下的所有note
|
||||
// 3. 使用Note.RederNotes()
|
||||
Notebook.ChangeNotebook = function(notebookId) {
|
||||
Notebook.changeNotebookNav(notebookId);
|
||||
|
||||
Notebook.curNotebookId = notebookId;
|
||||
|
||||
// 1
|
||||
// Note.CurChangedSaveIt();
|
||||
|
||||
// 2 先清空所有
|
||||
// Note.ClearAll();
|
||||
|
||||
var url = "/note/ListNotes/";
|
||||
var param = {notebookId: notebookId};
|
||||
|
||||
var notebook = Notebook.cache[notebookId]
|
||||
toggle("notes", notebook.Title + " 的笔记")
|
||||
|
||||
// 废纸篓
|
||||
if(Notebook.IsTrashNotebookId(notebookId)) {
|
||||
url = "/note/listTrashNotes";
|
||||
param = {};
|
||||
} else if(Notebook.IsAllNotebookId(notebookId)) {
|
||||
param = {};
|
||||
// 得到全部的...
|
||||
cacheNotes = Note.GetNotesByNotebookId();
|
||||
if(!isEmpty(cacheNotes)) { // 万一真的是没有呢?
|
||||
Note.RenderNotes(cacheNotes);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
cacheNotes = Note.GetNotesByNotebookId(notebookId);
|
||||
if(!isEmpty(cacheNotes)) { // 万一真的是没有呢?
|
||||
Note.RenderNotes(cacheNotes);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 2 得到笔记本
|
||||
// 这里可以缓存起来, note按notebookId缓存
|
||||
ajaxGet(url, param, Note.RenderNotes);
|
||||
|
||||
}
|
||||
|
||||
// 是否是当前选中的notebookId
|
||||
// 还包括共享
|
||||
Notebook.IsCurNotebook = function(notebookId) {
|
||||
return $(t('#notebookList [notebookId="?"], #shareNotebooks [notebookId="?"]', notebookId, notebookId)).attr("class") == "active";
|
||||
}
|
||||
|
||||
// 改变nav, 为了新建note
|
||||
Notebook.ChangeNotebookForNewNote = function(notebookId) {
|
||||
// 废纸篓
|
||||
if(Notebook.IsTrashNotebookId(notebookId) || Notebook.IsAllNotebookId(notebookId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Notebook.changeNotebookNav(notebookId);
|
||||
Notebook.curNotebookId = notebookId;
|
||||
|
||||
var url = "/note/ListNotes/";
|
||||
var param = {notebookId: notebookId};
|
||||
|
||||
// 2 得到笔记本
|
||||
// 这里可以缓存起来, note按notebookId缓存
|
||||
ajaxGet(url, param, function(ret) {
|
||||
// note 导航
|
||||
Note.RenderNotes(ret, true);
|
||||
});
|
||||
};
|
||||
|
||||
//---------------------------
|
||||
// 显示共享信息
|
||||
Notebook.ListNotebookShareUserInfo = function(target) {
|
||||
var notebookId = $(target).attr("notebookId");
|
||||
showDialogRemote("share/listNotebookShareUserInfo", {notebookId: notebookId});
|
||||
}
|
||||
// 共享笔记本
|
||||
Notebook.ShareNotebook = function(target) {
|
||||
var title = $(target).text();
|
||||
showDialog("dialogShareNote", {title: "分享笔记本给好友-" + title});
|
||||
setTimeout(function() {
|
||||
$("#friendsEmail").focus();
|
||||
}, 500);
|
||||
var notebookId = $(target).attr("notebookId");
|
||||
|
||||
shareNoteOrNotebook(notebookId, false);
|
||||
}
|
||||
|
||||
//-----------------------------
|
||||
// 设为blog/unset
|
||||
Notebook.SetNotebook2Blog = function(target) {
|
||||
var notebookId = $(target).attr("notebookId");
|
||||
var notebook = Notebook.cache[notebookId];
|
||||
var isBlog = true;
|
||||
if(notebook.IsBlog != undefined) {
|
||||
isBlog = !notebook.IsBlog;
|
||||
}
|
||||
|
||||
// 那么, 如果当前是该notebook下, 重新渲染之
|
||||
if(Notebook.curNotebookId == notebookId) {
|
||||
if(isBlog) {
|
||||
$("#noteList .item-blog").show();
|
||||
} else {
|
||||
$("#noteList .item-blog").hide();
|
||||
}
|
||||
|
||||
// 如果当前在所有笔记本下
|
||||
} else if(Notebook.curNotebookId == Notebook.allNotebookId){
|
||||
$("#noteItemList .item").each(function(){
|
||||
var noteId = $(this).attr("noteId");
|
||||
var note = Note.cache[noteId];
|
||||
if(note.NotebookId == notebookId) {
|
||||
if(isBlog) $(this).find(".item-blog").show();
|
||||
else $(this).find(".item-blog").hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
ajaxPost("blog/setNotebook2Blog", {notebookId: notebookId, isBlog: isBlog}, function(ret) {
|
||||
if(ret) {
|
||||
// 这里要设置notebook下的note的blog状态
|
||||
Note.setAllNoteBlogStatus(notebookId, isBlog);
|
||||
Notebook.setCache({NotebookId: notebookId, IsBlog: isBlog});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 添加, 修改完后都要对notebook的列表重新计算 TODO
|
||||
|
||||
// 修改笔记本标题
|
||||
Notebook.UpdateNotebookTitle = function(target) {
|
||||
var notebookTitle = $(target).text();
|
||||
var id = "editNotebookTitle";
|
||||
$(target).html(t('<input type="text" value="?" everValue="?" id="?" notebookId="?"/>', notebookTitle, notebookTitle, id, $(target).attr("notebookId")));
|
||||
$("#" + id).focus();
|
||||
}
|
||||
Notebook.DoUpdateNotebookTitle = function() {
|
||||
var title = $(this).val();
|
||||
var everTitle = $(this).attr("everTitle");
|
||||
var notebookId = $(this).attr("notebookId");
|
||||
|
||||
if(!title) {
|
||||
title = everTitle;
|
||||
}
|
||||
$(this).parent().html(title);
|
||||
|
||||
if(title != everTitle) {
|
||||
ajaxPost("/notebook/updateNotebookTitle", {notebookId: notebookId, title: title}, function(ret) {
|
||||
// 修改缓存
|
||||
Notebook.cache[notebookId].Title = title;
|
||||
// 改变nav
|
||||
Notebook.changeNav();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//-----------
|
||||
// 添加笔记本
|
||||
// 1 确保是展开的
|
||||
// 2 在所有后面添加<li></li>
|
||||
Notebook.addNotebookSeq = 1; // inputId
|
||||
Notebook.AddNotebook = function() {
|
||||
if($("#myNotebooks").hasClass("closed")) {
|
||||
$("#myNotebooks .folderHeader").trigger("click");
|
||||
}
|
||||
var inputId = "newNotebookInput" + Notebook.addNotebookSeq;
|
||||
Notebook.addNotebookSeq++;
|
||||
$("#notebookList li").eq(0).after(t('<li><a><input id="?"/></a></li>', inputId));
|
||||
|
||||
$("#" + inputId).focus();
|
||||
|
||||
// 回车调用blur
|
||||
enterBlur("#" + inputId);
|
||||
$("#" + inputId).blur(function() {
|
||||
// 为防多次发生blur
|
||||
$(this).unbind("blur");
|
||||
|
||||
var title = $(this).val();
|
||||
if(!title) {
|
||||
$(this).parent().parent().remove();
|
||||
} else {
|
||||
// 添加之
|
||||
var notebookId = getObjectId();
|
||||
var $a = $(this).parent();
|
||||
ajaxPost("/notebook/addNotebook", {notebookId: notebookId, title: title}, function(ret) {
|
||||
if(ret.NotebookId) {
|
||||
Notebook.cache[ret.NotebookId] = ret;
|
||||
$a.attr("notebookId", notebookId);
|
||||
$a.html(title);
|
||||
// 选中之
|
||||
Notebook.ChangeNotebook(notebookId);
|
||||
|
||||
// 改变nav
|
||||
Notebook.changeNav();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//-------------
|
||||
// 删除
|
||||
Notebook.DeleteNotebook = function(target) {
|
||||
var notebookId = $(target).attr("notebookId");
|
||||
if(!notebookId) {
|
||||
return;
|
||||
}
|
||||
|
||||
ajaxGet("/notebook/deleteNotebook", {notebookId: notebookId}, function(ret) {
|
||||
if(ret.Ok) {
|
||||
$(target).parent().remove();
|
||||
delete Notebook.cache[notebookId];
|
||||
// 改变nav
|
||||
Notebook.changeNav();
|
||||
} else {
|
||||
alert(ret.Msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(function() {
|
||||
//-------------------
|
||||
// 点击notebook
|
||||
$("#notebookList").on("click", "li a", function() {
|
||||
var notebookId = $(this).attr("notebookId");
|
||||
Notebook.ChangeNotebook(notebookId);
|
||||
});
|
||||
|
||||
// 添加笔记本
|
||||
$("#addNotebookPlus").click(function(e) {
|
||||
e.stopPropagation();
|
||||
Notebook.AddNotebook();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
92
public/mobile/js/app/mobile-page.js
Normal file
92
public/mobile/js/app/mobile-page.js
Normal file
@@ -0,0 +1,92 @@
|
||||
//------------------
|
||||
// mobile
|
||||
//------------------
|
||||
// 展示哪个notebooks, note, view, editor
|
||||
LEA.curStatus = "notebooks";
|
||||
LEA.preStatus = [];
|
||||
LEA.toggles = ["notebooks", "notes", "view"]
|
||||
function toggle(which, title, isBack) {
|
||||
if(!which || which == LEA.curStatus) {
|
||||
// 这个时候, 可以调出slider
|
||||
if(LEA.snapper.state().state=="left" ){
|
||||
LEA.snapper.close();
|
||||
} else {
|
||||
LEA.snapper.open('left');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// isBack, 不要加入历史中
|
||||
if(!isBack) {
|
||||
LEA.preStatus.push(LEA.curStatus);
|
||||
}
|
||||
LEA.curStatus = which;
|
||||
|
||||
for(var i in LEA.toggles) {
|
||||
var w = LEA.toggles[i];
|
||||
if(w != which && !$("#" + w).is(":hidden")) {
|
||||
// $("#" + w).fadeOut();
|
||||
$("#" + w).hide();
|
||||
}
|
||||
}
|
||||
// $("#" + which).show(100);
|
||||
$("#" + which).fadeIn();
|
||||
|
||||
// 设置标题
|
||||
if(title) {
|
||||
var maxTitleWidth = $("#" + which + " .content-controls").width()-50-$("#"+ which + " .btns").width();
|
||||
$("#" + which + " .g-title").html(title).width(maxTitleWidth - 10);
|
||||
}
|
||||
}// 当前状态是?
|
||||
|
||||
// notebooks -> notes -> view -> edit
|
||||
function back() {
|
||||
toggle(LEA.preStatus.pop(), "", true);
|
||||
}
|
||||
|
||||
$(function() {
|
||||
$(".back").click(function() {
|
||||
back();
|
||||
});
|
||||
/*
|
||||
window.onbeforeunload = function(e) {
|
||||
back();
|
||||
e.preventDefault();
|
||||
};
|
||||
*/
|
||||
$("#status").fadeOut(); // will first fade out the loading animation
|
||||
$("#preloader").delay(350).fadeOut("slow"); // will fade out the white DIV that covers the website.
|
||||
|
||||
$('.close-nav, .close-sidebar, .sidebar-close').click(function(){
|
||||
snapper.close();
|
||||
return false;
|
||||
});
|
||||
|
||||
var snapper = new Snap({
|
||||
element: document.getElementById('content')
|
||||
});
|
||||
LEA.snapper = snapper;
|
||||
|
||||
/*
|
||||
$('.deploy-sidebar').click(function(){
|
||||
if( snapper.state().state=="left" ){
|
||||
snapper.close();
|
||||
} else {
|
||||
snapper.open('left');
|
||||
}
|
||||
return false;
|
||||
});
|
||||
*/
|
||||
|
||||
$(".nav-newest").click(function() {
|
||||
Notebook.ChangeNotebook("0");
|
||||
snapper.close();
|
||||
});
|
||||
$(".nav-myNotebooks").click(function() {
|
||||
toggle("notebooks");
|
||||
snapper.close();
|
||||
});
|
||||
$(".nav-logout").click(function() {
|
||||
location.href="/mobile/logout";
|
||||
});
|
||||
})
|
||||
295
public/mobile/js/app/mobile-tag.js
Normal file
295
public/mobile/js/app/mobile-tag.js
Normal file
@@ -0,0 +1,295 @@
|
||||
// Tag
|
||||
|
||||
// 蓝色, 红色怎么存到数据库中? 直接存蓝色
|
||||
|
||||
Tag.classes = {
|
||||
"蓝色": "label label-blue",
|
||||
"红色": "label label-red",
|
||||
"绿色": "label label-green",
|
||||
"黄色": "label label-yellow",
|
||||
"blue": "label label-blue",
|
||||
"red": "label label-red",
|
||||
"green": "label label-green",
|
||||
"yellow": "label label-yellow"
|
||||
}
|
||||
|
||||
// 数据库中统一存En
|
||||
Tag.mapCn2En = {
|
||||
"蓝色": "blue",
|
||||
"红色": "red",
|
||||
"绿色": "green",
|
||||
"黄色": "yellow",
|
||||
|
||||
}
|
||||
Tag.mapEn2Cn = {
|
||||
"blue": "蓝色",
|
||||
"red": "红色",
|
||||
"green": "绿色",
|
||||
"yellow": "黄色",
|
||||
}
|
||||
|
||||
Tag.t = $("#tags");
|
||||
|
||||
Tag.GetTags = function() {
|
||||
var tags = [];
|
||||
Tag.t.children().each(function(){
|
||||
var text = $(this).text();
|
||||
text = text.substring(0, text.length - 1); // 把X去掉
|
||||
text = Tag.mapCn2En[text] || text;
|
||||
tags.push(text);
|
||||
});
|
||||
// 需要去重吗? 正常情况下不会重复
|
||||
return tags;
|
||||
}
|
||||
|
||||
Tag.ClearTags = function() {
|
||||
Tag.t.html("");
|
||||
}
|
||||
|
||||
// 设置tags
|
||||
Tag.RenderTags = function(tags) {
|
||||
Tag.t.html("");
|
||||
if(isEmpty(tags)) {
|
||||
return;
|
||||
}
|
||||
// TODO 重构, 这样不高效
|
||||
for(var i = 0; i < tags.length; ++i) {
|
||||
var tag = tags[i];
|
||||
Tag.AppendTag(tag);
|
||||
}
|
||||
}
|
||||
|
||||
// tag最初状态
|
||||
function revertTagStatus() {
|
||||
$("#addTagTrigger").show();
|
||||
$("#addTagInput").hide();
|
||||
// hideTagList();
|
||||
}
|
||||
|
||||
function hideTagList(event) {
|
||||
$("#tagDropdown").removeClass("open");
|
||||
if (event) {
|
||||
event.stopPropagation()
|
||||
}
|
||||
}
|
||||
function showTagList(event) {
|
||||
$("#tagDropdown").addClass("open");
|
||||
if (event) {
|
||||
event.stopPropagation()
|
||||
}
|
||||
}
|
||||
|
||||
// 只读模式下显示tags
|
||||
Tag.RenderReadOnlyTags = function(tags) {
|
||||
// 先清空
|
||||
$("#noteReadTags").html("");
|
||||
if(isEmpty(tags)) {
|
||||
$("#noteReadTags").html("无标签");
|
||||
}
|
||||
|
||||
var i = true;
|
||||
function getNextDefaultClasses() {
|
||||
if (i) {
|
||||
return "label label-default";
|
||||
i = false
|
||||
} else {
|
||||
i = true;
|
||||
return "label label-info";
|
||||
}
|
||||
}
|
||||
|
||||
for(var i in tags) {
|
||||
var text = tags[i];
|
||||
text = Tag.mapEn2Cn[text] || text;
|
||||
var classes = Tag.classes[text];
|
||||
if(!classes) {
|
||||
classes = getNextDefaultClasses();
|
||||
}
|
||||
tag = t('<span class="?">?</span>', classes, text);
|
||||
|
||||
$("#noteReadTags").append(tag);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加tag
|
||||
// tag = {classes:"label label-red", text:"红色"}
|
||||
// tag = life
|
||||
Tag.AppendTag = function(tag) {
|
||||
var isColor = false;
|
||||
var classes, text;
|
||||
|
||||
if (typeof tag == "object") {
|
||||
classes = tag.classes;
|
||||
text = tag.text;
|
||||
if(!text) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
tag = $.trim(tag);
|
||||
text = tag;
|
||||
if(!text) {
|
||||
return;
|
||||
}
|
||||
var classes = Tag.classes[text];
|
||||
if(classes) {
|
||||
isColor = true;
|
||||
} else {
|
||||
classes = "label label-default";
|
||||
}
|
||||
}
|
||||
|
||||
text = Tag.mapEn2Cn[text] || text;
|
||||
tag = t('<span class="?">?<i title="删除">X</i></span>', classes, text);
|
||||
|
||||
// 避免重复
|
||||
$("#tags").children().each(function() {
|
||||
if (isColor) {
|
||||
var tagHtml = $("<div></div>").append($(this).clone()).html();
|
||||
if (tagHtml == tag) {
|
||||
$(this).remove();
|
||||
}
|
||||
} else if (text + "X" == $(this).text()) {
|
||||
$(this).remove();
|
||||
}
|
||||
});
|
||||
|
||||
$("#tags").append(tag);
|
||||
|
||||
hideTagList();
|
||||
|
||||
if (!isColor) {
|
||||
reRenderTags();
|
||||
}
|
||||
}
|
||||
|
||||
// 为了颜色间隔, add, delete时调用
|
||||
function reRenderTags() {
|
||||
var defautClasses = [ "label label-default", "label label-info" ];
|
||||
var i = 0;
|
||||
$("#tags").children().each(
|
||||
function() {
|
||||
var thisClasses = $(this).attr("class");
|
||||
if (thisClasses == "label label-default"
|
||||
|| thisClasses == "label label-info") {
|
||||
$(this).removeClass(thisClasses).addClass(
|
||||
defautClasses[i % 2]);
|
||||
i++;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//-----------
|
||||
// 左侧nav en -> cn
|
||||
Tag.renderTagNav = function(tags) {
|
||||
tags = tags || [];
|
||||
for(var i in tags) {
|
||||
var tag = tags[i];
|
||||
if(tag == "red" || tag == "blue" || tag == "yellow" || tag == "green") {
|
||||
continue;
|
||||
}
|
||||
var text = Tag.mapEn2Cn[tag] || tag;
|
||||
var classes = Tag.classes[tag] || "label label-default";
|
||||
$("#tagNav").append(t('<li><a> <span class="?">?</span></li>', classes, text));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 事件
|
||||
$(function() {
|
||||
// tag
|
||||
$("#addTagTrigger").click(function() {
|
||||
$(this).hide();
|
||||
$("#addTagInput").show().focus().val("");
|
||||
});
|
||||
|
||||
$("#addTagInput").click(function(event) {
|
||||
showTagList(event);
|
||||
});
|
||||
|
||||
$("#addTagInput").blur(function() {
|
||||
var val = $(this).val();
|
||||
if(val) {
|
||||
Tag.AppendTag(val, true);
|
||||
}
|
||||
return;
|
||||
// 下面不能有, 有就有问题
|
||||
$("#addTagTrigger").show();
|
||||
$("#addTagInput").hide();
|
||||
// revertTagStatus();
|
||||
});
|
||||
$('#addTagInput').keydown(function(e) {
|
||||
if (e.keyCode == 13) {
|
||||
hideTagList();
|
||||
// 如果有值, 再生成, 没值直接隐藏
|
||||
if ($("#addTagInput").val()) {
|
||||
$(this).trigger("blur");
|
||||
$("#addTagTrigger").trigger("click");
|
||||
} else {
|
||||
$(this).trigger("blur");
|
||||
}
|
||||
}
|
||||
});
|
||||
// 点击下拉时也会触发input的blur事件
|
||||
$("#tagColor li").click(function(event) {
|
||||
var a;
|
||||
if($(this).attr("role")) {
|
||||
a = $(this).find("span");
|
||||
} else {
|
||||
a = $(this);
|
||||
}
|
||||
Tag.AppendTag({
|
||||
classes : a.attr("class"),
|
||||
text : a.text()
|
||||
});
|
||||
});
|
||||
// 这是个问题, 为什么? 捕获不了事件?, input的blur造成
|
||||
/*
|
||||
$(".label").click(function(event) {
|
||||
var a = $(this);
|
||||
Tag.AppendTag({
|
||||
classes : a.attr("class"),
|
||||
text : a.text()
|
||||
});
|
||||
// event.stopPropagation();
|
||||
});
|
||||
*/
|
||||
|
||||
$("#tags").on("click", "i", function() {
|
||||
$(this).parent().remove();
|
||||
reRenderTags();
|
||||
});
|
||||
|
||||
//-------------
|
||||
// nav 标签搜索
|
||||
function searchTag() {
|
||||
var tag = $.trim($(this).text());
|
||||
tag = Tag.mapCn2En[tag] || tag;
|
||||
|
||||
// 学习changeNotebook
|
||||
|
||||
// 1
|
||||
Note.CurChangedSaveIt();
|
||||
|
||||
// 2 先清空所有
|
||||
// 也会把curNoteId清空
|
||||
Note.ClearAll();
|
||||
|
||||
$("#tagSearch").html($(this).html()).show();
|
||||
showLoading();
|
||||
ajaxGet("/note/searchNoteByTags", {tags: [tag]}, function(notes) {
|
||||
hideLoading();
|
||||
if(notes) {
|
||||
// 和note搜索一样
|
||||
// 设空, 防止发生上述情况
|
||||
// Note.curNoteId = "";
|
||||
|
||||
Note.RenderNotes(notes);
|
||||
if(!isEmpty(notes)) {
|
||||
Note.ChangeNote(notes[0].NoteId);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
$("#myTag .folderBody").on("click", "li", searchTag);
|
||||
$("#minTagNav").on("click", "li", searchTag);
|
||||
});
|
||||
Reference in New Issue
Block a user