Skip to content

Commit

Permalink
minor bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Bosch committed Mar 21, 2012
1 parent 34dcd16 commit 184c272
Show file tree
Hide file tree
Showing 15 changed files with 178 additions and 259 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Expand Up @@ -8,10 +8,14 @@ Changelog
- removed `iff` expression as it was only used internally and is now no more needed.
- removed `$.mobile.globalScope` Use angular's `$rootScope` service instead.
- removed `ngm:fadein` directive, as it is not related to mobile
- removed `$navigate` expression, as angular now automatically evaluates promises to the result of the promises,
by which the `$navigate` expression was no more able to wait for the end of a call.
- TODO: The paging will change, as angular no more allows us to enhance list-expressions. Probably using filters.
- updated the build process
- removed custom build of jquery mobile, as no patches are needed any more to work
with angular 1.0.


1.0.6
-------------
- Update to jquery mobile 1.1
Expand Down
15 changes: 0 additions & 15 deletions README.md
Expand Up @@ -148,21 +148,6 @@ Default messages are:
- `$.mobile.loadingMessage`: for all other cases


### Angular-Expressions: Function $navigate
Every expression can now use the `$navigate` expression to define the navigation outside of the controlers
in the html pages. By this, the controllers stay independent of the navigation process and is reusable.

There are two types of syntax:
1. `$activate(target)`: Navigates to the given target using the `$navigate` service, so the target can also
include a transition.
2. `$activate(test,'outcome1:target','outcome2:target',...)`: Navigates to that target whose outcome equals
to the test. The special outcomes `success` is applied for any value for `test` that is not `false` (e.g. also `undefined`),
and the outcome `failure` is used for the value `false` of test.
This also supports promises. In that case, the navivation is done with the first argument of
the `done` / `fail` callback of the promise. Also, the `success` outcome is mapped to the `done` callback
and the `failure` outcome to the `fail` callback.


### Paging for lists
Lists can be paged in the sense that more entries can be additionally loaded. By "loading" we mean the
display of a sublist of a list that is already fully loaded in JavaScript. This is useful, as the main performance
Expand Down
129 changes: 47 additions & 82 deletions compiled/jquery-mobile-angular-adapter-1.0.7-SNAPSHOT.js
Expand Up @@ -249,58 +249,6 @@ jqmng.define('jqmng/navigate', ['jquery', 'angular'], function($, angular) {
return undefined;
}

mod.run(['$rootScope', '$navigate', function($rootScope, $navigate) {
$rootScope.$navigate = function() {
var args = Array.prototype.slice.call(arguments);
args.unshift($navigate);
return navigateExpression.apply(this, args);
}
}]);

/**
* Helper function to put the navigation part out of the controller into the page.
* @param scope
*/
var navigateExpression = function(service) {
if (arguments.length === 2) {
// used without the test.
service(arguments[1]);
return;
}
// parse the arguments...
var test = arguments[1];
var outcomes = {};
var parts;
for (var i = 2; i < arguments.length; i++) {
parts = splitAtFirstColon(arguments[i]);
outcomes[parts[0]] = parts[1];
}
if (test && test.then) {
// test is a promise.
test.then(function(test) {
if (outcomes[test]) {
service(outcomes[test]);
} else if (outcomes.success) {
service(outcomes.success);
}
}, function(test) {
if (outcomes[test]) {
service(outcomes[test]);
} else if (outcomes.failure) {
service(outcomes.failure);
}
});
} else {
if (outcomes[test]) {
service(outcomes[test]);
} else if (test !== false && outcomes.success) {
service(outcomes.success);
} else if (test === false && outcomes.failure) {
service(outcomes.failure);
}
}
};

return navigate;

});
Expand Down Expand Up @@ -701,6 +649,18 @@ jqmng.define('jqmng/widgets/disabledHandling', ['jquery', 'angular'], function (
}
}
});

