Splash preferences



Manage Splash Screen in IONIC(PhoneGap) or Native Project


  <preference name="SplashScreen" value="screen"/>
  <preference name="SplashScreenDelay" value="5000"/>
  <preference name="AutoHideSplashScreen" value="true" />
  <preference name="ShowSplashScreenSpinner" value="true"/>
  <preference name="FadeSplashScreen" value="true"/>
  <preference name="FadeSplashScreenDuration" value="1000"/>


For Manage Orientation

  <preference name="Orientation" value="portrait"/>

Capitalize in Javascript

You can Capitalise a string by core Javascript. I've write a function for this :

String.prototype.capitalize = function() {
return this.replace(/(?:^|\s)\S/g, function(a) {
return a.toUpperCase();
});

};

Show console.log in different colours in javascript

I've write a function for this :


function log(msg, color) {
    color = color || "black";
    bgc = "White";
    switch (color) {
        case "success":  color = "Green";      bgc = "White";       break;
        case "info":     color = "DodgerBlue"; bgc = "Turquoise";       break;
        case "error":    color = "Red";        bgc = "White";           break;
        case "start":    color = "OliveDrab"bgc = "PaleGreen";       break;
        case "warning":  color = "Tomato";     bgc = "Black";           break;
        case "end":      color = "Orchid";     bgc = "MediumVioletRed"; break;
        default: color = color;
    }

    if (typeof msg == "object") {
        console.log(msg);
    } else if (typeof color == "object") {
        console.log("%c" + msg, "color: PowderBlue;font-weight:bold; background-color: RoyalBlue;");
        console.log(color);
    } else {
        console.log("%c" + msg, "color:" + color + ";font-weight:bold; background-color: " + bgc + ";");
    }

}


You can use it like:

log("This is a Message", "error");

Sort JSON array in javascript

I've write a function for this :


function sortJson(arr, prop, dir) {
    return arr.sort(function(a,b) {       
        var propA = a[prop],propB = b[prop];
        
        if (dir=='asc') {
            return propA - propB;
        } else {
            return propB - propA;
        }
    });

}

Replace all in Javascript

I was notice that when you want to replace a string-1 to the another string-2 and the string-1 present on more the one place the the js replace function is not work properly, so here I've write a js prototype function for this :

String.prototype.replaceAll = function (find, replace) {
    var str = this;
    return str.replace(new RegExp(find.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), replace);

};

Watch Ionic menu(left or right)

.directive('watchMenu', function($timeout, $ionicSideMenuDelegate, $ionicScrollDelegate, $rootScope) {
  return {
    restrict: 'A',
    link: function($scope, $element, $attr) {
      // Run in the next scope digest
      $timeout(function() {
        // Watch for changes to the openRatio which is a value between 0 and 1 that says how "open" the side menu is
       
        $scope.$watch(function() { 
          return $ionicSideMenuDelegate.isOpenRight();
          //return $ionicSideMenuDelegate.isOpenLeft();
        }, 
          function(ratio) {
            $scope.data=ratio;
            if( ratio == 1){
              $rootScope.$broadcast('rightMenu.open');
              $ionicScrollDelegate.$getByHandle('rightMenuScroll').scrollTop();
            }else{}

          });
      });
    }
  };

});

On Click of anchor (a) open a url in inappbrowser and show loading

I've a write some functions for this :



document.onclick = function(e) {
e = e || window.event;
var element = e.target || e.srcElement;

if (element.tagName == 'A' && ((element.href.indexOf('http://') >= || element.href.indexOf('https://') >= 0)) && element.href.indexOf('//localhost:') < 0 ) {
e.preventDefault();
var ref = window.open(element.href, "_blank", "location=yes");;
ref.addEventListener('loadstart', inAppBrowserbLoadStart);
ref.addEventListener('loadstop', inAppBrowserbLoadStop);
ref.addEventListener('loaderror', inAppBrowserbLoadError);
ref.addEventListener('exit', inAppBrowserbClose);
return false;
}
}

function inAppBrowserbLoadStart(event) {
   navigator.notification.activityStart("Please Wait", "It'll only take a moment...");
}

function inAppBrowserbLoadStop(event) {
   navigator.notification.activityStop();
}

function inAppBrowserbLoadError(event) {
   navigator.notification.activityStop();
}

function inAppBrowserbClose(event) {
   navigator.notification.activityStop();
   ref.removeEventListener('loadstart', inAppBrowserbLoadStart);
   ref.removeEventListener('loadstop', inAppBrowserbLoadStop);
   ref.removeEventListener('loaderror', inAppBrowserbLoadError);
   ref.removeEventListener('exit', inAppBrowserbClose);

}

Convert time form AM/PM to 24 Hours fromat

I've made a function for this, it'll return the array of hour and minute :


function am_pm_to_hours(time) {
    var hours = Number(time.match(/^(\d+)/)[1]);
var minutes = Number(time.match(/:(\d+)/)[1]);
var AMPM = time.match(/\s(.*)$/)[1];
if(AMPM == "PM" && hours<12) hours = hours+12;
if(AMPM == "AM" && hours==12) hours = hours-12;
var sHours = hours.toString();
var sMinutes = minutes.toString();
if(hours<10) sHours = "0" + sHours;
if(minutes<10) sMinutes = "0" + sMinutes;
//console.log(sHours + ":" + sMinutes);
    return [sHours, sMinutes];

}

Add icon in android lollipop push notification

Use this code :


PushNotification.init({
"android" : {
"senderID" : "292145204069",
"icon" : "notification_icon", // It will search for notification_icon.png in your android drawable folder
"iconColor": "#0076cb"
}

});

Play a video in iframe


Write the following code :

<iframe width="100%" height="auto" ng-if="video_url" onerror="this.style.display = 'none'" src="{{video_url | VideoUrl}}"></iframe> 
.filter('VideoUrl', ['$sce', function($sce) {
    return function(val) {
        return $sce.trustAsResourceUrl(val);
    };
}])