angular.module('cool')
.provider('AllComment', ["$http", function ($http) {
var ctrl = 'AllCommentCtrl';
return {
setCtrl: function (data) {
ctrl = data;
return this;
},
$get: function () {
console.log(ctrl);
}
}
}]);
function getData(){
var url = $('.gridly').attr('req');
$.get(url, function(data){
var json = JSON.parse(data)
$.each(json, function(i, obj) {
$('.gridly').append('<div class="brick small">'+obj.fields.title +'<a href="."><img src="/media/'+obj.fields.head_pic+'"'+'></a><a class="delete" slug="'+obj.fields.slug+'"href="#">×</a></div>');
$('.gridly').gridly({
base: 60, // px
gutter: 20, // px
columns: 10
});
});
});
}
$(document).ready( getData );
<input id="cancel_changes" class="btn btn-success col-sm-6 col-xs-12 margin-bottom col-sm-offset-1 col-xs-offset-0" value="Отменить" type="button" onclick="getData()">
function sortDate(a,b){
var aDate = new Date(a.createdAt);
var bDate = new Date(b.createdAt);
if(aDate == bDate)
return 0;
if(aDate < bDate)
return -1;
if(aDate > bDate)
return 1;
};
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "https://api.parse.com/1/classes/Blog", true);
xmlhttp.setRequestHeader('Content-Type', 'application/json');
xmlhttp.setRequestHeader('X-Parse-Application-Id', 'GKid48BAvytRnKn8Y8CFKiKQ8jIJSYwpUsr1vID1');
xmlhttp.setRequestHeader('X-Parse-REST-API-Key', '6bnW8hVQNvuLQYiDiXvMHwIvV0inEne93gLzOC0A');
xmlhttp.onload = function () {
if (xmlhttp.status === 200) {
var userInfo = JSON.parse(this.responseText);
console.log(this.responseText);
debugger;
userInfo.results = userInfo.results.sort( sortDate );
var arr = userInfo.results.reverse();
var text = "";
for (var i = 0; i < arr.length; i++) {
text += '<div class="blog-post"><div class="blog-header">'+arr[i].title + '</div><br><img width="560px;" src="' + arr[i].img + '"><br><div class="blog-text">' + arr[i].text + '</div><div class="blog-share"><a href="http://gamer-by-life.com/share/?title='+arr[i].title + '&text='+arr[i].text + '&img='+arr[i].img + '&time='+arr[i].createdAt + '"><img src="share.png"></a></div><br></div><br>\n';
}
console.log(text);
}
};
xmlhttp.send();