mod.directive('ngDisabled', function () {
return {
compile:function () {
return {
post:function (scope, element, attr) {
instrumentAttrSetter(element, attr);
}
}
}
}
});
}
);
jqmng.define('jqmng/widgets/jqmButton', [
Expand Down Expand Up @@ -895,8 +855,11 @@ jqmng.define('jqmng/widgets/pageCompile', ['jquery', 'angular'], function ($, an
});

$('div').live('jqmngpagebeforeshow', function (event, data) {
var currPageScope = $(event.target).scope();
if (currPageScope) {
var page = $(event.target);
var currPageScope = page.scope();
if (page.data('angularLinked') && currPageScope) {
// We only need to trigger the digest for pages
// creates by angular, and not for those that are dynamically created by jquery mobile.
setCurrScope(currPageScope);
currPageScope.$root.$digest();
}
Expand All @@ -922,6 +885,9 @@ jqmng.define('jqmng/widgets/pageCompile', ['jquery', 'angular'], function ($, an
var currScope = null;

function setCurrScope(scope) {
if (scope===scope.$root) {
console.log("now");
}
currScope = scope;
}

Expand All @@ -930,37 +896,26 @@ jqmng.define('jqmng/widgets/pageCompile', ['jquery', 'angular'], function ($, an
ng.run(patchRootDigest);
var pages = [];
function patchRootDigest($rootScope) {
var _apply = $rootScope.$apply;
$rootScope.$apply = function() {
if ($rootScope.$$phase) {
return $rootScope.$eval.apply(this, arguments);
}
return _apply.apply(this, arguments);
};

var _digest = $rootScope.$digest;
$rootScope.$digest = function() {
var pages = $(":jqmData(role='page')");
var hasCompiledPages = false;
var notCompiledPages = [];
for (var i=0; i<pages.length; i++) {
var page = pages.eq(i);
if (page.data("page")) {
// used when angular creates new pages on the fly
hasCompiledPages = true;
} else {
notCompiledPages.push(page);
}
}
if (!hasCompiledPages) {
// first page compile...
$.mobile.initializePage();
}
for (var i=0; i<notCompiledPages.length; i++) {
// Case: Angular added a new page. This needs to be compiled
// with angular first.
var page = notCompiledPages[i];
page.page();
if ($rootScope.$$phase) {
return;
}
// digest the current page separately.
// This is due to performance reasons!
if (this !== currScope) {
var res = _digest.apply(this, arguments);
if (this===$rootScope) {
// digest the current page separately.
// This is due to performance reasons!
currScope && currScope.$digest();
}

return _digest.apply(this, arguments);
return res;
};
}
patchRootDigest.$inject = ['$rootScope'];
Expand Down Expand Up @@ -1006,13 +961,13 @@ jqmng.define('jqmng/widgets/pageCompile', ['jquery', 'angular'], function ($, an
return {
restrict:'A',
scope:true,
compile:function compile(tElement, tAttrs, transclude) {
compile:function compile(tElement, tAttrs) {
degradeInputs(tElement);
if (tAttrs.role !== 'page') {
return {};
}
return {
pre:function preLink(scope, iElement, iAttrs, controller) {
pre:function preLink(scope, iElement, iAttrs) {
// Detatch the scope for the normal $digest cycle
scope.$destroy();
var createJqmWidgetsFlag = false;
Expand All @@ -1029,6 +984,16 @@ jqmng.define('jqmng/widgets/pageCompile', ['jquery', 'angular'], function ($, an
}
return res;
};
},
post:function preLink(scope, iElement, iAttrs) {
if (!iElement.data("page")) {
iElement.data('angularLinked', true);
if (!scope.$root.jqmInitialized) {
scope.$root.jqmInitialized = true;
$.mobile.initializePage();
}
iElement.page();
}
}
}
}
Expand Down
1 change: 0 additions & 1 deletion jstd-unit.conf
Expand Up @@ -17,6 +17,5 @@ test:
# TODO remove this
exclude:
- src/test/webapp/unit/arrayPagingSpec.js
- src/test/webapp/unit/navigateSpec.js


52 changes: 0 additions & 52 deletions src/main/webapp/jqmng/navigate.js
Expand Up @@ -100,58 +100,6 @@ jqmng.define('jqmng/navigate', ['jquery', 'angular'], function($, angular) {
return undefined;
}

mod.run(['$rootScope', '$navigate', function($rootScope, $navigate) {
$rootScope.$navigate = function() {
var args = Array.prototype.slice.call(arguments);
args.unshift($navigate);
return navigateExpression.apply(this, args);
}
}]);

/**
* Helper function to put the navigation part out of the controller into the page.
* @param scope
*/
var navigateExpression = function(service) {
if (arguments.length === 2) {
// used without the test.
service(arguments[1]);
return;
}
// parse the arguments...
var test = arguments[1];
var outcomes = {};
var parts;
for (var i = 2; i < arguments.length; i++) {
parts = splitAtFirstColon(arguments[i]);
outcomes[parts[0]] = parts[1];
}
if (test && test.then) {
// test is a promise.
test.then(function(test) {
if (outcomes[test]) {
service(outcomes[test]);
} else if (outcomes.success) {
service(outcomes.success);
}
}, function(test) {
if (outcomes[test]) {
service(outcomes[test]);
} else if (outcomes.failure) {
service(outcomes.failure);
}
});
} else {
if (outcomes[test]) {
service(outcomes[test]);
} else if (test !== false && outcomes.success) {
service(outcomes.success);
} else if (test === false && outcomes.failure) {
service(outcomes.failure);
}
}
};

return navigate;

});
12 changes: 12 additions & 0 deletions src/main/webapp/jqmng/widgets/disabledHandling.js
Expand Up @@ -51,5 +51,17 @@ jqmng.define('jqmng/widgets/disabledHandling', ['jquery', 'angular'], function (
}
}
});

mod.directive('ngDisabled', function () {
return {
compile:function () {
return {
post:function (scope, element, attr) {
instrumentAttrSetter(element, attr);
}
}
}
}
});
}
);

0 comments on commit 184c272

Please sign in to comment.