<!DOCTYPE html>
<html>
<head>
<link data-require="bootstrap-css@*" data-semver="3.1.1" rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
<link rel="stylesheet" href="angular-block-ui.css" />
<script data-require="angular.js@*" data-semver="1.2.15" src="http://code.angularjs.org/1.2.15/angular.js"></script>
<script data-require="angular-resource@*" data-semver="1.2.14" src="http://code.angularjs.org/1.2.14/angular-resource.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="angular-block-ui.js"></script>
<script src="script.js"></script>
</head>
<body ng-app="myApp" class="container">
<h1>angular-block-ui
<a href="https://github.com/McNull/angular-block-ui" target="_blank" class="btn btn-default pull-right" title="Github project">
<img src="https://raw.githubusercontent.com/github/media/master/octocats/blacktocat-32.png" alt="github">
</a>
</h1>
<div ng-controller="MyController">
<pre><code>{{ blockUIState | json }}</code></pre>
<pre><code>{{ table.offset | json }}</code></pre>
<div ng-if="table.items.length">
<!-- create a block overlay element -->
<div block-ui></div>
<table class="table">
<tr>
<th>Name</th>
<th>Lastname</th>
<th>Email</th>
<th>Country</th>
</tr>
<tr ng-repeat="item in table.items">
<td>{{ item.first_name }}</td>
<td>{{ item.last_name }}</td>
<td>{{ item.email }}</td>
<td>{{ item.country }}</td>
</tr>
</table>
<ul class="pagination">
<li><a href="" ng-click="table.previous()">«</a>
</li>
<li ng-repeat="i in [1,2,3,4,5]" ng-class="{ active: ($index * 10) === table.offset }">
<a href="" ng-click="table.offset = $index * 10">{{ i }}</a>
</li>
<li><a href="" ng-click="table.next()">»</a>
</li>
</ul>
</div>
</div>
</body>
</html>
// Code goes here
console.log('---------------------------------------------------------');
var myApp = angular.module('myApp', ['blockUI', 'ngResource']);
// Create an interceptor that will fake response times from the server.
myApp.config(function($httpProvider) {
$httpProvider.interceptors.push(function($q, $timeout, $templateCache) {
return {
request: function(config) {
// Don't delay cached requests
if($templateCache.get(config.url) !== undefined) {
return config;
}
var d = $q.defer();
var delay = Math.floor(Math.random() * 1500) + 300;
$timeout(function() {
d.resolve(config);
}, delay);
return d.promise;
}
};
});
});
myApp.controller('MyController', function($scope, myFakeDataResource, $http, blockUI) {
// Just to display the state in the ui
$scope.blockUIState = blockUI.state();
$scope.table = {
items: [],
offset: 0,
previous: function() {
$scope.table.offset = Math.max(0, $scope.table.offset - 10);
},
next: function() {
$scope.table.offset = Math.min(40, $scope.table.offset + 10);
}
};
$scope.$watch('table.offset', function(value) {
myFakeDataResource.query({ limit: 10, offset: value }).$promise.then(function(data) {
$scope.table.items = data;
});
});
});
myApp.factory('myFakeDataResource', function($http, $q) {
return {
query: function(params) {
var d = $q.defer();
var ret = [];
ret.$resolved = false;
ret.$promise = d.promise;
$http.get('data-array.json').then(function(response) {
ret.length = 0;
if(params.offset + params.limit >= response.data.length) {
params.offset = 0;
}
response.data = response.data.splice(params.offset, params.limit);
Array.prototype.push.apply(ret, response.data);
d.resolve(ret);
});
return ret;
}
};
});
/* Styles go here */
[{
"id": 1,
"first_name": "Jacqueline",
"last_name": "Fernandez",
"country": "Venezuela",
"ip_address": "213.150.222.215",
"email": "jfernandez@oodoo.com"
}, {
"id": 2,
"first_name": "Alice",
"last_name": "Harrison",
"country": "Tuvalu",
"ip_address": "192.96.178.253",
"email": "aharrison@centimia.net"
}, {
"id": 3,
"first_name": "Norma",
"last_name": "Hanson",
"country": "Mauritius",
"ip_address": "36.111.47.140",
"email": "nhanson@livetube.gov"
}, {
"id": 4,
"first_name": "Alan",
"last_name": "Rose",
"country": "Central African Republic",
"ip_address": "193.47.227.99",
"email": "arose@thoughtbridge.com"
}, {
"id": 5,
"first_name": "Anne",
"last_name": "Fuller",
"country": "USSR",
"ip_address": "185.235.65.230",
"email": "afuller@skippad.com"
}, {
"id": 6,
"first_name": "Daniel",
"last_name": "Wheeler",
"country": "Zambia",
"ip_address": "30.54.58.183",
"email": "dwheeler@roomm.info"
}, {
"id": 7,
"first_name": "Roger",
"last_name": "Bailey",
"country": "Wallis and Futuna Islands",
"ip_address": "157.162.170.225",
"email": "rbailey@thoughtmix.net"
}, {
"id": 8,
"first_name": "Stephanie",
"last_name": "Shaw",
"country": "Timor-Leste",
"ip_address": "44.154.186.217",
"email": "sshaw@eadel.mil"
}, {
"id": 9,
"first_name": "Lori",
"last_name": "Hawkins",
"country": "Greenland",
"ip_address": "40.171.191.26",
"email": "lhawkins@wikivu.edu"
}, {
"id": 10,
"first_name": "Emily",
"last_name": "Turner",
"country": "Oman",
"ip_address": "63.115.224.141",
"email": "eturner@tagtune.net"
}, {
"id": 11,
"first_name": "Diana",
"last_name": "Little",
"country": "Guadeloupe",
"ip_address": "66.109.103.68",
"email": "dlittle@twiyo.gov"
}, {
"id": 12,
"first_name": "Anthony",
"last_name": "Burns",
"country": "Panama",
"ip_address": "210.230.86.167",
"email": "aburns@snaptags.gov"
}, {
"id": 13,
"first_name": "Juan",
"last_name": "Vasquez",
"country": "United States of America",
"ip_address": "211.224.152.98",
"email": "jvasquez@rhycero.com"
}, {
"id": 14,
"first_name": "Nancy",
"last_name": "Little",
"country": "Paraguay",
"ip_address": "100.196.205.139",
"email": "nlittle@flashpoint.edu"
}, {
"id": 15,
"first_name": "Maria",
"last_name": "Murphy",
"country": "Togo",
"ip_address": "171.102.2.119",
"email": "mmurphy@eazzy.gov"
}, {
"id": 16,
"first_name": "Tina",
"last_name": "Ray",
"country": "Vatican City State (Holy See)",
"ip_address": "35.243.185.254",
"email": "tray@oyoyo.net"
}, {
"id": 17,
"first_name": "Judith",
"last_name": "Day",
"country": "Lebanon",
"ip_address": "196.211.215.52",
"email": "jday@yamia.info"
}, {
"id": 18,
"first_name": "Deborah",
"last_name": "Frazier",
"country": "Vietnam",
"ip_address": "188.233.143.58",
"email": "dfrazier@tagpad.edu"
}, {
"id": 19,
"first_name": "Joshua",
"last_name": "Hudson",
"country": "Austria",
"ip_address": "192.124.208.113",
"email": "jhudson@yamia.mil"
}, {
"id": 20,
"first_name": "Alice",
"last_name": "Hicks",
"country": "Botswana",
"ip_address": "204.92.95.180",
"email": "ahicks@devbug.edu"
}, {
"id": 21,
"first_name": "Charles",
"last_name": "Diaz",
"country": "Armenia",
"ip_address": "202.180.156.245",
"email": "cdiaz@browsedrive.net"
}, {
"id": 22,
"first_name": "Kevin",
"last_name": "Campbell",
"country": "Lithuania",
"ip_address": "138.144.105.122",
"email": "kcampbell@kamba.mil"
}, {
"id": 23,
"first_name": "Linda",
"last_name": "Russell",
"country": "Cayman Islands",
"ip_address": "115.22.8.58",
"email": "lrussell@youbridge.com"
}, {
"id": 24,
"first_name": "Jean",
"last_name": "Sanchez",
"country": "Finland",
"ip_address": "163.131.117.53",
"email": "jsanchez@gabtype.info"
}, {
"id": 25,
"first_name": "Alice",
"last_name": "Knight",
"country": "British Virgin Islands",
"ip_address": "198.202.182.63",
"email": "aknight@reallinks.mil"
}, {
"id": 26,
"first_name": "Shirley",
"last_name": "Hansen",
"country": "Madagascar",
"ip_address": "244.211.36.222",
"email": "shansen@abatz.com"
}, {
"id": 27,
"first_name": "Ernest",
"last_name": "Fuller",
"country": "Philippines",
"ip_address": "144.16.167.26",
"email": "efuller@skimia.name"
}, {
"id": 28,
"first_name": "Julie",
"last_name": "Lane",
"country": "Eritrea",
"ip_address": "38.163.32.183",
"email": "jlane@meembee.biz"
}, {
"id": 29,
"first_name": "Christina",
"last_name": "Lynch",
"country": "Pitcairn Island",
"ip_address": "33.239.167.122",
"email": "clynch@meevee.edu"
}, {
"id": 30,
"first_name": "Brian",
"last_name": "Ryan",
"country": "Egypt",
"ip_address": "112.34.51.134",
"email": "bryan@linkbridge.info"
}, {
"id": 31,
"first_name": "Charles",
"last_name": "Greene",
"country": "Jordan",
"ip_address": "190.240.91.163",
"email": "cgreene@yodoo.com"
}, {
"id": 32,
"first_name": "Matthew",
"last_name": "Romero",
"country": "Tokelau",
"ip_address": "144.128.139.38",
"email": "mromero@rhynoodle.biz"
}, {
"id": 33,
"first_name": "Jonathan",
"last_name": "Sims",
"country": "Turkmenistan",
"ip_address": "226.37.173.119",
"email": "jsims@abata.mil"
}, {
"id": 34,
"first_name": "Frank",
"last_name": "Perry",
"country": "Mozambique",
"ip_address": "119.155.84.96",
"email": "fperry@ailane.name"
}, {
"id": 35,
"first_name": "Ann",
"last_name": "Reyes",
"country": "Gibraltar",
"ip_address": "102.131.14.108",
"email": "areyes@yotz.edu"
}, {
"id": 36,
"first_name": "Larry",
"last_name": "Gray",
"country": "Poland",
"ip_address": "221.51.16.44",
"email": "lgray@twitternation.name"
}, {
"id": 37,
"first_name": "Donna",
"last_name": "Matthews",
"country": "Bahrain",
"ip_address": "18.129.11.197",
"email": "dmatthews@babbleopia.net"
}, {
"id": 38,
"first_name": "Jessica",
"last_name": "Ward",
"country": "New Caledonia",
"ip_address": "7.226.231.119",
"email": "jward@zazio.net"
}, {
"id": 39,
"first_name": "Irene",
"last_name": "Clark",
"country": "\u00c5land",
"ip_address": "181.18.163.214",
"email": "iclark@twimbo.info"
}, {
"id": 40,
"first_name": "Barbara",
"last_name": "Freeman",
"country": "Dominican Republic",
"ip_address": "39.174.173.97",
"email": "bfreeman@teklist.org"
}, {
"id": 41,
"first_name": "Gary",
"last_name": "Vasquez",
"country": "Belize",
"ip_address": "108.145.159.131",
"email": "gvasquez@zoomcast.info"
}, {
"id": 42,
"first_name": "William",
"last_name": "Burns",
"country": "Singapore",
"ip_address": "184.232.182.77",
"email": "wburns@twitterlist.mil"
}, {
"id": 43,
"first_name": "Helen",
"last_name": "Lynch",
"country": "Kuwait",
"ip_address": "81.66.211.31",
"email": "hlynch@trilith.name"
}, {
"id": 44,
"first_name": "Mildred",
"last_name": "Garcia",
"country": "Kiribati",
"ip_address": "243.134.66.153",
"email": "mgarcia@quire.mil"
}, {
"id": 45,
"first_name": "Rebecca",
"last_name": "Dixon",
"country": "Eritrea",
"ip_address": "96.211.197.100",
"email": "rdixon@skinder.name"
}, {
"id": 46,
"first_name": "Donna",
"last_name": "Williams",
"country": "Egypt",
"ip_address": "155.245.190.105",
"email": "dwilliams@tanoodle.org"
}, {
"id": 47,
"first_name": "Roy",
"last_name": "Evans",
"country": "Kazakhstan",
"ip_address": "65.246.16.231",
"email": "revans@meetz.org"
}, {
"id": 48,
"first_name": "Samuel",
"last_name": "Young",
"country": "Togo",
"ip_address": "8.153.236.153",
"email": "syoung@youfeed.name"
}, {
"id": 49,
"first_name": "Dorothy",
"last_name": "Morris",
"country": "Niue",
"ip_address": "20.14.176.75",
"email": "dmorris@aimbu.info"
}, {
"id": 50,
"first_name": "Kimberly",
"last_name": "Hicks",
"country": "Bermuda",
"ip_address": "120.221.183.189",
"email": "khicks@jatri.edu"
}, {
"id": 51,
"first_name": "Kathryn",
"last_name": "Mason",
"country": "Ukraine",
"ip_address": "121.76.34.93",
"email": "kmason@gigashots.biz"
}, {
"id": 52,
"first_name": "Ernest",
"last_name": "Jacobs",
"country": "Dominica",
"ip_address": "239.214.100.196",
"email": "ejacobs@yoveo.com"
}, {
"id": 53,
"first_name": "Joan",
"last_name": "Ramirez",
"country": "Trinidad and Tobago",
"ip_address": "125.1.112.4",
"email": "jramirez@tazzy.name"
}, {
"id": 54,
"first_name": "Barbara",
"last_name": "Gray",
"country": "Indonesia",
"ip_address": "146.114.119.210",
"email": "bgray@skilith.mil"
}, {
"id": 55,
"first_name": "Elizabeth",
"last_name": "Castillo",
"country": "Laos",
"ip_address": "206.184.200.149",
"email": "ecastillo@livez.biz"
}, {
"id": 56,
"first_name": "Aaron",
"last_name": "Dean",
"country": "Dominica",
"ip_address": "51.175.196.40",
"email": "adean@quinu.org"
}, {
"id": 57,
"first_name": "Harold",
"last_name": "Miller",
"country": "Djibouti",
"ip_address": "118.125.34.59",
"email": "hmiller@brainverse.com"
}, {
"id": 58,
"first_name": "Louise",
"last_name": "Watson",
"country": "Christmas Island",
"ip_address": "140.128.170.92",
"email": "lwatson@livetube.name"
}, {
"id": 59,
"first_name": "Shirley",
"last_name": "Williamson",
"country": "Grenada",
"ip_address": "64.232.156.9",
"email": "swilliamson@buzzbean.biz"
}, {
"id": 60,
"first_name": "Johnny",
"last_name": "Rice",
"country": "Bosnia and Herzegovina",
"ip_address": "255.125.57.233",
"email": "jrice@wikizz.name"
}, {
"id": 61,
"first_name": "Janet",
"last_name": "Duncan",
"country": "American Samoa",
"ip_address": "223.58.143.95",
"email": "jduncan@devshare.edu"
}, {
"id": 62,
"first_name": "Bonnie",
"last_name": "Pierce",
"country": "Uruguay",
"ip_address": "171.65.104.223",
"email": "bpierce@avavee.gov"
}, {
"id": 63,
"first_name": "Amy",
"last_name": "Stevens",
"country": "Comoros",
"ip_address": "58.229.24.136",
"email": "astevens@feedfish.com"
}, {
"id": 64,
"first_name": "Dennis",
"last_name": "Mcdonald",
"country": "Libya",
"ip_address": "115.26.73.212",
"email": "dmcdonald@quamba.net"
}, {
"id": 65,
"first_name": "Samuel",
"last_name": "Carroll",
"country": "Cambodia",
"ip_address": "255.123.156.36",
"email": "scarroll@brightbean.edu"
}, {
"id": 66,
"first_name": "Donald",
"last_name": "Hunt",
"country": "India",
"ip_address": "249.243.180.224",
"email": "dhunt@wikivu.gov"
}, {
"id": 67,
"first_name": "Richard",
"last_name": "Grant",
"country": "Lithuania",
"ip_address": "40.251.117.40",
"email": "rgrant@zoomlounge.name"
}, {
"id": 68,
"first_name": "Peter",
"last_name": "Gray",
"country": "Venezuela",
"ip_address": "105.39.139.181",
"email": "pgray@fivebridge.org"
}, {
"id": 69,
"first_name": "Amanda",
"last_name": "Austin",
"country": "Puerto Rico",
"ip_address": "230.34.216.92",
"email": "aaustin@twimm.org"
}, {
"id": 70,
"first_name": "Daniel",
"last_name": "Anderson",
"country": "Bahrain",
"ip_address": "222.86.102.152",
"email": "danderson@wikizz.info"
}, {
"id": 71,
"first_name": "Billy",
"last_name": "Simpson",
"country": "Bulgaria",
"ip_address": "217.6.105.249",
"email": "bsimpson@centizu.com"
}, {
"id": 72,
"first_name": "Lois",
"last_name": "Bishop",
"country": "Spain",
"ip_address": "21.124.106.9",
"email": "lbishop@trupe.info"
}, {
"id": 73,
"first_name": "Patrick",
"last_name": "Wilson",
"country": "Uzbekistan",
"ip_address": "191.168.16.150",
"email": "pwilson@livez.net"
}, {
"id": 74,
"first_name": "Lois",
"last_name": "Castillo",
"country": "Hungary",
"ip_address": "161.11.183.164",
"email": "lcastillo@livez.net"
}, {
"id": 75,
"first_name": "Ronald",
"last_name": "Harrison",
"country": "Vatican City State (Holy See)",
"ip_address": "170.233.118.208",
"email": "rharrison@photobean.org"
}, {
"id": 76,
"first_name": "Joseph",
"last_name": "Richards",
"country": "Qatar",
"ip_address": "220.23.133.176",
"email": "jrichards@zooxo.info"
}, {
"id": 77,
"first_name": "Carol",
"last_name": "Grant",
"country": "Belgium",
"ip_address": "154.244.250.40",
"email": "cgrant@zava.com"
}, {
"id": 78,
"first_name": "Craig",
"last_name": "Knight",
"country": "Malaysia",
"ip_address": "127.110.140.37",
"email": "cknight@twitterlist.name"
}, {
"id": 79,
"first_name": "Philip",
"last_name": "Jones",
"country": "Azerbaijan",
"ip_address": "89.174.50.152",
"email": "pjones@twiyo.mil"
}, {
"id": 80,
"first_name": "Gary",
"last_name": "Garrett",
"country": "China",
"ip_address": "244.158.13.24",
"email": "ggarrett@yozio.net"
}, {
"id": 81,
"first_name": "Beverly",
"last_name": "Hawkins",
"country": "Oman",
"ip_address": "222.155.191.79",
"email": "bhawkins@tekfly.biz"
}, {
"id": 82,
"first_name": "Jimmy",
"last_name": "Mason",
"country": "Gambia",
"ip_address": "50.180.186.235",
"email": "jmason@skyble.edu"
}, {
"id": 83,
"first_name": "Joan",
"last_name": "Stanley",
"country": "Malawi",
"ip_address": "155.77.109.156",
"email": "jstanley@kaymbo.mil"
}, {
"id": 84,
"first_name": "Harry",
"last_name": "White",
"country": "Northern Mariana Islands",
"ip_address": "85.160.138.0",
"email": "hwhite@ntag.name"
}, {
"id": 85,
"first_name": "Cheryl",
"last_name": "Reed",
"country": "Oman",
"ip_address": "110.190.252.236",
"email": "creed@plambee.edu"
}, {
"id": 86,
"first_name": "Jane",
"last_name": "Green",
"country": "Tokelau",
"ip_address": "23.234.148.129",
"email": "jgreen@mynte.org"
}, {
"id": 87,
"first_name": "Sandra",
"last_name": "Hughes",
"country": "Sweden",
"ip_address": "82.225.14.54",
"email": "shughes@twiyo.org"
}, {
"id": 88,
"first_name": "Ruth",
"last_name": "Franklin",
"country": "Sudan",
"ip_address": "15.188.148.229",
"email": "rfranklin@jabbercube.mil"
}, {
"id": 89,
"first_name": "Wayne",
"last_name": "Jackson",
"country": "Palau",
"ip_address": "172.232.190.36",
"email": "wjackson@quimba.com"
}, {
"id": 90,
"first_name": "Catherine",
"last_name": "Daniels",
"country": "Bangladesh",
"ip_address": "87.126.48.62",
"email": "cdaniels@katz.name"
}, {
"id": 91,
"first_name": "Louise",
"last_name": "Lane",
"country": "Jersey",
"ip_address": "106.135.64.45",
"email": "llane@jabbersphere.org"
}, {
"id": 92,
"first_name": "Alan",
"last_name": "Sanchez",
"country": "Slovenia",
"ip_address": "197.99.177.234",
"email": "asanchez@flashdog.info"
}, {
"id": 93,
"first_name": "Ann",
"last_name": "Lopez",
"country": "Japan",
"ip_address": "59.220.111.196",
"email": "alopez@babbleopia.mil"
}, {
"id": 94,
"first_name": "Patricia",
"last_name": "Murray",
"country": "Faroe Islands",
"ip_address": "140.35.81.26",
"email": "pmurray@jaxspan.gov"
}, {
"id": 95,
"first_name": "Judith",
"last_name": "Pierce",
"country": "Brunei Darussalam",
"ip_address": "63.125.146.126",
"email": "jpierce@demivee.com"
}, {
"id": 96,
"first_name": "Angela",
"last_name": "Armstrong",
"country": "Grenada",
"ip_address": "251.9.149.42",
"email": "aarmstrong@twitternation.net"
}, {
"id": 97,
"first_name": "James",
"last_name": "Mendoza",
"country": "Netherlands",
"ip_address": "93.238.151.254",
"email": "jmendoza@npath.net"
}, {
"id": 98,
"first_name": "Stephen",
"last_name": "Hill",
"country": "Sri Lanka",
"ip_address": "5.214.209.161",
"email": "shill@jumpxs.net"
}, {
"id": 99,
"first_name": "Nancy",
"last_name": "Russell",
"country": "Saint Vincent and the Grenadines",
"ip_address": "111.39.156.179",
"email": "nrussell@agivu.name"
}]
/* Copyright (c) 2013-2014, Null McNull https://github.com/McNull, LICENSE: MIT */
// NOTE: this is a modified work in progress version.
(function(angular) {
angular.module('blockUI', ['templates-angularBlockUI']);
angular.module('blockUI').config(function($provide, $httpProvider) {
var _config = {
templateUrl: 'angular-block-ui/angular-block-ui.tmpl.html',
delay: 250,
message: "Loading ...",
autoBlock: true,
resetOnException: true,
requestFilter: angular.noop
};
$provide.provider('blockUIConfig', function() {
this.templateUrl = function(url) {
_config.templateUrl = url;
};
this.template = function(template) {
_config.template = template;
};
this.delay = function(delay) {
_config.delay = delay;
};
this.message = function(message) {
_config.message = message;
};
this.autoBlock = function(enabled) {
_config.autoBlock = enabled;
};
this.resetOnException = function(enabled) {
_config.resetOnException = enabled;
};
this.requestFilter = function(filter) {
_config.requestFilter = filter;
};
this.$get = function() {
return _config;
};
}); // blockUIConfig
$provide.decorator('$exceptionHandler', ['$delegate', '$injector',
function($delegate, $injector) {
var blockUI;
return function(exception, cause) {
if (_config.resetOnException) {
blockUI = blockUI || $injector.get('blockUI');
blockUI.reset();
}
$delegate(exception, cause);
};
}
]);
$provide.factory('blockUIHttpInterceptor', ['$q', '$injector',
function($q, $injector) {
var blockUI;
function injectBlockUI() {
blockUI = blockUI || $injector.get('blockUI');
}
function error(rejection) {
if (_config.autoBlock) {
injectBlockUI();
blockUI.stop();
}
return $q.reject(rejection);
}
return {
request: function(config) {
if (_config.autoBlock) {
// Don't block excluded requests
if (_config.requestFilter(config) === false) {
// Tag the config so we don't unblock this request
config.$_noBlock = true;
} else {
injectBlockUI();
blockUI.start();
}
}
return config;
},
requestError: error,
response: function(response) {
// Check if the response is tagged to ignore
if (_config.autoBlock && !response.config.$_noBlock) {
injectBlockUI();
blockUI.stop();
}
return response;
},
responseError: error
};
}
]);
$httpProvider.interceptors.push('blockUIHttpInterceptor');
});
angular.module('blockUI').directive('blockUi', function(blockUI, blockUIConfig) {
return {
restrict: 'A',
templateUrl: blockUIConfig.template ? undefined : blockUIConfig.templateUrl,
template: blockUIConfig.template,
link: function($scope, $element, $attrs) {
$scope.state = blockUI.state();
$element.addClass('block-ui');
var $parent = $element.parent();
// Locate the parent element
if ($parent) {
// If the parent is the body element, hook into the view loaded event
if ($parent[0].tagName === 'BODY') {
var fn = $scope.$on('$viewContentLoaded', function($event) {
// Unhook the view loaded and hook a function that will prevent
// location changes while the block is active.
fn();
$scope.$on('$locationChangeStart', function(event) {
if ($scope.state.blockCount > 0) {
event.preventDefault();
}
});
});
} else {
// Ensure that the parent position is set to relative
$parent.css('position', 'relative');
}
}
}
};
});
angular.module('blockUI').factory('blockUI', function(blockUIConfig, $timeout) {
var state = {
blockCount: 0,
message: blockUIConfig.message,
blocking: false
}, startPromise, stopPromise, doneCallbacks = [];
function start(message) {
state.message = message || blockUIConfig.message;
state.blockCount++;
if (!startPromise) {
startPromise = $timeout(function() {
startPromise = null;
state.blocking = true;
}, blockUIConfig.delay);
}
}
function cancelStartTimeout() {
if (startPromise) {
$timeout.cancel(startPromise);
startPromise = null;
}
}
function stop() {
state.blockCount = Math.max(0, --state.blockCount);
if (state.blockCount === 0) {
reset(true);
}
}
function message(message) {
state.message = message;
}
function reset(executeCallbacks) {
cancelStartTimeout();
state.blockCount = 0;
state.blocking = false;
try {
if (executeCallbacks) {
angular.forEach(doneCallbacks, function(cb) {
cb();
});
}
} finally {
doneCallbacks.length = 0;
}
}
function done(fn) {
doneCallbacks.push(fn);
}
return {
state: function() {
return state;
},
start: start,
stop: stop,
message: message,
reset: reset,
done: done
};
});
angular.module('blockUI').run(function($document) {
//$document.find('body').append('<div block-ui></div>');
});
})(angular);
angular.module('templates-angularBlockUI', ['angular-block-ui/angular-block-ui.tmpl.html']);
angular.module("angular-block-ui/angular-block-ui.tmpl.html", []).run(["$templateCache",
function($templateCache) {
$templateCache.put("angular-block-ui/angular-block-ui.tmpl.html",
"<div ng-show=\"state.blockCount > 0\" class=\"block-ui-overlay\" ng-class=\"{ 'block-ui-visible': state.blocking }\"></div>\n" +
"<div ng-show=\"state.blocking\" class=\"block-ui-message-container\">\n" +
" <div class=\"block-ui-message\">{{ state.message }}</div> \n" +
"</div>\n" +
"");
}
]);
.block-ui-overlay {
z-index: 10001;
border: none;
margin: 0;
padding: 0;
width: 100%;
height: 100%;
top: 0;
left: 0;
position: absolute;
}
body > .block-ui > .block-ui-overlay {
position: fixed;
}
.block-ui-overlay.block-ui-visible {
background-color: #fff;
opacity: 0.5;
-ms-filter:"alpha(opacity=50)";
cursor: wait;
}
.block-ui-message-container {
position: absolute;
top: 40%;
left: 0;
right: 0;
height: 0;
text-align: center;
z-index: 10002;
}
body > .block-ui > .block-ui-message-container {
position: fixed;
}
.block-ui-message {
cursor: wait;
display: inline-block;
text-align: left;
background-color: #333;
color: #f5f5f5;
padding: 20px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
font-size: 20px;
font-weight: bold;
}