Using Script # 0.7 with MVC 3 - asp.net-mvc-3

I'm trying to use Script# 0.7 with MVC 3 using the ScriptSharpSection and all that stuff.
So far I'm doing
#{ Ajax.InitializeScripts();
}
but I get the exception: "The referenced script named 'loader' was not registered in configuration as a script."
I can bypass that exception adding a <script name="loader" ... but I don't know that scripts has to do.
Is there any example showing how this is done?
Thanks.

I still need to get examples out.
Does your web.config have this:
<configSections>
<section name="scriptSharp" type="ScriptSharp.Web.Configuration.ScriptSharpSection, ScriptSharp.Web"
allowDefinition="MachineToApplication" requirePermission="false" />
</configSections>
...
<scriptSharp clientScriptStorageCookie="scripts">
<script name="loader" url="/Content/Scripts/ssloader.js" version="0.7" />
<script name="loader.debug" url="/Content/Scripts/ssloader.debug.js" version="0.7" />
<script name="core" url="/Content/Scripts/mscorlib.js" version="0.7" />
<script name="core.debug" url="/Content/Scripts/mscorlib.debug.js" version="0.7" />
<script name="jquery" url="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" />
<script name="jquery.debug" url="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js" />
</scriptSharp>
And do you have the ssloader.js script to go along with it?
The MVC APIs render out scripts that are then downloaded by the script loader while managing dependency order etc. For now it is required. Eventually I need to add couple of things:
Have a mode where this is not
required, i.e. it does the
dependency ordering on the server
and renders out vanilla script tags.
Have the ss.init/ss.ready callback
functionality implemented in
mscorlib.js as well, if someone is
only loading mscorlib.js and not
ssloader.js.
Hope that explains the current implementation and what will be added in the future to make ssloader.js optional.

Related

Firefox could not install the search engine from…

I'm trying to make APLcart work with OpenSearch, but keep getting Firefox could not install the search engine from: https://aplcart.info/opensearch.xml with:
<link rel="search" type="application/opensearchdescription+xml" title="APLcart"
href="/opensearch.xml">
Where /opensearch.xml is:
<OpenSearchDescription>
<ShortName>APLcart</ShortName>
<Description>
Search APLcart: A novel approach to finding your way in APL
</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16" type="image/x-icon">https://aplcart.info/favicon.ico</Image>
<Url type="text/html" template="https://aplcart.info/?q={searchTerms}"/>
</OpenSearchDescription>
Note that this is not the same issue, since I do have Url type="text/html".
I've tried with method="get"
What do I need to change for my OpenSearch specification to be compliant?
You have to use the correct namespace
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
If you open the browser console (CTRL+Shift+J) you can see the error message
Invalid search plugin due to namespace not matching.

Polymer iron-ajax/iron-request won't fire

