Skip to content

Instantly share code, notes, and snippets.

@shin1ogawa
Created September 5, 2012 16:07
Show Gist options
  • Save shin1ogawa/3639106 to your computer and use it in GitHub Desktop.
Save shin1ogawa/3639106 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head> <meta charset="utf-8"> </head>
<body>
<div> <button id="show-docs-picker">Select Documents in Google Docs</button> </div>
<div> <ul id="picked"></ul> </div>
<script src="https://www.google.com/jsapi"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script type="text/javascript">
(function () {
google.setOnLoadCallback(function () {
$('#show-docs-picker').on('click', showDocsPicker);
});
google.load('picker', '1');
function showDocsPicker() {
new google.picker.PickerBuilder()
.addViewGroup(
new google.picker.ViewGroup(google.picker.ViewId.DOCS)
.addView(google.picker.ViewId.DOCUMENTS)
.addView(google.picker.ViewId.SPREADSHEETS)
.addView(google.picker.ViewId.PRESENTATIONS)
.addView(google.picker.ViewId.FOLDERS)
.addView(google.picker.ViewId.FORMS)
.addView(google.picker.ViewId.PDFS)
)
.addView(google.picker.ViewId.MAPS)
.addView(google.picker.ViewId.IMAGE_SEARCH)
.addView(new google.picker.DocsUploadView())
.enableFeature(google.picker.Feature.MULTISELECT_ENABLED)
.setCallback(onPicked)
.build().setVisible(true);
}
function onPicked(data) {
if (data.action !== 'picked') return;
var k, v, picked, li;
$('#picked').empty();
for (k in data.docs) {
picked = data[google.picker.Response.DOCUMENTS][k];
li = $('<li></li>').appendTo('#picked');
$('<img>', {src:picked.iconUrl}).appendTo(li);
$('<a></a>', {href:picked.url}).text(picked.name).appendTo(li);
}
}
}());
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment