Skip to content

Instantly share code, notes, and snippets.

@iambigd
iambigd / gist:d8de76fe082e07e9801e
Last active December 10, 2015 17:15
Angular ngSrc image not found directive
app.directive('errSrc', function() {
return {
link: function(scope, element, attrs) {
scope.$watch(function() {
return attrs['ngSrc'];
}, function (value) {
if (!value) {
element.attr('src', attrs.errSrc);
}
@iambigd
iambigd / gist:57175bd5e99fde54ec4a
Created August 9, 2014 15:51
woocommerce 加入登入登出按鈕
function add_login_logout_link($items, $args)
{
if(is_user_logged_in() && $args->theme_location == 'avia2')
{
$newitems = '<li><a title="'.__('Logout','avia_framework').'" href="'. wp_logout_url(get_permalink()) .'">'.__('Logout','avia_framework').'</a></li>';
$newitems .= $items;
}
else if($args->theme_location == 'avia2')
{
$newitems = '<li><a title="'.__('Login','avia_framework').'" href="'. wp_login_url(get_permalink()) .'">'.__('Login','avia_framework').'</a></li>';
var myApp = angular.module('myApp', []);
myApp.factory('aProvider', function() {
console.log("factory");
});
myApp.directive("test1", function() {
console.log("directive setup");
return {
compile: function() {console.log("directive compile");}
}
@iambigd
iambigd / gist:a100d7ffbf066e46970c
Last active August 29, 2015 14:05
Angular Form validation: match
.directive('match', function() {
return {
require: 'ngModel',
restrict: 'A',
scope: {
match: '='
},
link: function(scope, elem, attrs, ngModel) {
scope.$watch(function() {
return (ngModel.$pristine && angular.isUndefined(ngModel.$modelValue)) || scope.match === ngModel.$modelValue;
@iambigd
iambigd / gist:c1cc7460e9af5e35001a
Created August 7, 2014 08:38
Angular Form validation: alphanumeric
.directive('alphanumeric', function() {
return {
require: 'ngModel',
restrict: 'A',
link: function(scope, elem, attr, ngModel) {
var validator = function(value) {
if (/^[a-zA-Z0-9]*$/.test(value)) {
ngModel.$setValidity('alphanumeric', true);
return value;
/* Side notes for calling out things
-------------------------------------------------- */
/* Base styles (regardless of theme) */
.bs-callout {
margin: 20px 0;
padding: 15px 30px 15px 15px;
border-left: 5px solid #eee;
app.filter('bytes', function() {
return function(bytes, precision) {
if (isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '-';
if (typeof precision === 'undefined') precision = 1;
var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'],
number = Math.floor(Math.log(bytes) / Math.log(1024));
return (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number];
}
});
@iambigd
iambigd / gist:8fcef57dd06c6ad58573
Last active August 29, 2015 14:04
Java jersey client API
package tw.org.iii.cosa.javabacked.rest;
import java.util.Iterator;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@iambigd
iambigd / gist:07b06de46aaea2512dea
Created July 6, 2014 15:27
Angular AuthInterceptor
.factory('AuthInterceptor', function($rootScope, $q, API_EVENTS, $log) {
return {
// On response success
response: function(response) {
// Return the response or promise.
return response || $q.when(response);
},
(function ($, window) {
$.fn.contextMenu = function (settings) {
return this.each(function () {
// Open context menu
$(this).on("contextmenu", function (e) {
//open menu
$(settings.menuSelector)