Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kityminder-core
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
吴志俊
kityminder-core
Commits
4a91abbc
Commit
4a91abbc
authored
Feb 27, 2014
by
techird
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
restore social.js
parent
031003c9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
154 additions
and
62 deletions
+154
-62
index.html
dist/index.html
+1
-1
social.js
dist/social.js
+153
-61
No files found.
dist/index.html
View file @
4a91abbc
...
...
@@ -8,7 +8,7 @@
<script
src=
"social.js"
charset=
"utf-8"
></script>
<script
src=
"../kity/dist/kitygraph.all.js"
charset=
"utf-8"
></script>
<script
src=
"../configure.js"
charset=
"utf-8"
></script>
<script
src=
"../dist/dev.
js
"
charset=
"utf-8"
></script>
<script
src=
"../dist/dev.
php
"
charset=
"utf-8"
></script>
<script
src=
"../lang/zh-cn/zh-cn.js"
charset=
"utf-8"
></script>
<link
href=
"../themes/default/css/import.css"
type=
"text/css"
rel=
"stylesheet"
>
<link
rel=
"stylesheet"
href=
"social.css"
>
...
...
dist/social.js
View file @
4a91abbc
$
.
extend
(
$
.
fn
,
{
disabled
:
function
(
value
)
{
if
(
value
===
undefined
)
return
!!
this
.
attr
(
'disabled'
);
if
(
value
)
{
this
.
attr
(
'disabled'
,
'disabled'
);
}
else
{
this
.
removeAttr
(
'disabled'
);
}
return
this
;
},
loading
:
function
(
text
)
{
if
(
text
)
{
if
(
!
this
.
disabled
()
)
{
this
.
disabled
(
true
);
this
.
attr
(
'origin-text'
,
this
.
text
()
);
}
this
.
text
(
text
);
}
else
{
this
.
text
(
this
.
attr
(
'origin-text'
)
);
this
.
removeAttr
(
'origin-text'
);
this
.
disabled
(
false
);
}
return
this
;
},
text
:
(
function
()
{
var
originFn
=
$
.
fn
.
text
;
return
function
()
{
var
textSpan
=
this
.
children
(
'span.text'
);
if
(
textSpan
.
length
)
{
return
originFn
.
apply
(
textSpan
,
arguments
);
}
else
{
return
originFn
.
apply
(
this
,
arguments
);
}
};
}
)()
}
);
$
(
function
()
{
var
$panel
=
$
(
'#social'
);
var
$login_btn
,
$save_btn
,
$share_btn
,
$user_btn
,
$user_menu
;
...
...
@@ -12,68 +49,33 @@ $( function () {
}
}
)();
$login_btn
=
$
(
'<button>登录</button>'
).
addClass
(
'login'
).
click
(
login
);
$login_btn
=
$
(
'<button>登录</button>'
).
addClass
(
'login'
).
click
(
login
);
$user_btn
=
$
(
'<button><
/button>'
).
addClass
(
'user-file'
);
$user_btn
=
$
(
'<button><
span class="text"></span></button>'
).
addClass
(
'user-file'
);
$user_menu
=
$
.
kmuidropmenu
(
{
data
:
[
{
label
:
'新建脑图'
,
value
:
'action_newminder'
click
:
newFile
},
{
divider
:
true
label
:
'到网盘管理文件...'
,
click
:
function
()
{
window
.
open
(
'http://pan.baidu.com/disk/home#dir/path=/apps/kityminder'
);
}
},
{
label
:
'最近脑图'
,
value
:
'action_recent'
divider
:
true
}
]
}
).
a
ppendTo
(
'body'
).
kmui
().
attachTo
(
$user_btn
);
}
).
a
ddClass
(
'user-file-menu'
).
appendTo
(
'body'
).
kmui
(
);
$
save_btn
=
$
(
'<button>保存</button>'
).
click
(
saveThisFile
).
addClass
(
'baidu-cloud'
);
$
user_menu
.
attachTo
(
$user_btn
);
$share_btn
=
$
(
'<button>分享</button>'
).
click
(
function
()
{
if
(
$share_btn
.
attr
(
'disabled'
)
)
{
return
;
}
var
data
=
window
.
km
.
exportData
(
'json'
);
$share_btn
.
attr
(
'disabled'
,
'disabled'
).
text
(
'正在分享...'
);
var
share_id
=
uuid
();
var
shareUrl
=
baseUrl
+
'index.html?share_id='
+
share_id
;
share
(
data
,
share_id
,
function
(
success
)
{
if
(
success
)
{
var
$popup
=
$
(
'<div></div>'
).
addClass
(
'popup'
).
appendTo
(
'body'
);
$popup
.
css
(
{
'position'
:
'absolute'
,
'right'
:
10
,
'top'
:
$share_btn
.
offset
().
top
+
$share_btn
.
height
()
+
10
,
'width'
:
250
,
'padding'
:
10
,
'background'
:
'white'
,
'border-radius'
:
'5px'
,
'box-shadow'
:
'1px 2px 4px rgba(0, 0, 0, .3)'
}
);
$popup
.
append
(
'<p style="margin: 5px 0; font-size: 12px;">分享成功,请复制URL:</p>'
);
var
$input
=
$
(
'<input type="text" style="width: 250px;" value="'
+
shareUrl
+
'"></input>'
).
appendTo
(
$popup
);
$input
[
0
].
select
();
$save_btn
=
$
(
'<button>保存</button>'
).
click
(
saveThisFile
).
addClass
(
'baidu-cloud'
);
$popup
.
mousedown
(
function
(
e
)
{
e
.
stopPropagation
();
}
);
$
(
'body'
).
on
(
'mousedown'
,
function
(
e
)
{
$popup
.
fadeOut
(
'fast'
,
function
()
{
$popup
.
remove
();
}
);
$share_btn
.
removeAttr
(
'disabled'
).
text
(
'分享'
);
$
(
'body'
).
off
(
'mousedown'
,
arguments
.
callee
);
}
);
}
}
);
}
).
addClass
(
'share'
);
$share_btn
=
$
(
'<button>分享</button>'
).
click
(
shareThisFile
).
addClass
(
'share'
);
var
AK
,
thisMapFilename
,
currentUser
;
var
AK
,
thisMapFilename
,
currentUser
,
share_id
=
uuid
(),
isShareLink
;
AK
=
'wiE55BGOG8BkGnpPs6UNtPbb'
;
...
...
@@ -85,11 +87,6 @@ $( function () {
}
}
);
currentUser
=
baidu
.
frontia
.
getCurrentAccount
();
if
(
currentUser
)
{
setCurrentUser
(
currentUser
);
}
function
login
()
{
var
options
=
{
response_type
:
'token'
,
...
...
@@ -127,19 +124,49 @@ $( function () {
function
loadRecent
()
{
var
sto
=
baidu
.
frontia
.
personalStorage
;
$user_btn
.
loading
(
'加载最近脑图...'
);
sto
.
listFile
(
'apps/kityminder/'
,
{
by
:
'time'
,
success
:
function
(
result
)
{
if
(
result
.
list
.
length
)
{
loadPersonal
(
result
.
list
[
0
].
path
);
if
(
!
isShareLink
)
{
loadPersonal
(
result
.
list
[
0
].
path
);
}
else
{
$user_btn
.
loading
(
false
);
}
addToRecentMenu
(
result
.
list
);
}
}
}
);
}
function
addToRecentMenu
(
list
)
{
list
=
list
.
splice
(
8
);
list
.
forEach
(
function
(
file
)
{
$user_menu
.
appendItem
(
{
item
:
{
label
:
getFileName
(
file
.
path
),
value
:
file
.
path
},
click
:
openFile
}
);
}
);
}
function
getFileName
(
path
)
{
var
filename
=
path
.
substr
(
path
.
lastIndexOf
(
'/'
)
+
1
);
return
filename
.
substr
(
0
,
filename
.
lastIndexOf
(
'.'
)
);
}
function
openFile
(
e
)
{
var
path
=
$
(
this
).
data
(
'value'
);
loadPersonal
(
path
);
}
function
loadPersonal
(
path
)
{
var
sto
=
baidu
.
frontia
.
personalStorage
;
thisMapFilename
=
path
;
$user_btn
.
loading
(
'加载“'
+
getFileName
(
path
)
+
'”...'
);
sto
.
getFileUrl
(
path
,
{
success
:
function
(
url
)
{
$
.
ajax
(
{
...
...
@@ -148,30 +175,46 @@ $( function () {
dataType
:
'text'
,
success
:
function
(
result
)
{
window
.
km
.
importData
(
result
,
'json'
);
$user_btn
.
loading
(
false
).
text
(
getFileName
(
path
)
);
}
}
);
}
}
);
}
function
getMapFileName
()
{
return
'/apps/kityminder/'
+
window
.
km
.
getMinderTitle
()
+
'.km'
;
}
function
newFile
()
{
thisMapFilename
=
null
;
window
.
km
.
importData
(
'新建脑图'
,
'plain'
);
$user_btn
.
text
(
'<新建脑图>'
);
}
function
saveThisFile
()
{
var
data
=
window
.
km
.
exportData
(
'json'
);
save
(
data
,
thisMapFilename
,
function
(
success
,
info
)
{
save
(
data
,
thisMapFilename
||
getMapFileName
()
,
function
(
success
,
info
)
{
if
(
success
)
{
$save_btn
.
text
(
'保存成功!'
);
setTimeout
(
function
()
{
$save_btn
.
removeAttr
(
'disabled'
).
text
(
'保存'
);
$save_btn
.
loading
(
false
);
},
3000
);
if
(
!
thisMapFilename
)
{
thisMapFilename
=
info
.
path
;
addToRecentMenu
(
[
info
]
);
$user_btn
.
text
(
getFileName
(
thisMapFilename
)
);
}
}
console
.
log
(
info
);
}
);
$save_btn
.
attr
(
'disabled'
,
'disabled'
).
text
(
'正在保存...'
);
$save_btn
.
loading
(
'正在保存...'
);
}
function
save
(
file
,
filename
,
callback
)
{
var
sto
=
baidu
.
frontia
.
personalStorage
;
var
options
=
{
ondup
:
sto
.
constant
.
ONDUP_OVERWRITE
,
ondup
:
thisMapFilename
?
sto
.
constant
.
ONDUP_OVERWRITE
:
sto
.
constant
.
ONDUP_NEWCOPY
,
success
:
function
(
result
)
{
callback
(
true
,
result
);
},
...
...
@@ -186,6 +229,47 @@ $( function () {
return
(
(
+
new
Date
()
*
10000
)
+
(
Math
.
random
()
*
9999
)
).
toString
(
36
);
}
function
shareThisFile
()
{
if
(
$share_btn
.
disabled
()
)
{
return
;
}
var
data
=
window
.
km
.
exportData
(
'json'
);
$share_btn
.
loading
(
'正在分享...'
);
var
shareUrl
=
baseUrl
+
'index.html?share_id='
+
share_id
;
share
(
data
,
share_id
,
function
(
success
)
{
if
(
success
)
{
var
$popup
=
$
(
'<div></div>'
).
addClass
(
'popup'
).
appendTo
(
'body'
);
$popup
.
css
(
{
'position'
:
'absolute'
,
'right'
:
10
,
'top'
:
$share_btn
.
offset
().
top
+
$share_btn
.
height
()
+
10
,
'width'
:
250
,
'padding'
:
10
,
'background'
:
'white'
,
'border-radius'
:
'5px'
,
'box-shadow'
:
'1px 2px 4px rgba(0, 0, 0, .3)'
}
);
$popup
.
append
(
'<p style="margin: 5px 0; font-size: 12px;">分享成功,请复制URL:</p>'
);
var
$input
=
$
(
'<input type="text" style="width: 250px;" value="'
+
shareUrl
+
'"></input>'
).
appendTo
(
$popup
);
$input
[
0
].
select
();
$popup
.
mousedown
(
function
(
e
)
{
e
.
stopPropagation
();
}
);
$
(
'body'
).
on
(
'mousedown'
,
function
(
e
)
{
$popup
.
fadeOut
(
'fast'
,
function
()
{
$popup
.
remove
();
}
);
$share_btn
.
loading
(
false
);
$
(
'body'
).
off
(
'mousedown'
,
arguments
.
callee
);
}
);
}
}
);
}
function
share
(
text
,
shareId
,
callback
)
{
var
data
=
new
baidu
.
frontia
.
Data
(
{
shareMinder
:
{
...
...
@@ -212,16 +296,24 @@ $( function () {
var
query
=
new
baidu
.
frontia
.
storage
.
Query
();
query
.
on
(
'shareMinder.id'
).
equal
(
shareId
);
$share_btn
.
attr
(
'disabled'
,
'disabled'
).
text
(
'正在加载分享内容...'
);
$share_btn
.
loading
(
'正在加载分享内容...'
);
baidu
.
frontia
.
storage
.
findData
(
query
,
{
success
:
function
(
ret
)
{
window
.
km
.
importData
(
ret
.
result
[
0
].
obj
.
shareMinder
.
data
,
'json'
);
$share_btn
.
removeAttr
(
'disabled'
).
text
(
'分享'
);
$share_btn
.
loading
(
false
);
},
error
:
function
(
e
)
{
console
.
log
(
e
);
}
}
);
isShareLink
=
true
;
}
loadShare
();
currentUser
=
baidu
.
frontia
.
getCurrentAccount
();
if
(
currentUser
)
{
setCurrentUser
(
currentUser
);
}
else
{
$login_btn
.
appendTo
(
$panel
);
}
}
);
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment