Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Title Case Function Ex. String.toProperCase();
- String.prototype.toProperCase = function () {
- return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
- };
- // dd/mm/yyyy format
- function getCurrentDate(){
- var date = new Date();
- var d = date.getDate(); // Date
- var m = date.getMonth() + 1; // Month
- var y = date.getFullYear(); // Year
- var current_date = d+'/'+m+'/'+y ;
- return current_date;
- }
- function date_format(dateObject) {
- // dd/mm/yyyy format date return
- var d = new Date(dateObject);
- var day = d.getDate();
- var month = d.getMonth() + 1;
- var year = d.getFullYear();
- if (day < 10) {
- day = "0" + day;
- }
- if (month < 10) {
- month = "0" + month;
- }
- var date = day + "-" + month + "-" + year;
- return date;
- }
- /**
- * Sets a Cookie with the given name and value.
- *
- * name Name of the cookie
- * value Value of the cookie
- * [expires] Expiration date of the cookie (default: end of current session)
- * [path] Path where the cookie is valid (default: path of calling document)
- * [domain] Domain where the cookie is valid
- * (default: domain of calling document)
- * [secure] Boolean value indicating if the cookie transmission requires a
- * secure transmission
- */
- function setCookie(name, value, expires, path, domain, secure) {
- document.cookie = name + "=" + escape(value) +
- ((expires) ? "; expires=" + expires.toGMTString() : "") +
- ((path) ? "; path=" + path : "") +
- ((domain) ? "; domain=" + domain : "") +
- ((secure) ? "; secure" : "");
- }
- /**
- * Gets the value of the specified cookie.
- *
- * name Name of the desired cookie.
- *
- * Returns a string containing value of specified cookie,
- * or null if cookie does not exist.
- */
- function getCookie(name) {
- var dc = document.cookie;
- var prefix = name + "=";
- var begin = dc.indexOf("; " + prefix);
- if (begin == -1) {
- begin = dc.indexOf(prefix);
- if (begin != 0) return null;
- } else {
- begin += 2;
- }
- var end = document.cookie.indexOf(";", begin);
- if (end == -1) {
- end = dc.length;
- }
- return unescape(dc.substring(begin + prefix.length, end));
- }
- /**
- * Deletes the specified cookie.
- *
- * name name of the cookie
- * [path] path of the cookie (must be same as path used to create cookie)
- * [domain] domain of the cookie (must be same as domain used to create cookie)
- */
- function deleteCookie(name, path, domain) {
- if (getCookie(name)) {
- document.cookie = name + "=" +
- ((path) ? "; path=" + path : "") +
- ((domain) ? "; domain=" + domain : "") +
- "; expires=Thu, 01-Jan-70 00:00:01 GMT";
- }
- }
- // No Right Click
- function f1() {
- if (document.all) {
- return false;
- }
- }
- function f2(e) {
- if (document.layers || (document.getElementById & !document.all)) {
- if (e.which == 2 || e.which == 3) {
- return false;
- }
- }
- }
- if (document.layers) {
- document.captureEvents(Event.MOUSEDOWN);
- document.onmousedown = f1;
- } else {
- document.onmouseup = f2;
- document.oncontextmenu = f1;
- }
- document.oncontextmenu = new function ("return false");
- // Generate Random String With Number
- function generateRandomAlphaNum(len) {
- var rdmString = "";
- for (; rdmString.length < len; rdmString += Math.random().toString(36).substr(2));
- return rdmString.substr(0, len);
- }
- function getExtension(filename) {
- return filename.split(".").pop();
- }
- // https://sebhastian.com/javascript-filename-extension/
- function formatFileSize(bytes,decimalPoint) {
- if(bytes == 0) return '0 Bytes';
- var k = 1000,
- dm = decimalPoint || 2,
- sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
- i = Math.floor(Math.log(bytes) / Math.log(k));
- return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
- }
- // https://www.knowledgewalls.com/johnpeter/books/one-day-one-thing-to-know/how-to-redirect-with-getpost-data-in-jquery-custom-method
- function url_redirect(options){
- var $form = $("<form />");
- $form.attr("action",options.url);
- $form.attr("method",options.method);
- for (var data in options.data)
- $form.append('<input type="hidden" name="'+data+'" value="'+options.data[data]+'" />');
- $("body").append($form);
- $form.submit();
- }
- $(function(){
- /*jquery statements */
- url_redirect({url: "http://www.knowledgewalls.com",
- method: "get",
- data: {"q":"KnowledgeWalls"}
- });
- });
- //https://bitexperts.com/Question/Detail/3316/determine-file-size-in-javascript-without-downloading-a-file
- function getFileSize(url)
- {
- var fileSize = '';
- var http = new XMLHttpRequest();
- http.open('HEAD', url, false); // false = Synchronous
- http.send(null); // it will stop here until this http request is complete
- // when we are here, we already have a response, b/c we used Synchronous XHR
- if (http.status === 200) {
- fileSize = http.getResponseHeader('content-length');
- console.log('fileSize = ' + fileSize);
- }
- return fileSize;
- }
- $(function () {
- $(document).ajaxStart(function () {
- console.log('=== app.js [4723] === Start Ajax');
- loader_show();
- });
- $(document).ajaxStop(function () {
- console.log('=== app.js [4723] === Stop ajax');
- loader_hide();
- });
- $(document).ajaxError(function () {
- console.log('=== app.js [4723] === Error ajax');
- loader_hide();
- });
- });
- // LocalData Set
- function set_userdata(key, array) {
- if(key !='' && array !='' ){
- localStorage.setItem(key,JSON.stringify(array));
- }
- }
- // LocalData Get
- function get_userdata(array_key) {
- if(array_key != ''){
- return JSON.parse(localStorage.getItem(array_key));
- }
- }
- // Check inArray Item
- function inArray(array_item, check_array_list) {
- if($.inArray(array_item, check_array_list) !== -1){
- return true;
- }else{
- return false;
- }
- }
- // Remove Last URI Segment From URL
- function remove_last_uri(url_path=''){
- if( url_path !='' )
- return url_path.substring(0, url_path.lastIndexOf('/'));
- }
- //https://github.com/kelvintaywl/dentist.js/blob/master/js/dentist.js
- Get Data From URL
- // Multi Dimensional Array to Get Single Array Column Row Comma Separate Array
- function array_column(array, column_name){
- return array.map(x => x[column_name]);
- }
- const convertTime12to24 = (time12h) => {
- const [time, modifier] = time12h.split(' ');
- let [hours, minutes] = time.split(':');
- if (hours === '12') {
- hours = '00';
- }
- if (modifier === 'PM') {
- hours = parseInt(hours, 10) + 12;
- }
- return `${hours}:${minutes}`;
- }
- function validate_reset_form(form_id=''){
- if(form_name !=""){
- $("#"+form_id).validate().resetForm();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement