Skip to content

Instantly share code, notes, and snippets.

@lsuarezj
lsuarezj / bytesToSize.js
Created December 14, 2017 16:32 — forked from lanqy/bytesToSize.js
JavaScript To Convert Bytes To MB, KB, Etc
// from http://scratch99.com/web-development/javascript/convert-bytes-to-mb-kb/
function bytesToSize(bytes) {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == 0) return 'n/a';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
if (i == 0) return bytes + ' ' + sizes[i];
return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i];
};
@lsuarezj
lsuarezj / getBlogItems.js
Created December 13, 2017 21:31 — forked from bruzie/getBlogItems.js
SharePoint 2013 REST: get number of comments on a post (a special kind of Lookup field)
// Getting list items based on ODATA Query
function getListItems(url, listname, query, complete, failure) {
// Executing our items via an ajax request
$.ajax({
url: url + "/_api/web/lists/getbytitle('" + listname + "')/items" + query,
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
complete(data); // Returns JSON collection of the results
},
@lsuarezj
lsuarezj / SP2010_create_list_item.html
Created August 19, 2016 14:58 — forked from havana59er/SP2010_create_list_item.html
Create a new list item in SharePoint 2010 using javascript
<div>
<label for="myAnnouncement">Announcement</label>
<input id="myAnnouncement" type="text" /><br />
<input type="button" value="Post Announcement" />
</div>
<script type="text/javascript" >
// Use this to delay execution until the file sp.js has loaded. Also a good way to keep your context free of globals.
ExecuteOrDelayUntilScriptLoaded(function() {
// get announcement text
@lsuarezj
lsuarezj / SharePointTinyCalender.js
Created August 3, 2016 19:00 — forked from marineko/SharePointTinyCalender.js
Show SharePoint Calender using jQuery UI DatePicker.
$(document).ready(function () {
$(".divDatePicker").datepicker({
onChangeMonthYear: function (year, month, inst) { //表示月変更
setTimeout(function () { syncCalendar(year, month, selectDate.getDate()); }, 100);
},
onSelect: function (dateText, inst) { //選択日変更
dispDayEvent(dateText);
}
});