Bound AngularJS template not changing in angular datatable - angularjs

I am using angular data table from below link
http://l-lin.github.io/angular-datatables/archives/#!/bindAngularDirective
I am using the defer rending concept here.
I have 2 button
Active (Show when user status is 1)
Inactive (Show when user status is 0)
As 2 way data binding not working here. I am unable to show Inactive button after clicking on active & viceversa
Below is my code
$scope.setCustomers = function (s, dto, dtc, f, c, h, t) {
s.dtInstance = {};
s.actions = {};
//dtOptions - Makes the ajax request to get the customer records, also builds the buttons to copy,csv,excel..etc
s.dtOptions = dto.fromSource('customers/showCustomers.json')
.withPaginationType('full_numbers')
.withDisplayLength(25)
.withOption('createdRow', createdRow)
.withDOM('<"html5buttons"B>lTfgitp').withDisplayLength(25);
// dtColumns - Builds the columns and renders the rows for each column
s.dtColumns = [
dtc.newColumn('name').withTitle('Name'),
dtc.newColumn('email').withTitle('Email'),
dtc.newColumn('phone').withTitle('Phone'),
dtc.newColumn('status').withTitle('Status')
.renderWith(function (data) {
return "<div style=text-align:center;>" + (data == 1 ? 'Accepted' : data == 2 ? 'Declined' : 'Pending') + "</div>";
}),
dtc.newColumn(null).withTitle('Actions').notSortable()
.renderWith(actionsHtml)
];
function createdRow(row, data, dataIndex) {
c(angular.element(row).contents())(s);
}
function actionsHtml(data, type, full, meta) {
s.actions[data.id] = data;
var actions = '<button ladda="loadingDemo' + data.customer_id + '" class="ladda-button ladda-button-demo btn btn-primary btn-xs" data-style="zoom-in" ng-click="resetPassword(actions[' + data.id + '])" uib-tooltip="Reset Password" tooltip-placement="top"><i class="fa fa-key"></i></button> '
+ '<i class="fa fa-money"></i></button> '
+ '<i class="fa fa-files-o"></i></button> '
+ '<i class="fa fa-eye"></i></button> '
+ '<i class="fa fa-pencil"></i></button> ';
if (data.is_active == 1) {
actions += '<button class="btn btn-success btn-xs" data-is_active="' + data.is_active + '" ng-click="setStatus(actions[' + data.id + '])" tooltip-placement="top" uib-tooltip="Inactive"><i class="fa fa-thumbs-up"></i></button> ';
} else {
actions += '<button class="btn btn-danger btn-xs" data-is_active="' + data.is_active + '" ng-click="setStatus(actions[' + data.id + '])" tooltip-placement="top" uib-tooltip="Active"><i class="fa fa-thumbs-down"></i></button> ';
}
return actions;
}
}
$scope.setCustomers($scope, DTOptionsBuilder, DTColumnBuilder, $filter, $compile, $http, toaster);
Thanks

Related

Getting ID for row on resourceLabelDidMount

I'm trying to get the ID for each row.
data.event.id isn't working. Any suggestions?
resourceLabelDidMount: function(data) {
var icon = document.createElement('strong');
icon .innerHTML = ' < a type="button" href="javascript:;" onclick="editReourceModal(1)" style="color: #0c0c0c"> ';
data.el.querySelector('.fc-datagrid-cell-main') .appendChild(icon );
},

How can I pass a variable between angularjs views?

