Skip to content

Instantly share code, notes, and snippets.

@shin1ogawa
Created September 3, 2012 16:57
Show Gist options
  • Save shin1ogawa/3610818 to your computer and use it in GitHub Desktop.
Save shin1ogawa/3610818 to your computer and use it in GitHub Desktop.
Google Picker is very conveinience especially for Google Apps Developer.
<!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="http://www.google.com/jsapi"></script>
<script src="//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().addView(google.picker.ViewId.DOCS)
.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