Jump to content

Archived

This topic is now archived and is closed to further replies.

timjay

Uncaught TypeError: undefined is not a function

Recommended Posts

timjay    0
timjay

Whenever I try to use DMS with internal javascript I've added to a post, I get the error below, but it doesn't point to my code, it points to Pagelines.

 

I see this error in the error console and the DMS/page never loads. I get "Oops, there may be an issue loading."

 

 

Uncaught TypeError: undefined is not a function pl.editor.js?ver=fd67d8:17

 

 

 

 
17.    $.jQee('alt+a', function() {
 
$('[data-action="toggle-grid"]')
.trigger('click')
})
 

Share this post


Link to post
Share on other sites
timjay    0
timjay

Also, I have tried deactivating all plugins and get the same issue.

Share this post


Link to post
Share on other sites
Simon    247
Simon
What script did you add?

Share this post


Link to post
Share on other sites
timjay    0
timjay

I used javascript, jquery, and Google Charts/Map APIs. this happens on all those posts. So it isn't just one script.

 

Is there a tutorial on adding javascript to a post? Is it even possible to do this with DMS?

Share this post


Link to post
Share on other sites
Danny    1,327
Danny

Can you provide the code you're using so we can test this ourselves please.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
timjay    0
timjay

Below is exactly what I have pasted in the post, minus some of the <p> tags/content

 

CSS

 <style>
			html, body{
				width:100%;
				height:100%;
			}
			.mainSec{
				width:100%;
				height:100%;
				font-family: Cambria, Georgia, serif;

				
			}
			.mainContent{
					width:90%;
					height:100%;
			}
			.chartSec{
					position:relative;
					width:70%;
					height:400px;
					display:inline;
					float:left;
			}
			.charts{
					width:100%;
					height:100%;
				
			}
			.contentSec{
					width:28%;
					height:90%;
					float:right;
					border-left-style:solid;
					border-left-width:2px;
					border-color:#ABABAB;
					display:none;
					overflow-y:auto;
					background-color: #FAFAFA;
			}
			.contentHed{
				
				font-family: "arial";
				color:#636566;
				margin-bottom:20%;
				margin-top:3%;
				text-align:center;
			}
			.contentBody{
				padding:5%;
			}
			.points1{
				position:absolute;
				z-index:99;
				color:red;
				cursor:pointer;
				font-size:xx-large;
				display:none;	
			}
			.points2{
				position:absolute;
				z-index:99;
				color:red;
				cursor:pointer;
				font-size:xx-large;
				display:none;	
			}
			.points1:hover{
				color:#FF5959;
			}
			.points2:hover{
				color:#FF5959;
			}
			.menuOption{
				cursor:pointer;
				text-align:center;
				border-bottom-style:solid;
				border-bottom-width:2px;
				border-color:#ABABAB;
				padding-bottom:10%;
				margin-bottom:10%;
				margin-left:5%;
			}
			.menuOption:hover{
				background-color:#EBEEF0;
			}
			.backToIntro{
				cursor:pointer;
				margin-top:10%;
				float:right;
				color:#636566;
			}
			.backToIntro2{
				cursor:pointer;
				margin-top:10%;
				float:right;
				color:#636566;
			}
			.chartSelectContainer{
				z-index:99;
				margin-left:30%;
				margin-top:2%;
			}
			.chartSelect{
				display:inline;
				cursor:pointer;
				margin-left:2%;
			}
.buffer{
margin-bottom:70%;
}
			#contentShowIntro2{
				display:none;
			}
			#chartSec1{
				margin-top:3%;
			
			}
			#contentShowChart1Point1{
				display:none;
			}
		</style>

HTML

<section class="mainSec">
			<p>Description</p>

			

			<div class="mainContent">
				
				<div class="chartSelectContainer">
				<strong>Select:</strong> <div class="chartSelect" id="chicagoSelect" onclick="drawChart1()">City</div> | <div class="chartSelect" id="illinoisSelect" onclick="drawChart2()">State</div>
				</div>
				<div class="chartSec">
				
				<span class="points1" id="chart1Point1" onclick="annotate('ShowChart1Point1')" style="left:23%; top:18%;" title="Black drivers stopped more often">&#x2022;</span>
				<span class="points1" id="chart1Point2" onclick="annotate('ShowChart1Point2')" style="left:51%; top:37%;" title="Blacks, Latinos searched more">&#x2022;</span>
				<span class="points1" id="chart1Point3" onclick="annotate('ShowChart1Point3')" style="left:70%; top:33%;" title="White drivers more likely to have contraband">&#x2022;</span>
				<span class="points2" id="chart2Point1" onclick="annotate('ShowChart2Point1')" style="left:17%; top:27%;" title="White drivers more likely to be stopped">&#x2022;</span>
				<span class="points2" id="chart2Point2" onclick="annotate('ShowChart2Point2')" style="left:50%; top:47%;" title="Black drivers more likely to be searched">&#x2022;</span>
				<span class="points2" id="chart2Point3" onclick="annotate('ShowChart2Point3')" style="left:70%; top:33%;" title="Overall Decrease">&#x2022;</span>
					<div class="charts" id="chartSec1"></div>
					<div class="charts" id="chartSec2"></div>
<p style="font-size:small;"> <strong>Source:</strong> American Civil Liberties Union Illinois</p>
				</div> <!--ends chartSec -->
				<div class="contentSec" id="contentShowIntro">	
					<h2 class="contentHed"> Title</h2>
					<div class="menuOption" id="menuchart1Point1"  onclick="annotate('ShowChart1Point1')"> Option1</div>
					<div class="menuOption" id="menuchart1Point2"  onclick="annotate('ShowChart1Point2')"> Option2</div>
					<div class="menuOption" id="menuchart1Point3"  onclick="annotate('ShowChart1Point3')"> Option3</div>
				</div> <!--ends contentSec -->
				<div class="contentSec" id="contentShowIntro2">	
					<h2 class="contentHed"> Title</h2>
					<div class="menuOption" id="menuchart2Point1"  onclick="annotate('ShowChart2Point1')"> Option </div>
					<div class="menuOption" id="menuchart2Point2"  onclick="annotate('ShowChart2Point2')"> Option</div>
					<div class="menuOption" id="menuchart2Point3"  onclick="annotate('ShowChart2Point3')"> Option</div>
				</div> <!--ends contentSec -->
				<div class="contentSec" id="contentShowChart1Point1">	
					<h2 class="contentHed">Title</h2>
					<div class="contentBody">
						<div class="backToIntro">Back to intro</div>
					</div>
				</div> <!-- ends contentShowChart1Point1 -->
				<div class="contentSec" id="contentShowChart1Point2">	
					<h2 class="contentHed">Title</h2>
					<div class="contentBody">
						
						<div class="backToIntro">Back to intro</div>
					</div>
				</div>
				<div class="contentSec" id="contentShowChart1Point3">	
					<h2 class="contentHed">Title</h2>
					<div class="contentBody">
						
						<div class="backToIntro">Back to intro</div>
					</div>
				</div>
				<div class="contentSec" id="contentShowChart2Point1">	
					<h2 class="contentHed">title</h2>
					<div class="contentBody">
						
						<div class="backToIntro2">Back to intro</div>
					</div>
				</div>
				<div class="contentSec" id="contentShowChart2Point2">	
					<h2 class="contentHed"> Title</h2>
					<div class="contentBody">
						
						<div class="backToIntro2">Back to intro</div>
					</div>
				</div>
				<div class="contentSec" id="contentShowChart2Point3">	
					<h2 class="contentHed">Title</h2>
					<div class="contentBody">
						
						<div class="backToIntro2">Back to intro</div>
					</div>
				</div>
			</div><!-- ends mainContent -->
			
		</section><!--ends mainSec-->

<div class="buffer"></div>