I am trying to make a request using iron-ajax.
My code looks like this:
<link rel="import" href="../bower_components/iron-ajax/iron-ajax.html">
<iron-ajax
id="fetch"
url="myapi.com/resource"
method="GET"
content-type="application/json"
handle-as="json"
on-response="storeData"
debounce-duration="300" auto>
</iron-ajax>
I consistently get this error and have linked to the source below.
Uncaught TypeError: request.completes.then is not a function
https://github.com/PolymerElements/iron-ajax/blob/master/iron-ajax.html#L447
When I log the spawned iron-request object request.completes out to my console, I see the below object.
g
_callbacks: Object
_pendingCallbacks: Object
ctx: null
promiser: ()
__proto__ : Object
I am using the following versions, and polymer serve to run the app locally.
iron-ajax: 1.4.3
polymer: 1.7
The awful resolution to this is that I had a naming conflict. I use bloodhound.js in this project and recently switched from a manually downloaded file over to bower. The bloodhound registered on bower is NOT the library written by twitter. It is an entirely different, one-starred, zero-forked library, last updated in 2014 that happens to overwrite the Promise prototype at a global scope :(
Thanks to all for your consideration and help!

Master page throws error when code is inserted

I have a master page that throws an error on content pages when the following line of code is inserted into the master page. It will not let me enter design mode.
<script src='<%= CacheHelper.Fingerprint("/assets/scripts/app.min.js") %>' />
However, the following line of code doesn't throw an error. I've tweaked the quotes, added a type etc, but it still refuses to play ball.
<link rel="stylesheet" href='<%= CacheHelper.Fingerprint("/assets/styles/app.min.css") %>' />
I'm using VS2010.
After trawling, trying and testing for a few hours I can categorically say that 99% of the answers to similar questions do not work.
The answer I found that did work was to replace the end tag '/> with '></script>' - after this Visual Studio started behaving.

How to implement message passing in Firefox extension?

I have a file which overwrites overlay.xul that overwrites browser.xul. I want to implement message passing in a similar way as implemented in chrome extensions.
chrome.manifest-
content helloworld content/
overlay chrome://browser/content/browser.xul chrome://helloworld/content/overlay.xul
overlay chrome://navigator/content/navigator.xul chrome://helloworld/content/overlay.xul
skin helloworld classic/1.0 skin/
style chrome://global/content/customizeToolbar.xul chrome://helloworld/content/overlay.css
How to I register content_script.js which in my case is overlay.js?
Overlay.xul -
<script type="application/x-javascript" src="chrome://helloworld/content/jquery.js" />
<script type="application/x-javascript" src="chrome://helloworld/content/overlay.js" />
<script type="application/x-javascript" src="chrome://helloworld/content/background.js" />
Now inside my overlay.js I'm using -
document.documentElement.addEventListener('click', function(e) {
messageManager.sendAsyncMessage('MyMessenger.MyMessage', {});
}, true);
And the background.js is-
addMessageListener("MyMessenger.MyMessage", function(obj) {
Firebug.Console.log(obj.name);
}, true);
What is the correct syntax for message passing?
How do I configure the connection between content script and browser script?
If all you are interested in is really injecting a content script and communicating with it then it should be easier to use the Add-on SDK, particularly the page-mod package. It allows injecting content scripts easily and provides a way to communicate (see "Communicating With Content Scripts" section in the docs I mentioned).
As to messageManager, it is meant for a multi-process environment but it will work in the current single-process Firefox as well. The main problem with your code above is: addMessageListener isn't a global function, you should call messageManager.addMessageListener(). But using messageManager to pass messages between scripts that are loaded into the same namespace and could call each other directly is an overkill anyway.
To communicate with a content script in the current tab the script in the overlay would do:
gBrowser.selectedBrowser.messageManager.sendAsyncMessage('MyMessenger.MyMessage', {});
And the content script would indeed have addMessageListener as a global function so this should work:
addMessageListener("MyMessenger.MyMessage", function(obj) {
console.log(obj.name);
});

Simple ajax/prototype problem

im beginning with Ajax, i have problem with including Ajax files.
Ajax code written in original page (like index.php) and placed in (head) section works fine, but when i try to place code in external file (in js folder, where is placed prototype.js file), i don't get any response, not even in Firefox Error Console.
I haven't changed Ajax code except url for calling PHP function.
edit:
calling ajax files:
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/myValidation.js"></script>
</head><body>
....
Username: <input type="text" name="uname" id='uname' />
Available?
<span id="result"></span>
Email address: <input type="text" name="email" />
...
I embaded this function call in html. Validate function is from book "PHP and Script.aculo.us Web 2.0 app interfaces"
myValidation.js
function Validate(){
var user=$('uname');
var name="uname="+user.value;
var pars=name;
new Ajax.Request(
'myValidation.php',
{
method:'post', parameters:pars, asynchronous:true, onComplete: showAvailable
}
);
}
function showAvailable(originalRequest){
var newData=originalRequest.responseText;
$('result').innerHTML=newData;
}
This example is from mentioned book
You haven't shown us your myValidation.js file, but here are the typical reasons I see when people move from inline script blocks to external files and things stop working:
They put script blocks in the external JavaScript files. You probably didn't do that, but I've seen it often enough to mention it. Your external script is pure JavaScript, so for instance it should be:
function Validate() {
// ...
}
not:
<script type='text/javascript'>
function Validate() {
// ...
}
</script>
I've seen the latter a fair bit.
They put the JavaScript file in a location that doesn't match their script tag src.
They left an opening <!-- or closing --> in the script. Important not to do that, in external JavaScript files those are syntax errors.
They're using a web server that's case sensitive and the src attribute and the file's actual name don't match.
They're using a web server sensitive to permissions and the file doesn't have the right permissions.
In the case of the last two above, it's easy to check: Just open a new tab and actually enter the URL of the JavaScript file. If you see the JavaScript, great; if not, you probably have more information.
For issues like this (and hundreds of others), there's nothing like having a decent toolset. For debugging JavaScript on browsers, there are quite a few. There's Firebug (a Firefox add-in), Chrome's and Safari's Development Tools (built into the browsers), Microsoft Visual Studio or Script Debugger for debugging with IE, etc. Firebug and Dev Tools would both tell you about broken src links, as well as any exceptions, etc.
Have you checked that those files are accessible from the HTML code? And more - have you placed you scripts in the bottom of the page - because AJAX will bind it's handlers only to existing elements?
Problem solved.
In /js/ folder i had one php file, that i put there just because of simplicity. After moving it to other location all worked. Don't know if that is rule, nut no php files in /js/ folder. Thanks T.J and Tomasz

Resources