Skip to content

Instantly share code, notes, and snippets.

View djabif's full-sized avatar

Dayana Jabif djabif

View GitHub Profile
@djabif
djabif / dynamicAnchorFix.js
Last active March 18, 2017 09:27
Directive to open external links in Ionic App using inAppBrowser cordova plugin
//Use this directive to open external links using inAppBrowser cordova plugin
.directive('dynamicAnchorFix', function($ionicGesture, $timeout, $cordovaInAppBrowser) {
return {
scope: {},
link: function(scope, element, attrs) {
$timeout(function(){
var anchors = element.find('a');
if(anchors.length > 0)
{
angular.forEach(anchors, function(a) {
@djabif
djabif / facebookConnectPlugin.js
Created September 6, 2015 02:42
JavaScript interface for PhoneGap bridge to Facebook Connect SDK
/* global FB */
"use strict";
/*
* @author Ally Ogilvie
* @copyright Wizcorp Inc. [ Incorporated Wizards ] 2014
* @file - facebookConnectPlugin.js
* @about - JavaScript interface for PhoneGap bridge to Facebook Connect SDK
*
*
@djabif
djabif / create_post_example.js
Last active November 12, 2015 13:39
Create WP post example
this.createPost = function() {
var deferred = $q.defer(),
nonce_dfd = $q.defer();
AuthService.requestNonce("posts", "create_post")
.then(function(nonce){
nonce_dfd.resolve(nonce);
});
nonce_dfd.promise.then(function(nonce){
@djabif
djabif / slugify.pipe.ts
Last active July 18, 2025 09:54
Angular Pipe to transform a string into a slug
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({name: 'slugify'})
export class SlugifyPipe implements PipeTransform {
transform(input: string): string {
return input.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
@djabif
djabif / phone.validator.ts
Created February 8, 2018 19:54
phone validator
import { AbstractControl, ValidatorFn } from '@angular/forms';
import libphonenumber from 'google-libphonenumber';
export class PhoneValidator {
// Inspired on: https://github.com/yuyang041060120/ng2-validation/blob/master/src/equal-to/validator.ts
static validCountryPhone = (countryControl: AbstractControl): ValidatorFn => {
let subscribe: boolean = false;
return (phoneControl: AbstractControl): {[key: string]: boolean} => {
@djabif
djabif / password.validator.ts
Last active February 28, 2023 12:38
Password Validator for ionic apps
import { FormControl, FormGroup } from '@angular/forms';
export class PasswordValidator {
static areEqual(formGroup: FormGroup) {
let val;
let valid = true;
for (let key in formGroup.controls) {
if (formGroup.controls.hasOwnProperty(key)) {
let control: FormControl = <FormControl>formGroup.controls[key];
@djabif
djabif / form.ts
Last active February 28, 2023 12:38
Ionic Password validator
import { PasswordValidator } from '../../validators/password.validator';
this.matching_passwords_group = new FormGroup({
password: new FormControl('', Validators.compose([
Validators.minLength(5),
Validators.required,
Validators.pattern('^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9]+$') //this is for the letters (both uppercase and lowercase) and numbers validation
])),
confirm_password: new FormControl('', Validators.required)
}, (formGroup: FormGroup) => {
return PasswordValidator.areEqual(formGroup);
validation_messages = {
'username': [
{ type: 'required', message: 'Username is required.' },
{ type: 'minlength', message: 'Username must be at least 5 characters long.' },
{ type: 'maxlength', message: 'Username cannot be more than 25 characters long.' },
{ type: 'pattern', message: 'Your username must contain only numbers and letters.' },
{ type: 'validUsername', message: 'Your username has already been taken.' }
],
'name': [
{ type: 'required', message: 'Name is required.' }
<ion-item>
<ion-label floating color="primary">Username</ion-label>
<ion-input type="text" formControlName="username" class="form-control"></ion-input>
</ion-item>
<div class="validation-errors">
<ng-container *ngFor="let validation of validation_messages.username" >
<div class="error-message" *ngIf="validations_form.get('username').hasError(validation.type) && (validations_form.get('username').dirty || validations_form.get('username').touched)">
{{ validation.message }}
</div>
</ng-container>
name: new FormControl('', Validators.required),
lastname: new FormControl('', Validators.required),
email: new FormControl('', Validators.compose([
Validators.required,
Validators.pattern('^[a-zA-Z0-9_.+-][email protected][a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$')
])),
terms: new FormControl(true, Validators.pattern('true'))