How do you include a JavaScript file from within a SharePoint WebPart? - sharepoint

We have a medium sized .js file that we include in our web framework that I am porting over to SharePoint. However, I'm not sure how to go about this or what the best practice is. This is for a framework solution that will be used by other client projects, so it's best for it to be self contained and deploy-able, rather than requiring manually deploying files to the webserver.
My current thinking to put the JavaScript into an embedded resource and then use the script manager to write out the file. Does this seem reasonable? Or does anyone have any other recommendations?

Embeded resource is the best way and you don't need to use the ScriptManager to render it out (as AJAX is not configured OoB on SharePoint), you can just render it as any other client script resource (through the ClientScriptManager).
Best idea is the have an if ContainsScriptManager else UsClientScriptManager style.
That way you get the best of both worlds

You could just toss it into a doc library.
If you are packaging your web part into a sharepoint solution, you could include it as a Module (VSEWSS item). Your manifest file would get something like:
<TemplateFiles>
<TemplateFile Location="LAYOUTS\somescript.js" />
</TemplateFiles>
Theres lots of info on how to do this on the web. I've liked the doc library option for images, css, and javascript because I don't have to rebuild and wait for for SP to JIT compile for 30 seconds each time I do a minor tweak to some style or script. I just edit these things in SPDesigner right out of the doc library.

Create resource mapped folder in your project and put the js file there and give the referene of the js file as _layout/jsfilename.js and this js file will be deployed with your project where ever you will deploy it.

Related

Templatize a file using nodejs

I have a requirement where i have a config file which has a bunch of properties. The user has to download the property file from the server using a browser. Some of these properties have to be changed based on the user's input and then the file has to be downloaded. This basically fits the perfect description of having templates and then at run time generating a file by replacing the properties provided by the user. How can i achieve this using node js. Any pointer will be deeply appreciated. Please pardon my limited knowledge of MEAN stack.
Template engines are a common thing and it's quite easy to use one with express.
I suggest you start with the docs on using template engines with express. They also have a wiki entry with a list of available engines.
Most template engines are meant to generate HTML, if you want to output something else (even plaintext) it can be a bit tricky sometimes.
Otherwise the choice mainly depends on what your familiar with. I can recommend Mozilla Nunjucks.

how to start using the framework foundation for sites and deploy the first project

I want start using the framework foundation for sites but after reading the DOCS (http://foundation.zurb.com/sites/docs/installation.html) I got confused:
Why I should use a package manager to download a bunch of html, css and javascript file?
Or is there something else in the pile?
I'm working on windows and I know what are more or less html, css and javascript, but I'm new to frontend framework.
Thanks for your attention.
Download foundation first here complete-f6.zip. Then use foundation.min.css and foundation.min.js (of course include jquery.js) on your page and you're free to use whatever is in the foundation docs.
Since you're new, I would recommend using Yeti Launch. Yeti Launch allows you to create a Foundation 6 project with a Basic or Advanced template. The templates use a package manager with everything wired up for you.
With Yeti Launch you get the benefits of a build system (browser reloading, page templates, minification/concatenation, include only the components you use, autoprefixes, etc.) and you don't have to use the command line if you're not comfortable with it.

How do I create transferable dll's for a specific website functionality?

VS2013 update 5, MVC5 using Areas
I have a stand-alone function programmed for a website. The functionality is a specific user interface to collect survey responses in a particular way. It has several controllers, a model and a group of views. The functionality is completely contained in an Area of the project, except for the Shared _Layout file that provides the main menu for consistency.
'Is it possible for me to' / 'how do I' compile this Area into a single or set of .dll file(s) that I could then add conveniently to other websites? I'm assuming creating something for transfer/download is very standard functionality. For example, I used Elmah.MVC for this site. What I want to do is pretty much create a package that can be downloaded in a similar way to how we integrate Elmah.MVC into a site. (Be certain I'm not talking about creating error logging software, I'm only using Elmah.MVC as an example of software that is easily integrated into other website applications.)
I've never compiled any website functionality into a .dll(s) for use elsewhere and would appreciate either some specific guidance, or perhaps what would be easier is to provide a link with a good step by step tutorial or explanation for how to do this. Most of what I've found on the web describes bits and pieces of doing this, but it's not enough for me to feel confident with it.
It seems to me there are a lot of 'moving parts' to taking a particular piece of an MVC application and turning it into something that is easily added to other projects.
A particular issue I don't quite grasp is the difference in downloaded packages between getting code and getting just the .dll(s). For instance, when I download an MVC5 site, I get controllers, models and views, but when I download Elmah I get a .dll and no code files. Also, I do understand the concept of transforms, but I'm just struggling right now with even getting from my programmed application into a 'package' regardless of the transforms that make it easy to integrate into another website.
These are just some of my questions I have about how to perform this particular process in developing deliverable and/or shareable software.
What you are looking to do is create a portable MVC Area project. A Portable Area is a set of reusable multi page functionality can be dropped into an application to provide rich functionality without having to custom build functionality that is literally the same in every application. An MVC Portable Area is really just a dll that contains the views, controllers, scripts, etc… needed to use in a website that is either a Web Forms website or an MVC website. A developer can use them for a reusable widget or a complete engine. I have actually used them for both. Here is a link with some basic info to get started. http://elegantcode.com/2012/04/06/mvc-portable-areas/

How do I host HTML files on cloudant?

the answer to this question must be so trivial because I can't find anything that spells it out for me.
I'm trying to set up a database on cloudant but I keep hearing that to abide the same origin policy the html files will need to be hosted in the same location.
How do I get my html files onto my cloudant domain?
I feel pretty stupid that I haven't been able to figure this out for myself.
You can host static sites on Cloudant similarly to CouchDB. Your best "Getting Started" resource is probably CouchApp.org which explains the mechanism and provides links to tooling which will help you bundle the assets together.
It's also worth mentioning that Cloudant now supports CORS so an externally hosted site is possible as well.
As attachments.
Upload your files as attachments and then access them by going to https://you.cloudant.com/dbname/documentid/name_of_file.html.
Tools like erica (a bigger list of options here) will do that for you. With them, you just need to put all your HTML, CSS and JS files in a folder and the tool will save them all as attachments of a Design Document, then that bundle will become your Couchapp.
(After that you just have to mix some ajax calls to _views and pure docs with links to _list and _show functions -- if you want -- and you'll be a complete couchapper).

Netscaler cannot access xpages mobile extention library 1.6.1 files

Hi I have an xpages app that I have built using the mobile extension library controls. The ap works fine if you go straight to the notes server but as soon as we use netscaler to access we are getting errors accessing the extention libarary files. We have tracked it down to not being able to access these “/xsp/.ibmxspres/dojoroot-1.6.1/dojo/dojo.js or whatever is in or around there.
For this post http://www.intec.co.uk/domino-8-5-3-greater-power-over-dojo-thanks-ibm-for-your-work/ it looks like these files use the new OSGi plugin functionality and are contained in a jar file on the server rather than as separate files on the domino server. Any idea how we can get the citrix gateway to see these files and use them?
Thanks
Mel
Seems like a Netscaler configuration problem to me. If the manuals don't help, ServerFault might be the better place to ask this question. As a wild guess: /. might be blocked by default since ../../../ is a popular path-traversal attack vector. Let us know how it goes

Resources