Skip to content

Instantly share code, notes, and snippets.

View bettysteger's full-sized avatar
🏠
Working from home

Betty Steger bettysteger

🏠
Working from home
View GitHub Profile
@bettysteger
bettysteger / trix_editor.css
Last active April 10, 2020 07:23
Trix Editor Toolbar Icons with FontAwesome
trix-toolbar .button_group button::before {
background-image: none !important;
font-family: 'FontAwesome';
font-size: 12px;
line-height: 28px;
}
trix-toolbar .button_group button.bold:before {
content: '\f032';
}
@bettysteger
bettysteger / croppieDrct.js
Last active July 15, 2018 08:02
Croppie Angular Directive for a simple image cropping. Directive => Component: https://github.com/lpsBetty/angular-croppie
/**
* Use Croppie for a simple image cropping.
* @see https://github.com/Foliotek/Croppie
* @example
* <lh-croppie src="cropped.source" ng-model="cropped.image"></lh-croppie>
*/
angular.module('lingohubApp').directive('lhCroppie', function () {
return {
restrict: 'E',
scope: {
@bettysteger
bettysteger / google_feed_api_deprecated.js
Last active December 2, 2015 09:43
Fetching feed in Angular
// BEFORE
var feedUrl = 'https://lingohub.com/blog/feed/rss2';
$http.jsonp('https://ajax.googleapis.com/ajax/services/feed/load', {params: {v: '1.0', q: feedUrl, num:-1, callback:'JSON_CALLBACK'}}).success(function(data) {
$scope.entries = data.responseData.feed.entries;
angular.forEach($scope.entries, function (entry) {
entry.publishedDate = new Date(entry.publishedDate);
});
});
@bettysteger
bettysteger / replace_regex.js
Last active August 29, 2015 14:27
How to reuse matched value of regex in replace JS function
var text = "this is a {highlighted} text";
var regex = /\{\S+?\}/g;
var html = text.replace(regex, '<mark>$&</mark>'); // $& = matched value = {highlight}
alert(html); // => "this is a <mark>{highlighted}</mark> text"
var regex2 = /\{(\S+?)\}/g; // you need ()-brackets to get $1
var html2 = text.replace(regex2, '<mark>$1</mark>'); // $1 = first () = highlight
alert(html2); // => "this is a <mark>highlighted</mark> text"
@bettysteger
bettysteger / 1modalStateProvider.js
Last active December 3, 2020 17:22
Bootstrap Modal window with custom URL in AngularJS (ui.bootstrap.modal with ui-router)
/**
* Modal provider. Adds state which will open a modal.
* Opens or closes modal on URL change.
*/
app.provider('modalState', function($stateProvider) {
var provider = this;
var modalResult;
this.$get = function() {
return provider;
};
@bettysteger
bettysteger / angular-translate.html
Last active October 19, 2016 09:20
Difference between angular-translate and the new Angular i18n approach
<a href="https://lingohub.com/projects" translate="projects_link"></a>
en.json: { "projects_link": "Projects" }
LingoHub creates:
de.json: { "projects_link": "Projekte" }
@bettysteger
bettysteger / config.js
Last active August 27, 2018 06:24
Angular $httpProvider interceptor to handle requests and also cancels request on state change
/**
* This array is needed for canceling requests when changing the state/route.
* @type {Array}
*/
var currentRequests = [];
/**
* Handles route changes.
*/
app.run(['$rootScope', function($rootScope) {
@bettysteger
bettysteger / directive.js
Created November 11, 2014 14:29
Declarative Metadata (Angular 2.0 directive)
// AtScript
@Directive({
selector: '[blink]'
})
class Blink {
constructor(elment:Element, options:Options, timeout:Timeout) {}
}
// ES6
class Blink {
// AtScript
class MyClass {
methodA(name:string):int {
var length:int = name.length;
return length;
}
}
// ES6
class MyClass {
@bettysteger
bettysteger / es6-classes-inheritance.js
Last active October 11, 2020 00:05
ES6 Classes and Inheritance example (www.es6fiddle.net)
/**
* Classes and Inheritance
* Code Example from http://www.es6fiddle.net/
*/
class Polygon {
constructor(height, width) { //class constructor
this.name = 'Polygon';
this.height = height;
this.width = width;
}