Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "LinkedList.h"
- #include "Media.h"
- #include "CompactDisc.h"
- #include "DigitalDisk.h"
- #include <iostream>
- #include <iomanip>
- #include <string>
- using namespace std;
- void addCD(LinkedList<CompactDisc> &);
- void addDVD(LinkedList<DigitalDisk> &);
- void subCD(LinkedList<CompactDisc> &);
- void subDVD(LinkedList<DigitalDisk> &);
- void modCD(LinkedList<CompactDisc> &);
- void modDVD(LinkedList<DigitalDisk> &);
- void quitManager(LinkedList<CompactDisc> &, LinkedList<DigitalDisk> &);
- int main()
- {
- LinkedList<CompactDisc> cdCollection;
- LinkedList<DigitalDisk> dvdCollection;
- int choice = 1;
- cout << "Welcome to media manager. What would you like to do? ";
- cout << "\n1. Add a CD\n2. Add a DVD\n3. Remove a CD\n4. Remove a
- DVD\n5. Change a CD\n6. Change a DVD\n7.Quit and display
- collection\n";
- cin >> choice;
- while (choice != 7)
- {
- if (choice == 1)
- {
- addCD(cdCollection);
- }
- else if (choice == 2)
- {
- addDVD(dvdCollection);
- }
- else if (choice == 3)
- {
- subCD(cdCollection);
- }
- else if (choice == 4)
- {
- subDVD(dvdCollection);
- }
- else if (choice == 5)
- {
- modCD(cdCollection);
- }
- else if (choice == 6)
- {
- modDVD(dvdCollection);
- }
- else
- {
- cout << "\nEnter a valid choice";
- }
- cout << "\n1. Add a CD\n2. Add a DVD\n3. Remove a CD\n4. Remove a
- DVD\n5. Change a CD\n6. Change a DVD\n7.Quit and display
- collection\n";
- cin >> choice;
- }
- quitManager(cdCollection, dvdCollection);
- return 0;
- }
- void addCD(LinkedList<CompactDisc> &cds)
- {
- string tempname;
- double temptime;
- string tempartist;
- CompactDisc tempdisk;
- cout << "\nEnter the name of the CD to add: ";
- cin.ignore();
- getline(cin, tempname);
- cout << "Enter the total length of the CD: ";
- cin >> temptime;
- cin.ignore();
- cout << "Enter the name of the CD artist: ";
- getline(cin, tempartist);
- tempdisk.setMediaName(tempname);
- tempdisk.setMediaLength(temptime);
- tempdisk.setArtistName(tempartist);
- cout << tempdisk.getMediaName();
- cds.appendNode(tempdisk);
- cout << "CD added\n";
- }
- void addDVD(LinkedList<DigitalDisk> &dvds)
- {
- string tempname;
- double temptime;
- int tempyear;
- DigitalDisk tempdisk;
- cout << "\nEnter the name of the DVD to add: ";
- cin.ignore();
- getline(cin, tempname);
- cout << "Enter the length of the movie: ";
- cin >> temptime;
- cout << "Enter the year the movie was released: ";
- cin >> tempyear;
- tempdisk.setMediaName(tempname);
- tempdisk.setMediaLength(temptime);
- tempdisk.setYearReleased(tempyear);
- dvds.appendNode(tempdisk);
- cout << "DVD added\n";
- }
- void subCD(LinkedList<CompactDisc> &cds)
- {
- string tempname;
- CompactDisc tempdisk;
- cout << "\nEnter the name of the CD to delete: ";
- cin.ignore();
- getline(cin, tempname);
- tempdisk.setMediaName(tempname);
- tempdisk = cds.searchList(tempdisk);
- if (tempdisk.getMediaLength() != 0)
- {
- cds.deleteNode(tempdisk);
- cout << "CD deleted\n";
- }
- else
- cout << "CD not in collection. Cannot Delete.\n";
- }
- void subDVD(LinkedList<DigitalDisk> &dvds)
- {
- string tempname;
- DigitalDisk tempdisk;
- cout << "\nEnter the name of the movie to delete: ";
- cin.ignore();
- getline(cin, tempname);
- tempdisk.setMediaName(tempname);
- tempdisk = dvds.searchList(tempdisk);
- if (tempdisk.getMediaLength() != 0)
- {
- dvds.deleteNode(tempdisk);
- cout << "\nDVD deleted";
- }
- else
- cout << "\nDVD not in collection. Cannot Delete.";
- }
- void modCD(LinkedList<CompactDisc> &cds)
- {
- int changeme;
- string tempname;
- CompactDisc tempdisc;
- cout << "\nEnter the name of a CD to change: ";
- cin.ignore();
- getline(cin, tempname);
- tempdisc.setMediaName(tempname);
- tempdisc = cds.searchList(tempdisc);
- while (tempdisc.getMediaLength() == 0)
- {
- cout << "\nEnter a valid name of a CD to change: ";
- cin.ignore();
- getline(cin, tempname);
- tempdisc.setMediaName(tempname);
- tempdisc = cds.searchList(tempdisc);
- }
- cout << "\nWhat would you like to change about this CD: ";
- cout << "\n1. Artist Name\n2.CD Length\n3. Add Song\n4. Delete
- Song\n5. CD Name\n6.Exit Modifier\n";
- cin >> changeme;
- cin.ignore();
- while (changeme != 6)
- {
- if (changeme == 1)
- {
- string tempname;
- cout << "\nEnter a new artist name: ";
- cin.ignore();
- getline(cin, tempname);
- tempdisc.setArtistName(tempname);
- cout << "\nName changed successfully";
- }
- else if (changeme == 2)
- {
- double temptime;
- cout << "\nEnter a new CD length: ";
- cin >> temptime;
- cin.ignore();
- tempdisc.setMediaLength(temptime);
- cout << "\nTime changed successfully";
- }
- else if (changeme == 3)
- {
- string tempname;
- double temptime;
- cout << "\nEnter a song name: ";
- cin.ignore();
- getline(cin, tempname);
- cout << "\nEnter a song length: ";
- cin >> temptime;
- cin.ignore();
- tempdisc.addSong(tempname, temptime);
- }
- else if (changeme == 4)
- {
- string tempname;
- cout << "\nEnter the name of a song to delete: ";
- getline(cin, tempname);
- if (tempdisc.deleteSong(tempname))
- {
- cout << "\nSong deleted successfully";
- }
- else
- cout << "\nSong does not exist in this CD to delete";
- }
- else
- {
- string tempname;
- cout << "\nEnter the new name of this CD: ";
- getline(cin, tempname);
- tempdisc.setMediaName(tempname);
- cout << "\nName changed successfully";
- }
- cout << "\nWhat would you like to change about this CD: ";
- cout << "\n1. Artist Name\n2.CD Length\n3. Add Song\n4. Delete
- Song\n5. CD Name\n6.Exit Modifier\n";
- cin >> changeme;
- cin.ignore();
- }
- cout << "\nNow exiting CD modifier...";
- }
- void modDVD(LinkedList<DigitalDisk> &dvds)
- {
- int changeme;
- string tempname;
- DigitalDisk tempdisc;
- cout << "\nEnter the name of a DVD to change: ";
- cin.ignore();
- getline(cin, tempname);
- tempdisc.setMediaName(tempname);
- tempdisc = dvds.searchList(tempdisc);
- while (tempdisc.getMediaLength() == 0)
- {
- cout << "\nEnter a valid name of a DVD to change: ";
- getline(cin, tempname);
- tempdisc.setMediaName(tempname);
- tempdisc = dvds.searchList(tempdisc);
- }
- cout << "\nWhat would you like to change about this DVD: ";
- cout << "\n1. Actor or Character name\n2.DVD Length\n3. Add
- Actor/Character\n4. Delete ActorCharacter\n5. Year Released\n6. DVD
- name";
- cout << "\n7.Exit Modifier\n";
- cin >> changeme;
- cin.ignore();
- while (changeme != 7)
- {
- if (changeme == 1)
- {
- int whichtochange;
- cout << "\nChange: \n1. Actor name\n2.Character name";
- cin >> whichtochange;
- cin.ignore();
- if (whichtochange == 1)
- {
- string tempname;
- cout << "\nEnter a new actor name: ";
- cin.ignore();
- getline(cin, tempname);
- if (tempdisc.changeActor(tempname))
- cout << "\nActor changed successfully";
- else
- cout << "\nActor does not exist to change";
- }
- else
- {
- string tempaname;
- string tempcname;
- cout << "\nEnter an actor to change their character's name: ";
- cin.ignore();
- getline(cin, tempaname);
- cout << "\nEnter their new character's name: ";
- cin.ignore();
- getline(cin, tempcname);
- if (tempdisc.changeCharacter(tempaname, tempcname))
- cout << "\nCharacter changed successfully";
- else
- cout << "\nActor does not exist to change character name";
- }
- }
- else if (changeme == 2)
- {
- double temptime;
- cout << "\nEnter a new movie length: ";
- cin >> temptime;
- cin.ignore();
- tempdisc.setMediaLength(temptime);
- cout << "\nTime changed successfully";
- }
- else if (changeme == 3)
- {
- string tempaname;
- string tempcname;
- cout << "\nEnter a new actor name: ";
- getline(cin, tempaname);
- cout << "\nEnter a new character name: ";
- getline(cin, tempcname);
- tempdisc.addPlayer(tempaname, tempcname);
- }
- else if (changeme == 4)
- {
- string tempname;
- cout << "\nEnter the name of an actor to delete: ";
- if (tempdisc.deletePlayer(tempname))
- {
- cout << "\nActor deleted successfully";
- }
- else
- cout << "\nActor does not exist in this movie to delete";
- }
- else if (changeme == 5)
- {
- int tempyear;
- cout << "\nEnter a new year of release for this movie: ";
- cin >> tempyear;
- cin.ignore();
- tempdisc.setYearReleased(tempyear);
- cout << "\nYear changed successfully";
- }
- else
- {
- string tempname;
- cout << "Enter the new name of this DVD: ";
- getline(cin, tempname);
- tempdisc.setMediaName(tempname);
- cout << "\nName changed successfully";
- }
- cout << "\nWhat would you like to change about this DVD: ";
- cout << "\n1. Actor or Character name\n2.DVD Length\n3. Add
- Actor/Character\n4. Delete ActorCharacter\n5. Year Released\n6. DVD
- name";
- cout << "\n7.Exit Modifier\n";
- cin >> changeme;
- cin.ignore();
- }
- cout << "\nNow exiting DVD modifier...";
- }
- void quitManager(LinkedList<CompactDisc> &cds, LinkedList<DigitalDisk> &dvds)
- {
- cout << "\nThank you for using Media Manager. Your collection is as
- follows: " << endl << endl;
- cout << "DVD Collection\n ~~~~~~~~~~~~~~~~~~\n";
- cout << "Movie Title " << setw(20) << "Length of Movie" << setw(20)
- << "Year Released" << setw(10) << "Actors" << setw(10) << "Character";
- dvds.displayList();
- cout << endl;
- }
- ----------------------------------------------
- #ifndef DIGITALDISK_H
- #define DIGITALDISK_H
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include "LinkedList.h"
- #include "Media.h"
- #include "Player.h"
- class DigitalDisk;
- ostream &operator << (ostream &, const DigitalDisk &);
- class DigitalDisk : public Media
- {
- private:
- int yearReleased;
- LinkedList<Player> credits;
- public:
- DigitalDisk() :Media()
- {
- yearReleased = 0;
- }
- DigitalDisk(std::string mn, double ml, int yr) : Media(mn, ml)
- {
- yearReleased = yr;
- }
- void setYearReleased(int yr)
- {
- yearReleased = yr;
- }
- int getYearReleased()
- {
- return yearReleased;
- }
- void addPlayer(string an, string cn)
- {
- Player temp;
- temp.setActorName(an);
- temp.setCharacterName(cn);
- credits.appendNode(temp);
- credits.displayList();
- cout << "\nActor/Character added";
- }
- bool deletePlayer(std::string an)
- {
- Player temp;
- temp.setActorName(an);
- temp = credits.searchList(temp);
- if (temp.getCharacterName() != "")
- {
- credits.deleteNode(temp);
- return true;
- }
- else
- return false;
- }
- bool changeActor(std::string an)
- {
- Player temp1;
- Player temp2;
- temp2.setActorName(an);
- temp2 = credits.searchList(temp2);
- if (temp2.getCharacterName() != "")
- {
- temp1 = temp2;
- temp1.setActorName(an);
- credits.deleteNode(temp2);
- credits.appendNode(temp1);
- return true;
- }
- else
- return false;
- }
- bool changeCharacter(std::string an, std::string cn)
- {
- Player temp1;
- Player temp2;
- temp2.setActorName(an);
- temp2 = credits.searchList(temp2);
- if (temp2.getCharacterName() != "")
- {
- temp1 = temp2;
- temp1.setCharacterName(cn);
- credits.deleteNode(temp2);
- credits.appendNode(temp1);
- return true;
- }
- else
- return false;
- }
- bool operator == (DigitalDisk &right)
- {
- if (mediaName == right.getMediaName())
- return true;
- else
- return false;
- }
- bool operator != (DigitalDisk &right)
- {
- if (mediaName != right.getMediaName())
- return true;
- else
- return false;
- }
- DigitalDisk operator = (DigitalDisk &right)
- {
- mediaName = right.getMediaName();
- mediaLength = right.getMediaLength();
- yearReleased = right.getYearReleased();
- return *this;
- }
- void displayCredits()
- {
- credits.displayList();
- }
- friend ostream &operator << (ostream & strm, const DigitalDisk &obj)
- {
- strm << endl << obj.mediaName << setw(10) << obj.mediaLength <<
- setw(10) << obj.yearReleased << setw(10);
- return strm;
- }
- };
- #endif
- ----------------------------------------------
- #ifndef COMPACTDISC_H
- #define COMPACTDISC_H
- #include <string>
- #include "LinkedList.h"
- #include "Media.h"
- class CompactDisc : public Media
- {
- struct song
- {
- std::string songName;
- double songLength;
- bool operator ==(song &right)
- {
- if (songName == right.songName && songLength == right.songLength)
- return true;
- else
- return false;
- }
- bool operator !=(song &right)
- {
- if (songName != right.songName && songLength != right.songLength)
- return true;
- else
- return false;
- }
- song operator = (song &right)
- {
- song temp;
- temp.songName = right.songName;
- temp.songLength = right.songLength;
- return temp;
- }
- void displaySong()
- {
- cout << songName << songLength;
- }
- };
- private:
- LinkedList<song> setlist;
- std::string artistName;
- public:
- CompactDisc() : Media()
- {
- artistName = "";
- }
- CompactDisc(std::string mn, double ml, std::string an) : Media(mn, ml)
- {
- artistName = an;
- }
- void setArtistName(std::string an)
- {
- artistName = an;
- }
- std::string getArtistName()
- {
- return artistName;
- }
- void addSong(std::string sn, double sl)
- {
- song temp;
- temp.songName = sn;
- temp.songLength = sl;
- setlist.appendNode(temp);
- }
- bool deleteSong(std::string sn)
- {
- song temp;
- temp.songName = sn;
- temp = setlist.searchList(temp);
- if (temp.songLength != 0)
- {
- setlist.deleteNode(temp);
- return true;
- }
- else
- return false;
- }
- bool operator == (CompactDisc &right)
- {
- if (mediaName == right.getMediaName())
- return true;
- else
- return false;
- }
- bool operator != (CompactDisc &right)
- {
- if (mediaName != right.getMediaName())
- return true;
- else
- return false;
- }
- CompactDisc operator = (CompactDisc &right)
- {
- mediaName = right.getMediaName();
- mediaLength = right.getMediaLength();
- artistName = right.getArtistName();
- return *this;
- }
- };
- #endif;
- ----------------------------------------------
- #ifndef MEDIA_H
- #define MEDIA_H
- #include <iostream>
- #include <string>
- using namespace std;
- class Media
- {
- protected:
- string mediaName;
- double mediaLength;
- public:
- Media()
- {
- mediaName = "";
- mediaLength = 0;
- }
- Media(string mn, double ml)
- {
- mediaName = mn;
- mediaLength = ml;
- }
- void setMediaName(string mn)
- {
- mediaName = mn;
- }
- void setMediaLength(double ml)
- {
- mediaLength = ml;
- }
- string getMediaName()
- {
- return mediaName;
- }
- double getMediaLength()
- {
- return mediaLength;
- }
- };
- #endif
- ----------------------------------------------
- #ifndef PLAYER_H
- #define PLAYER_H
- #include <string>
- #include <iostream>
- #include <iomanip>
- using namespace std;
- class Player;
- ostream &operator << (ostream &, const Player &);
- class Player
- {
- private:
- string actorName;
- string characterName;
- public:
- Player()
- {
- actorName = "";
- characterName = "";
- }
- void setActorName(string an)
- {
- actorName = an;
- }
- void setCharacterName(string cn)
- {
- characterName = cn;
- }
- string getCharacterName()
- {
- return characterName;
- }
- string getActorName()
- {
- return actorName;
- }
- bool operator == (Player &right)
- {
- if (actorName == right.getActorName())
- return true;
- else
- return false;
- }
- bool operator != (Player &right)
- {
- if (actorName != right.getActorName())
- return true;
- else
- return false;
- }
- Player operator = (Player &right)
- {
- actorName = right.getActorName();
- characterName = right.getCharacterName();
- return *this;
- }
- inline friend ostream &operator << (ostream & strm, const Player &obj)
- {
- strm << setw(30) << obj.actorName << "/" << obj.characterName << endl;
- return strm;
- }
- };
- #endif
- ----------------------------------------------
- //Class declaration for LinkedList. This class creates a
- //template class for a LinkedList that can be appended to,
- //have data inserted to or deleted from, and searched for a
- //position of a certain piece of data.
- #ifndef LINKEDLIST_H
- #define LINKEDLIST_H
- #include <string>
- #include <iostream>
- using namespace std;
- template<class T>
- class LinkedList
- {
- private:
- struct ListNode
- {
- T value;
- struct ListNode *next;
- };
- ListNode *head;
- public:
- //Constructor that starts a new linked list.
- LinkedList()
- {
- head = nullptr;
- }
- //Destructor that will destroy the list.
- ~LinkedList();
- void appendNode(T);
- void insertNode(T);
- void deleteNode(T);
- void displayList() const;
- T searchList(T);
- };
- //Function definition for appendNode
- //This function takes new information for a new list and
- //creates the list with the information entered in the order it
- //is recieved.
- template <class T>
- void LinkedList<T>::appendNode(T newValue)
- {
- ListNode *newNode;
- ListNode *nodePtr;
- newNode = new ListNode;
- newNode->value = newValue;
- newNode->next = nullptr;
- if (!head)
- head = newNode;
- else
- {
- nodePtr = head;
- while (nodePtr->next)
- nodePtr = nodePtr->next;
- nodePtr->next = newNode;
- }
- }
- //Function definition for displayList.
- //This function shows the list as it sits.
- template <class T>
- inline void LinkedList<T>::displayList() const
- {
- ListNode *nodePtr;
- nodePtr = head;
- while (nodePtr)
- {
- cout << nodePtr->value;
- nodePtr = nodePtr->next;
- }
- }
- //Function definition for insertNode.
- //This function will create and insert data into an
- //existing list. This function will insert the data
- //into the list in a sorted manner. I.E. if the list
- //is 4, 5, 7, 8, then 6 would be inserted in the middle.
- template <class T>
- void LinkedList<T>::insertNode(T newValue)
- {
- ListNode *newNode;
- ListNode *nodePtr;
- ListNode *previousNode = nullptr;
- newNode = new ListNode;
- newNode->value = newValue;
- if (!head)
- {
- head = newNode;
- newNode->next = nullptr;
- }
- else
- {
- nodePtr = head;
- previousNode = nullptr;
- while (nodePtr != nullptr && nodePtr->value < newValue)
- {
- previousNode = nodePtr;
- nodePtr = nodePtr->next;
- }
- if (previousNode == nullptr)
- {
- head = newNode;
- newNode->next = nodePtr;
- }
- else
- {
- previousNode->next = newNode;
- newNode->next = nodePtr;
- }
- }
- }
- //Function definition for deleteNode.
- //This function searches for a specified node
- //and deletes it and the place of the node in the
- //list so there is not just one huge gap in the list.
- template <class T>
- void LinkedList<T>::deleteNode(T searchValue)
- {
- ListNode *nodePtr;
- ListNode *previousNode = nullptr;
- if (!head)
- return;
- if (head->value == searchValue)
- {
- nodePtr = head->next;
- delete head;
- head = nodePtr;
- }
- else
- {
- nodePtr = head;
- while (nodePtr != nullptr && nodePtr->value != searchValue)
- {
- previousNode = nodePtr;
- nodePtr = nodePtr->next;
- }
- if (nodePtr)
- {
- previousNode->next = nodePtr->next;
- delete nodePtr;
- }
- }
- }
- //Destructor definition for class LinkedList.
- //This destructor destroys the whole list.
- template <class T>
- LinkedList<T>::~LinkedList()
- {
- ListNode *nodePtr;
- ListNode *nextNode;
- nodePtr = head;
- while (nodePtr != nullptr)
- {
- nextNode = nodePtr->next;
- delete nodePtr;
- nodePtr = nextNode;
- }
- }
- //Function definition for searchList.
- //This function searches for a specified data member.
- //If the number is found it returns the place of the data.
- //If the searched for is not found, then it returns negative 1.
- template <class T>
- T LinkedList<T>::searchList(T searchValue)
- {
- ListNode *nodePtr;
- nodePtr = head;
- while (nodePtr != nullptr)
- {
- if (nodePtr-> value == searchValue)
- {
- searchValue = nodePtr->value;
- return searchValue;
- }
- nodePtr = nodePtr->next;
- }
- return searchValue;
- }
- #endif
- <!DOCTYPE html>
- <html lang="en-US">
- <head>
- <title>Tryit Editor v3.0</title>
- <meta name="viewport" content="width=device-width">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <link rel="stylesheet" href="/lib/w3.css">
- <script src="/lib/w3codecolor.js"></script>
- <script>
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
- ga('create', 'UA-3855518-1', 'auto');
- ga('require', 'displayfeatures');
- ga('send', 'pageview');
- </script>
- <script>
- var googletag = googletag || {};
- googletag.cmd = googletag.cmd || [];
- (function() {
- var gads = document.createElement('script');
- gads.async = true;
- gads.type = 'text/javascript';
- var useSSL = 'https:' == document.location.protocol;
- gads.src = (useSSL ? 'https:' : 'http:') +
- '//www.googletagservices.com/tag/js/gpt.js';
- var node = document.getElementsByTagName('script')[0];
- node.parentNode.insertBefore(gads, node);
- })();
- </script>
- <script type='text/javascript'>
- // GPT slots
- var gptAdSlots = [];
- googletag.cmd.push(function() {
- var leaderMapping = googletag.sizeMapping().
- // Mobile ad
- addSize([0, 0], [320, 50]).
- // Vertical Tablet ad
- addSize([468, 0], [468, 60]).
- // Horizontal Tablet
- addSize([728, 0], [728, 90]).
- // Desktop and bigger ad
- addSize([970, 0], [[728, 90], [970, 90]]).build();
- // addSize([970, 0], [728, 90]).build();
- gptAdSlots[0] = googletag.defineSlot('/16833175/TryitLeaderboard',
- [[728, 90], [970, 90]], 'div-gpt-ad-1428407818244-0').
- // gptAdSlots[0] = googletag.defineSlot('/16833175/TryitLeaderboard',
- [728, 90], 'div-gpt-ad-1428407818244-0').
- defineSizeMapping(leaderMapping).addService(googletag.pubads());
- googletag.pubads().setTargeting("content","tryangular");
- googletag.enableServices();
- });
- </script>
- <script>
- if (window.addEventListener) {
- window.addEventListener("resize", browserResize);
- } else if (window.attachEvent) {
- window.attachEvent("onresize", browserResize);
- }
- var xbeforeResize = window.innerWidth;
- function browserResize() {
- var afterResize = window.innerWidth;
- if ((xbeforeResize < (970) && afterResize >= (970)) ||
- (xbeforeResize >= (970) && afterResize < (970)) ||
- (xbeforeResize < (728) && afterResize >= (728)) ||
- (xbeforeResize >= (728) && afterResize < (728)) ||
- (xbeforeResize < (468) && afterResize >= (468))
- ||(xbeforeResize >= (468) && afterResize < (468))) {
- xbeforeResize = afterResize;
- googletag.cmd.push(function() {
- googletag.pubads().refresh([gptAdSlots[0]]);
- });
- }
- if (window.screen.availWidth <= 768) {
- restack(window.innerHeight > window.innerWidth);
- }
- fixDragBtn();
- }
- </script>
- <style>
- * {
- -webkit-box-sizing: border-box;
- -moz-box-sizing: border-box;
- box-sizing: border-box;
- }
- body {
- color:#000000;
- margin:0px;
- font-size:100%;
- }
- .trytopnav {
- height:40px;
- overflow:hidden;
- min-width:600px;
- position:absolute;
- width:100%;
- top:99px;
- }
- .w3-navbar button {
- border:none;
- padding:8px 16px;
- display:block;
- }
- a.w3schoolslink {
- padding:0 !important;
- display:inline !important;
- }
- a.w3schoolslink:hover,a.w3schoolslink:active {
- text-decoration:underline !important;
- background-color:transparent !important;
- }
- #dragbar{
- position:absolute;
- cursor: col-resize;
- z-index:3;
- padding:5px;
- }
- #shield {
- display:none;
- top:0;
- left:0;
- width:100%;
- position:absolute;
- height:100%;
- z-index:4;
- }
- #container {
- background-color:#f1f1f1;
- width:100%;
- overflow:auto;
- position:absolute;
- top:138px;
- bottom:0;
- height:auto;
- }
- #textareacontainer, #iframecontainer {
- float:left;
- height:100%;
- width:50%;
- }
- #textarea, #iframe {
- height:100%;
- width:100%;
- padding-bottom:10px;
- padding-top:1px;
- }
- #textarea {
- padding-left:10px;
- padding-right:5px;
- }
- #iframe {
- padding-left:5px;
- padding-right:10px;
- }
- #textareawrapper {
- width:100%;
- height:100%;
- background-color: #ffffff;
- position:relative;
- box-shadow:0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
- }
- #iframewrapper {
- width:100%;
- height:100%;
- -webkit-overflow-scrolling: touch;
- background-color: #ffffff;
- box-shadow:0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
- }
- #textareaCode {
- background-color: #ffffff;
- font-family: consolas,"courier new",monospace;
- font-size:15px;
- height:100%;
- width:100%;
- padding:8px;
- resize: none;
- border:none;
- line-height:normal;
- }
- textarea.textareaCC {
- background-color:transparent !important;
- z-index:2;
- position:relative;
- -webkit-text-fill-color: transparent;
- line-height:normal;
- }
- .codecolorCC {
- position:absolute;
- font-family: consolas,"courier new",monospace;
- font-size: 15px;
- height: 100%;
- width: 100%;
- padding: 8px;
- resize: none;
- border: none;
- z-index: 1;
- overflow-y:auto;
- word-wrap: break-word;
- line-height:normal;
- }
- #iframeResult, #iframeSource {
- background-color: #ffffff;
- height:100%;
- width:100%;
- }
- #stackV {background-color:#999999;}
- #stackV.horizontal,#stackV.horizontal {background-color:transparent;}
- #stackV.horizontal:hover {background-color:#d3d3d3;}
- #stackH,#stackH {background-color:transparent;}
- #stackH:hover {background-color:#d3d3d3;}
- #stackH.horizontal {background-color:#999999;}
- #textareacontainer.horizontal,#iframecontainer.horizontal{
- height:50%;
- float:none;
- width:100%;
- }
- #textarea.horizontal{
- height:100%;
- padding-left:10px;
- padding-right:10px;
- }
- #iframe.horizontal{
- height:100%;
- padding-right:10px;
- padding-bottom:10px;
- padding-left:10px;
- }
- #container.horizontal{
- min-height:200px;
- margin-left:0;
- }
- #tryitLeaderboard {
- overflow:hidden;
- text-align:center;
- margin-top:5px;
- height:90px;
- }
- @media screen and (max-width: 727px) {
- .trytopnav {top:70px;}
- #container {top:108px;}
- }
- @media screen and (max-width: 467px) {
- .trytopnav {top:60px;}
- #container {top:98px;}
- }
- @media only screen and (max-device-width: 768px) {
- #iframewrapper {overflow: auto;}
- #container {min-width:320px;}
- .stack {display:none;}
- }
- #iframewrapper {
- }
- </style>
- <!--[if lt IE 8]>
- <style>
- #textareacontainer, #iframecontainer {width:48%;}
- #container {height:500px;}
- #textarea, #iframe {width:90%;height:450px;}
- #textareaCode, #iframeResult {height:450px;}
- .stack {display:none;}
- </style>
- <![endif]-->
- </head>
- <body>
- <div id='tryitLeaderboard' style="background-color:#ffffff">
- <!-- TryitLeaderboard -->
- <div id='div-gpt-ad-1428407818244-0'>
- <script type='text/javascript'>googletag.cmd.push(function() {
- googletag.display('div-gpt-ad-1428407818244-0'); });</script>
- </div>
- </div>
- <div class="trytopnav">
- <ul class="w3-navbar w3-light-grey" style="border-top:1px solid #f1f1f1;">
- <li style="width:auto !important;float:left;"><span
- style="padding:8px 16px 8px 10px;display:block">Edit The
- Code:</span></li>
- <li class="stack" style="width:auto !important;float:left;"><button
- title="Vertically" onclick="restack(false)" id="stackV"><img
- src="/images/stack_vertically.png"></button></li>
- <li class="stack" style="width:auto !important;float:left;"><button
- title="Horizontally" onclick="restack(true)" id="stackH"><img
- src="/images/stack_horizontally.png"></button></li>
- <li style="width:auto !important;float:left;"><button
- class="w3-green w3-hover-white w3-hover-text-green"
- onclick="submitTryit()">See Result »</button></li>
- <li class="w3-right w3-hide-small"><span style="padding:8px
- 16px;display:block">Try it Yourself - © <a
- href="http://www.w3schools.com"
- class="w3schoolslink">w3schools.com</a></span></li>
- </ul>
- </div>
- <div id="shield"></div>
- <a href="javascript:void(0)" id="dragbar"></a>
- <div id="container">
- <div id="textareacontainer">
- <div id="textarea">
- <div id="textareawrapper">
- <div id="codecolor"></div>
- <textarea autocomplete="off" id="textareaCode" wrap="logical"
- spellcheck="false"><!DOCTYPE html>
- <html>
- <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
- <body>
- <div ng-app="myApp" ng-controller="customersCtrl">
- <table>
- <tr ng-repeat="x in names">
- <td>{{ x.Name }}</td>
- <td>{{ x.Country }}</td>
- </tr>
- </table>
- </div>
- <script>
- var app = angular.module('myApp', []);
- app.controller('customersCtrl', function($scope, $http) {
- $http.get("http://www.w3schools.com/angular/customers.php")
- .then(function (response) {$scope.names = response.data.records;});
- });
- </script>
- </body>
- </html>
- </textarea>
- <form autocomplete="off" style="margin:0px;display:none;">
- <input type="hidden" name="code" id="code" />
- <input type="hidden" id="bt" name="bt" />
- </form>
- </div>
- </div>
- </div>
- <div id="iframecontainer">
- <div id="iframe">
- <div id="iframewrapper"></div>
- </div>
- </div>
- </div>
- <script>
- submitTryit()
- function submitTryit() {
- var text = document.getElementById("textareaCode").value;
- var ifr = document.createElement("iframe");
- ifr.setAttribute("frameborder", "0");
- ifr.setAttribute("id", "iframeResult");
- document.getElementById("iframewrapper").innerHTML = "";
- document.getElementById("iframewrapper").appendChild(ifr);
- var ifrw = (ifr.contentWindow) ? ifr.contentWindow :
- (ifr.contentDocument.document) ? ifr.contentDocument.document :
- ifr.contentDocument;
- ifrw.document.open();
- ifrw.document.write(text);
- ifrw.document.close();
- //23.02.2016: contentEditable is set to true, to fix text-selection
- (bug) in firefox.
- //(and back to false to prevent the content from being editable)
- //(To reproduce the error: Select text in the result window with,
- and without, the contentEditable statements below.)
- if (ifrw.document.body && !ifrw.document.body.isContentEditable) {
- ifrw.document.body.contentEditable = true;
- ifrw.document.body.contentEditable = false;
- }
- }
- function restack(horizontal) {
- var tc, ic, t, i, c, f, sv, sh, d, height, flt, width;
- tc = document.getElementById("textareacontainer");
- ic = document.getElementById("iframecontainer");
- t = document.getElementById("textarea");
- i = document.getElementById("iframe");
- c = document.getElementById("container");
- sv = document.getElementById("stackV");
- sh = document.getElementById("stackH");
- tc.className = tc.className.replace("horizontal", "");
- ic.className = ic.className.replace("horizontal", "");
- t.className = t.className.replace("horizontal", "");
- i.className = i.className.replace("horizontal", "");
- c.className = c.className.replace("horizontal", "");
- sv.className = sv.className.replace("horizontal", "");
- sh.className = sh.className.replace("horizontal", "");
- stack = "";
- if (horizontal) {
- tc.className = tc.className + " horizontal";
- ic.className = ic.className + " horizontal";
- t.className = t.className + " horizontal";
- i.className = i.className + " horizontal";
- c.className = c.className + " horizontal";
- sv.className = sv.className + " horizontal";
- sh.className = sh.className + " horizontal";
- stack = " horizontal";
- document.getElementById("textareacontainer").style.height = "50%";
- document.getElementById("iframecontainer").style.height = "50%";
- document.getElementById("textareacontainer").style.width = "100%";
- document.getElementById("iframecontainer").style.width = "100%";
- } else {
- document.getElementById("textareacontainer").style.height = "100%";
- document.getElementById("iframecontainer").style.height = "100%";
- document.getElementById("textareacontainer").style.width = "50%";
- document.getElementById("iframecontainer").style.width = "50%";
- }
- fixDragBtn();
- }
- if (navigator.userAgent.indexOf("WebKit") > -1 &&
- navigator.userAgent.indexOf("Edge") == -1) {
- document.getElementById("codecolor").className += " codecolorCC";
- document.getElementById("textareaCode").className += " textareaCC";
- colorcoding();
- if (document.getElementById("textareaCode").addEventListener) {
- document.getElementById("textareaCode").addEventListener("input",
- colorcoding);
- document.getElementById("textareaCode").addEventListener("scroll",
- syncscroll);
- } else if (document.getElementById("textareaCode").attachEvent) {
- document.getElementById("textareaCode").attachEvent("oninput",
- colorcoding);
- document.getElementById("textareaCode").attachEvent("onscroll",
- syncscroll);
- }
- }
- function syncscroll() {
- document.getElementById("codecolor").scrollTop =
- document.getElementById("textareaCode").scrollTop;
- }
- function colorcoding() {
- var text = document.getElementById("textareaCode").value;
- text = text.replace(/&/g, "&");
- text = text.replace(/\t/g,
- " ");
- text = text.replace(/ /g, " ");
- text = text.replace(/</g, "<");
- text = text.replace(/>/g, ">");
- text = text.replace(/(?:\r\n|\r|\n)/g, '<br>');
- text = text.replace(/<br> /g, "<br> ");
- text = w3CodeColorize(text);
- document.getElementById("codecolor").innerHTML = text + "<br><br>";
- }
- var i = 0;
- var dragging = false;
- var buttonwidth;
- var stack;
- if ((window.screen.availWidth <= 768 && window.innerHeight >
- window.innerWidth) || "" == " horizontal") {restack(true);}
- function fixDragBtn() {
- var textareawidth, leftpadding, dragleft, containertop
- var containertop =
- Number(w3_getStyleValue(document.getElementById("container"),
- "top").replace("px", ""));
- if (stack != " horizontal") {
- document.getElementById("dragbar").style.width = "5px";
- textareasize =
- Number(w3_getStyleValue(document.getElementById("textareaCode"),
- "width").replace("px", ""));
- leftpadding =
- Number(w3_getStyleValue(document.getElementById("textarea"),
- "padding-left").replace("px", ""));
- buttonwidth =
- Number(w3_getStyleValue(document.getElementById("dragbar"),
- "width").replace("px", ""));
- textareaheight =
- w3_getStyleValue(document.getElementById("textareaCode"), "height");
- dragleft = textareasize + leftpadding + (leftpadding / 2) -
- (buttonwidth / 2);
- document.getElementById("dragbar").style.top = containertop + "px";
- document.getElementById("dragbar").style.left = dragleft + "px";
- document.getElementById("dragbar").style.height = textareaheight;
- document.getElementById("dragbar").style.cursor = "col-resize";
- } else {
- document.getElementById("dragbar").style.height = "5px";
- if (window.getComputedStyle) {
- textareawidth =
- window.getComputedStyle(document.getElementById("textareaCode"),null).getPropertyValue("height");
- textareaheight =
- window.getComputedStyle(document.getElementById("textareaCode"),null).getPropertyValue("width");
- leftpadding =
- window.getComputedStyle(document.getElementById("textarea"),null).getPropertyValue("padding-top");
- buttonwidth =
- window.getComputedStyle(document.getElementById("dragbar"),null).getPropertyValue("height");
- } else {
- dragleft =
- document.getElementById("textareaCode").currentStyle["width"];
- }
- textareawidth = Number(textareawidth.replace("px", ""));
- leftpadding = Number(leftpadding .replace("px", ""));
- buttonwidth = Number(buttonwidth .replace("px", ""));
- dragleft = containertop + textareawidth + leftpadding + (leftpadding / 2);
- document.getElementById("dragbar").style.top = dragleft + "px";
- document.getElementById("dragbar").style.left = "5px";
- document.getElementById("dragbar").style.width = textareaheight;
- document.getElementById("dragbar").style.cursor = "row-resize";
- }
- }
- function dragstart(e) {
- e.preventDefault();
- dragging = true;
- var main = document.getElementById("iframecontainer");
- }
- function dragmove(e) {
- if (dragging)
- {
- document.getElementById("shield").style.display = "block";
- if (stack != " horizontal") {
- var percentage = (e.pageX / window.innerWidth) * 100;
- if (percentage > 5 && percentage < 98) {
- var mainPercentage = 100-percentage;
- document.getElementById("textareacontainer").style.width =
- percentage + "%";
- document.getElementById("iframecontainer").style.width =
- mainPercentage + "%";
- fixDragBtn();
- }
- } else {
- var containertop =
- Number(w3_getStyleValue(document.getElementById("container"),
- "top").replace("px", ""));
- var percentage = ((e.pageY - containertop + 20) /
- (window.innerHeight - containertop + 20)) * 100;
- if (percentage > 5 && percentage < 98) {
- var mainPercentage = 100-percentage;
- document.getElementById("textareacontainer").style.height =
- percentage + "%";
- document.getElementById("iframecontainer").style.height =
- mainPercentage + "%";
- fixDragBtn();
- }
- }
- }
- }
- function dragend() {
- document.getElementById("shield").style.display = "none";
- dragging = false;
- }
- if (window.addEventListener) {
- document.getElementById("dragbar").addEventListener("mousedown",
- function(e) {dragstart(e);});
- document.getElementById("dragbar").addEventListener("touchstart",
- function(e) {dragstart(e);});
- window.addEventListener("mousemove", function(e) {dragmove(e);});
- window.addEventListener("touchmove", function(e) {dragmove(e);});
- window.addEventListener("mouseup", dragend);
- window.addEventListener("touchend", dragend);
- window.addEventListener("load", fixDragBtn);
- }
- function w3_getStyleValue(elmnt,style) {
- if (window.getComputedStyle) {
- return window.getComputedStyle(elmnt,null).getPropertyValue(style);
- } else {
- return elmnt.currentStyle[style];
- }
- }
- </script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment