Swipelistener not working on menu - swipe

I am using jqMobi, ( NOT jQuery Mobile ).
I am trying to get a swipelistener to work on the menu. Basically I just want to 'swipe' the menu open or closed with a horizontal swiping motion. Here is my js:
$.ui.ready(function () {
. . . . .
$(window).swipeListener({
vthreshold: 50,
hthreshold: 70,
callBack: function (dir) {
if (dir.right) {
$.ui.toggleSideMenu(true);
}
if (dir.left) {
$.ui.toggleSideMenu(false);
}
}
});
});
This works great except for when I 'swipe' on this red part here -->
If I swipe anywhere else, it works fine. I have also tried to use the document selector, that also didn't work. I tried to add another swipelistener to the #menu and #menu_scroller as well.
This is very difficult for me to debug as my device is IOS6 and the "Debug Console" has been removed, so I can't just add a ton of console logging. ( I don't have a Mac, so I can't hook up the Developer Menu )
My theory is that since there are ontouchstart and ontouchend listeners on the menu items that this is interfering with my swipelistener. Any suggestions?

The swipeListener is being deprecated. Instead, there are events dispatched by jqUi [swipe,swipeLeft,swipeRight,swipeUp,swipeDown] that you can bind. The listeners you have for ontouchstart/ontouchend could be killing the event from propegating up though (are they custom listeners?)
$.ui.ready(function(){
$(document).bind("swipeLeft",function(){
$.ui.toggleSideMenu(false);
});
$(document).bind("swipeRight",function(){
$.ui.toggleSideMenu(true);
});
}

Related

Check if shortcut is present on homescreen as in normal mobile apps

I am trying to get the user to 'install' the shortcut icon to a webpage and use it as an icon to the PWA.
I am wondering if any of you had a chance to somehow discover if the user installed the shortcut on home screeen?
This is an interesting case, because when developing on Android or such one has access to such information, on the other hand I don't recall browser giving that information away.
The beforeinstallprompt will only fire if the user has NOT installed the PWA
First: Use that to check if installed
window.addEventListener('beforeinstallprompt', (e) => {
// If you get inside here, the PWA is not installed
});
Example code here
https://developers.google.com/web/fundamentals/app-install-banners
Second: If you are showing your own deferred prompt like the examples at the link above, you can listen to know if they close that without adding to home screen (A2HS)
// Wait for the user to respond to the prompt
this.deferredPrompt.userChoice
.then((choiceResult) => {
if (choiceResult.outcome === 'accepted') {
// User said yes to your A2HS
} else {
this.deferredPromptRejected = true;
}
});
Third: You can check if your PWA is running as a standalone
function isRunningStandalone() {
return (window.matchMedia('(display-mode: standalone)').matches);
}

Protractor - Unable to access element due to fixed Top navigation bar

I'm facing the following issue in protractor with jasmine
Click/mouse hover not working because of fixed top navigation bar in my application. I need to click/perform mouse hover on a web page.
Unfortunately that element is displaying behind that fixed navigation bar. So scroll till element present & click by x & y coordinates are not working.
My dependencies are :
protractor version 5.2.2
node 8.9.3
selenium standalone 3.13
chrome driver-2.40
chromebrowser v67
OS- Windows 10
Thanks in advance
Try using prototype executeScript
Just try clicking that element from the browser console using id,name or xpath.
For example :
var el = element(by.module('header'));
var tag = browser.executeScript('return arguments[0].click()', el).then(function() {
expect(something).toMatch(something);
});
Another way, along the same lines as what Bharath Kumar S and knowing JeffC's caveat that this approach is cheating, I had a similar issue where the App-Header kept getting in my way of clicking, and I knew I was willing to never need it (so, for instance, to find other ways to navigate or log out and not check for stuff that was on it). I, therefore, did the following, which solved the problem. Note if you refresh the screen, you have to call it again. Also note I am using a number of functions from https://github.com/hetznercloud/protractor-test-helper, which do what you would expect from their names.
var removeAppHeaderIfAny = async function() {
//this function hides the app header
//it is useful to avoid having covers there when Protractor worries that something else will get the click
let found = false;
try {
found = await waitToBeDisplayed(by.className("app-header"), 2000);
} catch (e) {
let s: string = "" + e;
if (s.search("TimeoutError") != 0) flowLog("presumably fine, cover already removed: " + e);
found = false;
}
if (!found) return;
if (found) {
let coverElement = await element(by.className("app-header"));
browser.executeScript(
"arguments[0].style.visibility='hidden';",
coverElement
);
await waitToBeNotDisplayed(by.className("app-header"), 10000);
}
return;
//note after this is called you will not see the item, so you cannot click it
};
As I look at the code, it strikes me one can probably remove the if (found) and associated brackets at the end. But I pasted in something I know has been working, so I am not messing with that.
As indicated up front, I knew I was willing to forego use of the app-header, and it is a bit crude.

leaflet no internet detection and notification

If for example, my wifi goes offline, in leaflet i see new map areas grey but no notification about what really happening.
if i open the console i see:
GET https://a.tiles.mapbox.com/v4/image.png?access_token=correct_token
net::ERR_INTERNET_DISCONNECTED
anyone knows a way to catch such events and displaying a custom warning?
I already tried catching:
$scope.$watch('tileerror', function (error, tile) {
alert("No coonection");
});
p.s. using angular-leaflet-directive
EDIT: as pointed out by Ghybs in the comments there is indeed a tileerror event firing from L.TileLayer, however as far as i can see it's not implemented in Angular Leaflet Directive, please correct me if i'm wrong.
L.TileLayer does have an option for setting a replacement image when the tile cannot be loaded called: errorTileUrl:
URL to the tile image to show in place of the tile that failed to load.
new L.TileLayer(URL, {
errorTileUrl: 'error.png'
});
http://leafletjs.com/reference.html#tilelayer-errortileurl
If you need to preform some logic when tiles fail to load you could overwrite L.TileLayer's _tileOnError method:
L.TileLayer.include({
_tileOnError: function (done, tile, e) {
// Do your stuff
alert('whooops!');
// Leaflet stuff
var errorUrl = this.options.errorTileUrl;
if (errorUrl) {
tile.src = errorUrl;
}
done(e, tile);
}
});
https://github.com/Leaflet/Leaflet/blob/master/src/layer/tile/TileLayer.js#L96

Drupal - magnific popup only works when logged in

I am using magnific popup JS (http://dimsemenov.com/plugins/magnific-popup/) to produce a popup for a youtube video on my Drupal site. The implementation works fine, but only if I am logged into Drupal. If I am not logged in, the popup link will just go the the youtube page (eg jQuery not initialising).
I suspect there may be something going on with Drupal loading a different version of jQuery when I am logged in. It seems that I may be able to add something to my template file to fix this. Haven't figured it out yet (https://www.drupal.org/node/2165555)
I do not have access to add jQuery update module.
Fixed. Added below snippet to template.php to force a later version of jQuery to load.
function theme_name_js_alter(&$javascript) {
$node_admin_paths = array(
'node/*/edit',
'node/add',
'node/add/*',
'node/*/extend_review_date',
);
$replace_jquery = TRUE;
if (path_is_admin(current_path())) {
$replace_jquery = FALSE;
} else {
foreach ($node_admin_paths as $node_admin_path) {
if (drupal_match_path(current_path(), $node_admin_path)) {
$replace_jquery = FALSE;
}
}
}
// Swap out jQuery to use an updated version of the library.
if ($replace_jquery) {
$javascript['misc/jquery.js']['data'] = '//code.jquery.com/jquery-1.7.0.min.js';
}
}

How can I use AngularJS data binding with CKEditor?

How should I go about this?
I was able to get the data into CKEditor by using a textarea with the name attribute matching my model and a script tag with ng:bind-template to call CKEDITOR.replace.
I then made a CKEditor plugin that detects changes and writes them back to the textarea. The problem is that the textarea looses its event handlers when CKEditor initializes and CKEditor doesn't pickup changes to the textarea. This makes me think that I am approaching this the wrong way.
Next I tried using ng:eval-order="LAST" ng:eval="setupCKEditor()" and setting up the editor from the setupCKEditor() function. This didn't work because even with ng:eval-order="LAST" the function is still run before the nodes are created.
I have found that adding a setTimeout(function () {...},0) around the CKEDITOR.replace helps. Now the only problem is that when it changes the model it doesn't repaint the screen until another field is edited.
scope.$root.$eval(); seems to fix that.
Update
We ended up abandoning this since we could never get it to reliably work. We switched to TinyMCE with Angular-UI for a while and then ended up building something custom.
This sort of works with the onchange plugin from http://alfonsoml.blogspot.com/2011/03/onchange-event-for-ckeditor.html.
angular.directive("my:ckeditor", function (expression, compiledElement) {
return function fn(element) {
var scope = this;
setTimeout(function () {
CKEDITOR.replace("editor-" + index, {extraPlugins: 'onchange'});
scope.$watch("layers[" + index + "].src", function () {
if (!CKEDITOR.instances["editor-" + index]) return;
if (scope[expression] == CKEDITOR.instances["editor-" + index].getData()) return;
CKEDITOR.instances["editor-" + index].setData(scope[expression]);
});
CKEDITOR.instances["editor-" + index].on("change", function () {
scope[expression] = CKEDITOR.instances["editor-" + index].getData();
scope.$root.$eval();
});
}, 0);
};
});
Update
This has only been tested on v0.10.6
For completeness, attached is a module to provide an angular directive. I've not used it yet, so I can not comment on how well it works/integrates.

Resources