I have a .slim file with AngularJS code. In this file, there's different views.
In the upload view, I have two radio buttons and I would like to keep the value of the radio selected in my edit view.
I read that I need a service, but I don't know Angular (and i'm pretty bad with javascript) so it's a bit difficult to understand and know what I have to do...
This is my whole view:
.gr-picture-upload-modal.modal.fade data-backdrop="static"
.modal-dialog
.modal-content data-ng-controller="PictureUploadCtrl" data-ng-if="view == 'upload'"
.modal-header
button type="button" class="close" data-ng-click="cancel()" ×
h4.modal-title= t('views.shared.picture_upload_modal.title')
.modal-body.picture-upload
.picture-upload-dropbox data-ng-model="files" data-ngf-drop=true data-ngf-drag-over-class="'dragover'" data-ngf-multiple="true" data-ngf-allow-dir="false" data-accept="image/jpeg,image/jpg,image/png,image/gif,image/bmp"
= t('views.shared.picture_upload_modal.drag_and_drop_or')
button type="button" class="btn-link" data-ngf-select="true" data-ng-model="files" data-ngf-multiple="true" data-accept="image/jpeg,image/jpg,image/png,image/gif,image/bmp"
= t('views.shared.picture_upload_modal.select')
= t('views.shared.picture_upload_modal.one_or_more_image')
p.picture-upload-hint= t('views.shared.picture_upload_modal.hints')
.list-group.picture-upload-list-group data-ng-show="pictures.length > 0"
.list-group-item data-ng-repeat="picture in pictures"
.row
.col-xs-8
img.picture-upload-thumbnail data-ngf-src="picture" alt="{{picture.name}}"
span.picture-upload-filename data-ng-hide="picture.upload.aborted || picture.errors" data-ng-bind="picture.name"
span.picture-upload-error.text-warning data-ng-show="picture.upload.aborted"= t('views.shared.picture_upload_modal.upload_aborted')
span.picture-upload-error.text-danger data-ng-show="picture.errors" data-ng-bind="picture.errors[0]"
.col-xs-3
.progress.picture-upload-progress data-ng-show="picture.progress >= 0"
.progress-bar data-ng-class="progressClass(picture)" style="width:{{picture.progress}}%;"
.col-xs-1
button.btn-link.picture-upload-abort type="button" title=t('views.application.buttons.cancel') data-ng-hide="picture.upload == null || picture.progress == 100 || picture.upload.aborted" data-ng-click="picture.upload.abort();picture.upload.aborted=true" ×
.modal-footer data-ng-show="pictures.length > 0"
div data-ng-if="successUpload > 0"
.row
.col-xs-4
p.pull-left= t('views.shared.picture_upload_modal.position')
.radio-inline
label
input type="radio" ng-model="position" value="first"= t('views.shared.picture_upload_modal.first_position')
.radio-inline
label
input type="radio" ng-model="position" value="last"= t('views.shared.picture_upload_modal.last_position')
.col-xs-8
button type="button" class="btn btn-primary pull-right" data-ng-disabled="uploading != 0" data-ng-click="editView()"= t('views.application.buttons.done')
div data-ng-if="successUpload == 0"
a.btn.btn-primary.pull-right href="" data-ng-class="{'disabled': (uploading != 0)}" data-ng-click="done('#{user_pictures_path(current_user.username)}')"
= t('views.application.buttons.done')
.modal-content data-ng-if="view == 'edit'"
.modal-header
.btn-toolbar.pull-right
.btn-group
button type="button" class="btn btn-default" data-ng-disabled="navIndex <= 0 || loading" data-ng-click="prevPicture()"
span.icon.icon-arrow-left
button type="button" class="btn btn-default" data-ng-disabled="navIndex >= (pictures.length - 1) || loading" data-ng-click="nextPicture()"
span.icon.icon-arrow-right
a.btn.btn-default href="" data-ng-class="{'disabled': loading}" data-ng-click="done('#{user_pictures_path(current_user.username)}')"
= t('views.application.buttons.done')
h4.modal-title #{t('views.shared.picture_upload_modal.new_image')} ({{navIndex + 1}}/{{pictures.length}})
.modal-body
form data-ng-submit="update(editPicture)"
.container-fluid
.row
.col-xs-12.col-md-4
.thumbnail.picture-upload-edit-thumbnail data-ng-style="{'background-image' : 'url(' + editPicture.image.thumbnail + ')'}"
.col-xs-12.col-md-8
.form-group data-ng-class="{'has-error': editPicture.errors['title']}"
label.control-label for="picture_title"= t('picture.labels.title')
input.form-control type="text" id="picture_title" name="picture[title]" data-ng-model="editPicture.title" autocomplete="off" maxlength="50"
span.help-block data-ng-bind="editPicture.errors['title'][0]"
.form-group data-ng-class="{'has-error': editPicture.errors['category_id']}"
label.control-label for="picture_category_id"= t('picture.labels.category')
- cache('categories._picture_upload_modal.select_tag', skip_digest: true) do
= select_tag 'category', options_for_select(Category.order(name: :asc).all.collect { |c| [c.name, c.id] }), id: 'picture_category_id', class: 'form-control', include_blank: true, data: { ng_model: 'editPicture.category_id' }
span.help-block data-ng-bind="editPicture.errors['category_id'][0]"
.form-group data-ng-class="{'has-error': editPicture.errors['description']}"
label.control-label for="picture_description"= t('picture.labels.description')
textarea.form-control id="picture_description" name="picture[description]" data-ng-model="editPicture.description" maxlength="800"
span.help-block data-ng-bind="editPicture.errors['description'][0]"
.form-group data-ng-class="{'has-error': editPicture.errors['tags_string']}"
label.control-label for="picture_tags_string" = t('picture.labels.tags_string')
input.form-control type="text" id="picture_tags_string" name="picture[tags_string]" data-ng-model="editPicture.tags_string" autocomplete="off" placeholder=t('picture.placeholders.tags_string')
span.help-block data-ng-bind="editPicture.errors['tags_string'][0]"
.form-group data-ng-class="{'has-error': editPicture.errors['license']}"
label.control-label for="picture_license"= t('picture.labels.license')
= select_tag 'license', options_for_select(t('picture.labels.licenses').collect { |k, v| [v, k] }), id: 'picture_license', class: 'form-control', include_blank: true, data: { ng_model: 'editPicture.license' }
span.help-block data-ng-bind="editPicture.errors['license'][0]"
.btn-toolbar.pull-right
button type="submit" class="btn btn-primary" name="commit" data-ladda="loading" data-style="expand-right"= t('helpers.submit.submit')
button type="button" class="btn btn-default" data-ng-class="{'disabled': loading}" data-ng-show="navIndex >= (pictures.length - 1)"
= link_to t('views.application.buttons.done'), URI::unescape(user_pictures_path(current_user.username, picturesNb: '{{pictures.length}}', position: '{{position}}'))
This is my radio buttons:
.radio-inline
label
input type="radio" ng-model="position" value="first"= t('views.shared.picture_upload_modal.first_position')
.radio-inline
label
input type="radio" ng-model="position" value="last"= t('views.shared.picture_upload_modal.last_position')
And this is where I want the value of the radio selected:
button type="button" class="btn btn-default" data-ng-class="{'disabled': loading}" data-ng-show="navIndex >= (pictures.length - 1)"
= link_to t('views.application.buttons.done'), URI::unescape(user_pictures_path(current_user.username, picturesNb: '{{pictures.length}}', position: '{{position}}'))
Also, this is my controller:
App.controller 'PictureUploadCtrl', ['$scope', '$rootScope', 'Upload', 'newPictures', ($scope, $rootScope, Upload, newPictures)->
$scope.pictures = []
$scope.uploading = 0
$scope.successUpload = 0
$scope.position = 'last'
$scope.$watch 'files', (files)->
if files and files.length
for file in files
$scope.pictures.push(file)
$scope.upload file
null
$scope.upload = (picture)->
$scope.uploading += 1
picture.upload = Upload.upload({
url: '/pictures',
data: { picture: { image: picture }}
}).progress((event)->
picture.progress = Math.min(100, parseInt(100.0 * event.loaded / event.total))
).success((data, status, headers, config)->
picture.id = data.picture.id
newPictures.add(data.picture)
$scope.uploading -= 1
$scope.successUpload += 1
).error((data, status, headers, config)->
if data is null
null
else if data.errors.base?
picture.errors = data.errors.base
else if data.errors.image?
picture.errors = data.errors.image
else if data.errors.image_fingerprint?
picture.errors = data.errors.image_fingerprint
$scope.uploading -= 1
)
$scope.cancel = ->
for picture in $scope.pictures
if picture.progress < 100 and not picture.upload.aborted
picture.upload.abort()
picture.upload.aborted = true
$scope.closeModal()
$scope.pictures = []
$scope.uploading = 0
$scope.successUpload = 0
$scope.progressClass = (picture)->
if picture.upload.aborted
'progress-bar-warning'
else if picture.progress == 100 and picture.errors?
'progress-bar-danger'
else if picture.progress == 100
'progress-bar-success'
else
''
]
Could you explain to me how can I keep the value of {{position}} between the views?
EDIT:
Well, I edited a service and added the position:
App.factory 'newPictures', ->
return {
pictures: []
position: 'last'
add: (picture)->
#pictures.push(picture)
clear: ->
#pictures = []
}
Then, in the directive, I just added the $scope.position
$scope.editView = ->
$scope.pictures = newPictures.pictures
$scope.position = newPictures.position
$scope.editPicture = $scope.pictures[0]
$scope.view = 'edit'
in my controller:
$scope.setPosition = (position) ->
$scope.position = position
newPictures.position = position
And I edited my view to add ng-change:
.row
.col-xs-4
p.pull-left= t('views.shared.picture_upload_modal.position')
.radio-inline
label
input type="radio" ng-model="position" data-ng-change="setPosition('first')" value="first"= t('views.shared.picture_upload_modal.first_position')
.radio-inline
label
input type="radio" ng-model="position" data-ng-change="setPosition('last')" value="last"= t('views.shared.picture_upload_modal.last_position')
I'm not sure if it's a clean way to do what I want but it works

