CourseSitesjQuery plug-in<br />
Context<br />Replace specific string(s) on a page that is part of href with something else <br />
CourseSites<br />Instructor homepage (ie. https://wayank12teacher2.coursesites.com)<br />List of courses<br />Course101 (h...
Firebug…locate the element<br />
Firebug…locate the element (2)<br />
Element of interest<br /><li class="course-navigation-course"><a class="highlight" href="https://wayank12teacher2.coursesi...
Find those elements<br />jQuery('li.course-navigation-course').find('a[href]')<br />Results:<br />[<a class=​"highlight" h...
Search and Replace ( Use Firebug if you have to)<br />location.host<br />Result  "wayank12teacher2.coursesites-stage.com"...
The plug-in<br />jQuery.fn.convertUsertoWWW = function() { return this.each( function() { <br />varc=$(this).attr('href');...
To execute<br />jQuery('li.course-navigation-course').find('a[href]').convertUsertoWWW();<br />
Final script<br />jQuery(document).ready(function() { jQuery.fn.convertUsertoWWW = function() { return this.each( function...
Upcoming SlideShare
Loading in …5
×

CourseSites jQuery plug-in

554 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
554
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

CourseSites jQuery plug-in

  1. 1. CourseSitesjQuery plug-in<br />
  2. 2. Context<br />Replace specific string(s) on a page that is part of href with something else <br />
  3. 3. CourseSites<br />Instructor homepage (ie. https://wayank12teacher2.coursesites.com)<br />List of courses<br />Course101 (https://wayank12teacher2.coursesites.com/s/_course101)<br />Course102 (https://wayank12teacher2.coursesites.com/s/_course102)<br />Goal  replace wayank12teacher2 with www<br />
  4. 4. Firebug…locate the element<br />
  5. 5. Firebug…locate the element (2)<br />
  6. 6. Element of interest<br /><li class="course-navigation-course"><a class="highlight" href="https://wayank12teacher2.coursesites-stage.com/s/_wayank12changestructure101">wayank12changestructure101»</a></li><br />
  7. 7. Find those elements<br />jQuery('li.course-navigation-course').find('a[href]')<br />Results:<br />[<a class=​"highlight" href=​"https:​/​/​wayank12teacher2.coursesites-stage.com/​s/​_wayank12changestructure101">​wayank12changestructure101»​</a>​<br />, <a class=​"highlight" href=​"https:​/​/​wayank12teacher2.coursesites-stage.com/​s/​_wayank12nov04test101">​wayank12nov04test101»​</a>​<br />]<br />
  8. 8. Search and Replace ( Use Firebug if you have to)<br />location.host<br />Result  "wayank12teacher2.coursesites-stage.com"<br />varb='https://' + location.host.replace(location.host.split('.')[0],'www')<br />
  9. 9. The plug-in<br />jQuery.fn.convertUsertoWWW = function() { return this.each( function() { <br />varc=$(this).attr('href'); <br />varb='https://' + location.host.replace(location.host.split('.')[0],'www')+c; <br />$(this).attr('href',b); <br />} <br />);<br />
  10. 10. To execute<br />jQuery('li.course-navigation-course').find('a[href]').convertUsertoWWW();<br />
  11. 11. Final script<br />jQuery(document).ready(function() { jQuery.fn.convertUsertoWWW = function() { return this.each( function() { <br />varc=$(this).attr('href'); <br />varb='https://' + location.host.replace(location.host.split('.')[0],'www')+c; <br />$(this).attr('href',b); } ); <br />};<br />jQuery('li.course-navigation-course').find('a[href]').convertUsertoWWW();<br />

×