Javascript

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
	  <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
	<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>	
	<script type="text/javascript">
	
		var fadeTime = 1000;
		var delay = 1000;
		var originalSelectedColor = 'black';
		var newSelectedColor = 'red';
		var newOptionColor = '#EBEEF0';
		var newDotColor='yellow';
		// Load the Visualization API library (latest is always 1.0) and the corechart library (pie, bar, column), other libaries require an action value.
			google.load('visualization', '1.0', {'packages':['corechart']});
			//now that libaries are loaded, tell DOM to draw chart--commented out, because in this case we want a user click to initiate drawchart function, not the loading of library
			google.setOnLoadCallback(drawChart1);
		function drawChart1() {
			/*var charts = document.getElementsByClassName('chartSec');
			$(charts).css('display', 'none');
			var current = document.getElementById('chartSec1')
			$(current).fadeIn(fadeTime); 
			
			var content = document.getElementsByClassName('contentSec');
			$(content).css('display', 'none');
			var intro = document.getElementById('intro1')
			$(intro).fadeIn(fadeTime); 
			
			var points2 = document.getElementsByClassName('points2');
			$(points2).css('display', 'none');
			var points3 = document.getElementsByClassName('points3');
			$(points3).css('display', 'none');
			
			var points1 = document.getElementsByClassName('points1');
			$(points1).fadeIn(fadeTime);
			*/
			var selectedChart = document.getElementById('chicagoSelect')
			$(selectedChart).css('color', newSelectedColor);
			
			var deSelectedChart = document.getElementById('illinoisSelect')
			$(deSelectedChart).css('color', originalSelectedColor);
			
			var charts = document.getElementsByClassName('charts');
			$(charts).css('display', 'none');
			var current = document.getElementById('chartSec1')
			$(current).fadeIn(fadeTime);
			
			var contentSecs = document.getElementsByClassName('contentSec');
			$(contentSecs).css('display', 'none');
			var currentContent = document.getElementById('contentShowIntro')
			$(currentContent).fadeIn(fadeTime).delay( delay );
			
			var points = document.getElementsByClassName('points2');
			$(points).css('display', 'none');
			var currentPoints = document.getElementsByClassName('points1')
			$(currentPoints).fadeIn(fadeTime).delay( delay );
			
			// Create the data table: call standard api function and place in data variable, create columns with value type and text, then rows with appropriate values. data format varies by chart--bar and pie have 2 columns, one for labes, one for value | You can also use "data queries" to fetch data from a google spreadsheet
			var data = new google.visualization.DataTable();
			data.addColumn('string', 'Traffic');
			data.addColumn('number', 'White');
			data.addColumn({type: 'string', role: 'annotation'});
			data.addColumn('number', 'Black');
			data.addColumn({type: 'string', role: 'annotation'});
			data.addColumn('number', 'Latino');
			data.addColumn({type: 'string', role: 'annotation'});
			data.addRows([
				['Stopped', 29, '29%', 44, '44%', 21, '21%'],
				['Consent Searched', .54, '.54%', 2.48, '2.5%',2.33, '2.3%'], 
				['Found with Contraband', 22, '22%', 17.71, '18%', 14.78, '15%']
			]);
			
		  
		   // Set chart options | you can specify height and width either here (default is px numer value, use string for percents) or in the containing html div, but must be specified somewhere
			var options = {
				'title':"Racial Disparities in Chicago Traffic Stops (2008-2013)",
				'colors': ['#AED2E9', '#103752', '#0A98F7'],
				'legend': {position: 'bottom', textStyle: {color: '#636566', fontSize: 14}
							},
				 vAxis: {
            logScale: true
        },
				'titleTextStyle':{ 
					'color': '#636566',
					//fontName: <string>,
					'fontSize': 24,
					'bold': true,
					'italic': false
				 },
				 annotations: {
					textStyle: {
					  //fontName: 'Times-Roman',
					  //fontSize: 18,
					  'bold': false,
					  //italic: true,
					  'color': 'gray',     // The color of the text.
					  'auraColor': 'none', // The color of the text outline.
					  'opacity': 0.9          // The transparency of the text.
					}
				},
				'tooltip' : {
					'trigger': 'none'
				}
			};
			
			
			// Instantiate and draw chart
			// first call correct chart function and apply it to correct div in DOM | then draw chart using options and data from above
			var chart = new google.visualization.ColumnChart(document.getElementById('chartSec1'));
			chart.draw(data, options);
			
		/*	window.onresize=function(){
				
				chart.draw(data, options);
			};*/
			
			$( window ).resize(function() {
				chart.draw(data, options);
			}); 
			
		} //end drawChart1() function
		// Google charts are naturally unresponsive because they load once, add this code to regenerate the chart each time the window resizes
			
		function drawChart2() {
			/*var charts = document.getElementsByClassName('chartSec');
			$(charts).css('display', 'none');
			var current = document.getElementById('chartSec1')
			$(current).fadeIn(fadeTime); 
			
			var content = document.getElementsByClassName('contentSec');
			$(content).css('display', 'none');
			var intro = document.getElementById('intro1')
			$(intro).fadeIn(fadeTime); 
			
			var points2 = document.getElementsByClassName('points2');
			$(points2).css('display', 'none');
			var points3 = document.getElementsByClassName('points3');
			$(points3).css('display', 'none');
			
			var points1 = document.getElementsByClassName('points1');
			$(points1).fadeIn(fadeTime);
			*/
			var selectedChart = document.getElementById('illinoisSelect')
			$(selectedChart).css('color', newSelectedColor);
			
			var deSelectedChart = document.getElementById('chicagoSelect')
			$(deSelectedChart).css('color', originalSelectedColor);
			
			var charts = document.getElementsByClassName('charts');
			$(charts).css('display', 'none');
			var current = document.getElementById('chartSec2')
			$(current).fadeIn(fadeTime);
			
			var contentSecs = document.getElementsByClassName('contentSec');
			$(contentSecs).css('display', 'none');
			var currentContent = document.getElementById('contentShowIntro2')
			$(currentContent).fadeIn(fadeTime).delay( delay );
			
			var points = document.getElementsByClassName('points1');
			$(points).css('display', 'none');
			var currentPoints2 = document.getElementsByClassName('points2')
			$(currentPoints2).fadeIn(fadeTime).delay( delay );
			
			// Create the data table: call standard api function and place in data variable, create columns with value type and text, then rows with appropriate values. data format varies by chart--bar and pie have 2 columns, one for labes, one for value | You can also use "data queries" to fetch data from a google spreadsheet
			var data = new google.visualization.DataTable();
			data.addColumn('string', 'Traffic');
			data.addColumn('number', 'White');
			data.addColumn({type: 'string', role: 'annotation'});
			data.addColumn('number', 'Black');
			data.addColumn({type: 'string', role: 'annotation'});
			data.addColumn('number', 'Latino');
			data.addColumn({type: 'string', role: 'annotation'});
			data.addRows([
				['Stopped', 67, '67%', 18, '18%', 12, '12%'],
				['Consent Searched', .72, '.72%', 1.55, '1.6%', 1.45, '1.5'], 
				['Found with Contraband', 25, '25.31%', 18.52, '19%', 14.75, '15%']
			]);
			
		  
		   // Set chart options | you can specify height and width either here (default is px numer value, use string for percents) or in the containing html div, but must be specified somewhere
			var options = {
				'title':"Racial Disparities in Illinois Traffic Stops (2008-2013)",
				'colors': ['#C8DBDB', '#4C7C7D', '#91BEBF'],
				'legend': {position: 'bottom', textStyle: {color: '#636566', fontSize: 14}},
				 vAxis: {
            logScale: true
        },
				'titleTextStyle':{ 
					'color': '#636566',
					//fontName: <string>,
					'fontSize': 24,
					'bold': true,
					'italic': false
				 },
				 annotations: {
					textStyle: {
					  //fontName: 'Times-Roman',
					  //fontSize: 18,
					  'bold': false,
					  //italic: true,
					  'color': 'gray',     // The color of the text.
					  'auraColor': 'none', // The color of the text outline.
					  'opacity': 0.9          // The transparency of the text.
					}
				},
				'tooltip' : {
					'trigger': 'none'
				}
			};
			
			
			// Instantiate and draw chart
			// first call correct chart function and apply it to correct div in DOM | then draw chart using options and data from above
			var chart = new google.visualization.ColumnChart(document.getElementById('chartSec2'));
			chart.draw(data, options);
			
		/*	window.onresize=function(){
				
				chart.draw(data, options);
			};*/
			
			$( window ).resize(function() {
				chart.draw(data, options);
			}); 
			
		} //end drawChart2() function
		
			
		var dotHover = document.getElementsByClassName('points1');
			var menuColor='';
			$(dotHover).mouseenter(
				function() {
					var dotID = $(this).attr('id');
					var menuOptionID = 'menu'+dotID 
					var menuOption = document.getElementById(menuOptionID);
					$(menuOption).css('background-color', newOptionColor);	
				}
			).mouseleave(
				function() {
					var dotID = $(this).attr('id');
					var menuOptionID = 'menu'+dotID 
					var menuOption = document.getElementById(menuOptionID);
					$(menuOption).css('background-color', menuColor);	
				}
			);
	
	var dotHover2 = document.getElementsByClassName('points2');
			var menuColor='';
			$(dotHover2).mouseenter(
				function() {
					var dotID = $(this).attr('id');
					var menuOptionID = 'menu'+dotID 
					var menuOption = document.getElementById(menuOptionID);
					$(menuOption).css('background-color', newOptionColor);	
				}
			).mouseleave(
				function() {
					var dotID = $(this).attr('id');
					var menuOptionID = 'menu'+dotID 
					var menuOption = document.getElementById(menuOptionID);
					$(menuOption).css('background-color', menuColor);	
				}
			);
			
			var optionHover = document.getElementsByClassName('menuOption');
			var dotColor='';
			$(optionHover).mouseenter(
				function() {
					var optionID = $(this).attr('id');
					var dotOptionID = optionID.replace('menu',''); 
					var dotOption = document.getElementById(dotOptionID);
					$(dotOption).css('color', newDotColor);	
				}
			).mouseleave(
				function() {
					var optionID = $(this).attr('id');
					var dotOptionID = optionID.replace('menu',''); 
					var dotOption = document.getElementById(dotOptionID);
					$(dotOption).css('color', dotColor);	
				}
			);

	var introLink = document.getElementsByClassName('backToIntro');
		$(introLink).click(function(){
			var content = document.getElementsByClassName('contentSec');
			$(content).fadeOut().delay( 500 );
			
			var showIntro = document.getElementById('contentShowIntro');
			$(showIntro).slideDown();
			
		});
	var introLink2 = document.getElementsByClassName('backToIntro2');
		$(introLink2).click(function(){
			var content2 = document.getElementsByClassName('contentSec');
			$(content2).fadeOut().delay( 500 );
			
			var showIntro2 = document.getElementById('contentShowIntro2');
			$(showIntro2).slideDown();
			
		});
		
		function annotate(id){
		
			//hide other content
			var content = document.getElementsByClassName('contentSec');
			$(content).fadeOut().delay( 500 );
	
			//create div id using button imput
			var contentId = "content"+id;
			
			//show appropriate id
			var showContent = document.getElementById(contentId);
			$(showContent).slideDown();		
		};
		

