Archive for the “Web Shots” Category

Hide SharePoint Toolbar

Posted on June 2nd, 2016 by webninjataylor

/**************************************/ /* 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’) […]

Remove SharePoint Induced White Spaces

Posted on June 2nd, 2016 by webninjataylor

jQuery(‘#s4-bodyContainer’).html(jQuery(‘#s4-bodyContainer’).html().replace(/\u200B|\u200C|\u200D|\uFEFF|&nbsp\;/g,”)); jQuery(‘#s4-bodyContainer’).find(‘br’).last().remove();

Simple IE Detection and CSS Selector Injection into HTML Tag

Posted on March 23rd, 2016 by webninjataylor

// 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’); }

D3 Course Notes

Posted on February 12th, 2016 by webninjataylor

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 […]

JavaScript .map() Method

Posted on December 1st, 2015 by webninjataylor

var numbers = [1, 4, 9]; var roots = numbers.map(Math.sqrt); // roots is now [1, 2, 3], numbers is still [1, 4, 9]

jQuery Promises

Posted on August 28th, 2015 by webninjataylor

JavaScript jQuery promises… Widgets.peopleHeader = {     name: ‘People Header’,     log: true,     promise: new $.Deferred() … $.when(Widgets.peopleHeader.promise).done(function () { …

Sizing Inline SVG

Posted on August 16th, 2015 by webninjataylor

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 […]

ReactJS Notes

Posted on July 22nd, 2015 by webninjataylor

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 […]

Arrow Tabs with CSS

Posted on July 15th, 2015 by webninjataylor

JS Bin on jsbin.com Resources CSS Arrow Please

Tags:
Posted in Web ShotsComments Off on Arrow Tabs with CSS

CSS Calculations

Posted on July 15th, 2015 by webninjataylor

You can calculate properties in CSS with calc()… height: calc(100vh – 313px); vh and vw are the new CSS3 viewport units.

Tags:
Posted in Web ShotsComments Off on CSS Calculations

JavaScript: Sample Request Reduction

Posted on June 28th, 2015 by webninjataylor

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.

Tags:
Posted in Web ShotsComments Off on JavaScript: Sample Request Reduction

Node.js and Gulp.js Basics

Posted on June 27th, 2015 by webninjataylor

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 […]

Ruby on Rails: JavaScript

Posted on May 5th, 2015 by webninjataylor

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 […]

Tags:
Posted in Web ShotsComments Off on Ruby on Rails: JavaScript

Ruby on Rails: Associations

Posted on May 5th, 2015 by webninjataylor

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 […]

Tags:
Posted in Web ShotsComments Off on Ruby on Rails: Associations

Ruby on Rails: Validations

Posted on May 4th, 2015 by webninjataylor

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 […]

Tags:
Posted in Web ShotsComments Off on Ruby on Rails: Validations

Ruby on Rails: Layouts and Rendering

Posted on May 4th, 2015 by webninjataylor

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 […]

Tags:
Posted in Web ShotsComments Off on Ruby on Rails: Layouts and Rendering

Ruby on Rails: Routing

Posted on May 1st, 2015 by webninjataylor

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’ // […]

Tags:
Posted in Web ShotsComments Off on Ruby on Rails: Routing

Ruby on Rails: Suggested Project Flow

Posted on April 26th, 2015 by webninjataylor

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 […]

Tags:
Posted in Web ShotsComments Off on Ruby on Rails: Suggested Project Flow

Chrome Extensions

Posted on April 22nd, 2015 by webninjataylor

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 … […]

Ruby on Rails: Relationships, Nested Resources, and AJAX in Rails

Posted on April 22nd, 2015 by webninjataylor

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 […]

Tags:
Posted in Web ShotsComments Off on Ruby on Rails: Relationships, Nested Resources, and AJAX in Rails

Ruby on Rails: Validation, Queries, Layouts, and Styling in Rails

Posted on April 15th, 2015 by webninjataylor

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 […]

Tags:
Posted in Web ShotsComments Off on Ruby on Rails: Validation, Queries, Layouts, and Styling in Rails

Ruby on Rails: Testing, Configuration, and Forms in Rails

Posted on April 8th, 2015 by webninjataylor

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 […]

Tags:
Posted in Web ShotsComments Off on Ruby on Rails: Testing, Configuration, and Forms in Rails

Ruby on Rails: Introduction to Ruby on Rails

Posted on April 8th, 2015 by webninjataylor

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 […]

Tags:
Posted in Web ShotsComments Off on Ruby on Rails: Introduction to Ruby on Rails

Ruby on Rails: Introduction to Ruby

Posted on April 8th, 2015 by webninjataylor

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 […]

Tags:
Posted in Web ShotsComments Off on Ruby on Rails: Introduction to Ruby

JavaScript Implicit vs. Explicit Coercion

Posted on April 3rd, 2015 by webninjataylor

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

Tags:
Posted in Web ShotsComments Off on JavaScript Implicit vs. Explicit Coercion