ClojureScript extern 'on' event - google-closure-compiler

I'm trying to use Twitter Bootstrap's modal dialog jQuery plugin with ClojureScript, which works fine without advanced optimizations, but when Google Closure munges method names, the on method becomes za.
I've been trying to protect on from being munged by using an externs file, but so far no luck creating a definition that fixes this. Tips?

What finally worked was:
var jQuery;
jQuery.fn = {
on: function() {}
};

with advanced you can either use goog.exportSymbol or window['object']['on'] = object['on']

Related

Using `within` in custom helpers

I'm using CodeceptJS and I'm trying to write a custom helper that asserts an text and clicks "OK". This dialog pops up as a iframe modal to consent with cookies.
If I write following steps in my scenario
I.amOnPage('/some-path');
within({frame: '#iframeID'}, () => {
I.see('Headline text for dialog');
I.click('OK');
});
// ...
...my test seems to work just fine.
But when I make an custom helper out of that and configure it properly so I can use it:
const { Helper } = codeceptjs;
class CookieConsent extends Helper {
consentWithCookies() {
const { Puppeteer } = this.helpers;
within({frame: '#iframeID'}, () => {
Puppeteer.see('Headline text for dialog');
Puppeteer.click('OK');
});
}
}
module.exports = CookieConsent;
...and use it as a step:
I.amOnPage('/some-path');
I.consentWithCookies();
// ...
...it doesn't seem to work as the consent dialog doesn't get clicked away as it was when implementing this directly in the scenario. According to some console.log() debugging the within callback doesn't get called at all. Console doesn't throw any errors about undefined within or anything suspicious.
I suspect that using within in a custom helper isn't working or I'm doing something wrong that I can't figure out from the documentation.
This warning at documentation doesn't really clarify when within is being used incorrectly, and using await doesn't help the problem.
within can cause problems when used incorrectly. If you see a weird behavior of a test try to refactor it to not use within. It is recommended to keep within for simplest cases when possible. Since within returns a Promise, it may be necessary to await the result even when you're not intending to use the return value.
iFrames can be a pain to work without when it comes down to automation. There are a number of factors that can make an iFrame unreachable to a framework such as cross-domain iFrames, commonly used for increased security on the content served.
Now to fix your issue, all you have to do is use switchTo() - Docs in CodeceptJS which is a function available for all helpers made available. The order should be
I.switchTo('your iframe');
..... some actions here;
I.switchTo(); // You do this so that you get out of the iFrame context when done

Adding keyup action to iframe of version of niceEdit

I am using nicEdit in its iframe format.Everytime the user write anything in the editor(keyup event), I need to run another js/jquery function. How to add this custom keyup action to the desired iframe?
The answer actually lies in the js code. In the nicEdit.js search for :
var nicEditorIFrameInstance = nicEditorInstance.extend({
Inside this, in the initFrame function,
look for this.frameDoc.addEvent.
This is where the events are being added(via addEvent). To this include your keyup statement :
addEvent('keyup',this.YOURFUNCTIONAME.closureListener(this))
You need to add closureListener(this) to get this working.Then create YOURFUNCTION after initFrame function like this :
YOURFUNCTIONAME: function() {
//Do what you like. Probably call any JS function that lies in the file where
//you have included the nicEdit.js
},
This method worked for me. Hope it does for you too. nicEdit is by far the worst documented third party stuff I have ever come across.

Drupal7 - Adding jQuery plugin in a block

I added the jQuery plugin smoothdivscroll to a block, it's works though it is not good to hard code all stuff to the block. I found that Drupal have already called jQuery core file in each page, but why the smoothdivscroll can't getting works if I don't add the jQuery core file AGAIN in the block?
It's because stock Drupal 7 runs jQuery in no conflict mode.
If you want to use it you'll have to either replace your $() calls with jQuery() calls, or wrap it in a function like this:
// We define a function that takes one parameter named $.
(function ($) {
// Now use jQuery with the $ shortcut again like you normally would
$('#content').hide();
// Here we immediately call the function with jQuery as the parameter.
}(jQuery));
In your case you'll want to call your smoothdivscroll functions from inside this function.

Drupal jQuery noConflict - working for alert by not css change

Im using the jQuery noConflict method here:
http://drupal.org/node/1058168
Now, both of the following work:
$jq("document").ready(function(){
alert('alert');
});
$("document").ready(function(){
alert('alert');
});
However this does work:
$("document").ready(function(){
$(".view-product-slideshow .pager-num-1 img").css("display","none");
});
But this does not:
$jq("document").ready(function(){
$jq(".view-product-slideshow .pager-num-1 img").css("display","none");
});
Ive used the noConflict method once before and it worked fine. Ive no idea why it would work for the alert but not the CSS change.
My site is here:
http://smartpeopletalkfast.co.uk/pp4/shop/baby-essentials/sleepsuit-plush
Thanks
UPDATE - Ive now removed the extra code from script.js so all thats there is:
//Hide thumnail on product page thats being used as main image
$jq("document").ready(function(){
$jq(".view-product-slideshow .pager-num-1 img").css("display","none");
});
your error is on line 61 of ur script.js:
Uncaught TypeError: Object #
has no method 'smoothDivScroll'
also in that file u should have everything wrapped in the .ready() not every individual thing
Turns out the element I was trying to target with jQuery was itself generated by javascript. Changing my document.ready to window.load fixed this.
When using the noconflict mode of jQuery, you should use this:
jQuery(document).ready(function($){
$(".view-product-slideshow .pager-num-1 img").css("display","none");
});
jQuery is the new $ and you can pass jQuery as $ to your function().
Also, it's document and not "document"

Why can't I get value fckeditor. done after their code example [Javascript]

I wonder why I can't get value from FCKEditor with this javascript? I work with asp.net so I know the controls get different names, mine is in a placeholder and in a usercontrol. How should I approach it to find the FCKEditor?
thx
function test()
{
var oEditor = FCKeditorAPI.GetInstance('FCKeditor1');
var pageValue = oEditor.GetHTML();
alert(pageValue);
}
This should work, but the problem is that using this approach you can not have this function in external JavaScript file. It has to be inline in your asp.net page.
function test()
{
var oEditor = FCKeditorAPI.GetInstance(<%= FCKeditor1.ClientID%>);
var pageValue = oEditor.GetHTML();
alert(pageValue);
}
FCKeditorAPI.GetInstance('<%=FCKeditor1.ClientID%>')
ASP.NET generates different IDs to the ones you use based on their position within the DOM. You should use the ClientID from within the client code to get at the actual ID, but without seeing the mark-up I can't tell for sure.
i tried this code an it work
FCKeditorAPI.GetInstance('ctl00_ContentPlaceHolder1_ctl00_FCKeditor1');
i tried
FCKeditorAPI.GetInstance('<%=FCKeditor1.ClientID%>')
thing that last wont work cause i got page - usercontrol - fckeditor
so the intellesence wont show the fckeditor. i would like to make it work with the last one
so i dont have to put the "ctl00_ContentPlaceHolder1_ctl00_FCKeditor1"

Resources