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

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

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

Share this post


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

Share this post


Link to post
Share on other sites
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

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

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

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

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

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

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

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

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

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

    • romanondrasek
      By romanondrasek+
      Hi, I just found that my site is not working - nothing to see what I have activated PL5 tap late (just white screen :-() , I can open just admin site . I tried to activate different template (tventy seventeen) and was working , but not with PL5. 
      could you pls let me know what is the problem ASAP 
       
      the site is : www.myfit.cz
      than you so much
       
    • Steve Webb
      By Steve Webb+
      I have a staging site up that I have been working on, and tonight was having PL5 account connection issues:
       
       
      I refreshed, didn't work, so I followed instructions and disconnected and clicked connect to get a new token, and got white screen with the following php error:
      Can someone tell me what I'm doing wrong?  
      https://staging2.imetropol.com/
    • Steve Webb
      By Steve Webb+
      I am having an issue with DMS editor not loading.  Just keeps spinning and spinning.
      Have tried several things - Logged in and out, cleared cache, deactivated all plugins, but the issue persists.
      I even had our host restore from a backup a few weeks ago, when I know it WAS working, as I edited a text box on the homepage.  The restore from backup didn't help either.
      Also, the front end of the site shows that the site is framed, or boxed now (whatever you call it), instead of full width as it was previously (last week).
      Dev console shows that there are php errors in Google maps - file is attached.
      Can someone please help?  Not sure what else I can do here...
      Thanks in advance.
      -Matt

    • tuciudadenred
      By tuciudadenred+
      Hi everyone, what happens is that the web page metrosalarmas.com has a google tags which I have not attacked where I can look to remove those tags and be able to locate the correct ones.
    • Steve Webb
      By Steve Webb+
      I am having an issue with DMS editor not loading.  Just keeps spinning and spinning.
      Have tried several things - Logged in and out, cleared cache, deactivated all plugins, but the issue persists.
      I even had our host restore from a backup a week ago, when I know it WAS working, as I edited a text box on the homepage.  The restore from backup didn't help either.
      Also, the front end of the site shows that the site is framed, or boxed now (whatever you call it), instead of full width as it was previously (last week).
      Dev console shows that there are php errors in Google maps - file is attached.
      Can someone please help?  Not sure what else I can do here...
      Thanks in advance.
      -Matt

×