Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Marco Kellershoff
pwny.gorilla.moe
Commits
6f0596f1
Commit
6f0596f1
authored
Jun 05, 2017
by
Marco Kellershoff
Browse files
Add Google Api URL shortener to share dialogue
parent
1f86cf30
Changes
3
Hide whitespace changes
Inline
Side-by-side
assets/pwny.js
View file @
6f0596f1
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
var
Pwny
=
function
()
{
var
Pwny
=
function
()
{
var
self
=
this
,
var
self
=
this
,
googleapikeys
=
{},
getWidth
=
function
(){
return
window
.
innerWidth
;},
getWidth
=
function
(){
return
window
.
innerWidth
;},
window_min_width
=
1000
,
window_min_width
=
1000
,
LOCAL_STORAGE_TEMPLATE_NAME
=
'
codetest_templates
'
,
LOCAL_STORAGE_TEMPLATE_NAME
=
'
codetest_templates
'
,
...
@@ -27,6 +28,18 @@
...
@@ -27,6 +28,18 @@
this
.
version
=
3
;
this
.
version
=
3
;
this
.
getGoogleApiKey
=
function
(
k
)
{
return
googleapikeys
[
k
];
};
this
.
getGoogleApiKeys
=
function
()
{
return
googleapikeys
;
};
this
.
setGoogleApiKeys
=
function
(
apikeys
)
{
googleapikeys
=
apikeys
;
};
this
.
append
=
function
(
element
,
target
)
{
this
.
append
=
function
(
element
,
target
)
{
target
=
target
||
document
.
body
;
target
=
target
||
document
.
body
;
if
(
typeof
target
===
'
string
'
)
target
=
document
.
querySelector
(
target
);
if
(
typeof
target
===
'
string
'
)
target
=
document
.
querySelector
(
target
);
...
@@ -440,6 +453,40 @@
...
@@ -440,6 +453,40 @@
return
input
&&
typeof
input
===
"
object
"
&&
(
input
instanceof
Array
||
(
input
.
buffer
&&
input
.
buffer
instanceof
ArrayBuffer
));
return
input
&&
typeof
input
===
"
object
"
&&
(
input
instanceof
Array
||
(
input
.
buffer
&&
input
.
buffer
instanceof
ArrayBuffer
));
};
};
this
.
initGoogleApiKeys
=
function
(
cb
)
{
$
.
ajax
({
url
:
'
googleapikeys.json
'
,
method
:
"
GET
"
,
}).
done
(
function
(
data
){
self
.
setGoogleApiKeys
(
data
);
if
(
cb
)
{
cb
();
}
});
};
this
.
shortenUrl
=
function
(
longUrl
,
cb
)
{
var
apikey
=
self
.
getGoogleApiKey
(
'
urlshortener
'
);
if
(
!
apikey
)
{
self
.
initGoogleApiKeys
(
function
(){
self
.
shortenUrl
(
longUrl
,
cb
);
});
}
else
{
$
.
ajax
({
url
:
'
https://www.googleapis.com/urlshortener/v1/url?key=
'
+
apikey
,
method
:
"
POST
"
,
processData
:
false
,
dataType
:
"
json
"
,
contentType
:
"
application/json
"
,
data
:
JSON
.
stringify
({
"
longUrl
"
:
longUrl
})
}).
done
(
function
(
data
){
cb
(
data
);
});
}
};
this
.
showShareWindow
=
function
(
link
)
{
this
.
showShareWindow
=
function
(
link
)
{
var
$shareDialogue
=
$
(
'
#shareDialogue
'
);
var
$shareDialogue
=
$
(
'
#shareDialogue
'
);
var
shareUrlBox
=
$shareDialogue
.
find
(
'
#shareUrlBox
'
);
var
shareUrlBox
=
$shareDialogue
.
find
(
'
#shareUrlBox
'
);
...
@@ -603,6 +650,21 @@
...
@@ -603,6 +650,21 @@
btn_file
.
onclick
=
function
(){
btn_file
.
onclick
=
function
(){
file
.
click
();
file
.
click
();
};
};
$
(
'
#shortenUrlCheckbox
'
).
on
(
'
change
'
,
function
(){
if
(
this
.
checked
===
true
)
{
self
.
shortenUrl
(
$
(
'
#shareUrlBox
'
).
val
(),
function
(
data
)
{
if
(
data
.
kind
===
'
urlshortener#url
'
)
{
$
(
'
#shareUrlBox
'
).
val
(
data
.
id
);
}
});
}
else
{
getShareableLink
({},
function
(
err
,
link
){
if
(
err
===
false
)
{
$
(
'
#shareUrlBox
'
).
val
(
link
);
}
});
}
});
$
(
window
).
on
(
'
hashchange
'
,
function
(){
window
.
location
.
reload
();});
$
(
window
).
on
(
'
hashchange
'
,
function
(){
window
.
location
.
reload
();});
self
.
loadFromHash
();
self
.
loadFromHash
();
};
};
...
...
googleapikeys.json
0 → 100644
View file @
6f0596f1
{
"urlshortener"
:
""
}
index.html
View file @
6f0596f1
...
@@ -242,6 +242,11 @@ html,body,#app{margin:0;padding:0;width:100%;height:100%;}
...
@@ -242,6 +242,11 @@ html,body,#app{margin:0;padding:0;width:100%;height:100%;}
<button
id=
"copyShareUrlButton"
data-dismiss=
"modal"
data-clipboard-target=
"#shareUrlBox"
class=
"btn btn-success"
type=
"button"
>
Copy
&
Close
</button>
<button
id=
"copyShareUrlButton"
data-dismiss=
"modal"
data-clipboard-target=
"#shareUrlBox"
class=
"btn btn-success"
type=
"button"
>
Copy
&
Close
</button>
</span>
</span>
</div>
</div>
<div
class=
"checkbox"
>
<label>
<input
type=
"checkbox"
id=
"shortenUrlCheckbox"
>
Shorten URL
</label>
</div>
</div>
</div>
<div
class=
"modal-footer"
>
<div
class=
"modal-footer"
>
<button
type=
"button"
class=
"btn btn-primary"
data-dismiss=
"modal"
>
Close
</button>
<button
type=
"button"
class=
"btn btn-primary"
data-dismiss=
"modal"
>
Close
</button>
...
@@ -258,5 +263,6 @@ html,body,#app{margin:0;padding:0;width:100%;height:100%;}
...
@@ -258,5 +263,6 @@ html,body,#app{margin:0;padding:0;width:100%;height:100%;}
<script
src=
"assets/jquery/jquery-3.2.1.min.js"
></script>
<script
src=
"assets/jquery/jquery-3.2.1.min.js"
></script>
<script
src=
"assets/bootstrap/bootstrap.min.js"
></script>
<script
src=
"assets/bootstrap/bootstrap.min.js"
></script>
<script
src=
"assets/clipboard.min.js"
></script>
<script
src=
"assets/clipboard.min.js"
></script>
<script
src=
"https://apis.google.com/js/client.js?onload=googleApiLoaded"
></script>
</body>
</body>
</html>
</html>
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