How to effectively use the 'application.js' file? [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I am using Ruby on Rails 4 and I would to effectively use the application.js file by stating in it some JavaScript functions shared between my application. For instance, I would like to attach data-* attributes to my HTML tag (as made here) and use those functions "the Rails way". However, since I am new to JavaScript, I do not know how to state functions in the application.js file and how to call those from within view templates.
There are some guides on the web where I can learn more about?

First off, you should only rely on the edge guides if you're using edge Rails (pre-release), because they might document features not present in the generally available package.
This is the same guide for the current Rails version.
Then, to answer your question:
The use of data-* attributes on HTML elements is not a Rails technique, and in fact it isn't related to any specific framework.
While it is true that your back-end (in this case, Rails) will need to decide what to write in those data-* attributes when it generates the HTML response, using them with javascript is something that happens on the front-end, and it's definitely not related to Rails.
In any case, if you are a complete beginner the guide you're reading (ajax and unobstrusive javascript) will only confuse you.
You should start with some Javascript tutorial and read about the asset pipeline to understand the role of application.js in Rails.

Related

Frameworks to reuse HTML compatible with bootstrap and knockout.js [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I've been working on a project where we are using bootstrap and kockout.js to handle the views but I'm noticing we're copy'ing a lot of the HTML.
We've tried some options like google closure and JQuery.load but we've had errors with both.
Closure couldn't compile because of bootstrap and Jquery load gave us CORS problems.
As an example, we would like to use "templates" for the navigation bar and for the user control panel that is on every page.
Do you guys know some frameworks that are compatible with our setup?
If you want to use plain knockout there is a template binding:
http://knockoutjs.com/documentation/template-binding.html
Or you can look for DurandalJS. This is a framework which uses Knockout as templating engine.
http://durandaljs.com/
If you use Visual Studio you can checkout the Hottowel SPA template of John Papa. This gives a initial setup for working with DurandalJS.
http://www.johnpapa.net/hottowel-1-1-with-durandal-2-now-available/
Another option you can do is looking in the source code for the template binding to see how the template is injected in the element. You could create a new binding based on the template binding with your own loading meganism.
After a quick bing I also find a nice blogpost about lazy loading templates, which is worth a look:
http://blog.vosnax.ru/2013/06/03/Knockoutjs-lazy-template/
You should try Angular in my opinion. It offers a simpler template structure than knockout and allows very easy JSON calls to web API's
http://angularjs.org/

Only Using Angular for Routing [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I'm working on a single page application and I'm referencing Angular in it. However, the only thing I am using Angular for is the routing (and ng-animate for animating transitions between partials) so that I can change views without reloading the entire page. I don't anticipate using anything else from Angular but I don't know that for sure, as this is my first SPA. I am concerned about things such as load times (especially for international users who aren't near CDNs) as well as security (no point in having potential vulnerabilities if I'm not using those features), etc.
Q: Is using Angular solely for routing overkill? Should I be using something more lightweight?
AngularJS is a framework use it only for routing it's like use a bazooka for a bug ...
I think you need a lightweight library.
The best choice for routing IMHO it's Sammy.js with mustache.js for templating if you need it.
http://sammyjs.org
http://mustache.github.io
Refer to this post :
Comparison between Sammy.js/History.js/Nav.js
Hope it Helps.

Javascript documentation generation [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
Im looking into documenting the javascript code we develop and are looking for some good javascript documentation generators, does anybody have any suggestions?
We used to used ndoc to create documentation for our c# code and are looking for something similar to document our js code - ideally something that can be run from a command line.
thanks in advance!
You can use famous JSDoc-Toolkit for that.
JsDoc Toolkit is an application, written in JavaScript, for
automatically generating template-formatted, multi-page HTML (or XML,
JSON, or any other text-based) documentation from commented JavaScript
source code.
And yes it also has command line options.
JSDoc is an approach to generating documentation from commented JavaScript. There are many variations:
It was originally implemented in Perl.
JSDoc-Toolkit ported it to JavaScript, but requires Java as it uses the Rhino JavaScript engine written in Java.
Several people have ported it to run directly on the node.js JavaScript engine/platform, e.g. node-jsdoc-toolkit.
dox also runs on node.js, it combines JSDoc-like tags and markdown markup but requires a separate templating engine(as used on Stack Overflow and github).
All run from the command line. Choose according to your tooling preferences. I like node.js for its speed and all-JavaScript-all-the-time feel. The DailyJS "Let's Make a Framework" post on writing documentation describes these and other tools; unfortunately dox was radically overhauled to just output JSON structures since that was written.
https://stackoverflow.com/q/1221413/1162195 mentions other JavaScript documentation generators.

How can I compile Ruby to Javascript? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I'm working on a piece of logic that I would like to express on the server as well as in the browser. Something like validating a form where there must be certain logical relationships between the elements based on what has already been entered.
So... If I can write the logic once and somehow end up with both Ruby and with Javascript, I can write the logic just once and not have to worry about making sure that two pieces of code written in different languages have the same functional behaviour.
I don't need to reproduce everything in Ruby, obviously, and one simplification might be to port a single general-purpose library like Functional Javascript to Ruby.
Does anyone have experience with RubyJS? Can anyone point me to an existing project using RubyJS?
Thanks in advance...
As far as I can tell, Opal is the best Ruby to JS converter/compiler out there right now. Here you can see it in action.
It isn't perfect, but it works most of the time and unlike older projects such as RubyJS, Opal is still being actively developed.
I know about http://hotruby.yukoba.jp/ but have never used it
maybe this helps:
http://opalrb.org/
haven't tried it though
I recently heard about a project named "Johnson" which embeds the Spidermonkey JavaScript interpreter inside Ruby. http://github.com/jbarnette/johnson
You could then eval some javascript inside ruby.

Tutorial/Example of how to implement "Browse A to Z" for a website [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I have found that simply googling this does not return what I am looking for. I am to find something simple and easy. I don't know if this requires javascript or not. I know I can "View Page Source" but I was hoping to find a tutorial. Some examples of what I am talking about can be found here:
-IBM
-Auburn
-About.com
Javascipt code works by running code on the viewer's computer. The pages you're linking are being dynamically generated by code that runs on the webserver itself, not in the browser. More than likely, all of those sites have some sort of database behind them.
I see from your other questions that you know C#. Microsoft provides a framework that uses C# known as ASP.NET. You can write code in C# that will run whenever someone views a page on your site (provided your site is running under IIS).
The ASP.NET Community website is a great resource if you want to find out more about that.
Other such tools that perform server-side operations would be PHP, Ruby on Rails, or Django (to name a popular few).
From viewing the examples you mentioned, it does not seem like there is any javascript used to make these "browse a to z" lists. (There should be a better name for them than that. I'm just going to call it a sitemap.)
I couldn't find any tutorials online that would teach expressly this type of sitemap, but figuring it out should be pretty straight-forward. (At least for implementing sitemaps like the IBM or Auburn examples. The About.com example would be more difficult as it seems that it is backed by a database or lots and lots of individual html pages.)
The trickiest part of making a sitemap page like these is using the tag, and luckily, it is way easy. Just keep checking the source of those pages you can have your own version in no time. The most time consuming part will be putting all of the links down, from A to Z.
http://www.w3schools.com/HTML/html_links.asp

Categories