Skip to content

Add css rules on the App start #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions demo/multipleReloadTest/multipleReload.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>Multiple reload test</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.js"></script>
<script src="../../src/ui-scroll.js"></script>
<script src="../../dist/ui-scroll.js"></script>
<script src="multipleReload.js"></script>
<link rel="stylesheet" href="../css/style.css" type="text/css"/>
</head>
Expand All @@ -17,12 +17,12 @@
<h1 class="page-header page-header-exapmle">Multiple reload test</h1>

<div class="actions">
<button ng-click="doSingleReload()"> Do single reload</button>
<button ng-click="show = !show"> Do single reload</button>
<button ng-click="doMultipleReload()"> Do multiple reload</button>
Loading: {{adapter.isLoading}}
</div>

<div class="viewport" id="viewport-scopeDatasource" ui-scroll-viewport>
<div class="viewport" id="viewport-scopeDatasource" ui-scroll-viewport ng-if="show">
<div class="item" ui-scroll="item in datasource" adapter="adapter">{{item}}</div>
</div>

Expand Down
46 changes: 29 additions & 17 deletions dist/ui-scroll.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/ui-scroll.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/ui-scroll.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ui-scroll.min.js.map

Large diffs are not rendered by default.

28 changes: 18 additions & 10 deletions src/modules/elementRoutines.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
const hideClassToken = 'ng-ui-scroll-hide';

function addCSSRule(sheet, selector, rules, index) {
if('insertRule' in sheet) {
sheet.insertRule(selector + '{' + rules + '}', index);
}
else if('addRule' in sheet) {
sheet.addRule(selector, rules, index);
}
}

export default class ElementRoutines {

static addCSSRules() {
const selector = '.' + hideClassToken;
const rules = 'display: none';
const sheet = document.styleSheets[0];
let index;
try {
index = sheet.cssRules.length;
} catch (err) {
index = 0;
}
if('insertRule' in sheet) {
sheet.insertRule(selector + '{' + rules + '}', index);
}
else if('addRule' in sheet) {
sheet.addRule(selector, rules, index);
}
}

constructor($injector, $q) {
this.$animate = ($injector.has && $injector.has('$animate')) ? $injector.get('$animate') : null;
this.isAngularVersionLessThen1_3 = angular.version.major === 1 && angular.version.minor < 3;
this.$q = $q;
addCSSRule(document.styleSheets[0], '.' + hideClassToken, 'display: none');
}

hideElement(wrapper) {
Expand Down
7 changes: 4 additions & 3 deletions src/ui-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import Adapter from './modules/adapter.js';
angular.module('ui.scroll', [])

.constant('JQLiteExtras', JQLiteExtras)
.run(['JQLiteExtras', (JQLiteExtras) =>
!window.jQuery ? (new JQLiteExtras()).registerFor(angular.element) : null
])
.run(['JQLiteExtras', (JQLiteExtras) => {
!window.jQuery ? (new JQLiteExtras()).registerFor(angular.element) : null;
ElementRoutines.addCSSRules();
}])

.directive('uiScrollViewport', function () {
return {
Expand Down