</script> 

Share this post


Link to post
Share on other sites
Danny    1,327
Danny

You don't add CSS or JavaScript to a post, you should add them to the correct locations such as adding CSS to the CSS editor in the DMS toolbar, the same goes for JavaScript. The only thing added to your post should really only be HTML and text.

 

However, in regards to the JavaScript, I would recommend adding it to a child theme, via the functions.php file in that child theme and enqueue it. You can use the child theme I created here - http://dannyholt.github.io/skeleton and learn how to add JavaScript correctly here - http://codex.wordpress.org/Function_Reference/wp_enqueue_script


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
timjay    0
timjay

The code is for the individual post. Why would I add it to functions.php or the CSS editor which apply it to the entire site? 

Share this post


Link to post
Share on other sites
Danny    1,327
Danny

Well you cannot or should not add code like that to a WordPress page or post via the content editor. As you will likely have validation issues, so that is why WordPress includes a enqueue function, which you can use conditionals so that the script or CSS will only load for that page or post or category etc...

If you're unsure on how to enqueue your scripts with conditionals, then I recommend you post this question on the WordPress support forums, as it is WordPress related.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
timjay    0
timjay

hmm. No that doesn't sound right. WP Enqueue is the preferred method for adding javascript to the header for sitewide usage. It is not generally feasible to constantly add new enqueues for every individual post or page I want. In fact for single post/page usage the Wordpress codex recommends at least adding javascript to a separate file and calling it from within the post, and so do others. I've done that and still get the error.

 