angular bootstrap datepicker default custom class, highlight current date

I need to update all my datepickers so they display current day highlighted. I found code custom-class="getDayClass(date, mode)" , but do i really need to copy-paste this to EVERY datepicker directive? Is there a way to set it in config so it affect all datepickers already existing on a page?
I tried uibDatepickerPopupConfig.customClass = function(data){return "class"} but its not working.
thanks
I found solution without modifying source code.
First we need to add new template to $templateCache and then we need to extend datepicker directive scope with new function for returning custom class.
$templateCache.put("uib/template/datepicker/day.html",
"<table role=\"grid\" aria-labelledby=\"{{::uniqueId}}-title\" aria-activedescendant=\"{{activeDateId}}\">\n" +
" <thead>\n" +
" <tr>\n" +
" <th><button type=\"button\" class=\"btn btn-default btn-sm pull-left uib-left\" ng-click=\"move(-1)\" tabindex=\"-1\"><i aria-hidden=\"true\" class=\"glyphicon glyphicon-chevron-left\"></i><span class=\"sr-only\">previous</span></button></th>\n" +
" <th colspan=\"{{::5 + showWeeks}}\"><button id=\"{{::uniqueId}}-title\" role=\"heading\" aria-live=\"assertive\" aria-atomic=\"true\" type=\"button\" class=\"btn btn-default btn-sm uib-title\" ng-click=\"toggleMode()\" ng-disabled=\"datepickerMode === maxMode\" tabindex=\"-1\"><strong>{{title}}</strong></button></th>\n" +
" <th><button type=\"button\" class=\"btn btn-default btn-sm pull-right uib-right\" ng-click=\"move(1)\" tabindex=\"-1\"><i aria-hidden=\"true\" class=\"glyphicon glyphicon-chevron-right\"></i><span class=\"sr-only\">next</span></button></th>\n" +
" </tr>\n" +
" <tr>\n" +
" <th ng-if=\"showWeeks\" class=\"text-center\"></th>\n" +
" <th ng-repeat=\"label in ::labels track by $index\" class=\"text-center\"><small aria-label=\"{{::label.full}}\">{{::label.abbr}}</small></th>\n" +
" </tr>\n" +
" </thead>\n" +
" <tbody>\n" +
" <tr class=\"uib-weeks\" ng-repeat=\"row in rows track by $index\" role=\"row\">\n" +
" <td ng-if=\"showWeeks\" class=\"text-center h6\"><em>{{ weekNumbers[$index] }}</em></td>\n" +
" <td ng-repeat=\"dt in row\" class=\"uib-day text-center\" role=\"gridcell\"\n" +
" id=\"{{::dt.uid}}\"\n" +
" ng-class=\"::dt.customClass\">\n" +
" <button type=\"button\" class=\"btn btn-default btn-sm\"\n" +
" ng-class=\"highlightCurrentDate(dt)\"\n" +
" uib-is-class=\"\n" +
" 'btn-info' for selectedDt,\n" +
" 'active' for activeDt\n" +
" on dt\"\n" +
" ng-click=\"select(dt.date)\"\n" +
" ng-disabled=\"::dt.disabled\"\n" +
" tabindex=\"-1\"><span ng-class=\"::{'text-muted': dt.secondary, 'text-info': dt.current}\">{{::dt.label}}</span></button>\n" +
" </td>\n" +
" </tr>\n" +
" </tbody>\n" +
"</table>\n" +
"");
You see we addednew line ng-class=\"highlightCurrentDate(dt)\"\n" +
And then we extend datepicker scope as i wrote:
angular.module('ui.bootstrap.datepicker')
.config(function ($provide) {
$provide.decorator('uibDatepickerDirective', function ($delegate, $timeout) {
var directive = $delegate[0];
var link = directive.link;
directive.compile = function () {
return function (scope, element, attrs, ctrls) {
link.apply(this, arguments);
scope.highlightCurrentDate = function (dt) {
if (dt.selected) {
return "";
}
var date = dt.date;
var dayToCheck = new Date(date).setHours(0, 0, 0, 0);
var currentDay = new Date().setHours(0, 0, 0, 0);
if (dayToCheck === currentDay) {
return 'highlight-current-date';
}
}
};
return $delegate;
});
});

AngularJS, Regex causes error in test

When the user enters a specific expression, it gets translated to a button in the view.
Here is the code:
scope.buttonmaker = function(haystack) {
needle = /argumentation-link_to\((\d+),\s([\w\sÀ-ž]+)\)/;
return $sce.trustAsHtml(haystack.replace(new RegExp(needle, 'gi'), function(match) {
return '<button ng-click="goToArgumentation(' + needle.exec(match)[1] + ', 2, 3, false)" class="btn btn-md btn-info"> ' + needle.exec(match)[2] + '</button>'
}));
};
The code works, as it should and it also captures more than one expression, that match the Regex and the buttons are made correctly.
However, when running a test, this error happens:
Error: Cannot supply flags when constructing one RegExp from another.
RegExp#[native code]
buttonmaker#http://127.0.0.1:46071/assets/application-a2e90460a4bfb22fd82a11fde4c3041112d7349933767571c5e4928ad1951bdb.js:56321:68
fn
Looking at this stackoverflow-question, I first thought, that I did make a spelling mistake, so I tried this:
needle = "argumentation-link_to\((\d+),\s([\w\sÀ-ž]+)\)";
No errors occur, but the buttons weren't made.
Then, I tried this:
needle = /argumentation-link_to\((\d+),\s([\w\sÀ-ž]+)\)/gi
return $sce.trustAsHtml(haystack.replace(needle, function(match) {
return '<button ng-click="goToArgumentation(' + needle.exec(match)[1] + ', 2, 3, false)" class="btn btn-md btn-info"> ' + needle.exec(match)[2] + '</button>'
}));
This error occurs:
Error: needle.exec(...) is null
After looking at this stackoverflow-question, I believe, I have to somehow iterate over my text, but I don't know how to do it in my case.
Can someone help me to correct the code, so it does work in tests too?
EDIT:
When I do this:
needle = /argumentation-link_to\((\d+),\s([\w\sÀ-ž]+)\)/;
return $sce.trustAsHtml(haystack.replace(needle, function(match) {
return '<button ng-click="goToArgumentation(' + needle.exec(match)[1] + ', 2, 3, false)" class="btn btn-md btn-info"> ' + needle.exec(match)[2] + '</button>'
}));
No errors occur, but ONLY the first button gets made. This is obvious, because the global flag is missing.
And since the code works outside of tests, I think, the problem is more about the flags than the constructor.
I found a cheap fix, which requires not too much maintenance-work:
needle = /argumentation-link_to\((\d+),\s([\w\sÀ-ž]+)\)/gi
needle2 = /argumentation-link_to\((\d+),\s([\w\sÀ-ž]+)\)/
return $sce.trustAsHtml(haystack.replace(needle, function(match) {
return '<button ng-click="goToArgumentation(' + needle2.exec(match)[1] + ', 2, 3, false)" class="btn btn-md btn-info"> ' + needle2.exec(match)[2] + '</button>'
}));

Widget for getting facebook group's timeline / posts

I want to integrate facebook Widget for getting facebook group's timeline / posts. I have searched & got this https://developers.facebook.com/docs/plugins/page-plugin but this gives user's & page's timeline. I wanted Group's timeline. I didn't found perfect answer on Fb Developer portal & didn't get anything on web.
Any help on this is appreciated.
Thanks in Advance.
After lots of search, no plugin kind of thing i got for this. But yes got one blog in php where the developer made custom widget manually, I modified it with JavaScript & jQuery.
<div style="height: 375px; background: #f6f7f9;">
<div id="fb-root"></div>
<p class="text-center media-body social-link" style="background: white">
<img src="~/Content/Images/Link-Red.png" />
Facebook Group
</p>
<div id="fix-div"></div>
<div id="facebook-group" style="overflow-y: scroll; height: 375px; margin-top: 55px;"></div>
</div>
Facebook JavaScript API as follows-
<script>
var access_token = '<!-- Valid fb access token -->';
var groupId = 'valid facebook group id';
window.fbAsyncInit = function () {
FB.init({
appId: 'valid facebook app id',
cookie: true,
xfbml: true,
version: 'v2.8'
});
FB.api("" + groupId + "?fields=cover,icon,name,privacy",
'get',
{ access_token: access_token },
function (groupResponse) {
if (groupResponse && !groupResponse.error) {
$("#fix-div").html('');
$("#facebook-group").html('');
var fixDivHtml =
"<div style='z-index: 10;position: absolute;border: 1px solid #e9ebee;max-width: 470px;background: white;min-height: 50px;'><div class='media' style='border: 0'><div class='media-left media-middle' style='vertical-align: bottom'><a href='https://www.facebook.com/groups/" + groupResponse.id + "' target='_blank'><img class='media-object' src='/Content/Images/Facebook-group.png' style='min-height: 50px;padding: 5px 10px;width: 64px;'></a></div><div class='media-body media-middle'><a href='https://www.facebook.com/groups/" + groupResponse.id + "' target='_blank'><h4 class='media-heading' style='font-size: 14px;font-weight: bold;'>" + groupResponse.name + "</h4></a></div></div></div>";
$("#fix-div").append(fixDivHtml);
FB.api("/" +
groupId +
"/feed?fields=id,message,link,attachments{media,description},created_time,from,object_id,parent_id&limit=1000",
'get',
{ access_token: access_token },
function (response) {
if (response && !response.error) {
for (var i = 0; i < response.data.length; i++) {
var picture = undefined;
var description = undefined;
var date = formatDate(response.data[i].created_time);
if (response.data[i].attachments !== undefined) {
if (response.data[i].attachments.data.length > 0) {
if (
response.data[i].attachments.data[0].media !==
undefined) {
if (
response.data[i].attachments.data[0].media
.image !==
undefined)
picture = response.data[i].attachments
.data[0].media.image.src;
if (
response.data[i].attachments.data[0].media
.image.description !==
undefined)
description = response.data[i].attachments
.data[0].media.image.description;
} else {
if (
response.data[i].attachments.data[0]
.description !==
undefined)
description = response.data[i].attachments
.data[0].description;
}
}
}
var message = response.data[i].message;
var
append =
"<div class='border'><div class='media'><div class='media-left media-middle'><a href='https://www.facebook.com/" + response.data[i].from.id + "' target='_blank'><img class='media-object' src='http://graph.facebook.com/" + response.data[i].from.id + "/picture?type=square'></a></div><div class='media-body' style='vertical-align: bottom'><a href='https://www.facebook.com/" + response.data[i].from.id + "' target='_blank'><h4 class='media-heading'>" + response.data[i].from.name + ".<br /><small>" + date + "</small></h4></a></div>";
if (message !== undefined) {
if (ValidURL(message) === 1) {
append +=
"<a class='ellipsis' href='" +
message +
"' target='_blank'>" +
message +
"</a>";
} else {
append += "<a class='ellipsis'>" + message + "</a>";
}
}
if (picture !== undefined)
append +=
"<a href='" +
response.data[i].link +
"' target='_blank'><img class='img-responsive' src='" +
picture +
"'/></a>";
if (description !== undefined)
append += "<p>" + description + "</p>";
append += '<hr///>' +
"<div class='btn-group btn-group-justified' role='group' aria-label='Justified button group'>" +
"<a href=" +
response.data[i].link +
" class='btn btn-default' role='button' target='_blank'><i class='fa fa-thumbs-up' aria-hidden='true'></i> Like</a>" +
"<a href=" +
response.data[i].link +
" class='btn btn-default' role='button' target='_blank'><i class='fa fa-comment' aria-hidden='true'></i> Comment</a></div></div></div>";
$("#facebook-group").append(append);
}
}
});
}
});
};
(function () {
var e = document.createElement('script');
e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
var formatDate = function (input) {
var d = new Date(Date.parse(input));
input = d.toString();
d = new Date(Date.parse(input.replace(/-/g, "/")));
var month = [
'january', 'February', 'March', 'April', 'May', 'June', 'July', 'August',
'September', 'October', 'November', 'December'
];
var date = d.getDay().toString() +
" " +
month[d.getMonth().toString()] +
", " +
d.getFullYear().toString();
return (date);
};
function ValidURL(str) {
if (
/^(http|https|ftp):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/i.test(str))
return 1;
else
return -1;
}
</script>
Here formatDate & ValidURL are helper functions used for some cosmetic operations.

Resources