Jump to content


Photo
- - - - -

Uncaught TypeError: undefined is not a function

dms error function

Best Answer Simon_P , 07 September 2014 - 11:07 PM

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();

}

Go to the full post


  • Please log in to reply
12 replies to this topic

#1 timjay

timjay

    Advanced Member

  • Members
  • PipPipPip
  • 34 posts
  • Country: Country Flag

Posted 01 September 2014 - 02:17 AM

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')
})
 

Edited by timjay, 01 September 2014 - 02:19 AM.


#2 timjay

timjay

    Advanced Member

  • Members
  • PipPipPip
  • 34 posts
  • Country: Country Flag

Posted 01 September 2014 - 04:39 AM

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



#3 Simon_P

Simon_P

    Messer

  • Administrators



  • 8388607 posts
  • LocationDevon
  • Framework Version:2.1.1
  • Country: Country Flag

Posted 01 September 2014 - 10:08 AM

What script did you add?

#4 timjay

timjay

    Advanced Member

  • Members
  • PipPipPip
  • 34 posts
  • Country: Country Flag

Posted 02 September 2014 - 09:05 PM

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?



#5 Danny

Danny

    Is Awesome!

  • Moderators
  • 16342 posts
  • LocationManchester, UK
  • Country: Country Flag

Posted 03 September 2014 - 10:16 AM

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



#6 timjay

timjay

    Advanced Member

  • Members
  • PipPipPip
  • 34 posts
  • Country: Country Flag

Posted 03 September 2014 - 05:28 PM

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> 

Edited by timjay, 03 September 2014 - 05:29 PM.


#7 Danny

Danny

    Is Awesome!

  • Moderators
  • 16342 posts
  • LocationManchester, UK
  • Country: Country Flag

Posted 04 September 2014 - 11:46 AM

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



#8 timjay

timjay

    Advanced Member

  • Members
  • PipPipPip
  • 34 posts
  • Country: Country Flag

Posted 04 September 2014 - 03:06 PM

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? 



#9 Danny

Danny

    Is Awesome!

  • Moderators
  • 16342 posts
  • LocationManchester, UK
  • Country: Country Flag

Posted 05 September 2014 - 12:40 PM

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.



#10 timjay

timjay

    Advanced Member

  • Members
  • PipPipPip
  • 34 posts
  • Country: Country Flag

Posted 07 September 2014 - 10:59 PM

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?

 

 



#11 Simon_P

Simon_P

    Messer

  • Administrators



  • 8388607 posts
  • LocationDevon
  • Framework Version:2.1.1
  • Country: Country Flag

Posted 07 September 2014 - 11:07 PM   Best Answer

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();

}



#12 timjay

timjay

    Advanced Member

  • Members
  • PipPipPip
  • 34 posts
  • Country: Country Flag

Posted 08 September 2014 - 12:35 AM

Is there no more convenient way to do this?

 

Can custom scripts editor be used for single posts?

 

 



#13 Danny

Danny

    Is Awesome!

  • Moderators
  • 16342 posts
  • LocationManchester, UK
  • Country: Country Flag

Posted 08 September 2014 - 08:52 AM

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.







Also tagged with one or more of these keywords: dms, error, function