Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
renderjs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Cédric Le Ninivin
renderjs
Commits
8ab4b629
Commit
8ab4b629
authored
Jun 07, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
shrink code
parent
d55d473e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
88 deletions
+25
-88
gadget/filebrowser_and_preview.js
gadget/filebrowser_and_preview.js
+9
-58
gadget/filecontent.js
gadget/filecontent.js
+2
-2
renderjs.js
renderjs.js
+14
-28
No files found.
gadget/filebrowser_and_preview.js
View file @
8ab4b629
...
...
@@ -2,37 +2,6 @@
"
use strict
"
;
(
function
(
document
,
$
)
{
var
myIndexOf
=
function
(
path
,
contains
)
{
var
len
=
path
.
length
;
var
wordLen
=
contains
.
length
;
for
(
var
i
=
0
;
i
<
len
;
i
++
)
{
var
j
=
0
;
for
(
j
=
0
;
j
<
wordLen
;
j
++
)
{
if
(
path
[
i
+
j
]
!=
contains
[
j
])
{
break
;
}
}
if
(
j
==
wordLen
)
{
return
i
;
}
}
return
-
1
;
};
var
generateUuid
=
function
()
{
var
S4
=
function
()
{
/* 65536 */
var
i
,
string
=
Math
.
floor
(
Math
.
random
()
*
0x10000
).
toString
(
16
);
for
(
i
=
string
.
length
;
i
<
4
;
i
+=
1
)
{
string
=
"
0
"
+
string
;
}
return
string
;
};
return
S4
()
+
S4
();
};
var
getParameter
=
function
(
searchString
,
paramName
)
{
var
i
,
val
,
params
=
searchString
.
split
(
"
&
"
);
...
...
@@ -106,22 +75,13 @@
$
(
this
).
text
(
errorThrown
);
},
success
:
function
(
value
,
textStatus
,
jqXHR
)
{
var
access
;
// detour to request, while working on the 2nd preview window
if
(
value
.
_links
.
target
.
href
===
"
preview_by_postmessage.html
"
)
{
access
=
"
request
"
;
}
else
{
access
=
"
plumb
"
;
}
// merge again once working!
browserAPI
=
"
data://application/hal+json;base64,
"
+
window
.
btoa
(
JSON
.
stringify
({
_links
:
{
self
:
{
href
:
value
.
_links
.
scope
.
href
},
self
:
{
href
:
''
},
scope
:
{
href
:
value
.
_links
.
scope
.
href
},
display
:
{
href
:
'
browser://
'
+
access
+
'
/parentwindow/
'
},
// pass API-url so child can call parent
call
:
{
href
:
'
browser://call/{method}/{scope}/{interaction}
'
}
}}));
...
...
@@ -130,27 +90,18 @@
_links
:
{
self
:
{
href
:
''
},
scope
:
{
href
:
value
.
_links
.
scope
.
href
},
display
:
{
href
:
''
},
call
:
{
href
:
'
browser://call/{method}/{scope}/{interaction}
'
}
}}));
$
(
"
body
"
).
html
(
'
<iframe src="
'
+
// XXX Hardcoded gadget to load
'
filebrowser.html?file=
'
+
browserAPI
+
'
" id="
'
+
generateUuid
()
+
'
">
'
+
'
<p>Your browser does not support iframes.</p>
'
+
'
</iframe">
'
);
$
(
"
body
"
).
addGadget
({
"
src
"
:
'
filebrowser.html?file=
'
+
browserAPI
,
"
iframe
"
:
"
true
"
});
$
(
"
body
"
).
append
(
'
<iframe src="
'
+
// XXX Hardcoded gadget to load
value
.
_links
.
target
.
href
+
'
?file=
'
+
previewAPI
+
'
" id="
'
+
generateUuid
()
+
'
">
'
+
'
<p>Your browser does not support iframes.</p>
'
+
'
</iframe">
'
);
$
(
"
body
"
).
addGadget
({
"
src
"
:
value
.
_links
.
target
.
href
+
'
?file=
'
+
previewAPI
,
"
iframe
"
:
"
true
"
});
}
});
}
else
{
...
...
gadget/filecontent.js
View file @
8ab4b629
...
...
@@ -9,12 +9,12 @@
sessionStorage
.
setItem
(
"
schnick
"
,
"
schnack
"
);
var
setup
=
function
()
{
// this will have to run automatically should renderJs have an easy API
// not an easy API...
// can this be done automatically?
var
instance1
=
"
data://application/hal+json;base64,
"
+
window
.
btoa
(
JSON
.
stringify
({
_links
:
{
self
:
{
href
:
''
},
// not sure if scope should be passed as a link or JSON parameter
scope
:
{
href
:
'
browser://browse/ls/
'
},
target
:
{
href
:
'
preview_by_hash_change.html
'
},
call
:
{
href
:
''
}
...
...
renderjs.js
View file @
8ab4b629
...
...
@@ -817,8 +817,7 @@
),
"
sandbox
"
:
priv
.
getAttribute
(
gadget
,
'
sandbox
'
)
||
false
,
"
iframe
"
:
priv
.
getAttribute
(
gadget
,
'
iframe
'
)
||
false
,
"
wrapper
"
:
gadget
,
"
directory
"
:
spec
"
wrapper
"
:
gadget
};
// add gadget
...
...
@@ -904,7 +903,7 @@
options
.
parent
.
replaceWith
(
newHTML
);
}
else
{
newParentElement
=
options
.
parent
;
$
(
newHTML
).
pre
pendTo
(
options
.
parent
);
$
(
newHTML
).
ap
pendTo
(
options
.
parent
);
}
if
(
callback
)
{
callback
();
...
...
@@ -931,7 +930,7 @@
options
.
parent
.
replaceWith
(
newHTML
);
}
else
{
newParentElement
=
options
.
parent
;
$
(
newHTML
).
pre
pendTo
(
options
.
parent
);
$
(
newHTML
).
ap
pendTo
(
options
.
parent
);
}
// select iframe
...
...
@@ -1025,12 +1024,11 @@
window
.
top
.
postMessage
(
options
,
window
.
location
.
href
);
};
// =>
load
gadget
// =>
add a
gadget
that
.
addGadget
=
$
.
fn
.
addGadget
=
function
(
options
)
{
var
addressArray
=
window
.
location
.
href
.
split
(
"
?
"
),
element
=
this
[
0
];
var
element
=
this
[
0
];
//
set
parent
//
check if we can remove the
parent
if
(
element
===
document
||
element
===
window
||
element
===
document
.
body
)
{
options
.
parent
=
document
.
body
;
options
.
replaceParent
=
false
;
...
...
@@ -1038,43 +1036,31 @@
options
.
parent
=
this
;
options
.
replaceParent
=
true
;
}
// set uuid
if
(
options
.
id
===
undefined
)
{
options
.
id
=
priv
.
generateUuid
();
}
// set directory (root)
// if no ?-param is available, we can only set to href
if
(
options
.
directory
===
undefined
)
{
if
(
addressArray
.
length
>
1
)
{
options
.
directory
=
{
"
root
"
:
priv
.
decodeURI
(
addressArray
[
1
].
split
(
"
=
"
)[
1
])
};
}
else
{
options
.
directory
=
{
"
root
"
:
that
.
gadgetService
?
that
.
gadgetService
.
root
:
window
.
location
.
href
};
}
}
// set offline
// set cors
//
LOADING
// module
//
======================== LOADING ========================
// module
/requireJs
if
(
options
.
module
&&
require
!==
undefined
)
{
require
([
priv
.
extractModuleName
(
options
.
src
)],
function
(
response
)
{
priv
.
appendGadget
(
response
,
options
);
});
// iFrame
}
else
if
(
options
.
iframe
)
{
priv
.
appendGadget
(
undefined
,
options
);
// via Ajax (default)
// straight ajax (default)
}
else
{
$
.
ajax
({
url
:
options
.
src
,
// not sure this is helpful or not
cache
:
true
,
method
:
options
.
method
||
"
GET
"
,
success
:
function
(
data
)
{
priv
.
appendGadget
(
data
,
options
);
...
...
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