"use strict"; angular.module("vocabulary") .service("utilService", ["$rootScope", "$state", "$location", function ($rootScope, $state, $location) { var applicationName = "Vocabulary A-Z"; var suffix = " | " + applicationName; var maxTitleLength = 75; return { setTitle: setTitle, setTitleFromFirstH1IfAny: setTitleFromFirstH1IfAny, setMetaDescriptionFromState: setMetaDescriptionFromState, setMetaDescriptionFromPath: setMetaDescriptionFromPath }; function setTitle(givenText) { if (givenText) { $rootScope.title = givenText.substring(givenText, maxTitleLength - suffix.length) + suffix; } else { $rootScope.title = applicationName; } } function setTitleFromFirstH1IfAny() { var firstH1 = angular.element("h1:first") .clone() //clone the element .children() //select all the children .remove() //remove all the children .end() //again go back to selected element .text() .trim(); if (firstH1) { setTitle(firstH1); } } function isOrHasParent(state, stateName) { if (!state) { return false; } if (state.name === stateName) { return true; } if (!state.parent) { return false; } return isOrHasParent(state.parent, stateName); } function setMetaDescriptionFromState() { var state = $state.$current; var url = $location.absUrl(); if (url.indexOf("/main/") >= 0) { return; } if (isOrHasParent(state, 'home')) { $rootScope.metaDescription = "Teach vocabulary in context with premade and customizable vocabulary lessons. Students extend learning beyond the classroom with game-based activities."; } else if (isOrHasParent(state, "lesson")) { $rootScope.metaDescription = "Create your own vocabulary lesson by browsing word lists, searching for words, or creating your own words."; } else if (isOrHasParent(state, "premadeLessons.razLeveledBooks")) { $rootScope.metaDescription = "Browse and assign ready-to-use vocabulary lessons connected to Raz-Plus leveled books, math books, and vocabulary books."; } else if (isOrHasParent(state, "premadeLessons.ellLanguageSkill")) { $rootScope.metaDescription = "Browse and assign ready-to-use vocabulary lessons connected to Raz-Plus ELL Edition language skill packs, vocabulary books, or vocabulary power packs."; } else if (isOrHasParent(state, "premadeLessons.science")) { $rootScope.metaDescription = "Browse and assign ready-to-use vocabulary lessons connected to Science A-Z Life, Earth & Space, or Physical units."; } else if (isOrHasParent(state, "premadeLessons.collection")) { $rootScope.metaDescription = "Browse and assign ready-to-use vocabulary lessons based on popular Harcourt, Macmillan, Scott Foresman, and Houghton Mifflin reading series."; } } function setMetaDescriptionFromPath() { var url = $location.absUrl(); if (url.indexOf("main/ViewPage/name/learn-more") >= 0) { $rootScope.metaDescription = "Connect your vocabulary instruction to topics and content in Raz-Plus, Raz-Plus ELL Edition, and Science A-Z."; } else if (url.indexOf("main/ViewPage/name/research") >= 0) { $rootScope.metaDescription = "Vocabulary learning based on language acquisition research. Resources support effective vocabulary instruction."; } else if (url.indexOf("main/ViewPage/name/get-students-reading") >= 0) { $rootScope.metaDescription = "Tips to get students started. Technology, student access, letter to parents, incentives & awards, and audio."; } else if (url.indexOf("main/ViewPage/name/student-portal") >= 0) { $rootScope.metaDescription = "Get to know the student portal, with assignments, interactivities and quizzes, messages, star zone, and stats."; } else if (url.indexOf("main/ViewPage/name/all-about-tiers") >= 0) { $rootScope.metaDescription = "Vocabulary analysis-based tiering system categorizes words on difficulty, specialization, frequency, and instructional potential."; } else if (url.indexOf("main/VideoLibrary") >= 0) { $rootScope.metaDescription = "Video resources for teaching vocabulary."; } } }]);