/**************************************/ /* SUITE BAR DISPLAY FOR ADMIN OPT-IN */ /**************************************/ /* Setting the flag on the admin page */ $(window).load(function($){ if(localStorage.getItem(‘suiteBar’) === ‘true’){ jQuery(‘.message’).html(‘SharePoint Suite Bar Status: ON’); } else { jQuery(‘.message’).html(‘SharePoint Suite Bar Status: OFF’); } jQuery(‘.suite-bar-opt-in’).click(function(){ localStorage.setItem(‘suiteBar’,’true’); jQuery(‘.message’).html(‘SharePoint Suite Bar Status: ON’); }); jQuery(‘.suite-bar-opt-out’).click(function(){ localStorage.setItem(‘suiteBar’,’false’); jQuery(‘.message’).html(‘SharePoint Suite Bar Status: OFF’); }); }); if(localStorage.getItem(‘suiteBar’) […]
// IE Detection (for alternative since icon font is being blocked) if((navigator.appVersion.indexOf(‘MSIE’)!== -1)||(navigator.appVersion.indexOf(‘Windows’)!== -1)){ rm.isIE = true; $(‘html’).addClass(‘ie’); }
You can use commas in the console.log() to add spaces You can set multiple variables (comma delimited) in the first argument of a ‘for’ loop myArray.forEach(function(entry){ console.log(entry.prop1, entry.prop2); }); // entry is the current object Note: ‘For’ loops are faster Some important JavaScript array methods… .filter() = Return a subset of an array based on the conditions […]
The best way I found to size inline SVG graphics: Trim artboard to artwork bounds in Illustrator (Object > Artboards > Fit to Artwork Bounds) Save as SVG and then open it in a text editor Leave the viewBox dimensions exactly as they are Calculate the % difference between width and height in the viewBox values […]
View only: In React, event handlers modify the “state”, and whenever the state is modified, React automatically calls render() again to update the UI You can nest components render: function() { return ( <p className=”secondary”> <PrimaryComponentName /> Resources Comprehensive Beginner’s Guide to ReactJS ReactJS Tutorial React.js Introduction For People Who Know Just Enough jQuery To […]
var testData = queryResponse.PrimaryQueryResult.RelevantResults.Table.Rows[0]; if (testData !== undefined) { return testData.Cells; } In this example, testData holds the result of the query so we can use it in a conditional and then return it without having to run the query again and again.
Node.js Install npm globally if you don’t already have it (check versions with node -v and npm -v) Run npm init command to initialize the package.json file to provide information about the project and help manage the dependencies… example… { “name”: “my_project”, “version”: “0.0.0”, “devDependencies”: { “gulp”: “~3.8.8” }, “dependencies”: { “jquery”: “~2.1.3”, “react”: “~0.13.1” } } devDependencies: These are […]
Sample CoffeeScript AJAX request… //This code fetches data from “/test”, and then appends the result to the div with an id of results… $.ajax(url: “/test”).done (html) -> $(“#results”).append html Unobtrusive JavaScript is separating the script from the HTML markup Built-in helper methods form_for and form_tag … helps in writing forms // Remote submits the form via […]
Associations between models make common operations simpler and easier class Customer < ActiveRecord::Base has_many :orders, dependent: :destroy end class Order < ActiveRecord::Base belongs_to :customer end By declaring that one model belongs_to another, you instruct Rails to maintain Primary Key-Foreign Key information between instances of the two models, and you also get a number of utility […]
Validations are used to ensure that only valid data is saved into your database Model-level validations are the best way They are database agnostic, cannot be bypassed by end users, and are convenient to test and maintain If any validations fail, the object will be marked as invalid and Active Record will not perform the […]
By default, controllers in Rails automatically render views with names that correspond to valid routes The rule is that if you do not explicitly render something at the end of a controller action, Rails will automatically look for the action_name.html.erb template in the controller’s view path and render it If you want to render the […]
Routing connects URLs to code and generates paths from code // routes.rb … e.g. directs a call of /patients/17 to the show action (method) in the patients controller with a parameter of {id: ’17’} … the ‘as’ option names the route, creating the patient_path and patient_url helper methods get ‘/patients/:id’, to: ‘patients#show’, as: ‘patient’ // […]
Sketch Use Cases, Page Flow, & Basic Data Identify basic use cases, sketch page flow on paper (or simple drawing app), and identify basic data (e.g. product which will have a name, description, image, and price) Ambiguity is ok at this stage since Ruby on Rails is great for agile, iterative development Pick a part of […]
Chrome extension is just some HTML, CSS and JavaScript that allows you to add some functionality to Chrome through some of the JavaScript APIs Chrome exposes. An extension is basically just a web page that is hosted within Chrome and can access some additional APIs Browser Action extension is a basic Chrome extension manifest.json … […]
Most common relationship types for models One-to-one One-to-many (parent/child relationships) The parent has many children The children belong to a parent Many-to-many A book has many authors An author has many books Create model in the middle so info can be reused A doctor has many patients through appointments Use the resource generator to generate […]
You can also validate any object, not just ActiveRecord objects Declare rules using validation helpers (e.g. validates :title, presence: true … which validates that the title is there) Lifecycle methods – save, update, and create “Bang” method variants raise exception if object is not valid (e.g. save!, create!, update!) include ActiveModel::Validations Validations populate the errors object […]
There’s a default testing framework in Ruby 1.9+ Borrows from Test::Unit and RSpec Choose one or the other to write all your tests in; don’t use both … be consistent Rails provides testing support out of the box Test runner (via Rake) Testing models against the database using fixtures Functional testing controllers (e.g. that the create […]
rails -v to check version Rails takes MVC further: when you develop in Rails, you start with a working application, there’s a place for each piece of code, and all the pieces of your application interact in a standard way Once you create an application with a specific version of Rails, it will continue to use […]
ruby -v to check version Everything in Ruby is an object You don’t declare variable types, but all objects have a type No compiler, so unit testing is crucial No auto type conversion … “3” + 4 results in a TypeError Created in Japan in 1995 by Yukihiro Matsumoto “Mats” Inspired by Pearl and Smalltalk […]
Using the minus or division math operator will coerce a string into a number … “123”-0 = 123 Never “==” to true or false, always “===”, because “==” will match falsy things like 0 == allows coercion (checks value) – implicit === disallows coercion (checks value and type) – explicit