Last active
May 3, 2016 15:53
-
-
Save adasq/7d0e789cff4d91dd6268 to your computer and use it in GitHub Desktop.
MODALwrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<!-- | |
Created using JS Bin | |
http://jsbin.com | |
Released under the MIT license: http://jsbin.mit-license.org | |
--> | |
<html> | |
<head> | |
<script src="http://code.jquery.com/jquery.min.js"></script> | |
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> | |
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> | |
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.10.0/ui-bootstrap-tpls.min.js"></script> | |
<meta name="description" content="test" /> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div ng-app="app"> | |
<div ng-controller="HomeCtrl"> | |
<button ng-click="open()" type="button" class="btn btn=default">modal</button> | |
</div> | |
</div> | |
<script id="jsbin-javascript"> | |
var app = angular.module('app', ['home']); | |
angular.module('ModalWrapper', ['ui.bootstrap']) | |
.factory('ModalWrapper', function($modal, $log, $templateCache ) { | |
$templateCache.put('ModalWrapper.base.html', | |
'<div class=""><div style="margin: 10px;" class="pull-right"><span ng-click="wrapController.close()" style="cursor: pointer;" class="glyphicon glyphicon-remove"></span></div></div>' + | |
'<div ng-include="template"></div>' | |
); | |
return function(config) { | |
var wrapController = function(template) { | |
return function($scope, $modalInstance, items){ | |
$scope.x= 99; | |
$scope.template = template; | |
$scope.wrapController = { | |
close: function(x) { | |
$modalInstance.dismiss(x); | |
}, | |
ok: function(x) { | |
$modalInstance.close(x); | |
} | |
}; | |
}; | |
}; | |
var modalInstance = null; | |
this.onResolve = function() { | |
$log.log('onResolve', arguments); | |
}; | |
this.onReject = function() { | |
$log.log('onReject',arguments); | |
}; | |
var innerTemplateUrl = config.templateUrl; | |
config.templateUrl= 'ModalWrapper.base.html'; | |
config.controller= wrapController(innerTemplateUrl); | |
this.open = function() { | |
modalInstance = $modal.open(config); | |
modalInstance.result.then(this.onResolve, this.onReject); | |
}; | |
this.close = function() { | |
modalInstance.close.apply(this, arguments); | |
} | |
}; | |
}); | |
angular.module('home', ['ui.bootstrap', 'ModalWrapper']) | |
.controller('templateIdCtrl', function ($scope) { | |
$scope.test= 'test'; | |
$scope.ok = function() { | |
$scope.wrapController.ok($scope.test); | |
}; | |
$scope.cancel = function() { | |
$scope.wrapController.close('cancel'); | |
}; | |
}) | |
.controller('HomeCtrl', function($log, $timeout, $scope, $modal, $templateCache, ModalWrapper){ | |
$templateCache.put('templateId.html', | |
'<div ng-controller="templateIdCtrl"> <div class="modal-header">'+ | |
' <h3 class="modal-title">title</h3>'+ | |
' </div>'+ | |
' <div class="modal-body"> <span ng-click="wrapController.close()">{{test}}</span> '+ | |
' </div>'+ | |
' <div class="modal-footer">'+ | |
' <button class="btn btn-primary" ng-click="ok()">OK</button>'+ | |
'<button class="btn btn-warning" ng-click="cancel()">Cancel</button>'+ | |
' </div></div>' | |
); | |
var modalWrapperConfig = { | |
templateUrl: 'templateId.html', | |
backdrop : 'static', | |
windowClass: 'xx-dialog', | |
resolve: { | |
items: function () { | |
return ['item1', 'item2', 'item3']; | |
} | |
} | |
}; | |
var modal = new ModalWrapper(modalWrapperConfig); | |
$log.log(ModalWrapper.t); | |
$scope.open= function() { | |
modal.open(); | |
}; | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment