Get the hostname with action script 2 - actionscript-2

I am creating some campaign swf banners and I don't use action script very often so any help from the experts would be great thanks.
I am supplying my banners on my website as resource downloads. And tutorials of how to embed the swf which has some javascript flashvars.
These flash variable is then concatenated into a google campaign link to change the utm_source.
This is my javascript...
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
<script type="text/javascript">
var flashvars = {};
flashvars.campaignSource = window.location.hostname;
var params = {};
params.loop = "true";
params.quality = "best";
params.wmode = "opaque";
params.swliveconnect = "true";
params.allowscriptaccess = "always";
var attributes = {};
swfobject.embedSWF("banner.swf", "banner_mpu", "300", "250", "9.0.0", false, flashvars, params, attributes);
</script>
and my html...
<div id="banner_mpu">
<a href="http://www.adobe.com/go/getflashplayer">
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
</a>
</div>
So the above js works great, however, not everyone will use my tutorial code and will probably use there own methods to embed the swf banner on their site.
So I need some back up action script 2 to get the current hostname into a action script variable
This is my action script which I have so far on my button (swf)...
on(release) {
function GetTheHostname() {
var RootFullUrl = _root._url;
txtFullUrl.text = RootFullUrl;
var lastSlashIndex:Number = RootFullUrl.lastIndexOf("/");
var DriveIndex:Number = RootFullUrl.indexOf("|");
if (DriveIndex>=0) {
baseUrl = RootFullUrl.substring(0, DriveIndex);
baseUrl += ":";
} else {
baseUrl = "";
}
baseUrl += RootFullUrl.substring(DriveIndex+1, lastSlashIndex+1);
txtBaseUrl.text = baseUrl;
return baseUrl;
}
var campaignSourceAS2:String= GetTheHostname();
if ( _root.campaignSource == undefined ) {
getURL("http://www.mysite.co.uk/?utm_source=" + campaignSourceAS2 + "&utm_medium=MPU&utm_campaign=My%20Campaign%202012", "_blank");
} else {
getURL("http://www.mysite.co.uk/?utm_source=" + _root.campaignSource + "&utm_medium=MPU&utm_campaign=My%20Campaign%202012", "_blank");
}
}
The problem with my action script is that it returns the full current URL.
Can any one please help me adapt the GetTheHostname function to get the host name instead of the baseURL
Thanks in advance

In that case, I guess it would be as easy as stripping the http:// from the url and then get all that's left to the first /
A one-liner to go from 'http://www.example.com/category/actionscript' to 'www.example.com' would be
var baseURL:String = _root._url.split("http://").join("").split("/")[0];
and to replace your full method
getURL("http://www.mysite.co.uk/?utm_source=" + (_root.campaignSource || _root._url.split("http://").join("").split("/")[0]) + "&utm_medium=MPU&utm_campaign=My%20Campaign%202012", "_blank");

Related

Using document.getElementsByClassName in Testcafe

I have a menu that always has the same structure, but the IDs can change from one installation to another. the only thing that stays the same is the heading (in my case "Plugins"). I call the document.getElementsByClassName function with a Selector inside my test:
var slides = Selector(() =>{
return document.getElementsByClassName("c-p-header-text");
});
Every heading of an menu element has the c-p-header-text class. Here is what a menu heading element looks like:
<div id="ext-comp-1002" class="c-p c-tree c-p-collapsed" style="width: auto;">
<div class="c-p-header c-unselectable c-accordion-hd" id="ext-gen135" style="cursor: pointer;">
<div class="c-tool c-tool-toggle" id="ext-gen140"> </div>
<img src="/backEnd/images/s.gif" class="c-p-inline-icon order"><span class="c-p-header-text" id="ext-gen150">Plugins</span>
</div>
It would be easy to use await t.click("#ext-gen150") but it is not safe that it is always this id.
here is what i tried:
await t
.click('#sites__db');
var slides = Selector(() =>{
return document.getElementsByClassName("c-p-header-text");
});
console.log("[DEBUG]" + slides);
console.log("[DEBUG] found " + slides.length + " elements");
for(var i = 0; i < slides.length; i++)
{
var txtOfCurrElem = slides.item(i).innerText;
console.log("[DEBUG "+ i +"] Text: " + txtOfCurrElem);
}
Running this test give me the following output:
[DEBUG]function __$$clientFunction$$() {
var testRun = builder.getBoundTestRun() || _testRunTracker2.default.resolveContextTestRun();
var callsite = (0, _getCallsite.getCallsiteForMethod)(builder.callsiteNames.execution);
var args = [];
// OPTIMIZATION: don't leak `arguments` object.
for (var i = 0; i < arguments.length; i++) {
args.push(arguments[i]);
}return builder._executeCommand(args, testRun, callsite);
}
[DEBUG] found 0 elements
The plan is to find the element (with the heading "Plugins") and then click on it when the test continuous.
You don't have to use document.getElementsByClassName in this case. You can just use CSS class selector instead:
var slides = Selector('.c-p-header-text');
You should use the count property when dealing with an array of Selectors. docs. Also, element properties, like exists, count, and DOM node state properties are Promisified, so when you use them not in t.expect, you should use the await keyword:
var count = await slides.length;
console.log("[DEBUG] found " + count + " elements");
for(var i = 0; i < count; i++)
{
var txtOfCurrElem = await slides.nth(i).innerText;
console.log("[DEBUG "+ i +"] Text: " + txtOfCurrElem);
}
I found a simple answer to my question. I use the .withText option to click on the Plugins element:
.click(Selector('span').withText("Plugins"))
Since this name is also unique, it is always the correct element that gets clicked. I do not know if it would have worked with the solution from #AndreyBelym if my site is not an extJS web application.

Janrain widget does not show expected providers

I have a basic Janrain account where I have configured about 8 providers successfully. From the Widgets & SDKs section, I have also selected six providers to be shown on the widget. I have enabled Janrain integration on on Social Engine 4.8.12. However, the Janrain widget only shows only 3 default providers on my SocialEngine website's log-in page. Does anyone know how to fix this?
This is what I have designed and expect to see:
This is what I see on the login page:
The Janrain Social Login(Engage) widget has two main ways to configure the display of social providers. These are shown in the following screen shot:
The first option "Save and Publish" will save the settings to the Janrain CDN. The warning at the bottom states "Changes may take up to one hour to appear in deployed widgets" - however it typically (but not always) does not take more than 5 minutes. It is important that you actually click the "Publish" button in order to save these settings.
The second option is "Save and Embed" it will generate the necessary Javascript code that you can embed on a web page to use the widget. Similar to the following:
<script type="text/javascript">
(function() {
if (typeof window.janrain !== 'object') window.janrain = {};
if (typeof window.janrain.settings !== 'object') window.janrain.settings = {};
/* _______________ can edit below this line _______________ */
janrain.settings.tokenUrl = '__REPLACE_WITH_YOUR_TOKEN_URL__';
janrain.settings.type = 'embed';
janrain.settings.appId = 'REPLACE_WITH_YOUR_APP_ID';
janrain.settings.appUrl = 'https://APPNAME.rpxnow.com';
janrain.settings.providers = [
'facebook',
'linkedin',
'googleplus',
'twitter',
'instagram',
'paypal_openidconnect',
'yahoo',
'microsoftaccount'];
janrain.settings.providersPerPage = '8';
janrain.settings.format = 'two column';
janrain.settings.actionText = 'Sign in using your account with';
janrain.settings.showAttribution = true;
janrain.settings.fontColor = '#333333';
janrain.settings.fontFamily = 'arial';
janrain.settings.backgroundColor = '#FFFFFF';
janrain.settings.width = '380';
janrain.settings.borderColor = '#CCCCCC';
janrain.settings.borderRadius = '10'; janrain.settings.buttonBorderColor = '#CCCCCC';
janrain.settings.buttonBorderRadius = '5';
janrain.settings.buttonBackgroundStyle = 'gradient';
janrain.settings.language = '';
janrain.settings.linkClass = 'janrainEngage';
/* _______________ can edit above this line _______________ */
function isReady() { janrain.ready = true; };
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", isReady, false);
} else {
window.attachEvent('onload', isReady);
}
var e = document.createElement('script');
e.type = 'text/javascript';
e.id = 'janrainAuthWidget';
if (document.location.protocol === 'https:') {
e.src = 'https://rpxnow.com/js/lib/APPNAME/engage.js';
} else {
e.src = 'http://widget-cdn.rpxnow.com/js/lib/APPNAME/engage.js';
}
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(e, s);
})();
</script>
You can see in the above code how the providers are listed as a Javascript array.
If neither of these options work then there may be something wrong with your apps configuration and you should contact Janrain's support for assistance at http://support.janrain.com

SharePoint 2010 Wiki Template Script Issue

I'm looking for a way to give my SharePoint users a way to create new wiki pages from an existing template. In the process of researching I found a great walkthrough that seems to fit the need (http://www.mssharepointtips.com/tip.asp?id=1072&page=2), but I'm having trouble getting it to work. The problem seems to lie in the assignment of a path to PATHTOWIKI-- if I use "/Weekly Update Wiki", the script returns an error of "There is no Web named '/Weekly Update Wiki'." If I use "Weekly Update Wiki" without the forward slash, I instead get an error of "There is no Web named '/sites/[parentSite]/[childSite]/Weekly Update Wiki/Weekly Update Wiki'."
Any ideas about what I'm not understanding here?
function myCreateProject() {
// Configure these for your environment
// include no slashes in paths
var PATHTOWIKI = "Weekly Update Wiki";
var PATHTOPAGES = "Pages";
// file name only for template page, no extension
var TEMPLATEFILENAME = "Template";
var myPathToWiki = encodeURIComponent(PATHTOWIKI);
var myPathToPages = PATHTOPAGES + "%2f";
var myTemplateFileName = encodeURIComponent(TEMPLATEFILENAME) + "%2easpx";
var EnteredProject = document.getElementById("NewProjName");
var myNewName = EnteredProject.value;
if(myNewName == "") {
alert('Please enter a name for the new project page');
} else {
myNewName = encodeURIComponent(myNewName) + "%2easpx"
$.ajax({
url: PATHTOWIKI + "/_vti_bin/_vti_aut/author.dll",
data: ( "method=move+document%3a14%2e0%2e0%2e4730&service%5fname="
+ myPathToWiki +
"&oldUrl=" + myPathToPages + myTemplateFileName +
"&newUrl=" + myPathToPages + myNewName +
"&url%5flist=%5b%5d&rename%5foption=nochangeall&put%5foption=edit&docopy=true"
),
success: function(data) {
var rpcmsg1 = getMessage(data, "message=", "<p>");
$("#myInfo").append("<br />" + rpcmsg1);
if(rpcmsg1.indexOf("successfully") < 0) {
// get error info
var rpcmsg2 = getMessage(data, "msg=", "<li>");
$("#myInfo").append("<br />" + rpcmsg2 + "<br />");
} else {
$("#myInfo").append("<br />Go to new page<br />");
}
},
type: "POST",
beforeSend: function(XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("X-Vermeer-Content-Type",
"application/x-www-form-urlencoded");
}
});
}
}
Update: I figured out what needed to happen in my case. Since I couldn't get a grasp on the relative approach, I just went with the absolute path for PATHTOWIKI and slightly modified the append in the ajax call.
PATHTOWIKI:
var PATHTOWIKI = "https://[domain]/sites/[parentSite]/[childSite]";
append:
$("#myInfo").append("<br />Go to new page<br />");
The change in the latter line of code is subtle; since I used an absolute path in PATHTOWIKI, I just removed the leading forward slash in the anchor tag, so that <a href=\"/" became <a href=\"". This renders the script slightly less portable, but since it's a one-off effort I'll stick with this unless anything comes along to expand the scope.

apache rewrite all hash tag to slash tag under one directory

How to rewrite all hash tag to slash tag under one directory? (apache)
http://www.domain.com/company/index#about => http://www.domain.com/company/index/about
http://www.domain.com/company/article#123456 => http://www.domain.com/company/article/123456
http://www.domain.com/company/events#October => http://www.domain.com/company/events/October
So, all the pages witch in /company/, rewrite # => /.
$(window).on('hashchange', function() {
//
}
In general all the browsers exclude the fragment part (#) from the request to the server. If you really want do it, you must rewrite the urls before call the server
function addHashtag2Pathname(url){
var a = document.createElement('a');
a.href = url;
if (a.pathname.substr(-1) != "/")
a.pathname = a.pathname + '/';
a.pathname += a.hash.replace(/^#/,'');
a.hash = '';
return a.href.replace(/#$/,'');
}
You can see this function in action here
http://jsfiddle.net/bknE4/43/
Actually I haven't tried this below, but it should work...
$(window).on('hashchange', function() {
var newurl = addHashtag2Pathname(location.href);
location.href = newurl;
})
If you navigate your web browser to http://www.domain.com/company/events#October, it will fetch the URL http://www.domain.com/company/events from the server. The server does not see the rest of the URL and can do nothing with it. Only Javascript can act on it.
$(window).on('hashchange', function() {
var a_tags = document.getElementsByTagName('a');
for (var i = 0; i < a_tags.length; i = i + 1) {
var elem = a_tags[i];
if (/company.*#/.test(elem.href)){
elem.href = elem.href.replace('#', '/');
}
}
}
You might want to change the regexp in the if conditional to be more specific.
The same for the replace function.
However I would change the HTML server side instead if it is supposed to be permanent.

Backup Bookmarklet Code

Hi i have bookmarklet code to load a scripts from a mirrored backup location if my main hosting goes down, it works but i want to know the best way to do this as i know the current way i am doing it is probably not the best way.
(this is a example of my backup bookmarlet code expanded)
javascript: (function () {
var scriptname = 'testscript';
function checkServerStatus() {
var v = setTimeout(function () {
loadscript('backupserver.hardiman.co.nz')
}, 4500);
var a = document.body.appendChild(document.createElement('img'));
a.onload = function () {
clearTimeout(v);
loadscript('screepts.com')
};
a.src = 'http://screepts.com/ping.gif?' + Math.random();
}
checkServerStatus();
function loadscript(b) {
var a = document.createElement('script');
a.type = 'text/javascript';
a.src = 'http://' + b + '/bm/' + scriptname + '.js?' + Math.random();
document.getElementsByTagName('head')[0].appendChild(a)
}
})();`
And this is it wrapped up as a bookmarklet :
Test Script
Any help or advice on loading a script from a backup server would be greatly appreciated..
Okay sorry i should have been more specific on the question. Since my hosting went down i was able to test the above code properly. I think the only thing i need to do is parse what server was loaded to the script.