Skip to content

Instantly share code, notes, and snippets.

View frontainer's full-sized avatar

せーぶる frontainer

  • Japan Chiba
View GitHub Profile
@frontainer
frontainer / bindonce.js
Created August 29, 2014 00:09
AngularJSのシンプルなbindOnceディレクティブ
//http://stackoverflow.com/questions/18790333/angular-js-render-value-without-data-binding
app.directive('bindOnce', function() {
return {
scope: true,
link: function( $scope, $element ) {
setTimeout(function() {
$scope.$destroy();
}, 0);
}
@frontainer
frontainer / jquery.transition-inout.js
Created August 20, 2014 15:19
CSSのTransitionを使ってdisplay:block;とnoneを切り分けるjQueryプチプラグイン
(function() {
var transitionEnd = 'transitionend webkitTransitionEnd oTransitionEnd';
function hideHandler() {
$(this).hide();
}
$.fn.transitionIn = function(cls) {
var $this = this;
$this.show();
$this.off(transitionEnd, hideHandler);
var timer = window.setTimeout(function() {
@frontainer
frontainer / sample.html
Created August 4, 2014 01:00
画像を要素のサイズに収まるようにリサイズしてセンタリングするCSS
<div class="thumb"><div><img src="http://placeimg.com/300/200/animals"></div></div>
/**
* Suggestディレクティブ
*/
angular.module('directives').directive('suggest',function($timeout) {
return {
restrict: 'AC',
scope: {
list: '=',
model: '=ngModel',
key: '@',
/**
* URLエンコードしてモデルに値を入れ直すディレクティブ
* <textarea ng-model="myModel" urldecode></textarea>
*/
angular.module('directives').directive('urldecode',function() {
return {
restrict: 'A',
scope: {
ngModel: '='
},
@frontainer
frontainer / ShiftSubmit.js
Created June 3, 2014 23:09
TextareaをShift+EnterでSubmitするAngularJSディレクティブ
/**
* Shift+Enterでsubmitするディレクティブ
*/
angular.module("directives").directive("shiftSubmit",
function() {
return {
restrict: 'AC',
link : function($scope, $element, $attr){
var $form = angular.element(document[$attr.shiftSubmit]);
$element.on("keydown", function(e) {
@frontainer
frontainer / LineBreak.js
Created June 3, 2014 23:05
改行コードを<br>に変換するAngularJSフィルタ
/**
* 改行コードをbrに変換するフィルタ
*/
angular.module('filters').filter('lineBreak', function () {
return function (input, exp) {
return input.replace(/\n|\r/g, "<br>");
}
});
@frontainer
frontainer / ExampleCtrl.js
Last active August 29, 2015 14:02
AngularJSとSocket.ioを接続するサービス
angular.module('controllers').controller('ExampleCtrl',function($scope,SocketService) {
$scope.messages = [];
SocketService.on('receive', function(message) {
$scope.messages.unshift(message);
});
$scope.send = function() {
SocketService.emit('send',$scope.inputMessage);
$scope.inputMessage = '';
};
});
@frontainer
frontainer / app.js
Created June 3, 2014 23:01
AngularJSのapp.js初期テンプレート
/**
* app.js
*/
(function(angular) {
var MODULES = [
'ngSanitize',
'ngAnimate',
'ngRoute',
'ngCookies'
];