Are you sure that adding enqueues will fix the "Uncaught TypeError: undefined is not a function pl.editor.js?ver=fd67d8"  error I am seeing?

 

And are you aware of anyone, including Pageline programmers, who successfully use javascript for individual posts on a regular basis using DMS? I can't be the only one in this position. Are they using the enqueue method?

 

 

Share this post


Link to post
Share on other sites
Simon    247
Simon

And are you aware of anyone, including Pageline programmers, who successfully use javascript for individual posts on a regular basis using DMS? I can't be the only one in this position. Are they using the enqueue method?

 

Thats what conditionals are for....

 

<?php 

 

if( is_page( 123 ) {

 

ob_start() ?>

...

...

... your 1000 lines of css/js

...

...

...

<?php echo ob_get_contents();

}

Share this post


Link to post
Share on other sites
timjay    0
timjay

Is there no more convenient way to do this?

 

Can custom scripts editor be used for single posts?

 

 

Share this post


Link to post
Share on other sites
Danny    1,327
Danny

You can not add scripts on a per page basis via the Custom Scripts panel, you need to use the enqueue function via a child themes functions.php file.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites

  • Similar Content

    • JawDesigns
      By JawDesigns
      Hi everyone,
      Flywheel have reported errors on my clients site 'www.racewaredirect.co.uk' and it's not loading. Can someone please provide some information on how to fix this? The site has never experienced these issues before.
      Thanks,
      James Wilson
    • MissT
      By MissT+
      Hi there,
      I've got an issue with 3 websites built with DMS since I migrated them from http to https that I need help with please.
      When any changes are made - e.g. new posts added or existing posts amended - certain sections of the live site seem to break e.g. image headers hang and don't load (b/g on canvas section), sliders hang and don't load (Revslider), flipper section doesn't load.
      Logging in and then clicking 'Edit the site using DMS' seems to fix the problem. Often if I try to open up another browser window to edit the site / re publish I'm unable to as the page wont load / hangs while trying to load.
      Any ideas how to fix this? On a couple of the sites I've installed a caching plugin as I thought it might be a loading speed issue but it's still happening.
      Website URL's can be provided privately.
      Many thanks in advance.
    • jeomiland
      By jeomiland+
      Hi
      I found this topic
      which talks about a similar issue I am having, but a little different. Hope someone can help me out.
      Best way to see the problem is to view http://cassclayton.com/ on Safari (Mac) compared to Firefox or Chrome. You will see the banner just under the fixed menubar has a gap between the menubar and top of the banner. Looking at Inspector, I found:
      <div class="fixed-top-pusher" style="height: 62px;"></div>
      <script> jQuery('.fixed-top-pusher').height( jQuery('.pl-fixed-top').height() ) </script>
      and indeed it seems the jquery is not always working consistently. For instance, if you simply refresh the page in Safari, it will loose the gap and all looks fine, so is it a browser cache issue that is interacting with the jquery? I do have W3 Total Cache installed. There must be a way to tell the code to make sure jquery is up and running and available to do it's majic?
      And perhaps there is just a better way to do this banner? Originally I tried several DMS sections and used the banner image as background, etc... Kept running into problems with resizing and the left/right parts of the image were getting chopped off. It is important the whole image show, so currently I just use a NextBox section with this code:
      <img src="[pl_site_url]/wp-content/uploads/2015/12/CassClayton-blues-tribute-banner.jpg" width="100%" />
      and it looks the way it should. Is there a better way to place a banner graphic under a fixed navbar and make sure the whole banner graphic displays regardless of screensize?
       
    • oseehys
      By oseehys+
      Hello There,
      So i want to use platform 5 and DMS sections on a single page, i am using a child theme with pinspro as my main theme and i activated platform 5, the only problem am having so far is the fixed option, my navbars are not aligning to their default size, and it will be great if platform 5 header and footer section will function, has anyone used this option, how can i make the best use of platform 5 and DMS on a site
      Cheers
×