`); let searchUrl = `/search/`; history.forEach((elem) => { prevsearch.find('#prevsearch-options').append(`
${elem}
`); }); } $('#search-pretype-options').empty(); $('#search-pretype-options').append(prevsearch); let prevbooks = $(false); [ {title:"Recently Opened Textbooks", books:previous_books}, {title:"Recommended Textbooks", books:recommended_books} ].forEach((book_segment) => { if (Array.isArray(book_segment.books) && book_segment.books.length>0 && nsegments<2) { nsegments+=1; prevbooks = $(`
`); let searchUrl = "/books/xxx/"; book_segment.books.forEach((elem) => { prevbooks.find('#prevbooks-options'+nsegments.toString()).append(`
${elem.title}
${ordinal(elem.edition)} ${elem.author}
`); }); } $('#search-pretype-options').append(prevbooks); }); } function anon_pretype() { let prebooks = null; try { prebooks = JSON.parse(localStorage.getItem('PRETYPE_BOOKS_ANON')); }catch(e) {} if ('previous_books' in prebooks && 'recommended_books' in prebooks) { previous_books = prebooks.previous_books; recommended_books = prebooks.recommended_books; if (typeof PREVBOOKS !== 'undefined' && Array.isArray(PREVBOOKS)) { new_prevbooks = PREVBOOKS; previous_books.forEach(elem => { for (let i = 0; i < new_prevbooks.length; i++) { if (elem.id == new_prevbooks[i].id) { return; } } new_prevbooks.push(elem); }); new_prevbooks = new_prevbooks.slice(0,3); previous_books = new_prevbooks; } if (typeof RECBOOKS !== 'undefined' && Array.isArray(RECBOOKS)) { new_recbooks = RECBOOKS; for (let j = 0; j < new_recbooks.length; j++) { new_recbooks[j].viewed_at = new Date(); } let insert = true; for (let i=0; i < recommended_books.length; i++){ for (let j = 0; j < new_recbooks.length; j++) { if (recommended_books[i].id == new_recbooks[j].id) { insert = false; } } if (insert){ new_recbooks.push(recommended_books[i]); } } new_recbooks.sort((a,b)=>{ adate = new Date(2000, 0, 1); bdate = new Date(2000, 0, 1); if ('viewed_at' in a) {adate = new Date(a.viewed_at);} if ('viewed_at' in b) {bdate = new Date(b.viewed_at);} // 100000000: instead of just erasing the suggestions from previous week, // we just move them to the back of the queue acurweek = ((new Date()).getDate()-adate.getDate()>7)?0:100000000; bcurweek = ((new Date()).getDate()-bdate.getDate()>7)?0:100000000; aviews = 0; bviews = 0; if ('views' in a) {aviews = acurweek+a.views;} if ('views' in b) {bviews = bcurweek+b.views;} return bviews - aviews; }); new_recbooks = new_recbooks.slice(0,3); recommended_books = new_recbooks; } localStorage.setItem('PRETYPE_BOOKS_ANON', JSON.stringify({ previous_books: previous_books, recommended_books: recommended_books })); build_popup(); } } var whiletyping_search_object = null; var whiletyping_search = { books: [], curriculum: [], topics: [] } var single_whiletyping_ajax_promise = null; var whiletyping_database_initial_burst = 0; //number of consecutive calls, after 3 we start the 1 per 5 min calls function get_whiletyping_database() { //gets the database from the server. // 1. by validating against a local database value we confirm that the framework is working and // reduce the ammount of continuous calls produced by errors to 1 per 5 minutes. return localforage.getItem('whiletyping_last_attempt').then(function(value) { if ( value==null || (new Date()) - (new Date(value)) > 1000*60*5 || (whiletyping_database_initial_burst < 3) ) { localforage.setItem('whiletyping_last_attempt', (new Date()).getTime()); // 2. Make an ajax call to the server and get the search database. let databaseUrl = `/search/whiletype_database/`; let resp = single_whiletyping_ajax_promise; if (resp === null) { whiletyping_database_initial_burst = whiletyping_database_initial_burst + 1; single_whiletyping_ajax_promise = resp = new Promise((resolve, reject) => { $.ajax({ url: databaseUrl, type: 'POST', data:{csrfmiddlewaretoken: "09tFiepnsJNJtQRnSO5yvrZGSyVwJYUeu1gFOxnPLP2xwPLzL1yhayUPjYmL0KG5"}, success: function (data) { // 3. verify that the elements of the database exist and are arrays if ( ('books' in data) && ('curriculum' in data) && ('topics' in data) && Array.isArray(data.books) && Array.isArray(data.curriculum) && Array.isArray(data.topics)) { localforage.setItem('whiletyping_last_success', (new Date()).getTime()); localforage.setItem('whiletyping_database', data); resolve(data); } }, error: function (error) { console.log(error); resolve(null); }, complete: function (data) { single_whiletyping_ajax_promise = null; } }) }); } return resp; } return Promise.resolve(null); }).catch(function(err) { console.log(err); return Promise.resolve(null); }); } function get_whiletyping_search_object() { // gets the fuse objects that will be in charge of the search if (whiletyping_search_object){ return Promise.resolve(whiletyping_search_object); } database_promise = localforage.getItem('whiletyping_database').then(function(database) { return localforage.getItem('whiletyping_last_success').then(function(last_success) { if (database==null || (new Date()) - (new Date(last_success)) > 1000*60*60*24*30 || (new Date('2023-04-25T00:00:00')) - (new Date(last_success)) > 0) { // New database update return get_whiletyping_database().then(function(new_database) { if (new_database) { database = new_database; } return database; }); } else { return Promise.resolve(database); } }); }); return database_promise.then(function(database) { if (database) { const options = { isCaseSensitive: false, includeScore: true, shouldSort: true, // includeMatches: false, // findAllMatches: false, // minMatchCharLength: 1, // location: 0, threshold: 0.2, // distance: 100, // useExtendedSearch: false, ignoreLocation: true, // ignoreFieldNorm: false, // fieldNormWeight: 1, keys: [ "title" ] }; let curriculum_index={}; let topics_index={}; database.curriculum.forEach(c => curriculum_index[c.id]=c); database.topics.forEach(t => topics_index[t.id]=t); for (j=0; j
${elem.title}
${ordinal(elem.edition)} ${elem.author}
${elem.title}
`); }); } $('#search-pretype-options').append(courses_section); if (Array.isArray(whiletyping_search.topics) && whiletyping_search.topics.length>0) { var topics_section = $(``); let searchUrl = "/topics/xxx/"; whiletyping_search.topics.forEach((elem) => { topics_section.find('#whiletyping-topics').append(` ${elem.title} `); }); } $('#search-pretype-options').append(topics_section); } function build_popup(first_time = false) { if ($('#search-text').val()=='') { build_pretype(); if (first_time) { do_whiletyping_search(); } } else { do_whiletyping_search().then((success) => { if (success) { build_whiletyping(); } else { build_pretype(); } }).catch((err) => { console.log(err); build_pretype(); }); } } var search_text_out = true; var search_popup_out = true; const is_login = false; function pretype_setup() { $('#search-text').focusin(function() { $('#search-popup').addClass('show'); resize_popup(); search_text_out = false; }); $( window ).resize(function() { resize_popup(); }); $('#search-text').focusout(() => { search_text_out = true; if (search_text_out && search_popup_out) { $('#search-popup').removeClass('show'); } }); $('#search-popup').mouseenter(() => { search_popup_out = false; }); $('#search-popup').mouseleave(() => { search_popup_out = true; if (search_text_out && search_popup_out) { $('#search-popup').removeClass('show'); } }); $('#search-text').on("keyup", function() { build_popup(); }); build_popup(true); let prevbookUrl = `/search/pretype_books/`; if (is_login) { $.ajax({ url: prevbookUrl, method: 'POST', data:{csrfmiddlewaretoken: "09tFiepnsJNJtQRnSO5yvrZGSyVwJYUeu1gFOxnPLP2xwPLzL1yhayUPjYmL0KG5"}, success: function(response){ previous_books = response.previous_books; recommended_books = response.recommended_books; build_popup(); }, error: function(response){ console.log(response); } }); } else { let prebooks = null; try { prebooks = JSON.parse(localStorage.getItem('PRETYPE_BOOKS_ANON')); }catch(e) {} if (prebooks && 'previous_books' in prebooks && 'recommended_books' in prebooks) { anon_pretype(); } else { $.ajax({ url: prevbookUrl, method: 'POST', data:{csrfmiddlewaretoken: "09tFiepnsJNJtQRnSO5yvrZGSyVwJYUeu1gFOxnPLP2xwPLzL1yhayUPjYmL0KG5"}, success: function(response){ previous_books = response.previous_books; recommended_books = response.recommended_books; build_popup(); }, error: function(response){ console.log(response); } }); } } } $( document ).ready(pretype_setup);
FAQs
How do you know when your Grignard reagent is ready? ›
The final Grignard mixture should be cloudy and most of the Mg metal should be gone. Cool the mixture to room temperature and then add enough anhydrous diethyl ether to give a final of volume of about 40 mL in the reaction flask. The Grignard reagent must be used immediately after it has cooled.
What is the conclusion of the Grignard reagent? ›To conclude, the reaction of magnesium with alkyl or aryl halides gives the Grignard reagent as a product, which is quite useful in the synthesis of alcohols, aldehydes or ketones. The Grignard reaction can also facilitate the formation of carbon-carbon bonds.
How do you prepare a Grignard reagent? ›The preparation of a Grignard reagent
Grignard reagents are made by adding the halogenoalkane to small bits of magnesium in a flask containing ethoxyethane (commonly called diethyl ether or just "ether"). The flask is fitted with a reflux condenser, and the mixture is warmed over a water bath for 20 - 30 minutes.
When a Grignard reagent reacts with water, a proton replaces the halogen, and the product is an alkane. The Grignard reagent therefore provides a pathway for converting a haloalkane to an alkane in two steps.
How do you prepare a Grignard reagent quizlet? ›How do you prepare a Grignard reagent? React an organohalide with magnesium metal. A Grignard reaction is the reaction between a Grignard reagent and... a carbonyl-containing compound.
What causes a Grignard reaction to fail? ›The problem here is that Grignard reagents are strong bases, and will react with even weak acids (like alcohols). If we try to make a Grignard on a molecule with an acidic functional group, we'll end up destroying our Grignard instead.
What reaction does a Grignard reagent show? ›The Grignard reaction (French: [ɡʁiɲaʁ]) is an organometallic chemical reaction in which carbon alkyl, allyl, vinyl, or aryl magnesium halides (Grignard reagent) are added to the carbonyl groups of either an aldehyde or ketone. This reaction is important for the formation of carbon–carbon bonds.
Why Grignard reagent should be prepared? ›(a) Grignard reagents are very reactive. In the presence of moisture, they react to give alkanes. Therefore, Grignard reagents should be prepared under anhydrous conditions.
What is the purpose of the Grignard reaction experiment? ›The purpose of this experiment was to reduce the carbonyl-containing compound benzophenone to the alcohol compound trimethylmethanol. This reduc- tion was done by the nucleophilic addition of the Grignard reagent: phenyl magnesium bromide, in a nonreactive ethyl ether solution.
What temperature is Grignard reagent prepared at? ›Functionalized Grignard reagents were successfully prepared by direct oxidative addition to aryl bromide substrates containing a nitrile, ester, or chloride group using highly active magnesium (Rieke magnesium) at low temperature (-78 °C).
What is the general method of preparation of alcohol by Grignard reagent? ›
Grignard Synthesis
The reaction of the Grignard reagent with formaldehyde leads to primary alcohols, that with aldehydes other than formaldehyde yield secondary alcohols and that with ketones give tertiary alcohols.
Water can destroy all or some of your Grignard reagent by acting as an acid. Remember that many good nucleophiles are also good bases. Since water is a strong acid, it can protontate the Grignard reagent to yield its conjugate acid, effectively derailing your reaction.
What happens when Grignard reagent reacts with dry ice? ›Grignard reagent reacts with solid CO2 (dry ice) to form magnesium salt of carboxylic acid. This is followed by acidification to obtain carboxylic acid. For example, the reaction between methyl magnesium bromide and carbon dioxide followed by acid hydrolysis will give acetic acid.
How is Grignard reagent prepared and what happens when it is hydrolysed? ›A Grignard reagent is treated with oxygen to create magnesium organo peroxide. When this compound is hydrolyzed, hydroperoxides or alcohol is formed.
How do you activate Grignard reagent? ›Activation of the magnesium surface is often necessary for successful Grignard reactions. A common practice is the use of small quantities of iodine or 1,2-dibromoethane as activating additives, which induce initiation of the reaction.
What observations will help you know that the Grignard reaction has started? ›6. Immediately assemble the apparatus and start to heat it gently. Before adding the remaining bromobenzene solution, you should observe signs of reaction initiation in the flask 3. These signs include appearance of bubbles on the Mg surface, cloudiness and disappearance of the purple iodine color.
What makes a good Grignard reagent? ›Grignard reagents are formed by the reaction of magnesium metal with alkyl or alkenyl halides. They're extremely good nucleophiles, reacting with electrophiles such as carbonyl compounds (aldehydes, ketones, esters, carbon dioxide, etc) and epoxides.
Why in the preparation of Grignard reagent all the starting material must be dry? ›Complete answer: (a) Grignard reagents are very reactive. In the presence of moisture, they react to give alkanes. Therefore, Grignard reagents should be prepared under anhydrous conditions.